]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - html/cgi-bin/dhcp.cgi
Merge branch 'next' of ssh://git.ipfire.org/pub/git/ipfire-2.x into next
[ipfire-2.x.git] / html / cgi-bin / dhcp.cgi
index 1ccaa400310bbd3325e0e8e1cb263686ef003909..dd48d58cb0d5cca8347e3ce93ca7361c6d48dc77 100644 (file)
@@ -1,29 +1,29 @@
 #!/usr/bin/perl
-#
-# SmoothWall CGIs
-#
-# This code is distributed under the terms of the GPL
-#
-# (c) The SmoothWall Team
-#
-# Copyright (C) 01-02-2002 Graham Smith <grhm@grhm.co.uk>
-#              - Fixed DHCP Leases added
-#
-# $Id: dhcp.cgi,v 1.14.2.81 2006/01/20 12:05:29 franck78 Exp $
-#
-#  Franck      -rewrite for two or more interface
-#  nov/2004    -check range is in correct subnet
-#              -add NTP option
-#              -add display sorting of actives leases
-#  dec/2004    -add comment field to fixed leases
-# 
-# to do : choose a correct format for displaying dates
-#
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2007  Michael Tremer & Christian Schmidt                      #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
 use strict;
 
 # enable only the following on debugging purpose
-use warnings;
-use CGI::Carp 'fatalsToBrowser';
+#use warnings;
+#use CGI::Carp 'fatalsToBrowser';
 
 require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/lang.pl";
@@ -44,12 +44,14 @@ our $filename3 = "${General::swroot}/dhcp/advoptions-list"; # Describe the allow
 my $errormessage = '';
 my $warnNTPmessage = '';
 my @nosaved=();
+my %color = ();
 
 #Basic syntax allowed for new Option definition. Not implemented: RECORDS & array of RECORDS 
 our $OptionTypes = 'boolean|((un)?signed )?integer (8|16|32)|ip-address|text|string|encapsulate \w+|array of ip-address';
 
 &Header::showhttpheaders();
