]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/dhcp.cgi
suricata: Change midstream policy to "pass-flow"
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / dhcp.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6 # #
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. #
11 # #
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. #
16 # #
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/>. #
19 # #
20 ###############################################################################
21
22 use strict;
23 use experimental 'smartmatch';
24
25 # enable only the following on debugging purpose
26 #use warnings;
27 #use CGI::Carp 'fatalsToBrowser';
28
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} );
34 undef (@dummy);
35
36 our %dhcpsettings=();
37 our %netsettings=();
38 my %mainsettings=();
39 my %timesettings=();
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 = '';
47 my @nosaved=();
48 my %color = ();
49
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';
52
53 &Header::showhttpheaders();
54 our @ITFs=('GREEN');
55 if (&Header::blue_used()){push(@ITFs,'BLUE');}
56
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}"} = '';
77 $dhcpsettings{"DENY_KNOWN_CLIENTS_${itf}"} = 'off';
78 }
79
80 $dhcpsettings{'SORT_FLEASELIST'} = 'FIPADDR';
81 $dhcpsettings{'SORT_LEASELIST'} = 'IPADDR';
82
83 # DNS Update settings
84 $dhcpsettings{'DNS_UPDATE_ENABLED'} = 'off';
85
86 #Settings2 for editing the multi-line list
87 #Must not be saved with writehash !
88 $dhcpsettings{'FIX_MAC'} = '';
89 $dhcpsettings{'FIX_ADDR'} = '';
90 $dhcpsettings{'FIX_ENABLED'} = 'off';
91 $dhcpsettings{'FIX_NEXTADDR'} = '';
92 $dhcpsettings{'FIX_FILENAME'} = '';
93 $dhcpsettings{'FIX_ROOTPATH'} = '';
94 $dhcpsettings{'FIX_REMARK'} = '';
95 $dhcpsettings{'ACTION'} = '';
96 $dhcpsettings{'KEY1'} = '';
97 $dhcpsettings{'KEY2'} = '';
98 @nosaved=('FIX_MAC','FIX_ADDR','FIX_ENABLED','FIX_NEXTADDR',
99 'FIX_FILENAME','FIX_ROOTPATH','FIX_REMARK');
100
101 $dhcpsettings{'ADVOPT_ENABLED'} = '';
102 $dhcpsettings{'ADVOPT_NAME'} = '';
103 $dhcpsettings{'ADVOPT_DATA'} = '';
104 unshift (@nosaved,'ADVOPT_ENABLED','ADVOPT_NAME','ADVOPT_DATA');
105 foreach my $itf (@ITFs) {
106 $dhcpsettings{"ADVOPT_SCOPE_${itf}"} = 'off';
107 unshift (@nosaved, "ADVOPT_SCOPE_${itf}");
108 }
109
110 # Read Ipcop settings
111 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
112 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
113 &General::readhash("${General::swroot}/time/settings", \%timesettings);
114 &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color);
115
116 #Get GUI values
117 &Header::getcgihash(\%dhcpsettings);
118
119 open(FILE, "$filename1") or die 'Unable to open dhcp advanced options file.';
120 our @current1 = <FILE>;
121 close(FILE);
122 # Extract OptionDefinition
123 foreach my $line (@current1) {
124 #chomp($line); # remove newline #don't know why, but this remove newline in @current1 .... !
125 my @temp = split(/\t/,$line);
126 AddNewOptionDefinition ($temp[1] . ' ' . $temp[2]);
127 }
128
129 open(FILE, "$filename2") or die 'Unable to open fixed leases file.';
130 our @current2 = <FILE>;
131 close(FILE);
132
133 # Open and read-in file which contains the list of allowed advanced options.
134 open(FILE, $filename3) or die "Could not open $filename3. $!\n";
135
136 # Grab file content.
137 my @advoptions_list = <FILE>;
138
139 # Close file handle.
140 close(FILE);
141
142 # Check Settings1 first because they are needed by &buildconf
143 if ($dhcpsettings{'ACTION'} eq $Lang::tr{'save'}) {
144 foreach my $itf (@ITFs) {
145 if ($dhcpsettings{"ENABLE_${itf}"} eq 'on' ) {
146 # "Start" is defined, need "End" and vice versa
147 if ($dhcpsettings{"START_ADDR_${itf}"}) {
148 if (!(&General::validip($dhcpsettings{"START_ADDR_${itf}"}))) {
149 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid start address'};
150 goto ERROR;
151 }
152 if (!$dhcpsettings{"END_ADDR_${itf}"}) {
153 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid end address'};
154 goto ERROR;
155 }
156 if (! &General::IpInSubnet ( $dhcpsettings{"START_ADDR_${itf}"},
157 $netsettings{"${itf}_NETADDRESS"},
158 $netsettings{"${itf}_NETMASK"})) {
159 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid start address'};
160 goto ERROR;
161 }
162 }
163
164 if ($dhcpsettings{"END_ADDR_${itf}"}) {
165 if (!(&General::validip($dhcpsettings{"END_ADDR_${itf}"}))) {
166 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid end address'};
167 goto ERROR;
168 }
169 if (!$dhcpsettings{"START_ADDR_${itf}"}) {
170 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid start address'};
171 goto ERROR;
172 }
173 if (! &General::IpInSubnet ( $dhcpsettings{"END_ADDR_${itf}"},
174 $netsettings{"${itf}_NETADDRESS"},
175 $netsettings{"${itf}_NETMASK"})) {
176 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid end address'};
177 goto ERROR;
178 }
179 #swap if necessary! (support 255.255.0.0 range, I doubt we need more) GE
180 my @startoct = split (/\./, $dhcpsettings{"START_ADDR_${itf}"});
181 my @endoct = split (/\./, $dhcpsettings{"END_ADDR_${itf}"});
182 if ( $endoct[2]*256+$endoct[3] < $startoct[2]*256+$startoct[3] ) {
183 ($dhcpsettings{"START_ADDR_${itf}"},$dhcpsettings{"END_ADDR_${itf}"}) =
184 ($dhcpsettings{"END_ADDR_${itf}"},$dhcpsettings{"START_ADDR_${itf}"});
185 }
186 }
187
188 if ($dhcpsettings{"DENY_KNOWN_CLIENTS_${itf}"} eq 'on') {
189 if (($dhcpsettings{"START_ADDR_${itf}"}) eq '' && ($dhcpsettings{"END_ADDR_${itf}"}) eq '') {
190 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'dhcp valid range required when deny known clients checked'};
191 goto ERROR;
192 }
193 }
194
195 if (!($dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"} =~ /^\d+$/)) {
196 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid default lease time'} . $dhcpsettings{'DEFAULT_LEASE_TIME_${itf}'};
197 goto ERROR;
198 }
199
200 if (!($dhcpsettings{"MAX_LEASE_TIME_${itf}"} =~ /^\d+$/)) {
201 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid max lease time'} . $dhcpsettings{'MAX_LEASE_TIME_${itf}'};
202 goto ERROR;
203 }
204
205 if ($dhcpsettings{"DNS1_${itf}"}) {
206 if (!(&General::validip($dhcpsettings{"DNS1_${itf}"}))) {
207 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid primary dns'};
208 goto ERROR;
209 }
210 }
211 if ($dhcpsettings{"DNS2_${itf}"}) {
212 if (!(&General::validip($dhcpsettings{"DNS2_${itf}"}))) {
213 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid secondary dns'};
214 goto ERROR;
215 }
216 if (! $dhcpsettings{"DNS1_${itf}"}) {
217 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'cannot specify secondary dns without specifying primary'};
218 goto ERROR;
219 }
220 }
221
222 if ($dhcpsettings{"WINS1_${itf}"}) {
223 if (!(&General::validip($dhcpsettings{"WINS1_${itf}"}))) {
224 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid wins address'};
225 goto ERROR;
226 }
227 }
228 if ($dhcpsettings{"WINS2_${itf}"}) {
229 if (!(&General::validip($dhcpsettings{"WINS2_${itf}"}))) {
230 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid wins address'};
231 goto ERROR;
232 }
233 if (! $dhcpsettings{"WINS1_${itf}"} ) {
234 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'cannot specify secondary wins without specifying primary'};
235 goto ERROR;
236 }
237 }
238 if ($dhcpsettings{"NEXT_${itf}"}) {
239 if (!(&General::validip($dhcpsettings{"NEXT_${itf}"}))) {
240 $errormessage = "next-server on ${itf}: " . $Lang::tr{'invalid ip'};
241 goto ERROR;
242 }
243 }
244 if ($dhcpsettings{"NTP1_${itf}"}) {
245 if (!(&General::validip($dhcpsettings{"NTP1_${itf}"}))) {
246 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid primary ntp'};
247 goto ERROR;
248 }
249 if ($dhcpsettings{"NTP1_${itf}"} eq $netsettings{"${itf}_ADDRESS"} && ($timesettings{'ENABLECLNTP'} ne 'on')) {
250 $warnNTPmessage = "DHCP on ${itf}: " . $Lang::tr{'local ntp server specified but not enabled'};
251 #goto ERROR;
252 }
253 }
254 if ($dhcpsettings{"NTP2_${itf}"}) {
255 if (!(&General::validip($dhcpsettings{"NTP2_${itf}"}))) {
256 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid secondary ntp'};
257 goto ERROR;
258 }
259 if ($dhcpsettings{"NTP2_${itf}"} eq $netsettings{"${itf}_ADDRESS"} && ($timesettings{'ENABLECLNTP'} ne 'on')) {
260 $warnNTPmessage = "DHCP on ${itf}: " . $Lang::tr{'local ntp server specified but not enabled'};
261 #goto ERROR;
262 }
263 if (! $dhcpsettings{"NTP1_${itf}"}) {
264 $errormessage = "DHCP on ${itf}: " . $Lang::tr{'cannot specify secondary ntp without specifying primary'};
265 goto ERROR;
266 }
267 }
268 } # enabled
269 }#loop interface verify
270
271 map (delete ($dhcpsettings{$_}) ,@nosaved,'ACTION','KEY1','KEY2','q'); # Must not be saved
272 &General::writehash($setting, \%dhcpsettings); # Save good settings
273 $dhcpsettings{'ACTION'} = $Lang::tr{'save'}; # create an 'ACTION'
274 map ($dhcpsettings{$_} = '',@nosaved,'KEY1','KEY2'); # and reinit vars to empty
275 &buildconf;
276 ERROR: # Leave the faulty field untouched
277 } else {
278 &General::readhash($setting, \%dhcpsettings); # Get saved settings and reset to good if needed
279 }
280
281 ## Sorting of fixed leases
282 if ($ENV{'QUERY_STRING'} =~ /^FETHER|^FIPADDR/ ) {
283 my $newsort=$ENV{'QUERY_STRING'};
284 my $act=$dhcpsettings{'SORT_FLEASELIST'};
285 #Reverse actual sort ?
286 if ($act =~ $newsort) {
287 my $Rev='';
288 if ($act !~ 'Rev') {
289 $Rev='Rev';
290 }
291 $newsort.=$Rev;
292 }
293 $dhcpsettings{'SORT_FLEASELIST'}=$newsort;
294 map (delete ($dhcpsettings{$_}) ,@nosaved,'ACTION','KEY1','KEY2', 'q'); # Must never be saved
295 &General::writehash($setting, \%dhcpsettings);
296 &sortcurrent2;
297 $dhcpsettings{'ACTION'} = 'SORT'; # create an 'ACTION'
298 map ($dhcpsettings{$_} = '',@nosaved,'KEY1','KEY2');# and reinit vars to empty
299 }
300
301 #Sorting of allocated leases
302 &Header::CheckSortOrder;
303
304
305 ## Now manipulate the two multi-line list with Settings2.
306 # '1' suffix is for ADVANCED OPTIONS
307 # '2' suffix is for FIXED LEASES
308
309 # Toggle enable/disable field on specified options.
310
311 if ($dhcpsettings{'ACTION'} eq $Lang::tr{'toggle enable disable'}.'1') {
312 #move out new line
313 chomp(@current1[$dhcpsettings{'KEY1'}]);
314 my @temp = split(/\t/,@current1[$dhcpsettings{'KEY1'}]); #use TAB separator !
315 $temp[0] = $temp[0] eq 'on' ? '' : 'on'; # Toggle the field
316 @current1[$dhcpsettings{'KEY1'}] = join ("\t",@temp)."\n";
317 $dhcpsettings{'KEY1'} = ''; # End edit mode
318 &General::log($Lang::tr{'dhcp advopt modified'});
319 open(FILE, ">$filename1") or die 'Unable to open dhcp advanced options file.';
320 print FILE @current1;
321 close(FILE);
322
323 #Write changes to dhcpd.conf.
324 &buildconf;
325 }
326
327
328
329 if ($dhcpsettings{'ACTION'} eq $Lang::tr{'add'}.'1' &&
330 $dhcpsettings{'SUBMIT'} ne $Lang::tr{'dhcp advopt help'}) {
331 $dhcpsettings{'ADVOPT_NAME'} =~ s/[^ \w-]//g; # prevent execution of code by removing everything except letters/space
332 $dhcpsettings{'ADVOPT_DATA'} =~ s/`//g; # back tik ` ? not allowed !
333
334 if ($dhcpsettings{'ADVOPT_DATA'} eq '') {
335 $errormessage=$Lang::tr{'dhcp advopt blank value'};
336 }
337
338 # Test for a new option definition string (join field name & data)
339 if (ExistNewOptionDefinition ($dhcpsettings{'ADVOPT_NAME'} . ' ' . $dhcpsettings{'ADVOPT_DATA'})) {
340 #only edit permitted if option definition exists
341 $errormessage = $Lang::tr{'dhcp advopt definition exists'} if ($dhcpsettings{'KEY1'} eq '');
342 $dhcpsettings{'ADVOPT_ENABLED'} = 'on'; # force active
343 map ($dhcpsettings{"ADVOPT_SCOPE_$_"} = 'off', @ITFs); # force global
344 } elsif (AddNewOptionDefinition ($dhcpsettings{'ADVOPT_NAME'} . ' ' . $dhcpsettings{'ADVOPT_DATA'})) {
345 #was a new option definition
346 $dhcpsettings{'ADVOPT_ENABLED'} = 'on'; # force active
347 map ($dhcpsettings{"ADVOPT_SCOPE_$_"} = 'off', @ITFs); # force global
348 } elsif (ValidNewOption ($dhcpsettings{'ADVOPT_NAME'} . ' ' . $dhcpsettings{'ADVOPT_DATA'})) {
349 #was a new option
350 } elsif (! grep(/option $dhcpsettings{'ADVOPT_NAME'}/, @advoptions_list)) {
351 $errormessage=$Lang::tr{'dhcp advopt unknown'}.': '.$dhcpsettings{'ADVOPT_NAME'};
352 }
353
354 unless ($errormessage) {
355
356 my $scope = '';
357 foreach my $itf (@ITFs) { # buils "RED,GREEN,ORANGE,... based on selection
358 $scope .= $dhcpsettings{"ADVOPT_SCOPE_${itf}"} eq 'on' ? "\t$itf" : "\toff" ;
359 }
360 if ($dhcpsettings{'KEY1'} eq '') { #add or edit ? TAB separator !
361 unshift (@current1, "$dhcpsettings{'ADVOPT_ENABLED'}\t$dhcpsettings{'ADVOPT_NAME'}\t$dhcpsettings{'ADVOPT_DATA'}$scope\n");
362 &General::log($Lang::tr{'dhcp advopt added'});
363 } else {
364 @current1[$dhcpsettings{'KEY1'}] = "$dhcpsettings{'ADVOPT_ENABLED'}\t$dhcpsettings{'ADVOPT_NAME'}\t$dhcpsettings{'ADVOPT_DATA'}$scope\n";
365 $dhcpsettings{'KEY1'} = ''; # End edit mode
366 &General::log($Lang::tr{'dhcp advopt modified'});
367 }
368
369 #Write changes to dhcpd.conf.
370 &sortcurrent1; # sort newly added/modified entry
371 &buildconf; # before calling buildconf which use fixed lease file !
372 }
373 }
374
375 if ($dhcpsettings{'ACTION'} eq $Lang::tr{'edit'}.'1') {
376 #move out new line
377 my $line = @current1[$dhcpsettings{'KEY1'}];
378 chomp($line);
379 my @temp = split(/\t/, $line);
380 $dhcpsettings{'ADVOPT_ENABLED'}=$temp[0];
381 $dhcpsettings{'ADVOPT_NAME'}=$temp[1];
382 $dhcpsettings{'ADVOPT_DATA'}=$temp[2];
383
384 # read next fields which are the name (color) of an interface if this interface is scoped
385 for (my $key=0; $key<@ITFs; $key++) {
386 my $itf = $temp[3+$key];
387 if ($itf ne 'off') # Only is an interface name is read
388 {
389 $dhcpsettings{"ADVOPT_SCOPE_${itf}"} = 'on';
390 }
391 }
392 }
393
394 if ($dhcpsettings{'ACTION'} eq $Lang::tr{'remove'}.'1') {
395 splice (@current1,$dhcpsettings{'KEY1'},1);
396 open(FILE, ">$filename1") or die 'Unable to open dhcp advanced options file.';
397 print FILE @current1;
398 close(FILE);
399 $dhcpsettings{'KEY1'} = ''; # End remove mode
400 &General::log($Lang::tr{'dhcp advopt removed'});
401 #Write changes to dhcpd.conf.
402 &buildconf;
403 }
404 #end KEY1
405
406
407 # Toggle enable/disable field on specified lease.
408 if ($dhcpsettings{'ACTION'} eq $Lang::tr{'toggle enable disable'}.'2') {
409 #move out new line
410 chomp(@current2[$dhcpsettings{'KEY2'}]);
411 my @temp = split(/\,/,@current2[$dhcpsettings{'KEY2'}]);
412 $temp[2] = $temp[2] eq 'on' ? '' : 'on'; # Toggle the field
413 @current2[$dhcpsettings{'KEY2'}] = join (',',@temp)."\n";
414 $dhcpsettings{'KEY2'} = ''; # End edit mode
415 &General::log($Lang::tr{'fixed ip lease modified'});
416 open(FILE, ">$filename2") or die 'Unable to open fixed leases file.';
417 print FILE @current2;
418 close(FILE);
419
420 #Write changes to dhcpd.conf.
421 &buildconf;
422 }
423
424 if ($dhcpsettings{'ACTION'} eq $Lang::tr{'add'}.'2') {
425 $dhcpsettings{'FIX_MAC'} =~ tr/-/:/;
426 unless(&General::validip($dhcpsettings{'FIX_ADDR'})) { $errormessage = $Lang::tr{'invalid fixed ip address'}; }
427 unless(&General::validmac($dhcpsettings{'FIX_MAC'})) { $errormessage = $Lang::tr{'invalid fixed mac address'}; }
428 if ($dhcpsettings{'FIX_NEXTADDR'}) {
429 unless(&General::validip($dhcpsettings{'FIX_NEXTADDR'})) { $errormessage = $Lang::tr{'invalid fixed ip address'}; }
430 }
431
432 my $key = 0;
433 CHECK:foreach my $line (@current2) {
434 my @temp = split(/\,/,$line);
435 if($dhcpsettings{'KEY2'} ne $key) {
436 # same MAC is OK on different subnets. This test is not complete because
437 # if ip are not inside a known subnet, I don't warn.
438 # Also it may be needed to put duplicate fixed lease in their right subnet definition..
439 foreach my $itf (@ITFs) {
440 my $scoped = &General::IpInSubnet($dhcpsettings{'FIX_ADDR'},
441 $netsettings{"${itf}_NETADDRESS"},
442 $netsettings{"${itf}_NETMASK"}) &&
443 $dhcpsettings{"ENABLE_${itf}"} eq 'on';
444 if ( $scoped &&
445 (lc($dhcpsettings{'FIX_MAC'}) eq lc($temp[0])) &&
446 &General::IpInSubnet($temp[1],
447 $netsettings{"${itf}_NETADDRESS"},
448 $netsettings{"${itf}_NETMASK"})) {
449 $errormessage = "$Lang::tr{'mac address in use'} $dhcpsettings{'FIX_MAC'}";
450 last CHECK;
451 }
452 }
453 }
454 $key++;
455 }
456
457 unless ($errormessage) {
458 $dhcpsettings{'FIX_REMARK'} = &Header::cleanhtml($dhcpsettings{'FIX_REMARK'});
459 $dhcpsettings{'FIX_NEXTADDR'} = &Header::cleanhtml($dhcpsettings{'FIX_NEXTADDR'});
460 $dhcpsettings{'FIX_FILENAME'} = &Header::cleanhtml($dhcpsettings{'FIX_FILENAME'});
461 $dhcpsettings{'FIX_ROOTPATH'} = &Header::cleanhtml($dhcpsettings{'FIX_ROOTPATH'});
462 if ($dhcpsettings{'KEY2'} eq '') { #add or edit ?
463 unshift (@current2, "$dhcpsettings{'FIX_MAC'},$dhcpsettings{'FIX_ADDR'},$dhcpsettings{'FIX_ENABLED'},$dhcpsettings{'FIX_NEXTADDR'},$dhcpsettings{'FIX_FILENAME'},$dhcpsettings{'FIX_ROOTPATH'},$dhcpsettings{'FIX_REMARK'}\n");
464 open(FILE, ">$filename2") or die 'Unable to open fixed lease file.';
465 print FILE @current2;
466 close(FILE);
467 &General::log($Lang::tr{'fixed ip lease added'});
468
469 # Enter edit mode
470 $dhcpsettings{'KEY2'} = 0;
471 } else {
472 @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";
473 $dhcpsettings{'KEY2'} = ''; # End edit mode
474 &General::log($Lang::tr{'fixed ip lease modified'});
475
476 # sort newly added/modified entry
477 &sortcurrent2;
478 }
479
480 #Write changes to dhcpd.conf.
481 &buildconf; # before calling buildconf which use fixed lease file !
482 }
483 }
484
485 if ($dhcpsettings{'ACTION_ALL'} eq '+') {
486 my $news = 0;
487 foreach (keys %dhcpsettings) {
488 if (/^(\d+\.\d+\.\d+\.\d+)-([0-9a-fA-F:]+)$/) { # checked names are index of the line
489 my $ip=$1;
490 my $mac=$2;
491 if (!grep (/$2/,@current2)) {
492 unshift (@current2, "$mac,$ip,on,,,,imported\n");
493 $news++;
494 }
495 }
496 }
497 if ($news) {
498 #Write changes to dhcpd.conf.
499 $warnNTPmessage = $Lang::tr{'fixed ip lease added'}."($news)";
500 &General::log($warnNTPmessage);
501 &sortcurrent2; # sort newly added/modified entry
502 &buildconf; # before calling buildconf which use fixed lease file !
503 }
504 }
505
506 if ($dhcpsettings{'ACTION'} eq $Lang::tr{'edit'}.'2') {
507 #move out new line
508 my $line = @current2[$dhcpsettings{'KEY2'}];
509 chomp($line);
510 my @temp = split(/\,/, $line);
511 $dhcpsettings{'FIX_MAC'}=$temp[0];
512 $dhcpsettings{'FIX_ADDR'}=$temp[1];
513 $dhcpsettings{'FIX_ENABLED'}=$temp[2];
514 $dhcpsettings{'FIX_NEXTADDR'}=$temp[3];
515 $dhcpsettings{'FIX_FILENAME'}=$temp[4];
516 $dhcpsettings{'FIX_ROOTPATH'}=$temp[5];
517 $dhcpsettings{'FIX_REMARK'}=$temp[6];
518 }
519
520 if ($dhcpsettings{'ACTION'} eq $Lang::tr{'remove'}.'2') {
521 splice (@current2,$dhcpsettings{'KEY2'},1);
522 open(FILE, ">$filename2") or die 'Unable to open fixed lease file.';
523 print FILE @current2;
524 close(FILE);
525 $dhcpsettings{'KEY2'} = ''; # End remove mode
526 &General::log($Lang::tr{'fixed ip lease removed'});
527 #Write changes to dhcpd.conf.
528 &buildconf;
529 }
530 #end KEY2 defined
531
532
533
534
535 if ($dhcpsettings{'ACTION'} eq '' ) { # First launch from GUI
536
537 # Set default DHCP values only if blank and disabled
538 foreach my $itf (@ITFs) {
539 if ($dhcpsettings{"ENABLE_${itf}"} ne 'on' ) {
540 $dhcpsettings{"DNS1_${itf}"} = $netsettings{"${itf}_ADDRESS"};
541 $dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"} = '60';
542 $dhcpsettings{"MAX_LEASE_TIME_${itf}"} = '120';
543 $dhcpsettings{"DOMAIN_NAME_${itf}"} = $mainsettings{'DOMAINNAME'};
544 }
545 }
546 $dhcpsettings{'FIX_ENABLED'} = 'on';
547 $dhcpsettings{'ADVOPT_ENABLED'} = 'on';
548 }
549
550 &Header::openpage($Lang::tr{'dhcp configuration'}, 1, '');
551 &Header::openbigbox('100%', 'left', '', $errormessage);
552
553 if ($errormessage) {
554 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
555 print "<font class='base'>$errormessage&nbsp;</font>\n";
556 &Header::closebox();
557 }
558 if ($warnNTPmessage) {
559 $warnNTPmessage = "<font color=${Header::colourred}><b>$Lang::tr{'capswarning'}</b></font>: $warnNTPmessage";
560 }
561
562 &Header::openbox('100%', 'left', 'DHCP');
563 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>";
564
565 foreach my $itf (@ITFs) {
566 my %checked=();
567 $checked{'ENABLE'}{'on'} = ( $dhcpsettings{"ENABLE_${itf}"} ne 'on') ? '' : "checked='checked'";
568 $checked{'ENABLEBOOTP'}{'on'} = ( $dhcpsettings{"ENABLEBOOTP_${itf}"} ne 'on') ? '' : "checked='checked'";
569 $checked{'DENY_KNOWN_CLIENTS'}{'on'} = ( $dhcpsettings{"DENY_KNOWN_CLIENTS_${itf}"} ne 'on') ? '' : "checked='checked'";
570
571 if ($netsettings{"${itf}_DEV"} ne '' ) { # Show only defined interface
572 my $lc_itf=lc($itf);
573 print <<END
574 <table width='100%'>
575 <tr>
576 <td width='25%' class='boldbase'><b><font color='${lc_itf}'>$Lang::tr{"$lc_itf interface"}</font></b></td>
577 <td class='base'>$Lang::tr{'enabled'}
578 <input type='checkbox' name='ENABLE_${itf}' $checked{'ENABLE'}{'on'} /></td>
579 <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>
580 </tr><tr>
581 <td width='25%' class='base'>$Lang::tr{'start address'}&nbsp;<img src='/blob.gif' alt='*' /></td>
582 <td width='25%'><input type='text' name='START_ADDR_${itf}' value='$dhcpsettings{"START_ADDR_${itf}"}' /></td>
583 <td width='25%' class='base'>$Lang::tr{'end address'}&nbsp;<img src='/blob.gif' alt='*' /></td>
584 <td width='25%'><input type='text' name='END_ADDR_${itf}' value='$dhcpsettings{"END_ADDR_${itf}"}' /></td>
585 </tr><tr>
586 <td class='base'>$Lang::tr{'dhcp deny known clients:'}</td>
587 <td><input type='checkbox' name='DENY_KNOWN_CLIENTS_${itf}' $checked{'DENY_KNOWN_CLIENTS'}{'on'} /></td>
588 </tr><tr>
589 <td class='base'>$Lang::tr{'default lease time'}&nbsp;<img src='/blob.gif' alt='*' /></td>
590 <td><input type='text' name='DEFAULT_LEASE_TIME_${itf}' value='$dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"}' /></td>
591 <td class='base'>$Lang::tr{'max lease time'}&nbsp;<img src='/blob.gif' alt='*' /></td>
592 <td><input type='text' name='MAX_LEASE_TIME_${itf}' value='$dhcpsettings{"MAX_LEASE_TIME_${itf}"}' /></td>
593 </tr><tr>
594 <td class='base'>$Lang::tr{'domain name suffix'}</td>
595 <td><input type='text' name='DOMAIN_NAME_${itf}' value='$dhcpsettings{"DOMAIN_NAME_${itf}"}' /></td>
596 <td>$Lang::tr{'dhcp allow bootp'}:</td>
597 <td><input type='checkbox' name='ENABLEBOOTP_${itf}' $checked{'ENABLEBOOTP'}{'on'} /></td>
598 </tr><tr>
599 <td class='base'>$Lang::tr{'primary dns'}&nbsp;<img src='/blob.gif' alt='*' /></td>
600 <td><input type='text' name='DNS1_${itf}' value='$dhcpsettings{"DNS1_${itf}"}' /></td>
601 <td class='base'>$Lang::tr{'secondary dns'}</td>
602 <td><input type='text' name='DNS2_${itf}' value='$dhcpsettings{"DNS2_${itf}"}' /></td>
603 </tr><tr>
604 <td class='base'>$Lang::tr{'primary ntp server'}:</td>
605 <td><input type='text' name='NTP1_${itf}' value='$dhcpsettings{"NTP1_${itf}"}' /></td>
606 <td class='base'>$Lang::tr{'secondary ntp server'}:</td>
607 <td><input type='text' name='NTP2_${itf}' value='$dhcpsettings{"NTP2_${itf}"}' /></td>
608 </tr><tr>
609 <td class='base'>$Lang::tr{'primary wins server address'}:</td>
610 <td><input type='text' name='WINS1_${itf}' value='$dhcpsettings{"WINS1_${itf}"}' /></td>
611 <td class='base'>$Lang::tr{'secondary wins server address'}:</td>
612 <td><input type='text' name='WINS2_${itf}' value='$dhcpsettings{"WINS2_${itf}"}' /></td>
613 </tr><tr>
614 <td class='base'>next-server:</td>
615 <td><input type='text' name='NEXT_${itf}' value='$dhcpsettings{"NEXT_${itf}"}' /></td>
616 <td class='base'>filename:</td>
617 <td><input type='text' name='FILE_${itf}' value='$dhcpsettings{"FILE_${itf}"}' /></td>
618 </tr>
619 </table>
620 <hr />
621 END
622 ;
623 }# Show only defined interface
624 }#foreach itf
625 print <<END
626 <table width='100%'>
627 <tr>
628 <td class='base' width='25%'><img src='/blob.gif' align='top' alt='*' />&nbsp;$Lang::tr{'required field'}</td>
629 <td class='base' width='30%'>$warnNTPmessage</td>
630 <td width='40%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
631 </tr>
632 </table>
633 END
634 ;
635 &Header::closebox();
636
637 # DHCP DNS update support (RFC2136)
638 &Header::openbox('100%', 'left', $Lang::tr{'dhcp dns update'});
639
640 my %checked = ();
641 $checked{'DNS_UPDATE_ENABLED'}{'on'} = ( $dhcpsettings{'DNS_UPDATE_ENABLED'} ne 'on') ? '' : "checked='checked'";
642
643 print <<END
644 <table width='100%'>
645 <tr>
646 <td width='30%' class='boldbase'>$Lang::tr{'dhcp dns enable update'}</td>
647 <td class='base'><input type='checkbox' name='DNS_UPDATE_ENABLED' $checked{'DNS_UPDATE_ENABLED'}{'on'}>
648 </td>
649 <tr>
650 </table>
651
652 <table width='100%'>
653 END
654 ;
655 my @domains = ();
656
657 # Print options for each interface.
658 foreach my $itf (@ITFs) {
659 # Check if DHCP for this interface is enabled.
660 if ($dhcpsettings{"ENABLE_${itf}"} eq 'on') {
661 # Check for same domain name.
662 next if ($dhcpsettings{"DOMAIN_NAME_${itf}"} ~~ @domains);
663 my $lc_itf = lc($itf);
664
665 # Select previously configured update algorithm.
666 my %selected = ();
667 $selected{'DNS_UPDATE_ALGO_${inf}'}{$dhcpsettings{'DNS_UPDATE_ALGO_${inf}'}} = 'selected';
668
669 print <<END
670 <tr>
671 <td colspan='6'>&nbsp;</td>
672 </tr>
673 <tr>
674 <td colspan='6' class='boldbase'><b>$dhcpsettings{"DOMAIN_NAME_${itf}"}</b></td>
675 </tr>
676 <tr>
677 <td width='10%' class='boldbase'>$Lang::tr{'dhcp dns key name'}:</td>
678 <td width='20%'><input type='text' name='DNS_UPDATE_KEY_NAME_${itf}' value='$dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"}'></td>
679 <td width='10%' class='boldbase' align='right'>$Lang::tr{'dhcp dns update secret'}:&nbsp;&nbsp;</td>
680 <td width='20%'><input type='password' name='DNS_UPDATE_KEY_SECRET_${itf}' value='$dhcpsettings{"DNS_UPDATE_KEY_SECRET_${itf}"}'></td>
681 <td width='10%' class='boldbase' align='right'>$Lang::tr{'dhcp dns update algo'}:&nbsp;&nbsp;</td>
682 <td width='20%'>
683 <select name='DNS_UPDATE_KEY_ALGO_${itf}'>
684 <!-- <option value='hmac-sha1' $selected{'DNS_UPDATE_KEY_ALGO_${itf}'}{'hmac-sha1'}>HMAC-SHA1</option> -->
685 <option value='hmac-md5' $selected{'DNS_UPDATE_KEY_ALGO_${itf}'}{'hmac-md5'}>HMAC-MD5</option>
686 </select>
687 </td>
688 </tr>
689 END
690 ;
691 }
692
693 # Store configured domain based on the interface
694 # in the temporary variable.
695 push(@domains, $dhcpsettings{"DOMAIN_NAME_${itf}"});
696 }
697 print <<END
698 </table>
699 <hr>
700 <table width='100%'>
701 <tr>
702 <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
703 </tr>
704 </table>
705 </form>
706 END
707 ;
708
709 &Header::closebox();
710
711 &Header::openbox('100%', 'left', $Lang::tr{'dhcp advopt list'});
712 # DHCP Advanced options settings
713 my %checked=();
714 $checked{'ADVOPT_ENABLED'}{'on'} = ($dhcpsettings{'ADVOPT_ENABLED'} ne 'on') ? '' : "checked='checked'";
715
716 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'>";
717 my $buttontext = $Lang::tr{'add'};
718 if ($dhcpsettings{'KEY1'} ne '') {
719 $buttontext = $Lang::tr{'update'};
720 print "<tr><td class='boldbase'><b>$Lang::tr{'dhcp advopt edit'}</b></td></tr>";
721 } else {
722 print "<tr><td class='boldbase'><b>$Lang::tr{'dhcp advopt add'}</b></td></tr>"
723 }
724
725 #search if the 'option' is in the list and print the syntax model
726 my $opt;
727
728 # Check if a advanced option name is set.
729 if ($dhcpsettings{'ADVOPT_NAME'}) {
730 # Check if the name is part of the list and grab syntax.
731 my @opt = grep(/option $dhcpsettings{'ADVOPT_NAME'}/, @advoptions_list);
732
733 # Assign array element to variable.
734 $opt = @opt[0];
735
736 # Remove newlines.
737 chomp($opt);
738 }
739
740 if ($opt ne '') {
741 $opt =~ s/option $dhcpsettings{'ADVOPT_NAME'}/Syntax:/; # "option xyz abc" => "syntax: abc"
742 $opt =~ s/;//;
743 $opt = "<tr><td></td><td></td><td colspan='2'>$opt</td></tr>";
744 }
745 print <<END
746 <tr>
747 <td class='base'>$Lang::tr{'dhcp advopt name'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
748 <td><input type='text' name='ADVOPT_NAME' value='$dhcpsettings{'ADVOPT_NAME'}' size='18' /></td>
749 <td class='base'>$Lang::tr{'dhcp advopt value'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
750 <td><input type='text' name='ADVOPT_DATA' value='$dhcpsettings{'ADVOPT_DATA'}' size='40' /></td>
751 </tr>$opt<tr>
752 <td class='base'>$Lang::tr{'enabled'}</td><td><input type='checkbox' name='ADVOPT_ENABLED' $checked{'ADVOPT_ENABLED'}{'on'} /></td>
753 <td class='base'>$Lang::tr{'dhcp advopt scope'}:</td>
754 <td>
755 END
756 ;
757
758 # Put a checkbox for each interface. Checkbox visible disabled if interface is disabled
759 foreach my $itf (@ITFs) {
760 my $lc_itf=lc($itf);
761 $checked{'ADVOPT_SCOPE_${itf}'}{'on'} = $dhcpsettings{"ADVOPT_SCOPE_${itf}"} ne 'on' ? '' : "checked='checked'";
762 print "$Lang::tr{\"${lc_itf}\"} <input type='checkbox' name='ADVOPT_SCOPE_${itf}' $checked{'ADVOPT_SCOPE_${itf}'}{'on'} ";
763 print $dhcpsettings{"ENABLE_${itf}"} eq 'on' ? "/>" : "disabled='disabled' />";
764 print "&nbsp; &nbsp;";
765 }
766
767 print <<END
768 </td>
769 </tr>
770 </table>
771 <hr />
772 <table width='100%'>
773 <tr>
774 <td class='base' width='50%'>$Lang::tr{'dhcp advopt scope help'}</td>
775 <td width='50%' align='right'>
776 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}1' />
777 <input type='submit' name='SUBMIT' value='$buttontext' />
778 <input type='submit' name='SUBMIT' value='$Lang::tr{'dhcp advopt help'}' />
779 <input type='hidden' name='KEY1' value='$dhcpsettings{'KEY1'}' />
780 </td>
781 </tr>
782 </table>
783 </form>
784 END
785 ;
786 #Edited line number (KEY1) passed until cleared by 'save' or 'remove' or 'new sort order'
787
788 # print help taken from the file describing options
789 if ($dhcpsettings{'SUBMIT'} eq $Lang::tr{'dhcp advopt help'}) {
790 print "<hr />";
791 print "<table width='100%'>";
792 print "<tr><td width='30%'><b>$Lang::tr{'dhcp advopt name'}</b></td><td width='70%'><b>$Lang::tr{'dhcp advopt value'}</b></td>";
793 open(FILE, "$filename3");
794 my @current3 = <FILE>;
795 close(FILE);
796 foreach my $line (@current3) {
797 $line =~ /option ([a-z0-9-]+) (.*);/;
798 print "<tr><td>$1</td><td>$2</td></tr>\n";
799 }
800 print "<tr><td colspan='2'><hr /></td></tr>\n";
801 print '<tr><td>string type</td><td>"quoted string" or 00:01:FF...</td></tr>';
802 print '<tr><td>ip-address type </td><td>10.0.0.1 | www.dot.com</td></tr>';
803 print '<tr><td>int,uint types</td><td>numbers</td></tr>';
804 print '<tr><td>flag type</td><td>on | off</td></tr>';
805 print '</table>';
806 print "<hr />";
807 print "<table width='100%'>";
808 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>";
809 print "<tr><td>any-name </td><td> code NNN=$OptionTypes</td></tr>";
810 print '<tr><td>a-string</td><td>code 100=string</td></tr>';
811 print '<tr><td>a-number</td><td>code 101=signed integer 8</td></tr>';
812 print '<tr><td>wpad</td><td>code 252=text</td></tr>';
813 print '<tr><td>wpad</td><td>"http://www.server.fr/path-to/proxy.pac"</td></tr>';
814 print '</table>';
815
816 }
817
818 print <<END
819 <hr />
820 <table width='100%'>
821 <tr>
822 <td width='30%' class='boldbase' align='center'><b>$Lang::tr{'dhcp advopt name'}</b></td>
823 <td width='50%' class='boldbase' align='center'><b>$Lang::tr{'dhcp advopt value'}</b></td>
824 <td width='20%' class='boldbase' align='center'><b>$Lang::tr{'dhcp advopt scope'}</b></td>
825 <td colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></td>
826 </tr>
827 END
828 ;
829 my $key = 0;
830 foreach my $line (@current1) {
831 my $gif = '';
832 my $gdesc = '';
833 chomp($line); # remove newline
834 my @temp = split(/\t/,$line);
835
836 if ($temp[0] eq "on") {
837 $gif = 'on.gif';
838 $gdesc = $Lang::tr{'click to disable'};
839 } else {
840 $gif = 'off.gif';
841 $gdesc = $Lang::tr{'click to enable'};
842 }
843
844 if ($dhcpsettings{'KEY1'} eq $key) {
845 print "<tr bgcolor='${Header::colouryellow}'>";
846 } elsif ($key % 2) {
847 print "<tr bgcolor='$color{'color22'}'>";
848 } else {
849 print "<tr bgcolor='$color{'color20'}'>";
850 }
851
852 print <<END
853 <td align='center'>$temp[1]</td>
854 <td align='center'>$temp[2]</td>
855 <td align='center'>
856 END
857 ;
858 # Prepare a global flag to make easy reading
859 my $global = '';
860 my $disabledTogle = '';
861 my $disabledEditRemove = '';
862 if ( ExistNewOptionDefinition ($temp[1] . ' ' . $temp[2]) ) {
863 $global = $Lang::tr{'dhcp advopt definition'};
864 $disabledTogle = "disabled='disabled'";
865 # Search if it is a used NewOptionDefinition to also disable edit & delete
866 $disabledEditRemove = "disabled='disabled'" if (IsUsedNewOptionDefinition ($temp[1], $temp[2]));
867 } else {
868 $global = $Lang::tr{'dhcp advopt scope global'};
869 }
870
871
872 # Print each checked interface
873 for (my $key=0; $key<@ITFs; $key++) {
874 my $itf = $temp[3+$key];
875 if ($itf ne 'off') { # Only if an interface name is read
876 print "$itf";
877 $global=''; # fall to local scope !
878 }
879 }
880 print <<END
881 $global</td>
882 <td align='center'>
883 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
884 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}1' />
885 <input $disabledTogle type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
886 <input type='hidden' name='KEY1' value='$key' />
887 </form>
888 </td>
889
890 <td align='center'>
891 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
892 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}1' />
893 <input $disabledEditRemove type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
894 <input type='hidden' name='KEY1' value='$key' />
895 </form>
896 </td>
897
898 <td align='center'>
899 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
900 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}1' />
901 <input $disabledEditRemove type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
902 <input type='hidden' name='KEY1' value='$key' />
903 </form>
904 </td>
905 </tr>
906 END
907 ;
908 $key++;
909 }
910
911 print "</table>";
912
913 # If there are dhcp options, print Key to action icons
914 if ($key) {
915 print <<END
916 <table>
917 <tr>
918 <td class='boldbase'>&nbsp;<b>$Lang::tr{'legend'}:&nbsp;</b></td>
919 <td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
920 <td class='base'>$Lang::tr{'click to disable'}</td>
921 <td>&nbsp;&nbsp;</td>
922 <td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
923 <td class='base'>$Lang::tr{'click to enable'}</td>
924 <td>&nbsp;&nbsp;</td>
925 <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
926 <td class='base'>$Lang::tr{'edit'}</td>
927 <td>&nbsp;&nbsp;</td>
928 <td><img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
929 <td class='base'>$Lang::tr{'remove'}</td>
930 </tr>
931 </table>
932 END
933 ;
934 }
935 &Header::closebox();
936
937 &Header::openbox('100%', 'left', $Lang::tr{'current fixed leases'});
938 # Fixed leases screens
939 $checked{'FIX_ENABLED'}{'on'} = ($dhcpsettings{'FIX_ENABLED'} ne 'on') ? '' : "checked='checked'";
940
941 $buttontext = $Lang::tr{'add'};
942 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'>";
943
944 if ($dhcpsettings{'KEY2'} ne '') {
945 $buttontext = $Lang::tr{'update'};
946 print "<tr><td class='boldbase' colspan='3'><b>$Lang::tr{'edit an existing lease'}</b></td></tr>";
947 } else {
948 print "<tr><td class='boldbase' colspan='3'><b>$Lang::tr{'add new lease'}</b></td></tr>"
949 }
950 print <<END
951 <tr>
952 <td class='base'>$Lang::tr{'mac address'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
953 <td><input type='text' name='FIX_MAC' value='$dhcpsettings{'FIX_MAC'}' size='18' /></td>
954 <td class='base'>$Lang::tr{'ip address'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
955 <td><input type='text' name='FIX_ADDR' value='$dhcpsettings{'FIX_ADDR'}' size='18' /></td>
956 <td class='base'>$Lang::tr{'remark'}:</td>
957 <td><input type='text' name='FIX_REMARK' value='$dhcpsettings{'FIX_REMARK'}' size='18' /></td>
958 </tr><tr>
959 <td class='base'>$Lang::tr{'enabled'}</td><td><input type='checkbox' name='FIX_ENABLED' $checked{'FIX_ENABLED'}{'on'} /></td>
960 </tr><tr>
961 <td colspan = '3'><b>$Lang::tr{'dhcp bootp pxe data'}</b></td>
962 </tr><tr>
963 <td class='base'>next-server:</td>
964 <td><input type='text' name='FIX_NEXTADDR' value='$dhcpsettings{'FIX_NEXTADDR'}' size='18' /></td>
965 <td class='base'>filename:</td>
966 <td><input type='text' name='FIX_FILENAME' value='$dhcpsettings{'FIX_FILENAME'}' size='18' /></td>
967 <td class='base'>root path:</td>
968 <td><input type='text' name='FIX_ROOTPATH' value='$dhcpsettings{'FIX_ROOTPATH'}' size='18' /></td>
969 </tr>
970 </table>
971 <hr />
972 <table width='100%'>
973 <tr>
974 <td class='base' width='50%'><img src='/blob.gif' align='top' alt='*' />&nbsp;$Lang::tr{'required field'}</td>
975 <td width='50%' align='right'>
976 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}2' />
977 <input type='submit' name='SUBMIT' value='$buttontext' />
978 <input type='hidden' name='KEY2' value='$dhcpsettings{'KEY2'}' /></td>
979 </tr>
980 </table>
981 </form>
982 END
983 ;
984 #Edited line number (KEY2) passed until cleared by 'save' or 'remove' or 'new sort order'
985
986 # Search for static leases
987 my $search_query = $dhcpsettings{'q'};
988
989 if (scalar @current2 >= 10) {
990 print <<END;
991 <form method="POST" action="#search">
992 <a name="search"></a>
993 <table width='100%'>
994 <tr>
995 <td>
996 <input type="text" name="q" value="$search_query">
997 <input type="submit" value="$Lang::tr{'search'}">
998 </td>
999 </tr>
1000 </table>
1001 </form>
1002 END
1003 }
1004
1005 print <<END
1006 <table width='100%' class='tbl'>
1007 <tr>
1008 <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FETHER'><b>$Lang::tr{'mac address'}</b></a></th>
1009 <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?FIPADDR'><b>$Lang::tr{'ip address'}</b></a></th>
1010 <th width='15%' align='center'><b>$Lang::tr{'remark'}</b></th>
1011 <th width='15%' class='boldbase' align='center'><b>next-server</b></th>
1012 <th width='15%' class='boldbase' align='center'><b>filename</b></th>
1013 <th width='15%' class='boldbase' align='center'><b>root path</b></th>
1014 <th colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></th>
1015 </tr>
1016 END
1017 ;
1018 my $ipdup = 0;
1019 my %ipinuse = ();
1020 my %macdupl = (); # Duplicate MACs have to be on different subnets
1021 my %ipoutside = ();
1022
1023 # mark duplicate ip or duplicate MAC
1024 foreach my $line (@current2) {
1025 my @temp = split(/\,/,$line);
1026 $macdupl{$temp[0]} += 1;
1027 if ($macdupl{$temp[0]} > 1) {
1028 $ipdup = 1; # Flag up duplicates for use later
1029 }
1030 $ipinuse{$temp[1]} += 1;
1031 if ($ipinuse{$temp[1]} > 1) {
1032 $ipdup = 1; # Flag up duplicates for use later
1033 }
1034 # Mark IP addresses outwith known subnets
1035 $ipoutside{$temp[1]} = 1;
1036 foreach my $itf (@ITFs) {
1037 if ( &General::IpInSubnet($temp[1],
1038 $netsettings{"${itf}_NETADDRESS"},
1039 $netsettings{"${itf}_NETMASK"})) {
1040 $ipoutside{$temp[1]} = 0;
1041 }
1042 }
1043 }
1044
1045 $key = 0;
1046 my $col="";
1047 foreach my $line (@current2) {
1048 my $gif = '';
1049 my $gdesc = '';
1050 chomp($line); # remove newline
1051 my @temp = split(/\,/,$line);
1052
1053 if ($temp[2] eq "on") {
1054 $gif = 'on.gif';
1055 $gdesc = $Lang::tr{'click to disable'};
1056 } else {
1057 $gif = 'off.gif';
1058 $gdesc = $Lang::tr{'click to enable'};
1059 }
1060
1061 # Skip all entries that do not match the search query
1062 if ($search_query ne "") {
1063 if (!grep(/$search_query/, @temp)) {
1064 $key++;
1065 next;
1066 }
1067 }
1068
1069 if ($dhcpsettings{'KEY2'} eq $key) {
1070 print "<tr>";
1071 $col="bgcolor='${Header::colouryellow}'";
1072 } elsif ($key % 2) {
1073 print "<tr>";
1074 $col="bgcolor='$color{'color20'}'";
1075 } else {
1076 print "<tr>";
1077 $col="bgcolor='$color{'color22'}'";
1078 }
1079 my $TAG0 = '';
1080 my $TAG1 = '';
1081 my $TAG2 = '';
1082 my $TAG3 = '';
1083 my $TAG4 = '';
1084 if ($ipinuse{$temp[1]} > 1) {
1085 $TAG0 = '<b>';
1086 $TAG1 = '</b>';
1087 }
1088 if ($macdupl{$temp[0]} > 1) {
1089 $TAG2 = '<b>';
1090 $TAG3 = '</b>';
1091 }
1092 if ($ipoutside{$temp[1]} > 0) {
1093 $TAG4 = "bgcolor='orange'" if ($dhcpsettings{'KEY2'} ne $key);
1094 }
1095
1096 print <<END
1097 <td align='center' $col>$TAG2$temp[0]$TAG3</td>
1098 <td align='center' $col $TAG4>$TAG0$temp[1]$TAG1</td>
1099 <td align='center' $col>$temp[6]&nbsp;</td>
1100 <td align='center' $col>$temp[3]&nbsp;</td>
1101 <td align='center' $col>$temp[4]&nbsp;</td>
1102 <td align='center' $col>$temp[5]&nbsp;</td>
1103
1104 <td align='center' $col>
1105 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1106 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}2' />
1107 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
1108 <input type='hidden' name='KEY2' value='$key' />
1109 </form>
1110 </td>
1111
1112 <td align='center' $col>
1113 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1114 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}2' />
1115 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
1116 <input type='hidden' name='KEY2' value='$key' />
1117 </form>
1118 </td>
1119
1120 <td align='center' $col>
1121 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1122 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}2' />
1123 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
1124 <input type='hidden' name='KEY2' value='$key' />
1125 </form>
1126 </td>
1127 </tr>
1128 END
1129 ;
1130 $key++;
1131 }
1132 print "</table>";
1133
1134 # If the fixed lease file contains entries, print Key to action icons
1135 if ($key) {
1136 my $dup = $ipdup ? "<td class='base'>$Lang::tr{'duplicate ip bold'}</td>" :'';
1137 print <<END
1138 <table>
1139 <tr>
1140 <td class='boldbase'>&nbsp;<b>$Lang::tr{'legend'}:&nbsp;</b></td>
1141 <td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
1142 <td class='base'>$Lang::tr{'click to disable'}</td>
1143 <td>&nbsp;&nbsp;</td>
1144 <td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
1145 <td class='base'>$Lang::tr{'click to enable'}</td>
1146 <td>&nbsp;&nbsp;</td>
1147 <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
1148 <td class='base'>$Lang::tr{'edit'}</td>
1149 <td>&nbsp;&nbsp;</td>
1150 <td><img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
1151 <td class='base'>$Lang::tr{'remove'}</td>
1152 </tr>
1153 <tr>
1154 <td>&nbsp;</td>
1155 <td bgcolor='orange'>&nbsp;</td>
1156 <td class='base'>$Lang::tr{'ip address outside subnets'}</td>
1157 <td>&nbsp;</td>
1158 <td>&nbsp;</td>
1159 $dup
1160 </tr>
1161 </table>
1162 END
1163 ;
1164 }
1165
1166 &Header::closebox();
1167
1168 foreach my $itf (@ITFs) {
1169 if ($dhcpsettings{"ENABLE_${itf}"} eq 'on') {
1170 # display leases with a list of actions to do with the global select checkbox.
1171 &Header::PrintActualLeases("+"); # "+" => create fixed leases from nodeaddress
1172 last; #Print one time only for all interfaces
1173 };
1174 }
1175
1176 &Header::closebigbox();
1177 &Header::closepage();
1178
1179 ## Ouf it's the end !
1180
1181 sub sortcurrent1 # by now, do not sort, just write
1182 {
1183 open(FILE, ">$filename1") or die 'Unable to open dhcp advanced options file.';
1184 print FILE @current1;
1185 close(FILE);
1186 }
1187
1188
1189 # Sort the "current2" array according to choices
1190 sub sortcurrent2
1191 {
1192 our %entries = ();
1193
1194 sub fixedleasesort {
1195 my $qs='';
1196 if (rindex ($dhcpsettings{'SORT_FLEASELIST'},'Rev') != -1) {
1197 $qs=substr ($dhcpsettings{'SORT_FLEASELIST'},0,length($dhcpsettings{'SORT_FLEASELIST'})-3);
1198 if ($qs eq 'FIPADDR') {
1199 my @a = split(/\./,$entries{$a}->{$qs});
1200 my @b = split(/\./,$entries{$b}->{$qs});
1201 ($b[0]<=>$a[0]) ||
1202 ($b[1]<=>$a[1]) ||
1203 ($b[2]<=>$a[2]) ||
1204 ($b[3]<=>$a[3]);
1205 } else {
1206 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1207 }
1208 } else { #not reverse
1209 $qs=$dhcpsettings{'SORT_FLEASELIST'};
1210 if ($qs eq 'FIPADDR') {
1211 my @a = split(/\./,$entries{$a}->{$qs});
1212 my @b = split(/\./,$entries{$b}->{$qs});
1213 ($a[0]<=>$b[0]) ||
1214 ($a[1]<=>$b[1]) ||
1215 ($a[2]<=>$b[2]) ||
1216 ($a[3]<=>$b[3]);
1217 } else {
1218 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1219 }
1220 }
1221 }
1222
1223 #Use an associative array (%entries)
1224 foreach my $line (@current2) {
1225 chomp( $line); #remove newline because can be on field 5 or 6 (addition of REMARK)
1226 my @temp = split (',',$line);
1227 my @record = ('FETHER',$temp[0],'FIPADDR',$temp[1],'DATA',join(',',@temp[2..6]));
1228 my $record = {}; # create a reference to empty hash
1229 %{$record} = @record; # populate that hash with @record
1230 # use combination of ether & IP as key to allow duplicates in either but not both
1231 $entries{$record->{FETHER} . $record->{FIPADDR}} = $record; # add this to a hash of hashes
1232 }
1233
1234 open(FILE, ">$filename2") or die 'Unable to open fixed lease file.';
1235 foreach my $entry ( sort fixedleasesort keys %entries) {
1236 print FILE "$entries{$entry}->{FETHER},$entries{$entry}->{FIPADDR},$entries{$entry}->{DATA}\n";
1237 }
1238 close(FILE);
1239
1240 # Reload sorted @current2
1241 open (FILE, "$filename2");
1242 @current2 = <FILE>;
1243 close (FILE);
1244 undef (%entries); #This array is reused latter. Clear it.
1245 }
1246
1247 # Build the configuration file mixing settings, fixed leases and advanced options
1248 sub buildconf {
1249 open(FILE, ">/${General::swroot}/dhcp/dhcpd.conf") or die "Unable to write dhcpd.conf file";
1250 flock(FILE, 2);
1251
1252 # Global settings
1253 print FILE "deny bootp; #default\n";
1254 print FILE "authoritative;\n";
1255
1256 # DNS Update settings
1257 if ($dhcpsettings{'DNS_UPDATE_ENABLED'} eq 'on') {
1258 print FILE "ddns-updates on;\n";
1259 print FILE "ddns-update-style interim;\n";
1260 print FILE "ddns-ttl 60; # 1 min\n";
1261 print FILE "ignore client-updates;\n";
1262 print FILE "update-static-leases on;\n";
1263 } else {
1264 print FILE "ddns-update-style none;\n";
1265 }
1266
1267 # Write first new option definition
1268 foreach my $line (@current1) {
1269 chomp($line); # remove newline
1270 my @temp = split(/\t/,$line);
1271 if (ExistNewOptionDefinition ($temp[1] . ' ' . $temp[2])) {
1272 print FILE "option $temp[1] $temp[2];\n";
1273 }
1274 }
1275 # Write other global options
1276 foreach my $line (@current1) {
1277 chomp($line); # remove newline
1278 my @temp = split(/\t/,$line);
1279
1280 if ($temp[0] eq 'on' && !ExistNewOptionDefinition ($temp[1] . ' ' . $temp[2])){ # active & !definition
1281 my $global=1;
1282 for (my $key=0; $key<@ITFs; $key++) {
1283 my $itf = $temp[3+$key];
1284 if ($itf ne 'off') # Only if an interface name is read
1285 {
1286 $global=0;
1287 }
1288 }
1289 if ($global) {
1290 print FILE "option $temp[1] $temp[2];\n";
1291 }
1292 }# on
1293 }# foreach line
1294 print FILE "\n";
1295
1296 #Subnet range definition
1297 foreach my $itf (@ITFs) {
1298 my $lc_itf=lc($itf);
1299 if ($dhcpsettings{"ENABLE_${itf}"} eq 'on' ){
1300 print FILE "subnet " . $netsettings{"${itf}_NETADDRESS"} . " netmask ". $netsettings{"${itf}_NETMASK"} . " #$itf\n";
1301 print FILE "{\n";
1302 if ($dhcpsettings{"START_ADDR_${itf}"}) {
1303 print FILE "pool {\n";
1304 print FILE "\trange " . $dhcpsettings{"START_ADDR_${itf}"} . ' ' . $dhcpsettings{"END_ADDR_${itf}"}.";\n";
1305 print FILE "\tdeny known-clients;\n" if ($dhcpsettings{"DENY_KNOWN_CLIENTS_${itf}"} eq 'on');
1306 print FILE " }\n"; # pool
1307 }
1308 print FILE "\toption subnet-mask " . $netsettings{"${itf}_NETMASK"} . ";\n";
1309 print FILE "\toption domain-name \"" . $dhcpsettings{"DOMAIN_NAME_${itf}"} . "\";\n";
1310 print FILE "\toption routers " . $netsettings{"${itf}_ADDRESS"} . ";\n";
1311 print FILE "\toption domain-name-servers " . $dhcpsettings{"DNS1_${itf}"} if ($dhcpsettings{"DNS1_${itf}"});
1312 print FILE ", " . $dhcpsettings{"DNS2_${itf}"} if ($dhcpsettings{"DNS2_${itf}"});
1313 print FILE ";\n" if ($dhcpsettings{"DNS1_${itf}"});
1314 print FILE "\toption ntp-servers " . $dhcpsettings{"NTP1_${itf}"} if ($dhcpsettings{"NTP1_${itf}"});
1315 print FILE ", " . $dhcpsettings{"NTP2_${itf}"} if ($dhcpsettings{"NTP2_${itf}"});
1316 print FILE ";\n" if ($dhcpsettings{"NTP1_${itf}"});
1317 print FILE "\toption netbios-name-servers " . $dhcpsettings{"WINS1_${itf}"} if ($dhcpsettings{"WINS1_${itf}"});
1318 print FILE ", " . $dhcpsettings{"WINS2_${itf}"} if ($dhcpsettings{"WINS2_${itf}"});
1319 print FILE ";\n" if ($dhcpsettings{"WINS1_${itf}"});
1320 print FILE "\tnext-server " . $dhcpsettings{"NEXT_${itf}"} . ";\n" if ($dhcpsettings{"NEXT_${itf}"});
1321 print FILE "\tfilename \"" . &EscapeFilename($dhcpsettings{"FILE_${itf}"}) . "\";\n" if ($dhcpsettings{"FILE_${itf}"});
1322 print FILE "\tdefault-lease-time " . ($dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"} * 60). ";\n";
1323 print FILE "\tmax-lease-time " . ($dhcpsettings{"MAX_LEASE_TIME_${itf}"} * 60) . ";\n";
1324 print FILE "\tallow bootp;\n" if ($dhcpsettings{"ENABLEBOOTP_${itf}"} eq 'on');
1325
1326
1327
1328 # Write scoped options
1329 foreach my $line (@current1) {
1330 chomp($line); # remove newline
1331 my @temp = split(/\t/,$line); # Use TAB separator !
1332
1333 if ($temp[0] eq 'on'){
1334 for (my $key=0; $key<@ITFs; $key++) {
1335 if ($itf eq $temp[3+$key]) # Only is an interface name is read
1336 {
1337 print FILE "\toption $temp[1] $temp[2];\n";
1338 }
1339 }
1340 }# on
1341 }# foreach line
1342 print FILE "} #$itf\n\n";
1343
1344 if (($dhcpsettings{"DNS_UPDATE_ENABLED"} eq "on") && ($dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"} ne "")) {
1345 print FILE "key " . $dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"} . " {\n";
1346 print FILE "\talgorithm " . $dhcpsettings{"DNS_UPDATE_KEY_ALGO_${itf}"} . ";\n";
1347 print FILE "\tsecret \"" . $dhcpsettings{"DNS_UPDATE_KEY_SECRET_${itf}"} . "\";\n";
1348 print FILE "};\n\n";
1349
1350 print FILE "zone " . $dhcpsettings{"DOMAIN_NAME_${itf}"} . ". {\n";
1351 print FILE "\tkey " . $dhcpsettings{"DNS_UPDATE_KEY_NAME_${itf}"} . ";\n";
1352 print FILE "}\n\n";
1353 }
1354
1355 &General::system('/usr/bin/touch', "${General::swroot}/dhcp/enable_${lc_itf}");
1356 &General::log("DHCP on ${itf}: " . $Lang::tr{'dhcp server enabled'})
1357 } else {
1358 unlink "${General::swroot}/dhcp/enable_${lc_itf}";
1359 &General::log("DHCP on ${itf}: " . $Lang::tr{'dhcp server disabled'})
1360 }
1361 }
1362
1363 #write fixed leases if any. Does not handle duplicates to write them elsewhere than the global scope.
1364 my $key = 0;
1365 foreach my $line (@current2) {
1366 chomp($line);
1367 my @temp = split(/\,/,$line);
1368 if ($temp[2] eq "on") {
1369 print FILE "\nhost fix$key # $temp[6]\n";
1370 print FILE "{\n";
1371 print FILE "\thardware ethernet $temp[0];\n";
1372 print FILE "\tfixed-address $temp[1];\n";
1373 print FILE "\tnext-server $temp[3];\n" if ($temp[3]);
1374 print FILE "\tfilename \"" . &EscapeFilename($temp[4]) . "\";\n" if ($temp[4]);
1375 print FILE "\toption root-path \"$temp[5]\";\n" if ($temp[5]);
1376 print FILE "}\n";
1377 $key++;
1378 }
1379 }
1380 print FILE "include \"${General::swroot}/dhcp/dhcpd.conf.local\";\n";
1381 close FILE;
1382 if ( $dhcpsettings{"ENABLE_GREEN"} eq 'on' || $dhcpsettings{"ENABLE_BLUE"} eq 'on' ) {&General::system('/usr/local/bin/dhcpctrl', 'enable');}
1383 else {&General::system('/usr/local/bin/dhcpctrl', 'disable');}
1384 &General::system_background('/usr/local/bin/dhcpctrl', 'restart');
1385 }
1386
1387 #
1388 # Receive a string and if it match model for a new option,
1389 # add it to the list %newOptions
1390 #
1391 my %NewOptions = ();
1392
1393 sub AddNewOptionDefinition {
1394 my ($line) = @_;
1395 if ( $line =~ /^([-\w]+)( code \d+=($OptionTypes))/ ) {
1396 $NewOptions{$1} = $2;
1397 #&General::log ("new:<$1><$2>");
1398 return 1;
1399 }
1400 return 0;
1401 }
1402
1403 #
1404 # Check existence of definition for a new option
1405 #
1406 sub ExistNewOptionDefinition {
1407 my ($line) = @_;
1408
1409 if ( $line =~ /^([-\w]+)( code \d+=($OptionTypes))/ ) {
1410 return defined $NewOptions{$1};
1411 }
1412 return 0;
1413 }
1414
1415 #
1416 # Check if it is a new option (definition must exist)
1417 # "code=" test eliminate a false response when definition exists
1418 # but this string is a definition with bad $OptionTypes.
1419 sub ValidNewOption {
1420 my ($line) = @_;
1421 if ($line =~ /^([-\w]+) (.*)/ ) {
1422 return defined ( $NewOptions{$1} ) && $2 !~ /code=/;
1423 }
1424 return 0;
1425 }
1426
1427 #
1428 # Check if the new option $opt is used, except the definition of itself!
1429 #
1430 sub IsUsedNewOptionDefinition {
1431 my ($opt,$val) = @_;
1432
1433 foreach my $line (@current1) {
1434 #chomp($line); # remove newline #don't know why, but this remove newline in @current1 .... !
1435 my @temp = split(/\t/,$line);
1436 # if we find something "opt value" & value != "code nnn=" it's ok.
1437 return 1 if ( ($opt eq $temp[1]) && ($temp[2] !~ /code \d+=/) );
1438 }
1439 return 0;
1440 }
1441
1442 sub EscapeFilename($) {
1443 my $filename = shift;
1444
1445 # Replace all single / by \/
1446 $filename =~ s/\//\\\//g;
1447
1448 return $filename;
1449 }