menu: Fix warnings, clean code

Message ID 20220420133234.1588-1-hofmann@leo-andres.de
State Accepted
Commit c13060fd4cda278ea79dd8d547291dbbc31840c1
Headers
Series menu: Fix warnings, clean code |

Commit Message

Leo-Andres Hofmann April 20, 2022, 1:32 p.m. UTC
  This patch adds default values and removes a missing translation
to fix "uninitialized value" and "odd number of elements" warnings.

Removes function calls from functions.pl that have already been
handled by the header before it is loaded by eval().

Signed-off-by: Leo-Andres Hofmann <hofmann@leo-andres.de>
---
 config/cfgroot/header.pl                     |  4 +++-
 config/menu/20-status.menu                   |  4 ++--
 config/menu/30-network.menu                  |  2 +-
 html/html/themes/ipfire/include/functions.pl | 16 +++++-----------
 langs/de/cgi-bin/de.pl                       |  1 -
 langs/fr/cgi-bin/fr.pl                       |  1 -
 6 files changed, 11 insertions(+), 17 deletions(-)
  

Comments

Bernhard Bitsch April 20, 2022, 1:42 p.m. UTC | #1
Reviewed-by: Bernhard Bitsch <bbitsch@ipfire.org>

Am 20.04.2022 um 15:32 schrieb Leo-Andres Hofmann:
> This patch adds default values and removes a missing translation
> to fix "uninitialized value" and "odd number of elements" warnings.
> 
> Removes function calls from functions.pl that have already been
> handled by the header before it is loaded by eval().
> 
> Signed-off-by: Leo-Andres Hofmann <hofmann@leo-andres.de>
> ---
>   config/cfgroot/header.pl                     |  4 +++-
>   config/menu/20-status.menu                   |  4 ++--
>   config/menu/30-network.menu                  |  2 +-
>   html/html/themes/ipfire/include/functions.pl | 16 +++++-----------
>   langs/de/cgi-bin/de.pl                       |  1 -
>   langs/fr/cgi-bin/fr.pl                       |  1 -
>   6 files changed, 11 insertions(+), 17 deletions(-)
> 
> diff --git a/config/cfgroot/header.pl b/config/cfgroot/header.pl
> index 5ddea348e..65459cc92 100644
> --- a/config/cfgroot/header.pl
> +++ b/config/cfgroot/header.pl
> @@ -46,7 +46,7 @@ my $menu = \%menuhash;
>   %settings = ();
>   %ethsettings = ();
>   %pppsettings = ();
> -@URI = ();
> +my @URI = split('\?', $ENV{'REQUEST_URI'});
>   
>   ### Make sure this is an SSL request
>   if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') {
> @@ -573,3 +573,5 @@ sub get_manualpage_url() {
>   	# No manual page configured, return nothing
>   	return;
>   }
> +
> +1; # End of package "Header"
> diff --git a/config/menu/20-status.menu b/config/menu/20-status.menu
> index 2bcf0d5e8..f969a3b0b 100644
> --- a/config/menu/20-status.menu
> +++ b/config/menu/20-status.menu
> @@ -49,7 +49,7 @@
>   	$substatus->{'54.networkovpnsrv'} = {
>   				'caption' => "$Lang::tr{'vpn statistic n2n'}",
>   				'uri' => '/cgi-bin/netovpnsrv.cgi',
> -				'title' => "$Lang::tr{'vpn statistics n2n'}",
> +				'title' => "$Lang::tr{'vpn statistic n2n'}",
>   				'enabled' => 1,
>   			  };
>       $substatus->{'60.hardwaregraphs'} = {
> @@ -90,7 +90,7 @@
>       $substatus->{'75.atm-status'} = {'caption' => 'Atm-status',
>   				  'uri' => '/cgi-bin/atm-status.cgi',
>   				  'title' => 'Atm-status',
> -				  'enabled' => `find /sys/class/atm/*/device 2>/dev/null`,
> +				  'enabled' => (`find /sys/class/atm/*/device 2>/dev/null` ? 1 : 0),
>   				  };
>       $substatus->{'76.mdstat'} = {'caption' => 'Mdstat',
>   				  'uri' => '/cgi-bin/mdstat.cgi',
> diff --git a/config/menu/30-network.menu b/config/menu/30-network.menu
> index 19571a870..4ef537ed4 100644
> --- a/config/menu/30-network.menu
> +++ b/config/menu/30-network.menu
> @@ -67,7 +67,7 @@
>   				  'caption' => $Lang::tr{'aliases'},
>   				  'uri' => '/cgi-bin/aliases.cgi',
>   				  'title' => "$Lang::tr{'aliases'}",
> -				  'enabled' => `grep "RED_TYPE=STATIC" /var/ipfire/ethernet/settings`,
> +				  'enabled' => (`grep "RED_TYPE=STATIC" /var/ipfire/ethernet/settings` ? 1 : 0),
>   				  };
>       $subnetwork->{'80.macadressmenu'} = {
>   				  'caption' => $Lang::tr{'mac address menu'},
> diff --git a/html/html/themes/ipfire/include/functions.pl b/html/html/themes/ipfire/include/functions.pl
> index d74c962e4..f2b8e9925 100644
> --- a/html/html/themes/ipfire/include/functions.pl
> +++ b/html/html/themes/ipfire/include/functions.pl
> @@ -31,8 +31,6 @@
>   # IPFire default theme.                                                       #
>   ###############################################################################
>   
> -require "${General::swroot}/lang.pl";
> -
>   ###############################################################################
>   #
>   # print menu html elements for submenu entries
> @@ -101,20 +99,15 @@ sub openpage {
>   	my $title = shift;
>   	my $boh = shift;
>   	my $extrahead = shift;
> -	my $suppressMenu = shift;
> +	my $suppressMenu = shift // 0;
>   	my @tmp = split(/\./, basename($0));
>   	my $scriptName = @tmp[0];
>   
> -	@URI=split ('\?',  $ENV{'REQUEST_URI'} );
> -	&General::readhash("${swroot}/main/settings", \%settings);
> -	&genmenu();
> -
>   	my $headline = "IPFire";
>   	if (($settings{'WINDOWWITHHOSTNAME'} eq 'on') || ($settings{'WINDOWWITHHOSTNAME'} eq '')) {
>   		$headline =  "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'}";
>   	}
>   
> -
>   print <<END;
>   <!DOCTYPE html>
>   <html>
> @@ -165,7 +158,10 @@ print <<END
>   END
>   ;
>   
> -&showmenu() if ($suppressMenu != 1);
> +unless($suppressMenu) {
> +	&genmenu();
> +	&showmenu();
> +}
>   
>   print <<END
>   	<div class="bigbox fixed">
> @@ -270,5 +266,3 @@ sub openbox {
>   sub closebox {
>   	print "</div>";
>   }
> -
> -1;
> diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl
> index 6094c191a..1145745e0 100644
> --- a/langs/de/cgi-bin/de.pl
> +++ b/langs/de/cgi-bin/de.pl
> @@ -2874,7 +2874,6 @@
>   'vpn start action start' => 'Immer An',
>   'vpn statistic n2n' => 'OpenVPN: Netz-zu-Netz-Statistik',
>   'vpn statistic rw' => 'OpenVPN: Roadwarrior-Statistik',
> -'vpn statistics n2n' => 'OpenVPN: Netz-zu-Netz-Statistiken',
>   'vpn subjectaltname' => 'SubjectAlternativeName',
>   'vpn subjectaltname missing' => 'SubjectAlternativeName darf nicht leer bleiben.',
>   'vpn wait' => 'WARTE',
> diff --git a/langs/fr/cgi-bin/fr.pl b/langs/fr/cgi-bin/fr.pl
> index 03fc754df..23c01ddb8 100644
> --- a/langs/fr/cgi-bin/fr.pl
> +++ b/langs/fr/cgi-bin/fr.pl
> @@ -2949,7 +2949,6 @@
>   'vpn start action start' => 'Toujours démarré',
>   'vpn statistic n2n' => 'OpenVPN (site-à-site)',
>   'vpn statistic rw' => 'OpenVPN (client nomade)',
> -'vpn statistics n2n' => 'OpenVPN (site-à-site)',
>   'vpn subjectaltname' => 'Nom de l\'objet',
>   'vpn subjectaltname missing' => 'Le nom de l\'objet ne peut être vide.',
>   'vpn wait' => 'ATTENTE',
  

Patch

diff --git a/config/cfgroot/header.pl b/config/cfgroot/header.pl
index 5ddea348e..65459cc92 100644
--- a/config/cfgroot/header.pl
+++ b/config/cfgroot/header.pl
@@ -46,7 +46,7 @@  my $menu = \%menuhash;
 %settings = ();
 %ethsettings = ();
 %pppsettings = ();
-@URI = ();
+my @URI = split('\?', $ENV{'REQUEST_URI'});
 
 ### Make sure this is an SSL request
 if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') {
@@ -573,3 +573,5 @@  sub get_manualpage_url() {
 	# No manual page configured, return nothing
 	return;
 }
+
+1; # End of package "Header"
diff --git a/config/menu/20-status.menu b/config/menu/20-status.menu
index 2bcf0d5e8..f969a3b0b 100644
--- a/config/menu/20-status.menu
+++ b/config/menu/20-status.menu
@@ -49,7 +49,7 @@ 
 	$substatus->{'54.networkovpnsrv'} = {
 				'caption' => "$Lang::tr{'vpn statistic n2n'}",
 				'uri' => '/cgi-bin/netovpnsrv.cgi',
-				'title' => "$Lang::tr{'vpn statistics n2n'}",
+				'title' => "$Lang::tr{'vpn statistic n2n'}",
 				'enabled' => 1,
 			  };
     $substatus->{'60.hardwaregraphs'} = {
@@ -90,7 +90,7 @@ 
     $substatus->{'75.atm-status'} = {'caption' => 'Atm-status',
 				  'uri' => '/cgi-bin/atm-status.cgi',
 				  'title' => 'Atm-status',
-				  'enabled' => `find /sys/class/atm/*/device 2>/dev/null`,
+				  'enabled' => (`find /sys/class/atm/*/device 2>/dev/null` ? 1 : 0),
 				  };
     $substatus->{'76.mdstat'} = {'caption' => 'Mdstat',
 				  'uri' => '/cgi-bin/mdstat.cgi',
diff --git a/config/menu/30-network.menu b/config/menu/30-network.menu
index 19571a870..4ef537ed4 100644
--- a/config/menu/30-network.menu
+++ b/config/menu/30-network.menu
@@ -67,7 +67,7 @@ 
 				  'caption' => $Lang::tr{'aliases'},
 				  'uri' => '/cgi-bin/aliases.cgi',
 				  'title' => "$Lang::tr{'aliases'}",
-				  'enabled' => `grep "RED_TYPE=STATIC" /var/ipfire/ethernet/settings`,
+				  'enabled' => (`grep "RED_TYPE=STATIC" /var/ipfire/ethernet/settings` ? 1 : 0),
 				  };
     $subnetwork->{'80.macadressmenu'} = {
 				  'caption' => $Lang::tr{'mac address menu'},
diff --git a/html/html/themes/ipfire/include/functions.pl b/html/html/themes/ipfire/include/functions.pl
index d74c962e4..f2b8e9925 100644
--- a/html/html/themes/ipfire/include/functions.pl
+++ b/html/html/themes/ipfire/include/functions.pl
@@ -31,8 +31,6 @@ 
 # IPFire default theme.                                                       #
 ###############################################################################
 
-require "${General::swroot}/lang.pl";
-
 ###############################################################################
 #
 # print menu html elements for submenu entries
@@ -101,20 +99,15 @@  sub openpage {
 	my $title = shift;
 	my $boh = shift;
 	my $extrahead = shift;
-	my $suppressMenu = shift;
+	my $suppressMenu = shift // 0;
 	my @tmp = split(/\./, basename($0));
 	my $scriptName = @tmp[0];
 
-	@URI=split ('\?',  $ENV{'REQUEST_URI'} );
-	&General::readhash("${swroot}/main/settings", \%settings);
-	&genmenu();
-
 	my $headline = "IPFire";
 	if (($settings{'WINDOWWITHHOSTNAME'} eq 'on') || ($settings{'WINDOWWITHHOSTNAME'} eq '')) {
 		$headline =  "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'}";
 	}
 
-
 print <<END;
 <!DOCTYPE html>
 <html>
@@ -165,7 +158,10 @@  print <<END
 END
 ;
 
-&showmenu() if ($suppressMenu != 1);
+unless($suppressMenu) {
+	&genmenu();
+	&showmenu();
+}
 
 print <<END
 	<div class="bigbox fixed">
@@ -270,5 +266,3 @@  sub openbox {
 sub closebox {
 	print "</div>";
 }
-
-1;
diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl
index 6094c191a..1145745e0 100644
--- a/langs/de/cgi-bin/de.pl
+++ b/langs/de/cgi-bin/de.pl
@@ -2874,7 +2874,6 @@ 
 'vpn start action start' => 'Immer An',
 'vpn statistic n2n' => 'OpenVPN: Netz-zu-Netz-Statistik',
 'vpn statistic rw' => 'OpenVPN: Roadwarrior-Statistik',
-'vpn statistics n2n' => 'OpenVPN: Netz-zu-Netz-Statistiken',
 'vpn subjectaltname' => 'SubjectAlternativeName',
 'vpn subjectaltname missing' => 'SubjectAlternativeName darf nicht leer bleiben.',
 'vpn wait' => 'WARTE',
diff --git a/langs/fr/cgi-bin/fr.pl b/langs/fr/cgi-bin/fr.pl
index 03fc754df..23c01ddb8 100644
--- a/langs/fr/cgi-bin/fr.pl
+++ b/langs/fr/cgi-bin/fr.pl
@@ -2949,7 +2949,6 @@ 
 'vpn start action start' => 'Toujours démarré',
 'vpn statistic n2n' => 'OpenVPN (site-à-site)',
 'vpn statistic rw' => 'OpenVPN (client nomade)',
-'vpn statistics n2n' => 'OpenVPN (site-à-site)',
 'vpn subjectaltname' => 'Nom de l\'objet',
 'vpn subjectaltname missing' => 'Le nom de l\'objet ne peut être vide.',
 'vpn wait' => 'ATTENTE',