]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/ddns.cgi
Merge remote-tracking branch 'dweismueller/owncloud-7' into next
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / ddns.cgi
index 43ee95275a7f2f92f07f036269b117365defb237..aeb0cd733296b44005edcffb3648977b088f6943 100644 (file)
@@ -47,7 +47,7 @@ my $datafile = "${General::swroot}/ddns/config";
 # Dynamic ddns programm call.
 my @ddnsprog = ("/usr/bin/ddns", "--config",
                "/var/ipfire/ddns/ddns.conf",
-               "update-all", "--force" );
+               "update-all");
 
 my %settings=();
 my $errormessage = '';
@@ -62,11 +62,19 @@ $settings{'LOGIN'} = '';
 $settings{'PASSWORD'} = '';
 $settings{'ENABLED'} = '';
 $settings{'PROXY'} = '';
-$settings{'WILDCARDS'} = '';
 $settings{'SERVICE'} = '';
 
 $settings{'ACTION'} = '';
 
+# Get supported ddns providers.
+my @providers = &GetProviders();
+
+# Hook to regenerate the configuration files, if cgi got called from command line.
+if ($ENV{"REMOTE_ADDR"} eq "") {
+       &GenerateDDNSConfigFile();
+       exit(0);
+}
+
 &Header::showhttpheaders();
 
 #Get GUI values
@@ -77,9 +85,6 @@ open(FILE, "$datafile") or die "Unable to open $datafile.";
 my @current = <FILE>;
 close (FILE);
 
-# Get supported ddns providers.
-my @providers = &GetProviders();
-
 #
 # Save General Settings.
 #
