Merge pull request #718 from rhansen/force_update

Cleanups to forced update logic
This commit is contained in:
Richard Hansen 2024-07-26 19:04:36 -04:00 committed by GitHub
commit 356c3354bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -709,7 +709,6 @@ our %variables = (
); );
our %protocols = ( our %protocols = (
'1984' => { '1984' => {
'force_update' => undef,
'update' => \&nic_1984_update, 'update' => \&nic_1984_update,
'examples' => \&nic_1984_examples, 'examples' => \&nic_1984_examples,
'variables' => { 'variables' => {
@ -719,7 +718,6 @@ our %protocols = (
}, },
}, },
'changeip' => { 'changeip' => {
'force_update' => undef,
'update' => \&nic_changeip_update, 'update' => \&nic_changeip_update,
'examples' => \&nic_changeip_examples, 'examples' => \&nic_changeip_examples,
'variables' => { 'variables' => {
@ -729,7 +727,6 @@ our %protocols = (
}, },
}, },
'cloudflare' => { 'cloudflare' => {
'force_update' => undef,
'update' => \&nic_cloudflare_update, 'update' => \&nic_cloudflare_update,
'examples' => \&nic_cloudflare_examples, 'examples' => \&nic_cloudflare_examples,
'variables' => { 'variables' => {
@ -746,7 +743,6 @@ our %protocols = (
}, },
}, },
'cloudns' => { 'cloudns' => {
'force_update' => undef,
'update' => \&nic_cloudns_update, 'update' => \&nic_cloudns_update,
'examples' => \&nic_cloudns_examples, 'examples' => \&nic_cloudns_examples,
'variables' => { 'variables' => {
@ -757,7 +753,6 @@ our %protocols = (
}, },
}, },
'ddns.fm' => { 'ddns.fm' => {
'force_update' => undef,
'update' => \&nic_ddnsfm_update, 'update' => \&nic_ddnsfm_update,
'examples' => \&nic_ddnsfm_examples, 'examples' => \&nic_ddnsfm_examples,
'variables' => { 'variables' => {
@ -767,7 +762,6 @@ our %protocols = (
}, },
}, },
'digitalocean' => { 'digitalocean' => {
'force_update' => undef,
'update' => \&nic_digitalocean_update, 'update' => \&nic_digitalocean_update,
'examples' => \&nic_digitalocean_examples, 'examples' => \&nic_digitalocean_examples,
'variables' => { 'variables' => {
@ -778,7 +772,6 @@ our %protocols = (
}, },
}, },
'dinahosting' => { 'dinahosting' => {
'force_update' => undef,
'update' => \&nic_dinahosting_update, 'update' => \&nic_dinahosting_update,
'examples' => \&nic_dinahosting_examples, 'examples' => \&nic_dinahosting_examples,
'variables' => { 'variables' => {
@ -789,7 +782,6 @@ our %protocols = (
}, },
}, },
'dnsmadeeasy' => { 'dnsmadeeasy' => {
'force_update' => undef,
'update' => \&nic_dnsmadeeasy_update, 'update' => \&nic_dnsmadeeasy_update,
'examples' => \&nic_dnsmadeeasy_examples, 'examples' => \&nic_dnsmadeeasy_examples,
'variables' => { 'variables' => {
@ -799,7 +791,6 @@ our %protocols = (
}, },
}, },
'dondominio' => { 'dondominio' => {
'force_update' => undef,
'update' => \&nic_dondominio_update, 'update' => \&nic_dondominio_update,
'examples' => \&nic_dondominio_examples, 'examples' => \&nic_dondominio_examples,
'variables' => { 'variables' => {
@ -808,7 +799,6 @@ our %protocols = (
}, },
}, },
'dslreports1' => { 'dslreports1' => {
'force_update' => undef,
'update' => \&nic_dslreports1_update, 'update' => \&nic_dslreports1_update,
'examples' => \&nic_dslreports1_examples, 'examples' => \&nic_dslreports1_examples,
'variables' => { 'variables' => {
@ -817,7 +807,6 @@ our %protocols = (
}, },
}, },
'domeneshop' => { 'domeneshop' => {
'force_update' => undef,
'update' => \&nic_domeneshop_update, 'update' => \&nic_domeneshop_update,
'examples' => \&nic_domeneshop_examples, 'examples' => \&nic_domeneshop_examples,
'variables' => { 'variables' => {
@ -826,7 +815,6 @@ our %protocols = (
}, },
}, },
'duckdns' => { 'duckdns' => {
'force_update' => undef,
'update' => \&nic_duckdns_update, 'update' => \&nic_duckdns_update,
'examples' => \&nic_duckdns_examples, 'examples' => \&nic_duckdns_examples,
'variables' => { 'variables' => {
@ -836,7 +824,6 @@ our %protocols = (
}, },
}, },
'dyndns1' => { 'dyndns1' => {
'force_update' => \&nic_dyndns2_force_update,
'update' => \&nic_dyndns1_update, 'update' => \&nic_dyndns1_update,
'examples' => \&nic_dyndns1_examples, 'examples' => \&nic_dyndns1_examples,
'variables' => { 'variables' => {
@ -846,7 +833,6 @@ our %protocols = (
}, },
}, },
'dyndns2' => { 'dyndns2' => {
'force_update' => \&nic_dyndns2_force_update,
'update' => \&nic_dyndns2_update, 'update' => \&nic_dyndns2_update,
'examples' => \&nic_dyndns2_examples, 'examples' => \&nic_dyndns2_examples,
'variables' => { 'variables' => {
@ -856,7 +842,6 @@ our %protocols = (
}, },
}, },
'easydns' => { 'easydns' => {
'force_update' => undef,
'update' => \&nic_easydns_update, 'update' => \&nic_easydns_update,
'examples' => \&nic_easydns_examples, 'examples' => \&nic_easydns_examples,
'variables' => { 'variables' => {
@ -872,7 +857,6 @@ our %protocols = (
}, },
}, },
'freedns' => { 'freedns' => {
'force_update' => undef,
'update' => \&nic_freedns_update, 'update' => \&nic_freedns_update,
'examples' => \&nic_freedns_examples, 'examples' => \&nic_freedns_examples,
'variables' => { 'variables' => {
@ -882,7 +866,6 @@ our %protocols = (
}, },
}, },
'freemyip' => { 'freemyip' => {
'force_update' => undef,
'update' => \&nic_freemyip_update, 'update' => \&nic_freemyip_update,
'examples' => \&nic_freemyip_examples, 'examples' => \&nic_freemyip_examples,
'variables' => { 'variables' => {
@ -892,7 +875,6 @@ our %protocols = (
}, },
}, },
'gandi' => { 'gandi' => {
'force_update' => undef,
'update' => \&nic_gandi_update, 'update' => \&nic_gandi_update,
'examples' => \&nic_gandi_examples, 'examples' => \&nic_gandi_examples,
'variables' => { 'variables' => {
@ -907,7 +889,6 @@ our %protocols = (
} }
}, },
'godaddy' => { 'godaddy' => {
'force_update' => undef,
'update' => \&nic_godaddy_update, 'update' => \&nic_godaddy_update,
'examples' => \&nic_godaddy_examples, 'examples' => \&nic_godaddy_examples,
'variables' => { 'variables' => {
@ -919,7 +900,6 @@ our %protocols = (
}, },
}, },
'he.net' => { 'he.net' => {
'updateable' => undef,
'update' => \&nic_henet_update, 'update' => \&nic_henet_update,
'examples' => \&nic_henet_examples, 'examples' => \&nic_henet_examples,
'variables' => { 'variables' => {
@ -930,7 +910,6 @@ our %protocols = (
}, },
}, },
'hetzner' => { 'hetzner' => {
'force_update' => undef,
'update' => \&nic_hetzner_update, 'update' => \&nic_hetzner_update,
'examples' => \&nic_hetzner_examples, 'examples' => \&nic_hetzner_examples,
'variables' => { 'variables' => {
@ -943,7 +922,6 @@ our %protocols = (
}, },
}, },
'inwx' => { 'inwx' => {
'force_update' => undef,
'update' => \&nic_inwx_update, 'update' => \&nic_inwx_update,
'examples' => \&nic_inwx_examples, 'examples' => \&nic_inwx_examples,
'variables' => { 'variables' => {
@ -953,7 +931,6 @@ our %protocols = (
}, },
}, },
'mythicdyn' => { 'mythicdyn' => {
'force_update' => undef,
'update' => \&nic_mythicdyn_update, 'update' => \&nic_mythicdyn_update,
'examples' => \&nic_mythicdyn_examples, 'examples' => \&nic_mythicdyn_examples,
'variables' => { 'variables' => {
@ -963,7 +940,6 @@ our %protocols = (
}, },
}, },
'namecheap' => { 'namecheap' => {
'force_update' => undef,
'update' => \&nic_namecheap_update, 'update' => \&nic_namecheap_update,
'examples' => \&nic_namecheap_examples, 'examples' => \&nic_namecheap_examples,
'variables' => { 'variables' => {
@ -973,7 +949,6 @@ our %protocols = (
}, },
}, },
'nfsn' => { 'nfsn' => {
'force_update' => undef,
'update' => \&nic_nfsn_update, 'update' => \&nic_nfsn_update,
'examples' => \&nic_nfsn_examples, 'examples' => \&nic_nfsn_examples,
'variables' => { 'variables' => {
@ -985,7 +960,6 @@ our %protocols = (
}, },
}, },
'njalla' => { 'njalla' => {
'force_update' => undef,
'update' => \&nic_njalla_update, 'update' => \&nic_njalla_update,
'examples' => \&nic_njalla_examples, 'examples' => \&nic_njalla_examples,
'variables' => { 'variables' => {
@ -996,7 +970,6 @@ our %protocols = (
}, },
}, },
'noip' => { 'noip' => {
'force_update' => undef,
'update' => \&nic_noip_update, 'update' => \&nic_noip_update,
'examples' => \&nic_noip_examples, 'examples' => \&nic_noip_examples,
'variables' => { 'variables' => {
@ -1005,7 +978,6 @@ our %protocols = (
}, },
}, },
'nsupdate' => { 'nsupdate' => {
'force_update' => undef,
'update' => \&nic_nsupdate_update, 'update' => \&nic_nsupdate_update,
'examples' => \&nic_nsupdate_examples, 'examples' => \&nic_nsupdate_examples,
'variables' => { 'variables' => {
@ -1017,7 +989,6 @@ our %protocols = (
}, },
}, },
'ovh' => { 'ovh' => {
'force_update' => undef,
'update' => \&nic_ovh_update, 'update' => \&nic_ovh_update,
'examples' => \&nic_ovh_examples, 'examples' => \&nic_ovh_examples,
'variables' => { 'variables' => {
@ -1027,7 +998,6 @@ our %protocols = (
}, },
}, },
'porkbun' => { 'porkbun' => {
'force_update' => undef,
'update' => \&nic_porkbun_update, 'update' => \&nic_porkbun_update,
'examples' => \&nic_porkbun_examples, 'examples' => \&nic_porkbun_examples,
'variables' => { 'variables' => {
@ -1041,7 +1011,6 @@ our %protocols = (
}, },
}, },
'sitelutions' => { 'sitelutions' => {
'force_update' => undef,
'update' => \&nic_sitelutions_update, 'update' => \&nic_sitelutions_update,
'examples' => \&nic_sitelutions_examples, 'examples' => \&nic_sitelutions_examples,
'variables' => { 'variables' => {
@ -1051,7 +1020,6 @@ our %protocols = (
}, },
}, },
'yandex' => { 'yandex' => {
'force_update' => undef,
'update' => \&nic_yandex_update, 'update' => \&nic_yandex_update,
'examples' => \&nic_yandex_examples, 'examples' => \&nic_yandex_examples,
'variables' => { 'variables' => {
@ -1061,7 +1029,6 @@ our %protocols = (
}, },
}, },
'zoneedit1' => { 'zoneedit1' => {
'force_update' => undef,
'update' => \&nic_zoneedit1_update, 'update' => \&nic_zoneedit1_update,
'examples' => \&nic_zoneedit1_examples, 'examples' => \&nic_zoneedit1_examples,
'variables' => { 'variables' => {
@ -1072,7 +1039,6 @@ our %protocols = (
}, },
}, },
'keysystems' => { 'keysystems' => {
'force_update' => undef,
'update' => \&nic_keysystems_update, 'update' => \&nic_keysystems_update,
'examples' => \&nic_keysystems_examples, 'examples' => \&nic_keysystems_examples,
'variables' => { 'variables' => {
@ -1082,7 +1048,6 @@ our %protocols = (
}, },
}, },
'dnsexit2' => { 'dnsexit2' => {
'force_update' => undef,
'update' => \&nic_dnsexit2_update, 'update' => \&nic_dnsexit2_update,
'examples' => \&nic_dnsexit2_examples, 'examples' => \&nic_dnsexit2_examples,
'variables' => { 'variables' => {
@ -1096,7 +1061,6 @@ our %protocols = (
}, },
}, },
'regfishde' => { 'regfishde' => {
'force_update' => undef,
'update' => \&nic_regfishde_update, 'update' => \&nic_regfishde_update,
'examples' => \&nic_regfishde_examples, 'examples' => \&nic_regfishde_examples,
'variables' => { 'variables' => {
@ -1106,7 +1070,6 @@ our %protocols = (
}, },
}, },
'enom' => { 'enom' => {
'force_update' => undef,
'update' => \&nic_enom_update, 'update' => \&nic_enom_update,
'examples' => \&nic_enom_examples, 'examples' => \&nic_enom_examples,
'variables' => { 'variables' => {
@ -1116,7 +1079,6 @@ our %protocols = (
}, },
}, },
'infomaniak' => { 'infomaniak' => {
'force_update' => undef,
'update' => \&nic_infomaniak_update, 'update' => \&nic_infomaniak_update,
'examples' => \&nic_infomaniak_examples, 'examples' => \&nic_infomaniak_examples,
'variables' => { 'variables' => {
@ -1125,7 +1087,6 @@ our %protocols = (
}, },
}, },
'emailonly' => { 'emailonly' => {
'force_update' => undef,
'update' => \&nic_emailonly_update, 'update' => \&nic_emailonly_update,
'examples' => \&nic_emailonly_examples, 'examples' => \&nic_emailonly_examples,
'variables' => { 'variables' => {
@ -1405,7 +1366,6 @@ sub update_nics {
for my $p (sort keys %protocols) { for my $p (sort keys %protocols) {
my (@hosts, %ipsv4, %ipsv6) = (); my (@hosts, %ipsv4, %ipsv6) = ();
my $force_update = $protocols{$p}{'force_update'};
my $update = $protocols{$p}{'update'}; my $update = $protocols{$p}{'update'};
for my $h (sort keys %config) { for my $h (sort keys %config) {
@ -1500,7 +1460,7 @@ sub update_nics {
next; next;
} }
next if !nic_updateable($h, $force_update); next if !nic_updateable($h);
push @hosts, $h; push @hosts, $h;
$ipsv4{$ipv4} = $h if ($ipv4); $ipsv4{$ipv4} = $h if ($ipv4);
@ -3566,8 +3526,8 @@ EoEXAMPLE
## Returns true if we can go ahead and update the IP address at server ## Returns true if we can go ahead and update the IP address at server
###################################################################### ######################################################################
sub nic_updateable { sub nic_updateable {
my $host = shift; my ($host) = @_;
my $sub = shift; my $force_update = $protocols{$config{$host}{protocol}}{force_update};
my $update = 0; my $update = 0;
my $ip = $config{$host}{'wantip'}; my $ip = $config{$host}{'wantip'};
my $ipv4 = $config{$host}{'wantipv4'}; my $ipv4 = $config{$host}{'wantipv4'};
@ -3747,17 +3707,12 @@ sub nic_updateable {
$update = 1; $update = 1;
} }
} elsif (defined($sub) && &$sub($host)) { } elsif (defined($force_update) && $force_update->($host)) {
$update = 1; $update = 1;
} elsif ((defined($recap{$host}{'static'}) && defined($config{$host}{'static'}) && } elsif (my @changed = grep({ my $rv = $recap{$host}{$_}; my $cv = $config{$host}{$_};
($recap{$host}{'static'} ne $config{$host}{'static'})) || defined($rv) && defined($cv) && $rv ne $cv; }
(defined($recap{$host}{'wildcard'}) && defined($config{$host}{'wildcard'}) && qw(static wildcard mx backupmx))) {
($recap{$host}{'wildcard'} ne $config{$host}{'wildcard'})) || info("$host: update forced because options changed: " . join(', ', @changed));
(defined($recap{$host}{'mx'}) && defined($config{$host}{'mx'}) &&
($recap{$host}{'mx'} ne $config{$host}{'mx'})) ||
(defined($recap{$host}{'backupmx'}) && defined($config{$host}{'backupmx'}) &&
($recap{$host}{'backupmx'} ne $config{$host}{'backupmx'}))) {
info("updating %s because host settings have been changed.", $host);
$update = 1; $update = 1;
} else { } else {
@ -3932,29 +3887,7 @@ sub nic_dyndns1_update {
} }
} }
} }
######################################################################
## nic_dyndns2_force_update
######################################################################
sub nic_dyndns2_force_update {
my $host = shift;
my $update = 0;
if ($config{$host}{'mx'} ne $recap{$host}{'mx'}) {
info("forcing updating %s because 'mx' has changed to %s.", $host, $config{$host}{'mx'});
$update = 1;
} elsif ($config{$host}{'mx'} && (ynu($config{$host}{'backupmx'}, 1, 2, 3) ne ynu($recap{$host}{'backupmx'}, 1, 2, 3))) {
info("forcing updating %s because 'backupmx' has changed to %s.", $host, ynu($config{$host}{'backupmx'}, "YES", "NO", "NO"));
$update = 1;
} elsif ($config{$host}{'static'} ne $recap{$host}{'static'}) {
info("forcing updating %s because 'static' has changed to %s.", $host, ynu($config{$host}{'static'}, "YES", "NO", "NO"));
$update = 1;
}
return $update;
}
###################################################################### ######################################################################
## nic_dyndns2_examples ## nic_dyndns2_examples
###################################################################### ######################################################################
@ -4675,30 +4608,6 @@ sub nic_zoneedit1_update {
} }
} }
######################################################################
## nic_easydns_force_update
######################################################################
sub nic_easydns_force_update {
my $host = shift;
my $update = 0;
if ($config{$host}{'mx'} ne $recap{$host}{'mx'}) {
info("forcing updating %s because 'mx' has changed to %s.", $host, $config{$host}{'mx'});
$update = 1;
} elsif ($config{$host}{'mx'} && (ynu($config{$host}{'backupmx'}, 1, 2, 3) ne ynu($config{$host}{'backupmx'}, 1, 2, 3))) {
info("forcing updating %s because 'backupmx' has changed to %s.", $host, ynu($config{$host}{'backupmx'}, "YES", "NO", "NO"));
$update = 1;
} elsif ($config{$host}{'static'} ne $recap{$host}{'static'}) {
info("forcing updating %s because 'static' has changed to %s.", $host, ynu($config{$host}{'static'}, "YES", "NO", "NO"));
$update = 1;
}
return $update;
}
###################################################################### ######################################################################
## nic_easydns_examples ## nic_easydns_examples
###################################################################### ######################################################################