X-Git-Url: http://git.ipfire.org/?p=ipfire-2.x.git;a=blobdiff_plain;f=html%2Fcgi-bin%2Fdhcp.cgi;h=dd48d58cb0d5cca8347e3ce93ca7361c6d48dc77;hp=be7e0bf5319ab1ffb7bb85bc88fe125d74c4c57c;hb=91fc30309fcc929ae3b4b88f6cac67e1214e73a9;hpb=ac1cfefab236b73ed52909e14f43eaffc8d6914e diff --git a/html/cgi-bin/dhcp.cgi b/html/cgi-bin/dhcp.cgi index be7e0bf531..dd48d58cb0 100644 --- a/html/cgi-bin/dhcp.cgi +++ b/html/cgi-bin/dhcp.cgi @@ -1,31 +1,31 @@ #!/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 -# - 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 . # +# # +############################################################################### + use strict; # enable only the following on debugging purpose #use warnings; #use CGI::Carp 'fatalsToBrowser'; -require 'CONFIG_ROOT/general-functions.pl'; +require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; #workaround to suppress a warning when a variable is used only once @@ -38,18 +38,20 @@ my %mainsettings=(); my %timesettings=(); my $setting = "${General::swroot}/dhcp/settings"; our $filename1 = "${General::swroot}/dhcp/advoptions"; # Field separator is TAB in this file (comma is standart) - # because we need commas in the some data + # because we need commas in the some data our $filename2 = "${General::swroot}/dhcp/fixleases"; -our $filename3 = "${General::swroot}/dhcp/advoptions-list"; # Describe the allowed syntax for dhcp options +our $filename3 = "${General::swroot}/dhcp/advoptions-list"; # Describe the allowed syntax for dhcp options 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) { @@ -66,6 +68,8 @@ foreach my $itf (@ITFs) { $dhcpsettings{"DNS2_${itf}"} = ''; $dhcpsettings{"NTP1_${itf}"} = ''; $dhcpsettings{"NTP2_${itf}"} = ''; + $dhcpsettings{"NEXT_${itf}"} = ''; + $dhcpsettings{"FILE_${itf}"} = ''; } $dhcpsettings{'SORT_FLEASELIST'} = 'FIPADDR'; @@ -99,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); @@ -206,7 +211,12 @@ if ($dhcpsettings{'ACTION'} eq $Lang::tr{'save'}) { goto ERROR; } } - + if ($dhcpsettings{"NEXT_${itf}"}) { + if (!(&General::validip($dhcpsettings{"NEXT_${itf}"}))) { + $errormessage = "next-server on ${itf}: " . $Lang::tr{'invalid ip'}; + goto ERROR; + } + } if ($dhcpsettings{"NTP1_${itf}"}) { if (!(&General::validip($dhcpsettings{"NTP1_${itf}"}))) { $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid primary ntp'}; @@ -428,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 @@ -532,11 +545,11 @@ print <$Lang::tr{"$lc_itf interface"} $Lang::tr{'enabled'} - $Lang::tr{'ip address'}/$Lang::tr{'netmask'}:$netsettings{"${itf}_ADDRESS"}/$netsettings{"${itf}_NETMASK"} + $Lang::tr{'ip address'}
$Lang::tr{'netmask'}:$netsettings{"${itf}_ADDRESS"}
$netsettings{"${itf}_NETMASK"}
- $Lang::tr{'start address'} * + $Lang::tr{'start address'} - $Lang::tr{'end address'} * + $Lang::tr{'end address'} $Lang::tr{'default lease time'} @@ -563,6 +576,11 @@ print < $Lang::tr{'secondary wins server address'}: * + + next-server: * + + filename: * +
@@ -575,10 +593,7 @@ print < * $Lang::tr{'this field may be blank'} $warnNTPmessage - - - - $Lang::tr{ + @@ -638,7 +653,7 @@ print < * $Lang::tr{'dhcp advopt scope help'} - + @@ -710,9 +725,9 @@ foreach my $line (@current1) { if ($dhcpsettings{'KEY1'} eq $key) { print ""; } elsif ($key % 2) { - print ""; + print ""; } else { - print ""; + print ""; } print < * $Lang::tr{'this field may be blank'} - + +
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 +} + print < - +
- - - - - - - + + + + + + + END ; @@ -891,6 +925,7 @@ foreach my $line (@current2) { } $key = 0; +my $col=""; foreach my $line (@current2) { my $gif = ''; my $gdesc = ''; @@ -905,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 ""; + print ""; + $col="bgcolor='${Header::colouryellow}'"; } elsif ($key % 2) { - print ""; + print ""; + $col="bgcolor='$color{'color20'}'"; } else { - print ""; + print ""; + $col="bgcolor='$color{'color22'}'"; } my $TAG0 = ''; my $TAG1 = ''; @@ -930,14 +973,14 @@ foreach my $line (@current2) { } print <$TAG2$temp[0]$TAG3 - - - - - - - + + + + + + + - -
$Lang::tr{'mac address'}$Lang::tr{'ip address'}$Lang::tr{'remark'}next-serverfilenameroot path$Lang::tr{'action'}$Lang::tr{'mac address'}$Lang::tr{'ip address'}$Lang::tr{'remark'}next-serverfilenameroot path$Lang::tr{'action'}
$TAG0$temp[1]$TAG1$temp[6] $temp[3] $temp[4] $temp[5]  +$TAG2$temp[0]$TAG3$TAG0$temp[1]$TAG1$temp[6] $temp[3] $temp[4] $temp[5] 
@@ -945,7 +988,7 @@ foreach my $line (@current2) {
+
@@ -953,7 +996,7 @@ foreach my $line (@current2) {
+
@@ -1001,7 +1044,6 @@ END &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. @@ -1138,6 +1180,8 @@ sub buildconf { print FILE "\toption netbios-name-servers " . $dhcpsettings{"WINS1_${itf}"} if ($dhcpsettings{"WINS1_${itf}"}); print FILE ", " . $dhcpsettings{"WINS2_${itf}"} if ($dhcpsettings{"WINS2_${itf}"}); print FILE ";\n" if ($dhcpsettings{"WINS1_${itf}"}); + print FILE "\tnext-server " . $dhcpsettings{"NEXT_${itf}"} . ";\n" if ($dhcpsettings{"NEXT_${itf}"}); + print FILE "\tfilename \"" . $dhcpsettings{"FILE_${itf}"} . "\";\n" if ($dhcpsettings{"FILE_${itf}"}); print FILE "\tdefault-lease-time " . ($dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"} * 60). ";\n"; print FILE "\tmax-lease-time " . ($dhcpsettings{"MAX_LEASE_TIME_${itf}"} * 60) . ";\n"; print FILE "\tallow bootp;\n" if ($dhcpsettings{"ENABLEBOOTP_${itf}"} eq 'on'); @@ -1160,7 +1204,7 @@ sub buildconf { }# foreach line print FILE "} #$itf\n"; - system ('/bin/touch', "${General::swroot}/dhcp/enable_${lc_itf}"); + system ('/usr/bin/touch', "${General::swroot}/dhcp/enable_${lc_itf}"); &General::log("DHCP on ${itf}: " . $Lang::tr{'dhcp server enabled'}) } else { unlink "${General::swroot}/dhcp/enable_${lc_itf}"; @@ -1185,8 +1229,11 @@ sub buildconf { $key++; } } + print FILE "include \"${General::swroot}/dhcp/dhcpd.conf.local\";\n"; close FILE; - system '/usr/local/bin/restartdhcp'; + 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'; } #