ui, fw: fixed adding rules when using service name

We were failing adding system fw rules when the user selected a
destination port by service name.

We allow to specify port ranges with '-' (8080-8088), and as some
service names contain '-' in the name (ftp-data, netbios-ns), it was
failing.
This commit is contained in:
Gustavo Iñiguez Goia 2025-01-25 01:09:33 +01:00
parent ced8410d43
commit 0dfec48120
Failed to generate hash of commit
2 changed files with 18 additions and 6 deletions

View file

@ -1445,10 +1445,10 @@ The value must be in the format: VALUE/UNITS/TIME, for example:
# 3. otherwise validate that the entered value is an
# int
try:
if "," in statem_value or "-" in statem_value:
raise ValueError("port entered is multiport or a port range")
service_idx = self.net_srv.service_by_name(statem_value)
statem_value = self.net_srv.port_by_index(service_idx)
if service_idx > 0 and "," in statem_value or "-" in statem_value:
raise ValueError("port entered is multiport or a port range")
except:
if "," not in statem_value and "-" not in statem_value:
if not self._is_valid_int_value(statem_value):

View file

@ -435,16 +435,28 @@ class NetworkServices():
return self.srv_array
def service_by_index(self, idx):
try:
return self.srv_array[idx]
except:
return ""
def service_by_name(self, name):
try:
return self.srv_array.index(name)
except:
return -1
def port_by_index(self, idx):
try:
return self.ports_list[idx]
except:
return -1
def index_by_port(self, port):
try:
return self.ports_list.index(str(port))
except:
return -1
class Icons():
"""Util to display Qt's built-in icons when the system is not configured as