Skip to content

Commit

Permalink
ui,stats: improved nodes search
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavo-iniguez-goya committed Dec 26, 2024
1 parent 7dcba7b commit d1f58eb
Showing 1 changed file with 39 additions and 12 deletions.
51 changes: 39 additions & 12 deletions ui/opensnitch/dialogs/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -2172,10 +2172,16 @@ def _set_events_query(self):
qstr += " WHERE " + action + " ("\
" " + self.COL_STR_PROCESS + " LIKE '%" + filter_text + "%'" \
" OR " + self.COL_STR_PROC_CMDLINE + " LIKE '%" + filter_text + "%'" \
" OR " + self.COL_STR_DESTINATION + " LIKE '%" + filter_text + "%'" \
" OR " + self.COL_STR_SRC_PORT + " LIKE '%" + filter_text + "%'" \
" OR " + self.COL_STR_SRC_IP + " LIKE '%" + filter_text + "%'" \
" OR " + self.COL_STR_DST_IP + " LIKE '%" + filter_text + "%'" \
" OR " + self.COL_STR_DST_HOST + " LIKE '%" + filter_text + "%'" \
" OR " + self.COL_STR_DST_PORT + " LIKE '%" + filter_text + "%'" \
" OR " + self.COL_STR_RULE + " LIKE '%" + filter_text + "%'" \
" OR " + self.COL_STR_NODE + " LIKE '%" + filter_text + "%'" \
" OR " + self.COL_STR_TIME + " LIKE '%" + filter_text + "%'" \
" OR " + self.COL_STR_PID + " LIKE '%" + filter_text + "%'" \
" OR " + self.COL_STR_UID + " LIKE '%" + filter_text + "%'" \
" OR " + self.COL_STR_PROTOCOL + " LIKE '%" + filter_text + "%')" \

qstr += self._get_order() + self._get_limit()
Expand Down Expand Up @@ -2222,25 +2228,46 @@ def _set_nodes_query(self, data):

def _get_nodes_filter_query(self, lastQuery, text):
base_query = lastQuery.split("GROUP BY")
if not self.IN_DETAIL_VIEW[self.TAB_NODES]:
base_query = lastQuery.split("ORDER BY")

qstr = base_query[0]
if "AND" in qstr:
# strip out ANDs if any
os = qstr.split('AND')
qstr = os[0]

if text != "":
qstr += "AND (c.time LIKE '%{0}%' OR " \
"c.action LIKE '%{0}%' OR " \
"c.pid LIKE '%{0}%' OR " \
"c.src_port LIKE '%{0}%' OR " \
"c.dst_port LIKE '%{0}%' OR " \
"c.src_ip LIKE '%{0}%' OR " \
"c.dst_ip LIKE '%{0}%' OR " \
"c.dst_host LIKE '%{0}%' OR " \
"c.process LIKE '%{0}%' OR " \
"c.process_args LIKE '%{0}%')".format(text)
if len(base_query) > 1:
if self.IN_DETAIL_VIEW[self.TAB_NODES]:
qstr += "AND (c.time LIKE '%{0}%' OR " \
"c.action LIKE '%{0}%' OR " \
"c.uid LIKE '%{0}%' OR " \
"c.pid LIKE '%{0}%' OR " \
"c.src_port LIKE '%{0}%' OR " \
"c.dst_port LIKE '%{0}%' OR " \
"c.src_ip LIKE '%{0}%' OR " \
"c.dst_ip LIKE '%{0}%' OR " \
"c.dst_host LIKE '%{0}%' OR " \
"c.process LIKE '%{0}%' OR " \
"c.process_cwd LIKE '%{0}%' OR " \
"c.process_args LIKE '%{0}%')".format(text)
else:
if "WHERE" in qstr:
w = qstr.split('WHERE')
qstr = w[0]

qstr += "WHERE (" \
"last_connection LIKE '%{0}%' OR " \
"addr LIKE '%{0}%' OR " \
"status LIKE '%{0}%' OR " \
"hostname LIKE '%{0}%' OR " \
"version LIKE '%{0}%'" \
")".format(text)

if self.IN_DETAIL_VIEW[self.TAB_NODES]:
qstr += " GROUP BY" + base_query[1]
else:
qstr += " ORDER BY" + base_query[1]

return qstr

Expand Down

0 comments on commit d1f58eb

Please sign in to comment.