From aacdd06765fa23ed1c39599abcd54df60ad2ee1d Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Wed, 14 Feb 2024 20:01:46 +0100 Subject: [PATCH] update-ipblocklists: Adjust code to work with latest improvements 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 --- src/scripts/update-ipblocklists | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/scripts/update-ipblocklists b/src/scripts/update-ipblocklists index 4eb1edb7f..36facf572 100644 --- a/src/scripts/update-ipblocklists +++ b/src/scripts/update-ipblocklists @@ -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(" Skipping $blocklist blocklist - Too frequent update attempts!"); @@ -109,9 +112,6 @@ foreach my $blocklist (@blocklists) { &_log_to_syslog(" 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); -- 2.39.5