Bugfix: DNS Updater would not work for freshly created DNS records or records with outdated info
All checks were successful
Run Tests on Code / run-tests (push) Successful in 18s

This commit is contained in:
Neshura 2023-12-26 18:53:22 +01:00
parent 6714f447de
commit f969e21418
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
2 changed files with 115 additions and 114 deletions

View file

@ -354,5 +354,5 @@ pub(crate) struct CloudflareDnsRecord {
pub(crate) id: String,
pub(crate) name: String,
pub(crate) r#type: DnsRecordType,
content: String
pub(crate) content: String
}

View file

@ -57,9 +57,7 @@ impl Addresses {
Ok(ret)
}
fn check_new(&mut self, update: bool) -> bool {
let mut new = false;
fn update(&mut self) {
match self.get_v4() {
Ok(ip) => {
if ip != self.ipv4 {
@ -68,8 +66,7 @@ impl Addresses {
true => info!("[INFO] {info_msg}"),
false => println!("[INFO] {info_msg}"),
}
new = true;
if update { self.ipv4 = ip }
self.ipv4 = ip;
}
}
Err(e) => {
@ -89,8 +86,7 @@ impl Addresses {
true => info!("[INFO] {info_msg}"),
false => println!("[INFO] {info_msg}"),
}
new = true;
if update { self.ipv6 = ip }
self.ipv6 = ip;
}
}
Err(e) => {
@ -101,8 +97,6 @@ impl Addresses {
}
}
}
new
}
fn get_v4(&self) -> Result<Ipv4Addr, reqwest::Error> {
@ -194,8 +188,7 @@ fn main() {
}
}
if ips.check_new(false) {
let mut error = false;
ips.update();
for zone in &zone_cfgs {
let cf_zone = match CloudflareZone::new(zone) {
Ok(data) => data,
@ -205,7 +198,6 @@ fn main() {
true => error!("[ERROR] {err_msg}"),
false => eprintln!("[ERROR] {err_msg}"),
}
error = true;
continue
}
};
@ -213,7 +205,6 @@ fn main() {
let cf_entries = match cf_zone.get_entries() {
Ok(entries) => entries,
Err(_) => {
error = true;
continue
}
};
@ -226,7 +217,6 @@ fn main() {
ipv6 = match ifaces.full_v6(&entry.interface, ips.ipv6) {
Ok(ip) => Some(ip),
Err(_) => {
error = true;
continue
}
};
@ -236,7 +226,6 @@ fn main() {
ipv6 = match ifaces.full_v6(&entry.interface, ips.ipv6) {
Ok(ip) => Some(ip),
Err(_) => {
error = true;
continue
}
};
@ -246,7 +235,6 @@ fn main() {
ipv6 = match ifaces.full_v6(&entry.interface, ips.ipv6) {
Ok(ip) => Some(ip),
Err(_) => {
error = true;
continue
}
};
@ -271,6 +259,22 @@ fn main() {
cf_entry.name == entry.name && &cf_entry.r#type == r#type
});
match cf_entry.unwrap().r#type {
DnsRecordType::A => {
let cf_ip = Ipv4Addr::from_str(cf_entry.unwrap().content.as_str()).expect("Cloudflare return should always be valid IP");
if Some(cf_ip) == ipv4 {
continue
}
},
DnsRecordType::AAAA => {
let cf_ip = Ipv6Addr::from_str(cf_entry.unwrap().content.as_str()).expect("Cloudflare return should always be valid IP");
if Some(cf_ip) == ipv6 {
continue
}
},
_ => {},
}
if let Some(cf_entry) = cf_entry {
match cf_zone.update(entry, r#type, &cf_entry.id, ipv6, ipv4) {
Ok(_) => {
@ -280,7 +284,7 @@ fn main() {
false => println!("[INFO] {info_msg}"),
}
},
Err(_) => error = true,
Err(_) => {},
};
}
else {
@ -292,16 +296,13 @@ fn main() {
false => println!("[INFO] {info_msg}"),
}
},
Err(_) => error = true,
Err(_) => {},
};
}
}
// handle return values
}
}
if !error { ips.check_new(true); }
}
}
else {
sleep(std::time::Duration::from_millis(200));