Skip to content

Commit

Permalink
ui, pop-ups: improved connections visualizing
Browse files Browse the repository at this point in the history
The path and arguments of a process were not displayed correctly.
closes #93

On the other hand, the combo box option (allow/deny) "from this process"
was misleading. Changed by "from this executable". #94
  • Loading branch information
gustavo-iniguez-goya committed Nov 24, 2020
1 parent e8683e7 commit 0b85f6b
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 46 deletions.
23 changes: 16 additions & 7 deletions ui/opensnitch/dialogs/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ def _checkbox_toggled(self, state):
self.checkUserID.setVisible(state)
self._ischeckAdvanceded = state

def _set_elide_text(self, widget, text, max_size=128):
if len(text) > max_size:
text = text[:max_size] + "..."

widget.setText(text)

def promptUser(self, connection, is_local, peer):
# one at a time
with self._lock:
Expand Down Expand Up @@ -191,8 +197,8 @@ def _set_cmd_action_text(self):
def _render_connection(self, con):
app_name, app_icon, _ = self._apps_parser.get_info_by_path(con.process_path, "terminal")
if app_name != con.process_path and con.process_path not in con.process_args:
self.appPathLabel.setFixedHeight(20)
self.appPathLabel.setText("(%s)" % con.process_path)
self.appPathLabel.setToolTip("Process path: %s" % con.process_path)
self._set_elide_text(self.appPathLabel, "(%s)" % con.process_path)
else:
self.appPathLabel.setFixedHeight(1)
self.appPathLabel.setText("")
Expand All @@ -202,9 +208,11 @@ def _render_connection(self, con):
self.appNameLabel.setText("Outgoing connection")
else:
self.appNameLabel.setText(app_name)
self.appNameLabel.setToolTip(app_name)

self.cwdLabel.setText(con.process_cwd)
self.cwdLabel.setToolTip(con.process_cwd)
self.cwdLabel.setToolTip("Process launched from: %s" % con.process_cwd)
self._set_elide_text(self.cwdLabel, con.process_cwd)

icon = QtGui.QIcon().fromTheme(app_icon)
pixmap = icon.pixmap(icon.actualSize(QtCore.QSize(48, 48)))
Expand All @@ -225,6 +233,7 @@ def _render_connection(self, con):
con.dst_port )

self.messageLabel.setText(message)
self.messageLabel.setToolTip(message)

self.sourceIPLabel.setText(con.src_ip)
self.destIPLabel.setText(con.dst_ip)
Expand All @@ -240,17 +249,17 @@ def _render_connection(self, con):

self.uidLabel.setText(uid)
self.pidLabel.setText("%s" % con.process_id)
self.argsLabel.setText(' '.join(con.process_args))
self._set_elide_text(self.argsLabel, ' '.join(con.process_args))
self.argsLabel.setToolTip(' '.join(con.process_args))

self.whatCombo.clear()
self.whatIPCombo.clear()
if int(con.process_id) > 0:
self.whatCombo.addItem("from this process", "process_path")
self.whatCombo.addItem("from this executable", "process_path")

self.whatCombo.addItem("from this command line", "process_args")
if self.argsLabel.text() == "":
self.argsLabel.setText(con.process_path)
self._set_elide_text(self.argsLabel, con.process_path)

# the order of the entries must match those in the preferences dialog
self.whatCombo.addItem("to port %d" % con.dst_port, "dst_port")
Expand Down Expand Up @@ -330,7 +339,7 @@ def _get_combo_operator(self, combo, what_idx):
return "simple", "process.path", self._con.process_path

elif combo.itemData(what_idx) == "process_args":
return "simple", "process.command", self.argsLabel.text()
return "simple", "process.command", ' '.join(self._con.process_args)

elif combo.itemData(what_idx) == "user_id":
return "simple", "user.id", "%s" % self._con.user_id
Expand Down
113 changes: 74 additions & 39 deletions ui/opensnitch/res/prompt.ui
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@
</property>
<property name="icon">
<iconset theme="emblem-important">
<normaloff>../../../../../../../../../../../../../../../../../../../../.designer/backup</normaloff>../../../../../../../../../../../../../../../../../../../../.designer/backup</iconset>
<normaloff>../../../../../../../../../../../../../../../../../../../../../../../../../../.designer/backup</normaloff>../../../../../../../../../../../../../../../../../../../../../../../../../../.designer/backup</iconset>
</property>
</widget>
</item>
Expand Down Expand Up @@ -549,7 +549,7 @@
</property>
<property name="icon">
<iconset theme="emblem-default">
<normaloff>../../../../../../../../../../../../../../../../../../../../.designer/backup</normaloff>../../../../../../../../../../../../../../../../../../../../.designer/backup</iconset>
<normaloff>../../../../../../../../../../../../../../../../../../../../../../../../../../.designer/backup</normaloff>../../../../../../../../../../../../../../../../../../../../../../../../../../.designer/backup</iconset>
</property>
</widget>
</item>
Expand Down Expand Up @@ -597,7 +597,7 @@
<property name="maximumSize">
<size>
<width>520</width>
<height>35</height>
<height>40</height>
</size>
</property>
<property name="text">
Expand All @@ -612,43 +612,72 @@
</widget>
</item>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="iconLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="resources.qrc">:/pics/icon.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
<layout class="QFormLayout" name="formLayout">
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
</widget>
<item>
<widget class="QLabel" name="iconLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="resources.qrc">:/pics/icon.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<item row="0" column="1">
<layout class="QGridLayout" name="gridLayout_4">
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QLabel" name="appNameLabel">
<property name="sizePolicy">
Expand Down Expand Up @@ -689,7 +718,7 @@
<property name="maximumSize">
<size>
<width>500</width>
<height>16777215</height>
<height>60</height>
</size>
</property>
<property name="font">
Expand Down Expand Up @@ -719,12 +748,18 @@
<property name="maximumSize">
<size>
<width>500</width>
<height>16777215</height>
<height>60</height>
</size>
</property>
<property name="text">
<string>(/path/to/bin/chromium)</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
Expand Down

0 comments on commit 0b85f6b

Please sign in to comment.