]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
ids-functions.pl: Allow "3" download attempts for each provider before fail.
authorStefan Schantl <stefan.schantl@ipfire.org>
Mon, 21 Mar 2022 19:19:25 +0000 (20:19 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Thu, 24 Mar 2022 19:04:03 +0000 (20:04 +0100)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/ids-functions.pl

index eb276030b6265618b11c7c42f27888dd36f1f338..29d186995574e90afd7b98ffaf36518a94699327 100644 (file)
@@ -256,6 +256,10 @@ sub downloadruleset ($) {
        # If no provider is given default to "all".
        $provider //= 'all';
 
+       # The amount of download attempts before giving up and
+       # logging an error.
+       my $max_dl_attempts = 3;
+
        # Hash to store the providers and access id's, for which rules should be downloaded.
        my %sheduled_providers = ();
 
@@ -364,19 +368,33 @@ sub downloadruleset ($) {
                # Pass the requested url to the downloader.
                my $request = HTTP::Request->new(GET => $url);
 
-               # Perform the request and save the output into the tmpfile.
-               my $response = $downloader->request($request, $tmpfile);
+               my $dl_attempt = 1;
+               my $response;
 
-               # Check if there was any error.
-               unless ($response->is_success) {
-                       # Obtain error.
-                       my $error = $response->content;
+               # Download and retry on failure.
+               while ($dl_attempt <= $max_dl_attempts) {
+                       # Perform the request and save the output into the tmpfile.
+                       $response = $downloader->request($request, $tmpfile);
 
-                       # Log error message.
-                       &_log_to_syslog("Unable to download the ruleset. \($error\)");
+                       # Check if the download was successfull.
+                       if($response->is_success) {
+                               # Break loop.
+                               last;
 
-                       # Return "1" - false.
-                       return 1;
+                       # Check if we ran out of download re-tries.
+                       } elsif ($dl_attempt eq $max_dl_attempts) {
+                               # Obtain error.
+                               my $error = $response->content;
+
+                               # Log error message.
+                               &_log_to_syslog("Unable to download the ruleset. \($error\)");
+
+                               # Return "1" - false.
+                               return 1;
+                       }
+
+                       # Increase download attempt counter.
+                       $dl_attempt++;
                }
 
                # Obtain the connection headers.