Merge pull request #558 from TinfoilSubmarine/fix/gandi
This commit is contained in:
commit
e0611ab192
2 changed files with 87 additions and 64 deletions
|
@ -197,10 +197,10 @@ ssl=yes # use ssl-support. Works with
|
|||
## Gandi (gandi.net)
|
||||
##
|
||||
## Single host update
|
||||
# protocol=gandi, \
|
||||
# zone=example.com, \
|
||||
# password=my-gandi-api-key, \
|
||||
# ttl=3h \
|
||||
# protocol=gandi
|
||||
# zone=example.com
|
||||
# password=my-gandi-api-key
|
||||
# ttl=10800 # optional
|
||||
# myhost.example.com
|
||||
|
||||
##
|
||||
|
|
65
ddclient.in
65
ddclient.in
|
@ -7346,20 +7346,20 @@ Available configuration variables:
|
|||
Required.
|
||||
* zone: The DNS zone to be updated. Required.
|
||||
* ttl: The time-to-live value associated with the updated DNS record.
|
||||
Optional; uses Gandi's default (3h) if unset.
|
||||
Optional; uses Gandi's default (10800) if unset.
|
||||
|
||||
Example ${program}.conf file entries:
|
||||
## Single host update.
|
||||
protocol=gandi, \\
|
||||
zone=example.com, \\
|
||||
password=my-gandi-api-key, \\
|
||||
protocol=gandi
|
||||
zone=example.com
|
||||
password=my-gandi-api-key
|
||||
host.example.com
|
||||
|
||||
## Multiple host update.
|
||||
protocol=gandi, \\
|
||||
zone=example.com, \\
|
||||
password=my-gandi-api-key, \\
|
||||
ttl=1h \\
|
||||
protocol=gandi
|
||||
zone=example.com
|
||||
password=my-gandi-api-key
|
||||
ttl=3600 # optional
|
||||
hosta.example.com,hostb.sub.example.com
|
||||
EoEXAMPLE
|
||||
}
|
||||
|
@ -7369,12 +7369,14 @@ EoEXAMPLE
|
|||
######################################################################
|
||||
sub nic_gandi_update {
|
||||
debug("\nnic_gandi_update -------------------");
|
||||
|
||||
# Update each set configured host.
|
||||
foreach my $h (@_) {
|
||||
my $ip = delete $config{$h}{'wantip'};
|
||||
foreach my $ipv ('ipv4', 'ipv6') {
|
||||
my $ip = delete $config{$h}{"want$ipv"};
|
||||
if(!$ip) {
|
||||
next;
|
||||
}
|
||||
(my $hostname = $h) =~ s/\.\Q$config{$h}{zone}\E$//;
|
||||
|
||||
info("%s -- Setting IP address to %s.", $h, $ip);
|
||||
verbose("UPDATE:", "updating %s", $h);
|
||||
|
||||
|
@ -7382,12 +7384,9 @@ sub nic_gandi_update {
|
|||
$headers = "Content-Type: application/json\n";
|
||||
$headers .= "Authorization: Apikey $config{$h}{'password'}\n";
|
||||
|
||||
my $data = encode_json({
|
||||
defined($config{$h}{'ttl'}) ? (rrset_ttl => $config{$h}{'ttl'}) : (),
|
||||
rrset_values => [$ip],
|
||||
});
|
||||
|
||||
my $rrset_type = is_ipv6($ip) ? "AAAA" : "A";
|
||||
|
||||
my $rrset_type = $ipv eq 'ipv6' ? 'AAAA' : 'A';
|
||||
my $url;
|
||||
$url = "https://$config{$h}{'server'}$config{$h}{'script'}";
|
||||
$url .= "/livedns/domains/$config{$h}{'zone'}/records/$hostname/$rrset_type";
|
||||
|
@ -7396,8 +7395,7 @@ sub nic_gandi_update {
|
|||
proxy => opt('proxy'),
|
||||
url => $url,
|
||||
headers => $headers,
|
||||
method => 'PUT',
|
||||
data => $data,
|
||||
method => 'GET'
|
||||
);
|
||||
unless ($reply) {
|
||||
failed("%s -- Could not connect to %s.", $h, $config{$h}{'server'});
|
||||
|
@ -7408,20 +7406,44 @@ sub nic_gandi_update {
|
|||
$reply =~ s/^.*?\n\n//s;
|
||||
my $response = eval { decode_json($reply) };
|
||||
if (!defined($response)) {
|
||||
$config{$h}{'status'} = "bad";
|
||||
$config{$h}{"status-$ipv"} = "bad";
|
||||
|
||||
failed("%s -- Unexpected service response.", $h);
|
||||
next;
|
||||
}
|
||||
if($response->{'rrset_values'}->[0] eq $ip && (!defined($config{$h}{'ttl'}) ||
|
||||
$response->{'rrset_ttl'} eq $config{$h}{'ttl'})) {
|
||||
$config{$h}{'ip'} = $ip;
|
||||
$config{$h}{'mtime'} = $now;
|
||||
$config{$h}{"status-$ipv"} = "good";
|
||||
success("updating %s: skipped: address was already set to %s.", $h, $ip);
|
||||
next;
|
||||
}
|
||||
|
||||
my $data = encode_json({
|
||||
defined($config{$h}{'ttl'}) ? (rrset_ttl => $config{$h}{'ttl'}) : (),
|
||||
rrset_values => [$ip],
|
||||
});
|
||||
$reply = geturl(
|
||||
proxy => opt('proxy'),
|
||||
url => $url,
|
||||
headers => $headers,
|
||||
method => 'PUT',
|
||||
data => $data,
|
||||
);
|
||||
unless ($reply) {
|
||||
failed("%s -- Could not connect to %s.", $h, $config{$h}{'server'});
|
||||
next;
|
||||
}
|
||||
$ok = header_ok($h, $reply);
|
||||
if ($ok) {
|
||||
$config{$h}{'ip'} = $ip;
|
||||
$config{$h}{'mtime'} = $now;
|
||||
$config{$h}{'status'} = "good";
|
||||
$config{$h}{"status-$ipv"} = "good";
|
||||
|
||||
success("%s -- Updated successfully to %s.", $h, $ip);
|
||||
} else {
|
||||
$config{$h}{'status'} = "bad";
|
||||
$config{$h}{"status-$ipv"} = "bad";
|
||||
|
||||
if (defined($response->{status}) && $response->{status} eq "error") {
|
||||
my @errors;
|
||||
|
@ -7434,6 +7456,7 @@ sub nic_gandi_update {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
######################################################################
|
||||
## nic_keysystems_examples
|
||||
|
|
Loading…
Reference in a new issue