dnsexit2: Fix when provided with a zone and a non-identical hostname

Trim the zone from the hostname in the request to fix issue.
This commit is contained in:
jortkoopmans 2024-05-27 00:42:40 +02:00 committed by Richard Hansen
parent ec2d5f7f69
commit 216741c9ce
3 changed files with 20 additions and 16 deletions

View file

@ -75,6 +75,8 @@ repository history](https://github.com/ddclient/ddclient/commits/master).
[#667](https://github.com/ddclient/ddclient/pull/667)
* Fixed unnecessary repeated updates for some services.
[#670](https://github.com/ddclient/ddclient/pull/670)
* Fixed DNSExit provider when configured with a zone and non-identical
hostname. [#673](https://github.com/ddclient/ddclient/issues/673)
## 2023-11-23 v3.11.2

View file

@ -4140,6 +4140,8 @@ o 'dnsexit2'
The 'dnsexit2' protocol is the updated protocol for the (free) dynamic hostname services
of 'DNSExit' (www.dnsexit.com). Their API is accepting JSON payload.
Note that we only update the record, it must already exist in the DNSExit system
(A and/or AAAA records where applicable).
Configuration variables applicable to the 'dnsexit2' protocol are:
protocol=dnsexit2 ##
@ -4173,10 +4175,19 @@ EoEXAMPLE
######################################################################
sub nic_dnsexit2_update {
debug("\nnic_dnsexit2_update -------------------");
# The DNSExit API does not support updating multiple hosts at a time.
# The DNSExit API does not support updating hosts with different zones at the same time,
# handling update per host.
for my $h (@_) {
$config{$h}{'zone'} //= $h;
my $name = $h;
# Remove the zone suffix from $name. If the zone eq $name, $name can be left alone or
# set to the empty string; both have identical semantics. For consistency, always
# remove the zone even if it means $name becomes the empty string.
if ($name =~ s/(?:^|\.)\Q$config{$h}{'zone'}\E$//) {
# The zone was successfully trimmed from $name.
} else {
fatal("Hostname %s does not end with the zone %s", $h, $config{$h}{'zone'});
}
# The IPv4 and IPv6 addresses must be updated together in a single API call.
my %ips;
my @updates;
@ -4186,7 +4197,7 @@ sub nic_dnsexit2_update {
info("Going to update IPv%s address to %s for %s.", $ipv, $ip, $h);
$config{$h}{"status-ipv$ipv"} = 'failed';
push(@updates, {
name => $h,
name => $name,
type => ($ipv eq '6') ? 'AAAA' : 'A',
content => $ip,
ttl => $config{$h}{'ttl'},

View file

@ -104,10 +104,7 @@ subtest 'Testing nic_dnsexit2_update' => sub {
}
]
});
TODO: {
local $TODO = "https://github.com/ddclient/ddclient/issues/673";
is_deeply($data, $expected_data, 'Data is correct');
}
reset_test_data();
};
@ -139,10 +136,7 @@ subtest 'Testing nic_dnsexit2_update without a zone set' => sub {
}
]
});
TODO: {
local $TODO = "https://github.com/ddclient/ddclient/issues/673";
is_deeply($data, $expected_data, 'Data is correct');
}
reset_test_data($ua);
};
@ -200,12 +194,9 @@ subtest 'Testing nic_dnsexit2_update with two hostnames, one with a zone and one
@requests = get_requests();
for my $i (0..1) {
my $data = decode_and_sort_array($requests[$i]->{content});
TODO: {
local $TODO = "https://github.com/ddclient/ddclient/issues/673";
is_deeply($data, $expected_data1, 'Data is correct for call host1') if $i == 0;
is_deeply($data, $expected_data2, 'Data is correct for call host2') if $i == 1;
}
}
reset_test_data();
};