]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
ids-functions.pl: Introduce alter_oinkmaster_provider_includes_file().
authorStefan Schantl <stefan.schantl@ipfire.org>
Fri, 2 Apr 2021 07:13:17 +0000 (09:13 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 19 Dec 2021 12:23:43 +0000 (13:23 +0100)
This function can be used to directly modify the desired file.

It takes two arguments:
 * An action which could be "add" or "remove"
 * A provider handle, which should be added or removed.

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

index 88405ab82b71009f73f4f07c06bef71226490216..28fbc2654d10086e3ece42223eb955536a0d9398 100644 (file)
@@ -910,6 +910,51 @@ sub get_oinkmaster_provider_modified_sids_file ($) {
        return $filename;
 }
 
+#
+## Function to directly altering the oinkmaster provider includes file.
+##
+## Requires tha acition "remove" or "add" and a provider handle.
+#
+sub alter_oinkmaster_provider_includes_file ($$) {
+       my ($action, $provider) = @_;
+
+       # Call function to get the path and name for the given providers
+       # oinkmaster modified sids file.
+       my $provider_modified_sids_file = &get_oinkmaster_provider_modified_sids_file($provider);
+
+       # Open the file for reading..
+       open (FILE, $oinkmaster_provider_includes_file) or die "Could not read $oinkmaster_provider_includes_file. $!\n";
+
+       # Read-in file content.
+       my @lines = <FILE>;
+
+       # Close file after reading.
+       close(FILE);
+
+       # Re-open the file for writing.
+       open(FILE, ">", $oinkmaster_provider_includes_file) or die "Could not write to $oinkmaster_provider_includes_file. $!\n";
+
+       # Loop through the file content.
+       foreach my $line (@lines) {
+               # Remove newlines.
+               chomp($line);
+
+               # Skip line if we found our given provider and the action should be remove.
+               next if (($line =~ /$provider/) && ($action eq "remove"));
+
+               # Write the read-in line back to the file.
+               print FILE "$line\n";
+       }
+
+       # Add the provider to the file if requested.
+       if ($action eq "add") {
+               print FILE "include $provider_modified_sids_file\n";
+       }
+
+       # Close file handle.
+       close(FILE);
+}
+
 #
 ## Function to check if the IDS is running.
 #