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