From: Stefan Schantl Date: Fri, 2 Apr 2021 07:13:17 +0000 (+0200) Subject: ids-functions.pl: Introduce alter_oinkmaster_provider_includes_file(). X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d878d9c01482510220aae1f432ad5c45bc05997d;p=people%2Fstevee%2Fipfire-2.x.git ids-functions.pl: Introduce alter_oinkmaster_provider_includes_file(). 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 --- diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl index 88405ab82b..28fbc2654d 100644 --- a/config/cfgroot/ids-functions.pl +++ b/config/cfgroot/ids-functions.pl @@ -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 = ; + + # 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. #