]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
ipblocklist-functions.pl: Add function to get the holdoff_rate of a
authorTim FitzGeorge <ipfr@tfitzgeorge.me.uk>
Sun, 6 Mar 2022 14:07:17 +0000 (15:07 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sat, 7 May 2022 09:32:08 +0000 (11:32 +0200)
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 <ipfr@tfitzgeorge.me.uk>
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/ipblocklist-functions.pl

index b6abb1befb6e18f3fb783478f8432f621ed20fa3..284503a02b1b53f6c46c901968d78703b326cf18 100644 (file)
@@ -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;