From: Stefan Schantl Date: Sat, 22 Apr 2023 07:38:48 +0000 (+0200) Subject: firewall-lib.pl: Add get_custom_srvgrp_ports() function X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6aafefaca215d33d65f6d16282129d72812fddda;p=people%2Fstevee%2Fipfire-2.x.git firewall-lib.pl: Add get_custom_srvgrp_ports() function This function can be used to get all service port numbers which are attached to a custom service group by it's name. You also have to choose if you want to get the ports for TCP or UDP services. Signed-off-by: Stefan Schantl --- diff --git a/config/firewall/firewall-lib.pl b/config/firewall/firewall-lib.pl index 1e5a92c25..54bc21ca4 100644 --- a/config/firewall/firewall-lib.pl +++ b/config/firewall/firewall-lib.pl @@ -698,4 +698,38 @@ sub get_custom_group_addresses ($) { return @addresses; } -return 1; +sub get_custom_srvgrp_ports ($$) { + my ($group_name, $proto) = @_; + + # Array to store the found port numbers. + my @ports = (); + + # Loop through the hash of customservicegrp + foreach my $key (keys %customservicegrp) { + # Skip entries which does not have the correct group name. + next unless($customservicegrp{$key}[0] eq "$group_name"); + + # Get created service name + my $service = $customservicegrp{$key}[2]; + + # Grab the configured port number for the service name + my $port = &get_srv_port($service, 1, $proto); + + # Skip entry if no port could be grabbed. + next unless($port); + + # Add the port to the array of ports. + push(@ports, $port); + } + + # Remove any double entries. + @ports = &General::uniq(@ports); + + # Sort the port numbers. + @ports = sort(@ports); + + # Return the port array. + return @ports; +} + +1;