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]
|
[package]
|
||||||
name = "check_ip"
|
name = "check_ip"
|
||||||
version = "2.1.0"
|
version = "2.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
lettre = "0.9"
|
lettre = "0.10"
|
||||||
lettre_email = "0.9"
|
|
||||||
native-tls = "0.2"
|
|
||||||
toml = "0.5"
|
toml = "0.5"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
simplelog = "0.11"
|
simplelog = "0.12"
|
||||||
clokwerk = "0.3"
|
clokwerk = "0.4"
|
||||||
trust-dns-resolver = {version = "0.21", features = ["serde-config"] }
|
trust-dns-resolver = {version = "0.22", features = ["serde-config"] }
|
||||||
query_external_ip = "0.1"
|
query_external_ip = "0.1"
|
||||||
tokio = "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
|
* [ ] Ajout de la version dans les logs
|
||||||
* [ ] Examples de fichiers de config (config + systemd)
|
* [ ] Examples de fichiers de config (config + systemd)
|
||||||
* [ ] Rustfmt
|
* [ ] Rustfmt
|
||||||
|
* [ ] Logs tournant
|
||||||
* [ ] Fonction check asychrone
|
* [ ] Fonction check asychrone
|
||||||
* [ ] Utilisation de l’[API Gandi](https://api.gandi.net/docs/livedns) via [restson](https://crates.io/crates/restson)
|
* [ ] 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 anyhow::{anyhow, bail, Result};
|
||||||
use clokwerk::{Scheduler, TimeUnits};
|
use clokwerk::{Job, Scheduler, TimeUnits};
|
||||||
use lettre::smtp::authentication::Credentials;
|
use lettre::message::Mailbox;
|
||||||
use lettre::{ClientSecurity, ClientTlsParameters, SmtpClient, Transport};
|
use lettre::transport::smtp::authentication::Credentials;
|
||||||
use lettre_email::EmailBuilder;
|
use lettre::{Address, Message, SmtpTransport, Transport};
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use query_external_ip::Consensus;
|
use query_external_ip::Consensus;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -39,8 +25,11 @@ fn main() -> Result<()> {
|
||||||
WriteLogger::init(
|
WriteLogger::init(
|
||||||
LevelFilter::Info,
|
LevelFilter::Info,
|
||||||
ConfigBuilder::new()
|
ConfigBuilder::new()
|
||||||
.set_time_format_str("%d/%m/%Y %H:%M:%S")
|
.set_time_format_custom(simplelog::format_description!(
|
||||||
.set_time_to_local(true)
|
"[day]/[month]/[year] [hour]:[minute]:[second]"
|
||||||
|
))
|
||||||
|
.set_time_offset_to_local()
|
||||||
|
.unwrap()
|
||||||
.build(),
|
.build(),
|
||||||
logfile,
|
logfile,
|
||||||
)
|
)
|
||||||
|
@ -68,7 +57,7 @@ fn main() -> Result<()> {
|
||||||
bail!("Cannot get initial IP");
|
bail!("Cannot get initial IP");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lauch scheduler
|
// Launch scheduler
|
||||||
if let Some(false) = tester.config.test {
|
if let Some(false) = tester.config.test {
|
||||||
// Init scheduler
|
// Init scheduler
|
||||||
info!("Init scheduler");
|
info!("Init scheduler");
|
||||||
|
@ -164,13 +153,13 @@ impl Tester {
|
||||||
|
|
||||||
fn test_domains(&self, ipv4: Ipv4Addr, ipv6: Ipv6Addr) -> Result<String> {
|
fn test_domains(&self, ipv4: Ipv4Addr, ipv6: Ipv6Addr) -> Result<String> {
|
||||||
macro_rules! msg {
|
macro_rules! msg {
|
||||||
($full_msg:expr, $($arg:tt)*) => {{
|
($full_msg:expr, $($arg:tt)*) => {{
|
||||||
let msg = format!($($arg)*);
|
let msg = format!($($arg)*);
|
||||||
info!("{}", msg);
|
info!("{}", msg);
|
||||||
$full_msg.push_str(&msg);
|
$full_msg.push_str(&msg);
|
||||||
$full_msg.push('\n');
|
$full_msg.push('\n');
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut full_msg = String::new();
|
let mut full_msg = String::new();
|
||||||
for domain in self.config.server.domains.iter() {
|
for domain in self.config.server.domains.iter() {
|
||||||
|
@ -211,32 +200,29 @@ impl Tester {
|
||||||
info!("Send mail {}", subject);
|
info!("Send mail {}", subject);
|
||||||
|
|
||||||
if let Some(false) = self.config.test {
|
if let Some(false) = self.config.test {
|
||||||
let email = EmailBuilder::new()
|
let email = Message::builder()
|
||||||
.to(self.config.mail.from.clone())
|
.to(Mailbox::new(
|
||||||
.from(self.config.mail.to.clone())
|
Some(self.config.mail.from.1.clone()),
|
||||||
|
self.config.mail.from.0.parse::<Address>()?,
|
||||||
|
))
|
||||||
|
.from(self.config.mail.to.parse()?)
|
||||||
.subject(subject)
|
.subject(subject)
|
||||||
.text(body)
|
.body(body)?;
|
||||||
.build()?;
|
|
||||||
|
|
||||||
// Create transport
|
// Create transport
|
||||||
let creds = Credentials::new(
|
let creds = Credentials::new(
|
||||||
self.config.mail.username.clone(),
|
self.config.mail.username.clone(),
|
||||||
self.config.mail.password.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 {
|
} else {
|
||||||
println!("subject: {} - body: {}", subject, body);
|
println!("subject: {} - body: {}", subject, body);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue