From: Stefan Schantl Date: Sun, 16 Apr 2023 14:17:11 +0000 (+0200) Subject: firewall-lib.pl: Add get_custom_group_addresses() function X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=330bc0c004888d1e8be09452b489c59865a9db13;p=people%2Fstevee%2Fipfire-2.x.git firewall-lib.pl: Add get_custom_group_addresses() function This function is used to get the host/nework address of each element of a given custom group name. Signed-off-by: Stefan Schantl --- diff --git a/config/firewall/firewall-lib.pl b/config/firewall/firewall-lib.pl index 767a9675d..b7d3ff958 100644 --- a/config/firewall/firewall-lib.pl +++ b/config/firewall/firewall-lib.pl @@ -663,4 +663,41 @@ sub get_custom_groups () { return @groups; } +sub get_custom_group_addresses ($) { + my ($group_name) = @_; + + # Array to store the found addresses/networks. + my @addresses = (); + + # Loop through the hash of customgroups. + foreach my $key (keys %customgrp) { + # Skip entries which does not belong to the current processed + # group. + next unless($customgrp{$key}[0] eq $group_name); + + # Call function to get the configured address of the current processed entry. + my @tmp = &get_address($customgrp{$key}[3], $customgrp{$key}[2], "tgt"); + + # The result is passed as a nested array, assign it to a better usable variable. + my $address = $tmp[0][0]; + + # Skip the entry if no address could be determined or it equals to "none". + next unless($address); + next if ($address eq "none"); + + # Normalize addresses of single hosts. + $address =~ s|/32||; + $address =~ s|/255.255.255.255||; + + # Assign the address to the addresses array. + push(@addresses, $address); + } + + # Remove any double entries. + @addresses = &General::uniq(@addresses); + + # Return the addresses array. + return @addresses; +} + return 1;