2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
24 # enable only the following on debugging purpose
26 #use CGI::Carp 'fatalsToBrowser';
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31 #workaround to suppress a warning when a variable is used only once
32 my @dummy = ( ${Header
::colouryellow
} );
39 my $setting = "${General::swroot}/dhcp/settings";
40 our $filename1 = "${General::swroot}/dhcp/advoptions"; # Field separator is TAB in this file (comma is standart)
41 # because we need commas in the some data
42 our $filename2 = "${General::swroot}/dhcp/fixleases";
43 our $filename3 = "${General::swroot}/dhcp/advoptions-list"; # Describe the allowed syntax for dhcp options
44 my $errormessage = '';
45 my $warnNTPmessage = '';
49 #Basic syntax allowed for new Option definition. Not implemented: RECORDS & array of RECORDS
50 our $OptionTypes = 'boolean|((un)?signed )?integer (8|16|32)|ip-address|text|string|encapsulate \w+|array of ip-address';
52 &Header
::showhttpheaders
();
54 if (&Header
::blue_used
()){push(@ITFs,'BLUE');}
56 #Settings1 for the first screen box
57 foreach my $itf (@ITFs) {
58 $dhcpsettings{"ENABLE_${itf}"} = 'off';
59 $dhcpsettings{"ENABLEBOOTP_${itf}"} = 'off';
60 $dhcpsettings{"START_ADDR_${itf}"} = '';
61 $dhcpsettings{"END_ADDR_${itf}"} = '';
62 $dhcpsettings{"DOMAIN_NAME_${itf}"} = '';
63 $dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"} = '';
64 $dhcpsettings{"MAX_LEASE_TIME_${itf}"} = '';
65 $dhcpsettings{"WINS1_${itf}"} = '';
66 $dhcpsettings{"WINS2_${itf}"} = '';
67 $dhcpsettings{"DNS1_${itf}"} = '';
68 $dhcpsettings{"DNS2_${itf}"} = '';
69 $dhcpsettings{"NTP1_${itf}"} = '';
70 $dhcpsettings{"NTP2_${itf}"} = '';
71 $dhcpsettings{"NEXT_${itf}"} = '';
72 $dhcpsettings{"FILE_${itf}"} = '';
73 $dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"} = '';
74 $dhcpsettings{"DNS_UPDATE_KEY_SECRET_${itf}"} = '';
75 $dhcpsettings{"DNS_UPDATE_KEY_ALGO_${itf}"} = '';
78 $dhcpsettings{'SORT_FLEASELIST'} = 'FIPADDR';
79 $dhcpsettings{'SORT_LEASELIST'} = 'IPADDR';
82 $dhcpsettings{'DNS_UPDATE_ENABLED'} = 'off';
84 #Settings2 for editing the multi-line list
85 #Must not be saved with writehash !
86 $dhcpsettings{'FIX_MAC'} = '';
87 $dhcpsettings{'FIX_ADDR'} = '';
88 $dhcpsettings{'FIX_ENABLED'} = 'off';
89 $dhcpsettings{'FIX_NEXTADDR'} = '';
90 $dhcpsettings{'FIX_FILENAME'} = '';
91 $dhcpsettings{'FIX_ROOTPATH'} = '';
92 $dhcpsettings{'FIX_REMARK'} = '';
93 $dhcpsettings{'ACTION'} = '';
94 $dhcpsettings{'KEY1'} = '';
95 $dhcpsettings{'KEY2'} = '';
96 @nosaved=('FIX_MAC','FIX_ADDR','FIX_ENABLED','FIX_NEXTADDR',
97 'FIX_FILENAME','FIX_ROOTPATH','FIX_REMARK');
99 $dhcpsettings{'ADVOPT_ENABLED'} = '';
100 $dhcpsettings{'ADVOPT_NAME'} = '';
101 $dhcpsettings{'ADVOPT_DATA'} = '';
102 unshift (@nosaved,'ADVOPT_ENABLED','ADVOPT_NAME','ADVOPT_DATA');
103 foreach my $itf (@ITFs) {
104 $dhcpsettings{"ADVOPT_SCOPE_${itf}"} = 'off';
105 unshift (@nosaved, "ADVOPT_SCOPE_${itf}");
108 # Read Ipcop settings
109 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
110 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
111 &General
::readhash
("${General::swroot}/time/settings", \
%timesettings);
112 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
115 &Header
::getcgihash
(\
%dhcpsettings);
117 open(FILE
, "$filename1") or die 'Unable to open dhcp advanced options file.';
118 our @current1 = <FILE
>;
120 # Extract OptionDefinition
121 foreach my $line (@current1) {
122 #chomp($line); # remove newline #don't know why, but this remove newline in @current1 .... !
123 my @temp = split(/\t/,$line);
124 AddNewOptionDefinition
($temp[1] . ' ' . $temp[2]);
127 open(FILE
, "$filename2") or die 'Unable to open fixed leases file.';
128 our @current2 = <FILE
>;
131 # Check Settings1 first because they are needed by &buildconf
132 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'save'}) {
133 foreach my $itf (@ITFs) {
134 if ($dhcpsettings{"ENABLE_${itf}"} eq 'on' ) {
135 # "Start" is defined, need "End" and vice versa
136 if ($dhcpsettings{"START_ADDR_${itf}"}) {
137 if (!(&General
::validip
($dhcpsettings{"START_ADDR_${itf}"}))) {
138 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid start address'};
141 if (!$dhcpsettings{"END_ADDR_${itf}"}) {
142 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid end address'};
145 if (! &General
::IpInSubnet
( $dhcpsettings{"START_ADDR_${itf}"},
146 $netsettings{"${itf}_NETADDRESS"},
147 $netsettings{"${itf}_NETMASK"})) {
148 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid start address'};
153 if ($dhcpsettings{"END_ADDR_${itf}"}) {
154 if (!(&General
::validip
($dhcpsettings{"END_ADDR_${itf}"}))) {
155 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid end address'};
158 if (!$dhcpsettings{"START_ADDR_${itf}"}) {
159 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid start address'};
162 if (! &General
::IpInSubnet
( $dhcpsettings{"END_ADDR_${itf}"},
163 $netsettings{"${itf}_NETADDRESS"},
164 $netsettings{"${itf}_NETMASK"})) {
165 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid end address'};
168 #swap if necessary! (support 255.255.0.0 range, I doubt we need more) GE
169 my @startoct = split (/\./, $dhcpsettings{"START_ADDR_${itf}"});
170 my @endoct = split (/\./, $dhcpsettings{"END_ADDR_${itf}"});
171 if ( $endoct[2]*256+$endoct[3] < $startoct[2]*256+$startoct[3] ) {
172 ($dhcpsettings{"START_ADDR_${itf}"},$dhcpsettings{"END_ADDR_${itf}"}) =
173 ($dhcpsettings{"END_ADDR_${itf}"},$dhcpsettings{"START_ADDR_${itf}"});
177 if (!($dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"} =~ /^\d+$/)) {
178 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid default lease time'} . $dhcpsettings{'DEFAULT_LEASE_TIME_${itf}'};
182 if (!($dhcpsettings{"MAX_LEASE_TIME_${itf}"} =~ /^\d+$/)) {
183 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid max lease time'} . $dhcpsettings{'MAX_LEASE_TIME_${itf}'};
187 if ($dhcpsettings{"DNS1_${itf}"}) {
188 if (!(&General
::validip
($dhcpsettings{"DNS1_${itf}"}))) {
189 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid primary dns'};
193 if ($dhcpsettings{"DNS2_${itf}"}) {
194 if (!(&General
::validip
($dhcpsettings{"DNS2_${itf}"}))) {
195 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid secondary dns'};
198 if (! $dhcpsettings{"DNS1_${itf}"}) {
199 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'cannot specify secondary dns without specifying primary'};
204 if ($dhcpsettings{"WINS1_${itf}"}) {
205 if (!(&General
::validip
($dhcpsettings{"WINS1_${itf}"}))) {
206 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid wins address'};
210 if ($dhcpsettings{"WINS2_${itf}"}) {
211 if (!(&General
::validip
($dhcpsettings{"WINS2_${itf}"}))) {
212 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid wins address'};
215 if (! $dhcpsettings{"WINS1_${itf}"} ) {
216 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'cannot specify secondary wins without specifying primary'};
220 if ($dhcpsettings{"NEXT_${itf}"}) {
221 if (!(&General
::validip
($dhcpsettings{"NEXT_${itf}"}))) {
222 $errormessage = "next-server on ${itf}: " . $Lang::tr
{'invalid ip'};
226 if ($dhcpsettings{"NTP1_${itf}"}) {
227 if (!(&General
::validip
($dhcpsettings{"NTP1_${itf}"}))) {
228 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid primary ntp'};
231 if ($dhcpsettings{"NTP1_${itf}"} eq $netsettings{"${itf}_ADDRESS"} && ($timesettings{'ENABLECLNTP'} ne 'on')) {
232 $warnNTPmessage = "DHCP on ${itf}: " . $Lang::tr
{'local ntp server specified but not enabled'};
236 if ($dhcpsettings{"NTP2_${itf}"}) {
237 if (!(&General
::validip
($dhcpsettings{"NTP2_${itf}"}))) {
238 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid secondary ntp'};
241 if ($dhcpsettings{"NTP2_${itf}"} eq $netsettings{"${itf}_ADDRESS"} && ($timesettings{'ENABLECLNTP'} ne 'on')) {
242 $warnNTPmessage = "DHCP on ${itf}: " . $Lang::tr
{'local ntp server specified but not enabled'};
245 if (! $dhcpsettings{"NTP1_${itf}"}) {
246 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'cannot specify secondary ntp without specifying primary'};
251 }#loop interface verify
253 map (delete ($dhcpsettings{$_}) ,@nosaved,'ACTION','KEY1','KEY2','q'); # Must not be saved
254 &General
::writehash
($setting, \
%dhcpsettings); # Save good settings
255 $dhcpsettings{'ACTION'} = $Lang::tr
{'save'}; # create an 'ACTION'
256 map ($dhcpsettings{$_} = '',@nosaved,'KEY1','KEY2'); # and reinit vars to empty
258 ERROR
: # Leave the faulty field untouched
260 &General
::readhash
($setting, \
%dhcpsettings); # Get saved settings and reset to good if needed
263 ## Sorting of fixed leases
264 if ($ENV{'QUERY_STRING'} =~ /^FETHER|^FIPADDR/ ) {
265 my $newsort=$ENV{'QUERY_STRING'};
266 my $act=$dhcpsettings{'SORT_FLEASELIST'};
267 #Reverse actual sort ?
268 if ($act =~ $newsort) {
275 $dhcpsettings{'SORT_FLEASELIST'}=$newsort;
276 map (delete ($dhcpsettings{$_}) ,@nosaved,'ACTION','KEY1','KEY2', 'q'); # Must never be saved
277 &General
::writehash
($setting, \
%dhcpsettings);
279 $dhcpsettings{'ACTION'} = 'SORT'; # create an 'ACTION'
280 map ($dhcpsettings{$_} = '',@nosaved,'KEY1','KEY2');# and reinit vars to empty
283 #Sorting of allocated leases
284 &Header
::CheckSortOrder
;
287 ## Now manipulate the two multi-line list with Settings2.
288 # '1' suffix is for ADVANCED OPTIONS
289 # '2' suffix is for FIXED LEASES
291 # Toggle enable/disable field on specified options.
293 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'toggle enable disable'}.'1') {
295 chomp(@current1[$dhcpsettings{'KEY1'}]);
296 my @temp = split(/\t/,@current1[$dhcpsettings{'KEY1'}]); #use TAB separator !
297 $temp[0] = $temp[0] eq 'on' ?
'' : 'on'; # Toggle the field
298 @current1[$dhcpsettings{'KEY1'}] = join ("\t",@temp)."\n";
299 $dhcpsettings{'KEY1'} = ''; # End edit mode
300 &General
::log($Lang::tr
{'dhcp advopt modified'});
301 open(FILE
, ">$filename1") or die 'Unable to open dhcp advanced options file.';
302 print FILE
@current1;
305 #Write changes to dhcpd.conf.
311 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'add'}.'1' &&
312 $dhcpsettings{'SUBMIT'} ne $Lang::tr
{'dhcp advopt help'}) {
313 $dhcpsettings{'ADVOPT_NAME'} =~ s/[^ \w-]//g; # prevent execution of code by removing everything except letters/space
314 $dhcpsettings{'ADVOPT_DATA'} =~ s/`//g; # back tik ` ? not allowed !
316 if ($dhcpsettings{'ADVOPT_DATA'} eq '') {
317 $errormessage=$Lang::tr
{'dhcp advopt blank value'};
320 # Test for a new option definition string (join field name & data)
321 if (ExistNewOptionDefinition
($dhcpsettings{'ADVOPT_NAME'} . ' ' . $dhcpsettings{'ADVOPT_DATA'})) {
322 #only edit permitted if option definition exists
323 $errormessage = $Lang::tr
{'dhcp advopt definition exists'} if ($dhcpsettings{'KEY1'} eq '');
324 $dhcpsettings{'ADVOPT_ENABLED'} = 'on'; # force active
325 map ($dhcpsettings{"ADVOPT_SCOPE_$_"} = 'off', @ITFs); # force global
326 } elsif (AddNewOptionDefinition
($dhcpsettings{'ADVOPT_NAME'} . ' ' . $dhcpsettings{'ADVOPT_DATA'})) {
327 #was a new option definition
328 $dhcpsettings{'ADVOPT_ENABLED'} = 'on'; # force active
329 map ($dhcpsettings{"ADVOPT_SCOPE_$_"} = 'off', @ITFs); # force global
330 } elsif (ValidNewOption
($dhcpsettings{'ADVOPT_NAME'} . ' ' . $dhcpsettings{'ADVOPT_DATA'})) {
332 } elsif (! `grep "\$option $dhcpsettings{'ADVOPT_NAME'} " $filename3`) {
333 $errormessage=$Lang::tr
{'dhcp advopt unknown'}.': '.$dhcpsettings{'ADVOPT_NAME'};
336 unless ($errormessage) {
339 foreach my $itf (@ITFs) { # buils "RED,GREEN,ORANGE,... based on selection
340 $scope .= $dhcpsettings{"ADVOPT_SCOPE_${itf}"} eq 'on' ?
"\t$itf" : "\toff" ;
342 if ($dhcpsettings{'KEY1'} eq '') { #add or edit ? TAB separator !
343 unshift (@current1, "$dhcpsettings{'ADVOPT_ENABLED'}\t$dhcpsettings{'ADVOPT_NAME'}\t$dhcpsettings{'ADVOPT_DATA'}$scope\n");
344 &General
::log($Lang::tr
{'dhcp advopt added'});
346 @current1[$dhcpsettings{'KEY1'}] = "$dhcpsettings{'ADVOPT_ENABLED'}\t$dhcpsettings{'ADVOPT_NAME'}\t$dhcpsettings{'ADVOPT_DATA'}$scope\n";
347 $dhcpsettings{'KEY1'} = ''; # End edit mode
348 &General
::log($Lang::tr
{'dhcp advopt modified'});
351 #Write changes to dhcpd.conf.
352 &sortcurrent1
; # sort newly added/modified entry
353 &buildconf
; # before calling buildconf which use fixed lease file !
357 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'edit'}.'1') {
359 my $line = @current1[$dhcpsettings{'KEY1'}];
361 my @temp = split(/\t/, $line);
362 $dhcpsettings{'ADVOPT_ENABLED'}=$temp[0];
363 $dhcpsettings{'ADVOPT_NAME'}=$temp[1];
364 $dhcpsettings{'ADVOPT_DATA'}=$temp[2];
366 # read next fields which are the name (color) of an interface if this interface is scoped
367 for (my $key=0; $key<@ITFs; $key++) {
368 my $itf = $temp[3+$key];
369 if ($itf ne 'off') # Only is an interface name is read
371 $dhcpsettings{"ADVOPT_SCOPE_${itf}"} = 'on';
376 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'remove'}.'1') {
377 splice (@current1,$dhcpsettings{'KEY1'},1);
378 open(FILE
, ">$filename1") or die 'Unable to open dhcp advanced options file.';
379 print FILE
@current1;
381 $dhcpsettings{'KEY1'} = ''; # End remove mode
382 &General
::log($Lang::tr
{'dhcp advopt removed'});
383 #Write changes to dhcpd.conf.
389 # Toggle enable/disable field on specified lease.
390 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'toggle enable disable'}.'2') {
392 chomp(@current2[$dhcpsettings{'KEY2'}]);
393 my @temp = split(/\,/,@current2[$dhcpsettings{'KEY2'}]);
394 $temp[2] = $temp[2] eq 'on' ?
'' : 'on'; # Toggle the field
395 @current2[$dhcpsettings{'KEY2'}] = join (',',@temp)."\n";
396 $dhcpsettings{'KEY2'} = ''; # End edit mode
397 &General
::log($Lang::tr
{'fixed ip lease modified'});
398 open(FILE
, ">$filename2") or die 'Unable to open fixed leases file.';
399 print FILE
@current2;
402 #Write changes to dhcpd.conf.
406 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'add'}.'2') {
407 $dhcpsettings{'FIX_MAC'} =~ tr/-/:/;
408 unless(&General
::validip
($dhcpsettings{'FIX_ADDR'})) { $errormessage = $Lang::tr
{'invalid fixed ip address'}; }
409 unless(&General
::validmac
($dhcpsettings{'FIX_MAC'})) { $errormessage = $Lang::tr
{'invalid fixed mac address'}; }
410 if ($dhcpsettings{'FIX_NEXTADDR'}) {
411 unless(&General
::validip
($dhcpsettings{'FIX_NEXTADDR'})) { $errormessage = $Lang::tr
{'invalid fixed ip address'}; }
415 CHECK:foreach my $line (@current2) {
416 my @temp = split(/\,/,$line);
417 if($dhcpsettings{'KEY2'} ne $key) {
418 # same MAC is OK on different subnets. This test is not complete because
419 # if ip are not inside a known subnet, I don't warn.
420 # Also it may be needed to put duplicate fixed lease in their right subnet definition..
421 foreach my $itf (@ITFs) {
422 my $scoped = &General
::IpInSubnet
($dhcpsettings{'FIX_ADDR'},
423 $netsettings{"${itf}_NETADDRESS"},
424 $netsettings{"${itf}_NETMASK"}) &&
425 $dhcpsettings{"ENABLE_${itf}"} eq 'on';
427 (lc($dhcpsettings{'FIX_MAC'}) eq lc($temp[0])) &&
428 &General
::IpInSubnet
($temp[1],
429 $netsettings{"${itf}_NETADDRESS"},
430 $netsettings{"${itf}_NETMASK"})) {
431 $errormessage = "$Lang::tr{'mac address in use'} $dhcpsettings{'FIX_MAC'}";
439 unless ($errormessage) {
440 $dhcpsettings{'FIX_REMARK'} = &Header
::cleanhtml
($dhcpsettings{'FIX_REMARK'});
441 $dhcpsettings{'FIX_NEXTADDR'} = &Header
::cleanhtml
($dhcpsettings{'FIX_NEXTADDR'});
442 $dhcpsettings{'FIX_FILENAME'} = &Header
::cleanhtml
($dhcpsettings{'FIX_FILENAME'});
443 $dhcpsettings{'FIX_ROOTPATH'} = &Header
::cleanhtml
($dhcpsettings{'FIX_ROOTPATH'});
444 if ($dhcpsettings{'KEY2'} eq '') { #add or edit ?
445 unshift (@current2, "$dhcpsettings{'FIX_MAC'},$dhcpsettings{'FIX_ADDR'},$dhcpsettings{'FIX_ENABLED'},$dhcpsettings{'FIX_NEXTADDR'},$dhcpsettings{'FIX_FILENAME'},$dhcpsettings{'FIX_ROOTPATH'},$dhcpsettings{'FIX_REMARK'}\n");
446 &General
::log($Lang::tr
{'fixed ip lease added'});
449 $dhcpsettings{'KEY2'} = $key;
451 @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";
452 $dhcpsettings{'KEY2'} = ''; # End edit mode
453 &General
::log($Lang::tr
{'fixed ip lease modified'});
456 #Write changes to dhcpd.conf.
457 &sortcurrent2
; # sort newly added/modified entry
458 &buildconf
; # before calling buildconf which use fixed lease file !
462 if ($dhcpsettings{'ACTION_ALL'} eq '+') {
464 foreach (keys %dhcpsettings) {
465 if (/^(\d+\.\d+\.\d+\.\d+)-([0-9a-fA-F:]+)$/) { # checked names are index of the line
468 if (!grep (/$2/,@current2)) {
469 unshift (@current2, "$mac,$ip,on,,,,imported\n");
475 #Write changes to dhcpd.conf.
476 $warnNTPmessage = $Lang::tr
{'fixed ip lease added'}."($news)";
477 &General
::log($warnNTPmessage);
478 &sortcurrent2
; # sort newly added/modified entry
479 &buildconf
; # before calling buildconf which use fixed lease file !
483 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'edit'}.'2') {
485 my $line = @current2[$dhcpsettings{'KEY2'}];
487 my @temp = split(/\,/, $line);
488 $dhcpsettings{'FIX_MAC'}=$temp[0];
489 $dhcpsettings{'FIX_ADDR'}=$temp[1];
490 $dhcpsettings{'FIX_ENABLED'}=$temp[2];
491 $dhcpsettings{'FIX_NEXTADDR'}=$temp[3];
492 $dhcpsettings{'FIX_FILENAME'}=$temp[4];
493 $dhcpsettings{'FIX_ROOTPATH'}=$temp[5];
494 $dhcpsettings{'FIX_REMARK'}=$temp[6];
497 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'remove'}.'2') {
498 splice (@current2,$dhcpsettings{'KEY2'},1);
499 open(FILE
, ">$filename2") or die 'Unable to open fixed lease file.';
500 print FILE
@current2;
502 $dhcpsettings{'KEY2'} = ''; # End remove mode
503 &General
::log($Lang::tr
{'fixed ip lease removed'});
504 #Write changes to dhcpd.conf.
512 if ($dhcpsettings{'ACTION'} eq '' ) { # First launch from GUI
514 # Set default DHCP values only if blank and disabled
515 foreach my $itf (@ITFs) {
516 if ($dhcpsettings{"ENABLE_${itf}"} ne 'on' ) {
517 $dhcpsettings{"DNS1_${itf}"} = $netsettings{"${itf}_ADDRESS"};
518 $dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"} = '60';
519 $dhcpsettings{"MAX_LEASE_TIME_${itf}"} = '120';
520 $dhcpsettings{"DOMAIN_NAME_${itf}"} = $mainsettings{'DOMAINNAME'};
523 $dhcpsettings{'FIX_ENABLED'} = 'on';
526 &Header
::openpage
($Lang::tr
{'dhcp configuration'}, 1, '');
527 &Header
::openbigbox
('100%', 'left', '', $errormessage);
530 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
531 print "<font class='base'>$errormessage </font>\n";
534 if ($warnNTPmessage) {
535 $warnNTPmessage = "<font color=${Header::colourred}><b>$Lang::tr{'capswarning'}</b></font>: $warnNTPmessage";
538 &Header
::openbox
('100%', 'left', 'DHCP');
539 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>";
541 foreach my $itf (@ITFs) {
543 $checked{'ENABLE'}{'on'} = ( $dhcpsettings{"ENABLE_${itf}"} ne 'on') ?
'' : "checked='checked'";
544 $checked{'ENABLEBOOTP'}{'on'} = ( $dhcpsettings{"ENABLEBOOTP_${itf}"} ne 'on') ?
'' : "checked='checked'";
546 if ($netsettings{"${itf}_DEV"} ne '' ) { # Show only defined interface
551 <td width='25%' class='boldbase'><b><font color='${lc_itf}'>$Lang::tr{"$lc_itf interface"}</font></b></td>
552 <td class='base'>$Lang::tr{'enabled'}
553 <input type='checkbox' name='ENABLE_${itf}' $checked{'ENABLE'}{'on'} /></td>
554 <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>
556 <td width='25%' class='base'>$Lang::tr{'start address'} <img src='/blob.gif' alt='*' /></td>
557 <td width='25%'><input type='text' name='START_ADDR_${itf}' value='$dhcpsettings{"START_ADDR_${itf}"}' /></td>
558 <td width='25%' class='base'>$Lang::tr{'end address'} <img src='/blob.gif' alt='*' /></td>
559 <td width='25%'><input type='text' name='END_ADDR_${itf}' value='$dhcpsettings{"END_ADDR_${itf}"}' /></td>
561 <td class='base'>$Lang::tr{'default lease time'} <img src='/blob.gif' alt='*' /></td>
562 <td><input type='text' name='DEFAULT_LEASE_TIME_${itf}' value='$dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"}' /></td>
563 <td class='base'>$Lang::tr{'max lease time'} <img src='/blob.gif' alt='*' /></td>
564 <td><input type='text' name='MAX_LEASE_TIME_${itf}' value='$dhcpsettings{"MAX_LEASE_TIME_${itf}"}' /></td>
566 <td class='base'>$Lang::tr{'domain name suffix'}</td>
567 <td><input type='text' name='DOMAIN_NAME_${itf}' value='$dhcpsettings{"DOMAIN_NAME_${itf}"}' /></td>
568 <td>$Lang::tr{'dhcp allow bootp'}:</td>
569 <td><input type='checkbox' name='ENABLEBOOTP_${itf}' $checked{'ENABLEBOOTP'}{'on'} /></td>
571 <td class='base'>$Lang::tr{'primary dns'} <img src='/blob.gif' alt='*' /></td>
572 <td><input type='text' name='DNS1_${itf}' value='$dhcpsettings{"DNS1_${itf}"}' /></td>
573 <td class='base'>$Lang::tr{'secondary dns'}</td>
574 <td><input type='text' name='DNS2_${itf}' value='$dhcpsettings{"DNS2_${itf}"}' /></td>
576 <td class='base'>$Lang::tr{'primary ntp server'}:</td>
577 <td><input type='text' name='NTP1_${itf}' value='$dhcpsettings{"NTP1_${itf}"}' /></td>
578 <td class='base'>$Lang::tr{'secondary ntp server'}:</td>
579 <td><input type='text' name='NTP2_${itf}' value='$dhcpsettings{"NTP2_${itf}"}' /></td>
581 <td class='base'>$Lang::tr{'primary wins server address'}:</td>
582 <td><input type='text' name='WINS1_${itf}' value='$dhcpsettings{"WINS1_${itf}"}' /></td>
583 <td class='base'>$Lang::tr{'secondary wins server address'}:</td>
584 <td><input type='text' name='WINS2_${itf}' value='$dhcpsettings{"WINS2_${itf}"}' /></td>
586 <td class='base'>next-server:</td>
587 <td><input type='text' name='NEXT_${itf}' value='$dhcpsettings{"NEXT_${itf}"}' /></td>
588 <td class='base'>filename:</td>
589 <td><input type='text' name='FILE_${itf}' value='$dhcpsettings{"FILE_${itf}"}' /></td>
595 }# Show only defined interface
600 <td class='base' width='25%'><img src='/blob.gif' align='top' alt='*' /> $Lang::tr{'required field'}</td>
601 <td class='base' width='30%'>$warnNTPmessage</td>
602 <td width='40%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
609 # DHCP DNS update support (RFC2136)
610 &Header
::openbox
('100%', 'left', $Lang::tr
{'dhcp dns update'});
613 $checked{'DNS_UPDATE_ENABLED'}{'on'} = ( $dhcpsettings{'DNS_UPDATE_ENABLED'} ne 'on') ?
'' : "checked='checked'";
618 <td width='25%' class='boldbase'>$Lang::tr{'dhcp dns enable update'}</td>
619 <td class='base'><input type='checkbox' name='DNS_UPDATE_ENABLED' $checked{'DNS_UPDATE_ENABLED'}{'on'}>
629 # Print options for each interface.
630 foreach my $itf (@ITFs) {
631 # Check if DHCP for this interface is enabled.
632 if ($dhcpsettings{"ENABLE_${itf}"} eq 'on') {
633 # Check for same domain name.
634 next if ($dhcpsettings{"DOMAIN_NAME_${itf}"} ~~ @domains);
635 my $lc_itf = lc($itf);
637 # Select previously configured update algorithm.
639 $selected{'DNS_UPDATE_ALGO_${inf}'}{$dhcpsettings{'DNS_UPDATE_ALGO_${inf}'}} = 'selected';
643 <td colspan='6'> </td>
646 <td colspan='6' class='boldbase'><b>$dhcpsettings{"DOMAIN_NAME_${itf}"}</b></td>
649 <td width='10%' class='boldbase'>$Lang::tr{'dhcp dns key name'}:</td>
650 <td width='20%'><input type='text' name='DNS_UPDATE_KEY_NAME_${itf}' value='$dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"}'></td>
651 <td width='10%' class='boldbase' align='right'>$Lang::tr{'dhcp dns update secret'}: </td>
652 <td width='20%'><input type='password' name='DNS_UPDATE_KEY_SECRET_${itf}' value='$dhcpsettings{"DNS_UPDATE_KEY_SECRET_${itf}"}'></td>
653 <td width='10%' class='boldbase' align='right'>$Lang::tr{'dhcp dns update algo'}: </td>
655 <select name='DNS_UPDATE_KEY_ALGO_${itf}'>
656 <!-- <option value='hmac-sha1' $selected{'DNS_UPDATE_KEY_ALGO_${itf}'}{'hmac-sha1'}>HMAC-SHA1</option> -->
657 <option value='hmac-md5' $selected{'DNS_UPDATE_KEY_ALGO_${itf}'}{'hmac-md5'}>HMAC-MD5</option>
665 # Store configured domain based on the interface
666 # in the temporary variable.
667 push(@domains, $dhcpsettings{"DOMAIN_NAME_${itf}"});
674 <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
683 &Header
::openbox
('100%', 'left', $Lang::tr
{'dhcp advopt list'});
684 # DHCP Advanced options settings
686 $checked{'ADVOPT_ENABLED'}{'on'} = ($dhcpsettings{'ADVOPT_ENABLED'} ne 'on') ?
'' : "checked='checked'";
688 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'>";
689 my $buttontext = $Lang::tr
{'add'};
690 if ($dhcpsettings{'KEY1'} ne '') {
691 $buttontext = $Lang::tr
{'update'};
692 print "<tr><td class='boldbase'><b>$Lang::tr{'dhcp advopt edit'}</b></td></tr>";
694 print "<tr><td class='boldbase'><b>$Lang::tr{'dhcp advopt add'}</b></td></tr>"
697 #search if the 'option' is in the list and print the syntax model
698 my $opt = `grep "\$option $dhcpsettings{'ADVOPT_NAME'} " $filename3`;
700 $opt =~ s/option $dhcpsettings{'ADVOPT_NAME'}/Syntax:/; # "option xyz abc" => "syntax: abc"
702 $opt = "<tr><td></td><td></td><td colspan='2'>$opt</td></tr>";
706 <td class='base'>$Lang::tr{'dhcp advopt name'}: <img src='/blob.gif' alt='*' /></td>
707 <td><input type='text' name='ADVOPT_NAME' value='$dhcpsettings{'ADVOPT_NAME'}' size='18' /></td>
708 <td class='base'>$Lang::tr{'dhcp advopt value'}: <img src='/blob.gif' alt='*' /></td>
709 <td><input type='text' name='ADVOPT_DATA' value='$dhcpsettings{'ADVOPT_DATA'}' size='40' /></td>
711 <td class='base'>$Lang::tr{'enabled'}</td><td><input type='checkbox' name='ADVOPT_ENABLED' $checked{'ADVOPT_ENABLED'}{'on'} /></td>
712 <td class='base'>$Lang::tr{'dhcp advopt scope'}:</td>
717 # Put a checkbox for each interface. Checkbox visible disabled if interface is disabled
718 foreach my $itf (@ITFs) {
720 $checked{'ADVOPT_SCOPE_${itf}'}{'on'} = $dhcpsettings{"ADVOPT_SCOPE_${itf}"} ne 'on' ?
'' : "checked='checked'";
721 print "$Lang::tr{\"${lc_itf}\"} <input type='checkbox' name='ADVOPT_SCOPE_${itf}' $checked{'ADVOPT_SCOPE_${itf}'}{'on'} ";
722 print $dhcpsettings{"ENABLE_${itf}"} eq 'on' ?
"/>" : "disabled='disabled' />";
723 print " ";
733 <td class='base' width='50%'>$Lang::tr{'dhcp advopt scope help'}</td>
734 <td width='50%' align='right'>
735 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}1' />
736 <input type='submit' name='SUBMIT' value='$buttontext' />
737 <input type='submit' name='SUBMIT' value='$Lang::tr{'dhcp advopt help'}' />
738 <input type='hidden' name='KEY1' value='$dhcpsettings{'KEY1'}' />
745 #Edited line number (KEY1) passed until cleared by 'save' or 'remove' or 'new sort order'
747 # print help taken from the file describing options
748 if ($dhcpsettings{'SUBMIT'} eq $Lang::tr
{'dhcp advopt help'}) {
750 print "<table width='100%'>";
751 print "<tr><td width='30%'><b>$Lang::tr{'dhcp advopt name'}</b></td><td width='70%'><b>$Lang::tr{'dhcp advopt value'}</b></td>";
752 open(FILE
, "$filename3");
753 my @current3 = <FILE
>;
755 foreach my $line (@current3) {
756 $line =~ /option ([a-z0-9-]+) (.*);/;
757 print "<tr><td>$1</td><td>$2</td></tr>\n";
759 print "<tr><td colspan='2'><hr /></td></tr>\n";
760 print '<tr><td>string type</td><td>"quoted string" or 00:01:FF...</td></tr>';
761 print '<tr><td>ip-address type </td><td>10.0.0.1 | www.dot.com</td></tr>';
762 print '<tr><td>int,uint types</td><td>numbers</td></tr>';
763 print '<tr><td>flag type</td><td>on | off</td></tr>';
766 print "<table width='100%'>";
767 print "<tr><td width='30%'><b>$Lang::tr{'dhcp advopt custom definition'}</b></td><td width='70%'><b>$Lang::tr{'dhcp advopt value'}</b></td>";
768 print "<tr><td>any-name </td><td> code NNN=$OptionTypes</td></tr>";
769 print '<tr><td>a-string</td><td>code 100=string</td></tr>';
770 print '<tr><td>a-number</td><td>code 101=signed integer 8</td></tr>';
771 print '<tr><td>wpad</td><td>code 252=text</td></tr>';
772 print '<tr><td>wpad</td><td>"http://www.server.fr/path-to/proxy.pac"</td></tr>';
781 <td width='30%' class='boldbase' align='center'><b>$Lang::tr{'dhcp advopt name'}</b></td>
782 <td width='50%' class='boldbase' align='center'><b>$Lang::tr{'dhcp advopt value'}</b></td>
783 <td width='20%' class='boldbase' align='center'><b>$Lang::tr{'dhcp advopt scope'}</b></td>
784 <td colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></td>
789 foreach my $line (@current1) {
792 chomp($line); # remove newline
793 my @temp = split(/\t/,$line);
795 if ($temp[0] eq "on") {
797 $gdesc = $Lang::tr
{'click to disable'};
800 $gdesc = $Lang::tr
{'click to enable'};
803 if ($dhcpsettings{'KEY1'} eq $key) {
804 print "<tr bgcolor='${Header::colouryellow}'>";
806 print "<tr bgcolor='$color{'color22'}'>";
808 print "<tr bgcolor='$color{'color20'}'>";
812 <td align='center'>$temp[1]</td>
813 <td align='center'>$temp[2]</td>
817 # Prepare a global flag to make easy reading
819 my $disabledTogle = '';
820 my $disabledEditRemove = '';
821 if ( ExistNewOptionDefinition
($temp[1] . ' ' . $temp[2]) ) {
822 $global = $Lang::tr
{'dhcp advopt definition'};
823 $disabledTogle = "disabled='disabled'";
824 # Search if it is a used NewOptionDefinition to also disable edit & delete
825 $disabledEditRemove = "disabled='disabled'" if (IsUsedNewOptionDefinition
($temp[1], $temp[2]));
827 $global = $Lang::tr
{'dhcp advopt scope global'};
831 # Print each checked interface
832 for (my $key=0; $key<@ITFs; $key++) {
833 my $itf = $temp[3+$key];
834 if ($itf ne 'off') { # Only if an interface name is read
836 $global=''; # fall to local scope !
842 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
843 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}1' />
844 <input $disabledTogle type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
845 <input type='hidden' name='KEY1' value='$key' />
850 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
851 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}1' />
852 <input $disabledEditRemove type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
853 <input type='hidden' name='KEY1' value='$key' />
858 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
859 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}1' />
860 <input $disabledEditRemove type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
861 <input type='hidden' name='KEY1' value='$key' />
872 # If there are dhcp options, print Key to action icons
877 <td class='boldbase'> <b>$Lang::tr{'legend'}: </b></td>
878 <td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
879 <td class='base'>$Lang::tr{'click to disable'}</td>
880 <td> </td>
881 <td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
882 <td class='base'>$Lang::tr{'click to enable'}</td>
883 <td> </td>
884 <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
885 <td class='base'>$Lang::tr{'edit'}</td>
886 <td> </td>
887 <td><img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
888 <td class='base'>$Lang::tr{'remove'}</td>
896 &Header
::openbox
('100%', 'left', $Lang::tr
{'current fixed leases'});
897 # Fixed leases screens
898 $checked{'FIX_ENABLED'}{'on'} = ($dhcpsettings{'FIX_ENABLED'} ne 'on') ?
'' : "checked='checked'";
900 $buttontext = $Lang::tr
{'add'};
901 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'>";
903 if ($dhcpsettings{'KEY2'} ne '') {
904 $buttontext = $Lang::tr
{'update'};
905 print "<tr><td class='boldbase' colspan='3'><b>$Lang::tr{'edit an existing lease'}</b></td></tr>";
907 print "<tr><td class='boldbase' colspan='3'><b>$Lang::tr{'add new lease'}</b></td></tr>"
911 <td class='base'>$Lang::tr{'mac address'}: <img src='/blob.gif' alt='*' /></td>
912 <td><input type='text' name='FIX_MAC' value='$dhcpsettings{'FIX_MAC'}' size='18' /></td>
913 <td class='base'>$Lang::tr{'ip address'}: <img src='/blob.gif' alt='*' /></td>
914 <td><input type='text' name='FIX_ADDR' value='$dhcpsettings{'FIX_ADDR'}' size='18' /></td>
915 <td class='base'>$Lang::tr{'remark'}:</td>
916 <td><input type='text' name='FIX_REMARK' value='$dhcpsettings{'FIX_REMARK'}' size='18' /></td>
918 <td class='base'>$Lang::tr{'enabled'}</td><td><input type='checkbox' name='FIX_ENABLED' $checked{'FIX_ENABLED'}{'on'} /></td>
920 <td colspan = '3'><b>$Lang::tr{'dhcp bootp pxe data'}</b></td>
922 <td class='base'>next-server:</td>
923 <td><input type='text' name='FIX_NEXTADDR' value='$dhcpsettings{'FIX_NEXTADDR'}' size='18' /></td>
924 <td class='base'>filename:</td>
925 <td><input type='text' name='FIX_FILENAME' value='$dhcpsettings{'FIX_FILENAME'}' size='18' /></td>
926 <td class='base'>root path:</td>
927 <td><input type='text' name='FIX_ROOTPATH' value='$dhcpsettings{'FIX_ROOTPATH'}' size='18' /></td>
933 <td class='base' width='50%'><img src='/blob.gif' align='top' alt='*' /> $Lang::tr{'required field'}</td>
934 <td width='50%' align='right'>
935 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}2' />
936 <input type='submit' name='SUBMIT' value='$buttontext' />
937 <input type='hidden' name='KEY2' value='$dhcpsettings{'KEY2'}' /></td>
943 #Edited line number (KEY2) passed until cleared by 'save' or 'remove' or 'new sort order'
945 # Search for static leases
946 my $search_query = $dhcpsettings{'q'};
948 if (scalar @current2 >= 10) {
950 <form method="POST" action="#search">
951 <a name="search"></a>
955 <input type="text" name="q" value="$search_query">
956 <input type="submit" value="$Lang::tr{'search'}">
965 <table width='100%' class='tbl'>
967 <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FETHER'><b>$Lang::tr{'mac address'}</b></a></th>
968 <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FIPADDR'><b>$Lang::tr{'ip address'}</b></a></th>
969 <th width='15%' align='center'><b>$Lang::tr{'remark'}</b></th>
970 <th width='15%' class='boldbase' align='center'><b>next-server</b></th>
971 <th width='15%' class='boldbase' align='center'><b>filename</b></th>
972 <th width='15%' class='boldbase' align='center'><b>root path</b></th>
973 <th colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></th>
979 my %macdupl = (); # Duplicate MACs have to be on different subnets
982 # mark duplicate ip or duplicate MAC
983 foreach my $line (@current2) {
984 my @temp = split(/\,/,$line);
985 $macdupl{$temp[0]} += 1;
986 if ($macdupl{$temp[0]} > 1) {
987 $ipdup = 1; # Flag up duplicates for use later
989 $ipinuse{$temp[1]} += 1;
990 if ($ipinuse{$temp[1]} > 1) {
991 $ipdup = 1; # Flag up duplicates for use later
993 # Mark IP addresses outwith known subnets
994 $ipoutside{$temp[1]} = 1;
995 foreach my $itf (@ITFs) {
996 if ( &General
::IpInSubnet
($temp[1],
997 $netsettings{"${itf}_NETADDRESS"},
998 $netsettings{"${itf}_NETMASK"})) {
999 $ipoutside{$temp[1]} = 0;
1006 foreach my $line (@current2) {
1009 chomp($line); # remove newline
1010 my @temp = split(/\,/,$line);
1012 if ($temp[2] eq "on") {
1014 $gdesc = $Lang::tr
{'click to disable'};
1017 $gdesc = $Lang::tr
{'click to enable'};
1020 # Skip all entries that do not match the search query
1021 if ($search_query ne "") {
1022 if (!grep(/$search_query/, @temp)) {
1028 if ($dhcpsettings{'KEY2'} eq $key) {
1030 $col="bgcolor='${Header::colouryellow}'";
1031 } elsif ($key % 2) {
1033 $col="bgcolor='$color{'color20'}'";
1036 $col="bgcolor='$color{'color22'}'";
1043 if ($ipinuse{$temp[1]} > 1) {
1047 if ($macdupl{$temp[0]} > 1) {
1051 if ($ipoutside{$temp[1]} > 0) {
1052 $TAG4 = "bgcolor='orange'" if ($dhcpsettings{'KEY2'} ne $key);
1056 <td align='center' $col>$TAG2$temp[0]$TAG3</td>
1057 <td align='center' $col $TAG4>$TAG0$temp[1]$TAG1</td>
1058 <td align='center' $col>$temp[6] </td>
1059 <td align='center' $col>$temp[3] </td>
1060 <td align='center' $col>$temp[4] </td>
1061 <td align='center' $col>$temp[5] </td>
1063 <td align='center' $col>
1064 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1065 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}2' />
1066 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
1067 <input type='hidden' name='KEY2' value='$key' />
1071 <td align='center' $col>
1072 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1073 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}2' />
1074 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
1075 <input type='hidden' name='KEY2' value='$key' />
1079 <td align='center' $col>
1080 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1081 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}2' />
1082 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
1083 <input type='hidden' name='KEY2' value='$key' />
1093 # If the fixed lease file contains entries, print Key to action icons
1095 my $dup = $ipdup ?
"<td class='base'>$Lang::tr{'duplicate ip bold'}</td>" :'';
1099 <td class='boldbase'> <b>$Lang::tr{'legend'}: </b></td>
1100 <td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
1101 <td class='base'>$Lang::tr{'click to disable'}</td>
1102 <td> </td>
1103 <td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
1104 <td class='base'>$Lang::tr{'click to enable'}</td>
1105 <td> </td>
1106 <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
1107 <td class='base'>$Lang::tr{'edit'}</td>
1108 <td> </td>
1109 <td><img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
1110 <td class='base'>$Lang::tr{'remove'}</td>
1114 <td bgcolor='orange'> </td>
1115 <td class='base'>$Lang::tr{'ip address outside subnets'}</td>
1125 &Header
::closebox
();
1127 foreach my $itf (@ITFs) {
1128 if ($dhcpsettings{"ENABLE_${itf}"} eq 'on') {
1129 # display leases with a list of actions to do with the global select checkbox.
1130 &Header
::PrintActualLeases
("+"); # "+" => create fixed leases from nodeaddress
1131 last; #Print one time only for all interfaces
1135 &Header
::closebigbox
();
1136 &Header
::closepage
();
1138 ## Ouf it's the end !
1140 sub sortcurrent1
# by now, do not sort, just write
1142 open(FILE
, ">$filename1") or die 'Unable to open dhcp advanced options file.';
1143 print FILE
@current1;
1148 # Sort the "current2" array according to choices
1153 sub fixedleasesort
{
1155 if (rindex ($dhcpsettings{'SORT_FLEASELIST'},'Rev') != -1) {
1156 $qs=substr ($dhcpsettings{'SORT_FLEASELIST'},0,length($dhcpsettings{'SORT_FLEASELIST'})-3);
1157 if ($qs eq 'FIPADDR') {
1158 my @a = split(/\./,$entries{$a}->{$qs});
1159 my @b = split(/\./,$entries{$b}->{$qs});
1165 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1167 } else { #not reverse
1168 $qs=$dhcpsettings{'SORT_FLEASELIST'};
1169 if ($qs eq 'FIPADDR') {
1170 my @a = split(/\./,$entries{$a}->{$qs});
1171 my @b = split(/\./,$entries{$b}->{$qs});
1177 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1182 #Use an associative array (%entries)
1183 foreach my $line (@current2) {
1184 chomp( $line); #remove newline because can be on field 5 or 6 (addition of REMARK)
1185 my @temp = split (',',$line);
1186 my @record = ('FETHER',$temp[0],'FIPADDR',$temp[1],'DATA',join(',',@temp[2..6]));
1187 my $record = {}; # create a reference to empty hash
1188 %{$record} = @record; # populate that hash with @record
1189 # use combination of ether & IP as key to allow duplicates in either but not both
1190 $entries{$record->{FETHER
} . $record->{FIPADDR
}} = $record; # add this to a hash of hashes
1193 open(FILE
, ">$filename2") or die 'Unable to open fixed lease file.';
1194 foreach my $entry ( sort fixedleasesort
keys %entries) {
1195 print FILE
"$entries{$entry}->{FETHER},$entries{$entry}->{FIPADDR},$entries{$entry}->{DATA}\n";
1199 # Reload sorted @current2
1200 open (FILE
, "$filename2");
1203 undef (%entries); #This array is reused latter. Clear it.
1206 # Build the configuration file mixing settings, fixed leases and advanced options
1208 open(FILE
, ">/${General::swroot}/dhcp/dhcpd.conf") or die "Unable to write dhcpd.conf file";
1212 print FILE
"deny bootp; #default\n";
1213 print FILE
"authoritative;\n";
1215 # DNS Update settings
1216 if ($dhcpsettings{'DNS_UPDATE_ENABLED'} eq 'on') {
1217 print FILE
"ddns-updates on;\n";
1218 print FILE
"ddns-update-style interim;\n";
1219 print FILE
"ddns-ttl 60; # 1 min\n";
1220 print FILE
"ignore client-updates;\n";
1221 print FILE
"update-static-leases on;\n";
1223 print FILE
"ddns-update-style none;\n";
1226 # Write first new option definition
1227 foreach my $line (@current1) {
1228 chomp($line); # remove newline
1229 my @temp = split(/\t/,$line);
1230 if (ExistNewOptionDefinition
($temp[1] . ' ' . $temp[2])) {
1231 print FILE
"option $temp[1] $temp[2];\n";
1234 # Write other global options
1235 foreach my $line (@current1) {
1236 chomp($line); # remove newline
1237 my @temp = split(/\t/,$line);
1239 if ($temp[0] eq 'on' && !ExistNewOptionDefinition
($temp[1] . ' ' . $temp[2])){ # active & !definition
1241 for (my $key=0; $key<@ITFs; $key++) {
1242 my $itf = $temp[3+$key];
1243 if ($itf ne 'off') # Only if an interface name is read
1249 print FILE
"option $temp[1] $temp[2];\n";
1255 #Subnet range definition
1256 foreach my $itf (@ITFs) {
1257 my $lc_itf=lc($itf);
1258 if ($dhcpsettings{"ENABLE_${itf}"} eq 'on' ){
1259 print FILE
"subnet " . $netsettings{"${itf}_NETADDRESS"} . " netmask ". $netsettings{"${itf}_NETMASK"} . " #$itf\n";
1261 print FILE
"\trange " . $dhcpsettings{"START_ADDR_${itf}"} . ' ' . $dhcpsettings{"END_ADDR_${itf}"}.";\n" if ($dhcpsettings{"START_ADDR_${itf}"});
1262 print FILE
"\toption subnet-mask " . $netsettings{"${itf}_NETMASK"} . ";\n";
1263 print FILE
"\toption domain-name \"" . $dhcpsettings{"DOMAIN_NAME_${itf}"} . "\";\n";
1264 print FILE
"\toption routers " . $netsettings{"${itf}_ADDRESS"} . ";\n";
1265 print FILE
"\toption domain-name-servers " . $dhcpsettings{"DNS1_${itf}"} if ($dhcpsettings{"DNS1_${itf}"});
1266 print FILE
", " . $dhcpsettings{"DNS2_${itf}"} if ($dhcpsettings{"DNS2_${itf}"});
1267 print FILE
";\n" if ($dhcpsettings{"DNS1_${itf}"});
1268 print FILE
"\toption ntp-servers " . $dhcpsettings{"NTP1_${itf}"} if ($dhcpsettings{"NTP1_${itf}"});
1269 print FILE
", " . $dhcpsettings{"NTP2_${itf}"} if ($dhcpsettings{"NTP2_${itf}"});
1270 print FILE
";\n" if ($dhcpsettings{"NTP1_${itf}"});
1271 print FILE
"\toption netbios-name-servers " . $dhcpsettings{"WINS1_${itf}"} if ($dhcpsettings{"WINS1_${itf}"});
1272 print FILE
", " . $dhcpsettings{"WINS2_${itf}"} if ($dhcpsettings{"WINS2_${itf}"});
1273 print FILE
";\n" if ($dhcpsettings{"WINS1_${itf}"});
1274 print FILE
"\tnext-server " . $dhcpsettings{"NEXT_${itf}"} . ";\n" if ($dhcpsettings{"NEXT_${itf}"});
1275 print FILE
"\tfilename \"" . $dhcpsettings{"FILE_${itf}"} . "\";\n" if ($dhcpsettings{"FILE_${itf}"});
1276 print FILE
"\tdefault-lease-time " . ($dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"} * 60). ";\n";
1277 print FILE
"\tmax-lease-time " . ($dhcpsettings{"MAX_LEASE_TIME_${itf}"} * 60) . ";\n";
1278 print FILE
"\tallow bootp;\n" if ($dhcpsettings{"ENABLEBOOTP_${itf}"} eq 'on');
1282 # Write scoped options
1283 foreach my $line (@current1) {
1284 chomp($line); # remove newline
1285 my @temp = split(/\t/,$line); # Use TAB separator !
1287 if ($temp[0] eq 'on'){
1288 for (my $key=0; $key<@ITFs; $key++) {
1289 if ($itf eq $temp[3+$key]) # Only is an interface name is read
1291 print FILE
"\toption $temp[1] $temp[2];\n";
1296 print FILE
"} #$itf\n\n";
1298 if (($dhcpsettings{"DNS_UPDATE_ENABLED"} eq "on") && ($dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"} ne "")) {
1299 print FILE
"key " . $dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"} . " {\n";
1300 print FILE
"\talgorithm " . $dhcpsettings{"DNS_UPDATE_KEY_ALGO_${itf}"} . ";\n";
1301 print FILE
"\tsecret \"" . $dhcpsettings{"DNS_UPDATE_KEY_SECRET_${itf}"} . "\";\n";
1302 print FILE
"};\n\n";
1304 print FILE
"zone " . $dhcpsettings{"DOMAIN_NAME_${itf}"} . ". {\n";
1305 print FILE
"\tkey " . $dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"} . ";\n";
1309 system ('/usr/bin/touch', "${General::swroot}/dhcp/enable_${lc_itf}");
1310 &General
::log("DHCP on ${itf}: " . $Lang::tr
{'dhcp server enabled'})
1312 unlink "${General::swroot}/dhcp/enable_${lc_itf}";
1313 &General
::log("DHCP on ${itf}: " . $Lang::tr
{'dhcp server disabled'})
1317 #write fixed leases if any. Does not handle duplicates to write them elsewhere than the global scope.
1319 foreach my $line (@current2) {
1321 my @temp = split(/\,/,$line);
1322 if ($temp[2] eq "on") {
1323 print FILE
"\nhost fix$key # $temp[6]\n";
1325 print FILE
"\thardware ethernet $temp[0];\n";
1326 print FILE
"\tfixed-address $temp[1];\n";
1327 print FILE
"\tnext-server $temp[3];\n" if ($temp[3]);
1328 print FILE
"\tfilename \"$temp[4]\";\n" if ($temp[4]);
1329 print FILE
"\toption root-path \"$temp[5]\";\n" if ($temp[5]);
1334 print FILE
"include \"${General::swroot}/dhcp/dhcpd.conf.local\";\n";
1336 if ( $dhcpsettings{"ENABLE_GREEN"} eq 'on' || $dhcpsettings{"ENABLE_BLUE"} eq 'on' ) {system '/usr/local/bin/dhcpctrl enable >/dev/null 2>&1';}
1337 else {system '/usr/local/bin/dhcpctrl disable >/dev/null 2>&1';}
1338 system '/usr/local/bin/dhcpctrl restart >/dev/null 2>&1';
1342 # Receive a string and if it match model for a new option,
1343 # add it to the list %newOptions
1345 my %NewOptions = ();
1347 sub AddNewOptionDefinition
{
1349 if ( $line =~ /^([-\w]+)( code \d+=($OptionTypes))/ ) {
1350 $NewOptions{$1} = $2;
1351 #&General::log ("new:<$1><$2>");
1358 # Check existence of definition for a new option
1360 sub ExistNewOptionDefinition
{
1363 if ( $line =~ /^([-\w]+)( code \d+=($OptionTypes))/ ) {
1364 return defined $NewOptions{$1};
1370 # Check if it is a new option (definition must exist)
1371 # "code=" test eliminate a false response when definition exists
1372 # but this string is a definition with bad $OptionTypes.
1373 sub ValidNewOption
{
1375 if ($line =~ /^([-\w]+) (.*)/ ) {
1376 return defined ( $NewOptions{$1} ) && $2 !~ /code=/;
1382 # Check if the new option $opt is used, except the definition of itself!
1384 sub IsUsedNewOptionDefinition
{
1385 my ($opt,$val) = @_;
1387 foreach my $line (@current1) {
1388 #chomp($line); # remove newline #don't know why, but this remove newline in @current1 .... !
1389 my @temp = split(/\t/,$line);
1390 # if we find something "opt value" & value != "code nnn=" it's ok.
1391 return 1 if ( ($opt eq $temp[1]) && ($temp[2] !~ /code \d+=/) );