Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/191'
Browse files Browse the repository at this point in the history
* origin/pr/191:
  Fixed parsing port ranges in VM settings
  Better handling of port/service names for VM settings
  • Loading branch information
marmarek committed Aug 2, 2019
2 parents 7c8b0d4 + 1d7d51e commit d5a4ddb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
22 changes: 12 additions & 10 deletions qubesmanager/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,17 @@ def populate_combos(self):
"192.168.1.100", "192.168.0.0/16",
"*"
]
displayed_services = [
'',
example_services = [
'', '22', '80', '1024-1234',
'http', 'https', 'ftp', 'ftps', 'smtp',
'smtps', 'pop3', 'pop3s', 'imap', 'imaps', 'odmr',
'pop3', 'pop3s', 'imap', 'imaps', 'odmr',
'nntp', 'nntps', 'ssh', 'telnet', 'telnets', 'ntp',
'snmp', 'ldap', 'ldaps', 'irc', 'ircs', 'xmpp-client',
'syslog', 'printer', 'nfs', 'x11',
'1024-1234'
'snmp', 'ldap', 'ldaps', 'irc', 'ircs-u', 'xmpp-client',
'syslog', 'printer', 'nfs', 'x11'
]
for address in example_addresses:
self.addressComboBox.addItem(address)
for service in displayed_services:
for service in example_services:
self.serviceComboBox.addItem(service)

def address_editing_finished(self):
Expand Down Expand Up @@ -143,8 +142,11 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
def __init__(self, parent=None):
QtCore.QAbstractItemModel.__init__(self, parent)

self.__column_names = {0: "Address", 1: "Service", 2: "Protocol", }
self.__column_names = {0: "Address", 1: "Port/Service", 2: "Protocol", }
self.__services = list()

self.port_range_pattern = re.compile(r'\d+-\d+')

pattern = re.compile(
r"(?P<name>[a-z][a-z0-9-]+)\s+(?P<port>[0-9]+)/"
r"(?P<protocol>[a-z]+)",
Expand Down Expand Up @@ -176,7 +178,7 @@ def sort(self, idx, order):
def get_service_name(self, port):
for service in self.__services:
if str(service[1]) == str(port):
return service[0]
return "{0} ({1})".format(str(port), service[0])
return str(port)

def get_service_port(self, name):
Expand Down Expand Up @@ -381,7 +383,7 @@ def run_rule_dialog(self, dialog, row=None):
elif dialog.udp_radio.isChecked():
rule.proto = 'udp'

if '-' in service:
if self.port_range_pattern.fullmatch(service):
try:
rule.dstports = service
except ValueError:
Expand Down
5 changes: 4 additions & 1 deletion ui/newfwruledlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Service</string>
<string>Port/Service</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -98,6 +98,9 @@
</item>
<item row="1" column="1" colspan="3">
<widget class="QComboBox" name="serviceComboBox">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Port/service can be provided as either port number (e.g. 122), port range (1024-1234) or service name (e.g. smtp) . For full list of services known, see /etc/services in dom0.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
Expand Down

0 comments on commit d5a4ddb

Please sign in to comment.