mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-16 14:03:00 +02:00
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 <michael.tremer@ipfire.org>
This commit is contained in:
@@ -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;}
|
||||
@@ -1039,11 +1035,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 "");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -613,15 +611,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'}";
|
||||
}
|
||||
|
||||
@@ -830,13 +826,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;
|
||||
|
||||
@@ -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"]));
|
||||
|
||||
Reference in New Issue
Block a user