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
All checks were successful
Run Tests on Code / run-tests (push) Successful in 18s
This commit is contained in:
parent
6714f447de
commit
f969e21418
2 changed files with 115 additions and 114 deletions
|
@ -354,5 +354,5 @@ pub(crate) struct CloudflareDnsRecord {
|
||||||
pub(crate) id: String,
|
pub(crate) id: String,
|
||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
pub(crate) r#type: DnsRecordType,
|
pub(crate) r#type: DnsRecordType,
|
||||||
content: String
|
pub(crate) content: String
|
||||||
}
|
}
|
43
src/main.rs
43
src/main.rs
|
@ -57,9 +57,7 @@ impl Addresses {
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_new(&mut self, update: bool) -> bool {
|
fn update(&mut self) {
|
||||||
let mut new = false;
|
|
||||||
|
|
||||||
match self.get_v4() {
|
match self.get_v4() {
|
||||||
Ok(ip) => {
|
Ok(ip) => {
|
||||||
if ip != self.ipv4 {
|
if ip != self.ipv4 {
|
||||||
|
@ -68,8 +66,7 @@ impl Addresses {
|
||||||
true => info!("[INFO] {info_msg}"),
|
true => info!("[INFO] {info_msg}"),
|
||||||
false => println!("[INFO] {info_msg}"),
|
false => println!("[INFO] {info_msg}"),
|
||||||
}
|
}
|
||||||
new = true;
|
self.ipv4 = ip;
|
||||||
if update { self.ipv4 = ip }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -89,8 +86,7 @@ impl Addresses {
|
||||||
true => info!("[INFO] {info_msg}"),
|
true => info!("[INFO] {info_msg}"),
|
||||||
false => println!("[INFO] {info_msg}"),
|
false => println!("[INFO] {info_msg}"),
|
||||||
}
|
}
|
||||||
new = true;
|
self.ipv6 = ip;
|
||||||
if update { self.ipv6 = ip }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -101,8 +97,6 @@ impl Addresses {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_v4(&self) -> Result<Ipv4Addr, reqwest::Error> {
|
fn get_v4(&self) -> Result<Ipv4Addr, reqwest::Error> {
|
||||||
|
@ -194,8 +188,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ips.check_new(false) {
|
ips.update();
|
||||||
let mut error = false;
|
|
||||||
for zone in &zone_cfgs {
|
for zone in &zone_cfgs {
|
||||||
let cf_zone = match CloudflareZone::new(zone) {
|
let cf_zone = match CloudflareZone::new(zone) {
|
||||||
Ok(data) => data,
|
Ok(data) => data,
|
||||||
|
@ -205,7 +198,6 @@ fn main() {
|
||||||
true => error!("[ERROR] {err_msg}"),
|
true => error!("[ERROR] {err_msg}"),
|
||||||
false => eprintln!("[ERROR] {err_msg}"),
|
false => eprintln!("[ERROR] {err_msg}"),
|
||||||
}
|
}
|
||||||
error = true;
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -213,7 +205,6 @@ fn main() {
|
||||||
let cf_entries = match cf_zone.get_entries() {
|
let cf_entries = match cf_zone.get_entries() {
|
||||||
Ok(entries) => entries,
|
Ok(entries) => entries,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
error = true;
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -226,7 +217,6 @@ fn main() {
|
||||||
ipv6 = match ifaces.full_v6(&entry.interface, ips.ipv6) {
|
ipv6 = match ifaces.full_v6(&entry.interface, ips.ipv6) {
|
||||||
Ok(ip) => Some(ip),
|
Ok(ip) => Some(ip),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
error = true;
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -236,7 +226,6 @@ fn main() {
|
||||||
ipv6 = match ifaces.full_v6(&entry.interface, ips.ipv6) {
|
ipv6 = match ifaces.full_v6(&entry.interface, ips.ipv6) {
|
||||||
Ok(ip) => Some(ip),
|
Ok(ip) => Some(ip),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
error = true;
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -246,7 +235,6 @@ fn main() {
|
||||||
ipv6 = match ifaces.full_v6(&entry.interface, ips.ipv6) {
|
ipv6 = match ifaces.full_v6(&entry.interface, ips.ipv6) {
|
||||||
Ok(ip) => Some(ip),
|
Ok(ip) => Some(ip),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
error = true;
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -271,6 +259,22 @@ fn main() {
|
||||||
cf_entry.name == entry.name && &cf_entry.r#type == r#type
|
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 {
|
if let Some(cf_entry) = cf_entry {
|
||||||
match cf_zone.update(entry, r#type, &cf_entry.id, ipv6, ipv4) {
|
match cf_zone.update(entry, r#type, &cf_entry.id, ipv6, ipv4) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
@ -280,7 +284,7 @@ fn main() {
|
||||||
false => println!("[INFO] {info_msg}"),
|
false => println!("[INFO] {info_msg}"),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(_) => error = true,
|
Err(_) => {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -292,16 +296,13 @@ fn main() {
|
||||||
false => println!("[INFO] {info_msg}"),
|
false => println!("[INFO] {info_msg}"),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(_) => error = true,
|
Err(_) => {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle return values
|
// handle return values
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !error { ips.check_new(true); }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sleep(std::time::Duration::from_millis(200));
|
sleep(std::time::Duration::from_millis(200));
|
||||||
|
|
Loading…
Reference in a new issue