@@ -136,11 +141,6 @@ if ($settings{'ACTION'} eq $Lang::tr{'toggle enable disable'}) {
 
                                # Update ENABLED.
                                print FILE "$temp[0],$temp[1],$temp[2],$temp[3],$temp[4],$temp[5],$temp[6],$settings{'ENABLED'}\n";
-
-                       } elsif ($settings{'WILDCARDS'} ne '') {
-
-                               # Update WILDCARDS.
-                               print FILE "$temp[0],$temp[1],$temp[2],$temp[3],$settings{'WILDCARDS'},$temp[5],$temp[6],$temp[7]\n";
                        }
                } else {
 
@@ -170,8 +170,6 @@ if ($settings{'ACTION'} eq $Lang::tr{'toggle enable disable'}) {
 #
 if (($settings{'ACTION'} eq $Lang::tr{'add'}) || ($settings{'ACTION'} eq $Lang::tr{'update'})) {
 
-       # XXX TODO: Check for provider which supports wildcards.
-
        # Check if a hostname has been given.
        if ($settings{'HOSTNAME'} eq '') {
                $errormessage = $Lang::tr{'hostname not set'};
@@ -316,8 +314,17 @@ if ($settings{'ACTION'} eq $Lang::tr{'edit'}) {
                        # Splitt lines (splitting element is a single ",") and save values into temp array.
                        @temp = split(/\,/,$line);
 
+                       # Handle hostname details. Only connect the values with a dott if both are available.
+                       my $hostname;
+
+                       if (($temp[1]) && ($temp[2])) {
+                               $hostname = "$temp[1].$temp[2]";
+                       } else {
+                               $hostname = "$temp[1]";
+                       }
+
                        $settings{'SERVICE'} = $temp[0];
-                       $settings{'HOSTNAME'} = "$temp[1].$temp[2]";
+                       $settings{'HOSTNAME'} = $hostname;
                        $settings{'PROXY'} = $temp[3];
                        $settings{'WILDCARDS'} = $temp[4];
                        $settings{'LOGIN'} = $temp[5];
@@ -356,7 +363,6 @@ $checked{'BEHINDROUTER'}{'RED_IP'} = '';
 $checked{'BEHINDROUTER'}{'FETCH_IP'} = '';
 $checked{'BEHINDROUTER'}{$settings{'BEHINDROUTER'}} = "checked='checked'";
 
-$checked{'WILDCARDS'}{'on'} = ($settings{'WILDCARDS'} eq '') ? '' : "checked='checked'";
 $checked{'ENABLED'}{'on'} = ($settings{'ENABLED'} eq '' ) ? '' : "checked='checked'";
 
 # Show box for errormessages..
@@ -453,9 +459,9 @@ print <<END
        </tr>
 
        <tr>
-               <td class='base'>$Lang::tr{'enable wildcards'}</td>
-               <td><input type='checkbox' name='WILDCARDS' value='on' $checked{'WILDCARDS'}{'on'} /></td>
-               <td class='base'>$Lang::tr{'username'}:</td>
+               <td class='base'>$Lang::tr{'enabled'}</td>
+               <td><input type='checkbox' name='ENABLED' value='on' $checked{'ENABLED'}{'on'} /></td>
+               <td class='base'>$Lang::tr{'username'}</td>
                <td><input type='text' name='LOGIN' value='$settings{'LOGIN'}' /></td>
        </tr>
 
@@ -465,13 +471,6 @@ print <<END
                <td class='base'>$Lang::tr{'password'}</td>
                <td><input type='password' name='PASSWORD' value='$settings{'PASSWORD'}' /></td>
        </tr>
-
-       <tr>
-               <td class='base'>$Lang::tr{'enabled'}</td>
-               <td><input type='checkbox' name='ENABLED' value='on' $checked{'ENABLED'}{'on'} /></td>
-               <td class='base'></td>
-               <td></td>
-       </tr>
 </table>
 <br>
 <hr>
@@ -490,92 +489,76 @@ END
 
 ##
 # Third section, display all created ddns hosts.
-
-&Header::openbox('100%', 'left', $Lang::tr{'current hosts'});
-print <<END
-<table width='100%' class='tbl'>
-       <tr>
-               <th width='15%' align='center' class='boldbase'><b>$Lang::tr{'service'}</b></th>
-               <th width='25%' align='center' class='boldbase'><b>$Lang::tr{'hostname'}</b></th>
-               <th width='30%' align='center' class='boldbase'><b>$Lang::tr{'domain'}</b></th>
-               <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'wildcards'}</b></th>
-               <th width='20%' colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></th>
-       </tr>
-END
-;
-
 # Re-open file to get changes.
 open(FILE, $datafile) or die "Unable to open $datafile.";
 @current = <FILE>;
 close(FILE);
 
 # Get IP address of the red interface.
-my $ip = &General::GetDyndnsRedIP;
+my $ip = &General::GetDyndnsRedIP();
 my $id = 0;
 my $toggle_enabled;
-my $toggle_wildcards;
 
-foreach my $line (@current) {
+if (@current) {
+       &Header::openbox('100%', 'left', $Lang::tr{'current hosts'});
 
-       # Remove newlines.
-       chomp(@current);
-       my @temp = split(/\,/,$line);
+       print <<END;
+<table width='100%' class='tbl'>
+       <tr>
+               <th width='30%' align='center' class='boldbase'><b>$Lang::tr{'service'}</b></th>
+               <th width='50%' align='center' class='boldbase'><b>$Lang::tr{'hostname'}</b></th>
+               <th width='20%' colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></th>
+       </tr>
+END
 
-       # Generate checkbox icons for wildcard.
-       my $gifwildcard='';
-       my $descwildcard='';
-       if ($temp[4] eq "on") {
-               $gifwildcard = 'on.gif';
-               $descwildcard = $Lang::tr{'click to disable'};
-               $toggle_wildcards = 'off';
-       } else {
-               $gifwildcard = 'off.gif';
-               $descwildcard = $Lang::tr{'click to enable'};
-               $toggle_wildcards = 'on';
-       }
+       foreach my $line (@current) {
+               # Remove newlines.
+               chomp(@current);
+               my @temp = split(/\,/,$line);
+
+               # Generate value for enable/disable checkbox.
+               my $sync = "<font color='blue'>";
+               my $gif = '';
+               my $gdesc = '';
+
+               if ($temp[7] eq "on") {
+                       $gif = 'on.gif';
+                       $gdesc = $Lang::tr{'click to disable'};
+                       $sync = (&General::DyndnsServiceSync ($ip,$temp[1], $temp[2]) ? "<font color='green'>": "<font color='red'>") ;
+                       $toggle_enabled = 'off';
+               } else {
+                       $gif = 'off.gif';
+                       $gdesc = $Lang::tr{'click to enable'};
+                       $toggle_enabled = 'on';
+               }
 
-       # Generate value for enable/disable checkbox.
-       my $sync = "<font color='blue'>";
-       my $gif = '';
-       my $gdesc = '';
+               # Background color.
+               my $col="";
 
-       if ($temp[7] eq "on") {
-               $gif = 'on.gif';
-               $gdesc = $Lang::tr{'click to disable'};
-               $sync = (&General::DyndnsServiceSync ($ip,$temp[1], $temp[2]) ? "<font color='green'>": "<font color='red'>") ;
-               $toggle_enabled = 'off';
-       } else {
-               $gif = 'off.gif';
-               $gdesc = $Lang::tr{'click to enable'};
-               $toggle_enabled = 'on';
-       }
+               if ($settings{'ID'} eq $id) {
+                       $col="bgcolor='${Header::colouryellow}'";
+               } elsif (!($temp[0] ~~ @providers)) {
+                       $col="bgcolor='#FF4D4D'";
+               } elsif ($id % 2) {
+                       $col="bgcolor='$color{'color20'}'";
+               } else {
+                       $col="bgcolor='$color{'color22'}'";
+               }
 
-       # Background color.
-       my $col="";
+               # Handle hostname details. Only connect the values with a dott if both are available.
+               my $hostname="";
 
-       if ($settings{'ID'} eq $id) {
-               $col="bgcolor='${Header::colouryellow}'";
-       } elsif (!&General::is_part_of("$temp[0]", @providers)) {
-               $col="bgcolor='#FF4D4D'";
-       } elsif ($id % 2) {
-               $col="bgcolor='$color{'color20'}'";
-       } else {
-               $col="bgcolor='$color{'color22'}'";
-       }
+               if (($temp[1]) && ($temp[2])) {
+                       $hostname="$temp[1].$temp[2]";
+               } else {
+                       $hostname="$temp[1]";
+               }
 
-# The following HTML Code still is part of the loop.
-print <<END
+               # The following HTML Code still is part of the loop.
+               print <<END;
 <tr>
        <td align='center' $col><a href='http://$temp[0]'>$temp[0]</a></td>
-       <td align='center' $col>$sync$temp[1]</td>
-       <td align='center' $col>$sync$temp[2]</td>
-
-       <td align='center' $col><form method='post' action='$ENV{'SCRIPT_NAME'}'>
-               <input type='hidden' name='ID' value='$id'>
-               <input type='hidden' name='WILDCARDS' value='$toggle_wildcards'>
-               <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
-               <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gifwildcard' alt='$descwildcard' title='$descwildcard' />
-       </form></td>
+       <td align='center' $col>$sync$hostname</td>
 
        <td align='center' $col><form method='post' action='$ENV{'SCRIPT_NAME'}'>
                <input type='hidden' name='ID' value='$id'>
@@ -597,14 +580,11 @@ print <<END
        </form></td>
 </tr>
 END
-;
-    $id++;
-}
-print "</table>";
+               $id++;
+       }
 
-# If table contains entries, print 'Key to action icons'
-if ($id) {
-print <<END
+       print <<END;
+</table>
 <table width='100%'>
        <tr>
                <td class='boldbase'>&nbsp;<b>$Lang::tr{'legend'}:&nbsp;</b></td>
@@ -625,10 +605,10 @@ print <<END
        </tr>
 </table>
 END
-;
+
+       &Header::closebox();
 }
 
-&Header::closebox();
 &Header::closebigbox();
 &Header::closepage();
 
@@ -674,36 +654,57 @@ sub GenerateDDNSConfigFile {
                my ($provider, $hostname, $domain, $proxy, $wildcards, $username, $password, $enabled) = @settings;
 
                # Skip entries if they are not (longer) supported.
-               next if (!&General::is_part_of("$provider", @providers));
+               next unless ($provider ~~ @providers);
 
                # Skip disabled entries.
                next if ($enabled eq "off");
 
-               print FILE "[$hostname.$domain]\n";
+               # Handle hostname details. Only connect the values with a dott if both are available.
+               if (($hostname) && ($domain)) {
+                       print FILE "[$hostname.$domain]\n";
+               } else {
+                       print FILE "[$hostname]\n";
+               }
+
                print FILE "provider = $provider\n";
 
                my $use_token = 0;
 
                # Handle token based auth for various providers.
-               if ($provider ~~ ["dns.lightningwirelabs.com", "regfish.com"] && $username eq "token") {
+               if ($provider ~~ ["dns.lightningwirelabs.com", "entrydns.net", "regfish.com"] && $username eq "token") {
                        $use_token = 1;
 
                # Handle token auth for freedns.afraid.org.
                } elsif ($provider eq "freedns.afraid.org" && $password eq "") {
                        $use_token = 1;
                        $password = $username;
+
+               # Handle keys for nsupdate
+               } elsif (($provider eq "nsupdate") && $username && $password) {
+                       print FILE "key = $username\n";
+                       print FILE "secret = $password\n";
+
+                       $username = "";
+                       $password = "";
+
+               # Handle keys for nsupdate.info
+               } elsif (($provider eq "nsupdate.info") && $password) {
+                       print FILE "secret = $password\n";
+
+                       $username = "";
+                       $password = "";
                }
 
                # Write auth details.
                if ($use_token) {
                        print FILE "token = $password\n";
-               } else {
+               } elsif ($username && $password) {
                        print FILE "username = $username\n";
                        print FILE "password = $password\n";
                }
 
                # These providers need to be set to only use IPv4.
-               if ($provider ~~ ["freedns.afraid.org", "variomedia.de", "zoneedit.com"]) {
+               if ($provider ~~ ["freedns.afraid.org", "nsupdate.info", "opendns.com", "variomedia.de", "zoneedit.com"]) {
                        print FILE "proto = ipv4\n";
                }