Cloudflare: Allow updating IPv4 and IPv6 at the same time
This commit is contained in:
parent
aea03be92f
commit
763463eaf3
1 changed files with 51 additions and 46 deletions
17
ddclient
17
ddclient
|
|
@ -4906,6 +4906,7 @@ sub nic_cloudflare_update {
|
||||||
my $hosts = join(',', @hosts);
|
my $hosts = join(',', @hosts);
|
||||||
my $key = $hosts[0];
|
my $key = $hosts[0];
|
||||||
my $ip = $config{$key}{'wantip'};
|
my $ip = $config{$key}{'wantip'};
|
||||||
|
my $ipv6 = $config{$key}{'wantipv6'};
|
||||||
|
|
||||||
my $headers = "X-Auth-Email: $config{$key}{'login'}\n";
|
my $headers = "X-Auth-Email: $config{$key}{'login'}\n";
|
||||||
$headers .= "X-Auth-Key: $config{$key}{'password'}\n";
|
$headers .= "X-Auth-Key: $config{$key}{'password'}\n";
|
||||||
|
|
@ -4915,8 +4916,10 @@ sub nic_cloudflare_update {
|
||||||
for my $domain (@hosts) {
|
for my $domain (@hosts) {
|
||||||
(my $hostname = $domain) =~ s/\.$config{$key}{zone}$//;
|
(my $hostname = $domain) =~ s/\.$config{$key}{zone}$//;
|
||||||
delete $config{$domain}{'wantip'};
|
delete $config{$domain}{'wantip'};
|
||||||
|
delete $config{$domain}{'wantipv6'};
|
||||||
|
|
||||||
info("setting IP address to %s for %s", $ip, $domain);
|
info("setting IP address to %s for %s", $ip, $domain);
|
||||||
|
info("setting IPv6 address to %s for %s", $ipv6, $domain);
|
||||||
verbose("UPDATE:","updating %s", $domain);
|
verbose("UPDATE:","updating %s", $domain);
|
||||||
|
|
||||||
# Get zone ID
|
# Get zone ID
|
||||||
|
|
@ -4946,12 +4949,13 @@ sub nic_cloudflare_update {
|
||||||
}
|
}
|
||||||
info("zone ID is $zone_id");
|
info("zone ID is $zone_id");
|
||||||
|
|
||||||
|
foreach my $ip_addr ($ip, $ipv6) {
|
||||||
# Get DNS record ID
|
# Get DNS record ID
|
||||||
$url = "https://$config{$key}{'server'}/zones/$zone_id/dns_records?";
|
$url = "https://$config{$key}{'server'}/zones/$zone_id/dns_records?";
|
||||||
if (is_ipv6($ip)) {
|
if ($ip_addr eq $ip) {
|
||||||
$url .= "type=AAAA&name=$domain";
|
|
||||||
} else {
|
|
||||||
$url .= "type=A&name=$domain";
|
$url .= "type=A&name=$domain";
|
||||||
|
} elsif ($ip_addr eq $ipv6) {
|
||||||
|
$url .= "type=AAAA&name=$domain";
|
||||||
}
|
}
|
||||||
|
|
||||||
$reply = geturl(opt('proxy'), $url, undef, undef, $headers);
|
$reply = geturl(opt('proxy'), $url, undef, undef, $headers);
|
||||||
|
|
@ -4979,7 +4983,7 @@ sub nic_cloudflare_update {
|
||||||
|
|
||||||
# Set domain
|
# Set domain
|
||||||
$url = "https://$config{$key}{'server'}/zones/$zone_id/dns_records/$dns_rec_id";
|
$url = "https://$config{$key}{'server'}/zones/$zone_id/dns_records/$dns_rec_id";
|
||||||
my $data = "{\"content\":\"$ip\"}";
|
my $data = "{\"content\":\"$ip_addr\"}";
|
||||||
$reply = geturl(opt('proxy'), $url, undef, undef, $headers, "PATCH", $data);
|
$reply = geturl(opt('proxy'), $url, undef, undef, $headers, "PATCH", $data);
|
||||||
unless ($reply) {
|
unless ($reply) {
|
||||||
failed("updating %s: Could not connect to %s.", $domain, $config{$domain}{'server'});
|
failed("updating %s: Could not connect to %s.", $domain, $config{$domain}{'server'});
|
||||||
|
|
@ -4993,12 +4997,13 @@ sub nic_cloudflare_update {
|
||||||
if (!defined $response || !defined $response->{result}) {
|
if (!defined $response || !defined $response->{result}) {
|
||||||
failed ("invalid json or result.");
|
failed ("invalid json or result.");
|
||||||
} else {
|
} else {
|
||||||
success ("%s -- Updated Successfully to %s", $domain, $ip);
|
success ("%s -- Updated Successfully to %s", $domain, $ip_addr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Cache
|
# Cache
|
||||||
$config{$key}{'ip'} = $ip;
|
$config{$key}{'ip'} = $ip;
|
||||||
|
$config{$key}{'ipv6'} = $ipv6;
|
||||||
$config{$key}{'mtime'} = $now;
|
$config{$key}{'mtime'} = $now;
|
||||||
$config{$key}{'status'} = 'good';
|
$config{$key}{'status'} = 'good';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue