Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Add all-inkl to dynamic DNS Service for Endian 2.4.1:
- # have to be changed: 2 files - ddns.cgi, setddns.pl
- # source of both files in bottom
- # Endian File-Path ddns.cgi: /home/httpd/cgi-bin/
- # Endian File-Path setddns.pl: /usr/local/bin
- # Modded to work with all-inkl.com update Url 22.08.2013 martinl
- #
- ################################ ddns.cgi #######################################
- #!/usr/bin/perl
- #
- # SmoothWall CGIs
- #
- # This code is distributed under the terms of the GPL
- #
- # (c) The SmoothWall Team
- #
- # $Id: ddns.cgi,v 1.7.2.15 2004/10/03 21:33:12 alanh Exp $
- #
- #!/usr/bin/perl
- #
- # SmoothWall CGIs
- #
- # This code is distributed under the terms of the GPL
- #
- # (c) The SmoothWall Team
- #
- # $Id: ddns.cgi,v 1.7.2.15 2004/10/03 21:33:12 alanh Exp $
- # added all-inkl to service 2013.08.22 martinl
- #
- require '/var/efw/header.pl';
- require '/home/httpd/cgi-bin/endianinc.pl';
- my @errormessages = ();
- my (%cgiparams,%selected,%checked);
- my $filename = "${swroot}/ddns/config";
- &showhttpheaders();
- $cgiparams{'ENABLED'} = 'off';
- $cgiparams{'PROXY'} = 'off';
- $cgiparams{'WILDCARDS'} = 'off';
- &getcgihash(\%cgiparams);
- my @service = ();
- open(FILE, "$filename") or die 'Unable to open config file.';
- my @current = <FILE>;
- close(FILE);
- if ($cgiparams{'ACTION'} eq 'add')
- {
- toggle_file("${swroot}/ddns/behindnat","$cgiparams{'BEHINDNAT'}");
- unless ($cgiparams{'SERVICE'} =~ /^(dhs\.org|dyndns\.org|dyndns-custom|dyndns-static|dyns\.cx|easydns\.com|freedns-afraid\.org|hn\.org|no-ip\.com|nsupdate|ovh\.com|regfish\.com|selfhost\.de|tzo\.com|zoneedit\.com|all-inkl)$/) {
- push(@errormessages, _('Invalid input'));
- }
- unless ($cgiparams{'LOGIN'} ne '') {
- push(@errormessages, _('Username not set.'));
- }
- # for free-dns.afraid.org, only 'connect string' is mandatory
- if ($cgiparams{'SERVICE'} ne 'freedns-afraid.org') {
- unless ($cgiparams{'SERVICE'} eq 'regfish.com' || $cgiparams{'PASSWORD'} ne '') {
- push(@errormessages, _('Password not set.'));
- }
- # Permit an empty HOSTNAME for the nsupdate, regfish, dyndns, ovh, zoneedit
- unless ($cgiparams{'SERVICE'} eq 'zoneedit.com' || $cgiparams{'SERVICE'} eq 'nsupdate' || $cgiparams{'SERVICE'} eq 'dyndns-custom'|| $cgiparams{'SERVICE'} eq 'regfish.com' || $cgiparams{'SERVICE'} eq 'ovh.com' || $cgiparams{'HOSTNAME'} ne '') {
- push(@errormessages, _('Hostname not set.'));
- }
- unless ($cgiparams{'HOSTNAME'} eq '' || $cgiparams{'HOSTNAME'} =~ /^[a-zA-Z_0-9-]+$/) {
- push(@errormessages, _('Invalid hostname.'));
- }
- if ($cgiparams{'DOMAIN'} eq '') {
- push(@errormessages, _('Domain not set.'));
- }
- else {
- unless ($cgiparams{'DOMAIN'} =~ /^[a-zA-Z_0-9.-]+$/ || $cgiparams{'DOMAIN'} =~ /[.]/) {
- push(@errormessages, _('Invalid domain name.'));
- }
- }
- }
- my $id = 0;
- foreach my $line (@current)
- {
- $id++;
- my @temp = split(/\,/,$line);
- if($cgiparams{'HOSTNAME'} eq $temp[1] &&
- $cgiparams{'DOMAIN'} eq $temp[2] &&
- $cgiparams{'EDITING'} ne $id)
- {
- push(@errormessages, _('Hostname and domain already in use.'));
- }
- }
- if (scalar(@errormessages) eq 0)
- {
- if ($cgiparams{'EDITING'} eq 'no')
- {
- open(FILE,">>$filename") or die 'Unable to open config file.';
- flock FILE, 2;
- print FILE "$cgiparams{'SERVICE'},$cgiparams{'HOSTNAME'},$cgiparams{'DOMAIN'},$cgiparams{'PROXY'},$cgiparams{'WILDCARDS'},$cgiparams{'LOGIN'},$cgiparams{'PASSWORD'},$cgiparams{'ENABLED'},$cgiparams{'KASID'},$cgiparams{'NAMESERVER'}\n";
- &log(_('Dynamic DNS hostname added'));
- } else {
- open(FILE,">$filename") or die 'Unable to open config file.';
- flock FILE, 2;
- my $id = 0;
- foreach my $line (@current)
- {
- $id++;
- chomp($line);
- my @temp = split(/\,/,$line);
- if ($cgiparams{'EDITING'} eq $id) {
- print FILE "$cgiparams{'SERVICE'},$cgiparams{'HOSTNAME'},$cgiparams{'DOMAIN'},$cgiparams{'PROXY'},$cgiparams{'WILDCARDS'},$cgiparams{'LOGIN'},$cgiparams{'PASSWORD'},$cgiparams{'ENABLED'},$cgiparams{'KASID'},$cgiparams{'NAMESERVER'}\n";
- } else {
- print FILE "$line\n";
- }
- }
- }
- close(FILE);
- undef %cgiparams;
- }
- }
- if ($cgiparams{'ACTION'} eq 'edit' )
- {
- my $id = 0;
- foreach my $line (@current)
- {
- $id++;
- chomp($line);
- my @temp = split(/\,/,$line);
- if ($cgiparams{'ID'} eq $id)
- {
- $cgiparams{'SERVICE'} = $temp[0];
- $cgiparams{'HOSTNAME'} = $temp[1];
- $cgiparams{'DOMAIN'} = $temp[2];
- $cgiparams{'PROXY'} = $temp[3];
- $cgiparams{'WILDCARDS'} = $temp[4];
- $cgiparams{'LOGIN'} = $temp[5];
- $cgiparams{'PASSWORD'} = $temp[6];
- $cgiparams{'ENABLED'} = $temp[7];
- $cgiparams{'KASID'} = $temp[8];
- $cgiparams{'NAMESERVER'} = $temp[9];
- }
- }
- }
- if ($cgiparams{'ACTION'} eq 'remove')
- {
- open(FILE, ">$filename") or die 'Unable to open config file.';
- flock FILE, 2;
- my $id = 0;
- foreach my $line (@current)
- {
- $id++;
- unless ($cgiparams{"ID"} eq $id) { print FILE "$line"; }
- }
- close(FILE);
- &log(_('Dynamic DNS hostname removed'));
- }
- if ($cgiparams{'ACTION'} eq 'toggle')
- {
- open(FILE, ">$filename") or die 'Unable to open config file.';
- flock FILE, 2;
- my $id = 0;
- foreach my $line (@current)
- {
- $id++;
- unless ($cgiparams{'ID'} eq $id) { print FILE "$line"; }
- else
- {
- my $pos = 7;
- if ($cgiparams{'KEY1'} eq 'wildcard') { $pos = 4; }
- elsif ($cgiparams{'KEY1'} eq 'proxy') { $pos = 3; }
- chomp($line);
- my @temp = split(/\,/,$line);
- if ($temp[$pos] eq "on") {
- $temp[$pos] = "off";
- } else {
- $temp[$pos] = "on";
- }
- print FILE join(',',@temp) . "\n";
- }
- }
- close(FILE);
- }
- if ($cgiparams{'ACTION'} eq 'forceupdate')
- {
- system('/usr/bin/sudo /usr/local/bin/setddns.pl -f 2&>/dev/null');
- }
- if ($cgiparams{'ACTION'} eq '')
- {
- $cgiparams{'ENABLED'} = 'on';
- }
- $selected{'SERVICE'}{'dhs.org'} = '';
- $selected{'SERVICE'}{'dyndns.org'} = '';
- $selected{'SERVICE'}{'dyndns-custom'} = '';
- $selected{'SERVICE'}{'dyndns-static'} = '';
- $selected{'SERVICE'}{'dyns.cx'} = '';
- $selected{'SERVICE'}{'easydns.com'} = '';
- $selected{'SERVICE'}{'freedns-afraid.org'} = '';
- $selected{'SERVICE'}{'hn.org'} = '';
- $selected{'SERVICE'}{'no-ip.com'} = '';
- $selected{'SERVICE'}{'nsupdate'} = '';
- $selected{'SERVICE'}{'ovh.com'} = '';
- $selected{'SERVICE'}{'regfish.com'} = '';
- $selected{'SERVICE'}{'selfhost.de'} = '';
- $selected{'SERVICE'}{'tzo.com'} = '';
- $selected{'SERVICE'}{'zoneedit.com'} = '';
- $selected{'SERVICE'}{'all-inkl'} = '';
- $selected{'SERVICE'}{$cgiparams{'SERVICE'}} = "selected='selected'";
- $checked{'PROXY'}{'off'} = '';
- $checked{'PROXY'}{'on'} = '';
- $checked{'PROXY'}{$cgiparams{'PROXY'}} = "checked='checked'";
- $checked{'WILDCARDS'}{'off'} = '';
- $checked{'WILDCARDS'}{'on'} = '';
- $checked{'WILDCARDS'}{$cgiparams{'WILDCARDS'}} = "checked='checked'";
- $checked{'ENABLED'}{'off'} = '';
- $checked{'ENABLED'}{'on'} = '';
- $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'";
- if( -e "${swroot}/ddns/behindnat" )
- {
- $checked{'BEHINDNAT'}{'on'} = "checked='checked'";
- }
- &openpage(_('Dynamic DNS'), 1, '');
- &openbigbox($errormessage, $warnmessage, $notemessage);
- if (scalar(@errormessages) > 0) {
- #Stay in edit mode if we are in it
- if ($cgiparams{'EDITING'} ne 'no') {
- $cgiparams{'ACTION'} = 'edit';
- $cgiparams{'ID'} = $cgiparams{'EDITING'};
- }
- }
- &openbox('100%', 'left', _('Current hosts'));
- # if ($cgiparams{'ACTION'} eq "edit") {
- # $action = "edit";
- # }
- # else {
- # $action = "add";
- # }
- openeditorbox(_("Add a host"), _("Add a host"), ($cgiparams{'ACTION'} eq 'edit' || scalar(@errormessages) > 0 ? "showeditor" : ""), "hosts", @errormessages);
- printf <<END
- <table width='100%'>
- <tr>
- <td width='25%' class='base'>%s *</td>
- <td width='25%'><select size='1' name='SERVICE'>
- <option $selected{'SERVICE'}{'all-inkl'}>all-inkl</option>
- <option $selected{'SERVICE'}{'dhs.org'}>dhs.org</option>
- <option $selected{'SERVICE'}{'dyndns.org'}>dyndns.org</option>
- <option $selected{'SERVICE'}{'dyndns-custom'}>dyndns-custom</option>
- <option $selected{'SERVICE'}{'dyndns-static'}>dyndns-static</option>
- <option $selected{'SERVICE'}{'dyns.cx'}>dyns.cx</option>
- <option $selected{'SERVICE'}{'easydns.com'}>easydns.com</option>
- <option $selected{'SERVICE'}{'freedns-afraid.org'}>freedns-afraid.org</option>
- <option $selected{'SERVICE'}{'hn.org'}>hn.org</option>
- <option $selected{'SERVICE'}{'no-ip.com'}>no-ip.com</option>
- <option $selected{'SERVICE'}{'nsupdate'}>nsupdate</option>
- <option $selected{'SERVICE'}{'ovh.com'}>ovh.com</option>
- <option $selected{'SERVICE'}{'regfish.com'}>regfish.com</option>
- <option $selected{'SERVICE'}{'selfhost.de'}>selfhost.de</option>
- <!-- <option $selected{'SERVICE'}{'tzo.com'}>tzo.com</option> comment this service out until a working fix is developed -->
- <option $selected{'SERVICE'}{'zoneedit.com'}>zoneedit.com</option>
- </select></td>
- <td width='25%' class='base'>%s <input type='checkbox' name='PROXY' value='on' $checked{'PROXY'}{'on'} /></td>
- <td width='25%' class='base'>%s <input type='checkbox' name='WILDCARDS' value='on' $checked{'WILDCARDS'}{'on'} /></td>
- </tr>
- <tr>
- <td class='base'>%s *</td>
- <td><input type='text' name='HOSTNAME' value='$cgiparams{'HOSTNAME'}' /></td>
- <td class='base'>%s *</td>
- <td><input type='text' name='DOMAIN' value='$cgiparams{'DOMAIN'}' /></td>
- </tr>
- <tr>
- <td class='base'>%s * <a href="http://kasapi.kasserver.com/dokumentation/">all-inkl docs</a></td>
- <td><input type='text' name='KASID' value='$cgiparams{'KASID'}' /></td>
- <td class='base'>%s * <a href="http://kasapi.kasserver.com/dokumentation/formular.php?kas_login=ihr_kas_login&kas_auth_type=sha1&kas_auth_data=ihr_kas_passwort&kas_action=get_dns_settings&var1=zone_host&wert1=meinedomain.de.&var2=nameserver&wert2=ns5.kasserver.com&anz_var=2">all-inkl docs</a></td>
- <td><input type='text' name='NAMESERVER' value='$cgiparams{'NAMESERVER'}' /></td>
- </tr>
- <tr>
- <td class='base'>%s *</td>
- <td><input type='text' name='LOGIN' value='$cgiparams{'LOGIN'}' /></td>
- <td class='base'>%s *<a href="http://kasapi.kasserver.com/dokumentation/formular.php?kas_login=ihr_kas_login&kas_auth_type=sha1&kas_auth_data=ihr_kas_passwort&kas_action=get_dns_settings&var1=zone_host&wert1=meinedomain.de.&var2=nameserver&wert2=ns5.kasserver.com&anz_var=2">all-inkl docs</a></td>
- <td><input type='password' name='PASSWORD' value='$cgiparams{'PASSWORD'}' /></td>
- </tr>
- <tr>
- <td class='base'>%s<input type='checkbox' name='BEHINDNAT' value='on' $checked{'BEHINDNAT'}{'on'} /></td>
- <td>
- %s<input type='checkbox' name='ENABLED' value='on' $checked{'ENABLED'}{'on'} />
- <input type="hidden" name="ACTION" value="add"/>
- </td>
- </tr>
- </table>
- END
- ,
- _('Service'),
- _('Behind a proxy'),
- _('Enable wildcards'),
- _('Hostname'),
- _('Domain'),
- _('Record_ID'),
- _('Nameserver'),
- _('Username'),
- _('Password'),
- _('behind Router(NAT)'),
- _('Enabled'),
- ;
- if ($cgiparams{'ACTION'} eq 'edit') {
- print "<input type='hidden' name='EDITING' value='$cgiparams{'ID'}' />\n";
- } else {
- print "<input type='hidden' name='EDITING' value='no' />\n";
- }
- &closeeditorbox(($cgiparams{'ACTION'} eq 'add' || $cgiparams{'ACTION'} eq 'edit' || scalar(@errormessages) > 0 ? _("Update Host") : _("Add Host")), _("Cancel"), "hostsbutton", "hosts", $ENV{'SCRIPT_NAME'});
- printf <<END
- <table class="ruleslist" width='100%' cellpadding="0" cellspacing="0" border="0">
- <tr>
- <th width='15%' class='boldbase'><b>%s</b></td>
- <th width='20%' class='boldbase'><b>%s</b></td>
- <th width='25%' class='boldbase'><b>%s</b></td>
- <th width='8%' nowrap="nowrap" align='center' class='boldbase'><b>%s</b></td>
- <th width='8%' class='boldbase'><b>%s</b></td>
- <th width='8%' class='boldbase'><b>%s</b></td>
- <th width='16%' class='boldbase' colspan='2'><b>%s</b></td>
- </tr>
- END
- ,
- _('Service'),
- _('Hostname'),
- _('Domain'),
- _('Anonymous web proxies'),
- _('Wildcards'),
- _('Enabled'),
- _('Actions')
- ;
- my $id = 0;
- open(SETTINGS, "$filename") or die 'Unable to open config file.';
- while (<SETTINGS>)
- {
- my ($gifproxy,$descproxy,$gifwildcards,$descwildcard,$gifenabled,$descenabled);
- $id++;
- chomp($_);
- my @temp = split(/\,/,$_);
- if ($cgiparams{'ACTION'} eq 'edit' && $cgiparams{'ID'} eq $id) {
- print "<tr class='selected'>\n"; }
- elsif ($id % 2) { print "<tr class='odd'>\n"; }
- else { print "<tr class='even'>\n"; }
- if ($temp[3] eq 'on') {
- $gifproxy = 'on.png';
- $descproxy = _('Enabled (click to disable)');
- } else {
- $gifproxy = 'off.png';
- $descproxy = _('Disabled (click to enable)');
- }
- if ($temp[4] eq 'on') {
- $gifwildcards = 'on.png';
- $descwildcard = _('Enabled (click to disable)');
- } else {
- $gifwildcards = 'off.png';
- $descwildcard = _('Disabled (click to enable)');
- }
- if ($temp[7] eq 'on') {
- $gifenabled = 'on.png';
- $descenabled = _('Enabled (click to disable)');
- } else {
- $gifenabled = 'off.png';
- $descenabled = _('Disabled (click to enable)');
- }
- printf <<END
- <td>$temp[0]</td>
- <td>$temp[1]</td>
- <td>$temp[2]</td>
- <form enctype='multipart/form-data' method='post' action='$ENV{'SCRIPT_NAME'}' name='frma$id'>
- <td class='center'>
- <input class='imagebutton' type='image' src='/images/$gifproxy' alt='$descproxy' title='$descproxy' border='0'/>
- <input type='hidden' name='ACTION' value='toggle' />
- <input type='hidden' name='ID' value='$id' />
- <input type='hidden' name='KEY1' value='proxy' />
- </td>
- </form>
- <form enctype='multipart/form-data' method='post' action='$ENV{'SCRIPT_NAME'}' name='frmb$id'>
- <td class='center'>
- <input class='imagebutton' type='image' src='/images/$gifwildcards' alt='$descwildcard' title='$descwildcard'/>
- <input type='hidden' name='ACTION' value='toggle' />
- <input type='hidden' name='ID' value='$id' />
- <input type='hidden' name='KEY1' value='wildcard' />
- </td>
- </form>
- <form enctype='multipart/form-data' method='post' action='$ENV{'SCRIPT_NAME'}' name='frmc$id'>
- <td class='center'>
- <input class='imagebutton' type='image' src='/images/$gifenabled' alt='$descenabled' title='$descenabled'/>
- <input type='hidden' name='ACTION' value='toggle' />
- <input type='hidden' name='ID' value='$id' />
- <input type='hidden' name='KEY1' value='enable' />
- </td>
- </form>
- <td class='center'>
- <form enctype='multipart/form-data' method='post' name='frmd$id' action='$ENV{'SCRIPT_NAME'}'>
- <input class='imagebutton' type='image' name='%s' src='/images/edit.png' title='%s' alt='%s' />
- <input type='hidden' name='ID' value='$id' />
- <input type='hidden' name='ACTION' value='edit' />
- </form>
- </td>
- <td align='center'>
- <form enctype='multipart/form-data' method='post' name='frme$id' action='$ENV{'SCRIPT_NAME'}'>
- <input class='imagebutton' type='image' name='%s' src='/images/delete.png' title='%s' alt='%s' />
- <input type='hidden' name='ID' value='$id' />
- <input type='hidden' name='ACTION' value='remove' />
- </form>
- </td>
- </tr>
- END
- ,
- _('Edit'),
- _('Edit'),
- _('Edit'),
- _('Remove'),
- _('Remove'),
- _('Remove')
- ;
- }
- close(SETTINGS);
- printf <<END
- </table>
- <form enctype='multipart/form-data' method='post' action='$ENV{'SCRIPT_NAME'}'>
- <input type='hidden' name='ACTION' value='forceupdate' />
- <table width='100%'>
- <tr>
- <td width='100%' align='center'><input class='submitbutton' type='submit' name='SUBMIT' value='%s' /></td>
- </tr>
- </table>
- </form>
- END
- , _('Force update')
- ;
- # If the file contains entries, print Key to action icons
- if ( ! -z "$filename") {
- printf <<END
- <table class="list-legend" cellpadding="0" cellspacing="0" border="0">
- <tr>
- <td class='boldbase'><b>%s:</b></td>
- <td> <img src='/images/on.png' alt='%s' /></td>
- <td class='base'>%s</td>
- <td> <img src='/images/off.png' alt='%s' /></td>
- <td class='base'>%s</td>
- <td> <img src='/images/edit.png' alt='%s' /></td>
- <td class='base'>%s</td>
- <td> <img src='/images/delete.png' alt='%s' /></td>
- <td class='base'>%s</td>
- </tr>
- </table>
- END
- ,
- _('Legend'),
- _('Enabled (click to disable)'),
- _('Enabled (click to disable)'),
- _('Disabled (click to enable)'),
- _('Disabled (click to enable)'),
- _('Edit'),
- _('Edit'),
- _('Remove'),
- _('Remove')
- ;
- }
- &closebox();
- &closebigbox();
- &closepage();
- ################################ setddns.pl #######################################
- #!/usr/bin/perl
- #
- # SmoothWall CGIs
- #
- # This code is distributed under the terms of the GPL
- #
- # (c) The SmoothWall Team
- #
- # $Id: setddns.pl,v 1.4.2.7 2004/10/12 16:36:10 alanh Exp $
- #
- # Modded to work with new ZoneEdit update URL - dynamic.zoneedit.com - By Darren Carter, www.citsystems.co.za. 2009/03/15
- # Modded to work with all-inkl.com update Url martinl; 22.08.2013
- #
- close(STDIN);
- close(STDOUT);
- close(STDERR);
- use IO::Socket;
- require '/var/efw/header.pl';
- my %settings;
- my %noipsettings;
- my $filename = "${swroot}/ddns/config";
- my $cachefile = "${swroot}/ddns/ipcache";
- my $ipcache = 0;
- open(FILE, "$filename") or die 'Unable to open config file.';
- my @current = <FILE>;
- close(FILE);
- my $lines = $#current + 1;
- unless($lines) { exit 0; }
- my $ip = '';
- if ( -f "${swroot}/ddns/behindnat" )
- {
- $ip = `/usr/local/bin/detectip`;
- } else {
- if (-f "${swroot}/uplinks/main/data") {
- my %conf_hash = ();
- readhash("${swroot}/uplinks/main/data", \%conf_hash);
- $ip = $conf_hash{'ip_address'};
- }
- }
- chomp $ip;
- if ($ARGV[0] ne '-f')
- {
- open(IPCACHE, "$cachefile");
- $ipcache = <IPCACHE>;
- close(IPCACHE);
- chomp $ipcache;
- }
- if ($ip ne $ipcache)
- {
- my $id = 0;
- my $success = 0;
- my $line;
- foreach $line (@current)
- {
- $id++;
- chomp($line);
- my @temp = split(/\,/,$line);
- unless ($temp[7] eq "off")
- {
- $settings{'SERVICE'} = $temp[0];
- $settings{'HOSTNAME'} = $temp[1];
- $settings{'DOMAIN'} = $temp[2];
- $settings{'PROXY'} = $temp[3];
- $settings{'WILDCARDS'} = $temp[4];
- $settings{'LOGIN'} = $temp[5];
- $settings{'PASSWORD'} = $temp[6];
- $settings{'ENABLED'} = $temp[7];
- $settings{'KASID'} = $temp[8];
- $settings{'NAMESERVER'} = $temp[9];
- my @service = split(/\./, "$settings{'SERVICE'}");
- $settings{'SERVICE'} = "$service[0]";
- if ($settings{'SERVICE'} eq 'no-ip')
- {
- $noipsettings{'LOGIN'} = $settings{'LOGIN'};
- $noipsettings{'PASSWORD'} = $settings{'PASSWORD'};
- $noipsettings{'HOSTNAME'} = $settings{'HOSTNAME'};
- $noipsettings{'DOMAIN'} = $settings{'DOMAIN'};
- $noipsettings{'DAEMON'} = 'N';
- $noipsettings{'DEVICE'} = '';
- $noipsettings{'INTERVAL'} = '1';
- $noipsettings{'NAT'} = 'N';
- $noipsettings{'GROUP'} = '';
- if ($settings{'PROXY'} eq 'on') { $noipsettings{'PROXY'} = 'Y'; }
- else { $noipsettings{'PROXY'} = 'N'; }
- &writehash("${swroot}/ddns/noipsettings", \%noipsettings);
- open(F, "${swroot}/ddns/noipsettings");
- my @unsorted = <F>;
- close(F);
- my @sorted = sort { $b cmp $a } @unsorted;
- open(F, ">${swroot}/ddns/noipsettings");
- flock F, 2;
- print F @sorted;
- close(F);
- my @ddnscommand = ('/usr/bin/noip','-i',"$ip");
- my $result = system(@ddnscommand);
- if ( $result != 0) { &log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'}: failure"); }
- else
- {
- &log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'}: success");
- $success++;
- }
- }
- elsif ($settings{'SERVICE'} eq 'selfhost')
- {
- my %proxysettings;
- &readhash("/usr/lib/efw/proxy/default/settings", \%proxysettings);
- if (-e "${swroot}/proxy/settings") {
- &readhash("${swroot}/proxy/settings", \%proxysettings);
- }
- my $peer = 'www.ns4you.de';
- my $peerport = 80;
- if ($proxysettings{'UPSTREAM_ENABLED'} eq "on") {
- $peer = $proxysettings{'UPSTREAM_SERVER'};
- $peerport = $proxysettings{'UPSTREAM_PORT'};
- }
- my $sock;
- unless($sock = new IO::Socket::INET (PeerAddr => $peer, PeerPort => $peerport, Proto => 'tcp', Timeout => 5)) {
- die "Could not connect to $peer:$peerport: $@";
- return 1;
- }
- my $GET_CMD;
- $GET_CMD = "GET http://www.ns4you.de/cgi-dns/dns.pl?$settings{'LOGIN'}&$settings{'PASSWORD'}&$ip HTTP/1.1\r\n";
- $GET_CMD .= "Host: www.ns4you.de\r\n";
- $GET_CMD .= "Connection: close\r\n\r\n";
- print $sock "$GET_CMD";
- my $out = '';
- while(<$sock>) {
- $out .= $_;
- }
- close($sock);
- if ( $out =~ m/<meta name="ns4you" title="error"/ ) {
- &log("Dynamic DNS ip-update ns4you failure");
- }
- else
- {
- $out =~ m/<meta name="ns4you" title="url" content="(.*)"/;
- &log("Dynamic DNS ip-update for $1: success");
- $success++;
- }
- }
- elsif ($settings{'SERVICE'} eq 'nsupdate') {
- # Fetch UI configurable values and assemble the host name.
- my $hostName="$settings{'DOMAIN'}";
- if ($settings{'HOSTNAME'} ne "") {
- $hostName="$settings{'HOSTNAME'}.$hostName";
- }
- my $keyName=$settings{'LOGIN'};
- my $keySecret=$settings{'PASSWORD'};
- # Use a relatively long TTL value to reduce load on DNS.
- # Some public Dynamic DNS servers use values around 4 hours,
- # some use values as low as 60 seconds.
- # XXX Maybe we could fetch the master value from the server
- # (not the timed-down version supplied by DNS cache)
- my $timeToLive="3600";
- # Internal setting that can be used to override the DNS server
- # where the update is applied. It can be of use when testing
- # against a private DNS server.
- my $masterServer="";
- # Prepare the nsupdate command script to remove and re-add the
- # updated A record for the domain.
- my $cmdFile="/tmp/nsupdate-$hostName-commands";
- my $logFile="/tmp/nsupdate-$hostName-result";
- open(TF, ">$cmdFile");
- if ($masterServer ne "") {
- print TF "server $masterServer\n";
- }
- if ($keyName ne "" && $keySecret ne "") {
- print TF "key $keyName $keySecret\n";
- }
- print TF "update delete $hostName A\n";
- print TF "update add $hostName $timeToLive A $ip\n";
- print TF "send\n";
- close(TF);
- # Run nsupdate with -v to use TCP instead of UDP because we're
- # issuing multiple cmds and potentially long keys, and -d to
- # get diagnostic result output.
- my $result = system("/usr/bin/nsupdate -v -d $cmdFile 2>$logFile");
- if ($result != 0) {
- &log("Dynamic DNS ip-update for $hostName: failure");
- open(NSLOG, "$logFile");
- my @nsLog = <NSLOG>;
- close(NSLOG);
- my $logLine;
- foreach $logLine (@nsLog) {
- chomp($logLine);
- if ($logLine ne "") {
- &log("... $logLine");
- }
- }
- }
- else
- {
- &log("Dynamic DNS ip-update for $hostName: success");
- $success++;
- }
- unlink $cmdFile, $logFile;
- }
- elsif ($settings{'SERVICE'} eq 'freedns-afraid')
- {
- my %proxysettings;
- &readhash("/usr/lib/efw/proxy/default/settings", \%proxysettings);
- if (-e "${swroot}/proxy/settings") {
- &readhash("${swroot}/proxy/settings", \%proxysettings);
- }
- my $peer = 'freedns.afraid.org';
- my $peerport = 80;
- if ($proxysettings{'UPSTREAM_ENABLED'} eq "on") {
- $peer = $proxysettings{'UPSTREAM_SERVER'};
- $peerport = $proxysettings{'UPSTREAM_PORT'};
- }
- my $sock;
- unless($sock = new IO::Socket::INET (PeerAddr => $peer, PeerPort => $peerport, Proto => 'tcp', Timeout => 5)) {
- die "Could not connect to $peer:$peerport: $@";
- return 1;
- }
- my $GET_CMD;
- $GET_CMD = "GET http://freedns.afraid.org/dynamic/update.php?$settings{'LOGIN'} HTTP/1.1\r\n";
- $GET_CMD .= "Host: freedns.afraid.org\r\n";
- $GET_CMD .= "Connection: close\r\n\r\n";
- print $sock "$GET_CMD";
- my $out = '';
- while(<$sock>) {
- $out .= $_;
- }
- close($sock);
- #Valid responses from service are:
- #Updated yourdomain.afraid.org to your IP
- #Address <ip> has not changed.
- if ( $out !~ m/(Updated|Address .* has not changed)/ig ) {
- #cleanup http response...
- $out =~ s/.+?\015?\012\015?\012//s; # header HTTP
- @out = split("\r", $out);
- &log("Dynamic DNS afraid.org : failure (@out[1])");
- }
- else
- {
- &log("Dynamic DNS afraid.org : success");
- $success++;
- }
- }
- elsif ($settings{'SERVICE'} eq 'regfish')
- {
- my %proxysettings;
- &readhash("/usr/lib/efw/proxy/default/settings", \%proxysettings);
- if (-e "${swroot}/proxy/settings") {
- &readhash("${swroot}/proxy/settings", \%proxysettings);
- }
- my $peer = 'www.regfish.com';
- my $peerport = 80;
- if ($proxysettings{'UPSTREAM_ENABLED'} eq "on") {
- $peer = $proxysettings{'UPSTREAM_SERVER'};
- $peerport = $proxysettings{'UPSTREAM_PORT'};
- }
- my $sock;
- unless($sock = new IO::Socket::INET (PeerAddr => $peer, PeerPort => $peerport, Proto => 'tcp', Timeout => 5)) {
- die "Could not connect to $peer:$peerport: $@";
- return 1;
- }
- my $GET_CMD;
- $GET_CMD = "GET http://www.regfish.com/dyndns/2/?fqdn=$settings{'DOMAIN'}&thisipv4=true&forcehost=1&authtype=secure&token=$settings{'LOGIN'} HTTP/1.1\r\n";
- $GET_CMD .= "Host: www.regfish.com\r\n";
- $GET_CMD .= "Connection: close\r\n\r\n";
- print $sock "$GET_CMD";
- my $out = '';
- while(<$sock>) {
- $out .= $_;
- }
- close($sock);
- #Valid responses from service:
- #success|100|update succeeded!
- #success|101|no update needed at this time..
- if ( $out !~ m/(success\|(100|101)\|)/ig ) {
- #cleanup http response...
- $out =~ s/.+?\015?\012\015?\012//s; # header HTTP
- @out = split("\r", $out);
- &log("Dynamic DNS regfish.com : @out[1]");
- }
- else
- {
- &log("Dynamic DNS regfish.com : success");
- $success++;
- }
- }
- elsif ($settings{'SERVICE'} eq 'ovh')
- {
- my %proxysettings;
- &readhash("/usr/lib/efw/proxy/default/settings", \%proxysettings);
- if (-e "${swroot}/proxy/settings") {
- &readhash("${swroot}/proxy/settings", \%proxysettings);
- }
- my $peer = 'www.ovh.com';
- my $peerport = 80;
- if ($proxysettings{'UPSTREAM_ENABLED'} eq "on") {
- $peer = $proxysettings{'UPSTREAM_SERVER'};
- $peerport = $proxysettings{'UPSTREAM_PORT'};
- }
- my $sock;
- unless($sock = new IO::Socket::INET (PeerAddr => $peer, PeerPort => $peerport, Proto => 'tcp', Timeout => 5)) {
- die "Could not connect to $peer:$peerport: $@";
- return 1;
- }
- if ($settings{'HOSTNAME'} eq '') {
- $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
- }
- else {
- $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
- }
- my $GET_CMD;
- $GET_CMD = "GET http://www.ovh.com/nic/update?system=dyndns&hostname=$settings{'HOSTDOMAIN'}&myip=$ip HTTP/1.1\r\n";
- $GET_CMD .= "Host: www.ovh.com\r\n";
- chomp($code64 = encode_base64("$settings{'LOGIN'}:$settings{'PASSWORD'}"));
- $GET_CMD .= "Authorization: Basic $code64\r\n";
- #$GET_CMD .= "User-Agent: ipcop\r\n";
- #$GET_CMD .= "Content-Type: application/x-www-form-urlencoded\r\n";
- $GET_CMD .= "\r\n";
- print $sock "$GET_CMD";
- my $out = '';
- while(<$sock>) {
- $out .= $_;
- }
- close($sock);
- #HTTP response => error (in Title tag) else text response
- #Valid responses from service:good,nochg (ez-ipupdate like)
- #Should use ez-ipdate but "system=dyndns" is not present
- if ( $out =~ m/<Title>(.*)<\/Title>/ig ) {
- &log("Dynamic DNS ovh.com : failure ($1)");
- }
- elsif ($out !~ m/good |nochg /ig) {
- $out =~ s/.+?\015?\012\015?\012//s; # header HTTP
- @out = split("\r", $out);
- &log("Dynamic DNS ovh.com : failure ($out[1])");
- }
- else {
- &log("Dynamic DNS ovh.com : success");
- $success++;
- }
- }
- elsif ($settings{'SERVICE'} eq 'all-inkl')
- {
- my %proxysettings;
- &readhash("/usr/lib/efw/proxy/default/settings", \%proxysettings);
- if (-e "${swroot}/proxy/settings") {
- &readhash("${swroot}/proxy/settings", \%proxysettings);
- }
- my $peer = 'kasapi.kasserver.com';
- my $peerport = 80;
- if ($proxysettings{'UPSTREAM_ENABLED'} eq "on") {
- $peer = $proxysettings{'UPSTREAM_SERVER'};
- $peerport = $proxysettings{'UPSTREAM_PORT'};
- }
- my $sock;
- unless($sock = new IO::Socket::INET (PeerAddr => $peer, PeerPort => $peerport, Proto => 'tcp', Timeout => 5)) {
- die "Could not connect to $peer:$peerport: $@";
- return 1;
- }
- # convert password to SHA1 HEX
- use Digest::SHA1 qw/ sha1_hex /;
- $shapass = &sha1_hex($settings{'PASSWORD'});
- # Multi Domain Time-Protector if more than on Domain
- sleep(2);
- my $GET_CMD;
- $GET_CMD = "GET http://kasapi.kasserver.com/kas.php?kas_action=update_dns_settings&kas_login=$settings{'LOGIN'}&kas_auth_type=sha1&kas_auth_data=$shapass&record_name=$settings{'HOSTNAME'}&record_type=A&record_data=$settings{'DOMAIN'}.&record_aux=0&record_id=$settings{'KASID'}&nameserver=$settings{'NAMESERVER'}&record_data=$ip
- HTTP/1.1\r\n";
- $GET_CMD .= "Connection: close\r\n\r\n";
- print $sock "$GET_CMD";
- my $out = '';
- while(<$sock>) {
- &log ($out .= $_);
- }
- close($sock);
- $hostname = $settings{'HOSTNAME'};
- $domain = $settings{'DOMAIN'};
- use Sys::Syslog;
- openlog "noip", "cons.pid", "local3";
- print $out;
- if ($out =~ m/TRUE/)
- {
- syslog ('news|notice', "Dynamic DNS Update ".$hostname.".".$domain." succeeded - IP:".$ip." updated");
- closelog;
- }
- elsif ($out =~ m/nothing_to_do/)
- {
- syslog ('news|notice', "Dynamic DNS Update ".$hostname.".".$domain." is up to date!");
- closelog;
- }
- else
- {
- syslog ('news|notice', "Dynamic DNS Update ".$hostname.".".$domain." failed! /n".$out."/n");
- closelog;
- }
- }
- else
- {
- if ($settings{'WILDCARDS'} eq 'on') {$settings{'WILDCARDS'} = '-w';}
- else {$settings{'WILDCARDS'} = '';}
- if ($settings{'SERVICE'} eq 'dyndns-custom' && $settings{'HOSTNAME'} eq '') {$settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};}
- else {$settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";}
- if ($settings{'SERVICE'} eq 'zoneedit') {$serverdir = '-s'; $serveradd = 'dynamic.zoneedit.com';}
- else {$serverdir = ''; $serveradd = '';}
- my @ddnscommand = ('/usr/bin/ez-ipupdate', '-a', "$ip", '-S', "$settings{'SERVICE'}", "$serverdir", "$serveradd", '-u', "$settings{'LOGIN'}:$settings{'PASSWORD'}", '-h', "$settings{'HOSTDOMAIN'}", "$settings{'WILDCARDS'}", '-q');
- my $result = system(@ddnscommand);
- if ( $result != 0) { &log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'}: failure"); }
- else
- {
- &log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'}: success");
- $success++;
- }
- }
- }
- else
- {
- # If a line is disabled, then we should discount it
- $lines--;
- }
- }
- if ($lines == $success)
- {
- open(IPCACHE, ">$cachefile");
- flock IPCACHE, 2;
- print IPCACHE $ip;
- close(IPCACHE);
- }
- }
- # Extracted from Base64.pm
- sub encode_base64 ($;$)
- {
- my $res = "";
- my $eol = $_[1];
- $eol = "\n" unless defined $eol;
- pos($_[0]) = 0; # ensure start at the beginning
- while ($_[0] =~ /(.{1,45})/gs) {
- $res .= substr(pack('u', $1), 1);
- chomp($res);
- }
- $res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs
- # fix padding at the end
- my $padding = (3 - length($_[0]) % 3) % 3;
- $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
- # break encoded string into lines of no more than 76 characters each
- if (length $eol) {
- $res =~ s/(.{1,76})/$1$eol/g;
- }
- $res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement