From: Tim FitzGeorge Date: Sun, 6 Mar 2022 14:07:17 +0000 (+0100) Subject: ipblocklist-functions.pl: Add function to get the holdoff_rate of a X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bb0ddb22d021055303ca69e35082bed77729d5d8;p=people%2Fstevee%2Fipfire-2.x.git ipblocklist-functions.pl: Add function to get the holdoff_rate of a given list. The function will return the rate in seconds based on the configured rate value in the blocklist sources file and the given blocklist. Signed-off-by: Tim FitzGeorge Signed-off-by: Stefan Schantl --- diff --git a/config/cfgroot/ipblocklist-functions.pl b/config/cfgroot/ipblocklist-functions.pl index b6abb1befb..284503a02b 100644 --- a/config/cfgroot/ipblocklist-functions.pl +++ b/config/cfgroot/ipblocklist-functions.pl @@ -337,4 +337,43 @@ sub _calculate_hashsize($) { return $hashsize; } +# +## sub get_holdoff_rate(list) +## +## This function is used to get the holdoff rate in seconds for a desired provider, +## based on the configured rate limit in minutes (m), hours (h) or days (d) in the +## blacklist sources settings file. +## +# +sub get_holdoff_rate($) { + my ($list) = @_; + + # Grab the configured lookup rate for the given list. + my $rate = $IPblocklist::List::sources{$list}{'rate'}; + + # Split the grabbed rate into value and unit. + my ($value, $unit) = (uc $rate) =~ m/(\d+)([DHM]?)/; + + # Days + if ($unit eq 'D') { + $value *= 60 * 60 * 24; + + # Minutes + } elsif ($unit eq 'M') { + $value *= 60; + + # Everything else - assume hours. + } else { + $value *= 60 * 60; + } + + # Sanity check - limit to range 5 min .. 1 week + + # d h m s + $value = 5 * 60 if ($value < 5 * 60); + $value = 7 * 24 * 60 * 60 if ($value > 7 * 24 * 60 * 60); + + return $value; +} + 1;