ids-functions.pl: Add function to get the available network zones

The get_available_network_zones() function uses the /var/ipfire/ethernet/settings
file and translates the configured mode into an array, which contains the names
of the configured network zones.

The array will be returned and easily can be used to loop over this list of
available network zones and perform any kind of actions in other scripts.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
This commit is contained in:
Stefan Schantl
2018-08-04 16:48:27 +02:00
parent ab114c276b
commit 1cae702c22

View File

@@ -254,4 +254,40 @@ sub _store_error_message ($) {
close (ERRORFILE);
}
#
## Function to get a list of all available network zones.
#
sub get_available_network_zones () {
# Get netsettings.
my %netsettings = ();
&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
# Obtain the configuration type from the netsettings hash.
my $config_type = $netsettings{'CONFIG_TYPE'};
# Hash which contains the conversation from the config mode
# to the existing network interface names. They are stored like
# an array.
#
# Mode "0" red is a modem and green
# Mode "1" red is a netdev and green
# Mode "2" red, green and orange
# Mode "3" red, green and blue
# Mode "4" red, green, blue, orange
my %config_type_to_interfaces = (
"0" => [ "red", "green" ],
"1" => [ "red", "green" ],
"2" => [ "red", "green", "orange" ],
"3" => [ "red", "green", "blue" ],
"4" => [ "red", "green", "blue", "orange" ]
);
# Obtain and dereference the corresponding network interaces based on the read
# network config type.
my @network_zones = @{ $config_type_to_interfaces{$config_type} };
# Return them.
return @network_zones;
}
1;