From ace124ad6a6946bc5ba6686deefd8022db078fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20I=C3=B1iguez=20Goia?= Date: Mon, 20 Jul 2020 23:59:14 +0200 Subject: [PATCH] added the host to the options of the pop-up dialog The host to where a process is connecting to was missing in the options list, when the connection to allow was a query to resolve the domain name. Reported here: #48 Also added the connection port to the rule name. --- ui/opensnitch/dialogs/prompt.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ui/opensnitch/dialogs/prompt.py b/ui/opensnitch/dialogs/prompt.py index fdcfe9af7c..a881df0a31 100644 --- a/ui/opensnitch/dialogs/prompt.py +++ b/ui/opensnitch/dialogs/prompt.py @@ -256,16 +256,17 @@ def _render_connection(self, con): if con.dst_host != "" and con.dst_host != con.dst_ip: try: - dst_host = re.search("(.*)\s\((.*)\)", con.dst_host) + # get the domain that a process is trying to resolve. format: 1.1.1.1 (host.example.com) + dst_host_regexp = re.search("(.*)\s\((.*)\)", con.dst_host) except Exception: pass - if dst_host != None and len(dst_host.groups()) == 2: - self._add_dsthost_to_combo(dst_host.group(2)) - else: - dst_host = con.dst_host - self.whatCombo.addItem("%s" % con.dst_host, "simple_host") - self._add_dsthost_to_combo(con.dst_host) + dst_host = con.dst_host + if dst_host_regexp != None and len(dst_host_regexp.groups()) == 2: + dst_host = dst_host_regexp.group(2) + print("host regexp: " + dst_host) + + self._add_dsthost_to_combo(dst_host) self.whatIPCombo.addItem("to %s" % con.dst_ip, "dst_ip") @@ -300,6 +301,9 @@ def closeEvent(self, e): e.ignore() def _add_dsthost_to_combo(self, dst_host): + self.whatCombo.addItem("%s" % dst_host, "simple_host") + self.whatIPCombo.addItem("%s" % dst_host, "simple_host") + parts = dst_host.split('.')[1:] nparts = len(parts) for i in range(0, nparts - 1): @@ -345,7 +349,7 @@ def _get_combo_operator(self, combo, what_idx): return "simple", "dest.ip", self._con.dst_ip elif combo.itemData(what_idx) == "simple_host": - return "simple", "dest.host", self._con.dst_host + return "simple", "dest.host", combo.currentText() elif combo.itemData(what_idx) == "regex_host": return "regexp", "dest.host", "%s" % '\.'.join(combo.currentText().split('.')).replace("*", ".*")[3:] @@ -394,6 +398,7 @@ def _send_rule(self): if self._ischeckAdvanceded and self.checkDstPort.isChecked() and self.whatCombo.itemData(what_idx) != "dst_port": data.append({"type": "simple", "operand": "dest.port", "data": str(self._con.dst_port)}) + rule_temp_name = slugify("%s %s" % (rule_temp_name, str(self._con.dst_port))) if self._ischeckAdvanceded and self.checkUserID.isChecked() and self.whatCombo.itemData(what_idx) != "user_id": data.append({"type": "simple", "operand": "user.id", "data": str(self._con.user_id)})