]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/scripts/setddns.pl
5 # This code is distributed under the terms of the GPL
7 # (c) The SmoothWall Team
9 # $Id: setddns.pl,v 1.4.2.32 2006/02/07 01:29:47 franck78 Exp $
20 require '/var/ipfire/general-functions.pl';
23 sub encode_base64
($;$);
26 my $filename = "${General::swroot}/ddns/config";
27 my $cachefile = "${General::swroot}/ddns/ipcache";
31 if (open(FILE
, "$filename")) {
38 &General
::log('Dynamic DNS failure : unable to open config file.');
42 &General
::readhash
("${General::swroot}/ddns/settings", \
%settings);
44 # ignore monthly update if not in minimize update mode
45 exit 0 if (($settings{'MINIMIZEUPDATES'} ne 'on') && ($ARGV[1] eq '-m'));
48 if (open(IP
, "${General::swroot}/red/local-ipaddress")) {
53 &General
::log('Dynamic DNS failure : unable to open local-ipaddress file.');
57 #If IP is reserved network, we are behind a router. May we ask for our real public IP ?
58 if ( &General
::IpInSubnet
($ip,'10.0.0.0','255.0.0.0') ||
59 &General
::IpInSubnet
($ip,'172.16.0.0','255.240.0.0') ||
60 &General
::IpInSubnet
($ip,'192.168.0.0','255.255.0.0')) {
61 # We can, but are we authorized by GUI ?
62 if ($settings{'BEHINDROUTER'} eq 'FETCH_IP') {
63 if ($ARGV[0] eq '-f'){
64 $settings{'BEHINDROUTERWAITLOOP'} = -1; # When forced option, fectch PublicIP now
67 # Increment counter modulo 4. When it is zero, fetch ip else exit
68 # This divides by 4 the requests to the dyndns server.
69 $settings{'BEHINDROUTERWAITLOOP'} = ($settings{'BEHINDROUTERWAITLOOP'}+1) %4;
70 &General
::writehash
("${General::swroot}/ddns/settings", \
%settings);
71 exit 0 if ( $settings{'BEHINDROUTERWAITLOOP'} ne 0 );
72 my $RealIP = &General
::FetchPublicIp
;
73 $ip = (&General
::validip
($RealIP) ?
$RealIP : 'unavailable');
74 &General
::log ("Dynamic DNS public router IP is:$ip");
78 if ($ARGV[0] eq '-f') {
79 unlink ($cachefile); # next regular calls will try again if this force update fails.
81 open(IPCACHE
, "$cachefile");
87 if ($ip ne $ipcache) {
93 foreach $line (@current) {
96 my @temp = split(/\,/,$line);
97 unless ($temp[7] ne "on") {
98 $settings{'SERVICE'} = $temp[0];
99 $settings{'HOSTNAME'} = $temp[1];
100 $settings{'DOMAIN'} = $temp[2];
101 $settings{'PROXY'} = $temp[3];
102 $settings{'WILDCARDS'} = $temp[4];
103 $settings{'LOGIN'} = $temp[5];
104 $settings{'PASSWORD'} = $temp[6];
105 $settings{'ENABLED'} = $temp[7];
107 #Some connection are very stable (more than 40 days). Finally force
108 #one update / month to avoid account lost
109 #cron call once/week with -f & once/month with -f -m options
111 if ( ($settings{'MINIMIZEUPDATES'} eq 'on') && ($ARGV[1] ne '-m') ) {
112 if (General
::DyndnsServiceSync
($ip, $settings{'HOSTNAME'},$settings{'DOMAIN'})) {
113 &General
::log ("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} is uptodate [$ip]");
115 next; # do not update, go to test next service
118 my @service = split(/\./, "$settings{'SERVICE'}");
119 $settings{'SERVICE'} = "$service[0]";
120 if ($settings{'SERVICE'} eq 'no-ip') {
121 open(F
, ">${General::swroot}/ddns/noipsettings");
123 print F
"PROXY=" . ($settings{'PROXY'} eq 'on' ?
"Y\n" : "N\n");
124 print F
"PASSWORD=$settings{'PASSWORD'}\n";
126 print F
"LOGIN=$settings{'LOGIN'}\n";
127 print F
"INTERVAL=1\n";
128 if ($settings{'HOSTNAME'} !~ s/$General::noipprefix//) {
129 print F
"HOSTNAME=$settings{'HOSTNAME'}\n";
132 print F
"HOSTNAME=\n";
133 print F
"GROUP=$settings{'HOSTNAME'}\n";
135 print F
"DOMAIN=$settings{'DOMAIN'}\n";
137 print F
"DAEMON=N\n";
140 my @ddnscommand = ('/usr/bin/noip','-c',"${General::swroot}/ddns/noipsettings",'-i',"$ip");
142 my $result = system(@ddnscommand);
144 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure");
146 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
151 elsif ($settings{'SERVICE'} eq 'cjb') {
154 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
155 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
156 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
157 Net
::SSLeay
::set_proxy
($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
160 my ($out, $response) = Net
::SSLeay
::get_http
( 'www.cjb.net',
162 "/cgi-bin/dynip.cgi?username=$settings{'LOGIN'}&password=$settings{'PASSWORD'}&ip=$ip",
163 Net
::SSLeay
::make_headers
('User-Agent' => 'IPFire' )
166 if ($response =~ m
%HTTP/1\
.. 200 OK
%) {
167 if ( $out !~ m/has been updated to point to/ ) {
168 &General
::log("Dynamic DNS ip-update for cjb.net ($settings{'LOGIN'}) : failure (bad password or login)");
170 &General
::log("Dynamic DNS ip-update for cjb.net ($settings{'LOGIN'}) : success");
174 &General
::log("Dynamic DNS ip-update for cjb.net ($settings{'LOGIN'}) : failure (could not connect to server)");
177 elsif ($settings{'SERVICE'} eq 'selfhost') {
180 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
181 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
182 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
183 Net
::SSLeay
::set_proxy
($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
186 my ($out, $response) = Net
::SSLeay
::get_https
( 'carol.selfhost.de',
188 "/update?username=$settings{'LOGIN'}&password=$settings{'PASSWORD'}&textmodi=1",
189 Net
::SSLeay
::make_headers
('User-Agent' => 'IPFire' )
192 if ($response =~ m
%HTTP/1\
.. 200 OK
%) {
193 if ( $out !~ m/status=(200|204)/ ) {
195 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure ($out)");
197 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
201 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure (could not connect to server)");
204 elsif ($settings{'SERVICE'} eq 'dnspark') {
207 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
208 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
209 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
210 Net
::SSLeay
::set_proxy
($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
213 if ($settings{'HOSTNAME'} eq '') {
214 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
216 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
219 my ($out, $response) = Net
::SSLeay
::get_https
( "www.dnspark.net",
221 "/api/dynamic/update.php?hostname=$settings{'HOSTDOMAIN'}&ip=$ip",
222 Net
::SSLeay
::make_headers
('User-Agent' => 'IPFire',
223 'Authorization' => 'Basic ' . encode_base64
("$settings{'LOGIN'}:$settings{'PASSWORD'}")
226 # Valid response are 'ok' 'nochange'
227 if ($response =~ m
%HTTP/1\
.. 200 OK
%) {
228 if ( $out !~ m/^(ok|nochange)/ ) {
230 &General
::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure ($out)");
232 &General
::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : success");
236 &General
::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server, check your credentials)");
239 elsif ($settings{'SERVICE'} eq 'enom') {
242 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
243 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
244 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
245 Net
::SSLeay
::set_proxy
($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
247 if ($settings{'HOSTNAME'} eq '') {
248 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
250 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
253 my ($out, $response) = Net
::SSLeay
::get_http
( 'dynamic.name-services.com',
255 "/interface.asp?Command=SetDNSHost&Zone=$settings{'DOMAIN'}&DomainPassword=$settings{'PASSWORD'}&Address=$ip",
256 Net
::SSLeay
::make_headers
('User-Agent' => 'IPFire' )
259 if ($response =~ m
%HTTP/1\
.. 200 OK
%) {
260 #Valid responses from update => ErrCount=0
261 if ( $out !~ m/ErrCount=0/ ) {
262 $out =~ s/(\n|\x0D)/ /g;
263 $out =~ /Err1=([\w ]+) /;
264 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure ($1)");
266 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
270 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure (could not connect to server)");
273 elsif ($settings{'SERVICE'} eq 'nsupdate') {
274 # Fetch UI configurable values and assemble the host name.
276 my $hostName="$settings{'DOMAIN'}";
277 if ($settings{'HOSTNAME'} ne "") {
278 $hostName="$settings{'HOSTNAME'}.$hostName";
280 my $keyName=$settings{'LOGIN'};
281 my $keySecret=$settings{'PASSWORD'};
283 # Use a relatively long TTL value to reduce load on DNS.
284 # Some public Dynamic DNS servers use values around 4 hours,
285 # some use values as low as 60 seconds.
286 # XXX Maybe we could fetch the master value from the server
287 # (not the timed-down version supplied by DNS cache)
289 my $timeToLive="3600";
291 # Internal setting that can be used to override the DNS server
292 # where the update is applied. It can be of use when testing
293 # against a private DNS server.
297 # Prepare the nsupdate command script to remove and re-add the
298 # updated A record for the domain.
300 my $cmdFile="/tmp/nsupdate-$hostName-commands";
301 my $logFile="/tmp/nsupdate-$hostName-result";
302 open(TF
, ">$cmdFile");
303 if ($masterServer ne "") {
304 print TF
"server $masterServer\n";
306 if ($keyName ne "" && $keySecret ne "") {
307 print TF
"key $keyName $keySecret\n";
309 print TF
"update delete $hostName A\n";
310 print TF
"update add $hostName $timeToLive A $ip\n";
314 # Run nsupdate with -v to use TCP instead of UDP because we're
315 # issuing multiple cmds and potentially long keys, and -d to
316 # get diagnostic result output.
318 my $result = system("/usr/bin/nsupdate -v -d $cmdFile 2>$logFile");
320 &General
::log("Dynamic DNS ip-update for $hostName : failure");
321 open(NSLOG
, "$logFile");
325 foreach $logLine (@nsLog) {
327 if ($logLine ne "") {
328 &General
::log("... $logLine");
332 &General
::log("Dynamic DNS ip-update for $hostName : success");
335 unlink $cmdFile, $logFile;
337 elsif ($settings{'SERVICE'} eq 'freedns') {
340 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
341 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
342 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
343 Net
::SSLeay
::set_proxy
($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
346 my ($out, $response) = Net
::SSLeay
::get_https
( 'freedns.afraid.org',
348 "/dynamic/update.php?$settings{'LOGIN'}",
349 Net
::SSLeay
::make_headers
('User-Agent' => 'IPFire' )
351 #Valid responses from service are:
352 #Updated n host(s) <domain>
353 #ERROR: <ip> has not changed.
354 if ($response =~ m
%HTTP/1\
.. 200 OK
%) {
355 #Valid responses from update => ErrCount=0
356 if ( $out !~ m/(^Updated|Address .* has not changed)/ig ) {
357 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure ($out)");
359 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
363 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure (could not connect to server)");
366 elsif ($settings{'SERVICE'} eq 'strato') {
369 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
370 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
371 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
372 Net
::SSLeay
::set_proxy
($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
375 if ($settings{'HOSTNAME'} eq '') {
376 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
378 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
381 my ($out, $response) = Net
::SSLeay
::get_https
( 'dyndns.strato.com',
383 "/nic/update?hostname=$settings{'HOSTDOMAIN'}&myip=$ip",
384 Net
::SSLeay
::make_headers
('User-Agent' => 'IPFire',
385 'Authorization' => 'Basic ' . encode_base64
("$settings{'LOGIN'}:$settings{'PASSWORD'}") )
388 if ($response =~ m
%HTTP/1\
.. 200 OK
%) {
389 #Valid responses from update => ErrCount=0
390 if ( $out =~ m/good |nochg /ig) {
391 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
394 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure1 ($out)");
397 } elsif ( $out =~ m/<title>(.*)<\/title
>/ig
) {
398 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure2 ($1)");
400 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure3 ($response)");
403 elsif ($settings{'SERVICE'} eq 'regfish') {
406 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
407 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
408 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
409 Net
::SSLeay
::set_proxy
($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
411 my ($out, $response) = Net
::SSLeay
::get_https
( 'dyndns.regfish.de',
413 "/?fqdn=$settings{'DOMAIN'}&ipv4=$ip&forcehost=1&authtype=secure&token=$settings{'LOGIN'}",
414 Net
::SSLeay
::make_headers
('User-Agent' => 'Ipfire' )
416 #Valid responses from service are:
417 #success|100|update succeeded!
418 #success|101|no update needed at this time..
419 if ($response =~ m
%HTTP/1\
.. 200 OK
%) {
420 if ( $out !~ m/(success\|(100|101)\|)/ig ) {
421 &General
::log("Dynamic DNS ip-update for $settings{'DOMAIN'} : failure ($out)");
423 &General
::log("Dynamic DNS ip-update for $settings{'DOMAIN'} : success");
427 &General
::log("Dynamic DNS ip-update for $settings{'DOMAIN'} : failure (could not connect to server)");
430 elsif ($settings{'SERVICE'} eq 'ovh') {
432 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
434 my $peer = 'www.ovh.com';
437 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
438 ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
442 unless($sock = new IO
::Socket
::INET
(PeerAddr
=> $peer, PeerPort
=> $peerport, Proto
=> 'tcp', Timeout
=> 5)) {
443 &General
::log("Dynamic DNS failure : could not connect to $peer:$peerport: $@");
447 if ($settings{'HOSTNAME'} eq '') {
448 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
450 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
453 my ($GET_CMD, $code64);
454 $GET_CMD = "GET http://www.ovh.com/nic/update?system=dyndns&hostname=$settings{'HOSTDOMAIN'}&myip=$ip HTTP/1.1\r\n";
455 $GET_CMD .= "Host: www.ovh.com\r\n";
456 chomp($code64 = encode_base64
("$settings{'LOGIN'}:$settings{'PASSWORD'}"));
457 $GET_CMD .= "Authorization: Basic $code64\r\n";
458 $GET_CMD .= "User-Agent: ipfire\r\n";
459 #$GET_CMD .= "Content-Type: application/x-www-form-urlencoded\r\n";
461 print $sock "$GET_CMD";
469 #HTTP response => error (in Title tag) else text response
470 #Valid responses from service:good,nochg (ez-ipupdate like)
471 #Should use ez-ipdate but "system=dyndns" is not present
472 if ( $out =~ m/<Title>(.*)<\/Title
>/ig
) {
473 &General
::log("Dynamic DNS ovh.com : failure ($1)");
475 elsif ($out !~ m/good |nochg /ig) {
476 $out =~ s/.+?\015?\012\015?\012//s; # header HTTP
477 my @out = split("\r", $out);
478 &General
::log("Dynamic DNS ip-update for $settings{'DOMAIN'} : failure ($out[1])");
480 &General
::log("Dynamic DNS ip-update for $settings{'DOMAIN'} : success");
484 elsif ($settings{'SERVICE'} eq 'dtdns') {
487 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
488 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
489 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
490 Net
::SSLeay
::set_proxy
($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
493 if ($settings{'HOSTNAME'} eq '') {
494 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
496 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
499 my ($out, $response) = Net
::SSLeay
::get_http
( 'www.dtdns.com',
501 "/api/autodns.cfm?id=$settings{'HOSTDOMAIN'}&pw=$settings{'PASSWORD'}",
502 Net
::SSLeay
::make_headers
('User-Agent' => 'IPFire' )
504 #Valid responses from service are:
507 if ($response =~ m
%HTTP/1\
.. 200 OK
%) {
508 if ( $out !~ m/Host .* now points to/ig ) {
509 &General
::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure ($out)");
511 &General
::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : success");
515 &General
::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server)");
519 elsif ($settings{'SERVICE'} eq 'namecheap') {
522 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
523 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
524 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
525 Net
::SSLeay
::set_proxy
($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
528 my ($out, $response) = Net
::SSLeay
::get_https
( 'dynamicdns.park-your-domain.com',
530 "/update?host=$settings{'HOSTNAME'}&domain=$settings{'DOMAIN'}&password=$settings{'PASSWORD'}&ip=$ip",
531 Net
::SSLeay
::make_headers
('User-Agent' => 'IPFire' )
533 #Valid responses from service are:
534 # wait confirmation!!
535 if ($response =~ m
%HTTP/1\
.. 200 OK
%) {
536 if ( $out !~ m/<ErrCount>0<\/ErrCount
>/ ) {
537 $out =~ m/<Err1>(.*)<\/Err1
>/;
538 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure ($1)");
540 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
544 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure (could not connect to server)");
548 elsif ($settings{'SERVICE'} eq 'dynu') {
551 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
552 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
553 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
554 Net
::SSLeay
::set_proxy
($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
557 if ($settings{'HOSTNAME'} eq '') {
558 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
560 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
563 my ($out, $response) = Net
::SSLeay
::get_http
( 'dynserv.ca',
565 "/dyn/dynengine.cgi?func=set&name=$settings{'LOGIN'}&pass=$settings{'PASSWORD'}&ip=$ip&domain=$settings{'DOMAIN'}",
566 Net
::SSLeay
::make_headers
('User-Agent' => 'IPFire' )
568 #Valid responses from service are:
569 # 02 == Domain already exists, refreshing data for ... => xxx.xxx.xxx.xxx
571 if ($response =~ m
%HTTP/1\
.. 200 OK
%) {
572 if ( $out !~ m/Domain already exists, refreshing data for/ig ) {
573 &General
::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure ($out)");
575 &General
::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : success");
579 &General
::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server)");
582 if ($settings{'WILDCARDS'} eq 'on') {
583 $settings{'WILDCARDS'} = '-w';
585 $settings{'WILDCARDS'} = '';
588 if (($settings{'SERVICE'} eq 'dyndns-custom' ||
589 $settings{'SERVICE'} eq 'easydns' ||
590 $settings{'SERVICE'} eq 'zoneedit') && $settings{'HOSTNAME'} eq '') {
591 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
593 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
596 my @ddnscommand = ('/usr/bin/ez-ipupdate', '-a', "$ip", '-S', "$settings{'SERVICE'}", '-u', "$settings{'LOGIN'}:$settings{'PASSWORD'}", '-h', "$settings{'HOSTDOMAIN'}", "$settings{'WILDCARDS'}", '-q');
598 my $result = system(@ddnscommand);
600 &General
::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'}: failure");
602 &General
::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'}: success");
607 # If a line is disabled, then we should discount it
612 if ($lines == $success) {
613 open(IPCACHE
, ">$cachefile");
623 # Extracted from Base64.pm
624 sub encode_base64
($;$) {
627 $eol = "\n" unless defined $eol;
628 pos($_[0]) = 0; # ensure start at the beginning
629 while ($_[0] =~ /(.{1,45})/gs) {
630 $res .= substr(pack('u', $1), 1);
633 $res =~ tr
|` -_|AA-Za-z0-9+/|; # `# help emacs
634 # fix padding at the end
635 my $padding = (3 - length($_[0]) % 3) % 3;
636 $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
637 # break encoded string into lines of no more than 76 characters each
639 $res =~ s/(.{1,76})/$1$eol/g;
647 old code
for selfhost
.de
650 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
652 my $peer = 'carol.selfhost.de';
655 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
656 ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
660 unless($sock = new IO
::Socket
::INET
(PeerAddr
=> $peer, PeerPort
=> $peerport, Proto
=> 'tcp', Timeout
=> 5)) {
661 die "Could not connect to $peer:$peerport: $@";
666 $GET_CMD = "GET https://carol.selfhost.de/update?username=$settings{'LOGIN'}&password=$settings{'PASSWORD'}&myip=$ip&textmodi=1 HTTP/1.1\r\n";
667 $GET_CMD .= "Host: carol.selfhost.de\r\n";
668 $GET_CMD .= "User-Agent: ipfire\r\n";
669 $GET_CMD .= "Connection: close\r\n\r\n";
670 print $sock "$GET_CMD";
678 if ( $out !~ m/status=(200|204)/ ) {
679 #cleanup http response...
680 $out =~ s/.+?\015?\012\015?\012//s; # header HTTP
681 my @out = split("\r", $out);
682 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure ($out[1])");
684 &General
::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");