Fix class methods

This commit is contained in:
Neshura 2023-02-27 16:15:00 +01:00
parent 4525eb1974
commit add93f26f4
No known key found for this signature in database
GPG key ID: ACDF5B6EBECF6B0A

View file

@ -55,71 +55,78 @@ struct DnsEntry {
}
impl DnsEntry {
fn update(&self, change4: &mut ChangeTracker, change6: &mut ChangeTracker, agent: &Instance, ips: &Ips) {
fn update(
&self,
change4: &mut ChangeTracker,
change6: &mut ChangeTracker,
agent: &Instance,
ips: &Ips,
zone: &DnsZone
) {
let mut found4 = false;
let mut found6 = false;
for cloudflare_entry in &agent.dns_entries {
// Update IPv4 Entry
if cloudflare_entry.is_equal(&self.name) {
found4 = true;
if cloudflare_entry.r#type == CloudflareDnsType::A && self.type4 {
let success = agent.update_entry(cloudflare_entry, &ips.ipv4);
if success {
change4.updated += 1;
}
else {
change4.error += 1;
}
}
else {
change4.unchanged += 1;
}
}
// Update IPv6 Entry
else if cloudflare_entry.r#type == CloudflareDnsType::AAAA && self.type6 {
found6 = true;
let ipv6 = ips.ipv6base.clone() + self.interface.as_ref().unwrap();
if cloudflare_entry.is_ip_new(&ipv6) {
let success = agent.update_entry(cloudflare_entry, &ipv6);
if success {
change6.updated += 1
if cloudflare_entry.is_ip_new(&ips.ipv4) {
if success {
change4.updated += 1;
}
else {
change4.error += 1;
}
}
else {
change6.error += 1
change4.unchanged += 1;
}
}
else {
change6.unchanged += 1;
// Update IPv6 Entry
else if cloudflare_entry.r#type == CloudflareDnsType::AAAA && self.type6 {
found6 = true;
let ipv6 = ips.ipv6base.clone() + self.interface.as_ref().unwrap();
if cloudflare_entry.is_ip_new(&ipv6) {
let success = agent.update_entry(cloudflare_entry, &ipv6);
if success {
change6.updated += 1
}
else {
change6.error += 1
}
}
else {
change6.unchanged += 1;
}
}
// ignore otherwise
else {}
}
}
if !found4 && self.type4 {
let success = agent.create_entry(&zone.id, "A", &self.name, &ips.ipv4);
if success {
change4.created += 1;
}
// ignore otherwise
else {
change4.error += 1;
};
}
if !found6 && self.type6 {
let ipv6 = ips.ipv6base.clone() + self.interface.as_ref().unwrap();
let success = agent.create_entry(&zone.id, "AAAA", &self.name, &ipv6);
if success {
change6.created += 1;
}
if !found4 && self.type4 {
let success = agent.create_entry(&cloudflare_entry.zone_id, "A", &self.name, &ips.ipv4);
if success {
change4.created += 1;
}
else {
change4.error += 1;
};
}
if !found6 && self.type6 {
let ipv6 = ips.ipv6base.clone() + self.interface.as_ref().unwrap();
let success = agent.create_entry(&cloudflare_entry.zone_id, "AAAA", &self.name, &ipv6);
if success {
change6.created += 1;
}
else {
change6.error += 1;
};
}
else {
change6.error += 1;
};
}
}
}
@ -139,7 +146,7 @@ impl DnsZone {
agent.load_entries(&self.email, &self.id);
for entry in &self.dns_entries {
entry.update(change4, change6, &agent, &ips);
entry.update(change4, change6, &agent, &ips, &self);
}
}
}