]>
git.ipfire.org Git - people/stevee/ipfire-2.x.git/blob - src/scripts/setddns.pl
939e9f2549643523b4046583bba6bac17bf452cd
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' ));
47 my $ip = & General
:: GetDyndnsRedIP
();
49 if ( $ip eq "unavailable" ) {
50 & General
:: log ( "Dynamic DNS error: RED/Public IP is unavailable" );
54 & General
:: log ( "Dynamic DNS public router IP is: $ip " );
56 if ( $ARGV [ 0 ] eq '-f' ) {
57 unlink ( $cachefile ); # next regular calls will try again if this force update fails.
59 open ( IPCACHE
, " $cachefile " );
65 if ( $ip ne $ipcache ) {
71 foreach $line ( @current ) {
74 my @temp = split ( /\,/ , $line );
75 unless ( $temp [ 7 ] ne "on" ) {
76 $settings { 'SERVICE' } = $temp [ 0 ];
77 $settings { 'HOSTNAME' } = $temp [ 1 ];
78 $settings { 'DOMAIN' } = $temp [ 2 ];
79 $settings { 'PROXY' } = $temp [ 3 ];
80 $settings { 'WILDCARDS' } = $temp [ 4 ];
81 $settings { 'LOGIN' } = $temp [ 5 ];
82 $settings { 'PASSWORD' } = $temp [ 6 ];
83 $settings { 'ENABLED' } = $temp [ 7 ];
85 #Some connection are very stable (more than 40 days). Finally force
86 #one update / month to avoid account lost
87 #cron call once/week with -f & once/month with -f -m options
89 if ( ( $settings { 'MINIMIZEUPDATES' } eq 'on' ) && ( $ARGV [ 1 ] ne '-m' ) ) {
90 if ( General
:: DyndnsServiceSync
( $ip , $settings { 'HOSTNAME' }, $settings { 'DOMAIN' })) {
91 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} is uptodate [ $ip ]" );
93 next ; # do not update, go to test next service
96 if ( $settings { 'SERVICE' } ne "dns.lightningwirelabs.com" ) {
97 my @service = split ( /\./ , " $settings {'SERVICE'}" );
98 $settings { 'SERVICE' } = " $service [0]" ;
100 if ( $settings { 'SERVICE' } eq 'no-ip' ) {
101 open ( F
, ">${General::swroot}/ddns/noipsettings" );
103 print F
"PROXY=" . ( $settings { 'PROXY' } eq 'on' ?
"Y \n " : "N \n " );
104 print F
"PASSWORD= $settings {'PASSWORD'} \n " ;
106 print F
"LOGIN= $settings {'LOGIN'} \n " ;
107 print F
"INTERVAL=1 \n " ;
108 if ( $settings { 'HOSTNAME' } !~ s/$General::noipprefix// ) {
109 print F
"HOSTNAME= $settings {'HOSTNAME'} \n " ;
112 print F
"HOSTNAME= \n " ;
113 print F
"GROUP= $settings {'HOSTNAME'} \n " ;
115 print F
"DOMAIN= $settings {'DOMAIN'} \n " ;
117 print F
"DAEMON=N \n " ;
120 my @ddnscommand = ( '/usr/bin/noip' , '-c' , "${General::swroot}/ddns/noipsettings" , '-i' , " $ip " );
122 my $result = system ( @ddnscommand );
124 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure" );
126 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
131 elsif ( $settings { 'SERVICE' } eq 'all-inkl' ) {
133 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
134 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
135 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
136 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
139 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( "dyndns.kasserver.com" , 443 , "/" , Net
:: SSLeay
:: make_headers
(
140 'User-Agent' => 'IPFire' , 'Authorization' => 'Basic ' . encode_base64
( " $settings {'LOGIN'}: $settings {'PASSWORD'}" )
143 # Valid response are 'ok' 'nochange'
144 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
145 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
148 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure (could not connect to server, check your credentials)" );
152 elsif ( $settings { 'SERVICE' } eq 'cjb' ) {
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_http
( 'www.cjb.net' ,
163 "/cgi-bin/dynip.cgi?username= $settings {'LOGIN'}&password= $settings {'PASSWORD'}&ip= $ip " ,
164 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
167 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
168 if ( $out !~ m/has been updated to point to/ ) {
169 & General
:: log ( "Dynamic DNS ip-update for cjb.net ( $settings {'LOGIN'}) : failure (bad password or login)" );
171 & General
:: log ( "Dynamic DNS ip-update for cjb.net ( $settings {'LOGIN'}) : success" );
175 & General
:: log ( "Dynamic DNS ip-update for cjb.net ( $settings {'LOGIN'}) : failure (could not connect to server)" );
178 elsif ( $settings { 'SERVICE' } eq 'selfhost' ) {
181 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
182 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
183 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
184 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
187 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( 'carol.selfhost.de' ,
189 "/update?username= $settings {'LOGIN'}&password= $settings {'PASSWORD'}&textmodi=1" ,
190 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
193 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
194 if ( $out !~ m/status=(200|204)/ ) {
196 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure ( $out )" );
198 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
202 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure (could not connect to server)" );
205 elsif ( $settings { 'SERVICE' } eq 'dnspark' ) {
208 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
209 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
210 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
211 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
214 if ( $settings { 'HOSTNAME' } eq '' ) {
215 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
217 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
220 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( "www.dnspark.net" ,
222 "/api/dynamic/update.php?hostname= $settings {'HOSTDOMAIN'}&ip= $ip " ,
223 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' ,
224 'Authorization' => 'Basic ' . encode_base64
( " $settings {'LOGIN'}: $settings {'PASSWORD'}" )
227 # Valid response are 'ok' 'nochange'
228 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
229 if ( $out !~ m/^(ok|nochange)/ ) {
231 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure ( $out )" );
233 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : success" );
237 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure (could not connect to server, check your credentials)" );
240 elsif ( $settings { 'SERVICE' } eq 'dns.lightningwirelabs.com' ) {
243 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
244 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
245 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
246 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
249 if ( $settings { 'HOSTNAME' } eq '' ) {
250 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
252 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
256 if ( $settings { 'LOGIN' } eq "token" ) {
257 $authstring = "token= $settings {'PASSWORD'}" ;
259 $authstring = "username= $settings {'LOGIN'}&password= $settings {'PASSWORD'}" ;
262 my $user_agent = & General
:: MakeUserAgent
();
263 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( "dns.lightningwirelabs.com" , 443 ,
264 "/update?hostname= $settings {'HOSTDOMAIN'}&address4= $ip & $authstring " ,
265 Net
:: SSLeay
:: make_headers
( 'User-Agent' => $user_agent )
268 # Valid response are 'ok' 'nochange'
269 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
270 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : success" );
273 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure (could not connect to server, check your credentials)" );
276 elsif ( $settings { 'SERVICE' } eq 'enom' ) {
279 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
280 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
281 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
282 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
284 if ( $settings { 'HOSTNAME' } eq '' ) {
285 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
287 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
290 my ( $out , $response ) = Net
:: SSLeay
:: get_http
( 'dynamic.name-services.com' ,
292 "/interface.asp?Command=SetDNSHost&Zone= $settings {'DOMAIN'}&DomainPassword= $settings {'PASSWORD'}&Address= $ip " ,
293 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
296 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
297 #Valid responses from update => ErrCount=0
298 if ( $out !~ m/ErrCount=0/ ) {
299 $out =~ s/(\n|\x0D)/ /g ;
300 $out =~ /Err1=([\w ]+) / ;
301 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure ( $1 )" );
303 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
307 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure (could not connect to server)" );
310 elsif ( $settings { 'SERVICE' } eq 'nsupdate' ) {
311 # Fetch UI configurable values and assemble the host name.
313 my $hostName = " $settings {'DOMAIN'}" ;
314 if ( $settings { 'HOSTNAME' } ne "" ) {
315 $hostName = " $settings {'HOSTNAME'}. $hostName " ;
317 my $keyName = $settings { 'LOGIN' };
318 my $keySecret = $settings { 'PASSWORD' };
320 # Use a relatively long TTL value to reduce load on DNS.
321 # Some public Dynamic DNS servers use values around 4 hours,
322 # some use values as low as 60 seconds.
323 # XXX Maybe we could fetch the master value from the server
324 # (not the timed-down version supplied by DNS cache)
326 my $timeToLive = "3600" ;
328 # Internal setting that can be used to override the DNS server
329 # where the update is applied. It can be of use when testing
330 # against a private DNS server.
334 # Prepare the nsupdate command script to remove and re-add the
335 # updated A record for the domain.
337 my $cmdFile = "/tmp/nsupdate- $hostName -commands" ;
338 my $logFile = "/tmp/nsupdate- $hostName -result" ;
339 open ( TF
, "> $cmdFile " );
340 if ( $masterServer ne "" ) {
341 print TF
"server $masterServer \n " ;
343 if ( $keyName ne "" && $keySecret ne "" ) {
344 print TF
"key $keyName $keySecret \n " ;
346 print TF
"update delete $hostName A \n " ;
347 print TF
"update add $hostName $timeToLive A $ip \n " ;
351 # Run nsupdate with -v to use TCP instead of UDP because we're
352 # issuing multiple cmds and potentially long keys, and -d to
353 # get diagnostic result output.
355 my $result = system ( "/usr/bin/nsupdate -v -d $cmdFile 2> $logFile " );
357 & General
:: log ( "Dynamic DNS ip-update for $hostName : failure" );
358 open ( NSLOG
, " $logFile " );
362 foreach $logLine ( @nsLog ) {
364 if ( $logLine ne "" ) {
365 & General
:: log ( "... $logLine " );
369 & General
:: log ( "Dynamic DNS ip-update for $hostName : success" );
372 unlink $cmdFile , $logFile ;
374 elsif ( $settings { 'SERVICE' } eq 'freedns' ) {
377 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
378 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
379 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
380 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
383 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( 'freedns.afraid.org' ,
385 "/dynamic/update.php? $settings {'LOGIN'}" ,
386 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
388 #Valid responses from service are:
389 #Updated n host(s) <domain>
390 #ERROR: <ip> has not changed.
391 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
392 #Valid responses from update => ErrCount=0
393 if ( $out !~ m/(^Updated|Address .* has not changed)/ig ) {
394 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure ( $out )" );
396 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
400 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure (could not connect to server)" );
403 elsif ( $settings { 'SERVICE' } eq 'strato' ) {
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' } );
412 if ( $settings { 'HOSTNAME' } eq '' ) {
413 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
415 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
418 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( 'dyndns.strato.com' ,
420 "/nic/update?hostname= $settings {'HOSTDOMAIN'}&myip= $ip " ,
421 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' ,
422 'Authorization' => 'Basic ' . encode_base64
( " $settings {'LOGIN'}: $settings {'PASSWORD'}" ) )
425 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
426 #Valid responses from update => ErrCount=0
427 if ( $out =~ m/good |nochg /ig ) {
428 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
431 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure1 ( $out )" );
434 } elsif ( $out =~ m/<title>(.*)<\/ title
>/ ig
) {
435 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure2 ( $1 )" );
437 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure3 ( $response )" );
440 elsif ( $settings { 'SERVICE' } eq 'regfish' ) {
443 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
444 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
445 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
446 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
448 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( 'dyndns.regfish.de' ,
450 "/?fqdn= $settings {'DOMAIN'}&ipv4= $ip &forcehost=1&authtype=secure&token= $settings {'LOGIN'}" ,
451 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'Ipfire' )
453 #Valid responses from service are:
454 #success|100|update succeeded!
455 #success|101|no update needed at this time..
456 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
457 if ( $out !~ m/(success\|(100|101)\|)/ig ) {
458 & General
:: log ( "Dynamic DNS ip-update for $settings {'DOMAIN'} : failure ( $out )" );
460 & General
:: log ( "Dynamic DNS ip-update for $settings {'DOMAIN'} : success" );
464 & General
:: log ( "Dynamic DNS ip-update for $settings {'DOMAIN'} : failure (could not connect to server)" );
467 elsif ( $settings { 'SERVICE' } eq 'ovh' ) {
469 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
471 my $peer = 'www.ovh.com' ;
474 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
475 ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
479 unless ( $sock = new IO
:: Socket
:: INET
( PeerAddr
=> $peer , PeerPort
=> $peerport , Proto
=> 'tcp' , Timeout
=> 5 )) {
480 & General
:: log ( "Dynamic DNS failure : could not connect to $peer : $peerport : $@" );
484 if ( $settings { 'HOSTNAME' } eq '' ) {
485 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
487 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
490 my ( $GET_CMD , $code64 );
491 $GET_CMD = "GET http://www.ovh.com/nic/update?system=dyndns&hostname= $settings {'HOSTDOMAIN'}&myip= $ip HTTP/1.1 \r\n " ;
492 $GET_CMD .= "Host: www.ovh.com \r\n " ;
493 chomp ( $code64 = encode_base64
( " $settings {'LOGIN'}: $settings {'PASSWORD'}" ));
494 $GET_CMD .= "Authorization: Basic $code64 \r\n " ;
495 $GET_CMD .= "User-Agent: ipfire \r\n " ;
496 #$GET_CMD .= "Content-Type: application/x-www-form-urlencoded\r\n";
498 print $sock " $GET_CMD " ;
506 #HTTP response => error (in Title tag) else text response
507 #Valid responses from service:good,nochg (ez-ipupdate like)
508 #Should use ez-ipdate but "system=dyndns" is not present
509 if ( $out =~ m/<Title>(.*)<\/ Title
>/ ig
) {
510 & General
:: log ( "Dynamic DNS ovh.com : failure ( $1 )" );
512 elsif ( $out !~ m/good |nochg /ig ) {
513 $out =~ s/.+?\015?\012\015?\012//s ; # header HTTP
514 my @out = split ( " \r " , $out );
515 & General
:: log ( "Dynamic DNS ip-update for $settings {'DOMAIN'} : failure ( $out [1])" );
517 & General
:: log ( "Dynamic DNS ip-update for $settings {'DOMAIN'} : success" );
521 elsif ( $settings { 'SERVICE' } eq 'dtdns' ) {
524 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
525 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
526 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
527 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
530 if ( $settings { 'HOSTNAME' } eq '' ) {
531 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
533 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
536 my ( $out , $response ) = Net
:: SSLeay
:: get_http
( 'www.dtdns.com' ,
538 "/api/autodns.cfm?id= $settings {'HOSTDOMAIN'}&pw= $settings {'PASSWORD'}" ,
539 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
541 #Valid responses from service are:
544 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
545 if ( $out !~ m/Host .* now points to/ig ) {
546 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure ( $out )" );
548 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : success" );
552 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure (could not connect to server)" );
556 elsif ( $settings { 'SERVICE' } eq 'namecheap' ) {
559 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
560 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
561 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
562 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
565 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( 'dynamicdns.park-your-domain.com' ,
567 "/update?host= $settings {'HOSTNAME'}&domain= $settings {'DOMAIN'}&password= $settings {'PASSWORD'}&ip= $ip " ,
568 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
570 #Valid responses from service are:
571 # wait confirmation!!
572 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
573 if ( $out !~ m/<ErrCount>0<\/ ErrCount
>/ ) {
574 $out =~ m/<Err1>(.*)<\/ Err1
>/;
575 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure ( $1 )" );
577 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );
581 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure (could not connect to server)" );
585 elsif ( $settings { 'SERVICE' } eq 'dynu' ) {
588 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
589 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
590 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
591 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
594 if ( $settings { 'HOSTNAME' } eq '' ) {
595 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
597 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
600 my ( $out , $response ) = Net
:: SSLeay
:: get_http
( 'dynserv.ca' ,
602 "/dyn/dynengine.cgi?func=set&name= $settings {'LOGIN'}&pass= $settings {'PASSWORD'}&ip= $ip &domain= $settings {'DOMAIN'}" ,
603 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' )
605 #Valid responses from service are:
606 # 02 == Domain already exists, refreshing data for ... => xxx.xxx.xxx.xxx
608 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
609 if ( $out !~ m/Domain already exists, refreshing data for/ig ) {
610 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure ( $out )" );
612 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : success" );
616 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure (could not connect to server)" );
619 elsif ( $settings { 'SERVICE' } eq 'udmedia.de' ) {
622 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
623 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
624 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
625 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
628 if ( $settings { 'HOSTNAME' } eq '' ) {
629 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
631 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
634 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( 'www.udmedia.de' ,
636 "/nic/update?myip= $ip &username= $settings {'HOSTDOMAIN'}&password= $settings {'PASSWORD'}" ,
637 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' ,
638 'Authorization' => 'Basic ' . encode_base64
( " $settings {'LOGIN'}: $settings {'PASSWORD'}" )) );
640 # Valid response are 'ok' 'nochange'
641 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
642 if ( $out !~ m/^(ok|nochg)/ ) {
644 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure ( $out )" );
646 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : success" );
650 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure (could not connect to server, check your credentials--- $out - $response --)" );
653 elsif ( $settings { 'SERVICE' } eq 'twodns.de' ) {
656 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
657 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
658 my ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
659 Net
:: SSLeay
:: set_proxy
( $peer , $peerport , $proxysettings { 'UPSTREAM_USER' }, $proxysettings { 'UPSTREAM_PASSWORD' } );
662 if ( $settings { 'HOSTNAME' } eq '' ) {
663 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
665 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
668 my ( $out , $response ) = Net
:: SSLeay
:: get_https
( 'update.twodns.de' ,
670 "/update?hostname= $settings {'HOSTDOMAIN'}&ip= $ip " ,
671 Net
:: SSLeay
:: make_headers
( 'User-Agent' => 'IPFire' ,
672 'Authorization' => 'Basic ' . encode_base64
( " $settings {'LOGIN'}: $settings {'PASSWORD'}" )) );
674 # Valid response are 'ok' 'nochange'
675 if ( $response =~ m
%HTTP / 1 \
.. 200 OK
%) {
676 if ( $out !~ m/^(good|nochg)/ ) {
678 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure ( $out )" );
680 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : success" );
684 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'} : failure (could not connect to server, check your credentials--- $out - $response --)" );
688 if ( $settings { 'WILDCARDS' } eq 'on' ) {
689 $settings { 'WILDCARDS' } = '-w' ;
691 $settings { 'WILDCARDS' } = '' ;
694 if (( $settings { 'SERVICE' } eq 'dyndns-custom' ||
695 $settings { 'SERVICE' } eq 'easydns' ||
696 $settings { 'SERVICE' } eq 'zoneedit' ) && $settings { 'HOSTNAME' } eq '' ) {
697 $settings { 'HOSTDOMAIN' } = $settings { 'DOMAIN' };
699 $settings { 'HOSTDOMAIN' } = " $settings {'HOSTNAME'}. $settings {'DOMAIN'}" ;
702 my @ddnscommand = ( '/usr/bin/ez-ipupdate' , '-a' , " $ip " , '-S' , " $settings {'SERVICE'}" , '-u' , " $settings {'LOGIN'}: $settings {'PASSWORD'}" , '-h' , " $settings {'HOSTDOMAIN'}" , " $settings {'WILDCARDS'}" , '-q' );
704 my $result = system ( @ddnscommand );
706 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'}: failure" );
708 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTDOMAIN'}: success" );
713 # If a line is disabled, then we should discount it
718 if ( $lines == $success ) {
719 open ( IPCACHE
, "> $cachefile " );
729 # Extracted from Base64.pm
730 sub encode_base64
($;$) {
733 $eol = " \n " unless defined $eol ;
734 pos ( $_ [ 0 ]) = 0 ; # ensure start at the beginning
735 while ( $_ [ 0 ] =~ /(.{1,45})/gs ) {
736 $res .= substr ( pack ( 'u' , $1 ), 1 );
739 $res =~ tr
| ` -_|AA-Za-z0-9+/|; # ` # help emacs
740 # fix padding at the end
741 my $padding = ( 3 - length ( $_ [ 0 ]) % 3 ) % 3 ;
742 $res =~ s/.{$padding}$/'=' x $padding/e if $padding ;
743 # break encoded string into lines of no more than 76 characters each
745 $res =~ s/(.{1,76})/$1$eol/g ;
753 old code
for selfhost
. de
756 & General
:: readhash
( "${General::swroot}/proxy/settings" , \
%proxysettings );
758 my $peer = 'carol.selfhost.de' ;
761 if ( $_ = $proxysettings { 'UPSTREAM_PROXY' }) {
762 ( $peer , $peerport ) = ( /^(?:[a-zA-Z ]+\:\/ \
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/ .* ?
) ?
$/);
766 unless ( $sock = new IO
:: Socket
:: INET
( PeerAddr
=> $peer , PeerPort
=> $peerport , Proto
=> 'tcp' , Timeout
=> 5 )) {
767 die "Could not connect to $peer : $peerport : $@" ;
772 $GET_CMD = "GET https://carol.selfhost.de/update?username= $settings {'LOGIN'}&password= $settings {'PASSWORD'}&myip= $ip &textmodi=1 HTTP/1.1 \r\n " ;
773 $GET_CMD .= "Host: carol.selfhost.de \r\n " ;
774 $GET_CMD .= "User-Agent: ipfire \r\n " ;
775 $GET_CMD .= "Connection: close \r\n\r\n " ;
776 print $sock " $GET_CMD " ;
784 if ( $out !~ m/status=(200|204)/ ) {
785 #cleanup http response...
786 $out =~ s/.+?\015?\012\015?\012//s ; # header HTTP
787 my @out = split ( " \r " , $out );
788 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : failure ( $out [1])" );
790 & General
:: log ( "Dynamic DNS ip-update for $settings {'HOSTNAME'}. $settings {'DOMAIN'} : success" );