X-Git-Url: http://git.ipfire.org/?p=people%2Fteissler%2Fipfire-2.x.git;a=blobdiff_plain;f=src%2Fscripts%2Fsetddns.pl;h=f97e75074b48e5bf9d6f6412b800ce7d5084a03e;hp=775c6ed03b2f3ed185b9324c82d8f1fcaba605f2;hb=36d809efb637c618359f40c1ecd8d820fcb2c882;hpb=4ed2816fef49842f2c53bac3afe6af418c8cf49c diff --git a/src/scripts/setddns.pl b/src/scripts/setddns.pl index 775c6ed03..f97e75074 100644 --- a/src/scripts/setddns.pl +++ b/src/scripts/setddns.pl @@ -44,37 +44,14 @@ 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 = ; - close(IP); - chomp $ip; -} else { - &General::log('Dynamic DNS failure : unable to open local-ipaddress file.'); - exit 0; -} +my $ip = &General::GetDyndnsRedIP(); -#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 - } - - # 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. @@ -116,8 +93,10 @@ if ($ip ne $ipcache) { next; # do not update, go to test next service } } - my @service = split(/\./, "$settings{'SERVICE'}"); - $settings{'SERVICE'} = "$service[0]"; + if ($settings{'SERVICE'} ne "dns.lightningwirelabs.com") { + my @service = split(/\./, "$settings{'SERVICE'}"); + $settings{'SERVICE'} = "$service[0]"; + } if ($settings{'SERVICE'} eq 'no-ip') { open(F, ">${General::swroot}/ddns/noipsettings"); flock F, 2; @@ -149,6 +128,27 @@ if ($ip ne $ipcache) { } } + elsif ($settings{'SERVICE'} eq 'all-inkl') { + 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'} ); + } + + my ($out, $response) = Net::SSLeay::get_https("dyndns.kasserver.com", 443, "/", 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%) { + &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success"); + $success++; + } else { + &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure (could not connect to server, check your credentials)"); + } + } + elsif ($settings{'SERVICE'} eq 'cjb') { # use proxy ? my %proxysettings; @@ -237,6 +237,42 @@ if ($ip ne $ipcache) { &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server, check your credentials)"); } } + elsif ($settings{'SERVICE'} eq 'dns.lightningwirelabs.com') { + # 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 $authstring; + if ($settings{'LOGIN'} eq "token") { + $authstring = "token=$settings{'PASSWORD'}"; + } else { + $authstring = "username=$settings{'LOGIN'}&password=$settings{'PASSWORD'}"; + } + + my $user_agent = &General::MakeUserAgent(); + my ($out, $response) = Net::SSLeay::get_https("dns.lightningwirelabs.com", 443, + "/update?hostname=$settings{'HOSTDOMAIN'}&address4=$ip&$authstring", + Net::SSLeay::make_headers('User-Agent' => $user_agent) + ); + + # Valid response are 'ok' 'nochange' + if ($response =~ m%HTTP/1\.. 200 OK%) { + &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)"); + } + } elsif ($settings{'SERVICE'} eq 'enom') { # use proxy ? my %proxysettings; @@ -364,6 +400,43 @@ 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 'strato') { + # 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.strato.com', + 443, + "/nic/update?hostname=$settings{'HOSTDOMAIN'}&myip=$ip", + Net::SSLeay::make_headers('User-Agent' => 'IPFire', + 'Authorization' => 'Basic ' . encode_base64("$settings{'LOGIN'}:$settings{'PASSWORD'}") ) + ); + + if ($response =~ m%HTTP/1\.. 200 OK%) { + #Valid responses from update => ErrCount=0 + if ( $out =~ m/good |nochg /ig) { + &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success"); + $success++; + } else { + &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure1 ($out)"); + $success++; + } + } elsif ( $out =~ m/(.*)<\/title>/ig ) { + &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure2 ($1)"); + } else { + &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure3 ($response)"); + } + } elsif ($settings{'SERVICE'} eq 'regfish') { # use proxy ? my %proxysettings; @@ -372,13 +445,11 @@ if ($ip ne $ipcache) { 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'} ); } - - - my ($out, $response) = Net::SSLeay::get_https( 'www.regfish.com', - 443, - "/dyndns/2/?fqdn=$settings{'DOMAIN'}&ipv4=$ip&forcehost=1&authtype=secure&token=$settings{'LOGIN'}", - Net::SSLeay::make_headers('User-Agent' => 'IPFire' ) - ); + my ($out, $response) = Net::SSLeay::get_https( 'dyndns.regfish.de', + 443, + "/?fqdn=$settings{'DOMAIN'}&ipv4=$ip&forcehost=1&authtype=secure&token=$settings{'LOGIN'}", + Net::SSLeay::make_headers('User-Agent' => 'Ipfire' ) + ); #Valid responses from service are: #success|100|update succeeded! #success|101|no update needed at this time.. @@ -481,6 +552,36 @@ if ($ip ne $ipcache) { &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server)"); } } + #namecheap test + elsif ($settings{'SERVICE'} eq 'namecheap') { + # 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'} ); + } + + my ($out, $response) = Net::SSLeay::get_https( 'dynamicdns.park-your-domain.com', + 443, + "/update?host=$settings{'HOSTNAME'}&domain=$settings{'DOMAIN'}&password=$settings{'PASSWORD'}&ip=$ip", + Net::SSLeay::make_headers('User-Agent' => 'IPFire' ) + ); + #Valid responses from service are: + # wait confirmation!! + if ($response =~ m%HTTP/1\.. 200 OK%) { + if ( $out !~ m/<ErrCount>0<\/ErrCount>/ ) { + $out =~ m/<Err1>(.*)<\/Err1>/; + &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure ($1)"); + } else { + &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success"); + $success++; + } + } else { + &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure (could not connect to server)"); + } + } + #end namecheap test elsif ($settings{'SERVICE'} eq 'dynu') { # use proxy ? my %proxysettings; @@ -514,7 +615,42 @@ if ($ip ne $ipcache) { } else { &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server)"); } - } else { + } + elsif ($settings{'SERVICE'} eq 'udmedia.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( 'www.udmedia.de', + 443, + "/nic/update?myip=$ip&username=$settings{'HOSTDOMAIN'}&password=$settings{'PASSWORD'}", + 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/^(ok|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--)"); + } + } + else { if ($settings{'WILDCARDS'} eq 'on') { $settings{'WILDCARDS'} = '-w'; } else {