]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - src/scripts/setddns.pl
DDNS: Fix API call for the "Dynu" DDNS service
[people/teissler/ipfire-2.x.git] / src / scripts / setddns.pl
index 12c0f1df5f19853160f5c212bb91c15cd8889ec1..5a195650c691c34d14dd7625bd01077d4751457c 100644 (file)
@@ -44,37 +44,15 @@ if (open(FILE, "$filename")) {
 # ignore monthly update if not in minimize update mode
 exit 0 if (($settings{'MINIMIZEUPDATES'} ne 'on') && ($ARGV[1] eq '-m'));
 
-my $ip;
-if (open(IP, "${General::swroot}/red/local-ipaddress")) {
-    $ip = <IP>;
-    close(IP);
-    chomp $ip;
-} else {
-    &General::log('Dynamic DNS failure : unable to open local-ipaddress file.');
-    exit 0;
-}
-
-#If IP is reserved network, we are behind a router. May we ask for our real public IP ?
-if ( &General::IpInSubnet ($ip,'10.0.0.0','255.0.0.0') ||
-     &General::IpInSubnet ($ip,'172.16.0.0','255.240.0.0') ||
-     &General::IpInSubnet ($ip,'192.168.0.0','255.255.0.0')) {
-    # We can, but are we authorized by GUI ?
-    if ($settings{'BEHINDROUTER'} eq 'FETCH_IP') {
-       if ($ARGV[0] eq '-f'){
-           $settings{'BEHINDROUTERWAITLOOP'} = -1; # When forced option, fectch PublicIP now
-       }
+my $ip = &General::GetDyndnsRedIP();
 
-       # Increment counter modulo 4. When it is zero, fetch ip else exit
-       # This divides by 4 the requests to the dyndns server.
-       $settings{'BEHINDROUTERWAITLOOP'} = ($settings{'BEHINDROUTERWAITLOOP'}+1) %4;
-       &General::writehash("${General::swroot}/ddns/settings", \%settings);
-       exit 0 if ( $settings{'BEHINDROUTERWAITLOOP'} ne 0 );
-       my $RealIP = &General::FetchPublicIp;
-       $ip = (&General::validip ($RealIP) ?  $RealIP : 'unavailable');
-       &General::log ("Dynamic DNS public router IP is:$ip");
-    }
+if ($ip eq "unavailable") {
+       &General::log("Dynamic DNS error: RED/Public IP is unavailable");
+       exit(0);
 }
 
+#&General::log("Dynamic DNS public router IP is: $ip");
+
 if ($ARGV[0] eq '-f') {
        unlink ($cachefile);    # next regular calls will try again if this force update fails.
 } else {
@@ -422,6 +400,41 @@ if ($ip ne $ipcache) {
                                &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure (could not connect to server)");
                            }
                        }
+                        elsif ($settings{'SERVICE'} eq 'spdns.de') {
+                            # use proxy ?
+                            my %proxysettings;
+                            &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
+                            if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
+                                my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
+                                Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
+                            }
+                            
+                            if ($settings{'HOSTNAME'} eq '') {
+                                $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
+                            } else {
+                                $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
+                            }
+                            
+                            my ($out, $response) = Net::SSLeay::get_https( 'update.spdns.de', 443,
+                                                                            "/nic/update?&hostname=$settings{'HOSTDOMAIN'}&myip=$ip",
+                                                                            Net::SSLeay::make_headers('User-Agent' => 'IPFire' ,
+                                                                                                      'Authorization' => 'Basic ' . encode_base64("$settings{'LOGIN'}:$settings{'PASSWORD'}"))
+                                                                         );
+                            
+                            #Valid responses from service are:
+                            # good xxx.xxx.xxx.xxx
+                            # nochg  xxx.xxx.xxx.xxx
+                            if ($response =~ m%HTTP/1\.. 200 OK%) {
+                                if ($out !~ m/good |nochg /ig) {
+                                    &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure ($out)");
+                                } else {
+                                    &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : success");
+                                    $success++;
+                                }
+                            } else {
+                                &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server)");
+                            }
+                        }
                        elsif ($settings{'SERVICE'} eq 'strato') {
                                # use proxy ?
                                my %proxysettings;
@@ -619,26 +632,25 @@ if ($ip ne $ipcache) {
                                $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
                            }
 
-                           my ($out, $response) = Net::SSLeay::get_http(  'dynserv.ca',
-                                                                           80,
-                                                                           "/dyn/dynengine.cgi?func=set&name=$settings{'LOGIN'}&pass=$settings{'PASSWORD'}&ip=$ip&domain=$settings{'DOMAIN'}",
+                           my ($out, $response) = Net::SSLeay::get_https( 'api.dynu.com',
+                                                                           443,
+                                                                           "/nic/update?hostname=$settings{'HOSTDOMAIN'}&myip=$ip&username=$settings{'LOGIN'}&password=$settings{'PASSWORD'}",
                                                                            Net::SSLeay::make_headers('User-Agent' => 'IPFire' )
                                                                         );
-                           #Valid responses from service are:
-                           # 02 == Domain already exists, refreshing data for ... => xxx.xxx.xxx.xxx
-                           #
+                           # Valid responses are 'good xxx.xxx.xxx.xxx', 'nochg'
+                           # see http://www.dynu.com/Default.aspx?page=dnsapi for further details
                            if ($response =~ m%HTTP/1\.. 200 OK%) {
-                               if ( $out !~ m/Domain already exists, refreshing data for/ig ) {
+                               if ( $out !~ m/^(good|nochg)/ ) {
                                    &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure ($out)");
                                } else {
-                                   &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : success");
+                                   &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : success ($out)");
                                    $success++;
                                }
                            } else {
-                               &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server)");
+                               &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server---$out-$response)");
                            }
                        }
-                       elsif ($settings{'SERVICE'} eq 'udmedia.de') {
+                       elsif ($settings{'SERVICE'} eq 'udmedia') {
                            # use proxy ?
                            my %proxysettings;
                            &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
@@ -672,6 +684,73 @@ if ($ip ne $ipcache) {
                                &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server, check your credentials---$out-$response--)");
                            }
                        }
+                        elsif ($settings{'SERVICE'} eq 'twodns') {
+                            # use proxy ?
+                            my %proxysettings;
+                            &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
+                            if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
+                                my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
+                                Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
+                            }
+
+                            if ($settings{'HOSTNAME'} eq '') {
+                                $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
+                            } else {
+                                $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
+                            }
+
+                            my ($out, $response) = Net::SSLeay::get_https( 'update.twodns.de',
+                                                                            443,
+                                                                           "/update?hostname=$settings{'HOSTDOMAIN'}&ip=$ip",
+                                                                            Net::SSLeay::make_headers('User-Agent' => 'IPFire',
+                                                                                                      'Authorization' => 'Basic ' . encode_base64("$settings{'LOGIN'}:$settings{'PASSWORD'}")) );
+
+                            # Valid response are 'ok'   'nochange'
+                            if ($response =~ m%HTTP/1\.. 200 OK%) {
+                                if ( $out !~ m/^(good|nochg)/ ) {
+                                    $out =~ s/\n/ /g;
+                                    &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure ($out)");
+                                } else {
+                                    &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : success");
+                                    $success++;
+                                }
+                            } else {
+                                &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server, check your credentials---$out-$response--)");
+                            }
+                        }
+                       elsif ($settings{'SERVICE'} eq 'variomedia') { 
+                           # use proxy ?
+                           my %proxysettings;
+                           &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
+                           if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
+                               my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
+                               Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
+                           }
+                           if ($settings{'HOSTNAME'} eq '') {
+                               $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
+                           } else {
+                               $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
+                           }
+                           my ($out, $response) = Net::SSLeay::get_https( 'dyndns.variomedia.de',
+                                                                           443,
+                                                                           "/nic/update?hostname=$settings{'HOSTDOMAIN'}&myip=$ip",
+                                                                           Net::SSLeay::make_headers('User-Agent' => 'IPFire',
+                                                                                                     'Authorization' => 'Basic ' . encode_base64("$settings{'LOGIN'}:$settings{'PASSWORD'}")) );
+                           # Valid response is 'good $ip'
+                           if ($response =~ m%HTTP/1\.. 200 OK%) {
+                               if ( $out !~ m/^good $ip/ ) {
+                                   &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} ($ip) : failure ($out)");
+                               } else {
+                                   &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} ($ip) : success");
+                                   $success++;
+                               }
+                           } else {
+                               &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server, check your credentials---$out-$response--)");
+                           }
+                       }
                        else {
                                if ($settings{'WILDCARDS'} eq 'on') {
                                    $settings{'WILDCARDS'} = '-w';