]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
ids-functions.pl: Try to enumerate the dl_rulesfile if a provider is not
authorStefan Schantl <stefan.schantl@ipfire.org>
Wed, 20 Apr 2022 18:58:04 +0000 (20:58 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Wed, 20 Apr 2022 18:58:04 +0000 (20:58 +0200)
supported anymore.

In this case the details about the file suffix is not available in the
ruleset-sources file anymore. In this case now the function tries to
enumerate the correct filename.

This allows to display the correct stats in the WUI and to extract and
use the downloaded ruleset of the provider until it got deleted by the
user.

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

index 41a07897b2354d99a9058553a9a16591bd05f15e..f6627ba2bff29b5f94962f0d0c04c5bd65abcf21 100644 (file)
@@ -1027,23 +1027,47 @@ sub _store_error_message ($) {
 sub _get_dl_rulesfile($) {
        my ($provider) = @_;
 
-       # Gather the download type for the given provider.
-       my $dl_type = $IDS::Ruleset::Providers{$provider}{'dl_type'};
+       # Check if the requested provider is known.
+       if ($IDS::Ruleset::Providers{$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;
+               }
 
-       # Obtain the file suffix for the download file type.
-       my $suffix = $dl_type_to_suffix{$dl_type};
+               # Generate the full filename and path for the stored rules file.
+               my $rulesfile = "$dl_rules_path/$dl_rulesfile_prefix-$provider$suffix";
 
-       # Check if a suffix has been found.
-       unless ($suffix) {
-               # Abort return - nothing.
-               return;
-       }
+               # Return the generated filename.
+               return $rulesfile;
 
-       # Generate the full filename and path for the stored rules file.
-       my $rulesfile = "$dl_rules_path/$dl_rulesfile_prefix-$provider$suffix";
+       } else {
+               # A downloaded ruleset for a provider which is not supported anymore is requested.
+               #
+               # Try to enumerate the downloaded ruleset file.
+               foreach my $dl_type (keys %dl_type_to_suffix) {
+                       # Get the file suffix for the supported type.
+                       my $suffix = $dl_type_to_suffix{$dl_type};
+
+                       # Generate possible ruleset file name.
+                       my $rulesfile = "$dl_rules_path/$dl_rulesfile_prefix-$provider$suffix";
+
+                       # Check if such a file exists.
+                       if (-f $rulesfile) {
+                               # Downloaded rulesfile found - Return the filename.
+                               return $rulesfile;
+                       }
+               }
+       }
 
-       # Return the generated filename.
-       return $rulesfile;
+       # If we got here, no rulesfile could be determined - return nothing.
+       return;
 }
 
 #