Upgrade dependencies
This commit is contained in:
parent
3ff8442c1a
commit
b912f9140e
4 changed files with 551 additions and 665 deletions
1121
Cargo.lock
generated
1121
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
16
Cargo.toml
16
Cargo.toml
|
@ -1,19 +1,19 @@
|
|||
[package]
|
||||
name = "check_ip"
|
||||
version = "2.1.0"
|
||||
version = "2.2.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
lettre = "0.9"
|
||||
lettre_email = "0.9"
|
||||
native-tls = "0.2"
|
||||
lettre = "0.10"
|
||||
toml = "0.5"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
log = "0.4"
|
||||
simplelog = "0.11"
|
||||
clokwerk = "0.3"
|
||||
trust-dns-resolver = {version = "0.21", features = ["serde-config"] }
|
||||
simplelog = "0.12"
|
||||
clokwerk = "0.4"
|
||||
trust-dns-resolver = {version = "0.22", features = ["serde-config"] }
|
||||
query_external_ip = "0.1"
|
||||
tokio = "1"
|
||||
systemstat = "0.1"
|
||||
systemstat = "0.2"
|
||||
time = "0.3"
|
||||
native-tls = { version = "0.2", features = ["vendored"]}
|
1
TODO.md
1
TODO.md
|
@ -2,5 +2,6 @@
|
|||
* [ ] Ajout de la version dans les logs
|
||||
* [ ] Examples de fichiers de config (config + systemd)
|
||||
* [ ] Rustfmt
|
||||
* [ ] Logs tournant
|
||||
* [ ] Fonction check asychrone
|
||||
* [ ] Utilisation de l’[API Gandi](https://api.gandi.net/docs/livedns) via [restson](https://crates.io/crates/restson)
|
78
src/main.rs
78
src/main.rs
|
@ -1,22 +1,8 @@
|
|||
extern crate anyhow;
|
||||
extern crate clokwerk;
|
||||
extern crate lettre;
|
||||
extern crate lettre_email;
|
||||
extern crate log;
|
||||
extern crate native_tls;
|
||||
extern crate serde;
|
||||
extern crate simplelog;
|
||||
extern crate systemstat;
|
||||
extern crate tokio;
|
||||
extern crate toml;
|
||||
extern crate trust_dns_resolver;
|
||||
|
||||
use self::native_tls::{Protocol, TlsConnector};
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use clokwerk::{Scheduler, TimeUnits};
|
||||
use lettre::smtp::authentication::Credentials;
|
||||
use lettre::{ClientSecurity, ClientTlsParameters, SmtpClient, Transport};
|
||||
use lettre_email::EmailBuilder;
|
||||
use clokwerk::{Job, Scheduler, TimeUnits};
|
||||
use lettre::message::Mailbox;
|
||||
use lettre::transport::smtp::authentication::Credentials;
|
||||
use lettre::{Address, Message, SmtpTransport, Transport};
|
||||
use log::{error, info, warn};
|
||||
use query_external_ip::Consensus;
|
||||
use serde::Deserialize;
|
||||
|
@ -39,8 +25,11 @@ fn main() -> Result<()> {
|
|||
WriteLogger::init(
|
||||
LevelFilter::Info,
|
||||
ConfigBuilder::new()
|
||||
.set_time_format_str("%d/%m/%Y %H:%M:%S")
|
||||
.set_time_to_local(true)
|
||||
.set_time_format_custom(simplelog::format_description!(
|
||||
"[day]/[month]/[year] [hour]:[minute]:[second]"
|
||||
))
|
||||
.set_time_offset_to_local()
|
||||
.unwrap()
|
||||
.build(),
|
||||
logfile,
|
||||
)
|
||||
|
@ -68,7 +57,7 @@ fn main() -> Result<()> {
|
|||
bail!("Cannot get initial IP");
|
||||
}
|
||||
|
||||
// Lauch scheduler
|
||||
// Launch scheduler
|
||||
if let Some(false) = tester.config.test {
|
||||
// Init scheduler
|
||||
info!("Init scheduler");
|
||||
|
@ -164,13 +153,13 @@ impl Tester {
|
|||
|
||||
fn test_domains(&self, ipv4: Ipv4Addr, ipv6: Ipv6Addr) -> Result<String> {
|
||||
macro_rules! msg {
|
||||
($full_msg:expr, $($arg:tt)*) => {{
|
||||
let msg = format!($($arg)*);
|
||||
info!("{}", msg);
|
||||
$full_msg.push_str(&msg);
|
||||
$full_msg.push('\n');
|
||||
}}
|
||||
}
|
||||
($full_msg:expr, $($arg:tt)*) => {{
|
||||
let msg = format!($($arg)*);
|
||||
info!("{}", msg);
|
||||
$full_msg.push_str(&msg);
|
||||
$full_msg.push('\n');
|
||||
}}
|
||||
}
|
||||
|
||||
let mut full_msg = String::new();
|
||||
for domain in self.config.server.domains.iter() {
|
||||
|
@ -211,32 +200,29 @@ impl Tester {
|
|||
info!("Send mail {}", subject);
|
||||
|
||||
if let Some(false) = self.config.test {
|
||||
let email = EmailBuilder::new()
|
||||
.to(self.config.mail.from.clone())
|
||||
.from(self.config.mail.to.clone())
|
||||
let email = Message::builder()
|
||||
.to(Mailbox::new(
|
||||
Some(self.config.mail.from.1.clone()),
|
||||
self.config.mail.from.0.parse::<Address>()?,
|
||||
))
|
||||
.from(self.config.mail.to.parse()?)
|
||||
.subject(subject)
|
||||
.text(body)
|
||||
.build()?;
|
||||
.body(body)?;
|
||||
|
||||
// Create transport
|
||||
let creds = Credentials::new(
|
||||
self.config.mail.username.clone(),
|
||||
self.config.mail.password.clone(),
|
||||
);
|
||||
let mut tls_builder = TlsConnector::builder();
|
||||
tls_builder.min_protocol_version(Some(Protocol::Sslv3));
|
||||
let tls_parameters = ClientTlsParameters::new(
|
||||
self.config.mail.server.clone(),
|
||||
tls_builder.build().unwrap(),
|
||||
);
|
||||
let mut mailer = SmtpClient::new(
|
||||
(self.config.mail.server.clone(), self.config.mail.port),
|
||||
ClientSecurity::Required(tls_parameters),
|
||||
)?
|
||||
.credentials(creds)
|
||||
.transport();
|
||||
|
||||
mailer.send(email.into())?;
|
||||
// Open a remote connection to gmail
|
||||
let mailer = SmtpTransport::relay(&self.config.mail.server)
|
||||
.unwrap()
|
||||
.credentials(creds)
|
||||
.port(self.config.mail.port)
|
||||
.build();
|
||||
|
||||
mailer.send(&email)?;
|
||||
} else {
|
||||
println!("subject: {} - body: {}", subject, body);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue