Merge pull request #603 from indrajitr/noip-v4-v6

noip: Adjust script to support simultaneous IPv4 and IPv6 updates
This commit is contained in:
Lenard Hess 2024-01-14 13:59:10 +01:00 committed by GitHub
commit 95ac201b4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4286,14 +4286,21 @@ sub nic_noip_update {
my @hosts = @{$groups{$sig}}; my @hosts = @{$groups{$sig}};
my $hosts = join(',', @hosts); my $hosts = join(',', @hosts);
my $h = $hosts[0]; my $h = $hosts[0];
my $ip = $config{$h}{'wantip'}; my $ipv4 = $config{$h}{'wantipv4'};
delete $config{$_}{'wantip'} foreach @hosts; my $ipv6 = $config{$h}{'wantipv6'};
delete $config{$_}{'wantipv4'} foreach @hosts;
delete $config{$_}{'wantipv6'} foreach @hosts;
info("setting IP address to %s for %s", $ip, $hosts); info("setting IPv4 address to %s for %s", $ipv4, $hosts) if $ipv4;
info("setting IPv6 address to %s for %s", $ipv6, $hosts) if $ipv6;
verbose("UPDATE:", "updating %s", $hosts); verbose("UPDATE:", "updating %s", $hosts);
my $url = "https://$config{$h}{'server'}/nic/update?system=noip&hostname=$hosts&myip="; my $url = "https://$config{$h}{'server'}/nic/update?system=noip&hostname=$hosts&myip=";
$url .= $ip if $ip; $url .= $ipv4 if $ipv4;
if ($ipv6) {
$url .= "," if $ipv4;
$url .= $ipv6;
}
my $reply = geturl( my $reply = geturl(
proxy => opt('proxy'), proxy => opt('proxy'),
@ -4319,22 +4326,34 @@ sub nic_noip_update {
} elsif ($state =~ /^results/) { } elsif ($state =~ /^results/) {
$state = 'results2'; $state = 'results2';
my ($status, $ip) = split / /, lc $line; my ($status, $returnedips) = split / /, lc $line;
my $h = shift @hosts; my $h = shift @hosts;
$config{$h}{'status'} = $status; foreach my $ip (split_by_comma($returnedips)) {
next if (!$ip);
my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4';
$config{$h}{"status-ipv$ipv"} = $status;
}
if ($status eq 'good') { if ($status eq 'good') {
$config{$h}{'ip'} = $ip; $config{$h}{'mtime'} = $now;
$config{$h}{'mtime'} = $now; foreach my $ip (split_by_comma($returnedips)) {
success("updating %s: %s: IP address set to %s", $h, $status, $ip); next if (!$ip);
my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4';
$config{$h}{"ipv$ipv"} = $ip;
success("updating %s: %s: IPv%s address set to %s", $h, $status, $ipv, $ip);
}
} elsif (exists $errors{$status}) { } elsif (exists $errors{$status}) {
if ($status eq 'nochg') { if ($status eq 'nochg') {
warning("updating %s: %s: %s", $h, $status, $errors{$status}); warning("updating %s: %s: %s", $h, $status, $errors{$status});
$config{$h}{'ip'} = $ip; $config{$h}{'mtime'} = $now;
$config{$h}{'mtime'} = $now; foreach my $ip (split_by_comma($returnedips)) {
$config{$h}{'status'} = 'good'; next if (!$ip);
my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4';
$config{$h}{"ipv$ipv"} = $ip;
$config{$h}{"status-ipv$ipv"} = 'good';
}
} else { } else {
failed("updating %s: %s: %s", $h, $status, $errors{$status}); failed("updating %s: %s: %s", $h, $status, $errors{$status});
} }