Skip to content

Commit 87be10c

Browse files
ui,pop-ups: improved default target logic
When displaying a new pop-up, we set the default target based on: - snap or appimages paths. - user's preferences. In order to respect user's preferences, the process path and cmdline must be non-empty. If any of these properties is empty, then we select by default the Destination Port of the connection. However, in some cases the cmdline is empty while the path is not, but we end up selecting the destination port as the default target anyway, which causes confusion and in some cases too much pop-ups. Now, if the cmdline is empty and the path is not, we'll select the path of the process as the default target. see #1521 for more details.
1 parent 444a4b5 commit 87be10c

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

ui/opensnitch/dialogs/prompt/constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
FIELD_APPIMAGE = "appimage_path"
2323
FIELD_SNAP = "snap_path"
2424

25+
TARGET_IDX_PROC_PATH = 0
26+
TARGET_IDX_PROC_CMDLINE = 1
27+
TARGET_IDX_DST_PORT = 2
28+
TARGET_IDX_DST_IP = 3
29+
TARGET_IDX_UID = 4
30+
TARGET_IDX_PID = 5
31+
2532
DURATION_30s = "30s"
2633
DURATION_5m = "5m"
2734
DURATION_15m = "15m"

ui/opensnitch/dialogs/prompt/utils.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def add_fixed_options_to_combo(combo, con, uid):
129129
# prefs -> UI -> Default target
130130
combo.addItem(QC.translate("popups", "from this executable"), constants.FIELD_PROC_PATH)
131131
if int(con.process_id) < 0:
132-
combo.model().item(0).setEnabled(False)
132+
combo.model().item(constants.TARGET_IDX_PROC_PATH).setEnabled(False)
133133

134134
combo.addItem(QC.translate("popups", "from this command line"), constants.FIELD_PROC_ARGS)
135135

@@ -138,7 +138,7 @@ def add_fixed_options_to_combo(combo, con, uid):
138138

139139
combo.addItem(QC.translate("popups", "from user {0}").format(uid), constants.FIELD_USER_ID)
140140
if int(con.user_id) < 0:
141-
combo.model().item(4).setEnabled(False)
141+
combo.model().item(constants.TARGET_IDX_UID).setEnabled(False)
142142

143143
combo.addItem(QC.translate("popups", "from this PID"), constants.FIELD_PROC_ID)
144144

@@ -241,10 +241,19 @@ def set_default_target(combo, con, cfg, app_name, app_args):
241241
combo.setCurrentIndex(idx)
242242
return
243243

244+
saved_target = int(cfg.getSettings(cfg.DEFAULT_TARGET_KEY))
245+
# In order to respect user selection, the app_name and app_args must be
246+
# non-empty.
247+
# Sometimes the app_args is empty, so in that case we'll fallback to
248+
# app_path if it's not empty.
249+
# Otherwise select the destination port.
244250
if int(con.process_id) > 0 and app_name != "" and app_args != "":
245-
combo.setCurrentIndex(int(cfg.getSettings(cfg.DEFAULT_TARGET_KEY)))
251+
combo.setCurrentIndex(saved_target)
252+
elif int(con.process_id) > 0 and app_name != "" and app_args == "":
253+
combo.setCurrentIndex(constants.TARGET_IDX_PROC_PATH)
246254
else:
247-
combo.setCurrentIndex(2)
255+
print("[warning] connection process details incomplete:", con)
256+
combo.setCurrentIndex(constants.TARGET_IDX_DST_PORT)
248257

249258
def get_combo_operator(data, comboText, con):
250259
if data == constants.FIELD_PROC_PATH:

0 commit comments

Comments
 (0)