duckdns: Simplify response processing

This commit is contained in:
Richard Hansen 2024-07-21 19:57:12 -04:00
parent 971e88452d
commit 91fd9e3842

View file

@ -6355,28 +6355,23 @@ sub nic_duckdns_update {
next;
}
next if !header_ok($h, $reply);
my @reply = split /\n/, $reply;
my $state = 'noresult';
my $line = '';
for $line (@reply) {
if ($line eq 'OK') {
$config{$h}{'ipv4'} = $ipv4 if $ipv4;
$config{$h}{'ipv6'} = $ipv6 if $ipv6;
$config{$h}{'mtime'} = $now;
$config{$h}{'status-ipv4'} = 'good' if $ipv4;
$config{$h}{'status-ipv6'} = 'good' if $ipv6;
$state = 'result';
success("updating %s: good: IPv4 address set to %s", $h, $ipv4) if $ipv4;
success("updating %s: good: IPv6 address set to %s", $h, $ipv6) if $ipv6;
} elsif ($line eq 'KO') {
$config{$h}{'status-ipv4'} = 'failed' if $ipv4;
$config{$h}{'status-ipv6'} = 'failed' if $ipv6;
$state = 'result';
failed("updating %s: Server said: '%s'", $h, $line);
}
}
if ($state eq 'noresult') {
failed("updating %s: Server said: '%s'", $h, $line);
(my $body = $reply) =~ s/^.*?\n\n//s or do {
failed("$h: Invalid response from server");
next;
};
chomp($body);
if ($body eq 'OK') {
$config{$h}{'ipv4'} = $ipv4 if $ipv4;
$config{$h}{'ipv6'} = $ipv6 if $ipv6;
$config{$h}{'mtime'} = $now;
$config{$h}{'status-ipv4'} = 'good' if $ipv4;
$config{$h}{'status-ipv6'} = 'good' if $ipv6;
success("updating %s: good: IPv4 address set to %s", $h, $ipv4) if $ipv4;
success("updating %s: good: IPv6 address set to %s", $h, $ipv6) if $ipv6;
} else {
$config{$h}{'status-ipv4'} = 'failed' if $ipv4;
$config{$h}{'status-ipv6'} = 'failed' if $ipv6;
failed("updating %s: Server said: '%s'", $h, $body);
}
}
}