Skip to content

Commit

Permalink
ui: make pop-up dialogs optionals
Browse files Browse the repository at this point in the history
If the default timeout is set to 0, do not display the pop-up dialog and
apply the default configured actions.

Fixed typo in preferences dialog.
  • Loading branch information
gustavo-iniguez-goya committed Oct 25, 2020
1 parent d815d4c commit 6522a94
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
24 changes: 7 additions & 17 deletions ui/opensnitch/dialogs/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ def promptUser(self, connection, is_local, peer):
return self._rule, self._timeout_triggered

def _timeout_worker(self):
if self._tick == 0:
self._timeout_trigger.emit()
return

while self._tick > 0 and self._done.is_set() is False:
t = threading.currentThread()
# stop only stops the coundtdown, not the thread itself.
Expand All @@ -136,7 +140,8 @@ def _timeout_worker(self):
@QtCore.pyqtSlot()
def on_connection_prompt_triggered(self):
self._render_connection(self._con)
self.show()
if self._tick > 0:
self.show()

@QtCore.pyqtSlot()
def on_tick_triggered(self):
Expand Down Expand Up @@ -180,8 +185,6 @@ def _set_cmd_action_text(self):
else:
self.denyButton.setText("%s (%d)" % (self._deny_text, self._tick))
self.applyButton.setText(self._apply_text)


self.checkAdvanced.setFocus()

def _render_connection(self, con):
Expand Down Expand Up @@ -255,18 +258,7 @@ def _render_connection(self, con):
self.whatCombo.addItem("from user %s" % uid, "user_id")

if con.dst_host != "" and con.dst_host != con.dst_ip:
try:
# get the domain that a process is trying to resolve. format: 1.1.1.1 (host.example.com)
dst_host_regexp = re.search("(.*)\s\((.*)\)", con.dst_host)
except Exception:
pass

dst_host = con.dst_host
if dst_host_regexp != None and len(dst_host_regexp.groups()) == 2:
dst_host = dst_host_regexp.group(2)
print("host regexp: " + dst_host)

self._add_dsthost_to_combo(dst_host)
self._add_dsthost_to_combo(con.dst_host)

self.whatIPCombo.addItem("to %s" % con.dst_ip, "dst_ip")

Expand Down Expand Up @@ -379,9 +371,7 @@ def _send_rule(self):
self._cfg.setSettings("promptDialog/geometry", self.saveGeometry())
self._rule = ui_pb2.Rule(name="user.choice")
self._rule.enabled = True

self._rule.action = self._default_action

self._rule.duration = self._get_duration(self.durationCombo.currentIndex())

what_idx = self.whatCombo.currentIndex()
Expand Down
13 changes: 2 additions & 11 deletions ui/opensnitch/res/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This timeout is the countdown you see when a pop-up dialog is shown.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This timeout is the countdown you see when a pop-up dialog is shown.&lt;/p&gt;&lt;p&gt;Set it to 0 to avoid displaying the pop-up. Instead, you'll see a warning that the default action has been applied.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Default timeout</string>
Expand Down Expand Up @@ -432,22 +432,13 @@
</property>
<item>
<property name="text">
<string>deny all</string>
<string>deny</string>
</property>
<property name="icon">
<iconset theme="emblem-important">
<normaloff>../../../../../../../../../../../../../../.designer/backup</normaloff>../../../../../../../../../../../../../../.designer/backup</iconset>
</property>
</item>
<item>
<property name="text">
<string>deny only supported protocols</string>
</property>
<property name="icon">
<iconset theme="dialog-warning">
<normaloff>../../../../../../../../.designer/backup</normaloff>../../../../../../../../.designer/backup</iconset>
</property>
</item>
<item>
<property name="text">
<string>allow</string>
Expand Down

0 comments on commit 6522a94

Please sign in to comment.