diff --git a/actions/firewall b/actions/firewall index 60635fcac..0fced7220 100755 --- a/actions/firewall +++ b/actions/firewall @@ -46,6 +46,12 @@ def parse_arguments(): '--zone', help='Zone from which the list is to be retrieved', required=True) + # Get service ports + get_service_ports = subparsers.add_parser( + 'get-service-ports', help='Get list of ports for service') + get_service_ports.add_argument('--service', help='Name of service', + required=True) + # Get interface status get_interfaces = subparsers.add_parser( 'get-interfaces', help='Get list of interfaces in a zone') @@ -105,8 +111,8 @@ def _flush_iptables_rules(): def set_firewall_backend(backend): """Set FirewallBackend attribute to the specified string.""" conf_file = '/etc/firewalld/firewalld.conf' - aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD + - augeas.Augeas.NO_MODL_AUTOLOAD) + aug = augeas.Augeas( + flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD) # lens for shell-script config file aug.set('/augeas/load/Shellvars/lens', 'Shellvars.lns') @@ -150,6 +156,14 @@ def subcommand_get_enabled_services(arguments): ['firewall-cmd', '--zone', arguments.zone, '--list-services']) +def subcommand_get_service_ports(arguments): + """Print list of ports for service""" + subprocess.call([ + 'firewall-cmd', '--permanent', '--service', arguments.service, + '--get-ports' + ]) + + def subcommand_get_interfaces(arguments): """Print the list of interfaces in a zone.""" subprocess.call( diff --git a/plinth/modules/firewall/__init__.py b/plinth/modules/firewall/__init__.py index c0fc801de..9f64467d7 100644 --- a/plinth/modules/firewall/__init__.py +++ b/plinth/modules/firewall/__init__.py @@ -95,6 +95,13 @@ def get_enabled_services(zone): return output.split() +def get_port_details(service_port): + """Return the port types and numbers for a service port""" + output = _run( + ['get-service-ports', '--service', service_port], superuser=True) + return output.split() + + def get_interfaces(zone): """Return the list of interfaces in a zone.""" output = _run(['get-interfaces', '--zone', zone], superuser=True)