From 016f4842ff13cd237e921eb80cba23a86abf5c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20I=C3=B1iguez=20Goia?= Date: Mon, 22 Jan 2024 12:54:10 +0100 Subject: [PATCH] ui:use appimages pattern as default target if found If the path of a process starts with /tmp/.mount_*, which is the common path for appimages, use it as the default target on the popups. Previously it was only added to the list of targets, but preselecting it will help users to create rules for appimages. --- ui/opensnitch/dialogs/prompt/__init__.py | 5 +---- ui/opensnitch/dialogs/prompt/_utils.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ui/opensnitch/dialogs/prompt/__init__.py b/ui/opensnitch/dialogs/prompt/__init__.py index eb4325d8..e11ceb9b 100644 --- a/ui/opensnitch/dialogs/prompt/__init__.py +++ b/ui/opensnitch/dialogs/prompt/__init__.py @@ -419,10 +419,7 @@ class PromptDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]): self._default_action = self._cfg.getInt(self._cfg.DEFAULT_ACTION_KEY) _utils.set_default_duration(self._cfg, self.durationCombo) - if int(con.process_id) > 0 and app_name != "" and app_args != "": - self.whatCombo.setCurrentIndex(int(self._cfg.getSettings(self._cfg.DEFAULT_TARGET_KEY))) - else: - self.whatCombo.setCurrentIndex(2) + _utils.set_default_target(self.whatCombo, con, self._cfg, app_name, app_args) self.checkDstIP.setChecked(self._cfg.getBool(self._cfg.DEFAULT_POPUP_ADVANCED_DSTIP)) self.checkDstPort.setChecked(self._cfg.getBool(self._cfg.DEFAULT_POPUP_ADVANCED_DSTPORT)) diff --git a/ui/opensnitch/dialogs/prompt/_utils.py b/ui/opensnitch/dialogs/prompt/_utils.py index 8db31c1b..972f0e90 100644 --- a/ui/opensnitch/dialogs/prompt/_utils.py +++ b/ui/opensnitch/dialogs/prompt/_utils.py @@ -119,6 +119,20 @@ def set_default_duration(cfg, durationCombo): else: durationCombo.setCurrentIndex(Config.DEFAULT_DURATION_IDX) +def set_default_target(combo, con, cfg, app_name, app_args): + # set appimage as default target if the process path starts with + # /tmp/._mount + if con.process_path.startswith(_constants.APPIMAGE_PREFIX): + idx = combo.findData(_constants.FIELD_APPIMAGE) + if idx != -1: + combo.setCurrentIndex(idx) + return + + if int(con.process_id) > 0 and app_name != "" and app_args != "": + combo.setCurrentIndex(int(cfg.getSettings(cfg.DEFAULT_TARGET_KEY))) + else: + combo.setCurrentIndex(2) + def get_combo_operator(data, comboText, con): if data == _constants.FIELD_PROC_PATH: return Config.RULE_TYPE_SIMPLE, Config.OPERAND_PROCESS_PATH, con.process_path