Skip to content

Commit 2b3028e

Browse files
ui: display all fields in the detail views
1 parent f8e2ab3 commit 2b3028e

File tree

4 files changed

+179
-61
lines changed

4 files changed

+179
-61
lines changed

ui/opensnitch/dialogs/preferences.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def _load_ui_columns_config(self):
534534
if cols == None:
535535
return
536536

537-
for c in range(8):
537+
for c in range(13):
538538
checked = str(c) in cols
539539

540540
if c == 0:
@@ -544,14 +544,26 @@ def _load_ui_columns_config(self):
544544
elif c == 2:
545545
self.checkHideAction.setChecked(checked)
546546
elif c == 3:
547-
self.checkHideDst.setChecked(checked)
547+
self.checkHideSrcPort.setChecked(checked)
548548
elif c == 4:
549-
self.checkHideProto.setChecked(checked)
549+
self.checkHideSrcIP.setChecked(checked)
550550
elif c == 5:
551-
self.checkHideProc.setChecked(checked)
551+
self.checkHideDstIP.setChecked(checked)
552552
elif c == 6:
553-
self.checkHideCmdline.setChecked(checked)
553+
self.checkHideDstHost.setChecked(checked)
554554
elif c == 7:
555+
self.checkHideDstPort.setChecked(checked)
556+
elif c == 8:
557+
self.checkHideProto.setChecked(checked)
558+
elif c == 9:
559+
self.checkHideUID.setChecked(checked)
560+
elif c == 10:
561+
self.checkHidePID.setChecked(checked)
562+
elif c == 11:
563+
self.checkHideProc.setChecked(checked)
564+
elif c == 12:
565+
self.checkHideCmdline.setChecked(checked)
566+
elif c == 13:
555567
self.checkHideRule.setChecked(checked)
556568

557569
def _reset_node_settings(self):
@@ -706,16 +718,28 @@ def _save_ui_columns_config(self):
706718
cols.append("1")
707719
if self.checkHideAction.isChecked():
708720
cols.append("2")
709-
if self.checkHideDst.isChecked():
721+
if self.checkHideSrcPort.isChecked():
710722
cols.append("3")
711-
if self.checkHideProto.isChecked():
723+
if self.checkHideSrcIP.isChecked():
712724
cols.append("4")
713-
if self.checkHideProc.isChecked():
725+
if self.checkHideDstIP.isChecked():
714726
cols.append("5")
715-
if self.checkHideCmdline.isChecked():
727+
if self.checkHideDstHost.isChecked():
716728
cols.append("6")
717-
if self.checkHideRule.isChecked():
729+
if self.checkHideDstPort.isChecked():
718730
cols.append("7")
731+
if self.checkHideProto.isChecked():
732+
cols.append("8")
733+
if self.checkHideUID.isChecked():
734+
cols.append("9")
735+
if self.checkHidePID.isChecked():
736+
cols.append("10")
737+
if self.checkHideProc.isChecked():
738+
cols.append("11")
739+
if self.checkHideCmdline.isChecked():
740+
cols.append("12")
741+
if self.checkHideRule.isChecked():
742+
cols.append("13")
719743

720744
self._cfg.setSettings(Config.STATS_SHOW_COLUMNS, cols)
721745

ui/opensnitch/dialogs/stats.py

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,22 @@ class StatsDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
4343
LAST_GROUP_BY = ""
4444

4545
# general
46-
COL_TIME = 0
47-
COL_NODE = 1
48-
COL_ACTION = 2
49-
COL_DSTIP = 3
50-
COL_PROTO = 4
51-
COL_PROCS = 5
52-
COL_CMDLINE = 6
53-
COL_RULES = 7
54-
GENERAL_COL_NUM = 8
46+
COL_TIME = 0
47+
COL_NODE = 1
48+
COL_ACTION = 2
49+
COL_SRCPORT = 3
50+
COL_SRCIP = 4
51+
COL_DSTIP = 5
52+
COL_DSTHOST = 6
53+
COL_DSTPORT = 7
54+
COL_PROTO = 8
55+
COL_UID = 9
56+
COL_PID = 10
57+
COL_PROCS = 11
58+
COL_CMDLINE = 12
59+
COL_RULES = 13
60+
# total number of columns: cols + 1
61+
GENERAL_COL_NUM = 14
5562

