Skip to content

Commit

Permalink
Alias to DstIp combobox
Browse files Browse the repository at this point in the history
  • Loading branch information
nolancarougepro committed Dec 16, 2024
1 parent 31da993 commit ee0a158
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions ui/opensnitch/dialogs/prompt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,6 @@ def _add_fixed_options_to_combo(self, combo, con, uid):
combo.addItem(QC.translate("popups", "to port {0}").format(con.dst_port), _constants.FIELD_DST_PORT)
combo.addItem(QC.translate("popups", "to {0}").format(con.dst_ip), _constants.FIELD_DST_IP)

alias = NetworkAliases.get_alias(con.dst_ip)
if alias:
combo.addItem(QC.translate("popups", f"to {alias}"), _constants.FIELD_DST_NETWORK)

combo.addItem(QC.translate("popups", "from user {0}").format(uid), _constants.FIELD_USER_ID)
if int(con.user_id) < 0:
combo.model().item(4).setEnabled(False)
Expand Down Expand Up @@ -538,6 +534,9 @@ def _add_appimage_pattern_to_combo(self, combo, con):
)

def _add_dst_networks_to_combo(self, combo, dst_ip):
alias = NetworkAliases.get_alias(dst_ip)
if alias:
combo.addItem(QC.translate("popups", f"to {alias}"), _constants.FIELD_DST_NETWORK)
if type(ipaddress.ip_address(dst_ip)) == ipaddress.IPv4Address:
combo.addItem(QC.translate("popups", "to {0}").format(ipaddress.ip_network(dst_ip + "/24", strict=False)), _constants.FIELD_DST_NETWORK)
combo.addItem(QC.translate("popups", "to {0}").format(ipaddress.ip_network(dst_ip + "/16", strict=False)), _constants.FIELD_DST_NETWORK)
Expand Down Expand Up @@ -590,7 +589,7 @@ def _send_rule(self):
self._rule.operator.type, self._rule.operator.operand, self._rule.operator.data = _utils.get_combo_operator(
self.whatCombo.itemData(what_idx),
self.whatCombo.currentText(),
self._con)
self._con)
if self._rule.operator.data == "":
print("popups: Invalid rule, discarding: ", self._rule)
self._rule = None
Expand All @@ -607,13 +606,10 @@ def _send_rule(self):
if self.whatCombo.itemData(what_idx) == _constants.FIELD_DST_NETWORK:
alias = NetworkAliases.get_alias(self._con.dst_ip)
if alias:
_type, _operand, _data = Config.RULE_TYPE_SIMPLE, Config.OPERAND_PROCESS_PATH, self._con.process_path
data.append({"type": _type, "operand": _operand, "data": _data})
rule_temp_name = slugify(f"{rule_temp_name} {os.path.basename(self._con.process_path)}")
alias_selected = True
data.append({
"type": Config.RULE_TYPE_SIMPLE,
"operand": Config.OPERAND_PROCESS_PATH,
"data": self._con.process_path
})
rule_temp_name = slugify(f"{rule_temp_name}-{os.path.basename(self._con.process_path)}")

if self.checkDstIP.isChecked() and self.whatCombo.itemData(what_idx) != _constants.FIELD_DST_IP:
_type, _operand, _data = _utils.get_combo_operator(
Expand Down

0 comments on commit ee0a158

Please sign in to comment.