]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
web: Read ethernet settings file only once in headers
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 23 Mar 2024 15:42:16 +0000 (16:42 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 23 Mar 2024 15:45:52 +0000 (16:45 +0100)
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 <michael.tremer@ipfire.org>
config/cfgroot/general-functions.pl
config/cfgroot/header.pl
config/cfgroot/network-functions.pl

index c6d68bcea3226cf19d28567d8808b31764b1952c..0a9ab6b7021d96f8348fdd4b404bf2c891b823a0 100644 (file)
@@ -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 "");
index 7aaf6f94fc43bfa7dbdd28a412e5d74dd2db89ee..97d32674c4954b170439ee94232bb679d2b9587f 100644 (file)
@@ -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 "<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 &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 "<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'} ){
+       } elsif (  $string =~ "ppp0" or $string =~ $Network::ethernet{'RED_DEV'} or $string =~ "0.0.0.0" or $string =~ $Network::ethernet{'RED_ADDRESS'} ){
                return "<font color='".${Header::colourred}."'>".$string."</font>";
-       } 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 "<font color='".${Header::colourblue}."'>".$string."</font>";
-       } 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 "<font color='".${Header::colourorange}."'>".$string."</font>";
        } else {
                return $string;
index 507e85c2398d746faefffa4ec3a3b01bff3c24a2..221239e5c963651af8d3b2190f14f6a13353ec4b 100644 (file)
@@ -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"]));