]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
ids-functions.pl: Introduce private _get_dl_rulesfile() function.
authorStefan Schantl <stefan.schantl@ipfire.org>
Fri, 26 Mar 2021 12:19:58 +0000 (13:19 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Tue, 3 Aug 2021 17:25:45 +0000 (19:25 +0200)
This function can be used to generate/get the absolute file and path
for a given ruleset provider.

The files will be stored in the usual "/var/tmp" folder with a new
file format based on the dl_file type and the provider.

Examples could be:
* /var/ipfire/idsrules-emerging.tar.gz
* /var/ipfire/idsrules-registered.tar.gz
* /var/ipfire/idsrules-somprovider.rules

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

index a71305b988224f40fd5fa2c0f9b7bf403e06a276..51bc6a3c3a3d0d2ae9471cd1f9ed43b08fd8ae13 100644 (file)
@@ -65,9 +65,12 @@ our $providers_settings_file = "$settingsdir/providers-settings";
 # File which stores the configured settings for whitelisted addresses.
 our $ignored_file = "$settingsdir/ignored";
 
-# Location and name of the tarball which contains the ruleset.
+# DEPRECATED - Location and name of the tarball which contains the ruleset.
 our $rulestarball = "/var/tmp/idsrules.tar.gz";
 
+# Location where the downloaded rulesets are stored.
+our $dl_rules_path = "/var/tmp";
+
 # File to store any errors, which also will be read and displayed by the wui.
 our $storederrorfile = "/tmp/ids_storederror";
 
@@ -93,6 +96,9 @@ our $idspidfile = "/var/run/suricata.pid";
 # Location of suricatactrl.
 my $suricatactrl = "/usr/local/bin/suricatactrl";
 
+# Prefix for each downloaded ruleset.
+my $dl_rulesfile_prefix = "idsrules";
+
 # Array with allowed commands of suricatactrl.
 my @suricatactrl_cmds = ( 'start', 'stop', 'restart', 'reload', 'fix-rules-dir', 'cron' );
 
@@ -103,6 +109,12 @@ my @cron_intervals = ('off', 'daily', 'weekly' );
 # http_ports_file.
 my @http_ports = ('80', '81');
 
+# Hash which allows to convert the download type (dl_type) to a file suffix.
+my %dl_type_to_suffix = (
+       "archive" => ".tar.gz",
+       "plain" => ".rules",
+);
+
 #
 ## Function to check and create all IDS related files, if the does not exist.
 #
@@ -431,6 +443,31 @@ sub _store_error_message ($) {
        &set_ownership("$storederrorfile");
 }
 
+#
+## Private function to get the path and filename for a downloaded ruleset by a given provider.
+#
+sub _get_dl_rulesfile($) {
+       my ($provider) = @_;
+
+       # Gather the download type for the given provider.
+       my $dl_type = $IDS::Ruleset::Providers{$provider}{'dl_type'};
+
+       # Obtain the file suffix for the download file type.
+       my $suffix = $dl_type_to_suffix{$dl_type};
+
+       # Check if a suffix has been found.
+       unless ($suffix) {
+               # Abort return - nothing.
+               return;
+       }
+
+       # Generate the full filename and path for the stored rules file.
+       my $rulesfile = "$dl_rules_path/$dl_rulesfile_prefix-$provider$suffix";
+
+       # Return the generated filename.
+       return $rulesfile;
+}
+
 #
 ## Function to check if the IDS is running.
 #