From d826f3d3290da05eeac2fad0ed6e6e5b249fa6d5 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 23 Mar 2024 16:42:16 +0100 Subject: [PATCH] web: Read ethernet settings file only once in headers The web UI is rather slow and one of the reasons for that is that we are reading the same files over and over again... Signed-off-by: Michael Tremer --- config/cfgroot/general-functions.pl | 15 ++++----------- config/cfgroot/header.pl | 24 ++++++++++-------------- config/cfgroot/network-functions.pl | 11 ++++++----- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index c6d68bcea..0a9ab6b70 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -115,11 +115,9 @@ sub log } sub setup_default_networks { - my %netsettings=(); + my %netsettings = %Network::ethernet; my $defaultNetworks = shift; - &readhash("/var/ipfire/ethernet/settings", \%netsettings); - # Get current defined networks (Red, Green, Blue, Orange) $defaultNetworks->{$Lang::tr{'fwhost any'}}{'IPT'} = "0.0.0.0/0.0.0.0"; $defaultNetworks->{$Lang::tr{'fwhost any'}}{'NAME'} = "ALL"; @@ -579,11 +577,10 @@ sub checksubnets sub check_net_internal_range{ my $network=shift; my ($ip,$cidr)=split(/\//,$network); - my %ownnet=(); + my %ownnet = %Network::ethernet; my $errormessage; $cidr=&iporsubtocidr($cidr); #check if we use one of ipfire's networks (green,orange,blue) - &readhash("${General::swroot}/ethernet/settings", \%ownnet); if (($ownnet{'GREEN_NETADDRESS'} ne '' && $ownnet{'GREEN_NETADDRESS'} ne '0.0.0.0') && &IpInSubnet($ip,$ownnet{'GREEN_NETADDRESS'},&iporsubtodec($ownnet{'GREEN_NETMASK'}))){ $errormessage=$Lang::tr{'ccd err green'};return $errormessage;} if (($ownnet{'ORANGE_NETADDRESS'} ne '' && $ownnet{'ORANGE_NETADDRESS'} ne '0.0.0.0') && &IpInSubnet($ip,$ownnet{'ORANGE_NETADDRESS'},&iporsubtodec($ownnet{'ORANGE_NETMASK'}))){ $errormessage=$Lang::tr{'ccd err orange'};return $errormessage;} if (($ownnet{'BLUE_NETADDRESS'} ne '' && $ownnet{'BLUE_NETADDRESS'} ne '0.0.0.0') && &IpInSubnet($ip,$ownnet{'BLUE_NETADDRESS'},&iporsubtodec($ownnet{'BLUE_NETMASK'}))){ $errormessage=$Lang::tr{'ccd err blue'};return $errormessage;} @@ -593,11 +590,10 @@ sub check_net_internal_range{ sub check_net_internal_exact{ my $network=shift; my ($ip,$cidr)=split(/\//,$network); - my %ownnet=(); + my %ownnet = %Network::ethernet; my $errormessage; $cidr=&iporsubtocidr($cidr); #check if we use one of ipfire's networks (green,orange,blue) - &readhash("${General::swroot}/ethernet/settings", \%ownnet); if (($ownnet{'GREEN_NETADDRESS'} ne '' && $ownnet{'GREEN_NETADDRESS'} ne '0.0.0.0') && &Network::network_equal("$ownnet{'GREEN_NETADDRESS'}/$ownnet{'GREEN_NETMASK'}", $network)){ $errormessage=$Lang::tr{'ccd err green'};return $errormessage;} if (($ownnet{'ORANGE_NETADDRESS'} ne '' && $ownnet{'ORANGE_NETADDRESS'} ne '0.0.0.0') && &Network::network_equal("$ownnet{'ORANGE_NETADDRESS'}/$ownnet{'ORANGE_NETMASK'}", $network)){ $errormessage=$Lang::tr{'ccd err orange'};return $errormessage;} if (($ownnet{'BLUE_NETADDRESS'} ne '' && $ownnet{'BLUE_NETADDRESS'} ne '0.0.0.0') && &Network::network_equal("$ownnet{'BLUE_NETADDRESS'}/$ownnet{'BLUE_NETMASK'}", $network)){ $errormessage=$Lang::tr{'ccd err blue'};return $errormessage;} @@ -1024,11 +1020,8 @@ sub MakeUserAgent() { sub RedIsWireless() { # This function checks if a network device is a wireless device. - my %settings = (); - &readhash("${General::swroot}/ethernet/settings", \%settings); - # Find the name of the network device. - my $device = $settings{'RED_DEV'}; + my $device = $Network::ethernet{'RED_DEV'}; # Exit, if no device is configured. return 0 if ($device eq ""); diff --git a/config/cfgroot/header.pl b/config/cfgroot/header.pl index 7aaf6f94f..97d32674c 100644 --- a/config/cfgroot/header.pl +++ b/config/cfgroot/header.pl @@ -88,7 +88,6 @@ END my %menuhash = (); my $menu = \%menuhash; %settings = (); -%ethsettings = (); %pppsettings = (); my @URI = split('\?', $ENV{'REQUEST_URI'}); @@ -101,7 +100,6 @@ if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') { ### Initialize environment &General::readhash("${swroot}/main/settings", \%settings); -&General::readhash("${swroot}/ethernet/settings", \%ethsettings); &General::readhash("${swroot}/ppp/settings", \%pppsettings); $hostname = $settings{'HOSTNAME'}; $hostnameintitle = 0; @@ -379,7 +377,7 @@ sub closebox { } sub green_used() { - if ($ethsettings{'GREEN_DEV'} && $ethsettings{'GREEN_DEV'} ne "") { + if ($Network::ethernet{'GREEN_DEV'} && $Network::ethernet{'GREEN_DEV'} ne "") { return 1; } @@ -387,14 +385,14 @@ sub green_used() { } sub orange_used () { - if ($ethsettings{'CONFIG_TYPE'} =~ /^[24]$/) { + if ($Network::ethernet{'CONFIG_TYPE'} =~ /^[24]$/) { return 1; } return 0; } sub blue_used () { - if ($ethsettings{'CONFIG_TYPE'} =~ /^[34]$/) { + if ($Network::ethernet{'CONFIG_TYPE'} =~ /^[34]$/) { return 1; } return 0; @@ -432,7 +430,7 @@ sub genmenu { if (! blue_used()) { $menu->{'05.firewall'}{'subMenu'}->{'60.wireless'}{'enabled'} = 0; } - if ( $ethsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) { + if ( $Network::ethernet{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $Network::ethernet{'RED_TYPE'} eq 'STATIC' ) { $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1; } @@ -440,7 +438,7 @@ sub genmenu { $menu->{'01.system'}{'subMenu'}->{'21.wlan'}{'enabled'} = 1; } - if ( $ethsettings{'RED_TYPE'} eq "PPPOE" && $pppsettings{'MONPORT'} ne "" ) { + if ( $Network::ethernet{'RED_TYPE'} eq "PPPOE" && $pppsettings{'MONPORT'} ne "" ) { $menu->{'02.status'}{'subMenu'}->{'74.modem-status'}{'enabled'} = 1; } @@ -599,15 +597,13 @@ sub cleanhtml { sub connectionstatus { my %pppsettings = (); - my %netsettings = (); my $iface=''; $pppsettings{'PROFILENAME'} = 'None'; &General::readhash("${General::swroot}/ppp/settings", \%pppsettings); - &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); my $profileused=''; - unless ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) { + unless ($Network::ethernet{'RED_TYPE'} =~ /^(DHCP|STATIC)$/) { $profileused="- $pppsettings{'PROFILENAME'}"; } @@ -816,13 +812,13 @@ sub colorize { return "".$string.""; } elsif ( $string =~ "lo" or $string =~ "127.0.0.0" ){ return "".$string.""; - } elsif ( $string =~ $ethsettings{'GREEN_DEV'} or &General::IpInSubnet($string2,$ethsettings{'GREEN_NETADDRESS'},$ethsettings{'GREEN_NETMASK'}) ){ + } elsif ( $string =~ $Network::ethernet{'GREEN_DEV'} or &General::IpInSubnet($string2,$Network::ethernet{'GREEN_NETADDRESS'},$Network::ethernet{'GREEN_NETMASK'}) ){ return "".$string.""; - } elsif ( $string =~ "ppp0" or $string =~ $ethsettings{'RED_DEV'} or $string =~ "0.0.0.0" or $string =~ $ethsettings{'RED_ADDRESS'} ){ + } elsif ( $string =~ "ppp0" or $string =~ $Network::ethernet{'RED_DEV'} or $string =~ "0.0.0.0" or $string =~ $Network::ethernet{'RED_ADDRESS'} ){ return "".$string.""; - } elsif ( $ethsettings{'CONFIG_TYPE'}>1 and ( $string =~ $ethsettings{'BLUE_DEV'} or &General::IpInSubnet($string2,$ethsettings{'BLUE_NETADDRESS'},$ethsettings{'BLUE_NETMASK'}) )){ + } elsif ( $Network::ethernet{'CONFIG_TYPE'}>1 and ( $string =~ $Network::ethernet{'BLUE_DEV'} or &General::IpInSubnet($string2,$Network::ethernet{'BLUE_NETADDRESS'},$Network::ethernet{'BLUE_NETMASK'}) )){ return "".$string.""; - } elsif ( $ethsettings{'CONFIG_TYPE'}>2 and ( $string =~ $ethsettings{'ORANGE_DEV'} or &General::IpInSubnet($string2,$ethsettings{'ORANGE_NETADDRESS'},$ethsettings{'ORANGE_NETMASK'}) )){ + } elsif ( $Network::ethernet{'CONFIG_TYPE'}>2 and ( $string =~ $Network::ethernet{'ORANGE_DEV'} or &General::IpInSubnet($string2,$Network::ethernet{'ORANGE_NETADDRESS'},$Network::ethernet{'ORANGE_NETMASK'}) )){ return "".$string.""; } else { return $string; diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl index 507e85c23..221239e5c 100644 --- a/config/cfgroot/network-functions.pl +++ b/config/cfgroot/network-functions.pl @@ -29,8 +29,9 @@ use experimental 'smartmatch'; use Socket; # System ethernet configuration -our %ethernet_settings = (); -&General::readhash("${General::swroot}/ethernet/settings", \%ethernet_settings); +our %ethernet = (); + +&General::readhash("${General::swroot}/ethernet/settings", \%ethernet); # List of all possible network zones that can be configured our @known_network_zones = ("red", "green", "orange", "blue"); @@ -593,7 +594,7 @@ sub get_intf_by_address($) { # sub get_available_network_zones () { # Obtain the configuration type from the netsettings hash. - my $config_type = $ethernet_settings{'CONFIG_TYPE'}; + my $config_type = $ethernet{'CONFIG_TYPE'}; # Hash which contains the conversation from the config mode # to the existing network interface names. They are stored like @@ -639,8 +640,8 @@ sub is_zone_available() { # sub is_red_mode_ip() { # Obtain the settings from the netsettings hash - my $config_type = $ethernet_settings{'CONFIG_TYPE'}; - my $red_type = $ethernet_settings{'RED_TYPE'}; + my $config_type = $ethernet{'CONFIG_TYPE'}; + my $red_type = $ethernet{'RED_TYPE'}; # RED must be a network device (configuration 1-4) with dynamic or static IP return (($config_type ~~ [1..4]) && ($red_type ~~ ["DHCP", "STATIC"])); -- 2.39.5