###############################################################################
# #
# IPFire.org - A linux based firewall #
-# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
+# Copyright (C) 2007-2023 IPFire Team <info@ipfire.org> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
my @nosaved=();
my %color = ();
-#Basic syntax allowed for new Option definition. Not implemented: RECORDS & array of RECORDS
+#Basic syntax allowed for new Option definition. Not implemented: RECORDS & array of RECORDS
our $OptionTypes = 'boolean|((un)?signed )?integer (8|16|32)|ip-address|text|string|encapsulate \w+|array of ip-address';
&Header::showhttpheaders();
$errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid end address'};
goto ERROR;
}
- if (! &General::IpInSubnet ( $dhcpsettings{"START_ADDR_${itf}"},
+ if (! &General::IpInSubnet ( $dhcpsettings{"START_ADDR_${itf}"},
$netsettings{"${itf}_NETADDRESS"},
$netsettings{"${itf}_NETMASK"})) {
$errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid start address'};
goto ERROR;
}
}
-
+
if ($dhcpsettings{"END_ADDR_${itf}"}) {
if (!(&General::validip($dhcpsettings{"END_ADDR_${itf}"}))) {
$errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid end address'};
$errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid start address'};
goto ERROR;
}
- if (! &General::IpInSubnet ( $dhcpsettings{"END_ADDR_${itf}"},
+ if (! &General::IpInSubnet ( $dhcpsettings{"END_ADDR_${itf}"},
$netsettings{"${itf}_NETADDRESS"},
- $netsettings{"${itf}_NETMASK"})) {
+ $netsettings{"${itf}_NETMASK"})) {
$errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid end address'};
goto ERROR;
}
goto ERROR;
}
if (! $dhcpsettings{"DNS1_${itf}"}) {
- $errormessage = "DHCP on ${itf}: " . $Lang::tr{'cannot specify secondary dns without specifying primary'};
+ $errormessage = "DHCP on ${itf}: " . $Lang::tr{'cannot specify secondary dns without specifying primary'};
goto ERROR;
}
}
if (! $dhcpsettings{"WINS1_${itf}"} ) {
$errormessage = "DHCP on ${itf}: " . $Lang::tr{'cannot specify secondary wins without specifying primary'};
goto ERROR;
- }
+ }
}
if ($dhcpsettings{"NEXT_${itf}"}) {
if (!(&General::validip($dhcpsettings{"NEXT_${itf}"}))) {
&General::writehash($setting, \%dhcpsettings);
&sortcurrent2;
$dhcpsettings{'ACTION'} = 'SORT'; # create an 'ACTION'
- map ($dhcpsettings{$_} = '',@nosaved,'KEY1','KEY2');# and reinit vars to empty
+ map ($dhcpsettings{$_} = '',@nosaved,'KEY1','KEY2');# and reinit vars to empty
}
#Sorting of allocated leases
&Header::CheckSortOrder;
-## Now manipulate the two multi-line list with Settings2.
+## Now manipulate the two multi-line list with Settings2.
# '1' suffix is for ADVANCED OPTIONS
# '2' suffix is for FIXED LEASES
open(FILE, ">$filename1") or die 'Unable to open dhcp advanced options file.';
print FILE @current1;
close(FILE);
-
+
#Write changes to dhcpd.conf.
&buildconf;
}
-
+
if ($dhcpsettings{'ACTION'} eq $Lang::tr{'add'}.'1' &&
$dhcpsettings{'SUBMIT'} ne $Lang::tr{'dhcp advopt help'}) {
if ($dhcpsettings{'ADVOPT_DATA'} eq '') {
$errormessage=$Lang::tr{'dhcp advopt blank value'};
}
-
+
# Test for a new option definition string (join field name & data)
if (ExistNewOptionDefinition ($dhcpsettings{'ADVOPT_NAME'} . ' ' . $dhcpsettings{'ADVOPT_DATA'})) {
#only edit permitted if option definition exists
}
unless ($errormessage) {
-
+
my $scope = '';
foreach my $itf (@ITFs) { # buils "RED,GREEN,ORANGE,... based on selection
$scope .= $dhcpsettings{"ADVOPT_SCOPE_${itf}"} eq 'on' ? "\t$itf" : "\toff" ;
if ($itf ne 'off') # Only is an interface name is read
{
$dhcpsettings{"ADVOPT_SCOPE_${itf}"} = 'on';
- }
+ }
}
}
open(FILE, ">$filename2") or die 'Unable to open fixed leases file.';
print FILE @current2;
close(FILE);
-
+
#Write changes to dhcpd.conf.
&buildconf;
}
if ($dhcpsettings{'FIX_NEXTADDR'}) {
unless(&General::validip($dhcpsettings{'FIX_NEXTADDR'})) { $errormessage = $Lang::tr{'invalid fixed ip address'}; }
}
-
+
my $key = 0;
CHECK:foreach my $line (@current2) {
my @temp = split(/\,/,$line);
# Also it may be needed to put duplicate fixed lease in their right subnet definition..
foreach my $itf (@ITFs) {
my $scoped = &General::IpInSubnet($dhcpsettings{'FIX_ADDR'},
- $netsettings{"${itf}_NETADDRESS"},
+ $netsettings{"${itf}_NETADDRESS"},
$netsettings{"${itf}_NETMASK"}) &&
$dhcpsettings{"ENABLE_${itf}"} eq 'on';
if ( $scoped &&
(lc($dhcpsettings{'FIX_MAC'}) eq lc($temp[0])) &&
&General::IpInSubnet($temp[1],
- $netsettings{"${itf}_NETADDRESS"},
+ $netsettings{"${itf}_NETADDRESS"},
$netsettings{"${itf}_NETMASK"})) {
$errormessage = "$Lang::tr{'mac address in use'} $dhcpsettings{'FIX_MAC'}";
last CHECK;
$dhcpsettings{'ADVOPT_ENABLED'} = 'on';
}
-&Header::openpage($Lang::tr{'dhcp configuration'}, 1, '');
+### START PAGE ###
+&Header::openpage($Lang::tr{'dhcp configuration'}, 1, $Header::extraHead);
&Header::openbigbox('100%', 'left', '', $errormessage);
if ($errormessage) {
END
;
-# Put a checkbox for each interface. Checkbox visible disabled if interface is disabled
+# Put a checkbox for each interface. Checkbox visible disabled if interface is disabled
foreach my $itf (@ITFs) {
my $lc_itf=lc($itf);
- $checked{'ADVOPT_SCOPE_${itf}'}{'on'} = $dhcpsettings{"ADVOPT_SCOPE_${itf}"} ne 'on' ? '' : "checked='checked'";
+ $checked{'ADVOPT_SCOPE_${itf}'}{'on'} = $dhcpsettings{"ADVOPT_SCOPE_${itf}"} ne 'on' ? '' : "checked='checked'";
print "$Lang::tr{\"${lc_itf}\"} <input type='checkbox' name='ADVOPT_SCOPE_${itf}' $checked{'ADVOPT_SCOPE_${itf}'}{'on'} ";
print $dhcpsettings{"ENABLE_${itf}"} eq 'on' ? "/>" : "disabled='disabled' />";
print " ";
print "<tr><td colspan='2'><hr /></td></tr>\n";
print '<tr><td>string type</td><td>"quoted string" or 00:01:FF...</td></tr>';
print '<tr><td>ip-address type </td><td>10.0.0.1 | www.dot.com</td></tr>';
+ print '<tr><td>domain-list type </td><td>"example.com", "eng.example.com", "sales.example.com"</td></tr>';
print '<tr><td>int,uint types</td><td>numbers</td></tr>';
print '<tr><td>flag type</td><td>on | off</td></tr>';
print '</table>';
print '<tr><td>wpad</td><td>code 252=text</td></tr>';
print '<tr><td>wpad</td><td>"http://www.server.fr/path-to/proxy.pac"</td></tr>';
print '</table>';
-
+
}
print <<END
$gdesc = $Lang::tr{'click to disable'};
} else {
$gif = 'off.gif';
- $gdesc = $Lang::tr{'click to enable'};
+ $gdesc = $Lang::tr{'click to enable'};
}
if ($dhcpsettings{'KEY1'} eq $key) {
- print "<tr bgcolor='${Header::colouryellow}'>";
+ print "<tr class='colouryellow'>";
} elsif ($key % 2) {
- print "<tr bgcolor='$color{'color22'}'>";
+ print "<tr class='color22'>";
} else {
- print "<tr bgcolor='$color{'color20'}'>";
+ print "<tr class='color20'>";
}
print <<END
} else {
$global = $Lang::tr{'dhcp advopt scope global'};
}
-
-
+
+
# Print each checked interface
for (my $key=0; $key<@ITFs; $key++) {
my $itf = $temp[3+$key];
my %ipinuse = ();
my %macdupl = (); # Duplicate MACs have to be on different subnets
my %ipoutside = ();
+my %ipinrange = ();
-# mark duplicate ip or duplicate MAC
+# mark duplicate IP, duplicate MAC or IP in dynamic range
foreach my $line (@current2) {
my @temp = split(/\,/,$line);
$macdupl{$temp[0]} += 1;
- if ($macdupl{$temp[0]} > 1) {
+ if ($macdupl{$temp[0]} > 1) {
$ipdup = 1; # Flag up duplicates for use later
}
$ipinuse{$temp[1]} += 1;
- if ($ipinuse{$temp[1]} > 1) {
+ if ($ipinuse{$temp[1]} > 1) {
$ipdup = 1; # Flag up duplicates for use later
}
- # Mark IP addresses outwith known subnets
$ipoutside{$temp[1]} = 1;
+ $ipinrange{$temp[1]} = 0;
foreach my $itf (@ITFs) {
- if ( &General::IpInSubnet($temp[1],
- $netsettings{"${itf}_NETADDRESS"},
- $netsettings{"${itf}_NETMASK"})) {
- $ipoutside{$temp[1]} = 0;
- }
+ # Mark IP addresses outwith known subnets
+ if ( &General::IpInSubnet($temp[1],
+ $netsettings{"${itf}_NETADDRESS"},
+ $netsettings{"${itf}_NETMASK"})) {
+ $ipoutside{$temp[1]} = 0;
+ }
+ # Mark IP addresses that overlap with dynamic range
+ if (&Network::ip_address_in_range($temp[1],
+ $dhcpsettings{"START_ADDR_${itf}"},
+ $dhcpsettings{"END_ADDR_${itf}"})) {
+ $ipinrange{$temp[1]} = 1;
+ }
}
}
$gdesc = $Lang::tr{'click to disable'};
} else {
$gif = 'off.gif';
- $gdesc = $Lang::tr{'click to enable'};
+ $gdesc = $Lang::tr{'click to enable'};
}
# Skip all entries that do not match the search query
if ($dhcpsettings{'KEY2'} eq $key) {
print "<tr>";
- $col="bgcolor='${Header::colouryellow}'";
+ $col="class='colouryellow'";
} elsif ($key % 2) {
print "<tr>";
- $col="bgcolor='$color{'color20'}'";
+ $col="class='color20'";
} else {
print "<tr>";
- $col="bgcolor='$color{'color22'}'";
+ $col="class='color22'";
}
my $TAG0 = '';
my $TAG1 = '';
my $TAG2 = '';
my $TAG3 = '';
my $TAG4 = '';
- if ($ipinuse{$temp[1]} > 1) {
+ if ($ipinuse{$temp[1]} > 1) {
$TAG0 = '<b>';
$TAG1 = '</b>';
}
- if ($macdupl{$temp[0]} > 1) {
+ if ($macdupl{$temp[0]} > 1) {
$TAG2 = '<b>';
$TAG3 = '</b>';
}
- if ($ipoutside{$temp[1]} > 0) {
- $TAG4 = "bgcolor='orange'" if ($dhcpsettings{'KEY2'} ne $key);
+ if ($ipoutside{$temp[1]} > 0) {
+ $TAG4 = "class='orange'" if ($dhcpsettings{'KEY2'} ne $key);
+ }
+ if ($ipinrange{$temp[1]} > 0) {
+ $TAG4 = "class='red'" if ($dhcpsettings{'KEY2'} ne $key);
}
print <<END
<td align='center' $col>$TAG2$temp[0]$TAG3</td>
-<td align='center' $col $TAG4>$TAG0$temp[1]$TAG1</td>
+<td align='center' $TAG4 $col>$TAG0$temp[1]$TAG1</td>
<td align='center' $col>$temp[6] </td>
<td align='center' $col>$temp[3] </td>
<td align='center' $col>$temp[4] </td>
<td class='boldbase'> <b>$Lang::tr{'legend'}: </b></td>
<td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
<td class='base'>$Lang::tr{'click to disable'}</td>
- <td> </td>
<td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
<td class='base'>$Lang::tr{'click to enable'}</td>
<td> </td>
</tr>
<tr>
<td> </td>
- <td bgcolor='orange'> </td>
- <td class='base'>$Lang::tr{'ip address outside subnets'}</td>
+ <td class='base orange'> </td>
+ <td class='base'> $Lang::tr{'ip address outside subnets'} </td>
+ <td class='base red'> </td>
+ <td class='base'> $Lang::tr{'dhcp fixed ip address in dynamic range'}</td>
<td> </td>
<td> </td>
$dup
# use combination of ether & IP as key to allow duplicates in either but not both
$entries{$record->{FETHER} . $record->{FIPADDR}} = $record; # add this to a hash of hashes
}
-
+
open(FILE, ">$filename2") or die 'Unable to open fixed lease file.';
foreach my $entry ( sort fixedleasesort keys %entries) {
print FILE "$entries{$entry}->{FETHER},$entries{$entry}->{FIPADDR},$entries{$entry}->{DATA}\n";
close (FILE);
undef (%entries); #This array is reused latter. Clear it.
}
-
+
# Build the configuration file mixing settings, fixed leases and advanced options
sub buildconf {
open(FILE, ">/${General::swroot}/dhcp/dhcpd.conf") or die "Unable to write dhcpd.conf file";
} else {
print FILE "ddns-update-style none;\n";
}
-
+
# Write first new option definition
foreach my $line (@current1) {
chomp($line); # remove newline
foreach my $line (@current1) {
chomp($line); # remove newline
my @temp = split(/\t/,$line);
-
+
if ($temp[0] eq 'on' && !ExistNewOptionDefinition ($temp[1] . ' ' . $temp[2])){ # active & !definition
my $global=1;
for (my $key=0; $key<@ITFs; $key++) {
if ($global) {
print FILE "option $temp[1] $temp[2];\n";
}
- }# on
+ }# on
}# foreach line
print FILE "\n";
foreach my $line (@current1) {
chomp($line); # remove newline
my @temp = split(/\t/,$line); # Use TAB separator !
-
+
if ($temp[0] eq 'on'){
for (my $key=0; $key<@ITFs; $key++) {
if ($itf eq $temp[3+$key]) # Only is an interface name is read
print FILE "\toption $temp[1] $temp[2];\n";
}
}
- }# on
+ }# on
}# foreach line
print FILE "} #$itf\n\n";