Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ui/opensnitch/customwidgets/generictableview.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ def onKeyDown(self):
self._rows_selection.clear()
self._rows_selection.add(curIdx.data())

viewport_row = self.getViewportRowPos(curRow)
newValue = self.vScrollBar.value()

offset = self.model().queryOffset
Expand Down
1 change: 1 addition & 0 deletions ui/opensnitch/customwidgets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def refreshViewport(self, value, maxRowsInViewport):
#sequential number of topmost/bottommost rows in viewport (numbering starts from the bottom with 1 not with 0)
botRowNo = max(1, self.totalRowCount - (value + maxRowsInViewport-1))
topRowNo = min(botRowNo + maxRowsInViewport-1, self.totalRowCount)
offsetInRange = 0

if not self.isQueryFilter:
part1, part2 = self.origQueryStr.split('ORDER')
Expand Down
13 changes: 9 additions & 4 deletions ui/opensnitch/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ def remove(self, qstr, args=None):

def _insert(self, query_str, columns):
with self._lock:
q = None
try:

q = QSqlQuery(self.db)
q.prepare(query_str)
for idx, v in enumerate(columns):
Expand All @@ -465,7 +465,8 @@ def _insert(self, query_str, columns):
except Exception as e:
self.logger.warning("_insert exception: %s", repr(e))
finally:
q.finish()
if q is not None:
q.finish()

return False