-our @ITFs=('GREEN','BLUE');
+our @ITFs=('GREEN');
+if (&Header::blue_used()){push(@ITFs,'BLUE');}
 
 #Settings1 for the first screen box
 foreach my $itf (@ITFs) {
@@ -101,6 +103,7 @@ foreach my $itf (@ITFs) {
 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
 &General::readhash("${General::swroot}/time/settings", \%timesettings);
+&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
 
 #Get GUI values
 &Header::getcgihash(\%dhcpsettings);
@@ -435,6 +438,9 @@ if ($dhcpsettings{'ACTION'} eq $Lang::tr{'add'}.'2') {
        if ($dhcpsettings{'KEY2'} eq '') { #add or edit ?
            unshift (@current2, "$dhcpsettings{'FIX_MAC'},$dhcpsettings{'FIX_ADDR'},$dhcpsettings{'FIX_ENABLED'},$dhcpsettings{'FIX_NEXTADDR'},$dhcpsettings{'FIX_FILENAME'},$dhcpsettings{'FIX_ROOTPATH'},$dhcpsettings{'FIX_REMARK'}\n");
            &General::log($Lang::tr{'fixed ip lease added'});
+
+           # Enter edit mode
+           $dhcpsettings{'KEY2'} = $key;
        } else {
            @current2[$dhcpsettings{'KEY2'}] = "$dhcpsettings{'FIX_MAC'},$dhcpsettings{'FIX_ADDR'},$dhcpsettings{'FIX_ENABLED'},$dhcpsettings{'FIX_NEXTADDR'},$dhcpsettings{'FIX_FILENAME'},$dhcpsettings{'FIX_ROOTPATH'},$dhcpsettings{'FIX_REMARK'}\n";
            $dhcpsettings{'KEY2'} = '';       # End edit mode
@@ -541,9 +547,9 @@ print <<END
     <input type='checkbox' name='ENABLE_${itf}' $checked{'ENABLE'}{'on'} /></td>
     <td width='25%' class='base'>$Lang::tr{'ip address'}<br />$Lang::tr{'netmask'}:</td><td><b>$netsettings{"${itf}_ADDRESS"}<br />$netsettings{"${itf}_NETMASK"}</b></td>
 </tr><tr>
-    <td width='25%' class='base'>$Lang::tr{'start address'}&nbsp;<img src='/blob.gif' alt='*' /></td>
+    <td width='25%' class='base'>$Lang::tr{'start address'}</td>
     <td width='25%'><input type='text' name='START_ADDR_${itf}' value='$dhcpsettings{"START_ADDR_${itf}"}' /></td>
-    <td width='25%' class='base'>$Lang::tr{'end address'}&nbsp;<img src='/blob.gif' alt='*' /></td>
+    <td width='25%' class='base'>$Lang::tr{'end address'}</td>
     <td width='25%'><input type='text' name='END_ADDR_${itf}' value='$dhcpsettings{"END_ADDR_${itf}"}' /></td>
 </tr><tr>
     <td class='base'>$Lang::tr{'default lease time'}</td>
@@ -587,8 +593,7 @@ print <<END
 <tr>
     <td class='base' width='25%'><img src='/blob.gif' align='top' alt='*' />&nbsp;$Lang::tr{'this field may be blank'}</td>
     <td class='base' width='30%'>$warnNTPmessage</td>
-    <td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
-    <td width='5%' align='right'>&nbsp;</td>
+    <td width='40%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
 </tr>
 </table>
 </form>
@@ -648,7 +653,7 @@ print <<END
 <table width='100%'>
 <tr>
     <td class='base' width='50%'><img src='/blob.gif' align='top' alt='*' />&nbsp;$Lang::tr{'dhcp advopt scope help'}</td>
-    <td width='50%' align='center'>
+    <td width='50%' align='right'>
     <input type='hidden' name='ACTION' value='$Lang::tr{'add'}1' />
     <input type='submit' name='SUBMIT' value='$buttontext' />
     <input type='submit' name='SUBMIT' value='$Lang::tr{'dhcp advopt help'}' />
@@ -720,9 +725,9 @@ foreach my $line (@current1) {
     if ($dhcpsettings{'KEY1'} eq $key) {
        print "<tr bgcolor='${Header::colouryellow}'>";
     } elsif ($key % 2) {
-       print "<tr bgcolor='${Header::table2colour}'>";
+       print "<tr bgcolor='$color{'color22'}'>";
     } else {
-       print "<tr bgcolor='${Header::table1colour}'>"; 
+       print "<tr bgcolor='$color{'color20'}'>"; 
     }
 
     print <<END
@@ -848,28 +853,47 @@ print <<END
 <table width='100%'>
 <tr>
     <td class='base' width='50%'><img src='/blob.gif' align='top' alt='*' />&nbsp;$Lang::tr{'this field may be blank'}</td>
-    <td width='50%' align='center'>
+    <td width='50%' align='right'>
        <input type='hidden' name='ACTION' value='$Lang::tr{'add'}2' />
        <input type='submit' name='SUBMIT' value='$buttontext' />
        <input type='hidden' name='KEY2' value='$dhcpsettings{'KEY2'}' /></td>
 </tr>
 </table>
 </form>
+<hr />
 END
 ;
 #Edited line number (KEY2) passed until cleared by 'save' or 'remove' or 'new sort order'
 
+# Search for static leases
+my $search_query = $dhcpsettings{'q'};
+
+if (scalar @current2 >= 10) {
+       print <<END;
+               <form method="POST" action="#search">
+                       <a name="search"></a>
+                       <table width='100%'>
+                               <tr>
+                                       <td>
+                                               <input type="text" name="q" value="$search_query">
+                                               <input type="submit" value="$Lang::tr{'search'}">
+                                       </td>
+                               </tr>
+                       </table>
+               </form>
+END
+}
+
 print <<END
-<hr />
-<table width='100%'>
+<table width='100%' class='tbl'>
 <tr>
-    <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FETHER'><b>$Lang::tr{'mac address'}</b></a></td>
-    <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FIPADDR'><b>$Lang::tr{'ip address'}</b></a></td>
-    <td width='15%' align='center'><b>$Lang::tr{'remark'}</b></td>
-    <td width='15%' class='boldbase' align='center'><b>next-server</b></td>
-    <td width='15%' class='boldbase' align='center'><b>filename</b></td>
-    <td width='15%' class='boldbase' align='center'><b>root path</b></td>
-    <td colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></td>
+    <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FETHER'><b>$Lang::tr{'mac address'}</b></a></th>
+    <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FIPADDR'><b>$Lang::tr{'ip address'}</b></a></th>
+    <th width='15%' align='center'><b>$Lang::tr{'remark'}</b></th>
+    <th width='15%' class='boldbase' align='center'><b>next-server</b></th>
+    <th width='15%' class='boldbase' align='center'><b>filename</b></th>
+    <th width='15%' class='boldbase' align='center'><b>root path</b></th>
+    <th colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></th>
 </tr>
 END
 ;
@@ -901,6 +925,7 @@ foreach my $line (@current2) {
 }
 
 $key = 0;
+my $col="";
 foreach my $line (@current2) {
     my $gif = '';
     my $gdesc = '';
@@ -915,12 +940,20 @@ foreach my $line (@current2) {
        $gdesc = $Lang::tr{'click to enable'}; 
     }
 
+    # Skip all entries that do not match the search query
+    if ($search_query ne "") {
+       next if (!grep(/$search_query/, @temp));
+    }
+
     if ($dhcpsettings{'KEY2'} eq $key) {
-       print "<tr bgcolor='${Header::colouryellow}'>";
+       print "<tr>";
+       $col="bgcolor='${Header::colouryellow}'";
     } elsif ($key % 2) {
-       print "<tr bgcolor='${Header::table2colour}'>";
+       print "<tr>";
+       $col="bgcolor='$color{'color20'}'";
     } else {
-       print "<tr bgcolor='${Header::table1colour}'>"; 
+       print "<tr>";
+       $col="bgcolor='$color{'color22'}'";
     }
     my $TAG0 = '';
     my $TAG1 = '';
@@ -940,14 +973,14 @@ foreach my $line (@current2) {
     }
 
     print <<END
-<td align='center'>$TAG2$temp[0]$TAG3</td>
-<td align='center' $TAG4>$TAG0$temp[1]$TAG1</td>
-<td align='center'>$temp[6]&nbsp;</td>
-<td align='center'>$temp[3]&nbsp;</td>
-<td align='center'>$temp[4]&nbsp;</td>
-<td align='center'>$temp[5]&nbsp;</td>
-
-<td align='center'>
+<td align='center' $col>$TAG2$temp[0]$TAG3</td>
+<td align='center' $col $TAG4>$TAG0$temp[1]$TAG1</td>
+<td align='center' $col>$temp[6]&nbsp;</td>
+<td align='center' $col>$temp[3]&nbsp;</td>
+<td align='center' $col>$temp[4]&nbsp;</td>
+<td align='center' $col>$temp[5]&nbsp;</td>
+
+<td align='center' $col>
 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}2' />
 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
@@ -955,7 +988,7 @@ foreach my $line (@current2) {
 </form>
 </td>
 
-<td align='center'>
+<td align='center' $col>
 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}2' />
 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
@@ -963,7 +996,7 @@ foreach my $line (@current2) {
 </form>
 </td>
 
-<td align='center'>
+<td align='center' $col>
 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}2' />
 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
@@ -1011,33 +1044,6 @@ END
 
 &Header::closebox();
 
-&Header::openbox('100%', 'left', $Lang::tr{'arp table entries'});
-my @ip = qx(/sbin/ip neigh show | awk '{print \$1}');
-my @mac = qx(/sbin/ip neigh show | awk '{print \$5}');
-
-print <<END
-<hr />
-<table width='100%'>
-<tr>
-<td width='40%'><b>$Lang::tr{'ip address'}</b></td><td width='40%'><b>$Lang::tr{'mac address'}</b></td><td width='20%'>Optionen</td>
-</tr>
-END
-;
-my $i=0;
-
-foreach my $ip(@ip)
-{
- print"<tr><form method='post' action='$ENV{'SCRIPT_NAME'}'><td><input type='hidden' name='FIX_ADDR' value='$ip' />$ip</td>";
- print"<td><input type='hidden' name='FIX_MAC' value='@mac[$i]' />@mac[$i]</td>";
- print"<td><input type='hidden' name='ACTION' value='$Lang::tr{'add'}2' /><input type='submit' name='SUBMIT' value='$buttontext' /></td></form></tr>";
-}
-
-
-print"</table>";
-
-&Header::closebox();
-
-
 foreach my $itf (@ITFs) {
     if ($dhcpsettings{"ENABLE_${itf}"} eq 'on') {
        # display leases with a list of actions to do with the global select checkbox.
@@ -1199,11 +1205,9 @@ sub buildconf {
            print FILE "} #$itf\n";
 
            system ('/usr/bin/touch', "${General::swroot}/dhcp/enable_${lc_itf}");
-           system ('/usr/local/bin/dhcpctrl enable');
            &General::log("DHCP on ${itf}: " . $Lang::tr{'dhcp server enabled'})
        } else {
            unlink "${General::swroot}/dhcp/enable_${lc_itf}";
-           system ('/usr/local/bin/dhcpctrl disable');
            &General::log("DHCP on ${itf}: " . $Lang::tr{'dhcp server disabled'})
        }
     }
@@ -1225,7 +1229,10 @@ sub buildconf {
            $key++;
        }
     }
+    print FILE "include \"${General::swroot}/dhcp/dhcpd.conf.local\";\n";
     close FILE;
+    if ( $dhcpsettings{"ENABLE_GREEN"} eq 'on' || $dhcpsettings{"ENABLE_BLUE"} eq 'on' ) {system '/usr/local/bin/dhcpctrl enable >/dev/null 2>&1';}
+    else {system '/usr/local/bin/dhcpctrl disable >/dev/null 2>&1';}
     system '/usr/local/bin/dhcpctrl restart >/dev/null 2>&1';
 }