Added support for multiple IP adresses. See

http://permalink.gmane.org/gmane.network.dns.ddclient.user/17


git-svn-id: svn+ssh://svn.code.sf.net/p/ddclient/code/trunk@101 3873ddee-7413-0410-b6c4-c2c57c1ab35a
This commit is contained in:
wimpunk 2008-09-30 20:49:07 +00:00
parent eb93d66237
commit c92e2d1c61
2 changed files with 279 additions and 17 deletions

View file

@ -10,6 +10,9 @@
# #
# website: http://ddclient.sf.net # website: http://ddclient.sf.net
# #
# Support for multiple IP numbers added by
# Astaro AG, Ingo Schwarze <ischwarze-OOs/4mkCeqbQT0dZR+AlfA@public.gmane.org> September 16, 2008
#
###################################################################### ######################################################################
require 5.004; require 5.004;
use strict; use strict;
@ -349,6 +352,19 @@ my %variables = (
'login' => setv(T_LOGIN, 1, 0, 1, '', undef), 'login' => setv(T_LOGIN, 1, 0, 1, '', undef),
'password' => setv(T_PASSWD, 1, 0, 1, '', undef), 'password' => setv(T_PASSWD, 1, 0, 1, '', undef),
'host' => setv(T_STRING, 1, 1, 1, '', undef), 'host' => setv(T_STRING, 1, 1, 1, '', undef),
'use' => setv(T_USE, 0, 0, 1, 'ip', undef),
'if' => setv(T_IF, 0, 0, 1, 'ppp0', undef),
'if-skip' => setv(T_STRING,0, 0, 1, '', undef),
'web' => setv(T_STRING,0, 0, 1, 'dyndns', undef),
'web-skip' => setv(T_STRING,0, 0, 1, '', undef),
'fw' => setv(T_ANY, 0, 0, 1, '', undef),
'fw-skip' => setv(T_STRING,0, 0, 1, '', undef),
'fw-login' => setv(T_LOGIN, 0, 0, 1, '', undef),
'fw-password' => setv(T_PASSWD,0, 0, 1, '', undef),
'cmd' => setv(T_PROG, 0, 0, 1, '', undef),
'cmd-skip' => setv(T_STRING,0, 0, 1, '', undef),
'ip' => setv(T_IP, 0, 1, 0, undef, undef), 'ip' => setv(T_IP, 0, 1, 0, undef, undef),
'wtime' => setv(T_DELAY, 0, 1, 1, 0, interval('30s')), 'wtime' => setv(T_DELAY, 0, 1, 1, 0, interval('30s')),
'mtime' => setv(T_NUMBER, 0, 1, 0, 0, undef), 'mtime' => setv(T_NUMBER, 0, 1, 0, 0, undef),
@ -625,7 +641,7 @@ if (opt('daemon') && !opt('force')) {
} }
umask 077; umask 077;
my ($daemon, $ip); my $daemon;
do { do {
$now = time; $now = time;
$result = 'OK'; $result = 'OK';
@ -648,19 +664,7 @@ do {
$daemon = $opt{'daemon'}; $daemon = $opt{'daemon'};
$daemon = 0 if opt('force'); $daemon = 0 if opt('force');
## obtain the IP address to use.
$ip = get_ip(opt('use'));
## a little sanity check and then update the NICs..
if (!defined $ip || !$ip) {
warning("unable to determine IP address") if !$daemon || opt('verbose');
} elsif ($ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
warning("malformed IP address (%s)", $ip);
} else {
update_nics(); update_nics();
}
if ($daemon) { if ($daemon) {
debug("sleep %s", $daemon); debug("sleep %s", $daemon);
@ -714,20 +718,34 @@ sub update_nics {
my %examined = (); my %examined = ();
foreach my $s (sort keys %services) { foreach my $s (sort keys %services) {
my @hosts = (); my (@hosts, %ips) = ();
my $updateable = $services{$s}{'updateable'}; my $updateable = $services{$s}{'updateable'};
my $update = $services{$s}{'update'}; my $update = $services{$s}{'update'};
foreach my $h (sort keys %config) { foreach my $h (sort keys %config) {
next if $config{$h}{'protocol'} ne lc($s); next if $config{$h}{'protocol'} ne lc($s);
$examined{$h} = 1; $examined{$h} = 1;
my $use = $config{$h}{'use'} || opt('use');
local $opt{$use} = $config{$h}{$use} if $config{$h}{$use};
my $ip = get_ip($use);
if (!defined $ip || !$ip) {
warning("unable to determine IP address")
if !$daemon || opt('verbose');
next;
}
if ($ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
warning("malformed IP address (%s)", $ip);
next;
}
$config{$h}{'wantip'} = $ip;
next if !nic_updateable($h, $updateable); next if !nic_updateable($h, $updateable);
push @hosts, $h; push @hosts, $h;
$ips{$ip} = $h;
} }
if (@hosts) { if (@hosts) {
$0 = sprintf("%s - updating %s", $program, join(',', @hosts)); $0 = sprintf("%s - updating %s", $program, join(',', @hosts));
&$update(@hosts); &$update(@hosts);
runpostscript($ip); runpostscript(join ' ', keys %ips);
} }
} }
foreach my $h (sort keys %config) { foreach my $h (sort keys %config) {
@ -1916,7 +1934,7 @@ sub group_hosts_by {
my %groups = (); my %groups = ();
foreach my $h (@$hosts) { foreach my $h (@$hosts) {
my @keys = @$attributes; my @keys = (@$attributes, 'wantip');
map { $config{$h}{$_} = '' unless exists $config{$h}{$_} } @keys; map { $config{$h}{$_} = '' unless exists $config{$h}{$_} } @keys;
my $sig = join(',', map { "$_=$config{$h}{$_}" } @keys); my $sig = join(',', map { "$_=$config{$h}{$_}" } @keys);
@ -1996,6 +2014,7 @@ sub nic_updateable {
my $host = shift; my $host = shift;
my $sub = shift; my $sub = shift;
my $update = 0; my $update = 0;
my $ip = $config{$host}{'wantip'};
if ($config{$host}{'login'} eq '') { if ($config{$host}{'login'} eq '') {
warning("null login name specified for host %s.", $host); warning("null login name specified for host %s.", $host);
@ -2156,6 +2175,7 @@ sub nic_dyndns1_update {
debug("\nnic_dyndns1_update -------------------"); debug("\nnic_dyndns1_update -------------------");
## update each configured host ## update each configured host
foreach my $h (@_) { foreach my $h (@_) {
my $ip = delete $config{$h}{'wantip'};
info("setting IP address to %s for %s", $ip, $h); info("setting IP address to %s for %s", $ip, $h);
verbose("UPDATE:","updating %s", $h); verbose("UPDATE:","updating %s", $h);
@ -2300,6 +2320,8 @@ sub nic_dyndns2_update {
my @hosts = @{$groups{$sig}}; my @hosts = @{$groups{$sig}};
my $hosts = join(',', @hosts); my $hosts = join(',', @hosts);
my $h = $hosts[0]; my $h = $hosts[0];
my $ip = $config{$h}{'wantip'};
delete $config{$_}{'wantip'} foreach @hosts;
info("setting IP address to %s for %s", $ip, $hosts); info("setting IP address to %s for %s", $ip, $hosts);
verbose("UPDATE:","updating %s", $hosts); verbose("UPDATE:","updating %s", $hosts);
@ -2563,6 +2585,7 @@ sub nic_concont_update {
## update each configured host ## update each configured host
foreach my $h (@_) { foreach my $h (@_) {
my $ip = delete $config{$h}{'wantip'};
info("setting IP address to %s for %s", $ip, $h); info("setting IP address to %s for %s", $ip, $h);
verbose("UPDATE:","updating %s", $h); verbose("UPDATE:","updating %s", $h);
@ -2645,6 +2668,7 @@ sub nic_dslreports1_update {
debug("\nnic_dslreports1_update -------------------"); debug("\nnic_dslreports1_update -------------------");
## update each configured host ## update each configured host
foreach my $h (@_) { foreach my $h (@_) {
my $ip = delete $config{$h}{'wantip'};
info("setting IP address to %s for %s", $ip, $h); info("setting IP address to %s for %s", $ip, $h);
verbose("UPDATE:","updating %s", $h); verbose("UPDATE:","updating %s", $h);
@ -2720,6 +2744,7 @@ sub nic_hammernode1_update {
## update each configured host ## update each configured host
foreach my $h (@_) { foreach my $h (@_) {
my $ip = delete $config{$h}{'wantip'};
info("setting IP address to %s for %s", $ip, $h); info("setting IP address to %s for %s", $ip, $h);
verbose("UPDATE:","updating %s", $h); verbose("UPDATE:","updating %s", $h);
@ -2801,6 +2826,8 @@ sub nic_zoneedit1_update {
my @hosts = @{$groups{$sig}}; my @hosts = @{$groups{$sig}};
my $hosts = join(',', @hosts); my $hosts = join(',', @hosts);
my $h = $hosts[0]; my $h = $hosts[0];
my $ip = $config{$h}{'wantip'};
delete $config{$_}{'wantip'} foreach @hosts;
info("setting IP address to %s for %s", $ip, $hosts); info("setting IP address to %s for %s", $ip, $hosts);
verbose("UPDATE:","updating %s", $hosts); verbose("UPDATE:","updating %s", $hosts);
@ -2943,6 +2970,9 @@ sub nic_easydns_update {
my @hosts = @{$groups{$sig}}; my @hosts = @{$groups{$sig}};
my $hosts = join(',', @hosts); my $hosts = join(',', @hosts);
my $h = $hosts[0]; my $h = $hosts[0];
my $ip = $config{$h}{'wantip'};
delete $config{$_}{'wantip'} foreach @hosts;
info("setting IP address to %s for %s", $ip, $hosts); info("setting IP address to %s for %s", $ip, $hosts);
verbose("UPDATE:","updating %s", $hosts); verbose("UPDATE:","updating %s", $hosts);
@ -3100,6 +3130,9 @@ sub nic_dnspark_update {
my @hosts = @{$groups{$sig}}; my @hosts = @{$groups{$sig}};
my $hosts = join(',', @hosts); my $hosts = join(',', @hosts);
my $h = $hosts[0]; my $h = $hosts[0];
my $ip = $config{$h}{'wantip'};
delete $config{$_}{'wantip'} foreach @hosts;
info("setting IP address to %s for %s", $ip, $hosts); info("setting IP address to %s for %s", $ip, $hosts);
verbose("UPDATE:","updating %s", $hosts); verbose("UPDATE:","updating %s", $hosts);
@ -3215,6 +3248,7 @@ sub nic_namecheap_update {
## update each configured host ## update each configured host
foreach my $h (@_) { foreach my $h (@_) {
my $ip = delete $config{$h}{'wantip'};
info("setting IP address to %s for %s", $ip, $h); info("setting IP address to %s for %s", $ip, $h);
verbose("UPDATE:","updating %s", $h); verbose("UPDATE:","updating %s", $h);
@ -3297,6 +3331,7 @@ sub nic_sitelutions_update {
## update each configured host ## update each configured host
foreach my $h (@_) { foreach my $h (@_) {
my $ip = delete $config{$h}{'wantip'};
info("setting IP address to %s for %s", $ip, $h); info("setting IP address to %s for %s", $ip, $h);
verbose("UPDATE:","updating %s", $h); verbose("UPDATE:","updating %s", $h);

227
patches/multiple-ip.patch Normal file
View file

@ -0,0 +1,227 @@
#
# Patch to add multiple IP support to ddclient-3.7.3
# Copyright (C) 2008 Astaro AG www.astaro.com
# Author: Ingo Schwarze <ischwarze-OOs/4mkCeqbQT0dZR+AlfA@public.gmane.org> 16.09.2008
#
# This patch is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This patch is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the ddclient program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA,
# or look up http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt .
#
Index: ddclient
===================================================================
RCS file: /home/cvs/sources/d/ddclient/ddclient,v
retrieving revision 1.1.1.2
retrieving revision 1.4.2.1
diff -u -p -r1.1.1.2 -r1.4.2.1
--- ddclient 15 Sep 2008 11:13:55 -0000 1.1.1.2
+++ ddclient 24 Sep 2008 10:06:24 -0000 1.4.2.1
@@ -10,6 +10,9 @@
#
# website: http://ddclient.sf.net
#
+# Support for multiple IP numbers added by
+# Astaro AG, Ingo Schwarze <ischwarze-OOs/4mkCeqbQT0dZR+AlfA@public.gmane.org> September 16, 2008
+#
######################################################################
require 5.004;
use strict;
@@ -349,6 +352,19 @@ my %variables = (
'login' => setv(T_LOGIN, 1, 0, 1, '', undef),
'password' => setv(T_PASSWD, 1, 0, 1, '', undef),
'host' => setv(T_STRING, 1, 1, 1, '', undef),
+
+ 'use' => setv(T_USE, 0, 0, 1, 'ip', undef),
+ 'if' => setv(T_IF, 0, 0, 1, 'ppp0', undef),
+ 'if-skip' => setv(T_STRING,0, 0, 1, '', undef),
+ 'web' => setv(T_STRING,0, 0, 1, 'dyndns', undef),
+ 'web-skip' => setv(T_STRING,0, 0, 1, '', undef),
+ 'fw' => setv(T_ANY, 0, 0, 1, '', undef),
+ 'fw-skip' => setv(T_STRING,0, 0, 1, '', undef),
+ 'fw-login' => setv(T_LOGIN, 0, 0, 1, '', undef),
+ 'fw-password' => setv(T_PASSWD,0, 0, 1, '', undef),
+ 'cmd' => setv(T_PROG, 0, 0, 1, '', undef),
+ 'cmd-skip' => setv(T_STRING,0, 0, 1, '', undef),
+
'ip' => setv(T_IP, 0, 1, 0, undef, undef),
'wtime' => setv(T_DELAY, 0, 1, 1, 0, interval('30s')),
'mtime' => setv(T_NUMBER, 0, 1, 0, 0, undef),
@@ -594,7 +610,7 @@ if (opt('daemon') && !opt('force')) {
}
umask 077;
-my ($daemon, $ip);
+my $daemon;
do {
$now = time;
$result = 'OK';
@@ -617,19 +633,7 @@ do {
$daemon = $opt{'daemon'};
$daemon = 0 if opt('force');
- ## obtain the IP address to use.
- $ip = get_ip(opt('use'));
-
- ## a little sanity check and then update the NICs..
- if (!defined $ip || !$ip) {
- warning("unable to determine IP address") if !$daemon || opt('verbose');
-
- } elsif ($ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
- warning("malformed IP address (%s)", $ip);
-
- } else {
- update_nics();
- }
+ update_nics();
if ($daemon) {
debug("sleep %s", $daemon);
@@ -683,20 +687,34 @@ sub update_nics {
my %examined = ();
foreach my $s (sort keys %services) {
- my @hosts = ();
+ my (@hosts, %ips) = ();
my $updateable = $services{$s}{'updateable'};
my $update = $services{$s}{'update'};
foreach my $h (sort keys %config) {
next if $config{$h}{'protocol'} ne lc($s);
$examined{$h} = 1;
+ my $use = $config{$h}{'use'} || opt('use');
+ local $opt{$use} = $config{$h}{$use} if $config{$h}{$use};
+ my $ip = get_ip($use);
+ if (!defined $ip || !$ip) {
+ warning("unable to determine IP address")
+ if !$daemon || opt('verbose');
+ next;
+ }
+ if ($ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
+ warning("malformed IP address (%s)", $ip);
+ next;
+ }
+ $config{$h}{'wantip'} = $ip;
next if !nic_updateable($h, $updateable);
push @hosts, $h;
+ $ips{$ip} = $h;
}
if (@hosts) {
$0 = sprintf("%s - updating %s", $program, join(',', @hosts));
&$update(@hosts);
- runpostscript($ip);
+ runpostscript(join ' ', keys %ips);
}
}
foreach my $h (sort keys %config) {
@@ -1885,7 +1903,7 @@ sub group_hosts_by {
my %groups = ();
foreach my $h (@$hosts) {
- my @keys = @$attributes;
+ my @keys = (@$attributes, 'wantip');
map { $config{$h}{$_} = '' unless exists $config{$h}{$_} } @keys;
my $sig = join(',', map { "$_=$config{$h}{$_}" } @keys);
@@ -1964,6 +1982,7 @@ sub nic_updateable {
my $host = shift;
my $sub = shift;
my $update = 0;
+ my $ip = $config{$host}{'wantip'};
if ($config{$host}{'login'} eq '') {
warning("null login name specified for host %s.", $host);
@@ -2122,6 +2141,7 @@ sub nic_dyndns1_update {
debug("\nnic_dyndns1_update -------------------");
## update each configured host
foreach my $h (@_) {
+ my $ip = delete $config{$h}{'wantip'};
info("setting IP address to %s for %s", $ip, $h);
verbose("UPDATE:","updating %s", $h);
@@ -2266,6 +2286,8 @@ sub nic_dyndns2_update {
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);
@@ -2398,6 +2420,7 @@ sub nic_concont_update {
## update each configured host
foreach my $h (@_) {
+ my $ip = delete $config{$h}{'wantip'};
info("setting IP address to %s for %s", $ip, $h);
verbose("UPDATE:","updating %s", $h);
@@ -2480,6 +2503,7 @@ sub nic_dslreports1_update {
debug("\nnic_dslreports1_update -------------------");
## update each configured host
foreach my $h (@_) {
+ my $ip = delete $config{$h}{'wantip'};
info("setting IP address to %s for %s", $ip, $h);
verbose("UPDATE:","updating %s", $h);
@@ -2555,6 +2579,7 @@ sub nic_hammernode1_update {
## update each configured host
foreach my $h (@_) {
+ my $ip = delete $config{$h}{'wantip'};
info("setting IP address to %s for %s", $ip, $h);
verbose("UPDATE:","updating %s", $h);
@@ -2636,6 +2661,8 @@ sub nic_zoneedit1_update {
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);
@@ -2778,6 +2805,9 @@ sub nic_easydns_update {
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);
@@ -2935,6 +2965,9 @@ sub nic_dnspark_update {
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);
@@ -3050,6 +3083,7 @@ sub nic_namecheap_update {
## update each configured host
foreach my $h (@_) {
+ my $ip = delete $config{$h}{'wantip'};
info("setting IP address to %s for %s", $ip, $h);
verbose("UPDATE:","updating %s", $h);
@@ -3132,6 +3166,7 @@ sub nic_sitelutions_update {
## update each configured host
foreach my $h (@_) {
+ my $ip = delete $config{$h}{'wantip'};
info("setting IP address to %s for %s", $ip, $h);
verbose("UPDATE:","updating %s", $h);