]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
ids-functions.pl: Add get_providers_mode() function.
authorStefan Schantl <stefan.schantl@ipfire.org>
Sun, 20 Mar 2022 14:33:09 +0000 (15:33 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sat, 26 Mar 2022 10:33:28 +0000 (11:33 +0100)
This function is used to gather the modes of the configured providers
and return them as hash.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/ids-functions.pl

index b2a3a73907e07e625128b6886700c30b06044e94..2aab57b41e69f09a749f8ef561557ff75d9ce159 100644 (file)
@@ -234,6 +234,42 @@ sub get_enabled_providers () {
        return @enabled_providers;
 }
 
+#
+## Function to get a hash of provider handles and their configured modes (IDS/IPS).
+#
+sub get_providers_mode () {
+       my %used_providers = ();
+
+       # Hash to store the providers and their configured modes.
+       my %providers_mode = ();
+
+       # Read-in the providers config file.
+       &General::readhasharray("$providers_settings_file", \%used_providers);
+
+       # Loop through the hash of used_providers.
+       foreach my $id (keys %used_providers) {
+               # Skip disabled providers.
+               next unless ($used_providers{$id}[3] eq "enabled");
+
+               # Grab the provider handle.
+               my $provider = "$used_providers{$id}[0]";
+
+               # Grab the provider mode.
+               my $mode = "$used_providers{$id}[4]";
+
+               # Fall back to IDS if no mode could be obtained.
+               unless($mode) {
+                       $mode = "IDS";
+               }
+
+               # Add details to provider_modes hash.
+               $providers_mode{$provider} = $mode;
+       }
+
+       # Return the hash.
+       return %providers_mode;
+}
+
 #
 ## Function for checking if at least 300MB of free disk space are available
 ## on the "/var" partition.