5663
# stats
5764
COL_WHAT = 0
@@ -135,11 +142,14 @@ class StatsDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
135142
"display_fields": "time as Time, " \
136143
"node as Node, " \
137144
"action as Action, " \
138-
"CASE dst_host WHEN ''" \
139-
" THEN dst_ip || ' -> ' || dst_port " \
140-
" ELSE dst_host || ' -> ' || dst_port " \
141-
"END Destination, " \
145+
"src_port as SrcPort, " \
146+
"src_ip as SrcIP, " \
147+
"dst_ip as DstIP, " \
148+
"dst_host as DstHost, " \
149+
"dst_port as DstPort, " \
142150
"protocol as Protocol, " \
151+
"uid as UID, " \
152+
"pid as PID, " \
143153
"process as Process, " \
144154
"process_args as Cmdline, " \
145155
"rule as Rule",
@@ -314,11 +324,14 @@ def __init__(self, parent=None, address=None, db=None, dbname="db", appicon=None
314324
self.COL_STR_PROCESS = QC.translate("stats", "Process", "This is a word, without spaces and symbols.").replace(" ", "")
315325
self.COL_STR_PROC_CMDLINE = QC.translate("stats", "Cmdline", "This is a word, without spaces and symbols.").replace(" ", "")
316326
self.COL_STR_DESTINATION = QC.translate("stats", "Destination", "This is a word, without spaces and symbols.").replace(" ", "")
327+
self.COL_STR_SRC_PORT = QC.translate("stats", "SrcPort", "This is a word, without spaces and symbols.").replace(" ", "")
328+
self.COL_STR_SRC_IP = QC.translate("stats", "SrcIP", "This is a word, without spaces and symbols.").replace(" ", "")
317329
self.COL_STR_DST_IP = QC.translate("stats", "DstIP", "This is a word, without spaces and symbols.").replace(" ", "")
318330
self.COL_STR_DST_HOST = QC.translate("stats", "DstHost", "This is a word, without spaces and symbols.").replace(" ", "")
319331
self.COL_STR_DST_PORT = QC.translate("stats", "DstPort", "This is a word, without spaces and symbols.").replace(" ", "")
320332
self.COL_STR_RULE = QC.translate("stats", "Rule", "This is a word, without spaces and symbols.").replace(" ", "")
321333
self.COL_STR_UID = QC.translate("stats", "UserID", "This is a word, without spaces and symbols.").replace(" ", "")
334+
self.COL_STR_PID = QC.translate("stats", "UserID", "This is a word, without spaces and symbols.").replace(" ", "")
322335
self.COL_STR_LAST_CONNECTION = QC.translate("stats", "LastConnection", "This is a word, without spaces and symbols.").replace(" ", "")
323336

324337
self.FIREWALL_STOPPED = QC.translate("stats", "Not running")
@@ -467,9 +480,16 @@ def __init__(self, parent=None, address=None, db=None, dbname="db", appicon=None
467480
self.COL_STR_TIME,
468481
self.COL_STR_NODE,
469482
self.COL_STR_ACTION,
470-
self.COL_STR_DESTINATION,
483+
self.COL_STR_SRC_PORT,
484+
self.COL_STR_SRC_IP,
485+
self.COL_STR_DST_IP,
486+
self.COL_STR_DST_HOST,
487+
self.COL_STR_DST_PORT,
471488
self.COL_STR_PROTOCOL,
489+
self.COL_STR_UID,
490+
self.COL_STR_PID,
472491
self.COL_STR_PROCESS,
492+
self.COL_STR_PROC_CMDLINE,
473493
self.COL_STR_RULE,
474494
]),
475495
verticalScrollBar=self.connectionsTableScrollBar,
@@ -1526,14 +1546,44 @@ def _cb_main_table_double_clicked(self, row):
15261546
self._set_rules_query(r_name, node)
15271547

15281548
elif idx == StatsDialog.COL_DSTIP:
1529-
cur_idx = self.TAB_HOSTS
1549+
cur_idx = self.TAB_ADDRS
15301550
self.IN_DETAIL_VIEW[cur_idx] = True
15311551
rowdata = row.model().index(row.row(), self.COL_DSTIP).data()
1532-
hostip = rowdata.split(" ")[0]
1533-
self.LAST_SELECTED_ITEM = hostip
1552+
ip = rowdata
1553+
self.LAST_SELECTED_ITEM = ip
1554+
self.tabWidget.setCurrentIndex(cur_idx)
1555+
self._set_active_widgets(prev_idx, True, ip)
1556+
self._set_addrs_query(ip)
1557+
1558+
elif idx == StatsDialog.COL_DSTHOST:
1559+
cur_idx = self.TAB_HOSTS
1560+
self.IN_DETAIL_VIEW[cur_idx] = True
1561+
rowdata = row.model().index(row.row(), self.COL_DSTHOST).data()
1562+
host = rowdata
1563+
self.LAST_SELECTED_ITEM = host
1564+
self.tabWidget.setCurrentIndex(cur_idx)
1565+
self._set_active_widgets(prev_idx, True, host)
1566+
self._set_hosts_query(host)
1567+
1568+
elif idx == StatsDialog.COL_DSTPORT:
1569+
cur_idx = self.TAB_PORTS
1570+
self.IN_DETAIL_VIEW[cur_idx] = True
1571+
rowdata = row.model().index(row.row(), self.COL_DSTPORT).data()
1572+
port = rowdata
1573+
self.LAST_SELECTED_ITEM = port
1574+
self.tabWidget.setCurrentIndex(cur_idx)
1575+
self._set_active_widgets(prev_idx, True, port)
1576+
self._set_ports_query(port)
1577+
1578+
elif idx == StatsDialog.COL_UID:
1579+
cur_idx = self.TAB_USERS
1580+
self.IN_DETAIL_VIEW[cur_idx] = True
1581+
rowdata = row.model().index(row.row(), self.COL_UID).data()
1582+
uid = rowdata
1583+
self.LAST_SELECTED_ITEM = uid
15341584
self.tabWidget.setCurrentIndex(cur_idx)
1535-
self._set_active_widgets(prev_idx, True, hostip)
1536-
self._set_hosts_query(hostip)
1585+
self._set_active_widgets(prev_idx, True, uid)
1586+
self._set_users_query(uid)
15371587

15381588
else:
15391589
cur_idx = self.TAB_PROCS

ui/opensnitch/nodes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ def get_nodes(self):
168168

169169
def get_node_config(self, addr):
170170
try:
171+
if addr not in self._nodes:
172+
return None
171173
return self._nodes[addr]['data'].config
172174
except Exception as e:
173175
print(self.LOG_TAG + " exception get_node_config(): ", e)

0 commit comments

Comments
 (0)