From 963f0159d77dbacd41e34139baae7db73de54a89 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Sat, 22 Apr 2023 09:38:48 +0200 Subject: [PATCH] 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 --- config/firewall/firewall-lib.pl | 36 ++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/config/firewall/firewall-lib.pl b/config/firewall/firewall-lib.pl index 1e5a92c25f..54bc21ca44 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; -- 2.39.5