Pull request #560: Updated GoDaddy to new IPv4/IPv6 logic
Changes by Lenard Hess based on Awalon's pull request: - Rebased to master - Removed use=disabled addition from this commit
This commit is contained in:
parent
fc4f87b33e
commit
f5a1a906d1
2 changed files with 86 additions and 70 deletions
|
@ -203,6 +203,16 @@ ssl=yes # use ssl-support. Works with
|
||||||
# ttl=10800 # optional
|
# ttl=10800 # optional
|
||||||
# myhost.example.com
|
# myhost.example.com
|
||||||
|
|
||||||
|
##
|
||||||
|
## GoDaddy (godaddy.com)
|
||||||
|
##
|
||||||
|
# protocol=godaddy, \
|
||||||
|
# password=my-godaddy-api-key, \
|
||||||
|
# password=my-godaddy-secret, \
|
||||||
|
# ttl=600 \
|
||||||
|
# zone=example.com, \
|
||||||
|
# myhost.example.com,nexthost.example.com
|
||||||
|
|
||||||
##
|
##
|
||||||
## Google Domains (www.google.com/domains)
|
## Google Domains (www.google.com/domains)
|
||||||
##
|
##
|
||||||
|
|
146
ddclient.in
146
ddclient.in
|
@ -5698,85 +5698,91 @@ sub nic_godaddy_update {
|
||||||
|
|
||||||
# Update each set configured host.
|
# Update each set configured host.
|
||||||
for my $host (@hosts) {
|
for my $host (@hosts) {
|
||||||
my $ip = delete $config{$host}{'wantip'};
|
my $ipv4 = delete $config{$host}{'wantipv4'};
|
||||||
|
my $ipv6 = delete $config{$host}{'wantipv6'};
|
||||||
|
|
||||||
my $zone = $config{$host}{'zone'};
|
my $zone = $config{$host}{'zone'};
|
||||||
(my $hostname = $host) =~ s/\.\Q$zone\E$//;
|
(my $hostname = $host) =~ s/\.\Q$zone\E$//;
|
||||||
|
|
||||||
info("%s.%s -- Setting IP address to %s.", $hostname, $zone, $ip);
|
foreach my $ip ($ipv4, $ipv6) {
|
||||||
verbose("UPDATE:", "updating %s.%s", $hostname, $zone);
|
next if (!$ip);
|
||||||
|
|
||||||
my $ipversion = is_ipv6($ip) ? "6" : "4";
|
info("%s.%s -- Setting IP address to %s.", $hostname, $zone, $ip);
|
||||||
my $rrset_type = $ipversion == "6" ? "AAAA" : "A";
|
verbose("UPDATE:", "updating %s.%s", $hostname, $zone);
|
||||||
my $data = encode_json([{
|
|
||||||
data => $ip,
|
|
||||||
defined($config{$host}{'ttl'}) ? (ttl => $config{$host}{'ttl'}) : (),
|
|
||||||
name => $hostname,
|
|
||||||
type => $rrset_type,
|
|
||||||
}]);
|
|
||||||
|
|
||||||
my $url = "https://$config{$host}{'server'}";
|
my $ipversion = ($ip eq ($ipv6 // '')) ? '6' : '4';
|
||||||
$url .= "/${zone}/records/${rrset_type}/${hostname}";
|
my $rrset_type = ($ipversion eq '6') ? 'AAAA' : 'A';
|
||||||
|
my $data = encode_json([ {
|
||||||
|
data => $ip,
|
||||||
|
defined($config{$host}{'ttl'}) ? (ttl => $config{$host}{'ttl'}) : (),
|
||||||
|
name => $hostname,
|
||||||
|
type => $rrset_type,
|
||||||
|
} ]);
|
||||||
|
|
||||||
my $header = "Content-Type: application/json\n";
|
my $url = "https://$config{$host}{'server'}";
|
||||||
$header .= "Accept: application/json\n";
|
$url .= "/${zone}/records/${rrset_type}/${hostname}";
|
||||||
$header .= "Authorization: sso-key $config{$host}{'login'}:$config{$host}{'password'}\n";
|
|
||||||
my $reply = geturl(
|
|
||||||
proxy => opt('proxy'),
|
|
||||||
url => $url,
|
|
||||||
headers => $header,
|
|
||||||
method => 'PUT',
|
|
||||||
data => $data,
|
|
||||||
);
|
|
||||||
unless ($reply) {
|
|
||||||
failed("%s.%s -- Could not connect to %s.", $hostname, $zone, $config{$host}{'server'});
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
(my $status) = ($reply =~ m%^s*HTTP/.*\s+(\d+)%i);
|
my $header = "Content-Type: application/json\n";
|
||||||
my $ok = header_ok($host, $reply);
|
$header .= "Accept: application/json\n";
|
||||||
my $msg;
|
$header .= "Authorization: sso-key $config{$host}{'login'}:$config{$host}{'password'}\n";
|
||||||
$reply =~ s/^.*?\n\n//s; # extract payload
|
my $reply = geturl(
|
||||||
my $response = eval { decode_json($reply) };
|
proxy => opt('proxy'),
|
||||||
if (!defined($response) && $status != "200") {
|
url => $url,
|
||||||
$config{$host}{'status'} = "bad";
|
headers => $header,
|
||||||
|
method => 'PUT',
|
||||||
failed("%s.%s -- Unexpected or empty service response, cannot parse data.", $hostname, $zone);
|
data => $data,
|
||||||
} elsif (defined($response->{code})) {
|
);
|
||||||
verbose("%s.%s -- %s - %s.", $hostname, $zone, $response->{code}, $response->{message});
|
unless ($reply) {
|
||||||
}
|
failed("%s.%s -- Could not connect to %s.", $hostname, $zone, $config{$host}{'server'});
|
||||||
if ($ok) {
|
next;
|
||||||
# read data
|
|
||||||
$config{$host}{'ip'} = $ip;
|
|
||||||
$config{$host}{'mtime'} = $now;
|
|
||||||
$config{$host}{'status'} = "good";
|
|
||||||
|
|
||||||
success("%s.%s -- Updated successfully to %s (status: %s).", $hostname, $zone, $ip, $status);
|
|
||||||
next;
|
|
||||||
} elsif ($status == "400") {
|
|
||||||
$msg = 'GoDaddy API URL ($url) was malformed.';
|
|
||||||
} elsif ($status == "401") { # authentication error
|
|
||||||
if ($config{$host}{'login'} && $config{$host}{'login'}) {
|
|
||||||
$msg = 'login or password option incorrect.';
|
|
||||||
} else {
|
|
||||||
$msg = 'login or password option missing.';
|
|
||||||
}
|
}
|
||||||
$msg .= ' Correct values can be obtained from from https://developer.godaddy.com/keys/.';
|
|
||||||
} elsif ($status == "403") {
|
|
||||||
$msg = 'Customer identified by login and password options denied permission.';
|
|
||||||
} elsif ($status == "404") {
|
|
||||||
$msg = "\"${hostname}.${zone}\" not found at GoDaddy, please check zone option and login/password.";
|
|
||||||
} elsif ($status == "422") {
|
|
||||||
$msg = "\"${hostname}.${zone}\" has invalid domain or lacks A/AAAA record.";
|
|
||||||
} elsif ($status == "429") {
|
|
||||||
$msg = 'Too many requests to GoDaddy within brief period.';
|
|
||||||
} elsif ($status == "503") {
|
|
||||||
$msg = "\"${hostname}.${zone}\" is unavailable.";
|
|
||||||
} else {
|
|
||||||
$msg = 'Unexpected service response.';
|
|
||||||
}
|
|
||||||
|
|
||||||
$config{$host}{'status'} = "bad";
|
(my $status) = ($reply =~ m%^s*HTTP/.*\s+(\d+)%i);
|
||||||
failed("%s.%s -- %s", $hostname, $zone, $msg);
|
my $ok = header_ok($host, $reply);
|
||||||
|
my $msg;
|
||||||
|
$reply =~ s/^.*?\n\n//s; # extract payload
|
||||||
|
my $response = eval {decode_json($reply)};
|
||||||
|
if (!defined($response) && $status != "200") {
|
||||||
|
$config{$host}{'status'} = "bad";
|
||||||
|
|
||||||
|
failed("%s.%s -- Unexpected or empty service response, cannot parse data.", $hostname, $zone);
|
||||||
|
} elsif (defined($response->{code})) {
|
||||||
|
verbose("%s.%s -- %s - %s.", $hostname, $zone, $response->{code}, $response->{message});
|
||||||
|
}
|
||||||
|
if ($ok) {
|
||||||
|
# read data
|
||||||
|
$config{$host}{"ipv$ipversion"} = $ip;
|
||||||
|
$config{$host}{'mtime'} = $now;
|
||||||
|
$config{$host}{"status-ipv$ipversion"} = 'good';
|
||||||
|
|
||||||
|
success("%s.%s -- Updated successfully to %s (status: %s).", $hostname, $zone, $ip, $status);
|
||||||
|
next;
|
||||||
|
} elsif ($status == "400") {
|
||||||
|
$msg = 'GoDaddy API URL ($url) was malformed.';
|
||||||
|
} elsif ($status == "401") { # authentication error
|
||||||
|
if ($config{$host}{'login'} && $config{$host}{'login'}) {
|
||||||
|
$msg = 'login or password option incorrect.';
|
||||||
|
} else {
|
||||||
|
$msg = 'login or password option missing.';
|
||||||
|
}
|
||||||
|
$msg .= ' Correct values can be obtained from from https://developer.godaddy.com/keys/.';
|
||||||
|
} elsif ($status == "403") {
|
||||||
|
$msg = 'Customer identified by login and password options denied permission.';
|
||||||
|
} elsif ($status == "404") {
|
||||||
|
$msg = "\"${hostname}.${zone}\" not found at GoDaddy, please check zone option and login/password.";
|
||||||
|
} elsif ($status == "422") {
|
||||||
|
$msg = "\"${hostname}.${zone}\" has invalid domain or lacks A/AAAA record.";
|
||||||
|
} elsif ($status == "429") {
|
||||||
|
$msg = 'Too many requests to GoDaddy within brief period.';
|
||||||
|
} elsif ($status == "503") {
|
||||||
|
$msg = "\"${hostname}.${zone}\" is unavailable.";
|
||||||
|
} else {
|
||||||
|
$msg = 'Unexpected service response.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$config{$host}{"status-ipv$ipversion"} = 'bad';
|
||||||
|
failed("%s.%s -- %s", $hostname, $zone, $msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue