[2/4] connections.cgi: Ignore empty interfaces

Message ID 20241206164417.3840426-2-michael.tremer@ipfire.org
State New
Headers
Series [1/4] connections.cgi: Fix colour of destination country |

Commit Message

Michael Tremer Dec. 6, 2024, 4:44 p.m. UTC
  Parsing any custom routes for any custom interfaces was broken so that
arbitrary routes were imported when not all interfaces were in use.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 html/cgi-bin/connections.cgi | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Bernhard Bitsch Dec. 7, 2024, 11:56 p.m. UTC | #1
If %interfaces contains defined interfaces only, this is not necessary.

For blue and orange interfaces this can be done by

my %interfaces = (
	$settings{'GREEN_DEV'}  => ${Header::colourgreen},

	# IPsec
	"gre[0-9]+"             => ${Header::colourvpn},
	"vti[0-9]+"             => ${Header::colourvpn},

	# OpenVPN
	"tun[0-9]+"             => ${Header::colourovpn},
);

# BLUE interface
if ($settings{BLUE_DEV} ne "") {
	$interfaces{$settings{'BLUE_DEV'} } = ${Header::colourblue};
}

#ORANGE interface
if ($settings{ORANGE_DEV} ne "") {
	$interfaces{$settings{'ORANGE_DEV'} }= ${Header::colourorange};
}

For VPN this has to be adapted.

Reviewed-by-: Bernhard Bitsch <bbitsch@ipfire.org>

Am 06.12.2024 um 17:44 schrieb Michael Tremer:
> Parsing any custom routes for any custom interfaces was broken so that
> arbitrary routes were imported when not all interfaces were in use.
> 
> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
> ---
>   html/cgi-bin/connections.cgi | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/html/cgi-bin/connections.cgi b/html/cgi-bin/connections.cgi
> index af375effe..705118576 100644
> --- a/html/cgi-bin/connections.cgi
> +++ b/html/cgi-bin/connections.cgi
> @@ -89,6 +89,9 @@ my @routes = &General::system_output("ip", "route", "show");
>   
>   # Find all routes
>   foreach my $intf (keys %interfaces) {
> +	# Skip empty interfaces
> +	next if ($intf eq "");
> +
>   	foreach my $route (grep(/dev ${intf}/, @routes)) {
>   		if ($route =~ m/^(\d+\.\d+\.\d+\.\d+\/\d+)/) {
>   			$networks{$1} = $interfaces{$intf};
  
Michael Tremer Dec. 9, 2024, 11:30 a.m. UTC | #2
This is also an option.

I found throwing away what is empty in the loop was shorter to write.

-Michael

> On 7 Dec 2024, at 23:56, Bernhard Bitsch <bbitsch@ipfire.org> wrote:
> 
> If %interfaces contains defined interfaces only, this is not necessary.
> 
> For blue and orange interfaces this can be done by
> 
> my %interfaces = (
> $settings{'GREEN_DEV'}  => ${Header::colourgreen},
> 
> # IPsec
> "gre[0-9]+"             => ${Header::colourvpn},
> "vti[0-9]+"             => ${Header::colourvpn},
> 
> # OpenVPN
> "tun[0-9]+"             => ${Header::colourovpn},
> );
> 
> # BLUE interface
> if ($settings{BLUE_DEV} ne "") {
> $interfaces{$settings{'BLUE_DEV'} } = ${Header::colourblue};
> }
> 
> #ORANGE interface
> if ($settings{ORANGE_DEV} ne "") {
> $interfaces{$settings{'ORANGE_DEV'} }= ${Header::colourorange};
> }
> 
> For VPN this has to be adapted.
> 
> Reviewed-by-: Bernhard Bitsch <bbitsch@ipfire.org>
> 
> Am 06.12.2024 um 17:44 schrieb Michael Tremer:
>> Parsing any custom routes for any custom interfaces was broken so that
>> arbitrary routes were imported when not all interfaces were in use.
>> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
>> ---
>>  html/cgi-bin/connections.cgi | 3 +++
>>  1 file changed, 3 insertions(+)
>> diff --git a/html/cgi-bin/connections.cgi b/html/cgi-bin/connections.cgi
>> index af375effe..705118576 100644
>> --- a/html/cgi-bin/connections.cgi
>> +++ b/html/cgi-bin/connections.cgi
>> @@ -89,6 +89,9 @@ my @routes = &General::system_output("ip", "route", "show");
>>    # Find all routes
>>  foreach my $intf (keys %interfaces) {
>> + # Skip empty interfaces
>> + next if ($intf eq "");
>> +
>>   foreach my $route (grep(/dev ${intf}/, @routes)) {
>>   if ($route =~ m/^(\d+\.\d+\.\d+\.\d+\/\d+)/) {
>>   $networks{$1} = $interfaces{$intf};
>
  

Patch

diff --git a/html/cgi-bin/connections.cgi b/html/cgi-bin/connections.cgi
index af375effe..705118576 100644
--- a/html/cgi-bin/connections.cgi
+++ b/html/cgi-bin/connections.cgi
@@ -89,6 +89,9 @@  my @routes = &General::system_output("ip", "route", "show");
 
 # Find all routes
 foreach my $intf (keys %interfaces) {
+	# Skip empty interfaces
+	next if ($intf eq "");
+
 	foreach my $route (grep(/dev ${intf}/, @routes)) {
 		if ($route =~ m/^(\d+\.\d+\.\d+\.\d+\/\d+)/) {
 			$networks{$1} = $interfaces{$intf};