]>
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 if ( $settings { 'SERVICE' } ne "dns.lightningwirelabs.com" ) {
119 my @service = split ( /\./ , " $settings {'SERVICE'}" );
120 $settings { 'SERVICE' } = " $service [0]" ;
122 if ( $settings { 'SERVICE' } eq 'no-ip' ) {
123 open ( F
, ">${General::swroot}/ddns/noipsettings" );
125 print F
"PROXY=" . ( $settings { 'PROXY' } eq 'on' ?
"Y \n " : "N \n " );
126 print F
"PASSWORD= $settings {'PASSWORD'} \n " ;
128 print F
"LOGIN= $settings {'LOGIN'} \n " ;
129 print F
"INTERVAL=1 \n " ;
130 if ( $settings { 'HOSTNAME' } !~ s/$General::noipprefix// ) {
131 print F
"HOSTNAME= $settings {'HOSTNAME'} \n " ;
134 print F
"HOSTNAME= \n " ;
135 print F
"GROUP= $settings {'HOSTNAME'} \n " ;
137 print F
"DOMAIN= $settings {'DOMAIN'} \n " ;
139 print F
"DAEMON=N \n " ;
142 my @ddnscommand = ( '/usr/bin/noip' , '-c' , "${General::swroot}/ddns/noipsettings" , '-i' , " $ip " );
144 my $result = system ( @ddnscommand );
146 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure" );
148 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
153 elsif ( $settings { 'SERVICE' } eq 'all-inkl' ) {
155 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
156 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
157 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
158 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
161 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( "dyndns.kasserver.com" , 443 , "/" , Net
:: SSLeay
:: make_headers
(
162 'User-Agent' => 'IPFire' , 'Authorization' => 'Basic ' . encode_base64
( " $settings {'LOGIN'}: $settings {'PASSWORD'}" )
165 # Valid response are 'ok' 'nochange'
166 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
167 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
170 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure (could not connect to server, check your credentials)" );
174 elsif ( $settings { 'SERVICE' } eq 'cjb' ) {
177 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
178 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
179 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
180 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
183 my ( $out , $response ) = Net
:: SSLeay
:: get_http
( 'www.cjb.net' ,
185 "/cgi-bin/dynip.cgi?username= $settings {'LOGIN'}&password= $settings {'PASSWORD'}&ip= $ip " ,
186 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
189 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
190 if ( $out !~ m/has been updated to point to/ ) {
191 & General
:: log ( "Dynamic DNS ip-update for cjb.net ( $settings {'LOGIN'}) : failure (bad password or login)" );
193 & General
:: log ( "Dynamic DNS ip-update for cjb.net ( $settings {'LOGIN'}) : success" );
197 & General
:: log ( "Dynamic DNS ip-update for cjb.net ( $settings {'LOGIN'}) : failure (could not connect to server)" );
200 elsif ( $settings { 'SERVICE' } eq 'selfhost' ) {
203 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
204 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
205 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
206 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
209 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( 'carol.selfhost.de' ,
211 "/update?username= $settings {'LOGIN'}&password= $settings {'PASSWORD'}&textmodi=1" ,
212 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
215 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
216 if ( $out !~ m/status=(200|204)/ ) {
218 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure ( $out )" );
220 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
224 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure (could not connect to server)" );
227 elsif ( $settings { 'SERVICE' } eq 'dnspark' ) {
230 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
231 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
232 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
233 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
236 if ( $settings { 'HOSTNAME' } eq '' ) {
237 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
239 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
242 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( "www.dnspark.net" ,
244 "/api/dynamic/update.php?hostname= $settings {'HOSTDOMAIN'}&ip= $ip " ,
245 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' ,
246 'Authorization' => 'Basic ' . encode_base64
( " $settings {'LOGIN'}: $settings {'PASSWORD'}" )
249 # Valid response are 'ok' 'nochange'
250 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
251 if ( $out !~ m/^(ok|nochange)/ ) {
253 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure ( $out )" );
255 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : success" );
259 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure (could not connect to server, check your credentials)" );
262 elsif ( $settings { 'SERVICE' } eq 'dns.lightningwirelabs.com' ) {
265 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
266 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
267 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
268 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
271 if ( $settings { 'HOSTNAME' } eq '' ) {
272 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
274 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
278 if ( $settings { 'LOGIN' } eq "token" ) {
279 $authstring = "token= $settings {'PASSWORD'}" ;
281 $authstring = "username= $settings {'LOGIN'}&password= $settings {'PASSWORD'}" ;
284 my $user_agent = & General
:: MakeUserAgent
();
285 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( "dns.lightningwirelabs.com" , 443 ,
286 "/update?hostname= $settings {'HOSTDOMAIN'}&address4= $ip & $authstring " ,
287 Net
:: SSLeay
:: make_headers
( 'User-Agent' => $user_agent )
290 # Valid response are 'ok' 'nochange'
291 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
292 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : success" );
295 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure (could not connect to server, check your credentials)" );
298 elsif ( $settings { 'SERVICE' } eq 'enom' ) {
301 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
302 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
303 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
304 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
306 if ( $settings { 'HOSTNAME' } eq '' ) {
307 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
309 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
312 my ( $out , $response ) = Net
:: SSLeay
:: get_http
( 'dynamic.name-services.com' ,
314 "/interface.asp?Command=SetDNSHost&Zone= $settings {'DOMAIN'}&DomainPassword= $settings {'PASSWORD'}&Address= $ip " ,
315 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
318 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
319 #Valid responses from update => ErrCount=0
320 if ( $out !~ m/ErrCount=0/ ) {
321 $out =~ s/(\n|\x0D)/ /g ;
322 $out =~ /Err1=([\w ]+) / ;
323 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure ( $1 )" );
325 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
329 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure (could not connect to server)" );
332 elsif ( $settings { 'SERVICE' } eq 'nsupdate' ) {
333 # Fetch UI configurable values and assemble the host name.
335 my $hostName = " $settings {'DOMAIN'}" ;
336 if ( $settings { 'HOSTNAME' } ne "" ) {
337 $hostName = " $settings {'HOSTNAME'}. $hostName " ;
339 my $keyName = $settings { 'LOGIN' };
340 my $keySecret = $settings { 'PASSWORD' };
342 # Use a relatively long TTL value to reduce load on DNS.
343 # Some public Dynamic DNS servers use values around 4 hours,
344 # some use values as low as 60 seconds.
345 # XXX Maybe we could fetch the master value from the server
346 # (not the timed-down version supplied by DNS cache)
348 my $timeToLive = "3600" ;
350 # Internal setting that can be used to override the DNS server
351 # where the update is applied. It can be of use when testing
352 # against a private DNS server.
356 # Prepare the nsupdate command script to remove and re-add the
357 # updated A record for the domain.
359 my $cmdFile = "/tmp/nsupdate- $hostName -commands" ;
360 my $logFile = "/tmp/nsupdate- $hostName -result" ;
361 open ( TF
, "> $cmdFile " );
362 if ( $masterServer ne "" ) {
363 print TF
"server $masterServer \n " ;
365 if ( $keyName ne "" && $keySecret ne "" ) {
366 print TF
"key $keyName $keySecret \n " ;
368 print TF
"update delete $hostName A \n " ;
369 print TF
"update add $hostName $timeToLive A $ip \n " ;
373 # Run nsupdate with -v to use TCP instead of UDP because we're
374 # issuing multiple cmds and potentially long keys, and -d to
375 # get diagnostic result output.
377 my $result = system ( "/usr/bin/nsupdate -v -d $cmdFile 2> $logFile " );
379 & General
:: log ( "Dynamic DNS ip-update for $hostName : failure" );
380 open ( NSLOG
, " $logFile " );
384 foreach $logLine ( @nsLog ) {
386 if ( $logLine ne "" ) {
387 & General
:: log ( "... $logLine " );
391 & General
:: log ( "Dynamic DNS ip-update for $hostName : success" );
394 unlink $cmdFile , $logFile ;
396 elsif ( $settings { 'SERVICE' } eq 'freedns' ) {
399 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
400 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
401 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
402 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
405 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( 'freedns.afraid.org' ,
407 "/dynamic/update.php? $settings {'LOGIN'}" ,
408 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
410 #Valid responses from service are:
411 #Updated n host(s) <domain>
412 #ERROR: <ip> has not changed.
413 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
414 #Valid responses from update => ErrCount=0
415 if ( $out !~ m/(^Updated|Address .* has not changed)/ig ) {
416 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure ( $out )" );
418 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
422 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure (could not connect to server)" );
425 elsif ( $settings { 'SERVICE' } eq 'strato' ) {
428 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
429 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
430 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
431 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
434 if ( $settings { 'HOSTNAME' } eq '' ) {
435 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
437 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
440 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( 'dyndns.strato.com' ,
442 "/nic/update?hostname= $settings {'HOSTDOMAIN'}&myip= $ip " ,
443 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' ,
444 'Authorization' => 'Basic ' . encode_base64
( " $settings {'LOGIN'}: $settings {'PASSWORD'}" ) )
447 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
448 #Valid responses from update => ErrCount=0
449 if ( $out =~ m/good |nochg /ig ) {
450 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
453 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure1 ( $out )" );
456 } elsif ( $out =~ m/<title>(.*)<\/ title
>/ ig
) {
457 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure2 ( $1 )" );
459 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure3 ( $response )" );
462 elsif ( $settings { 'SERVICE' } eq 'regfish' ) {
465 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
466 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
467 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
468 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
470 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( 'dyndns.regfish.de' ,
472 "/?fqdn= $settings {'DOMAIN'}&ipv4= $ip &forcehost=1&authtype=secure&token= $settings {'LOGIN'}" ,
473 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'Ipfire' )
475 #Valid responses from service are:
476 #success|100|update succeeded!
477 #success|101|no update needed at this time..
478 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
479 if ( $out !~ m/(success\|(100|101)\|)/ig ) {
480 & General
:: log ( "Dynamic DNS ip-update for $settings {'DOMAIN'} : failure ( $out )" );
482 & General
:: log ( "Dynamic DNS ip-update for $settings {'DOMAIN'} : success" );
486 & General
:: log ( "Dynamic DNS ip-update for $settings {'DOMAIN'} : failure (could not connect to server)" );
489 elsif ( $settings { 'SERVICE' } eq 'ovh' ) {
491 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
493 my $peer = 'www.ovh.com' ;
496 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
497 ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
501 unless ( $sock = new IO
:: Socket
:: INET
( PeerAddr
=> $peer , PeerPort
=> $peerport , Proto
=> 'tcp' , Timeout
=> 5 )) {
502 & General
:: log ( "Dynamic DNS failure : could not connect to $peer : $peerport : $@" );
506 if ( $settings { 'HOSTNAME' } eq '' ) {
507 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
509 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
512 my ( $GET_CMD , $code64 );
513 $GET_CMD = "GET http://www.ovh.com/nic/update?system=dyndns&hostname= $settings {'HOSTDOMAIN'}&myip= $ip HTTP/1.1 \r\n " ;
514 $GET_CMD .= "Host: www.ovh.com \r\n " ;
515 chomp ( $code64 = encode_base64
( " $settings {'LOGIN'}: $settings {'PASSWORD'}" ));
516 $GET_CMD .= "Authorization: Basic $code64 \r\n " ;
517 $GET_CMD .= "User-Agent: ipfire \r\n " ;
518 #$GET_CMD .= "Content-Type: application/x-www-form-urlencoded\r\n";
520 print $sock " $GET_CMD " ;
528 #HTTP response => error (in Title tag) else text response
529 #Valid responses from service:good,nochg (ez-ipupdate like)
530 #Should use ez-ipdate but "system=dyndns" is not present
531 if ( $out =~ m/<Title>(.*)<\/ Title
>/ ig
) {
532 & General
:: log ( "Dynamic DNS ovh.com : failure ( $1 )" );
534 elsif ( $out !~ m/good |nochg /ig ) {
535 $out =~ s/.+?\015?\012\015?\012//s ; # header HTTP
536 my @out = split ( " \r " , $out );
537 & General
:: log ( "Dynamic DNS ip-update for $settings {'DOMAIN'} : failure ( $out [1])" );
539 & General
:: log ( "Dynamic DNS ip-update for $settings {'DOMAIN'} : success" );
543 elsif ( $settings { 'SERVICE' } eq 'dtdns' ) {
546 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
547 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
548 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
549 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
552 if ( $settings { 'HOSTNAME' } eq '' ) {
553 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
555 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
558 my ( $out , $response ) = Net
:: SSLeay
:: get_http
( 'www.dtdns.com' ,
560 "/api/autodns.cfm?id= $settings {'HOSTDOMAIN'}&pw= $settings {'PASSWORD'}" ,
561 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
563 #Valid responses from service are:
566 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
567 if ( $out !~ m/Host .* now points to/ig ) {
568 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure ( $out )" );
570 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : success" );
574 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure (could not connect to server)" );
578 elsif ( $settings { 'SERVICE' } eq 'namecheap' ) {
581 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
582 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
583 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
584 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
587 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( 'dynamicdns.park-your-domain.com' ,
589 "/update?host= $settings {'HOSTNAME'}&domain= $settings {'DOMAIN'}&password= $settings {'PASSWORD'}&ip= $ip " ,
590 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
592 #Valid responses from service are:
593 # wait confirmation!!
594 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
595 if ( $out !~ m/<ErrCount>0<\/ ErrCount
>/ ) {
596 $out =~ m/<Err1>(.*)<\/ Err1
>/;
597 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure ( $1 )" );
599 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
603 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure (could not connect to server)" );
607 elsif ( $settings { 'SERVICE' } eq 'dynu' ) {
610 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
611 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
612 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
613 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
616 if ( $settings { 'HOSTNAME' } eq '' ) {
617 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
619 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
622 my ( $out , $response ) = Net
:: SSLeay
:: get_http
( 'dynserv.ca' ,
624 "/dyn/dynengine.cgi?func=set&name= $settings {'LOGIN'}&pass= $settings {'PASSWORD'}&ip= $ip &domain= $settings {'DOMAIN'}" ,
625 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
627 #Valid responses from service are:
628 # 02 == Domain already exists, refreshing data for ... => xxx.xxx.xxx.xxx
630 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
631 if ( $out !~ m/Domain already exists, refreshing data for/ig ) {
632 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure ( $out )" );
634 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : success" );
638 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure (could not connect to server)" );
641 elsif ( $settings { 'SERVICE' } eq 'udmedia.de' ) {
644 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
645 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
646 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
647 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
650 if ( $settings { 'HOSTNAME' } eq '' ) {
651 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
653 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
656 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( 'www.udmedia.de' ,
658 "/nic/update?myip= $ip &username= $settings {'HOSTDOMAIN'}&password= $settings {'PASSWORD'}" ,
659 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' ,
660 'Authorization' => 'Basic ' . encode_base64
( " $settings {'LOGIN'}: $settings {'PASSWORD'}" )) );
662 # Valid response are 'ok' 'nochange'
663 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
664 if ( $out !~ m/^(ok|nochg)/ ) {
666 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure ( $out )" );
668 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : success" );
672 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure (could not connect to server, check your credentials--- $out - $response --)" );
676 if ( $settings { 'WILDCARDS' } eq 'on' ) {
677 $settings { 'WILDCARDS' } = '-w' ;
679 $settings { 'WILDCARDS' } = '' ;
682 if (( $settings { 'SERVICE' } eq 'dyndns-custom' ||
683 $settings { 'SERVICE' } eq 'easydns' ||
684 $settings { 'SERVICE' } eq 'zoneedit' ) && $settings { 'HOSTNAME' } eq '' ) {
685 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
687 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
690 my @ddnscommand = ( '/usr/bin/ez-ipupdate' , '-a' , " $ip " , '-S' , " $settings {'SERVICE'}" , '-u' , " $settings {'LOGIN'}: $settings {'PASSWORD'}" , '-h' , " $settings {'HOSTDOMAIN'}" , " $settings {'WILDCARDS'}" , '-q' );
692 my $result = system ( @ddnscommand );
694 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'}: failure" );
696 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'}: success" );
701 # If a line is disabled, then we should discount it
706 if ( $lines == $success ) {
707 open ( IPCACHE
, "> $cachefile " );
717 # Extracted from Base64.pm
718 sub encode_base64
($;$) {
721 $eol = " \n " unless defined $eol ;
722 pos ( $_ [ 0 ]) = 0 ; # ensure start at the beginning
723 while ( $_ [ 0 ] =~ /(.{1,45})/gs ) {
724 $res .= substr ( pack ( 'u' , $1 ), 1 );
727 $res =~ tr
| ` -_|AA-Za-z0-9+/|; # ` # help emacs
728 # fix padding at the end
729 my $padding = ( 3 - length ( $_ [ 0 ]) % 3 ) % 3 ;
730 $res =~ s/.{$padding}$/'=' x $padding/e if $padding ;
731 # break encoded string into lines of no more than 76 characters each
733 $res =~ s/(.{1,76})/$1$eol/g ;
741 old code
for selfhost
. de
744 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
746 my $peer = 'carol.selfhost.de' ;
749 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
750 ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
754 unless ( $sock = new IO
:: Socket
:: INET
( PeerAddr
=> $peer , PeerPort
=> $peerport , Proto
=> 'tcp' , Timeout
=> 5 )) {
755 die "Could not connect to $peer : $peerport : $@" ;
760 $GET_CMD = "GET https://carol.selfhost.de/update?username= $settings {'LOGIN'}&password= $settings {'PASSWORD'}&myip= $ip &textmodi=1 HTTP/1.1 \r\n " ;
761 $GET_CMD .= "Host: carol.selfhost.de \r\n " ;
762 $GET_CMD .= "User-Agent: ipfire \r\n " ;
763 $GET_CMD .= "Connection: close \r\n\r\n " ;
764 print $sock " $GET_CMD " ;
772 if ( $out !~ m/status=(200|204)/ ) {
773 #cleanup http response...
774 $out =~ s/.+?\015?\012\015?\012//s ; # header HTTP
775 my @out = split ( " \r " , $out );
776 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure ( $out [1])" );
778 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );