Advertisement
martinl

all-inkl.com ddns.cgi setddns.pl (Dynamic DNS)

Aug 22nd, 2013
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 32.86 KB | None | 0 0
  1. # Add all-inkl to dynamic DNS Service for Endian 2.4.1:
  2. # have to be changed: 2 files - ddns.cgi, setddns.pl
  3. # source of both files in bottom
  4. # Endian File-Path ddns.cgi: /home/httpd/cgi-bin/
  5. # Endian File-Path setddns.pl: /usr/local/bin
  6. # Modded to work with all-inkl.com update Url 22.08.2013 martinl
  7. #
  8. ################################ ddns.cgi #######################################
  9. #!/usr/bin/perl
  10. #
  11. # SmoothWall CGIs
  12. #
  13. # This code is distributed under the terms of the GPL
  14. #
  15. # (c) The SmoothWall Team
  16. #
  17. # $Id: ddns.cgi,v 1.7.2.15 2004/10/03 21:33:12 alanh Exp $
  18. #
  19. #!/usr/bin/perl
  20. #
  21. # SmoothWall CGIs
  22. #
  23. # This code is distributed under the terms of the GPL
  24. #
  25. # (c) The SmoothWall Team
  26. #
  27. # $Id: ddns.cgi,v 1.7.2.15 2004/10/03 21:33:12 alanh Exp $
  28. # added all-inkl to service 2013.08.22 martinl
  29. #
  30.  
  31. require '/var/efw/header.pl';
  32. require '/home/httpd/cgi-bin/endianinc.pl';
  33.  
  34. my @errormessages = ();
  35. my (%cgiparams,%selected,%checked);
  36. my $filename = "${swroot}/ddns/config";
  37.  
  38. &showhttpheaders();
  39.  
  40. $cgiparams{'ENABLED'} = 'off';
  41. $cgiparams{'PROXY'} = 'off';
  42. $cgiparams{'WILDCARDS'} = 'off';
  43. &getcgihash(\%cgiparams);
  44.  
  45. my @service = ();
  46. open(FILE, "$filename") or die 'Unable to open config file.';
  47. my @current = <FILE>;
  48. close(FILE);
  49.  
  50. if ($cgiparams{'ACTION'} eq 'add')
  51. {
  52.     toggle_file("${swroot}/ddns/behindnat","$cgiparams{'BEHINDNAT'}");
  53.     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)$/) {
  54.         push(@errormessages, _('Invalid input'));
  55.     }
  56.     unless ($cgiparams{'LOGIN'} ne '') {
  57.         push(@errormessages, _('Username not set.'));
  58.     }
  59.     # for free-dns.afraid.org, only 'connect string' is mandatory
  60.     if ($cgiparams{'SERVICE'} ne 'freedns-afraid.org') {
  61.       unless ($cgiparams{'SERVICE'} eq 'regfish.com' || $cgiparams{'PASSWORD'} ne '') {
  62.           push(@errormessages, _('Password not set.'));
  63.       }
  64.       # Permit an empty HOSTNAME for the nsupdate, regfish, dyndns, ovh, zoneedit
  65.       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 '') {
  66.           push(@errormessages, _('Hostname not set.'));
  67.       }
  68.       unless ($cgiparams{'HOSTNAME'} eq '' || $cgiparams{'HOSTNAME'} =~ /^[a-zA-Z_0-9-]+$/) {
  69.           push(@errormessages, _('Invalid hostname.'));
  70.       }
  71.       if ($cgiparams{'DOMAIN'} eq '') {
  72.           push(@errormessages, _('Domain not set.'));
  73.       }
  74.       else {
  75.           unless ($cgiparams{'DOMAIN'} =~ /^[a-zA-Z_0-9.-]+$/ || $cgiparams{'DOMAIN'} =~ /[.]/) {
  76.               push(@errormessages, _('Invalid domain name.'));
  77.           }
  78.       }
  79.     }
  80.     my $id = 0;
  81.     foreach my $line (@current)
  82.     {
  83.         $id++;
  84.         my @temp = split(/\,/,$line);
  85.         if($cgiparams{'HOSTNAME'} eq $temp[1] &&
  86.            $cgiparams{'DOMAIN'} eq $temp[2] &&
  87.            $cgiparams{'EDITING'} ne $id)
  88.         {
  89.              push(@errormessages, _('Hostname and domain already in use.'));
  90.         }
  91.     }
  92.     if (scalar(@errormessages) eq 0)
  93.     {
  94.         if ($cgiparams{'EDITING'} eq 'no')
  95.         {
  96.             open(FILE,">>$filename") or die 'Unable to open config file.';
  97.             flock FILE, 2;
  98.             print FILE "$cgiparams{'SERVICE'},$cgiparams{'HOSTNAME'},$cgiparams{'DOMAIN'},$cgiparams{'PROXY'},$cgiparams{'WILDCARDS'},$cgiparams{'LOGIN'},$cgiparams{'PASSWORD'},$cgiparams{'ENABLED'},$cgiparams{'KASID'},$cgiparams{'NAMESERVER'}\n";
  99.             &log(_('Dynamic DNS hostname added'));
  100.         } else {
  101.             open(FILE,">$filename") or die 'Unable to open config file.';
  102.             flock FILE, 2;
  103.             my $id = 0;
  104.             foreach my $line (@current)
  105.             {
  106.                 $id++;
  107.                 chomp($line);
  108.                 my @temp = split(/\,/,$line);
  109.                 if ($cgiparams{'EDITING'} eq $id) {
  110.                     print FILE "$cgiparams{'SERVICE'},$cgiparams{'HOSTNAME'},$cgiparams{'DOMAIN'},$cgiparams{'PROXY'},$cgiparams{'WILDCARDS'},$cgiparams{'LOGIN'},$cgiparams{'PASSWORD'},$cgiparams{'ENABLED'},$cgiparams{'KASID'},$cgiparams{'NAMESERVER'}\n";
  111.                 } else {
  112.                     print FILE "$line\n";
  113.                 }
  114.             }
  115.         }
  116.         close(FILE);
  117.         undef %cgiparams;
  118.     }
  119. }
  120.  
  121. if ($cgiparams{'ACTION'} eq 'edit' )
  122. {
  123.     my $id = 0;
  124.     foreach my $line (@current)
  125.     {
  126.         $id++;
  127.         chomp($line);
  128.         my @temp = split(/\,/,$line);
  129.         if ($cgiparams{'ID'} eq $id)
  130.         {
  131.             $cgiparams{'SERVICE'} = $temp[0];
  132.             $cgiparams{'HOSTNAME'} = $temp[1];
  133.             $cgiparams{'DOMAIN'} = $temp[2];
  134.             $cgiparams{'PROXY'} = $temp[3];
  135.             $cgiparams{'WILDCARDS'} = $temp[4];
  136.             $cgiparams{'LOGIN'} = $temp[5];
  137.             $cgiparams{'PASSWORD'} = $temp[6];
  138.             $cgiparams{'ENABLED'} = $temp[7];
  139.             $cgiparams{'KASID'} = $temp[8];
  140.             $cgiparams{'NAMESERVER'} = $temp[9];
  141.         }
  142.     }
  143. }
  144.  
  145. if ($cgiparams{'ACTION'} eq 'remove')
  146. {
  147.     open(FILE, ">$filename") or die 'Unable to open config file.';
  148.     flock FILE, 2;
  149.     my $id = 0;
  150.     foreach my $line (@current)
  151.     {
  152.         $id++;
  153.         unless ($cgiparams{"ID"} eq $id) { print FILE "$line"; }
  154.     }
  155.     close(FILE);
  156.     &log(_('Dynamic DNS hostname removed'));
  157. }
  158.  
  159. if ($cgiparams{'ACTION'} eq 'toggle')
  160. {
  161.     open(FILE, ">$filename") or die 'Unable to open config file.';
  162.     flock FILE, 2;
  163.     my $id = 0;
  164.     foreach my $line (@current)
  165.     {
  166.         $id++;
  167.         unless ($cgiparams{'ID'} eq $id) { print FILE "$line"; }
  168.         else
  169.         {
  170.             my $pos = 7;
  171.             if ($cgiparams{'KEY1'} eq 'wildcard') { $pos = 4; }
  172.             elsif ($cgiparams{'KEY1'} eq 'proxy') { $pos = 3; }
  173.             chomp($line);
  174.             my @temp = split(/\,/,$line);
  175.             if ($temp[$pos] eq "on") {
  176.                 $temp[$pos] = "off";
  177.             } else {
  178.                 $temp[$pos] = "on";
  179.             }
  180.             print FILE join(',',@temp) . "\n";
  181.         }
  182.     }
  183.     close(FILE);
  184. }
  185.  
  186. if ($cgiparams{'ACTION'} eq 'forceupdate')
  187. {
  188.     system('/usr/bin/sudo /usr/local/bin/setddns.pl -f 2&>/dev/null');
  189. }
  190.  
  191. if ($cgiparams{'ACTION'} eq '')
  192. {
  193.     $cgiparams{'ENABLED'} = 'on';
  194. }
  195.  
  196. $selected{'SERVICE'}{'dhs.org'} = '';
  197. $selected{'SERVICE'}{'dyndns.org'} = '';
  198. $selected{'SERVICE'}{'dyndns-custom'} = '';
  199. $selected{'SERVICE'}{'dyndns-static'} = '';
  200. $selected{'SERVICE'}{'dyns.cx'} = '';
  201. $selected{'SERVICE'}{'easydns.com'} = '';
  202. $selected{'SERVICE'}{'freedns-afraid.org'} = '';
  203. $selected{'SERVICE'}{'hn.org'} = '';
  204. $selected{'SERVICE'}{'no-ip.com'} = '';
  205. $selected{'SERVICE'}{'nsupdate'} = '';
  206. $selected{'SERVICE'}{'ovh.com'} = '';
  207. $selected{'SERVICE'}{'regfish.com'} = '';
  208. $selected{'SERVICE'}{'selfhost.de'} = '';
  209. $selected{'SERVICE'}{'tzo.com'} = '';
  210. $selected{'SERVICE'}{'zoneedit.com'} = '';
  211. $selected{'SERVICE'}{'all-inkl'} = '';
  212. $selected{'SERVICE'}{$cgiparams{'SERVICE'}} = "selected='selected'";
  213.  
  214. $checked{'PROXY'}{'off'} = '';
  215. $checked{'PROXY'}{'on'} = '';
  216. $checked{'PROXY'}{$cgiparams{'PROXY'}} = "checked='checked'";
  217.  
  218. $checked{'WILDCARDS'}{'off'} = '';
  219. $checked{'WILDCARDS'}{'on'} = '';
  220. $checked{'WILDCARDS'}{$cgiparams{'WILDCARDS'}} = "checked='checked'";
  221.  
  222. $checked{'ENABLED'}{'off'} = '';
  223. $checked{'ENABLED'}{'on'} = '';  
  224. $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'";
  225.  
  226. if( -e  "${swroot}/ddns/behindnat" )
  227. {
  228.     $checked{'BEHINDNAT'}{'on'} = "checked='checked'";
  229. }
  230.  
  231. &openpage(_('Dynamic DNS'), 1, '');
  232. &openbigbox($errormessage, $warnmessage, $notemessage);
  233.  
  234. if (scalar(@errormessages) > 0) {
  235.     #Stay in edit mode if we are in it
  236.     if ($cgiparams{'EDITING'} ne 'no') {
  237.         $cgiparams{'ACTION'} = 'edit';
  238.         $cgiparams{'ID'} = $cgiparams{'EDITING'};
  239.     }    
  240. }
  241.  
  242. &openbox('100%', 'left', _('Current hosts'));
  243.  
  244. # if ($cgiparams{'ACTION'} eq "edit") {
  245. #     $action = "edit";
  246. # }
  247. # else {
  248. #     $action = "add";
  249. # }
  250.  
  251. openeditorbox(_("Add a host"), _("Add a host"), ($cgiparams{'ACTION'} eq 'edit' || scalar(@errormessages) > 0 ? "showeditor" : ""), "hosts", @errormessages);
  252.  
  253. printf <<END
  254. <table width='100%'>
  255. <tr>
  256.     <td width='25%' class='base'>%s *</td>
  257.     <td width='25%'><select size='1' name='SERVICE'>
  258.             <option $selected{'SERVICE'}{'all-inkl'}>all-inkl</option>
  259.             <option $selected{'SERVICE'}{'dhs.org'}>dhs.org</option>
  260.             <option $selected{'SERVICE'}{'dyndns.org'}>dyndns.org</option>
  261.             <option $selected{'SERVICE'}{'dyndns-custom'}>dyndns-custom</option>
  262.             <option $selected{'SERVICE'}{'dyndns-static'}>dyndns-static</option>
  263.             <option $selected{'SERVICE'}{'dyns.cx'}>dyns.cx</option>
  264.             <option $selected{'SERVICE'}{'easydns.com'}>easydns.com</option>
  265.             <option $selected{'SERVICE'}{'freedns-afraid.org'}>freedns-afraid.org</option>
  266.             <option $selected{'SERVICE'}{'hn.org'}>hn.org</option>
  267.             <option $selected{'SERVICE'}{'no-ip.com'}>no-ip.com</option>
  268.             <option $selected{'SERVICE'}{'nsupdate'}>nsupdate</option>
  269.             <option $selected{'SERVICE'}{'ovh.com'}>ovh.com</option>
  270.             <option $selected{'SERVICE'}{'regfish.com'}>regfish.com</option>
  271.             <option $selected{'SERVICE'}{'selfhost.de'}>selfhost.de</option>
  272. <!--            <option $selected{'SERVICE'}{'tzo.com'}>tzo.com</option>    comment this service out until a working fix is developed -->
  273.             <option $selected{'SERVICE'}{'zoneedit.com'}>zoneedit.com</option>
  274.         </select></td>
  275.     <td width='25%' class='base'>%s <input type='checkbox' name='PROXY' value='on' $checked{'PROXY'}{'on'} /></td>
  276.     <td width='25%' class='base'>%s <input type='checkbox' name='WILDCARDS' value='on' $checked{'WILDCARDS'}{'on'} /></td>
  277. </tr>
  278. <tr>
  279.     <td class='base'>%s *</td>
  280.     <td><input type='text' name='HOSTNAME' value='$cgiparams{'HOSTNAME'}' /></td>
  281.     <td class='base'>%s *</td>
  282.     <td><input type='text' name='DOMAIN' value='$cgiparams{'DOMAIN'}' /></td>
  283. </tr>
  284. <tr>
  285.     <td class='base'>%s * <a href="http://kasapi.kasserver.com/dokumentation/">all-inkl docs</a></td>
  286.     <td><input type='text' name='KASID' value='$cgiparams{'KASID'}' /></td>
  287.     <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>
  288.     <td><input type='text' name='NAMESERVER' value='$cgiparams{'NAMESERVER'}' /></td>
  289. </tr>
  290. <tr>
  291.     <td class='base'>%s *</td>
  292.     <td><input type='text' name='LOGIN' value='$cgiparams{'LOGIN'}' /></td>
  293.     <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>
  294.     <td><input type='password' name='PASSWORD' value='$cgiparams{'PASSWORD'}' /></td>
  295. </tr>
  296. <tr>
  297.     <td class='base'>%s<input type='checkbox' name='BEHINDNAT' value='on' $checked{'BEHINDNAT'}{'on'} /></td>
  298.     <td>
  299.         %s<input type='checkbox' name='ENABLED' value='on' $checked{'ENABLED'}{'on'} />
  300.         <input type="hidden" name="ACTION" value="add"/>
  301.     </td>
  302. </tr>
  303. </table>
  304. END
  305. ,
  306. _('Service'),
  307. _('Behind a proxy'),
  308. _('Enable wildcards'),
  309. _('Hostname'),
  310. _('Domain'),
  311. _('Record_ID'),
  312. _('Nameserver'),
  313. _('Username'),
  314. _('Password'),
  315. _('behind Router(NAT)'),
  316. _('Enabled'),
  317. ;
  318.  
  319. if ($cgiparams{'ACTION'} eq 'edit') {
  320.     print "<input type='hidden' name='EDITING' value='$cgiparams{'ID'}' />\n";
  321. } else {
  322.     print "<input type='hidden' name='EDITING' value='no' />\n";
  323. }
  324.  
  325. &closeeditorbox(($cgiparams{'ACTION'} eq 'add' || $cgiparams{'ACTION'} eq 'edit' || scalar(@errormessages) > 0 ? _("Update Host") : _("Add Host")), _("Cancel"), "hostsbutton", "hosts", $ENV{'SCRIPT_NAME'});
  326.  
  327. printf <<END
  328. <table class="ruleslist" width='100%' cellpadding="0" cellspacing="0" border="0">
  329. <tr>
  330.     <th width='15%' class='boldbase'><b>%s</b></td>
  331.     <th width='20%' class='boldbase'><b>%s</b></td>
  332.     <th width='25%' class='boldbase'><b>%s</b></td>
  333.     <th width='8%' nowrap="nowrap" align='center' class='boldbase'><b>%s</b></td>
  334.     <th width='8%' class='boldbase'><b>%s</b></td>
  335.     <th width='8%' class='boldbase'><b>%s</b></td>
  336.     <th width='16%' class='boldbase' colspan='2'><b>%s</b></td>
  337. </tr>
  338. END
  339. ,
  340. _('Service'),
  341. _('Hostname'),
  342. _('Domain'),
  343. _('Anonymous web proxies'),
  344. _('Wildcards'),
  345. _('Enabled'),
  346. _('Actions')
  347. ;
  348.  
  349. my $id = 0;
  350. open(SETTINGS, "$filename") or die 'Unable to open config file.';
  351. while (<SETTINGS>)
  352. {
  353.     my ($gifproxy,$descproxy,$gifwildcards,$descwildcard,$gifenabled,$descenabled);
  354.     $id++;
  355.     chomp($_);
  356.     my @temp = split(/\,/,$_);
  357.     if ($cgiparams{'ACTION'} eq 'edit' && $cgiparams{'ID'} eq $id) {
  358.         print "<tr class='selected'>\n"; }
  359.     elsif ($id % 2) { print "<tr class='odd'>\n"; }
  360.     else { print "<tr class='even'>\n"; }
  361.     if ($temp[3] eq 'on') {
  362.         $gifproxy = 'on.png';
  363.         $descproxy = _('Enabled (click to disable)');
  364.     } else {
  365.         $gifproxy = 'off.png';
  366.         $descproxy = _('Disabled (click to enable)');
  367.     }
  368.     if ($temp[4] eq 'on') {
  369.         $gifwildcards = 'on.png';
  370.         $descwildcard = _('Enabled (click to disable)');
  371.     } else {
  372.         $gifwildcards = 'off.png';
  373.         $descwildcard = _('Disabled (click to enable)');
  374.     }
  375.     if ($temp[7] eq 'on') {
  376.         $gifenabled = 'on.png';
  377.         $descenabled = _('Enabled (click to disable)');
  378.     } else {
  379.         $gifenabled = 'off.png';
  380.         $descenabled = _('Disabled (click to enable)');
  381.     }
  382.  
  383. printf <<END
  384. <td>$temp[0]</td>
  385. <td>$temp[1]</td>
  386. <td>$temp[2]</td>
  387.  
  388. <form enctype='multipart/form-data' method='post' action='$ENV{'SCRIPT_NAME'}' name='frma$id'>
  389. <td class='center'>
  390.     <input class='imagebutton' type='image' src='/images/$gifproxy' alt='$descproxy' title='$descproxy' border='0'/>
  391.     <input type='hidden' name='ACTION' value='toggle' />
  392.     <input type='hidden' name='ID' value='$id' />
  393.     <input type='hidden' name='KEY1' value='proxy' />
  394. </td>
  395. </form>
  396.  
  397. <form enctype='multipart/form-data' method='post' action='$ENV{'SCRIPT_NAME'}' name='frmb$id'>
  398. <td class='center'>
  399.     <input class='imagebutton' type='image' src='/images/$gifwildcards' alt='$descwildcard' title='$descwildcard'/>
  400.     <input type='hidden' name='ACTION' value='toggle' />
  401.     <input type='hidden' name='ID' value='$id' />
  402.     <input type='hidden' name='KEY1' value='wildcard' />
  403. </td>
  404. </form>
  405.  
  406. <form enctype='multipart/form-data' method='post' action='$ENV{'SCRIPT_NAME'}' name='frmc$id'>
  407. <td class='center'>
  408.     <input class='imagebutton' type='image' src='/images/$gifenabled' alt='$descenabled' title='$descenabled'/>
  409.     <input type='hidden' name='ACTION' value='toggle' />
  410.     <input type='hidden' name='ID' value='$id' />
  411.     <input type='hidden' name='KEY1' value='enable' />
  412. </td>
  413. </form>
  414.  
  415. <td class='center'>
  416.     <form enctype='multipart/form-data' method='post' name='frmd$id' action='$ENV{'SCRIPT_NAME'}'>
  417.     <input class='imagebutton' type='image' name='%s' src='/images/edit.png' title='%s' alt='%s' />
  418.     <input type='hidden' name='ID' value='$id' />
  419.     <input type='hidden' name='ACTION' value='edit' />
  420.     </form>
  421. </td>
  422.  
  423. <td align='center'>
  424.     <form enctype='multipart/form-data' method='post' name='frme$id' action='$ENV{'SCRIPT_NAME'}'>
  425.     <input class='imagebutton' type='image' name='%s' src='/images/delete.png' title='%s' alt='%s' />
  426.     <input type='hidden' name='ID' value='$id' />
  427.     <input type='hidden' name='ACTION' value='remove' />
  428.     </form>
  429. </td>
  430.  
  431.  
  432. </tr>
  433. END
  434. ,
  435. _('Edit'),
  436. _('Edit'),
  437. _('Edit'),
  438. _('Remove'),
  439. _('Remove'),
  440. _('Remove')
  441. ;
  442. }
  443. close(SETTINGS);
  444. printf <<END
  445. </table>
  446. <form enctype='multipart/form-data' method='post' action='$ENV{'SCRIPT_NAME'}'>
  447. <input type='hidden' name='ACTION' value='forceupdate' />
  448. <table width='100%'>
  449. <tr>
  450. <td width='100%' align='center'><input class='submitbutton' type='submit' name='SUBMIT' value='%s' /></td>
  451. </tr>
  452. </table>
  453. </form>
  454. END
  455. , _('Force update')
  456. ;
  457.  
  458. # If the file contains entries, print Key to action icons
  459. if ( ! -z "$filename") {
  460. printf <<END
  461. <table class="list-legend" cellpadding="0" cellspacing="0" border="0">
  462. <tr>
  463.     <td class='boldbase'><b>%s:</b></td>
  464.     <td>&nbsp; <img src='/images/on.png' alt='%s' /></td>
  465.     <td class='base'>%s</td>
  466.     <td>&nbsp; &nbsp; <img src='/images/off.png' alt='%s' /></td>
  467.     <td class='base'>%s</td>
  468.     <td>&nbsp; &nbsp; <img src='/images/edit.png' alt='%s' /></td>
  469.     <td class='base'>%s</td>
  470.     <td>&nbsp; &nbsp; <img src='/images/delete.png' alt='%s' /></td>
  471.     <td class='base'>%s</td>
  472. </tr>
  473. </table>
  474. END
  475. ,
  476. _('Legend'),
  477. _('Enabled (click to disable)'),
  478. _('Enabled (click to disable)'),
  479. _('Disabled (click to enable)'),
  480. _('Disabled (click to enable)'),
  481. _('Edit'),
  482. _('Edit'),
  483. _('Remove'),
  484. _('Remove')
  485. ;
  486. }
  487.  
  488. &closebox();
  489.  
  490. &closebigbox();
  491.  
  492. &closepage();
  493.  
  494. ################################ setddns.pl #######################################
  495. #!/usr/bin/perl
  496. #
  497. # SmoothWall CGIs
  498. #
  499. # This code is distributed under the terms of the GPL
  500. #
  501. # (c) The SmoothWall Team
  502. #
  503. # $Id: setddns.pl,v 1.4.2.7 2004/10/12 16:36:10 alanh Exp $
  504. #
  505. # Modded to work with new ZoneEdit update URL - dynamic.zoneedit.com - By Darren Carter, www.citsystems.co.za. 2009/03/15
  506. # Modded to work with all-inkl.com update Url martinl; 22.08.2013
  507. #
  508. close(STDIN);
  509. close(STDOUT);
  510. close(STDERR);
  511.  
  512. use IO::Socket;
  513. require '/var/efw/header.pl';
  514.  
  515. my %settings;
  516. my %noipsettings;
  517. my $filename = "${swroot}/ddns/config";
  518. my $cachefile = "${swroot}/ddns/ipcache";
  519. my $ipcache = 0;
  520.  
  521. open(FILE, "$filename") or die 'Unable to open config file.';
  522. my @current = <FILE>;
  523. close(FILE);
  524. my $lines = $#current + 1;
  525. unless($lines) { exit 0; }
  526.  
  527. my $ip = '';
  528. if ( -f "${swroot}/ddns/behindnat" )
  529. {
  530.     $ip = `/usr/local/bin/detectip`;   
  531. } else {
  532.     if (-f "${swroot}/uplinks/main/data") {
  533.     my %conf_hash = ();
  534.     readhash("${swroot}/uplinks/main/data", \%conf_hash);
  535.     $ip = $conf_hash{'ip_address'};
  536.     }
  537. }
  538. chomp $ip;
  539. if ($ARGV[0] ne '-f')
  540. {
  541.     open(IPCACHE, "$cachefile");
  542.     $ipcache = <IPCACHE>;
  543.     close(IPCACHE);
  544.     chomp $ipcache;
  545. }
  546.  
  547. if ($ip ne $ipcache)
  548. {
  549.     my $id = 0;
  550.     my $success = 0;
  551.     my $line;
  552.  
  553.     foreach $line (@current)
  554.     {
  555.         $id++;
  556.         chomp($line);
  557.         my @temp = split(/\,/,$line);
  558.         unless ($temp[7] eq "off")
  559.         {
  560.             $settings{'SERVICE'} = $temp[0];
  561.             $settings{'HOSTNAME'} = $temp[1];
  562.             $settings{'DOMAIN'} = $temp[2];
  563.             $settings{'PROXY'} = $temp[3];
  564.             $settings{'WILDCARDS'} = $temp[4];
  565.             $settings{'LOGIN'} = $temp[5];
  566.             $settings{'PASSWORD'} = $temp[6];
  567.             $settings{'ENABLED'} = $temp[7];
  568.             $settings{'KASID'} = $temp[8];
  569.             $settings{'NAMESERVER'} = $temp[9];
  570.             my @service = split(/\./, "$settings{'SERVICE'}");
  571.             $settings{'SERVICE'} = "$service[0]";
  572.             if ($settings{'SERVICE'} eq 'no-ip')
  573.             {
  574.                 $noipsettings{'LOGIN'} = $settings{'LOGIN'};
  575.                 $noipsettings{'PASSWORD'} = $settings{'PASSWORD'};
  576.                 $noipsettings{'HOSTNAME'} = $settings{'HOSTNAME'};
  577.                 $noipsettings{'DOMAIN'} = $settings{'DOMAIN'};
  578.                 $noipsettings{'DAEMON'} = 'N';
  579.                 $noipsettings{'DEVICE'} = '';
  580.                 $noipsettings{'INTERVAL'} = '1';
  581.                 $noipsettings{'NAT'} = 'N';
  582.                 $noipsettings{'GROUP'} = '';
  583.                 if ($settings{'PROXY'} eq 'on') { $noipsettings{'PROXY'} = 'Y'; }
  584.                 else { $noipsettings{'PROXY'} = 'N'; }
  585.  
  586.                 &writehash("${swroot}/ddns/noipsettings", \%noipsettings);
  587.                 open(F, "${swroot}/ddns/noipsettings");
  588.                 my @unsorted = <F>;
  589.                 close(F);
  590.                 my @sorted = sort { $b cmp $a } @unsorted;
  591.                 open(F, ">${swroot}/ddns/noipsettings");
  592.                 flock F, 2;
  593.                 print F @sorted;
  594.                 close(F);
  595.  
  596. my @ddnscommand = ('/usr/bin/noip','-i',"$ip");
  597.                 my $result = system(@ddnscommand);
  598.                 if ( $result != 0) { &log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'}: failure"); }
  599.                 else
  600.                 {
  601.                     &log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'}: success");
  602.                     $success++;
  603.                 }
  604.             }
  605.             elsif ($settings{'SERVICE'} eq 'selfhost')
  606.             {
  607.                 my %proxysettings;
  608.                 &readhash("/usr/lib/efw/proxy/default/settings", \%proxysettings);
  609.                 if (-e "${swroot}/proxy/settings") {
  610.                     &readhash("${swroot}/proxy/settings", \%proxysettings);
  611.                 }
  612.                 my $peer = 'www.ns4you.de';
  613.                 my $peerport = 80;
  614.  
  615.                 if ($proxysettings{'UPSTREAM_ENABLED'} eq "on") {
  616.                     $peer = $proxysettings{'UPSTREAM_SERVER'};
  617.                     $peerport = $proxysettings{'UPSTREAM_PORT'};
  618.                 }
  619.  
  620.                 my $sock;
  621.                 unless($sock = new IO::Socket::INET (PeerAddr => $peer, PeerPort => $peerport, Proto => 'tcp', Timeout => 5)) {
  622.                     die "Could not connect to $peer:$peerport: $@";
  623.                     return 1;
  624.                 }
  625.  
  626.                     my $GET_CMD;
  627.                 $GET_CMD  = "GET http://www.ns4you.de/cgi-dns/dns.pl?$settings{'LOGIN'}&$settings{'PASSWORD'}&$ip HTTP/1.1\r\n";
  628.                 $GET_CMD .= "Host: www.ns4you.de\r\n";
  629.                 $GET_CMD .= "Connection: close\r\n\r\n";
  630.                 print $sock "$GET_CMD";
  631.  
  632.                 my $out = '';
  633.                 while(<$sock>) {
  634.                     $out .= $_;
  635.                 }
  636.                 close($sock);
  637.  
  638.                 if ( $out =~ m/<meta name="ns4you" title="error"/ ) {
  639.                     &log("Dynamic DNS ip-update ns4you failure");
  640.                 }
  641.                 else
  642.                 {
  643.                     $out =~ m/<meta name="ns4you" title="url" content="(.*)"/;
  644.                     &log("Dynamic DNS ip-update for $1: success");
  645.                     $success++;
  646.                 }
  647.             }
  648.             elsif ($settings{'SERVICE'} eq 'nsupdate') {
  649.                 # Fetch UI configurable values and assemble the host name.
  650.  
  651.                 my $hostName="$settings{'DOMAIN'}";
  652.                 if ($settings{'HOSTNAME'} ne "") {
  653.                     $hostName="$settings{'HOSTNAME'}.$hostName";
  654.                 }
  655.                 my $keyName=$settings{'LOGIN'};
  656.                 my $keySecret=$settings{'PASSWORD'};
  657.  
  658.                 # Use a relatively long TTL value to reduce load on DNS.
  659.                 # Some public Dynamic DNS servers use values around 4 hours,
  660.                 # some use values as low as 60 seconds.
  661.                 # XXX Maybe we could fetch the master value from the server
  662.                 # (not the timed-down version supplied by DNS cache)
  663.  
  664.                 my $timeToLive="3600";
  665.  
  666.                 # Internal setting that can be used to override the DNS server
  667.                 # where the update is applied. It can be of use when testing
  668.                 # against a private DNS server.
  669.  
  670.                 my $masterServer="";
  671.  
  672.                 # Prepare the nsupdate command script to remove and re-add the
  673.                 # updated A record for the domain.
  674.  
  675.                 my $cmdFile="/tmp/nsupdate-$hostName-commands";
  676.                 my $logFile="/tmp/nsupdate-$hostName-result";
  677.                 open(TF, ">$cmdFile");
  678.                 if ($masterServer ne "") {
  679.                     print TF "server $masterServer\n";
  680.                 }
  681.                 if ($keyName ne "" && $keySecret ne "") {
  682.                     print TF "key $keyName $keySecret\n";
  683.                 }
  684.                 print TF "update delete $hostName A\n";
  685.                 print TF "update add $hostName $timeToLive A $ip\n";
  686.                 print TF "send\n";
  687.                 close(TF);
  688.  
  689.                 # Run nsupdate with -v to use TCP instead of UDP because we're
  690.                 # issuing multiple cmds and potentially long keys, and -d to
  691.                 # get diagnostic result output.
  692.  
  693.                 my $result = system("/usr/bin/nsupdate -v -d $cmdFile 2>$logFile");
  694.                 if ($result != 0) {
  695.                     &log("Dynamic DNS ip-update for $hostName: failure");
  696.                     open(NSLOG, "$logFile");
  697.                     my @nsLog = <NSLOG>;
  698.                     close(NSLOG);
  699.                     my $logLine;
  700.                     foreach $logLine (@nsLog) {
  701.                         chomp($logLine);
  702.                         if ($logLine ne "") {
  703.                             &log("... $logLine");
  704.                         }
  705.                     }
  706.                 }
  707.                 else
  708.                 {
  709.                     &log("Dynamic DNS ip-update for $hostName: success");
  710.                     $success++;
  711.                 }
  712.  
  713.                 unlink $cmdFile, $logFile;
  714.             }
  715.             elsif ($settings{'SERVICE'} eq 'freedns-afraid')
  716.             {
  717.                 my %proxysettings;
  718.                 &readhash("/usr/lib/efw/proxy/default/settings", \%proxysettings);
  719.                 if (-e "${swroot}/proxy/settings") {
  720.                     &readhash("${swroot}/proxy/settings", \%proxysettings);
  721.                 }
  722.                 my $peer = 'freedns.afraid.org';
  723.                 my $peerport = 80;
  724.  
  725.                 if ($proxysettings{'UPSTREAM_ENABLED'} eq "on") {
  726.                     $peer = $proxysettings{'UPSTREAM_SERVER'};
  727.                     $peerport = $proxysettings{'UPSTREAM_PORT'};
  728.                 }
  729.  
  730.                 my $sock;
  731.                 unless($sock = new IO::Socket::INET (PeerAddr => $peer, PeerPort => $peerport, Proto => 'tcp', Timeout => 5)) {
  732.                     die "Could not connect to $peer:$peerport: $@";
  733.                     return 1;
  734.                 }
  735.  
  736.                     my $GET_CMD;
  737.                 $GET_CMD  = "GET http://freedns.afraid.org/dynamic/update.php?$settings{'LOGIN'} HTTP/1.1\r\n";
  738.                 $GET_CMD .= "Host: freedns.afraid.org\r\n";
  739.                 $GET_CMD .= "Connection: close\r\n\r\n";
  740.                 print $sock "$GET_CMD";
  741.  
  742.                 my $out = '';
  743.                 while(<$sock>) {
  744.                     $out .= $_;
  745.                 }
  746.                 close($sock);
  747.                
  748.                 #Valid responses from service are:
  749.                                 #Updated yourdomain.afraid.org to your IP
  750.                                 #Address <ip> has not changed.
  751.  
  752.                 if ( $out !~ m/(Updated|Address .* has not changed)/ig ) {
  753.                     #cleanup http response...
  754.                     $out =~ s/.+?\015?\012\015?\012//s;    # header HTTP
  755.                     @out = split("\r", $out);
  756.                     &log("Dynamic DNS afraid.org : failure (@out[1])");
  757.                 }
  758.                 else
  759.                 {
  760.                     &log("Dynamic DNS afraid.org : success");
  761.                     $success++;
  762.                 }
  763.             }
  764.             elsif ($settings{'SERVICE'} eq 'regfish')
  765.             {
  766.                 my %proxysettings;
  767.                 &readhash("/usr/lib/efw/proxy/default/settings", \%proxysettings);
  768.                 if (-e "${swroot}/proxy/settings") {
  769.                     &readhash("${swroot}/proxy/settings", \%proxysettings);
  770.                 }
  771.                 my $peer = 'www.regfish.com';
  772.                 my $peerport = 80;
  773.  
  774.                 if ($proxysettings{'UPSTREAM_ENABLED'} eq "on") {
  775.                     $peer = $proxysettings{'UPSTREAM_SERVER'};
  776.                     $peerport = $proxysettings{'UPSTREAM_PORT'};
  777.                 }
  778.  
  779.                 my $sock;
  780.                 unless($sock = new IO::Socket::INET (PeerAddr => $peer, PeerPort => $peerport, Proto => 'tcp', Timeout => 5)) {
  781.                     die "Could not connect to $peer:$peerport: $@";
  782.                     return 1;
  783.                 }
  784.  
  785.                     my $GET_CMD;
  786.                 $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";
  787.                 $GET_CMD .= "Host: www.regfish.com\r\n";
  788.                 $GET_CMD .= "Connection: close\r\n\r\n";
  789.                 print $sock "$GET_CMD";
  790.  
  791.                 my $out = '';
  792.                 while(<$sock>) {
  793.                     $out .= $_;
  794.                 }
  795.                 close($sock);
  796.                
  797.                 #Valid responses from service:
  798.                 #success|100|update succeeded!
  799.                 #success|101|no update needed at this time..
  800.  
  801.                 if ( $out !~ m/(success\|(100|101)\|)/ig ) {
  802.                     #cleanup http response...
  803.                     $out =~ s/.+?\015?\012\015?\012//s;    # header HTTP
  804.                     @out = split("\r", $out);
  805.                     &log("Dynamic DNS regfish.com : @out[1]");
  806.                 }
  807.                 else
  808.                 {
  809.                     &log("Dynamic DNS regfish.com : success");
  810.                     $success++;
  811.                 }
  812.             }
  813.             elsif ($settings{'SERVICE'} eq 'ovh')
  814.             {
  815.                 my %proxysettings;
  816.                 &readhash("/usr/lib/efw/proxy/default/settings", \%proxysettings);
  817.                 if (-e "${swroot}/proxy/settings") {
  818.                     &readhash("${swroot}/proxy/settings", \%proxysettings);
  819.                 }
  820.                 my $peer = 'www.ovh.com';
  821.                 my $peerport = 80;
  822.  
  823.                 if ($proxysettings{'UPSTREAM_ENABLED'} eq "on") {
  824.                     $peer = $proxysettings{'UPSTREAM_SERVER'};
  825.                     $peerport = $proxysettings{'UPSTREAM_PORT'};
  826.                 }
  827.  
  828.                 my $sock;
  829.                 unless($sock = new IO::Socket::INET (PeerAddr => $peer, PeerPort => $peerport, Proto => 'tcp', Timeout => 5)) {
  830.                     die "Could not connect to $peer:$peerport: $@";
  831.                     return 1;
  832.                 }
  833.  
  834.                 if ($settings{'HOSTNAME'} eq '') {
  835.                     $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
  836.                 }
  837.                 else {
  838.                     $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
  839.                 }
  840.  
  841.                 my $GET_CMD;
  842.                 $GET_CMD  = "GET http://www.ovh.com/nic/update?system=dyndns&hostname=$settings{'HOSTDOMAIN'}&myip=$ip HTTP/1.1\r\n";
  843.                 $GET_CMD .= "Host: www.ovh.com\r\n";
  844.                 chomp($code64 = encode_base64("$settings{'LOGIN'}:$settings{'PASSWORD'}"));
  845.                 $GET_CMD .= "Authorization: Basic $code64\r\n";
  846.                    #$GET_CMD .= "User-Agent: ipcop\r\n";
  847.                    #$GET_CMD .= "Content-Type: application/x-www-form-urlencoded\r\n";
  848.                 $GET_CMD .= "\r\n";
  849.                 print $sock "$GET_CMD";
  850.                 my $out = '';
  851.                 while(<$sock>) {
  852.                     $out .= $_;
  853.                 }
  854.                 close($sock);
  855.  
  856.                                 #HTTP response => error (in  Title tag) else text response
  857.                     #Valid responses from service:good,nochg  (ez-ipupdate like)
  858.                 #Should use ez-ipdate but "system=dyndns" is not present
  859.                 if ( $out =~ m/<Title>(.*)<\/Title>/ig ) {
  860.                     &log("Dynamic DNS ovh.com : failure ($1)");
  861.                 }
  862.                 elsif ($out !~ m/good |nochg /ig) {
  863.                     $out =~ s/.+?\015?\012\015?\012//s;    # header HTTP
  864.                     @out = split("\r", $out);
  865.                     &log("Dynamic DNS ovh.com : failure ($out[1])");
  866.                 }
  867.                 else {
  868.                         &log("Dynamic DNS ovh.com : success");
  869.                     $success++;
  870.                 }
  871.             }
  872.             elsif ($settings{'SERVICE'} eq 'all-inkl')
  873.             {
  874.                 my %proxysettings;
  875.                 &readhash("/usr/lib/efw/proxy/default/settings", \%proxysettings);
  876.                 if (-e "${swroot}/proxy/settings") {
  877.                     &readhash("${swroot}/proxy/settings", \%proxysettings);
  878.                 }
  879.                 my $peer = 'kasapi.kasserver.com';
  880.                 my $peerport = 80;
  881.  
  882.                 if ($proxysettings{'UPSTREAM_ENABLED'} eq "on") {
  883.                     $peer = $proxysettings{'UPSTREAM_SERVER'};
  884.                     $peerport = $proxysettings{'UPSTREAM_PORT'};
  885.                 }
  886.                 my $sock;
  887.                 unless($sock = new IO::Socket::INET (PeerAddr => $peer, PeerPort => $peerport, Proto => 'tcp', Timeout => 5)) {
  888.                     die "Could not connect to $peer:$peerport: $@";
  889.                     return 1;
  890.                 }
  891.                 # convert password to SHA1 HEX
  892.                 use Digest::SHA1    qw/ sha1_hex /;
  893.                 $shapass = &sha1_hex($settings{'PASSWORD'});
  894.                 # Multi Domain Time-Protector if more than on Domain
  895.                 sleep(2);
  896.                 my $GET_CMD;
  897.                 $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
  898. HTTP/1.1\r\n";
  899.                 $GET_CMD .= "Connection: close\r\n\r\n";
  900.                 print $sock "$GET_CMD";
  901.                 my $out = '';
  902.                 while(<$sock>) {
  903.                     &log ($out .= $_);
  904.                 }
  905.                 close($sock);
  906.                 $hostname = $settings{'HOSTNAME'};
  907.                 $domain = $settings{'DOMAIN'};
  908.                 use Sys::Syslog;
  909.                 openlog "noip", "cons.pid", "local3";
  910.                 print $out;
  911.                 if ($out =~ m/TRUE/)
  912.                 {
  913.                     syslog ('news|notice', "Dynamic DNS Update ".$hostname.".".$domain." succeeded - IP:".$ip." updated");
  914.                     closelog;
  915.                 }
  916.                 elsif ($out =~ m/nothing_to_do/)
  917.                 {
  918.                     syslog ('news|notice', "Dynamic DNS Update ".$hostname.".".$domain." is up to date!");
  919.                     closelog;
  920.                 }
  921.                 else
  922.                 {
  923.                     syslog ('news|notice', "Dynamic DNS Update ".$hostname.".".$domain." failed! /n".$out."/n");
  924.                     closelog;
  925.                 }
  926.             }
  927.             else
  928.             {
  929.                 if ($settings{'WILDCARDS'} eq 'on') {$settings{'WILDCARDS'} = '-w';}
  930.                 else {$settings{'WILDCARDS'} = '';}
  931.  
  932.                 if ($settings{'SERVICE'} eq 'dyndns-custom' && $settings{'HOSTNAME'} eq '') {$settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};}
  933.                 else {$settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";}
  934.  
  935.                 if ($settings{'SERVICE'} eq 'zoneedit') {$serverdir = '-s'; $serveradd = 'dynamic.zoneedit.com';}
  936.                 else {$serverdir = ''; $serveradd = '';}
  937.            
  938.                 my @ddnscommand = ('/usr/bin/ez-ipupdate', '-a', "$ip", '-S', "$settings{'SERVICE'}", "$serverdir", "$serveradd", '-u', "$settings{'LOGIN'}:$settings{'PASSWORD'}", '-h', "$settings{'HOSTDOMAIN'}", "$settings{'WILDCARDS'}", '-q');
  939.  
  940.                 my $result = system(@ddnscommand);
  941.                 if ( $result != 0) { &log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'}: failure"); }
  942.                 else
  943.                 {
  944.                     &log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'}: success");
  945.                     $success++;
  946.                 }
  947.             }
  948.         }
  949.         else
  950.         {
  951.             # If a line is disabled, then we should discount it
  952.             $lines--;
  953.         }
  954.     }
  955.  
  956.     if ($lines == $success)
  957.     {
  958.         open(IPCACHE, ">$cachefile");
  959.         flock IPCACHE, 2;
  960.         print IPCACHE $ip;
  961.         close(IPCACHE);
  962.     }
  963. }
  964.  
  965. # Extracted from Base64.pm
  966. sub encode_base64 ($;$)
  967. {
  968.     my $res = "";
  969.     my $eol = $_[1];
  970.     $eol = "\n" unless defined $eol;
  971.     pos($_[0]) = 0;                          # ensure start at the beginning
  972.     while ($_[0] =~ /(.{1,45})/gs) {
  973.         $res .= substr(pack('u', $1), 1);
  974.         chomp($res);
  975.     }
  976.     $res =~ tr|` -_|AA-Za-z0-9+/|;               # `# help emacs
  977.     # fix padding at the end
  978.     my $padding = (3 - length($_[0]) % 3) % 3;
  979.     $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
  980.     # break encoded string into lines of no more than 76 characters each
  981.     if (length $eol) {
  982.         $res =~ s/(.{1,76})/$1$eol/g;
  983.     }
  984.     $res;
  985. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement