mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-28 11:43:25 +02:00
Refactor "get_available_network_zones", move to network-functions.pl
This function nicely translates the ethernet/settings "CONFIG_TYPE" into a list of available zones. Therefore it should be more accessible! Signed-off-by: Leo-Andres Hofmann <hofmann@leo-andres.de> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
committed by
Michael Tremer
parent
f1d98a1c3f
commit
abffcc99ad
@@ -24,6 +24,7 @@
|
|||||||
package IDS;
|
package IDS;
|
||||||
|
|
||||||
require '/var/ipfire/general-functions.pl';
|
require '/var/ipfire/general-functions.pl';
|
||||||
|
require "${General::swroot}/network-functions.pl";
|
||||||
|
|
||||||
# Location where all config and settings files are stored.
|
# Location where all config and settings files are stored.
|
||||||
our $settingsdir = "${General::swroot}/suricata";
|
our $settingsdir = "${General::swroot}/suricata";
|
||||||
@@ -410,42 +411,6 @@ sub _store_error_message ($) {
|
|||||||
&set_ownership("$storederrorfile");
|
&set_ownership("$storederrorfile");
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
|
||||||
## 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
#
|
||||||
## Function to check if the IDS is running.
|
## Function to check if the IDS is running.
|
||||||
#
|
#
|
||||||
@@ -613,7 +578,7 @@ sub generate_home_net_file() {
|
|||||||
&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
|
&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
|
||||||
|
|
||||||
# Get available network zones.
|
# Get available network zones.
|
||||||
my @network_zones = &get_available_network_zones();
|
my @network_zones = &Network::get_available_network_zones();
|
||||||
|
|
||||||
# Temporary array to store network address and prefix of the configured
|
# Temporary array to store network address and prefix of the configured
|
||||||
# networks.
|
# networks.
|
||||||
|
|||||||
@@ -444,6 +444,42 @@ sub get_mac_by_name($) {
|
|||||||
return $mac;
|
return $mac;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
## 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;
|
1;
|
||||||
|
|
||||||
# Remove the next line to enable the testsuite
|
# Remove the next line to enable the testsuite
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ use strict;
|
|||||||
|
|
||||||
require '/var/ipfire/general-functions.pl';
|
require '/var/ipfire/general-functions.pl';
|
||||||
require "${General::swroot}/ids-functions.pl";
|
require "${General::swroot}/ids-functions.pl";
|
||||||
|
require "${General::swroot}/network-functions.pl";
|
||||||
|
|
||||||
# Snort settings file, which contains the settings from the WUI.
|
# Snort settings file, which contains the settings from the WUI.
|
||||||
my $snort_settings_file = "${General::swroot}/snort/settings";
|
my $snort_settings_file = "${General::swroot}/snort/settings";
|
||||||
@@ -129,7 +130,7 @@ my %rulessettings = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
# Get all available network zones.
|
# Get all available network zones.
|
||||||
my @network_zones = &IDS::get_available_network_zones();
|
my @network_zones = &Network::get_available_network_zones();
|
||||||
|
|
||||||
# Read-in snort settings file.
|
# Read-in snort settings file.
|
||||||
&General::readhash("$snort_settings_file", \%snortsettings);
|
&General::readhash("$snort_settings_file", \%snortsettings);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ require '/var/ipfire/general-functions.pl';
|
|||||||
require "${General::swroot}/lang.pl";
|
require "${General::swroot}/lang.pl";
|
||||||
require "${General::swroot}/header.pl";
|
require "${General::swroot}/header.pl";
|
||||||
require "${General::swroot}/ids-functions.pl";
|
require "${General::swroot}/ids-functions.pl";
|
||||||
|
require "${General::swroot}/network-functions.pl";
|
||||||
|
|
||||||
my %color = ();
|
my %color = ();
|
||||||
my %mainsettings = ();
|
my %mainsettings = ();
|
||||||
@@ -47,7 +48,7 @@ my %ignored=();
|
|||||||
|
|
||||||
# Get the available network zones, based on the config type of the system and store
|
# Get the available network zones, based on the config type of the system and store
|
||||||
# the list of zones in an array.
|
# the list of zones in an array.
|
||||||
my @network_zones = &IDS::get_available_network_zones();
|
my @network_zones = &Network::get_available_network_zones();
|
||||||
|
|
||||||
# Check if openvpn is started and add it to the array of network zones.
|
# Check if openvpn is started and add it to the array of network zones.
|
||||||
if ( -e "/var/run/openvpn.pid") {
|
if ( -e "/var/run/openvpn.pid") {
|
||||||
|
|||||||
Reference in New Issue
Block a user