Skip to content

Commit

Permalink
added the host to the options of the pop-up dialog
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gustavo-iniguez-goya committed Jul 20, 2020
1 parent 97139ec commit ace124a
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions ui/opensnitch/dialogs/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:]
Expand Down Expand Up @@ -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)})
Expand Down

0 comments on commit ace124a

Please sign in to comment.