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 ###############################################################################
23 use experimental
'smartmatch';
25 # enable only the following on debugging purpose
27 #use CGI::Carp 'fatalsToBrowser';
29 require '/var/ipfire/general-functions.pl';
30 require "${General::swroot}/lang.pl";
31 require "${General::swroot}/header.pl";
32 #workaround to suppress a warning when a variable is used only once
33 my @dummy = ( ${Header
::colouryellow
} );
40 my $setting = "${General::swroot}/dhcp/settings";
41 our $filename1 = "${General::swroot}/dhcp/advoptions"; # Field separator is TAB in this file (comma is standart)
42 # because we need commas in the some data
43 our $filename2 = "${General::swroot}/dhcp/fixleases";
44 our $filename3 = "${General::swroot}/dhcp/advoptions-list"; # Describe the allowed syntax for dhcp options
45 my $errormessage = '';
46 my $warnNTPmessage = '';
50 #Basic syntax allowed for new Option definition. Not implemented: RECORDS & array of RECORDS
51 our $OptionTypes = 'boolean|((un)?signed )?integer (8|16|32)|ip-address|text|string|encapsulate \w+|array of ip-address';
53 &Header
::showhttpheaders
();
55 if (&Header
::blue_used
()){push(@ITFs,'BLUE');}
57 #Settings1 for the first screen box
58 foreach my $itf (@ITFs) {
59 $dhcpsettings{"ENABLE_${itf}"} = 'off';
60 $dhcpsettings{"ENABLEBOOTP_${itf}"} = 'off';
61 $dhcpsettings{"START_ADDR_${itf}"} = '';
62 $dhcpsettings{"END_ADDR_${itf}"} = '';
63 $dhcpsettings{"DOMAIN_NAME_${itf}"} = '';
64 $dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"} = '';
65 $dhcpsettings{"MAX_LEASE_TIME_${itf}"} = '';
66 $dhcpsettings{"WINS1_${itf}"} = '';
67 $dhcpsettings{"WINS2_${itf}"} = '';
68 $dhcpsettings{"DNS1_${itf}"} = '';
69 $dhcpsettings{"DNS2_${itf}"} = '';
70 $dhcpsettings{"NTP1_${itf}"} = '';
71 $dhcpsettings{"NTP2_${itf}"} = '';
72 $dhcpsettings{"NEXT_${itf}"} = '';
73 $dhcpsettings{"FILE_${itf}"} = '';
74 $dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"} = '';
75 $dhcpsettings{"DNS_UPDATE_KEY_SECRET_${itf}"} = '';
76 $dhcpsettings{"DNS_UPDATE_KEY_ALGO_${itf}"} = '';
79 $dhcpsettings{'SORT_FLEASELIST'} = 'FIPADDR';
80 $dhcpsettings{'SORT_LEASELIST'} = 'IPADDR';
83 $dhcpsettings{'DNS_UPDATE_ENABLED'} = 'off';
85 #Settings2 for editing the multi-line list
86 #Must not be saved with writehash !
87 $dhcpsettings{'FIX_MAC'} = '';
88 $dhcpsettings{'FIX_ADDR'} = '';
89 $dhcpsettings{'FIX_ENABLED'} = 'off';
90 $dhcpsettings{'FIX_NEXTADDR'} = '';
91 $dhcpsettings{'FIX_FILENAME'} = '';
92 $dhcpsettings{'FIX_ROOTPATH'} = '';
93 $dhcpsettings{'FIX_REMARK'} = '';
94 $dhcpsettings{'ACTION'} = '';
95 $dhcpsettings{'KEY1'} = '';
96 $dhcpsettings{'KEY2'} = '';
97 @nosaved=('FIX_MAC','FIX_ADDR','FIX_ENABLED','FIX_NEXTADDR',
98 'FIX_FILENAME','FIX_ROOTPATH','FIX_REMARK');
100 $dhcpsettings{'ADVOPT_ENABLED'} = '';
101 $dhcpsettings{'ADVOPT_NAME'} = '';
102 $dhcpsettings{'ADVOPT_DATA'} = '';
103 unshift (@nosaved,'ADVOPT_ENABLED','ADVOPT_NAME','ADVOPT_DATA');
104 foreach my $itf (@ITFs) {
105 $dhcpsettings{"ADVOPT_SCOPE_${itf}"} = 'off';
106 unshift (@nosaved, "ADVOPT_SCOPE_${itf}");
109 # Read Ipcop settings
110 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
111 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
112 &General
::readhash
("${General::swroot}/time/settings", \
%timesettings);
113 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
116 &Header
::getcgihash
(\
%dhcpsettings);
118 open(FILE
, "$filename1") or die 'Unable to open dhcp advanced options file.';
119 our @current1 = <FILE
>;
121 # Extract OptionDefinition
122 foreach my $line (@current1) {
123 #chomp($line); # remove newline #don't know why, but this remove newline in @current1 .... !
124 my @temp = split(/\t/,$line);
125 AddNewOptionDefinition
($temp[1] . ' ' . $temp[2]);
128 open(FILE
, "$filename2") or die 'Unable to open fixed leases file.';
129 our @current2 = <FILE
>;
132 # Check Settings1 first because they are needed by &buildconf
133 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'save'}) {
134 foreach my $itf (@ITFs) {
135 if ($dhcpsettings{"ENABLE_${itf}"} eq 'on' ) {
136 # "Start" is defined, need "End" and vice versa
137 if ($dhcpsettings{"START_ADDR_${itf}"}) {
138 if (!(&General
::validip
($dhcpsettings{"START_ADDR_${itf}"}))) {
139 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid start address'};
142 if (!$dhcpsettings{"END_ADDR_${itf}"}) {
143 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid end address'};
146 if (! &General
::IpInSubnet
( $dhcpsettings{"START_ADDR_${itf}"},
147 $netsettings{"${itf}_NETADDRESS"},
148 $netsettings{"${itf}_NETMASK"})) {
149 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid start address'};
154 if ($dhcpsettings{"END_ADDR_${itf}"}) {
155 if (!(&General
::validip
($dhcpsettings{"END_ADDR_${itf}"}))) {
156 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid end address'};
159 if (!$dhcpsettings{"START_ADDR_${itf}"}) {
160 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid start address'};
163 if (! &General
::IpInSubnet
( $dhcpsettings{"END_ADDR_${itf}"},
164 $netsettings{"${itf}_NETADDRESS"},
165 $netsettings{"${itf}_NETMASK"})) {
166 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid end address'};
169 #swap if necessary! (support 255.255.0.0 range, I doubt we need more) GE
170 my @startoct = split (/\./, $dhcpsettings{"START_ADDR_${itf}"});
171 my @endoct = split (/\./, $dhcpsettings{"END_ADDR_${itf}"});
172 if ( $endoct[2]*256+$endoct[3] < $startoct[2]*256+$startoct[3] ) {
173 ($dhcpsettings{"START_ADDR_${itf}"},$dhcpsettings{"END_ADDR_${itf}"}) =
174 ($dhcpsettings{"END_ADDR_${itf}"},$dhcpsettings{"START_ADDR_${itf}"});
178 if (!($dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"} =~ /^\d+$/)) {
179 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid default lease time'} . $dhcpsettings{'DEFAULT_LEASE_TIME_${itf}'};
183 if (!($dhcpsettings{"MAX_LEASE_TIME_${itf}"} =~ /^\d+$/)) {
184 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid max lease time'} . $dhcpsettings{'MAX_LEASE_TIME_${itf}'};
188 if ($dhcpsettings{"DNS1_${itf}"}) {
189 if (!(&General
::validip
($dhcpsettings{"DNS1_${itf}"}))) {
190 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid primary dns'};
194 if ($dhcpsettings{"DNS2_${itf}"}) {
195 if (!(&General
::validip
($dhcpsettings{"DNS2_${itf}"}))) {
196 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid secondary dns'};
199 if (! $dhcpsettings{"DNS1_${itf}"}) {
200 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'cannot specify secondary dns without specifying primary'};
205 if ($dhcpsettings{"WINS1_${itf}"}) {
206 if (!(&General
::validip
($dhcpsettings{"WINS1_${itf}"}))) {
207 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid wins address'};
211 if ($dhcpsettings{"WINS2_${itf}"}) {
212 if (!(&General
::validip
($dhcpsettings{"WINS2_${itf}"}))) {
213 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid wins address'};
216 if (! $dhcpsettings{"WINS1_${itf}"} ) {
217 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'cannot specify secondary wins without specifying primary'};
221 if ($dhcpsettings{"NEXT_${itf}"}) {
222 if (!(&General
::validip
($dhcpsettings{"NEXT_${itf}"}))) {
223 $errormessage = "next-server on ${itf}: " . $Lang::tr
{'invalid ip'};
227 if ($dhcpsettings{"NTP1_${itf}"}) {
228 if (!(&General
::validip
($dhcpsettings{"NTP1_${itf}"}))) {
229 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid primary ntp'};
232 if ($dhcpsettings{"NTP1_${itf}"} eq $netsettings{"${itf}_ADDRESS"} && ($timesettings{'ENABLECLNTP'} ne 'on')) {
233 $warnNTPmessage = "DHCP on ${itf}: " . $Lang::tr
{'local ntp server specified but not enabled'};
237 if ($dhcpsettings{"NTP2_${itf}"}) {
238 if (!(&General
::validip
($dhcpsettings{"NTP2_${itf}"}))) {
239 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'invalid secondary ntp'};
242 if ($dhcpsettings{"NTP2_${itf}"} eq $netsettings{"${itf}_ADDRESS"} && ($timesettings{'ENABLECLNTP'} ne 'on')) {
243 $warnNTPmessage = "DHCP on ${itf}: " . $Lang::tr
{'local ntp server specified but not enabled'};
246 if (! $dhcpsettings{"NTP1_${itf}"}) {
247 $errormessage = "DHCP on ${itf}: " . $Lang::tr
{'cannot specify secondary ntp without specifying primary'};
252 }#loop interface verify
254 map (delete ($dhcpsettings{$_}) ,@nosaved,'ACTION','KEY1','KEY2','q'); # Must not be saved
255 &General
::writehash
($setting, \
%dhcpsettings); # Save good settings
256 $dhcpsettings{'ACTION'} = $Lang::tr
{'save'}; # create an 'ACTION'
257 map ($dhcpsettings{$_} = '',@nosaved,'KEY1','KEY2'); # and reinit vars to empty
259 ERROR
: # Leave the faulty field untouched
261 &General
::readhash
($setting, \
%dhcpsettings); # Get saved settings and reset to good if needed
264 ## Sorting of fixed leases
265 if ($ENV{'QUERY_STRING'} =~ /^FETHER|^FIPADDR/ ) {
266 my $newsort=$ENV{'QUERY_STRING'};
267 my $act=$dhcpsettings{'SORT_FLEASELIST'};
268 #Reverse actual sort ?
269 if ($act =~ $newsort) {
276 $dhcpsettings{'SORT_FLEASELIST'}=$newsort;
277 map (delete ($dhcpsettings{$_}) ,@nosaved,'ACTION','KEY1','KEY2', 'q'); # Must never be saved
278 &General
::writehash
($setting, \
%dhcpsettings);
280 $dhcpsettings{'ACTION'} = 'SORT'; # create an 'ACTION'
281 map ($dhcpsettings{$_} = '',@nosaved,'KEY1','KEY2');# and reinit vars to empty
284 #Sorting of allocated leases
285 &Header
::CheckSortOrder
;
288 ## Now manipulate the two multi-line list with Settings2.
289 # '1' suffix is for ADVANCED OPTIONS
290 # '2' suffix is for FIXED LEASES
292 # Toggle enable/disable field on specified options.
294 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'toggle enable disable'}.'1') {
296 chomp(@current1[$dhcpsettings{'KEY1'}]);
297 my @temp = split(/\t/,@current1[$dhcpsettings{'KEY1'}]); #use TAB separator !
298 $temp[0] = $temp[0] eq 'on' ?
'' : 'on'; # Toggle the field
299 @current1[$dhcpsettings{'KEY1'}] = join ("\t",@temp)."\n";
300 $dhcpsettings{'KEY1'} = ''; # End edit mode
301 &General
::log($Lang::tr
{'dhcp advopt modified'});
302 open(FILE
, ">$filename1") or die 'Unable to open dhcp advanced options file.';
303 print FILE
@current1;
306 #Write changes to dhcpd.conf.
312 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'add'}.'1' &&
313 $dhcpsettings{'SUBMIT'} ne $Lang::tr
{'dhcp advopt help'}) {
314 $dhcpsettings{'ADVOPT_NAME'} =~ s/[^ \w-]//g; # prevent execution of code by removing everything except letters/space
315 $dhcpsettings{'ADVOPT_DATA'} =~ s/`//g; # back tik ` ? not allowed !
317 if ($dhcpsettings{'ADVOPT_DATA'} eq '') {
318 $errormessage=$Lang::tr
{'dhcp advopt blank value'};
321 # Test for a new option definition string (join field name & data)
322 if (ExistNewOptionDefinition
($dhcpsettings{'ADVOPT_NAME'} . ' ' . $dhcpsettings{'ADVOPT_DATA'})) {
323 #only edit permitted if option definition exists
324 $errormessage = $Lang::tr
{'dhcp advopt definition exists'} if ($dhcpsettings{'KEY1'} eq '');
325 $dhcpsettings{'ADVOPT_ENABLED'} = 'on'; # force active
326 map ($dhcpsettings{"ADVOPT_SCOPE_$_"} = 'off', @ITFs); # force global
327 } elsif (AddNewOptionDefinition
($dhcpsettings{'ADVOPT_NAME'} . ' ' . $dhcpsettings{'ADVOPT_DATA'})) {
328 #was a new option definition
329 $dhcpsettings{'ADVOPT_ENABLED'} = 'on'; # force active
330 map ($dhcpsettings{"ADVOPT_SCOPE_$_"} = 'off', @ITFs); # force global
331 } elsif (ValidNewOption
($dhcpsettings{'ADVOPT_NAME'} . ' ' . $dhcpsettings{'ADVOPT_DATA'})) {
333 } elsif (! `grep "\$option $dhcpsettings{'ADVOPT_NAME'} " $filename3`) {
334 $errormessage=$Lang::tr
{'dhcp advopt unknown'}.': '.$dhcpsettings{'ADVOPT_NAME'};
337 unless ($errormessage) {
340 foreach my $itf (@ITFs) { # buils "RED,GREEN,ORANGE,... based on selection
341 $scope .= $dhcpsettings{"ADVOPT_SCOPE_${itf}"} eq 'on' ?
"\t$itf" : "\toff" ;
343 if ($dhcpsettings{'KEY1'} eq '') { #add or edit ? TAB separator !
344 unshift (@current1, "$dhcpsettings{'ADVOPT_ENABLED'}\t$dhcpsettings{'ADVOPT_NAME'}\t$dhcpsettings{'ADVOPT_DATA'}$scope\n");
345 &General
::log($Lang::tr
{'dhcp advopt added'});
347 @current1[$dhcpsettings{'KEY1'}] = "$dhcpsettings{'ADVOPT_ENABLED'}\t$dhcpsettings{'ADVOPT_NAME'}\t$dhcpsettings{'ADVOPT_DATA'}$scope\n";
348 $dhcpsettings{'KEY1'} = ''; # End edit mode
349 &General
::log($Lang::tr
{'dhcp advopt modified'});
352 #Write changes to dhcpd.conf.
353 &sortcurrent1
; # sort newly added/modified entry
354 &buildconf
; # before calling buildconf which use fixed lease file !
358 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'edit'}.'1') {
360 my $line = @current1[$dhcpsettings{'KEY1'}];
362 my @temp = split(/\t/, $line);
363 $dhcpsettings{'ADVOPT_ENABLED'}=$temp[0];
364 $dhcpsettings{'ADVOPT_NAME'}=$temp[1];
365 $dhcpsettings{'ADVOPT_DATA'}=$temp[2];
367 # read next fields which are the name (color) of an interface if this interface is scoped
368 for (my $key=0; $key<@ITFs; $key++) {
369 my $itf = $temp[3+$key];
370 if ($itf ne 'off') # Only is an interface name is read
372 $dhcpsettings{"ADVOPT_SCOPE_${itf}"} = 'on';
377 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'remove'}.'1') {
378 splice (@current1,$dhcpsettings{'KEY1'},1);
379 open(FILE
, ">$filename1") or die 'Unable to open dhcp advanced options file.';
380 print FILE
@current1;
382 $dhcpsettings{'KEY1'} = ''; # End remove mode
383 &General
::log($Lang::tr
{'dhcp advopt removed'});
384 #Write changes to dhcpd.conf.
390 # Toggle enable/disable field on specified lease.
391 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'toggle enable disable'}.'2') {
393 chomp(@current2[$dhcpsettings{'KEY2'}]);
394 my @temp = split(/\,/,@current2[$dhcpsettings{'KEY2'}]);
395 $temp[2] = $temp[2] eq 'on' ?
'' : 'on'; # Toggle the field
396 @current2[$dhcpsettings{'KEY2'}] = join (',',@temp)."\n";
397 $dhcpsettings{'KEY2'} = ''; # End edit mode
398 &General
::log($Lang::tr
{'fixed ip lease modified'});
399 open(FILE
, ">$filename2") or die 'Unable to open fixed leases file.';
400 print FILE
@current2;
403 #Write changes to dhcpd.conf.
407 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'add'}.'2') {
408 $dhcpsettings{'FIX_MAC'} =~ tr/-/:/;
409 unless(&General
::validip
($dhcpsettings{'FIX_ADDR'})) { $errormessage = $Lang::tr
{'invalid fixed ip address'}; }
410 unless(&General
::validmac
($dhcpsettings{'FIX_MAC'})) { $errormessage = $Lang::tr
{'invalid fixed mac address'}; }
411 if ($dhcpsettings{'FIX_NEXTADDR'}) {
412 unless(&General
::validip
($dhcpsettings{'FIX_NEXTADDR'})) { $errormessage = $Lang::tr
{'invalid fixed ip address'}; }
416 CHECK:foreach my $line (@current2) {
417 my @temp = split(/\,/,$line);
418 if($dhcpsettings{'KEY2'} ne $key) {
419 # same MAC is OK on different subnets. This test is not complete because
420 # if ip are not inside a known subnet, I don't warn.
421 # Also it may be needed to put duplicate fixed lease in their right subnet definition..
422 foreach my $itf (@ITFs) {
423 my $scoped = &General
::IpInSubnet
($dhcpsettings{'FIX_ADDR'},
424 $netsettings{"${itf}_NETADDRESS"},
425 $netsettings{"${itf}_NETMASK"}) &&
426 $dhcpsettings{"ENABLE_${itf}"} eq 'on';
428 (lc($dhcpsettings{'FIX_MAC'}) eq lc($temp[0])) &&
429 &General
::IpInSubnet
($temp[1],
430 $netsettings{"${itf}_NETADDRESS"},
431 $netsettings{"${itf}_NETMASK"})) {
432 $errormessage = "$Lang::tr{'mac address in use'} $dhcpsettings{'FIX_MAC'}";
440 unless ($errormessage) {
441 $dhcpsettings{'FIX_REMARK'} = &Header
::cleanhtml
($dhcpsettings{'FIX_REMARK'});
442 $dhcpsettings{'FIX_NEXTADDR'} = &Header
::cleanhtml
($dhcpsettings{'FIX_NEXTADDR'});
443 $dhcpsettings{'FIX_FILENAME'} = &Header
::cleanhtml
($dhcpsettings{'FIX_FILENAME'});
444 $dhcpsettings{'FIX_ROOTPATH'} = &Header
::cleanhtml
($dhcpsettings{'FIX_ROOTPATH'});
445 if ($dhcpsettings{'KEY2'} eq '') { #add or edit ?
446 unshift (@current2, "$dhcpsettings{'FIX_MAC'},$dhcpsettings{'FIX_ADDR'},$dhcpsettings{'FIX_ENABLED'},$dhcpsettings{'FIX_NEXTADDR'},$dhcpsettings{'FIX_FILENAME'},$dhcpsettings{'FIX_ROOTPATH'},$dhcpsettings{'FIX_REMARK'}\n");
447 open(FILE
, ">$filename2") or die 'Unable to open fixed lease file.';
448 print FILE
@current2;
450 &General
::log($Lang::tr
{'fixed ip lease added'});
453 $dhcpsettings{'KEY2'} = 0;
455 @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";
456 $dhcpsettings{'KEY2'} = ''; # End edit mode
457 &General
::log($Lang::tr
{'fixed ip lease modified'});
459 # sort newly added/modified entry
463 #Write changes to dhcpd.conf.
464 &buildconf
; # before calling buildconf which use fixed lease file !
468 if ($dhcpsettings{'ACTION_ALL'} eq '+') {
470 foreach (keys %dhcpsettings) {
471 if (/^(\d+\.\d+\.\d+\.\d+)-([0-9a-fA-F:]+)$/) { # checked names are index of the line
474 if (!grep (/$2/,@current2)) {
475 unshift (@current2, "$mac,$ip,on,,,,imported\n");
481 #Write changes to dhcpd.conf.
482 $warnNTPmessage = $Lang::tr
{'fixed ip lease added'}."($news)";
483 &General
::log($warnNTPmessage);
484 &sortcurrent2
; # sort newly added/modified entry
485 &buildconf
; # before calling buildconf which use fixed lease file !
489 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'edit'}.'2') {
491 my $line = @current2[$dhcpsettings{'KEY2'}];
493 my @temp = split(/\,/, $line);
494 $dhcpsettings{'FIX_MAC'}=$temp[0];
495 $dhcpsettings{'FIX_ADDR'}=$temp[1];
496 $dhcpsettings{'FIX_ENABLED'}=$temp[2];
497 $dhcpsettings{'FIX_NEXTADDR'}=$temp[3];
498 $dhcpsettings{'FIX_FILENAME'}=$temp[4];
499 $dhcpsettings{'FIX_ROOTPATH'}=$temp[5];
500 $dhcpsettings{'FIX_REMARK'}=$temp[6];
503 if ($dhcpsettings{'ACTION'} eq $Lang::tr
{'remove'}.'2') {
504 splice (@current2,$dhcpsettings{'KEY2'},1);
505 open(FILE
, ">$filename2") or die 'Unable to open fixed lease file.';
506 print FILE
@current2;
508 $dhcpsettings{'KEY2'} = ''; # End remove mode
509 &General
::log($Lang::tr
{'fixed ip lease removed'});
510 #Write changes to dhcpd.conf.
518 if ($dhcpsettings{'ACTION'} eq '' ) { # First launch from GUI
520 # Set default DHCP values only if blank and disabled
521 foreach my $itf (@ITFs) {
522 if ($dhcpsettings{"ENABLE_${itf}"} ne 'on' ) {
523 $dhcpsettings{"DNS1_${itf}"} = $netsettings{"${itf}_ADDRESS"};
524 $dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"} = '60';
525 $dhcpsettings{"MAX_LEASE_TIME_${itf}"} = '120';
526 $dhcpsettings{"DOMAIN_NAME_${itf}"} = $mainsettings{'DOMAINNAME'};
529 $dhcpsettings{'FIX_ENABLED'} = 'on';
532 &Header
::openpage
($Lang::tr
{'dhcp configuration'}, 1, '');
533 &Header
::openbigbox
('100%', 'left', '', $errormessage);
536 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
537 print "<font class='base'>$errormessage </font>\n";
540 if ($warnNTPmessage) {
541 $warnNTPmessage = "<font color=${Header::colourred}><b>$Lang::tr{'capswarning'}</b></font>: $warnNTPmessage";
544 &Header
::openbox
('100%', 'left', 'DHCP');
545 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>";
547 foreach my $itf (@ITFs) {
549 $checked{'ENABLE'}{'on'} = ( $dhcpsettings{"ENABLE_${itf}"} ne 'on') ?
'' : "checked='checked'";
550 $checked{'ENABLEBOOTP'}{'on'} = ( $dhcpsettings{"ENABLEBOOTP_${itf}"} ne 'on') ?
'' : "checked='checked'";
552 if ($netsettings{"${itf}_DEV"} ne '' ) { # Show only defined interface
557 <td width='25%' class='boldbase'><b><font color='${lc_itf}'>$Lang::tr{"$lc_itf interface"}</font></b></td>
558 <td class='base'>$Lang::tr{'enabled'}
559 <input type='checkbox' name='ENABLE_${itf}' $checked{'ENABLE'}{'on'} /></td>
560 <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>
562 <td width='25%' class='base'>$Lang::tr{'start address'} <img src='/blob.gif' alt='*' /></td>
563 <td width='25%'><input type='text' name='START_ADDR_${itf}' value='$dhcpsettings{"START_ADDR_${itf}"}' /></td>
564 <td width='25%' class='base'>$Lang::tr{'end address'} <img src='/blob.gif' alt='*' /></td>
565 <td width='25%'><input type='text' name='END_ADDR_${itf}' value='$dhcpsettings{"END_ADDR_${itf}"}' /></td>
567 <td class='base'>$Lang::tr{'default lease time'} <img src='/blob.gif' alt='*' /></td>
568 <td><input type='text' name='DEFAULT_LEASE_TIME_${itf}' value='$dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"}' /></td>
569 <td class='base'>$Lang::tr{'max lease time'} <img src='/blob.gif' alt='*' /></td>
570 <td><input type='text' name='MAX_LEASE_TIME_${itf}' value='$dhcpsettings{"MAX_LEASE_TIME_${itf}"}' /></td>
572 <td class='base'>$Lang::tr{'domain name suffix'}</td>
573 <td><input type='text' name='DOMAIN_NAME_${itf}' value='$dhcpsettings{"DOMAIN_NAME_${itf}"}' /></td>
574 <td>$Lang::tr{'dhcp allow bootp'}:</td>
575 <td><input type='checkbox' name='ENABLEBOOTP_${itf}' $checked{'ENABLEBOOTP'}{'on'} /></td>
577 <td class='base'>$Lang::tr{'primary dns'} <img src='/blob.gif' alt='*' /></td>
578 <td><input type='text' name='DNS1_${itf}' value='$dhcpsettings{"DNS1_${itf}"}' /></td>
579 <td class='base'>$Lang::tr{'secondary dns'}</td>
580 <td><input type='text' name='DNS2_${itf}' value='$dhcpsettings{"DNS2_${itf}"}' /></td>
582 <td class='base'>$Lang::tr{'primary ntp server'}:</td>
583 <td><input type='text' name='NTP1_${itf}' value='$dhcpsettings{"NTP1_${itf}"}' /></td>
584 <td class='base'>$Lang::tr{'secondary ntp server'}:</td>
585 <td><input type='text' name='NTP2_${itf}' value='$dhcpsettings{"NTP2_${itf}"}' /></td>
587 <td class='base'>$Lang::tr{'primary wins server address'}:</td>
588 <td><input type='text' name='WINS1_${itf}' value='$dhcpsettings{"WINS1_${itf}"}' /></td>
589 <td class='base'>$Lang::tr{'secondary wins server address'}:</td>
590 <td><input type='text' name='WINS2_${itf}' value='$dhcpsettings{"WINS2_${itf}"}' /></td>
592 <td class='base'>next-server:</td>
593 <td><input type='text' name='NEXT_${itf}' value='$dhcpsettings{"NEXT_${itf}"}' /></td>
594 <td class='base'>filename:</td>
595 <td><input type='text' name='FILE_${itf}' value='$dhcpsettings{"FILE_${itf}"}' /></td>
601 }# Show only defined interface
606 <td class='base' width='25%'><img src='/blob.gif' align='top' alt='*' /> $Lang::tr{'required field'}</td>
607 <td class='base' width='30%'>$warnNTPmessage</td>
608 <td width='40%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
615 # DHCP DNS update support (RFC2136)
616 &Header
::openbox
('100%', 'left', $Lang::tr
{'dhcp dns update'});
619 $checked{'DNS_UPDATE_ENABLED'}{'on'} = ( $dhcpsettings{'DNS_UPDATE_ENABLED'} ne 'on') ?
'' : "checked='checked'";
624 <td width='25%' class='boldbase'>$Lang::tr{'dhcp dns enable update'}</td>
625 <td class='base'><input type='checkbox' name='DNS_UPDATE_ENABLED' $checked{'DNS_UPDATE_ENABLED'}{'on'}>
635 # Print options for each interface.
636 foreach my $itf (@ITFs) {
637 # Check if DHCP for this interface is enabled.
638 if ($dhcpsettings{"ENABLE_${itf}"} eq 'on') {
639 # Check for same domain name.
640 next if ($dhcpsettings{"DOMAIN_NAME_${itf}"} ~~ @domains);
641 my $lc_itf = lc($itf);
643 # Select previously configured update algorithm.
645 $selected{'DNS_UPDATE_ALGO_${inf}'}{$dhcpsettings{'DNS_UPDATE_ALGO_${inf}'}} = 'selected';
649 <td colspan='6'> </td>
652 <td colspan='6' class='boldbase'><b>$dhcpsettings{"DOMAIN_NAME_${itf}"}</b></td>
655 <td width='10%' class='boldbase'>$Lang::tr{'dhcp dns key name'}:</td>
656 <td width='20%'><input type='text' name='DNS_UPDATE_KEY_NAME_${itf}' value='$dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"}'></td>
657 <td width='10%' class='boldbase' align='right'>$Lang::tr{'dhcp dns update secret'}: </td>
658 <td width='20%'><input type='password' name='DNS_UPDATE_KEY_SECRET_${itf}' value='$dhcpsettings{"DNS_UPDATE_KEY_SECRET_${itf}"}'></td>
659 <td width='10%' class='boldbase' align='right'>$Lang::tr{'dhcp dns update algo'}: </td>
661 <select name='DNS_UPDATE_KEY_ALGO_${itf}'>
662 <!-- <option value='hmac-sha1' $selected{'DNS_UPDATE_KEY_ALGO_${itf}'}{'hmac-sha1'}>HMAC-SHA1</option> -->
663 <option value='hmac-md5' $selected{'DNS_UPDATE_KEY_ALGO_${itf}'}{'hmac-md5'}>HMAC-MD5</option>
671 # Store configured domain based on the interface
672 # in the temporary variable.
673 push(@domains, $dhcpsettings{"DOMAIN_NAME_${itf}"});
680 <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
689 &Header
::openbox
('100%', 'left', $Lang::tr
{'dhcp advopt list'});
690 # DHCP Advanced options settings
692 $checked{'ADVOPT_ENABLED'}{'on'} = ($dhcpsettings{'ADVOPT_ENABLED'} ne 'on') ?
'' : "checked='checked'";
694 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'>";
695 my $buttontext = $Lang::tr
{'add'};
696 if ($dhcpsettings{'KEY1'} ne '') {
697 $buttontext = $Lang::tr
{'update'};
698 print "<tr><td class='boldbase'><b>$Lang::tr{'dhcp advopt edit'}</b></td></tr>";
700 print "<tr><td class='boldbase'><b>$Lang::tr{'dhcp advopt add'}</b></td></tr>"
703 #search if the 'option' is in the list and print the syntax model
704 my $opt = `grep "\$option $dhcpsettings{'ADVOPT_NAME'} " $filename3`;
706 $opt =~ s/option $dhcpsettings{'ADVOPT_NAME'}/Syntax:/; # "option xyz abc" => "syntax: abc"
708 $opt = "<tr><td></td><td></td><td colspan='2'>$opt</td></tr>";
712 <td class='base'>$Lang::tr{'dhcp advopt name'}: <img src='/blob.gif' alt='*' /></td>
713 <td><input type='text' name='ADVOPT_NAME' value='$dhcpsettings{'ADVOPT_NAME'}' size='18' /></td>
714 <td class='base'>$Lang::tr{'dhcp advopt value'}: <img src='/blob.gif' alt='*' /></td>
715 <td><input type='text' name='ADVOPT_DATA' value='$dhcpsettings{'ADVOPT_DATA'}' size='40' /></td>
717 <td class='base'>$Lang::tr{'enabled'}</td><td><input type='checkbox' name='ADVOPT_ENABLED' $checked{'ADVOPT_ENABLED'}{'on'} /></td>
718 <td class='base'>$Lang::tr{'dhcp advopt scope'}:</td>
723 # Put a checkbox for each interface. Checkbox visible disabled if interface is disabled
724 foreach my $itf (@ITFs) {
726 $checked{'ADVOPT_SCOPE_${itf}'}{'on'} = $dhcpsettings{"ADVOPT_SCOPE_${itf}"} ne 'on' ?
'' : "checked='checked'";
727 print "$Lang::tr{\"${lc_itf}\"} <input type='checkbox' name='ADVOPT_SCOPE_${itf}' $checked{'ADVOPT_SCOPE_${itf}'}{'on'} ";
728 print $dhcpsettings{"ENABLE_${itf}"} eq 'on' ?
"/>" : "disabled='disabled' />";
729 print " ";
739 <td class='base' width='50%'>$Lang::tr{'dhcp advopt scope help'}</td>
740 <td width='50%' align='right'>
741 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}1' />
742 <input type='submit' name='SUBMIT' value='$buttontext' />
743 <input type='submit' name='SUBMIT' value='$Lang::tr{'dhcp advopt help'}' />
744 <input type='hidden' name='KEY1' value='$dhcpsettings{'KEY1'}' />
751 #Edited line number (KEY1) passed until cleared by 'save' or 'remove' or 'new sort order'
753 # print help taken from the file describing options
754 if ($dhcpsettings{'SUBMIT'} eq $Lang::tr
{'dhcp advopt help'}) {
756 print "<table width='100%'>";
757 print "<tr><td width='30%'><b>$Lang::tr{'dhcp advopt name'}</b></td><td width='70%'><b>$Lang::tr{'dhcp advopt value'}</b></td>";
758 open(FILE
, "$filename3");
759 my @current3 = <FILE
>;
761 foreach my $line (@current3) {
762 $line =~ /option ([a-z0-9-]+) (.*);/;
763 print "<tr><td>$1</td><td>$2</td></tr>\n";
765 print "<tr><td colspan='2'><hr /></td></tr>\n";
766 print '<tr><td>string type</td><td>"quoted string" or 00:01:FF...</td></tr>';
767 print '<tr><td>ip-address type </td><td>10.0.0.1 | www.dot.com</td></tr>';
768 print '<tr><td>int,uint types</td><td>numbers</td></tr>';
769 print '<tr><td>flag type</td><td>on | off</td></tr>';
772 print "<table width='100%'>";
773 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>";
774 print "<tr><td>any-name </td><td> code NNN=$OptionTypes</td></tr>";
775 print '<tr><td>a-string</td><td>code 100=string</td></tr>';
776 print '<tr><td>a-number</td><td>code 101=signed integer 8</td></tr>';
777 print '<tr><td>wpad</td><td>code 252=text</td></tr>';
778 print '<tr><td>wpad</td><td>"http://www.server.fr/path-to/proxy.pac"</td></tr>';
787 <td width='30%' class='boldbase' align='center'><b>$Lang::tr{'dhcp advopt name'}</b></td>
788 <td width='50%' class='boldbase' align='center'><b>$Lang::tr{'dhcp advopt value'}</b></td>
789 <td width='20%' class='boldbase' align='center'><b>$Lang::tr{'dhcp advopt scope'}</b></td>
790 <td colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></td>
795 foreach my $line (@current1) {
798 chomp($line); # remove newline
799 my @temp = split(/\t/,$line);
801 if ($temp[0] eq "on") {
803 $gdesc = $Lang::tr
{'click to disable'};
806 $gdesc = $Lang::tr
{'click to enable'};
809 if ($dhcpsettings{'KEY1'} eq $key) {
810 print "<tr bgcolor='${Header::colouryellow}'>";
812 print "<tr bgcolor='$color{'color22'}'>";
814 print "<tr bgcolor='$color{'color20'}'>";
818 <td align='center'>$temp[1]</td>
819 <td align='center'>$temp[2]</td>
823 # Prepare a global flag to make easy reading
825 my $disabledTogle = '';
826 my $disabledEditRemove = '';
827 if ( ExistNewOptionDefinition
($temp[1] . ' ' . $temp[2]) ) {
828 $global = $Lang::tr
{'dhcp advopt definition'};
829 $disabledTogle = "disabled='disabled'";
830 # Search if it is a used NewOptionDefinition to also disable edit & delete
831 $disabledEditRemove = "disabled='disabled'" if (IsUsedNewOptionDefinition
($temp[1], $temp[2]));
833 $global = $Lang::tr
{'dhcp advopt scope global'};
837 # Print each checked interface
838 for (my $key=0; $key<@ITFs; $key++) {
839 my $itf = $temp[3+$key];
840 if ($itf ne 'off') { # Only if an interface name is read
842 $global=''; # fall to local scope !
848 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
849 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}1' />
850 <input $disabledTogle type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
851 <input type='hidden' name='KEY1' value='$key' />
856 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
857 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}1' />
858 <input $disabledEditRemove type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
859 <input type='hidden' name='KEY1' value='$key' />
864 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
865 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}1' />
866 <input $disabledEditRemove type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
867 <input type='hidden' name='KEY1' value='$key' />
878 # If there are dhcp options, print Key to action icons
883 <td class='boldbase'> <b>$Lang::tr{'legend'}: </b></td>
884 <td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
885 <td class='base'>$Lang::tr{'click to disable'}</td>
886 <td> </td>
887 <td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
888 <td class='base'>$Lang::tr{'click to enable'}</td>
889 <td> </td>
890 <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
891 <td class='base'>$Lang::tr{'edit'}</td>
892 <td> </td>
893 <td><img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
894 <td class='base'>$Lang::tr{'remove'}</td>
902 &Header
::openbox
('100%', 'left', $Lang::tr
{'current fixed leases'});
903 # Fixed leases screens
904 $checked{'FIX_ENABLED'}{'on'} = ($dhcpsettings{'FIX_ENABLED'} ne 'on') ?
'' : "checked='checked'";
906 $buttontext = $Lang::tr
{'add'};
907 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'>";
909 if ($dhcpsettings{'KEY2'} ne '') {
910 $buttontext = $Lang::tr
{'update'};
911 print "<tr><td class='boldbase' colspan='3'><b>$Lang::tr{'edit an existing lease'}</b></td></tr>";
913 print "<tr><td class='boldbase' colspan='3'><b>$Lang::tr{'add new lease'}</b></td></tr>"
917 <td class='base'>$Lang::tr{'mac address'}: <img src='/blob.gif' alt='*' /></td>
918 <td><input type='text' name='FIX_MAC' value='$dhcpsettings{'FIX_MAC'}' size='18' /></td>
919 <td class='base'>$Lang::tr{'ip address'}: <img src='/blob.gif' alt='*' /></td>
920 <td><input type='text' name='FIX_ADDR' value='$dhcpsettings{'FIX_ADDR'}' size='18' /></td>
921 <td class='base'>$Lang::tr{'remark'}:</td>
922 <td><input type='text' name='FIX_REMARK' value='$dhcpsettings{'FIX_REMARK'}' size='18' /></td>
924 <td class='base'>$Lang::tr{'enabled'}</td><td><input type='checkbox' name='FIX_ENABLED' $checked{'FIX_ENABLED'}{'on'} /></td>
926 <td colspan = '3'><b>$Lang::tr{'dhcp bootp pxe data'}</b></td>
928 <td class='base'>next-server:</td>
929 <td><input type='text' name='FIX_NEXTADDR' value='$dhcpsettings{'FIX_NEXTADDR'}' size='18' /></td>
930 <td class='base'>filename:</td>
931 <td><input type='text' name='FIX_FILENAME' value='$dhcpsettings{'FIX_FILENAME'}' size='18' /></td>
932 <td class='base'>root path:</td>
933 <td><input type='text' name='FIX_ROOTPATH' value='$dhcpsettings{'FIX_ROOTPATH'}' size='18' /></td>
939 <td class='base' width='50%'><img src='/blob.gif' align='top' alt='*' /> $Lang::tr{'required field'}</td>
940 <td width='50%' align='right'>
941 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}2' />
942 <input type='submit' name='SUBMIT' value='$buttontext' />
943 <input type='hidden' name='KEY2' value='$dhcpsettings{'KEY2'}' /></td>
949 #Edited line number (KEY2) passed until cleared by 'save' or 'remove' or 'new sort order'
951 # Search for static leases
952 my $search_query = $dhcpsettings{'q'};
954 if (scalar @current2 >= 10) {
956 <form method="POST" action="#search">
957 <a name="search"></a>
961 <input type="text" name="q" value="$search_query">
962 <input type="submit" value="$Lang::tr{'search'}">
971 <table width='100%' class='tbl'>
973 <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FETHER'><b>$Lang::tr{'mac address'}</b></a></th>
974 <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FIPADDR'><b>$Lang::tr{'ip address'}</b></a></th>
975 <th width='15%' align='center'><b>$Lang::tr{'remark'}</b></th>
976 <th width='15%' class='boldbase' align='center'><b>next-server</b></th>
977 <th width='15%' class='boldbase' align='center'><b>filename</b></th>
978 <th width='15%' class='boldbase' align='center'><b>root path</b></th>
979 <th colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></th>
985 my %macdupl = (); # Duplicate MACs have to be on different subnets
988 # mark duplicate ip or duplicate MAC
989 foreach my $line (@current2) {
990 my @temp = split(/\,/,$line);
991 $macdupl{$temp[0]} += 1;
992 if ($macdupl{$temp[0]} > 1) {
993 $ipdup = 1; # Flag up duplicates for use later
995 $ipinuse{$temp[1]} += 1;
996 if ($ipinuse{$temp[1]} > 1) {
997 $ipdup = 1; # Flag up duplicates for use later
999 # Mark IP addresses outwith known subnets
1000 $ipoutside{$temp[1]} = 1;
1001 foreach my $itf (@ITFs) {
1002 if ( &General
::IpInSubnet
($temp[1],
1003 $netsettings{"${itf}_NETADDRESS"},
1004 $netsettings{"${itf}_NETMASK"})) {
1005 $ipoutside{$temp[1]} = 0;
1012 foreach my $line (@current2) {
1015 chomp($line); # remove newline
1016 my @temp = split(/\,/,$line);
1018 if ($temp[2] eq "on") {
1020 $gdesc = $Lang::tr
{'click to disable'};
1023 $gdesc = $Lang::tr
{'click to enable'};
1026 # Skip all entries that do not match the search query
1027 if ($search_query ne "") {
1028 if (!grep(/$search_query/, @temp)) {
1034 if ($dhcpsettings{'KEY2'} eq $key) {
1036 $col="bgcolor='${Header::colouryellow}'";
1037 } elsif ($key % 2) {
1039 $col="bgcolor='$color{'color20'}'";
1042 $col="bgcolor='$color{'color22'}'";
1049 if ($ipinuse{$temp[1]} > 1) {
1053 if ($macdupl{$temp[0]} > 1) {
1057 if ($ipoutside{$temp[1]} > 0) {
1058 $TAG4 = "bgcolor='orange'" if ($dhcpsettings{'KEY2'} ne $key);
1062 <td align='center' $col>$TAG2$temp[0]$TAG3</td>
1063 <td align='center' $col $TAG4>$TAG0$temp[1]$TAG1</td>
1064 <td align='center' $col>$temp[6] </td>
1065 <td align='center' $col>$temp[3] </td>
1066 <td align='center' $col>$temp[4] </td>
1067 <td align='center' $col>$temp[5] </td>
1069 <td align='center' $col>
1070 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1071 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}2' />
1072 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
1073 <input type='hidden' name='KEY2' value='$key' />
1077 <td align='center' $col>
1078 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1079 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}2' />
1080 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
1081 <input type='hidden' name='KEY2' value='$key' />
1085 <td align='center' $col>
1086 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1087 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}2' />
1088 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
1089 <input type='hidden' name='KEY2' value='$key' />
1099 # If the fixed lease file contains entries, print Key to action icons
1101 my $dup = $ipdup ?
"<td class='base'>$Lang::tr{'duplicate ip bold'}</td>" :'';
1105 <td class='boldbase'> <b>$Lang::tr{'legend'}: </b></td>
1106 <td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
1107 <td class='base'>$Lang::tr{'click to disable'}</td>
1108 <td> </td>
1109 <td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
1110 <td class='base'>$Lang::tr{'click to enable'}</td>
1111 <td> </td>
1112 <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
1113 <td class='base'>$Lang::tr{'edit'}</td>
1114 <td> </td>
1115 <td><img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
1116 <td class='base'>$Lang::tr{'remove'}</td>
1120 <td bgcolor='orange'> </td>
1121 <td class='base'>$Lang::tr{'ip address outside subnets'}</td>
1131 &Header
::closebox
();
1133 foreach my $itf (@ITFs) {
1134 if ($dhcpsettings{"ENABLE_${itf}"} eq 'on') {
1135 # display leases with a list of actions to do with the global select checkbox.
1136 &Header
::PrintActualLeases
("+"); # "+" => create fixed leases from nodeaddress
1137 last; #Print one time only for all interfaces
1141 &Header
::closebigbox
();
1142 &Header
::closepage
();
1144 ## Ouf it's the end !
1146 sub sortcurrent1
# by now, do not sort, just write
1148 open(FILE
, ">$filename1") or die 'Unable to open dhcp advanced options file.';
1149 print FILE
@current1;
1154 # Sort the "current2" array according to choices
1159 sub fixedleasesort
{
1161 if (rindex ($dhcpsettings{'SORT_FLEASELIST'},'Rev') != -1) {
1162 $qs=substr ($dhcpsettings{'SORT_FLEASELIST'},0,length($dhcpsettings{'SORT_FLEASELIST'})-3);
1163 if ($qs eq 'FIPADDR') {
1164 my @a = split(/\./,$entries{$a}->{$qs});
1165 my @b = split(/\./,$entries{$b}->{$qs});
1171 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1173 } else { #not reverse
1174 $qs=$dhcpsettings{'SORT_FLEASELIST'};
1175 if ($qs eq 'FIPADDR') {
1176 my @a = split(/\./,$entries{$a}->{$qs});
1177 my @b = split(/\./,$entries{$b}->{$qs});
1183 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1188 #Use an associative array (%entries)
1189 foreach my $line (@current2) {
1190 chomp( $line); #remove newline because can be on field 5 or 6 (addition of REMARK)
1191 my @temp = split (',',$line);
1192 my @record = ('FETHER',$temp[0],'FIPADDR',$temp[1],'DATA',join(',',@temp[2..6]));
1193 my $record = {}; # create a reference to empty hash
1194 %{$record} = @record; # populate that hash with @record
1195 # use combination of ether & IP as key to allow duplicates in either but not both
1196 $entries{$record->{FETHER
} . $record->{FIPADDR
}} = $record; # add this to a hash of hashes
1199 open(FILE
, ">$filename2") or die 'Unable to open fixed lease file.';
1200 foreach my $entry ( sort fixedleasesort
keys %entries) {
1201 print FILE
"$entries{$entry}->{FETHER},$entries{$entry}->{FIPADDR},$entries{$entry}->{DATA}\n";
1205 # Reload sorted @current2
1206 open (FILE
, "$filename2");
1209 undef (%entries); #This array is reused latter. Clear it.
1212 # Build the configuration file mixing settings, fixed leases and advanced options
1214 open(FILE
, ">/${General::swroot}/dhcp/dhcpd.conf") or die "Unable to write dhcpd.conf file";
1218 print FILE
"deny bootp; #default\n";
1219 print FILE
"authoritative;\n";
1221 # DNS Update settings
1222 if ($dhcpsettings{'DNS_UPDATE_ENABLED'} eq 'on') {
1223 print FILE
"ddns-updates on;\n";
1224 print FILE
"ddns-update-style interim;\n";
1225 print FILE
"ddns-ttl 60; # 1 min\n";
1226 print FILE
"ignore client-updates;\n";
1227 print FILE
"update-static-leases on;\n";
1229 print FILE
"ddns-update-style none;\n";
1232 # Write first new option definition
1233 foreach my $line (@current1) {
1234 chomp($line); # remove newline
1235 my @temp = split(/\t/,$line);
1236 if (ExistNewOptionDefinition
($temp[1] . ' ' . $temp[2])) {
1237 print FILE
"option $temp[1] $temp[2];\n";
1240 # Write other global options
1241 foreach my $line (@current1) {
1242 chomp($line); # remove newline
1243 my @temp = split(/\t/,$line);
1245 if ($temp[0] eq 'on' && !ExistNewOptionDefinition
($temp[1] . ' ' . $temp[2])){ # active & !definition
1247 for (my $key=0; $key<@ITFs; $key++) {
1248 my $itf = $temp[3+$key];
1249 if ($itf ne 'off') # Only if an interface name is read
1255 print FILE
"option $temp[1] $temp[2];\n";
1261 #Subnet range definition
1262 foreach my $itf (@ITFs) {
1263 my $lc_itf=lc($itf);
1264 if ($dhcpsettings{"ENABLE_${itf}"} eq 'on' ){
1265 print FILE
"subnet " . $netsettings{"${itf}_NETADDRESS"} . " netmask ". $netsettings{"${itf}_NETMASK"} . " #$itf\n";
1267 print FILE
"\trange " . $dhcpsettings{"START_ADDR_${itf}"} . ' ' . $dhcpsettings{"END_ADDR_${itf}"}.";\n" if ($dhcpsettings{"START_ADDR_${itf}"});
1268 print FILE
"\toption subnet-mask " . $netsettings{"${itf}_NETMASK"} . ";\n";
1269 print FILE
"\toption domain-name \"" . $dhcpsettings{"DOMAIN_NAME_${itf}"} . "\";\n";
1270 print FILE
"\toption routers " . $netsettings{"${itf}_ADDRESS"} . ";\n";
1271 print FILE
"\toption domain-name-servers " . $dhcpsettings{"DNS1_${itf}"} if ($dhcpsettings{"DNS1_${itf}"});
1272 print FILE
", " . $dhcpsettings{"DNS2_${itf}"} if ($dhcpsettings{"DNS2_${itf}"});
1273 print FILE
";\n" if ($dhcpsettings{"DNS1_${itf}"});
1274 print FILE
"\toption ntp-servers " . $dhcpsettings{"NTP1_${itf}"} if ($dhcpsettings{"NTP1_${itf}"});
1275 print FILE
", " . $dhcpsettings{"NTP2_${itf}"} if ($dhcpsettings{"NTP2_${itf}"});
1276 print FILE
";\n" if ($dhcpsettings{"NTP1_${itf}"});
1277 print FILE
"\toption netbios-name-servers " . $dhcpsettings{"WINS1_${itf}"} if ($dhcpsettings{"WINS1_${itf}"});
1278 print FILE
", " . $dhcpsettings{"WINS2_${itf}"} if ($dhcpsettings{"WINS2_${itf}"});
1279 print FILE
";\n" if ($dhcpsettings{"WINS1_${itf}"});
1280 print FILE
"\tnext-server " . $dhcpsettings{"NEXT_${itf}"} . ";\n" if ($dhcpsettings{"NEXT_${itf}"});
1281 print FILE
"\tfilename \"" . &EscapeFilename
($dhcpsettings{"FILE_${itf}"}) . "\";\n" if ($dhcpsettings{"FILE_${itf}"});
1282 print FILE
"\tdefault-lease-time " . ($dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"} * 60). ";\n";
1283 print FILE
"\tmax-lease-time " . ($dhcpsettings{"MAX_LEASE_TIME_${itf}"} * 60) . ";\n";
1284 print FILE
"\tallow bootp;\n" if ($dhcpsettings{"ENABLEBOOTP_${itf}"} eq 'on');
1288 # Write scoped options
1289 foreach my $line (@current1) {
1290 chomp($line); # remove newline
1291 my @temp = split(/\t/,$line); # Use TAB separator !
1293 if ($temp[0] eq 'on'){
1294 for (my $key=0; $key<@ITFs; $key++) {
1295 if ($itf eq $temp[3+$key]) # Only is an interface name is read
1297 print FILE
"\toption $temp[1] $temp[2];\n";
1302 print FILE
"} #$itf\n\n";
1304 if (($dhcpsettings{"DNS_UPDATE_ENABLED"} eq "on") && ($dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"} ne "")) {
1305 print FILE
"key " . $dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"} . " {\n";
1306 print FILE
"\talgorithm " . $dhcpsettings{"DNS_UPDATE_KEY_ALGO_${itf}"} . ";\n";
1307 print FILE
"\tsecret \"" . $dhcpsettings{"DNS_UPDATE_KEY_SECRET_${itf}"} . "\";\n";
1308 print FILE
"};\n\n";
1310 print FILE
"zone " . $dhcpsettings{"DOMAIN_NAME_${itf}"} . ". {\n";
1311 print FILE
"\tkey " . $dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"} . ";\n";
1315 system ('/usr/bin/touch', "${General::swroot}/dhcp/enable_${lc_itf}");
1316 &General
::log("DHCP on ${itf}: " . $Lang::tr
{'dhcp server enabled'})
1318 unlink "${General::swroot}/dhcp/enable_${lc_itf}";
1319 &General
::log("DHCP on ${itf}: " . $Lang::tr
{'dhcp server disabled'})
1323 #write fixed leases if any. Does not handle duplicates to write them elsewhere than the global scope.
1325 foreach my $line (@current2) {
1327 my @temp = split(/\,/,$line);
1328 if ($temp[2] eq "on") {
1329 print FILE
"\nhost fix$key # $temp[6]\n";
1331 print FILE
"\thardware ethernet $temp[0];\n";
1332 print FILE
"\tfixed-address $temp[1];\n";
1333 print FILE
"\tnext-server $temp[3];\n" if ($temp[3]);
1334 print FILE
"\tfilename \"" . &EscapeFilename
($temp[4]) . "\";\n" if ($temp[4]);
1335 print FILE
"\toption root-path \"$temp[5]\";\n" if ($temp[5]);
1340 print FILE
"include \"${General::swroot}/dhcp/dhcpd.conf.local\";\n";
1342 if ( $dhcpsettings{"ENABLE_GREEN"} eq 'on' || $dhcpsettings{"ENABLE_BLUE"} eq 'on' ) {system '/usr/local/bin/dhcpctrl enable >/dev/null 2>&1';}
1343 else {system '/usr/local/bin/dhcpctrl disable >/dev/null 2>&1';}
1344 system '/usr/local/bin/dhcpctrl restart >/dev/null 2>&1 &';
1348 # Receive a string and if it match model for a new option,
1349 # add it to the list %newOptions
1351 my %NewOptions = ();
1353 sub AddNewOptionDefinition
{
1355 if ( $line =~ /^([-\w]+)( code \d+=($OptionTypes))/ ) {
1356 $NewOptions{$1} = $2;
1357 #&General::log ("new:<$1><$2>");
1364 # Check existence of definition for a new option
1366 sub ExistNewOptionDefinition
{
1369 if ( $line =~ /^([-\w]+)( code \d+=($OptionTypes))/ ) {
1370 return defined $NewOptions{$1};
1376 # Check if it is a new option (definition must exist)
1377 # "code=" test eliminate a false response when definition exists
1378 # but this string is a definition with bad $OptionTypes.
1379 sub ValidNewOption
{
1381 if ($line =~ /^([-\w]+) (.*)/ ) {
1382 return defined ( $NewOptions{$1} ) && $2 !~ /code=/;
1388 # Check if the new option $opt is used, except the definition of itself!
1390 sub IsUsedNewOptionDefinition
{
1391 my ($opt,$val) = @_;
1393 foreach my $line (@current1) {
1394 #chomp($line); # remove newline #don't know why, but this remove newline in @current1 .... !
1395 my @temp = split(/\t/,$line);
1396 # if we find something "opt value" & value != "code nnn=" it's ok.
1397 return 1 if ( ($opt eq $temp[1]) && ($temp[2] !~ /code \d+=/) );
1402 sub EscapeFilename
($) {
1403 my $filename = shift;
1405 # Replace all single / by \/
1406 $filename =~ s/\//\\\
//g;