]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
ids-functions.pl: Introduce get_used_rulesfiles() function.
authorStefan Schantl <stefan.schantl@ipfire.org>
Wed, 31 Mar 2021 10:01:22 +0000 (12:01 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 19 Dec 2021 12:23:00 +0000 (13:23 +0100)
This function simply returns an array which contains the used rulesfiles
files.

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

index ef4c74a578f1403c021b985b3d261784f37c8c81..519488d6a915560bef0aa5f5b302b932398733d5 100644 (file)
@@ -1476,6 +1476,48 @@ sub get_red_address() {
        return;
 }
 
+#
+## Function to get all used rulesfiles files.
+#
+sub get_used_rulesfiles() {
+       # Array to store the used rulefiles.
+       my @used_rulesfiles = ();
+
+       # Check if the used rulesfile is empty.
+       unless (-z $used_rulesfiles_file) {
+               # Open the file or used rulefiles and read-in content.
+               open(FILE, $used_rulefiles_file) or die "Could not open $used_rulefiles_file. $!\n";
+
+               while (<FILE>) {
+                       # Assign the current line to a nice variable.
+                       my $line = $_;
+
+                       # Remove newlines.
+                       chomp($line);
+
+                       # Skip comments.
+                       next if ($line =~ /\#/);
+
+                       # Skip blank  lines.
+                       next if ($line =~ /^\s*$/);
+
+                       # Gather the rulefile.
+                       if ($line =~ /.*- (.*)/) {
+                               my $rulefile = $1;
+
+                               # Add the rulefile to the array of used rulesfiles.
+                               push(@used_rulesfiles, $rulefile);
+                       }
+               }
+
+               # Close the file.
+               close(FILE);
+       }
+
+       # Return the array of used rulesfiles.
+       return @used_rulesfiles;
+}
+
 #
 ## Function to write the lock file for locking the WUI, while
 ## the autoupdate script runs.