From 0a245f8c9b773a1a78c779ddc12d787eaad68123 Mon Sep 17 00:00:00 2001 From: wimpunk Date: Mon, 2 Jun 2014 19:51:10 +0000 Subject: [PATCH] Adding support for nsupdate. Patch provided by Daniel Roethlisberger through github. git-svn-id: svn+ssh://svn.code.sf.net/p/ddclient/code/trunk@163 3873ddee-7413-0410-b6c4-c2c57c1ab35a --- README.md | 1 + ddclient | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) diff --git a/README.md b/README.md index bfc0b4c..abd5a20 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Dynamic DNS services currently supported include: Freedns - See http://freedns.afraid.org/ for details ChangeIP - See http://www.changeip.com/ for details dtdns - See http://www.dtdns.com/ for details + nsupdate - See nsupdate(1) and ddns-confgen(8) for details DDclient now supports many of cable/dsl broadband routers. diff --git a/ddclient b/ddclient index 5ff01cf..9a4a2f1 100755 --- a/ddclient +++ b/ddclient @@ -429,6 +429,10 @@ my %variables = ( 'login' => setv(T_LOGIN, 0, 0, 0, 'unused', undef), 'client' => setv(T_STRING, 0, 1, 1, $program, undef), }, + 'nsupdate-common-defaults' => { + 'ttl' => setv(T_NUMBER, 0, 1, 0, 600, undef), + 'zone' => setv(T_STRING, 1, 1, 1, '', undef), + }, ); my %services = ( 'dyndns1' => { @@ -573,6 +577,16 @@ my %services = ( $variables{'service-common-defaults'}, ), }, + 'nsupdate' => { + 'updateable' => undef, + 'update' => \&nic_nsupdate_update, + 'examples' => \&nic_nsupdate_examples, + 'variables' => merge( + { 'login' => setv(T_LOGIN, 1, 0, 1, '/usr/bin/nsupdate', undef), }, + $variables{'nsupdate-common-defaults'}, + $variables{'service-common-defaults'}, + ), + }, ); $variables{'merged'} = merge($variables{'global-defaults'}, $variables{'service-common-defaults'}, @@ -3765,6 +3779,108 @@ sub nic_dtdns_update { } } +###################################################################### +## nic_nsupdate_examples +###################################################################### +sub nic_nsupdate_examples { + return < ## fully qualified hostname to update + +Example ${program}.conf file entries: + ## single host update + protocol=nsupdate \\ + server=ns1.example.com \\ + password=/etc/${program}/dyn.example.com.key \\ + zone=dyn.example.com \\ + ttl=3600 \\ + myhost.dyn.example.com + +EoEXAMPLE +} + +###################################################################### +## nic_nsupdate_update +## by Daniel Roethlisberger +###################################################################### +sub nic_nsupdate_update { + debug("\nnic_nsupdate_update -------------------"); + + ## group hosts with identical attributes together + my %groups = group_hosts_by([ @_ ], [ qw(login password server zone) ]); + + ## 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 $binary = $config{$h}{'login'}; + my $keyfile = $config{$h}{'password'}; + my $server = $config{$h}{'server'}; + my $zone = $config{$h}{'zone'}; + 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); + + ## send separate requests for each zone with all hosts in that zone + my $instructions = <