Merge pull request #702 from rhansen/dyndns2
`dyndns2` readability improvements
This commit is contained in:
commit
9eff7404e3
1 changed files with 58 additions and 56 deletions
76
ddclient.in
76
ddclient.in
|
@ -4013,7 +4013,6 @@ EoEXAMPLE
|
||||||
######################################################################
|
######################################################################
|
||||||
sub nic_dyndns2_update {
|
sub nic_dyndns2_update {
|
||||||
debug("\nnic_dyndns2_update -------------------");
|
debug("\nnic_dyndns2_update -------------------");
|
||||||
my @groups = group_hosts_by(\@_, qw(login password server script static custom wildcard mx backupmx wantipv4 wantipv6));
|
|
||||||
my %errors = (
|
my %errors = (
|
||||||
'badauth' => 'Bad authorization (username or password)',
|
'badauth' => 'Bad authorization (username or password)',
|
||||||
'badsys' => 'The system parameter given was not valid',
|
'badsys' => 'The system parameter given was not valid',
|
||||||
|
@ -4027,7 +4026,20 @@ sub nic_dyndns2_update {
|
||||||
'dnserr' => 'System error: DNS error encountered. Contact support@dyndns.org',
|
'dnserr' => 'System error: DNS error encountered. Contact support@dyndns.org',
|
||||||
'nochg' => 'No update required; unnecessary attempts to change to the current address are considered abusive',
|
'nochg' => 'No update required; unnecessary attempts to change to the current address are considered abusive',
|
||||||
);
|
);
|
||||||
for my $group (@groups) {
|
my @group_by_attrs = qw(
|
||||||
|
backupmx
|
||||||
|
custom
|
||||||
|
login
|
||||||
|
mx
|
||||||
|
password
|
||||||
|
script
|
||||||
|
server
|
||||||
|
static
|
||||||
|
wantipv4
|
||||||
|
wantipv6
|
||||||
|
wildcard
|
||||||
|
);
|
||||||
|
for my $group (group_hosts_by(\@_, @group_by_attrs)) {
|
||||||
my @hosts = @{$group->{hosts}};
|
my @hosts = @{$group->{hosts}};
|
||||||
my %groupcfg = %{$group->{cfg}};
|
my %groupcfg = %{$group->{cfg}};
|
||||||
my $hosts = join(',', @hosts);
|
my $hosts = join(',', @hosts);
|
||||||
|
@ -4073,44 +4085,29 @@ sub nic_dyndns2_update {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
next if !header_ok($hosts, $reply);
|
next if !header_ok($hosts, $reply);
|
||||||
my @reply = split /\n/, $reply;
|
# Some services can return 200 OK even if there is an error (e.g., bad authentication,
|
||||||
my $state = 'header';
|
# updates too frequent) so the body of the response must also be checked.
|
||||||
for my $line (@reply) {
|
(my $body = $reply) =~ s/^.*?\n\n//s;
|
||||||
if ($state eq 'header') {
|
my ($line) = grep(qr/^results/, split(qr/\n/, $body));
|
||||||
$state = 'body';
|
if (!$line) {
|
||||||
} elsif ($state eq 'body') {
|
failed("updating %s: Could not connect to %s.", $hosts, $groupcfg{'server'});
|
||||||
$state = 'results' if $line eq '';
|
next;
|
||||||
} elsif ($state =~ /^results/) {
|
}
|
||||||
$state = 'results2';
|
# The IP address normally comes after the status, but we ignore it. (Some services do not
|
||||||
# bug #10: some dyndns providers does not return the IP so
|
# return the IP so we can't rely on it anyway.)
|
||||||
# we can't use the returned IP
|
(my $status = $line) =~ s/ .*$//;
|
||||||
my ($status, $returnedips) = split / /, lc $line;
|
if ($status eq 'nochg') {
|
||||||
|
warning("updating %s: %s: %s", $hosts, $status, $errors{$status});
|
||||||
|
$status = 'good';
|
||||||
|
}
|
||||||
for my $h (@hosts) {
|
for my $h (@hosts) {
|
||||||
$config{$h}{'status-ipv4'} = $status if $ipv4;
|
$config{$h}{'status-ipv4'} = $status if $ipv4;
|
||||||
$config{$h}{'status-ipv6'} = $status if $ipv6;
|
$config{$h}{'status-ipv6'} = $status if $ipv6;
|
||||||
}
|
}
|
||||||
if ($status eq 'good') {
|
if ($status ne 'good') {
|
||||||
for my $h (@hosts) {
|
if (exists($errors{$status})) {
|
||||||
$config{$h}{'ipv4'} = $ipv4 if $ipv4;
|
|
||||||
$config{$h}{'ipv6'} = $ipv6 if $ipv6;
|
|
||||||
$config{$h}{'mtime'} = $now;
|
|
||||||
}
|
|
||||||
success("updating %s: %s: IPv4 address set to %s", $hosts, $status, $ipv4) if $ipv4;
|
|
||||||
success("updating %s: %s: IPv6 address set to %s", $hosts, $status, $ipv6) if $ipv6;
|
|
||||||
} elsif (exists $errors{$status}) {
|
|
||||||
if ($status eq 'nochg') {
|
|
||||||
warning("updating %s: %s: %s", $hosts, $status, $errors{$status});
|
|
||||||
for my $h (@hosts) {
|
|
||||||
$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;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
failed("updating %s: %s: %s", $hosts, $status, $errors{$status});
|
failed("updating %s: %s: %s", $hosts, $status, $errors{$status});
|
||||||
}
|
} elsif ($status =~ qr/w(\d+)(.)/) {
|
||||||
} elsif ($status =~ /w(\d+)(.)/) {
|
|
||||||
my ($wait, $units) = ($1, lc $2);
|
my ($wait, $units) = ($1, lc $2);
|
||||||
my ($sec, $scale) = ($wait, 1);
|
my ($sec, $scale) = ($wait, 1);
|
||||||
($scale, $units) = (1, 'seconds') if $units eq 's';
|
($scale, $units) = (1, 'seconds') if $units eq 's';
|
||||||
|
@ -4124,10 +4121,15 @@ sub nic_dyndns2_update {
|
||||||
} else {
|
} else {
|
||||||
failed("updating %s: unexpected status (%s)", $hosts, $line);
|
failed("updating %s: unexpected status (%s)", $hosts, $line);
|
||||||
}
|
}
|
||||||
|
next;
|
||||||
}
|
}
|
||||||
|
for my $h (@hosts) {
|
||||||
|
$config{$h}{'ipv4'} = $ipv4 if $ipv4;
|
||||||
|
$config{$h}{'ipv6'} = $ipv6 if $ipv6;
|
||||||
|
$config{$h}{'mtime'} = $now;
|
||||||
}
|
}
|
||||||
failed("updating %s: Could not connect to %s.", $hosts, $groupcfg{'server'})
|
success("updating %s: %s: IPv4 address set to %s", $hosts, $status, $ipv4) if $ipv4;
|
||||||
if $state ne 'results2';
|
success("updating %s: %s: IPv6 address set to %s", $hosts, $status, $ipv6) if $ipv6;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue