Skip to content

Commit

Permalink
ui, rules: replace rules received from the daemon
Browse files Browse the repository at this point in the history
We added UPSERTS, to update the time of a rule when a connection matched
that rule.

However UPSERTS in SQLite weren't introduced until v3.24.x, thus it
causes errors on older versions (like the ones shipped with Ubuntu
16/18).

On the other hand, we need to replace the rules once we receive them
from the daemon, to reflect on the GUI any change made on the rules by hand.

More info: #344
  • Loading branch information
gustavo-iniguez-goya committed Feb 13, 2021
1 parent f0384fb commit 510a351
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ui/opensnitch/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ def insert(self, table, fields, columns, update_field=None, update_values=None,
qstr = qstr[0:len(qstr)-1] + ")"

if update_field != None:
# NOTE: UPSERTS on sqlite are only supported from v3.24 on.
# On Ubuntu16.04/18 for example (v3.11/3.22) updating a record on conflict
# fails with "Parameter count error"
qstr += " ON CONFLICT (" + update_field + ") DO UPDATE SET "
for idx, field in enumerate(update_values):
qstr += str(field) + "=excluded." + str(field) + ","
Expand Down
4 changes: 1 addition & 3 deletions ui/opensnitch/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,7 @@ def _populate_stats(self, db, proto, addr, stats):
event.rule.action, event.rule.duration,
event.rule.operator.type, str(event.rule.operator.sensitive),
event.rule.operator.operand, event.rule.operator.data),
update_field="node,name",
update_values=["time"],
action_on_conflict="IGNORE")
action_on_conflict="REPLACE")

details_need_refresh = self._populate_stats_details(db, addr, stats)
self._last_stats[addr] = []
Expand Down

0 comments on commit 510a351

Please sign in to comment.