header.pl: Remove duplicate "IpInSubnet" function
Commit Message
This function is deprecated. The commonly used and maintained "IpInSubnet" function can be found in general-functions.pl.
Signed-off-by: Leo-Andres Hofmann <hofmann@leo-andres.de>
---
config/cfgroot/header.pl | 22 +++-------------------
1 file changed, 3 insertions(+), 19 deletions(-)
Comments
Hello,
Good catch :) I like cleaning up things :)
-Michael
> On 12 Jan 2021, at 18:11, Leo-Andres Hofmann <hofmann@leo-andres.de> wrote:
>
> This function is deprecated. The commonly used and maintained "IpInSubnet" function can be found in general-functions.pl.
>
> Signed-off-by: Leo-Andres Hofmann <hofmann@leo-andres.de>
> ---
> config/cfgroot/header.pl | 22 +++-------------------
> 1 file changed, 3 insertions(+), 19 deletions(-)
>
> diff --git a/config/cfgroot/header.pl b/config/cfgroot/header.pl
> index e2e6fd689..5684c01c5 100644
> --- a/config/cfgroot/header.pl
> +++ b/config/cfgroot/header.pl
> @@ -311,22 +311,6 @@ sub getcgihash {
> return;
> }
>
> -
> -# Test if IP is within a subnet
> -# Call: IpInSubnet (Addr, Subnet, Subnet Mask)
> -# Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
> -# Everything in dottted notation
> -# Return: TRUE/FALSE
> -sub IpInSubnet
> -{
> - $ip = unpack('N', inet_aton(shift));
> - $start = unpack('N', inet_aton(shift));
> - $mask = unpack('N', inet_aton(shift));
> - $start &= $mask; # base of subnet...
> - $end = $start + ~$mask;
> - return (($ip >= $start) && ($ip <= $end));
> -}
> -
> sub escape($) {
> my $s = shift;
> return HTML::Entities::encode_entities($s);
> @@ -559,13 +543,13 @@ sub colorize {
> return "<font color='".${Header::colourovpn}."'>".$string."</font>";
> } elsif ( $string =~ "lo" or $string =~ "127.0.0.0" ){
> return "<font color='".${Header::colourfw}."'>".$string."</font>";
> - } elsif ( $string =~ $ethsettings{'GREEN_DEV'} or &IpInSubnet($string2,$ethsettings{'GREEN_NETADDRESS'},$ethsettings{'GREEN_NETMASK'}) ){
> + } elsif ( $string =~ $ethsettings{'GREEN_DEV'} or &General::IpInSubnet($string2,$ethsettings{'GREEN_NETADDRESS'},$ethsettings{'GREEN_NETMASK'}) ){
> return "<font color='".${Header::colourgreen}."'>".$string."</font>";
> } elsif ( $string =~ "ppp0" or $string =~ $ethsettings{'RED_DEV'} or $string =~ "0.0.0.0" or $string =~ $ethsettings{'RED_ADDRESS'} ){
> return "<font color='".${Header::colourred}."'>".$string."</font>";
> - } elsif ( $ethsettings{'CONFIG_TYPE'}>1 and ( $string =~ $ethsettings{'BLUE_DEV'} or &IpInSubnet($string2,$ethsettings{'BLUE_NETADDRESS'},$ethsettings{'BLUE_NETMASK'}) )){
> + } elsif ( $ethsettings{'CONFIG_TYPE'}>1 and ( $string =~ $ethsettings{'BLUE_DEV'} or &General::IpInSubnet($string2,$ethsettings{'BLUE_NETADDRESS'},$ethsettings{'BLUE_NETMASK'}) )){
> return "<font color='".${Header::colourblue}."'>".$string."</font>";
> - } elsif ( $ethsettings{'CONFIG_TYPE'}>2 and ( $string =~ $ethsettings{'ORANGE_DEV'} or &IpInSubnet($string2,$ethsettings{'ORANGE_NETADDRESS'},$ethsettings{'ORANGE_NETMASK'}) )){
> + } elsif ( $ethsettings{'CONFIG_TYPE'}>2 and ( $string =~ $ethsettings{'ORANGE_DEV'} or &General::IpInSubnet($string2,$ethsettings{'ORANGE_NETADDRESS'},$ethsettings{'ORANGE_NETMASK'}) )){
> return "<font color='".${Header::colourorange}."'>".$string."</font>";
> } else {
> return $string;
> --
> 2.27.0.windows.1
>
@@ -311,22 +311,6 @@ sub getcgihash {
return;
}
-
-# Test if IP is within a subnet
-# Call: IpInSubnet (Addr, Subnet, Subnet Mask)
-# Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
-# Everything in dottted notation
-# Return: TRUE/FALSE
-sub IpInSubnet
-{
- $ip = unpack('N', inet_aton(shift));
- $start = unpack('N', inet_aton(shift));
- $mask = unpack('N', inet_aton(shift));
- $start &= $mask; # base of subnet...
- $end = $start + ~$mask;
- return (($ip >= $start) && ($ip <= $end));
-}
-
sub escape($) {
my $s = shift;
return HTML::Entities::encode_entities($s);
@@ -559,13 +543,13 @@ sub colorize {
return "<font color='".${Header::colourovpn}."'>".$string."</font>";
} elsif ( $string =~ "lo" or $string =~ "127.0.0.0" ){
return "<font color='".${Header::colourfw}."'>".$string."</font>";
- } elsif ( $string =~ $ethsettings{'GREEN_DEV'} or &IpInSubnet($string2,$ethsettings{'GREEN_NETADDRESS'},$ethsettings{'GREEN_NETMASK'}) ){
+ } elsif ( $string =~ $ethsettings{'GREEN_DEV'} or &General::IpInSubnet($string2,$ethsettings{'GREEN_NETADDRESS'},$ethsettings{'GREEN_NETMASK'}) ){
return "<font color='".${Header::colourgreen}."'>".$string."</font>";
} elsif ( $string =~ "ppp0" or $string =~ $ethsettings{'RED_DEV'} or $string =~ "0.0.0.0" or $string =~ $ethsettings{'RED_ADDRESS'} ){
return "<font color='".${Header::colourred}."'>".$string."</font>";
- } elsif ( $ethsettings{'CONFIG_TYPE'}>1 and ( $string =~ $ethsettings{'BLUE_DEV'} or &IpInSubnet($string2,$ethsettings{'BLUE_NETADDRESS'},$ethsettings{'BLUE_NETMASK'}) )){
+ } elsif ( $ethsettings{'CONFIG_TYPE'}>1 and ( $string =~ $ethsettings{'BLUE_DEV'} or &General::IpInSubnet($string2,$ethsettings{'BLUE_NETADDRESS'},$ethsettings{'BLUE_NETMASK'}) )){
return "<font color='".${Header::colourblue}."'>".$string."</font>";
- } elsif ( $ethsettings{'CONFIG_TYPE'}>2 and ( $string =~ $ethsettings{'ORANGE_DEV'} or &IpInSubnet($string2,$ethsettings{'ORANGE_NETADDRESS'},$ethsettings{'ORANGE_NETMASK'}) )){
+ } elsif ( $ethsettings{'CONFIG_TYPE'}>2 and ( $string =~ $ethsettings{'ORANGE_DEV'} or &General::IpInSubnet($string2,$ethsettings{'ORANGE_NETADDRESS'},$ethsettings{'ORANGE_NETMASK'}) )){
return "<font color='".${Header::colourorange}."'>".$string."</font>";
} else {
return $string;