]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/ddns.cgi
ddns.cgi: Hide listing if no entries exist.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / ddns.cgi
index a12ac00a2c801fb63b65bf8ed98ce8bd7c0b08a0..ada92c0529d853e74c3b07208bc67f7d1f8a24e4 100644 (file)
@@ -29,6 +29,12 @@ require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
 
+# Hook to regenerate the configuration files, if cgi got called from command line.
+if ($ENV{"REMOTE_ADDR"} eq "") {
+       &GenerateDDNSConfigFile();
+       exit(0);
+}
+
 #workaround to suppress a warning when a variable is used only once
 my @dummy = ( ${Header::table2colour}, ${Header::colouryellow} );
 undef (@dummy);
@@ -444,9 +450,9 @@ print <<END
        </tr>
 
        <tr>
-               <td class='base'></td>
-               <td></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>
 
@@ -456,13 +462,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>
@@ -481,65 +480,64 @@ 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='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
-;
-
 # 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;
 
-foreach my $line (@current) {
-
-       # Remove newlines.
-       chomp(@current);
-       my @temp = split(/\,/,$line);
+if (@current) {
+       &Header::openbox('100%', 'left', $Lang::tr{'current hosts'});
 
-       # Generate value for enable/disable checkbox.
-       my $sync = "<font color='blue'>";
-       my $gif = '';
-       my $gdesc = '';
+       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
 
-       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';
-       }
+       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';
+               }
 
-       # Background color.
-       my $col="";
+               # Background color.
+               my $col="";
 
-       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 ($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'}'";
+               }
 
-# 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].$sync$temp[2]</td>
@@ -564,14 +562,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>
@@ -592,10 +587,10 @@ print <<END
        </tr>
 </table>
 END
-;
+
+       &Header::closebox();
 }
 
-&Header::closebox();
 &Header::closebigbox();
 &Header::closepage();
 
@@ -659,18 +654,33 @@ sub GenerateDDNSConfigFile {
                } 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", "variomedia.de", "zoneedit.com"]) {
                        print FILE "proto = ipv4\n";
                }