From e45d8f67336160ae61a9dc24f899752f5199a01b Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Fri, 16 Jul 2021 11:24:13 +0200 Subject: [PATCH] Be able to accept multiple domains. --- src/config.rs | 5 ++--- src/main.rs | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index e3b1309..fb6b7cf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,14 +8,13 @@ use crate::error::Result; pub struct Config { pub delay_between_check: time::Duration, pub api_key: String, - pub fqdn: String, - pub domains: Vec, + pub domains: Vec<(String, String)>, // Hostname, domain. pub ttl: i32 } impl Config { pub fn default() -> Self { - Config { delay_between_check: time::Duration::from_secs(120), api_key: String::from(""), fqdn: String::from(""), domains: Vec::new(), ttl: 300 } + Config { delay_between_check: time::Duration::from_secs(120), api_key: String::from(""), domains: Vec::new(), ttl: 300 } } pub fn read(file_path: &str) -> Result { diff --git a/src/main.rs b/src/main.rs index 496fd98..f9d8f4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ fn main() -> Result<()> { loop { let time_beginning_loop = time::Instant::now(); - if let Err(err) = check_and_update_dns(&config.api_key, &config.fqdn, &config.domains, config.ttl) { + if let Err(err) = check_and_update_dns(&config.api_key, &config.domains, config.ttl) { println!("!! {}", err); } @@ -43,15 +43,15 @@ fn main() -> Result<()> { } } -fn check_and_update_dns(api_key: &str, fqdn: &str, domains: &Vec, ttl: i32) -> Result<()> { +fn check_and_update_dns(api_key: &str, domains: &Vec<(String, String)>, ttl: i32) -> Result<()> { let real_ip = get_real_ip()?; - for domain in domains { - let current_ip = get_current_record_ip(api_key, domain, fqdn)?; + for (hostname, domain) in domains { + let current_ip = get_current_record_ip(api_key, hostname, domain)?; if real_ip != current_ip { println!("IP addresses don't match for domain {}: real = {}, dns = {}. Renewing DNS...", domain, real_ip, current_ip); - update_record_ip(api_key, domain, fqdn, real_ip, ttl)?; + update_record_ip(api_key, hostname, domain, real_ip, ttl)?; println!("Renewing of {} successfully", domain); } } -- 2.45.2