Skip to content

Commit

Permalink
ui:use appimages pattern as default target if found
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gustavo-iniguez-goya committed Jan 22, 2024
1 parent 2f1a9b8 commit 016f484
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 1 addition & 4 deletions ui/opensnitch/dialogs/prompt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,7 @@ def _render_connection(self, con):
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))
Expand Down
14 changes: 14 additions & 0 deletions ui/opensnitch/dialogs/prompt/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 016f484

Please sign in to comment.