Expand Down Expand Up @@ -497,6 +498,7 @@ def update(self, table, fields, values, condition=None, action_on_conflict="OR I
qstr = "UPDATE " + action_on_conflict + " " + table + " SET " + fields
if condition is not None:
qstr += " WHERE " + condition
q = None
try:
with self._lock:
q = QSqlQuery(qstr, self.db)
Expand All @@ -510,11 +512,13 @@ def update(self, table, fields, values, condition=None, action_on_conflict="OR I
except Exception as e:
self.logger.warning("update() exception: %s", repr(e))
finally:
q.finish()
if q is not None:
q.finish()

def _insert_batch(self, query_str, fields, values):
result=True
with self._lock:
q = None
try:
q = QSqlQuery(self.db)
q.prepare(query_str)
Expand All @@ -530,7 +534,8 @@ def _insert_batch(self, query_str, fields, values):
except Exception as e:
self.logger.warning("_insert_batch() exception: %s", repr(e))
finally:
q.finish()
if q is not None:
q.finish()

return result

Expand Down
7 changes: 4 additions & 3 deletions ui/opensnitch/desktop_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import re
import locale

is_pyinotify_available = True
try:
import pyinotify
except Exception as e:
is_pyinotify_available = False
pyinotify = None
print("Error importing pyinotify:", e)

DESKTOP_PATHS = tuple([
Expand Down Expand Up @@ -47,7 +46,7 @@ def __init__(self):
for desktop_file in glob.glob(os.path.join(desktop_path, '*.desktop')):
self._parse_desktop_file(desktop_file)

if is_pyinotify_available:
if pyinotify is not None:
self.start()

def get_locale(self):
Expand Down Expand Up @@ -179,6 +178,8 @@ def get_info_by_binname(self, name, default_icon):
return self.apps.get(def_name, (def_name, default_icon, None))

def run(self):
if pyinotify is None:
return
self.running = True
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(wm)
Expand Down
1 change: 1 addition & 0 deletions ui/opensnitch/dialogs/events/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def configure_fwrules_contextual_menu(self, pos):
rule_action = model.index(selection[0].row(), FirewallTableModel.COL_ACTION).data()
rule_action = rule_action.lower()

_action_accept = _action_drop = _action_reject = _action_return = None
nodes_menu = []
if self.nodes_count() > 1:
nodes_menu.append(
Expand Down
2 changes: 2 additions & 0 deletions ui/opensnitch/dialogs/events/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ def get_filter_line(self, idx, text, adv_search=None):

def get_indetail_filter(self, indetail_view, lastQuery, text, advanced_filter):
"""builds the query when a tab is in the detail view."""
base_query = []
qstr = ""
try:
cur_idx = self.win.get_current_view_idx()
base_query = lastQuery.split("GROUP BY")
Expand Down
2 changes: 1 addition & 1 deletion ui/opensnitch/dialogs/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ def on_menu_import_clicked(self, triggered):
QtWidgets.QMessageBox.Icon.Warning)

def on_cmd_back_clicked(self, idx):
cur_idx = self.get_current_view_idx()
try:
cur_idx = self.get_current_view_idx()
self.set_in_detail_view(cur_idx, False)

self.set_active_widgets(cur_idx, False)
Expand Down
1 change: 1 addition & 0 deletions ui/opensnitch/dialogs/prompt/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ def _display_checksums_warning(self, peer, con):
self.set_message_style('')
self.labelChecksumStatus.setText('')
is_valid = True
expected = ""
checksums = con.process_checksums
expected_list = []

Expand Down
21 changes: 1 addition & 20 deletions ui/opensnitch/firewall/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,6 @@ def get(self):
chains[node] = self.get_node_chains(node)
return chains

def get_node_chains(self, addr):
node = self._nodes.get_node(addr)
if node == None:
return rules
if not 'firewall' in node:
return rules

chains = []
for c in node['firewall'].SystemRules:
# Chains node does not exist on <= v1.5.x
try:
chains.append(c.Chains)
except Exception:
pass
return chains

def get_node_chains(self, addr):
node = self._nodes.get_node(addr)
if node is None:
Expand Down Expand Up @@ -65,10 +49,7 @@ def set_policy(self, node_addr, hook=Hooks.INPUT.value, _type=ChainType.FILTER.v
# specify ipv4 OR/AND ipv6? some systems have ipv6 disabled
if c.Hook.lower() == hook and c.Type.lower() == _type and c.Family.lower() == family:
fwcfg.SystemRules[sdx].Chains[cdx].Policy = policy

if wantedHook == Fw.Hooks.INPUT.value and wantedPolicy == Fw.Policy.DROP.value:
fwcfg.SystemRules[sdx].Chains[cdx].Rules.extend([rule.Rules[0]])
self._nodes.add_fw_config(node_addr, fwcfg)
self._nodes.add_fw_config(node_addr, fwcfg)
return True
return False

Expand Down
4 changes: 0 additions & 4 deletions ui/opensnitch/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ def connect(self, callback):
def disconnect(self, callback):
self.signal.disconnect(callback)

#@QtCore.pyqtSlot(dict)
def cb_signal(self, args):
self.signal.disconnect(callback)

class PluginsList():
"""plugins store. Whenever a plugin is instantiated, it's added to the
plugin list automatically
Expand Down
1 change: 1 addition & 0 deletions ui/opensnitch/plugins/downloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def compile(self):
interval = ((float(config['interval']) * 60) * 60) * 60
else:
logger.warning("compile() unknown time format '{0}'".format(config['units']))
continue

self.scheduled_tasks[config['name']] = self.new_timer(interval, config)
except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions ui/opensnitch/plugins/virustotal/virustotal.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ def update_popup(self, what, response, parent, config, conn, errmsg=None):

error = (errmsg is not None)
malicious = False
verdict = None
labelStyle = "color: {0}".format(config['benign-label-style'])
try:
if error:
Expand Down
1 change: 1 addition & 0 deletions ui/opensnitch/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def export_rule(self, node, rule_name, outdir):
"""Gets the rule from the DB and writes it out to a directory.
A new directory per node will be created.
"""
rulesdir = outdir
try:
records = self._db.get_rule(rule_name, node)
if records.next() == False:
Expand Down
4 changes: 3 additions & 1 deletion ui/opensnitch/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ def callback_open_clicked(notifObject, action):
self._stats_dialog.activateWindow()

has_ntfs, ntf_type = self._has_desktop_notifications()
timeout = self._cfg.getInt(Config.DEFAULT_TIMEOUT_KEY, 15)
if has_ntfs:
timeout = self._cfg.getInt(Config.DEFAULT_TIMEOUT_KEY, 15)
try:
self.show_systray_msg(
title,
Expand Down Expand Up @@ -636,6 +636,8 @@ def _is_local_request(self, proto, addr):
return False

def _build_missed_rule_msg(self, conn, rule, node, hostname):
_title = ""
tmpl = ""
try:
_title = conn.process_path
if _title == "":
Expand Down
1 change: 1 addition & 0 deletions ui/opensnitch/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def new(widget, icon_name):
def get_by_appname(app_icon):
"""return the pixmap of an application.
"""
pixmap = None
try:
icon = QtGui.QIcon().fromTheme(app_icon)
pixmap = icon.pixmap(icon.actualSize(QtCore.QSize(48, 48)))
Expand Down