From dd3aba1a6a233e6385add5c38820ebc19a271476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20I=C3=B1iguez=20Goia?= Date: Thu, 8 Feb 2024 15:34:05 +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. (cherry picked from commit 016f4842ff13cd237e921eb80cba23a86abf5c5f) --- ui/opensnitch/dialogs/prompt.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ui/opensnitch/dialogs/prompt.py b/ui/opensnitch/dialogs/prompt.py index 015b90104c..a1c021ea58 100644 --- a/ui/opensnitch/dialogs/prompt.py +++ b/ui/opensnitch/dialogs/prompt.py @@ -324,6 +324,20 @@ def _set_app_args(self, app_name, app_args): self.argsLabel.setVisible(False) self.argsLabel.setText("") + def _set_default_target(self, combo, con, app_name, app_args): + # set appimage as default target if the process path starts with + # /tmp/._mount + if con.process_path.startswith(self.APPIMAGE_PREFIX): + idx = combo.findData(self.FIELD_APPIMAGE) + if idx != -1: + combo.setCurrentIndex(idx) + return + + 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) + def _render_connection(self, con): app_name, app_icon, description, _ = self._apps_parser.get_info_by_path(con.process_path, "terminal") app_args = " ".join(con.process_args) @@ -415,11 +429,7 @@ def _render_connection(self, con): self._configure_default_duration() - 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) - + self._set_default_target(self.whatCombo, con, 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)) @@ -444,7 +454,7 @@ def closeEvent(self, e): e.ignore() def _add_appimage_pattern_to_combo(self, combo, con): - """appimages' absolute path usually starts with /tmp/.mount_< + """appimages' absolute path usually starts with /tmp/.mount_ """ appimage_bin = os.path.basename(con.process_path) appimage_path = os.path.dirname(con.process_path)