Skip to content

Commit ff22d94

Browse files
pop-ups: better unique rule names
When answering a pop-up we generate the rule name based on the properties of the connection. When sending the rule to the daemon, the daemon verifies that the name is unique and save it. If it's not, it generates a unique name. However, if you responded to a pop-up and later modified any property of the rule without changing the name, if the same connection tried to be established again, you were prompted to allow/deny it, generating the same name for the rule. This could cause some confusion, because when sending the new rule to the daemon the rule name was regenerated to be unique, but on the GUI it was not updated, and even more, the old-personalized rule was replaced with the new one.
1 parent 3d8bdfc commit ff22d94

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

ui/opensnitch/dialogs/prompt.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from opensnitch.desktop_parser import LinuxDesktopParser
1717
from opensnitch.config import Config
1818
from opensnitch.version import version
19+
from opensnitch.actions import Actions
20+
from opensnitch.rules import Rules
1921

2022
from opensnitch import ui_pb2
2123

@@ -55,6 +57,8 @@ def __init__(self, parent=None, appicon=None):
5557
QtWidgets.QDialog.__init__(self, parent, QtCore.Qt.WindowStaysOnTopHint)
5658
# Other interesting flags: QtCore.Qt.Tool | QtCore.Qt.BypassWindowManagerHint
5759
self._cfg = Config.get()
60+
self._rules = Rules.instance()
61+
5862
self.setupUi(self)
5963
self.setWindowIcon(appicon)
6064
self.installEventFilter(self)
@@ -649,7 +653,7 @@ def _send_rule(self):
649653
self._rule.operator.type = Config.RULE_TYPE_LIST
650654
self._rule.operator.operand = Config.RULE_TYPE_LIST
651655

652-
self._rule.name = rule_temp_name
656+
self._rule.name = self._rules.new_unique_name(rule_temp_name, self._peer, "")
653657

654658
self.hide()
655659
if self._ischeckAdvanceded:

ui/opensnitch/rules.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ def delete(self, name, addr, callback):
101101
def delete_by_field(self, field, values):
102102
return self._db.delete_rules_by_field(field, values)
103103

104+
def new_unique_name(self, rule_name, node_addr, prefix):
105+
"""generate a new name, if the supplied one already exists
106+
"""
107+
if self._db.get_rule(rule_name, node_addr).next() == False:
108+
return rule_name
109+
110+
for idx in range(0, 100):
111+
new_rule_name = "{0}-{1}".format(rule_name, idx)
112+
if self._db.get_rule(new_rule_name, node_addr).next() == False:
113+
return new_rule_name
114+
115+
return rule_name
116+
104117
def update_time(self, time, name, addr):
105118
"""Updates the time of a rule, whenever a new connection matched a
106119
rule.

0 commit comments

Comments
 (0)