From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adolf Belka To: development@lists.ipfire.org Subject: [PATCH 2/2] dhcp.cgi: Fix bug#10629 - Highlight fixed IP's in dynamic range in red Date: Mon, 13 Feb 2023 18:55:15 +0100 Message-ID: <20230213175515.18840-2-adolf.belka@ipfire.org> In-Reply-To: <20230213175515.18840-1-adolf.belka@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7428243858150472415==" List-Id: --===============7428243858150472415== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable - This patch marks all IP's that are in the Fixed list but are also in the dy= namic range that has been defined, in red. - Additional function created to check if an ip address is in a defined range. - Added an additional key item under the Fixed Leases table for Fixed IP in d= ynamic range - Added line to English Language file for this key item. - ./make lang run before commit. - Tested in vm testbed and confirmed that any ip address in the Fixed Leases = table that is in the defined dynamic range is highlighted in red - This uses the css background-color appoach from the first patch in this set. - This patch only highlights those IP's that overlap in red but does nothing = more. So a user can still create new ones if they want but they will all show up in r= ed. - I may come back at a later time with a further patch that allows IP's that = overlap but are in the existing leases file to continue being used and edited but prev= ents new IP's that overlap from being created. - This patch flags up if people are doing things that they shouldn't be doing= but allows them to continue doing so without changing anything if they don't want to. Tested-by: Adolf Belka Signed-off-by: Adolf Belka --- config/cfgroot/network-functions.pl | 24 +++++++++++++++++++++++ doc/language_issues.de | 2 +- doc/language_issues.en | 2 +- doc/language_issues.es | 2 ++ doc/language_issues.fr | 15 ++++++--------- doc/language_issues.it | 2 +- doc/language_issues.nl | 2 +- doc/language_issues.pl | 2 +- doc/language_issues.ru | 2 +- doc/language_issues.tr | 2 +- doc/language_missings | 15 ++++++++------- html/cgi-bin/dhcp.cgi | 30 ++++++++++++++++++++++------- langs/en/cgi-bin/en.pl | 1 + 13 files changed, 71 insertions(+), 30 deletions(-) diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-fun= ctions.pl index 4ac6d8670..7b38cfac7 100644 --- a/config/cfgroot/network-functions.pl +++ b/config/cfgroot/network-functions.pl @@ -307,6 +307,24 @@ sub ip_address_in_network($$) { return (($address_bin >=3D $network_bin) && ($address_bin <=3D $broadcast_b= in)); } =20 +# Returns True if $ipaddress is within $ipstart and $ipend range. +sub ip_address_in_range($$) { + my $ipaddress =3D shift; + my $ipstart =3D shift; + my $ipend =3D shift; + + my $ipaddress_bin =3D &ip2bin($ipaddress); + return undef unless (defined $ipaddress_bin); + + my $ipstart_bin =3D &ip2bin($ipstart); + return undef unless (defined $ipstart_bin); + + my $ipend_bin =3D &ip2bin($ipend); + return undef unless (defined $ipend_bin); + + return (($ipaddress_bin >=3D $ipstart_bin) && ($ipaddress_bin <=3D $ipend_b= in)); +} + sub setup_upstream_proxy() { my %proxysettings =3D (); &General::readhash("${General::swroot}/proxy/settings", \%proxysettings); @@ -666,6 +684,12 @@ sub testsuite() { $result =3D &ip_address_in_network("192.168.30.11", "0.0.0.0/8"); assert('ip_address_in_network("192.168.30.11", "0.0.0.0/8")', !$result); =20 + $result =3D &ip_address_in_range("192.168.30.11", "192.168.30.10", "192.168= .30.20"); + assert('ip_address_in_range("192.168.30.11", "192.168.30.10", "192.168.30.2= 0")', $result); + + $result =3D &ip_address_in_range("192.168.30.21", "192.168.30.10", "192.168= .30.20"); + assert('ip_address_in_range("192.168.30.21", "192.168.30.10", "192.168.30.2= 0")', !$result); + print "Testsuite completed successfully!\n"; =20 return 0; diff --git a/doc/language_issues.de b/doc/language_issues.de index 88c7879be..392416192 100644 --- a/doc/language_issues.de +++ b/doc/language_issues.de @@ -883,7 +883,7 @@ WARNING: untranslated string: cake profile pppoe-ptm 27 = =3D PPPoE PTM (27 bytes) WARNING: untranslated string: cake profile pppoe-vcmux 32 =3D PPPoE VC-MUX (= 32 bytes) WARNING: untranslated string: cake profile raw 0 =3D Raw (no overhead compen= sation) WARNING: untranslated string: desired =3D Desired -WARNING: untranslated string: dh parameter =3D unknown string +WARNING: untranslated string: dhcp fixed ip address in dynamic range =3D Fix= ed IP Address in dynamic range WARNING: untranslated string: disable =3D Disable WARNING: untranslated string: download apple profile =3D Download Apple Conf= iguration Profile WARNING: untranslated string: enable =3D Enable diff --git a/doc/language_issues.en b/doc/language_issues.en index c29e3bed6..08fda35b7 100644 --- a/doc/language_issues.en +++ b/doc/language_issues.en @@ -574,7 +574,6 @@ WARNING: untranslated string: details =3D Details WARNING: untranslated string: device =3D Device WARNING: untranslated string: devices on blue =3D Devices on BLUE WARNING: untranslated string: dh =3D Diffie-Hellman-Parameter -WARNING: untranslated string: dh parameter =3D unknown string WARNING: untranslated string: dhcp advopt add =3D Add a DHCP option WARNING: untranslated string: dhcp advopt added =3D DHCP option added WARNING: untranslated string: dhcp advopt blank value =3D DHCP Option value = cannot be empty. @@ -601,6 +600,7 @@ WARNING: untranslated string: dhcp dns key name =3D Key N= ame WARNING: untranslated string: dhcp dns update =3D DNS Update WARNING: untranslated string: dhcp dns update algo =3D Algorithm WARNING: untranslated string: dhcp dns update secret =3D Secret +WARNING: untranslated string: dhcp fixed ip address in dynamic range =3D Fix= ed IP Address in dynamic range WARNING: untranslated string: dhcp make fixed lease =3D Add to fix leases WARNING: untranslated string: dhcp server =3D DHCP Server WARNING: untranslated string: dhcp server disabled =3D DHCP server disabled.= Stopped. diff --git a/doc/language_issues.es b/doc/language_issues.es index 0bd390d5d..ffe423bd1 100644 --- a/doc/language_issues.es +++ b/doc/language_issues.es @@ -228,6 +228,7 @@ WARNING: translation string unused: dh key move failed WARNING: translation string unused: dh key warn WARNING: translation string unused: dh key warn1 WARNING: translation string unused: dh name is invalid +WARNING: translation string unused: dh parameter WARNING: translation string unused: dhcp base ip fixed lease WARNING: translation string unused: dhcp create fixed leases WARNING: translation string unused: dhcp fixed lease err1 @@ -943,6 +944,7 @@ WARNING: untranslated string: access point name is invali= d =3D Access Point Name i WARNING: untranslated string: access point name is required =3D Access Point= Name is required WARNING: untranslated string: bytes =3D unknown string WARNING: untranslated string: cpu frequency =3D CPU frequency +WARNING: untranslated string: dhcp fixed ip address in dynamic range =3D Fix= ed IP Address in dynamic range WARNING: untranslated string: dns servers =3D DNS Servers WARNING: untranslated string: error message =3D unknown string WARNING: untranslated string: fwhost cust locationgrp =3D unknown string diff --git a/doc/language_issues.fr b/doc/language_issues.fr index 56d69d86e..cb06f0ab3 100644 --- a/doc/language_issues.fr +++ b/doc/language_issues.fr @@ -392,7 +392,6 @@ WARNING: translation string unused: generatepolicy WARNING: translation string unused: generatereport WARNING: translation string unused: genkey WARNING: translation string unused: green interface -WARNING: translation string unused: guaranteed bandwith WARNING: translation string unused: guest ok WARNING: translation string unused: gz with key WARNING: translation string unused: harddisk temperature graphs @@ -404,6 +403,7 @@ WARNING: translation string unused: host deny WARNING: translation string unused: hostname and domain already in use WARNING: translation string unused: hour-graph WARNING: translation string unused: hours2 +WARNING: translation string unused: ibod for dual isdn only WARNING: translation string unused: icmp selected but no type WARNING: translation string unused: icmp type WARNING: translation string unused: id @@ -453,6 +453,10 @@ WARNING: translation string unused: ipblocklist category= scanner WARNING: translation string unused: ipfire side WARNING: translation string unused: ipsec no connections WARNING: translation string unused: iptable rules +WARNING: translation string unused: isdn +WARNING: translation string unused: isdn settings +WARNING: translation string unused: isdn1 +WARNING: translation string unused: isdn2 WARNING: translation string unused: javascript menu error1 WARNING: translation string unused: javascript menu error2 WARNING: translation string unused: kernel version @@ -908,15 +912,11 @@ WARNING: translation string unused: zoneconf val zonesl= ave amount error WARNING: untranslated string: access point name =3D Access Point Name WARNING: untranslated string: access point name is invalid =3D Access Point = Name is invalid WARNING: untranslated string: access point name is required =3D Access Point= Name is required -WARNING: untranslated string: advproxy errmsg invalid url =3D Invalid URL WARNING: untranslated string: core notice 3 =3D available. -WARNING: untranslated string: dh =3D Diffie-Hellman-Parameter -WARNING: untranslated string: dh parameter =3D unknown string -WARNING: untranslated string: email recipient invalid =3D Invalid email reci= pient +WARNING: untranslated string: dhcp fixed ip address in dynamic range =3D Fix= ed IP Address in dynamic range WARNING: untranslated string: error message =3D unknown string WARNING: untranslated string: fwhost cust locationgrp =3D unknown string WARNING: untranslated string: fwhost err hostip =3D unknown string -WARNING: untranslated string: guaranteed bandwidth =3D Guaranteed bandwidth WARNING: untranslated string: guardian block a host =3D unknown string WARNING: untranslated string: guardian block httpd brute-force =3D unknown s= tring WARNING: untranslated string: guardian block ssh brute-force =3D unknown str= ing @@ -947,9 +947,6 @@ WARNING: untranslated string: guardian logtarget_syslog = =3D unknown string WARNING: untranslated string: guardian no entries =3D unknown string WARNING: untranslated string: guardian service =3D unknown string WARNING: untranslated string: pakfire ago =3D ago. -WARNING: untranslated string: retbleed =3D Retbleed WARNING: untranslated string: route config changed =3D unknown string WARNING: untranslated string: routing config added =3D unknown string WARNING: untranslated string: routing config changed =3D unknown string -WARNING: untranslated string: service boot setting unavailable =3D No valid = runlevel symlink was found for the initscript of this service. -WARNING: untranslated string: show dh =3D Show Diffie-Hellman parameters diff --git a/doc/language_issues.it b/doc/language_issues.it index 9999f947c..dd794f57a 100644 --- a/doc/language_issues.it +++ b/doc/language_issues.it @@ -940,13 +940,13 @@ WARNING: untranslated string: dangerous =3D Dangerous WARNING: untranslated string: default IP address =3D Default IP Address WARNING: untranslated string: desired =3D Desired WARNING: untranslated string: dh =3D Diffie-Hellman-Parameter -WARNING: untranslated string: dh parameter =3D unknown string WARNING: untranslated string: dhcp deny known clients: =3D Deny known client= s: WARNING: untranslated string: dhcp dns enable update =3D Enable DNS Update (= RFC2136): WARNING: untranslated string: dhcp dns key name =3D Key Name WARNING: untranslated string: dhcp dns update =3D DNS Update WARNING: untranslated string: dhcp dns update algo =3D Algorithm WARNING: untranslated string: dhcp dns update secret =3D Secret +WARNING: untranslated string: dhcp fixed ip address in dynamic range =3D Fix= ed IP Address in dynamic range WARNING: untranslated string: dhcp make fixed lease =3D Add to fix leases WARNING: untranslated string: dhcp valid range required when deny known clie= nts checked =3D Valid range required when "Deny known clients:" is checked WARNING: untranslated string: disable =3D Disable diff --git a/doc/language_issues.nl b/doc/language_issues.nl index 14a7b420e..4f100abd2 100644 --- a/doc/language_issues.nl +++ b/doc/language_issues.nl @@ -943,12 +943,12 @@ WARNING: untranslated string: default =3D Default WARNING: untranslated string: default IP address =3D Default IP Address WARNING: untranslated string: desired =3D Desired WARNING: untranslated string: dh =3D Diffie-Hellman-Parameter -WARNING: untranslated string: dh parameter =3D unknown string WARNING: untranslated string: dhcp dns enable update =3D Enable DNS Update (= RFC2136): WARNING: untranslated string: dhcp dns key name =3D Key Name WARNING: untranslated string: dhcp dns update =3D DNS Update WARNING: untranslated string: dhcp dns update algo =3D Algorithm WARNING: untranslated string: dhcp dns update secret =3D Secret +WARNING: untranslated string: dhcp fixed ip address in dynamic range =3D Fix= ed IP Address in dynamic range WARNING: untranslated string: dhcp make fixed lease =3D Add to fix leases WARNING: untranslated string: disable =3D Disable WARNING: untranslated string: disconnected =3D Disconnected diff --git a/doc/language_issues.pl b/doc/language_issues.pl index a53a208d9..e91e62c5b 100644 --- a/doc/language_issues.pl +++ b/doc/language_issues.pl @@ -915,13 +915,13 @@ WARNING: untranslated string: default IP address =3D De= fault IP Address WARNING: untranslated string: desired =3D Desired WARNING: untranslated string: details =3D Details WARNING: untranslated string: dh =3D Diffie-Hellman-Parameter -WARNING: untranslated string: dh parameter =3D unknown string WARNING: untranslated string: dhcp deny known clients: =3D Deny known client= s: WARNING: untranslated string: dhcp dns enable update =3D Enable DNS Update (= RFC2136): WARNING: untranslated string: dhcp dns key name =3D Key Name WARNING: untranslated string: dhcp dns update =3D DNS Update WARNING: untranslated string: dhcp dns update algo =3D Algorithm WARNING: untranslated string: dhcp dns update secret =3D Secret +WARNING: untranslated string: dhcp fixed ip address in dynamic range =3D Fix= ed IP Address in dynamic range WARNING: untranslated string: dhcp make fixed lease =3D Add to fix leases WARNING: untranslated string: dhcp valid range required when deny known clie= nts checked =3D Valid range required when "Deny known clients:" is checked WARNING: untranslated string: disable =3D Disable diff --git a/doc/language_issues.ru b/doc/language_issues.ru index c5dc1aa61..7dd1a63d7 100644 --- a/doc/language_issues.ru +++ b/doc/language_issues.ru @@ -911,13 +911,13 @@ WARNING: untranslated string: default IP address =3D De= fault IP Address WARNING: untranslated string: desired =3D Desired WARNING: untranslated string: details =3D Details WARNING: untranslated string: dh =3D Diffie-Hellman-Parameter -WARNING: untranslated string: dh parameter =3D unknown string WARNING: untranslated string: dhcp deny known clients: =3D Deny known client= s: WARNING: untranslated string: dhcp dns enable update =3D Enable DNS Update (= RFC2136): WARNING: untranslated string: dhcp dns key name =3D Key Name WARNING: untranslated string: dhcp dns update =3D DNS Update WARNING: untranslated string: dhcp dns update algo =3D Algorithm WARNING: untranslated string: dhcp dns update secret =3D Secret +WARNING: untranslated string: dhcp fixed ip address in dynamic range =3D Fix= ed IP Address in dynamic range WARNING: untranslated string: dhcp make fixed lease =3D Add to fix leases WARNING: untranslated string: dhcp valid range required when deny known clie= nts checked =3D Valid range required when "Deny known clients:" is checked WARNING: untranslated string: disable =3D Disable diff --git a/doc/language_issues.tr b/doc/language_issues.tr index 552082a96..3443b1f1a 100644 --- a/doc/language_issues.tr +++ b/doc/language_issues.tr @@ -926,8 +926,8 @@ WARNING: untranslated string: dangerous =3D Dangerous WARNING: untranslated string: default IP address =3D Default IP Address WARNING: untranslated string: desired =3D Desired WARNING: untranslated string: dh =3D Diffie-Hellman-Parameter -WARNING: untranslated string: dh parameter =3D unknown string WARNING: untranslated string: dhcp deny known clients: =3D Deny known client= s: +WARNING: untranslated string: dhcp fixed ip address in dynamic range =3D Fix= ed IP Address in dynamic range WARNING: untranslated string: dhcp make fixed lease =3D Add to fix leases WARNING: untranslated string: dhcp valid range required when deny known clie= nts checked =3D Valid range required when "Deny known clients:" is checked WARNING: untranslated string: disable =3D Disable diff --git a/doc/language_missings b/doc/language_missings index 65d38b422..78b9e8a2d 100644 --- a/doc/language_missings +++ b/doc/language_missings @@ -47,6 +47,7 @@ < could not connect to www ipfire org < cryptographic settings < desired +< dhcp fixed ip address in dynamic range < dhcp server disabled on blue interface < dhcp server enabled on blue interface < disable @@ -102,6 +103,7 @@ < access point name is required < addon < cpu frequency +< dhcp fixed ip address in dynamic range < dns servers < hardware vulnerabilities < invalid ip or hostname @@ -115,18 +117,12 @@ < access point name < access point name is invalid < access point name is required -< advproxy errmsg invalid url < ansi t1.483 < bewan adsl pci st < bewan adsl usb -< dh -< email recipient invalid +< dhcp fixed ip address in dynamic range < g.dtm < g.lite -< guaranteed bandwidth -< retbleed -< service boot setting unavailable -< show dh < upload fcdsl.o ############################################################################ # Checking cgi-bin translations for language: it # @@ -252,6 +248,7 @@ < dhcp dns update < dhcp dns update algo < dhcp dns update secret +< dhcp fixed ip address in dynamic range < dhcp make fixed lease < dhcp valid range required when deny known clients checked < disable @@ -756,6 +753,7 @@ < dhcp dns update < dhcp dns update algo < dhcp dns update secret +< dhcp fixed ip address in dynamic range < dhcp make fixed lease < disable < Disabled @@ -1353,6 +1351,7 @@ < dhcp dns update < dhcp dns update algo < dhcp dns update secret +< dhcp fixed ip address in dynamic range < dhcp make fixed lease < dhcp valid range required when deny known clients checked < disable @@ -2330,6 +2329,7 @@ < dhcp dns update < dhcp dns update algo < dhcp dns update secret +< dhcp fixed ip address in dynamic range < dhcp make fixed lease < dhcp valid range required when deny known clients checked < disable @@ -3173,6 +3173,7 @@ < desired < dh < dhcp deny known clients: +< dhcp fixed ip address in dynamic range < dhcp make fixed lease < dhcp valid range required when deny known clients checked < disable diff --git a/html/cgi-bin/dhcp.cgi b/html/cgi-bin/dhcp.cgi index 2d162b204..1b1102932 100644 --- a/html/cgi-bin/dhcp.cgi +++ b/html/cgi-bin/dhcp.cgi @@ -127,6 +127,9 @@ my $extraHead =3D < END @@ -1042,8 +1045,9 @@ my $ipdup =3D 0; my %ipinuse =3D (); my %macdupl =3D (); # Duplicate MACs have to be on different subnets my %ipoutside =3D (); +my %ipinrange =3D (); =20 -# mark duplicate ip or duplicate MAC +# mark duplicate IP, duplicate MAC or IP in dynamic range foreach my $line (@current2) { my @temp =3D split(/\,/,$line); $macdupl{$temp[0]} +=3D 1; @@ -1054,14 +1058,21 @@ foreach my $line (@current2) { if ($ipinuse{$temp[1]} > 1) { $ipdup =3D 1; # Flag up duplicates for use later } - # Mark IP addresses outwith known subnets $ipoutside{$temp[1]} =3D 1; + $ipinrange{$temp[1]} =3D 0; foreach my $itf (@ITFs) { - if ( &General::IpInSubnet($temp[1], - $netsettings{"${itf}_NETADDRESS"}, - $netsettings{"${itf}_NETMASK"})) { - $ipoutside{$temp[1]} =3D 0; - } + # Mark IP addresses outwith known subnets + if ( &General::IpInSubnet($temp[1], + $netsettings{"${itf}_NETADDRESS"}, + $netsettings{"${itf}_NETMASK"})) { + $ipoutside{$temp[1]} =3D 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]} =3D 1; + } =20 } } =20 @@ -1115,6 +1126,9 @@ foreach my $line (@current2) { if ($ipoutside{$temp[1]} > 0) { $TAG4 =3D "class=3D'cell-orange'" if ($dhcpsettings{'KEY2'} ne $key); } + if ($ipinrange{$temp[1]} > 0) {=20 + $TAG4 =3D "class=3D'cell-red'" if ($dhcpsettings{'KEY2'} ne $key); + } =20 print <$TAG2$temp[0]$TAG3 @@ -1177,6 +1191,8 @@ print <    $Lang::tr{'ip address outside subnets'} +    + $Lang::tr{'dhcp fixed ip address in dyna= mic range'}     $dup diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index 80753b841..5a72f53b8 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -827,6 +827,7 @@ 'dhcp dns update' =3D> 'DNS Update', 'dhcp dns update algo' =3D> 'Algorithm', 'dhcp dns update secret' =3D> 'Secret', +'dhcp fixed ip address in dynamic range' =3D> 'Fixed IP Address in dynamic r= ange', 'dhcp fixed lease err1' =3D> 'For a fix lease you have to enter the MAC addr= ess or the hostname, or you enter both.', 'dhcp fixed lease help1' =3D> 'IP Addresses might be entered as FQDN', 'dhcp make fixed lease' =3D> 'Add to fix leases', --=20 2.39.1 --===============7428243858150472415==--