]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
ipblocklist-functions.pl: Add function to get all enabled blocklists
authorStefan Schantl <stefan.schantl@ipfire.org>
Fri, 14 Apr 2023 15:35:48 +0000 (17:35 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 3 Mar 2024 11:56:02 +0000 (12:56 +0100)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/ipblocklist-functions.pl

index a53018f11d85ecef81a336451b45b274270102cd..943d3fd345c319544eaebbc08ef3c706fcba2168 100644 (file)
@@ -69,6 +69,32 @@ sub get_blocklists () {
        return sort(@blocklists);
 }
 
+#
+## Function to get all enabled blocklists.
+#
+sub get_enabled_blocklists () {
+       my @enabled_blocklists;
+       my %settings;
+
+       # Get all available blocklists.
+       my @blocklists = &get_blocklists();
+
+       # Read-in blocklist settings.
+       &General::readhash($settings_file, \%settings) if (-e $settings_file);
+
+       # Loop through the array of available blocklists.
+       foreach my $blocklist (@blocklists) {
+               # Check if the blocklist is enabled.
+               if ((exists($settings{$blocklist})) && ($settings{$blocklist} eq "on")) {
+                       # Add the blocklist to the array of enabled blocklists.
+                       push(@enabled_blocklists, $blocklist);
+               }
+       }
+
+       # Return the array of enabled blocklists.
+       return @enabled_blocklists;
+}
+
 #
 ## Function to get the full path and name of the cached blocklist.
 #