pub struct Config {\r
pub delay_between_check: time::Duration,\r
pub api_key: String,\r
- pub fqdn: String,\r
- pub domains: Vec<String>,\r
+ pub domains: Vec<(String, String)>, // Hostname, domain.\r
pub ttl: i32\r
}\r
\r
impl Config {\r
pub fn default() -> Self {\r
- Config { delay_between_check: time::Duration::from_secs(120), api_key: String::from(""), fqdn: String::from(""), domains: Vec::new(), ttl: 300 }\r
+ Config { delay_between_check: time::Duration::from_secs(120), api_key: String::from(""), domains: Vec::new(), ttl: 300 }\r
}\r
\r
pub fn read(file_path: &str) -> Result<Config> {\r
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);
}
}
}
-fn check_and_update_dns(api_key: &str, fqdn: &str, domains: &Vec<String>, 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);
}
}