Merge pull request #1 from roberthawdon/develop

Added support for Cloudflare and multi domain support for namecheap
This commit is contained in:
Robert Hawdon 2014-09-07 21:30:19 +01:00
commit 2733cf44d5
2 changed files with 4185 additions and 2 deletions

153
ddclient
View file

@ -13,6 +13,8 @@
# Support for multiple IP numbers added by # Support for multiple IP numbers added by
# Astaro AG, Ingo Schwarze <ischwarze-OOs/4mkCeqbQT0dZR+AlfA@public.gmane.org> September 16, 2008 # Astaro AG, Ingo Schwarze <ischwarze-OOs/4mkCeqbQT0dZR+AlfA@public.gmane.org> September 16, 2008
# #
# Modified to work with Cloudflare by Robert Ian Hawdon 2012-07-16: http://robertianhawdon.me.uk/
#
###################################################################### ######################################################################
require 5.004; require 5.004;
use strict; use strict;
@ -433,6 +435,13 @@ my %variables = (
'ttl' => setv(T_NUMBER, 0, 1, 0, 600, undef), 'ttl' => setv(T_NUMBER, 0, 1, 0, 600, undef),
'zone' => setv(T_STRING, 1, 1, 1, '', undef), 'zone' => setv(T_STRING, 1, 1, 1, '', undef),
}, },
'cloudflare-common-defaults' => {
'server' => setv(T_FQDNP, 1, 0, 1, 'www.cloudflare.com', undef),
'static' => setv(T_BOOL, 0, 1, 1, 0, undef),
'wildcard' => setv(T_BOOL, 0, 1, 1, 0, undef),
'mx' => setv(T_OFQDN, 0, 1, 1, '', undef),
'backupmx' => setv(T_BOOL, 0, 1, 1, 0, undef),
},
); );
my %services = ( my %services = (
'dyndns1' => { 'dyndns1' => {
@ -587,6 +596,17 @@ my %services = (
$variables{'service-common-defaults'}, $variables{'service-common-defaults'},
), ),
}, },
'cloudflare' => {
'updateable' => undef,
'update' => \&nic_cloudflare_update,
'examples' => \&nic_cloudflare_examples,
'variables' => merge(
{ 'server' => setv(T_FQDNP, 1, 0, 1, 'www.cloudflare.com', undef) },
{ 'min-interval' => setv(T_DELAY, 0, 0, 1, interval('5m'), 0),},
$variables{'cloudflare-common-defaults'},
$variables{'service-common-defaults'},
),
},
); );
$variables{'merged'} = merge($variables{'global-defaults'}, $variables{'merged'} = merge($variables{'global-defaults'},
$variables{'service-common-defaults'}, $variables{'service-common-defaults'},
@ -3411,8 +3431,11 @@ sub nic_namecheap_update {
my $url; my $url;
$url = "http://$config{$h}{'server'}/update"; $url = "http://$config{$h}{'server'}/update";
$url .= "?host=$h"; my $domain = $config{$h}{'login'};
$url .= "&domain=$config{$h}{'login'}"; my $host = $h;
$host =~ s/(.*)\.$domain(.*)/$1$2/;
$url .= "?host=$host";
$url .= "&domain=$domain";
$url .= "&password=$config{$h}{'password'}"; $url .= "&password=$config{$h}{'password'}";
$url .= "&ip="; $url .= "&ip=";
$url .= $ip if $ip; $url .= $ip if $ip;
@ -3881,6 +3904,132 @@ EoINSTR3
} }
} }
######################################################################
######################################################################
## nic_cloudflare_examples
##
## written by Ian Pye
##
## https://www.cloudflare.com/api.html?a=DIUP&u=myemail@mydomain.com&tkn=SecretPass&ip=192.168.10.4&hosts=example.com
##
######################################################################
sub nic_cloudflare_examples {
return <<EoEXAMPLE;
o 'cloudflare'
The 'cloudflare' protocol is used by DNS service offered by www.cloudflare.com.
Configuration variables applicable to the 'cloudflare' protocol are:
protocol=cloudflare ##
server=fqdn.of.service ## defaults to www.cloudflare.com
login=service-login ## login name and password registered with the service
password=service-password ##
fully.qualified.host ## the host registered with the service.
Example ${program}.conf file entries:
## single host update
protocol=cloudflare, \\
login=my-cloudflare.com-login, \\
password=my-cloudflare.com-secure-token \\
myhost.com
## multiple host update to the custom DNS service
protocol=cloudflare, \\
login=my-cloudflare.com-login, \\
password=my-cloudflare.com-secure-token \\
my-toplevel-domain.com,my-other-domain.com
EoEXAMPLE
}
######################################################################
## nic_cloudflare_update
######################################################################
sub nic_cloudflare_update {
debug("\nnic_cloudflare_update -------------------");
## group hosts with identical attributes together
my %groups = group_hosts_by([ @_ ], [ qw(ssh login password server wildcard mx backupmx) ]);
## each host is in a group by itself
##my %groups = map { $_ => [ $_ ] } @_;
my %errors = (
'E_NOUPDATE' => 'No changes made to the hostname(s). Continual updates with no changes lead to blocked clients.',
'E_NOHOST' => 'No valid FQDN (fully qualified domain name) was specified',
'E_INVLDHST'=> 'An invalid hostname was specified. This may be due to the fact the hostname has not been created in the system. Creating new host names via clients is not supported.',
'E_UNAUTH' => 'The username specified is not authorized to update this hostname and domain.',
'E_INVLDIP' => 'The IP address given is not valid.',
'E_DUPHST' => 'Duplicate values exist for a record. Only single values for records are supported currently.',
);
## update each set of hosts that had similar configurations
foreach my $sig (keys %groups) {
my @hosts = @{$groups{$sig}};
my $hosts = join(',', @hosts);
my $h = $hosts[0];
my $ip = $config{$h}{'wantip'};
delete $config{$_}{'wantip'} foreach @hosts;
info("setting IP address to %s for %s", $ip, $hosts);
verbose("UPDATE:","updating %s", $hosts);
my $url;
$url = "https://$config{$h}{'server'}/api.html?a=DIUP";
$url .= "&hosts=$hosts";
$url .= "&u=".$config{$h}{'login'};
$url .= "&tkn=".$config{$h}{'password'};
$url .= "&ip=";
$url .= "$ip" if $ip;
my $reply = geturl(opt('proxy'), $url);
if (!defined($reply) || !$reply) {
failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'});
last;
}
last if !header_ok($hosts, $reply);
my @reply = split /\n/, $reply;
my @body = ();
my $in_header = 1;
foreach my $line (@reply) {
if ($line eq "") {
$in_header = 0;
} elsif (!$in_header) {
push(@body, $line);
}
}
if ($reply =~ /E_UNAUTH/) {
failed ("%s", $errors{"E_UNAUTH"});
} elsif ($reply =~ /E_NOHOST/) {
failed ("%s", $errors{"E_NOHOST"});
} elsif ($reply =~ /E_INVLDHST/) {
failed ("%s", $errors{"E_INVLDHST"});
} elsif ($reply =~ /E_INVLDIP/) {
failed ("%s", $errors{"E_INVLDIP"});
} elsif ($reply =~ /E_DUPHST/) {
failed ("%s", $errors{"E_DUPHST"});
} else {
foreach my $line (@body) {
my @res = split / /, $line;
if ($res[1] eq "E_NOUPDATE") {
$config{$res[0]}{'ip'} = $ip;
$config{$res[0]}{'mtime'} = $now;
$config{$res[0]}{'status'} = 'good';
warning ("%s -- %s", $res[0], $errors{"E_NOUPDATE"});
} elsif ($res[1] eq "OK") {
$config{$res[0]}{'ip'} = $ip;
$config{$res[0]}{'mtime'} = $now;
$config{$res[0]}{'status'} = 'good';
success ("%s -- Updated Successfully to %s", $res[0], $ip);
}
}
}
}
}
###################################################################### ######################################################################
# vim: ai ts=4 sw=4 tw=78 : # vim: ai ts=4 sw=4 tw=78 :

4034
ddclient.orig Executable file

File diff suppressed because it is too large Load diff