]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
update-ipblocklists: Adjust code to work with latest improvements
authorStefan Schantl <stefan.schantl@ipfire.org>
Wed, 14 Feb 2024 19:01:46 +0000 (20:01 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 3 Mar 2024 11:56:03 +0000 (12:56 +0100)
The former used modified file is not longer used (does not longer exist)
because the new general downloader uses stat instead.

Now to calculate the correct holdoff time when doing automatic updates
of a ruleset, we need to grab the last download time also by using stat.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
src/scripts/update-ipblocklists

index 4eb1edb7f81cb926664d545e94e528adfc6ee5aa..36facf572ea40ce8cb554ebddc554590c9d38e94 100644 (file)
@@ -25,6 +25,9 @@ use POSIX;
 # Load perl module to talk to the kernel syslog.
 use Sys::Syslog qw(:DEFAULT setlogsock);
 
+# Load module to get file stats.
+use File::stat;
+
 require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/ipblocklist-functions.pl";
 require "${General::swroot}/lang.pl";
@@ -60,23 +63,23 @@ my @blocklists = &IPblocklist::get_blocklists();
 # They need to be reloaded.
 my @updated_blocklists = ();
 
-# Gather the details, when a list got modified last time.
-my %modified = ();
-
-# Read-in data if the file exists.
-&General::readhash($IPblocklist::modified_file, \%modified ) if (-e $IPblocklist::modified_file);
-
 # Loop through the array of blocklists.
 foreach my $blocklist (@blocklists) {
        # Skip if the blocklist is not enabled.
        next if($settings{$blocklist} ne "on");
 
+       # Get name and full path of the cached blocklist file.
+       my $cached_file = &IPblocklist::get_cached_blocklist_file($blocklist);
+
+       # Call stat on the cached blocklist file if it is present.
+       my $stat = stat($cached_file) if (-f $cached_file);
+
+       # Omit the time the file last time has been modified.
+       my $last_download_time = $stat->mtime;
+
        # Get current time.
        my $time = time();
 
-       # Get time, when the blocklist has been downloaded last.
-       my $last_download_time = $modified{$blocklist};
-
        # Get the holdoff rate in seconds for the current processed blocklist.
        my $rate_time = &IPblocklist::get_holdoff_rate($blocklist);
 
@@ -84,7 +87,7 @@ foreach my $blocklist (@blocklists) {
        my $holdoff_time = $last_download_time + $rate_time;
 
        # Check if enough time has passed since the last download of the list.
-       if ($time <= $holdoff_time) {
+       if ($time le $holdoff_time) {
                # To frequent updates, log to syslog.
                &_log_to_syslog("<INFO> Skipping $blocklist blocklist - Too frequent update attempts!");
 
@@ -109,9 +112,6 @@ foreach my $blocklist (@blocklists) {
                        &_log_to_syslog("<ERROR> Could not update $blocklist blocklist - Unexpected error\!");
                }
        } else {
-               # Get the filename of the blocklist.
-               my $cached_file = &IPblocklist::get_cached_blocklist_file($blocklist);
-
                # Set the correct ownership.
                &IPblocklist::set_ownership($cached_file);