fwhosts.cgi: properly fetch configured IPsec N2N subnets

Message ID ac8e8aff-b4fb-3392-8d25-c85f9d286ca2@ipfire.org
State Accepted
Commit 6f36132e6890f4a423de2a0df14ccf3c720110c1
Headers
Series fwhosts.cgi: properly fetch configured IPsec N2N subnets |

Commit Message

Peter Müller April 22, 2021, 8:20 p.m. UTC
  Previously, the getcolor() function did not correctly process IPsec
N2N connections with more than one remote network configured, resulting
in networks mistakenly marked as being part of a VPN connection, or vice
versa.

Fixes: #11235

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
---
 html/cgi-bin/fwhosts.cgi | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
  

Comments

Stefan Schantl July 15, 2021, 3:49 p.m. UTC | #1
Hello Peter,

I've reviewed and tested your patch and it seems to fix the issue.

Thanks for working and submitting it.

Best regards,

-Stefan

Acked-by: Stefan Schantl <stefan.schantl@ipfire.org>
> Previously, the getcolor() function did not correctly process IPsec
> N2N connections with more than one remote network configured,
> resulting
> in networks mistakenly marked as being part of a VPN connection, or
> vice
> versa.
> 
> Fixes: #11235
> 
> Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
> ---
>  html/cgi-bin/fwhosts.cgi | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/html/cgi-bin/fwhosts.cgi b/html/cgi-bin/fwhosts.cgi
> index 84b018459..648fc7c8e 100644
> --- a/html/cgi-bin/fwhosts.cgi
> +++ b/html/cgi-bin/fwhosts.cgi
> @@ -1974,11 +1974,13 @@ sub getcolor
>                 #Check if IP is part of a IPsec N2N network
>                 foreach my $key (sort keys %ipsecconf){
>                         if ($ipsecconf{$key}[11]){
> -                               my ($a,$b) =
> split("/",$ipsecconf{$key}[11]);
> -                               $b=&General::iporsubtodec($b);
> -                               if
> (&General::IpInSubnet($sip,$a,$b)){
> -                                       $tdcolor="<font style='color:
> $Header::colourvpn;'>$c</font>";
> -                                       return $tdcolor;
> +                               foreach my $ipsecsubitem (split(/\|/,
> $ipsecconf{$key}[11])) {
> +                                       my ($a,$b) =
> split("/",$ipsecsubitem);
> +                                       $b=&General::iporsubtodec($b)
> ;
> +                                       if
> (&General::IpInSubnet($sip,$a,$b)){
> +                                               $tdcolor="<font
> style='color: $Header::colourvpn;'>$c</font>";
> +                                               return $tdcolor;
> +                                       }
>                                 }
>                         }
>                 }
  
Michael Tremer July 15, 2021, 3:50 p.m. UTC | #2
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>

> On 22 Apr 2021, at 21:20, Peter Müller <peter.mueller@ipfire.org> wrote:
> 
> Previously, the getcolor() function did not correctly process IPsec
> N2N connections with more than one remote network configured, resulting
> in networks mistakenly marked as being part of a VPN connection, or vice
> versa.
> 
> Fixes: #11235
> 
> Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
> ---
> html/cgi-bin/fwhosts.cgi | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/html/cgi-bin/fwhosts.cgi b/html/cgi-bin/fwhosts.cgi
> index 84b018459..648fc7c8e 100644
> --- a/html/cgi-bin/fwhosts.cgi
> +++ b/html/cgi-bin/fwhosts.cgi
> @@ -1974,11 +1974,13 @@ sub getcolor
> 		#Check if IP is part of a IPsec N2N network
> 		foreach my $key (sort keys %ipsecconf){
> 			if ($ipsecconf{$key}[11]){
> -				my ($a,$b) = split("/",$ipsecconf{$key}[11]);
> -				$b=&General::iporsubtodec($b);
> -				if (&General::IpInSubnet($sip,$a,$b)){
> -					$tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
> -					return $tdcolor;
> +				foreach my $ipsecsubitem (split(/\|/, $ipsecconf{$key}[11])) {
> +					my ($a,$b) = split("/",$ipsecsubitem);
> +					$b=&General::iporsubtodec($b);
> +					if (&General::IpInSubnet($sip,$a,$b)){
> +						$tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
> +						return $tdcolor;
> +					}
> 				}
> 			}
> 		}
> -- 
> 2.26.2
  

Patch

diff --git a/html/cgi-bin/fwhosts.cgi b/html/cgi-bin/fwhosts.cgi
index 84b018459..648fc7c8e 100644
--- a/html/cgi-bin/fwhosts.cgi
+++ b/html/cgi-bin/fwhosts.cgi
@@ -1974,11 +1974,13 @@  sub getcolor
 		#Check if IP is part of a IPsec N2N network
 		foreach my $key (sort keys %ipsecconf){
 			if ($ipsecconf{$key}[11]){
-				my ($a,$b) = split("/",$ipsecconf{$key}[11]);
-				$b=&General::iporsubtodec($b);
-				if (&General::IpInSubnet($sip,$a,$b)){
-					$tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
-					return $tdcolor;
+				foreach my $ipsecsubitem (split(/\|/, $ipsecconf{$key}[11])) {
+					my ($a,$b) = split("/",$ipsecsubitem);
+					$b=&General::iporsubtodec($b);
+					if (&General::IpInSubnet($sip,$a,$b)){
+						$tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
+						return $tdcolor;
+					}
 				}
 			}
 		}