mirror of
https://github.com/evilsocket/opensnitch.git
synced 2025-03-04 08:34:40 +01:00
Added UI alerts to warn about unanswered connections
This commit is contained in:
commit
6b77ce1346
4 changed files with 36 additions and 5 deletions
|
@ -50,6 +50,7 @@ class PromptDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
|||
self._tick_thread = None
|
||||
self._done = threading.Event()
|
||||
self._apply_text = "Apply"
|
||||
self._timeout_triggered = False
|
||||
|
||||
self._apps_parser = LinuxDesktopParser()
|
||||
|
||||
|
@ -104,6 +105,7 @@ class PromptDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
|||
self._tick = self._cfg.default_timeout
|
||||
self._tick_thread = threading.Thread(target=self._timeout_worker)
|
||||
self._tick_thread.stop = self._is_advanced_checked
|
||||
self._timeout_triggered = False
|
||||
self._rule = None
|
||||
self._local = is_local
|
||||
self._peer = peer
|
||||
|
@ -116,7 +118,7 @@ class PromptDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
|||
# wait for user choice or timeout
|
||||
self._done.wait()
|
||||
|
||||
return self._rule
|
||||
return self._rule, self._timeout_triggered
|
||||
|
||||
def _timeout_worker(self):
|
||||
while self._tick > 0 and self._done.is_set() is False:
|
||||
|
@ -143,6 +145,7 @@ class PromptDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
|||
|
||||
@QtCore.pyqtSlot()
|
||||
def on_timeout_triggered(self):
|
||||
self._timeout_triggered = True
|
||||
self._on_apply_clicked()
|
||||
|
||||
def _render_connection(self, con):
|
||||
|
|
|
@ -21,6 +21,7 @@ class StatsDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
|||
GREEN = QtGui.QColor(0x2e, 0x90, 0x59)
|
||||
|
||||
_trigger = QtCore.pyqtSignal()
|
||||
_shown_trigger = QtCore.pyqtSignal()
|
||||
|
||||
SORT_ORDER = ["ASC", "DESC"]
|
||||
LAST_ORDER_TO = 1
|
||||
|
@ -188,6 +189,10 @@ class StatsDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
|||
if address is not None:
|
||||
self.setWindowapply_Title("OpenSnitch Network Statistics for %s" % address)
|
||||
|
||||
def showEvent(self, event):
|
||||
super(StatsDialog, self).showEvent(event)
|
||||
self._shown_trigger.emit()
|
||||
|
||||
def _load_settings(self):
|
||||
dialog_geometry = self._cfg.getSettings("statsDialog/geometry")
|
||||
dialog_last_tab = self._cfg.getSettings("statsDialog/last_tab")
|
||||
|
|
BIN
ui/opensnitch/res/icon-alert.png
Normal file
BIN
ui/opensnitch/res/icon-alert.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 109 KiB |
|
@ -1,4 +1,4 @@
|
|||
from PyQt5 import QtWidgets, QtGui, QtCore
|
||||
from PyQt5 import QtWidgets, QtGui, QtCore, Qt
|
||||
from PyQt5.QtSql import QSqlDatabase, QSqlDatabase, QSqlQueryModel, QSqlQuery
|
||||
|
||||
from datetime import datetime
|
||||
|
@ -88,6 +88,7 @@ class UIService(ui_pb2_grpc.UIServicer, QtWidgets.QGraphicsObject):
|
|||
self._version_warning_trigger.connect(self._on_diff_versions)
|
||||
self._status_change_trigger.connect(self._on_status_change)
|
||||
self._new_remote_trigger.connect(self._on_new_remote)
|
||||
self._stats_dialog._shown_trigger.connect(self._on_stats_dialog_shown)
|
||||
|
||||
def _setup_icons(self):
|
||||
self.off_image = QtGui.QPixmap(os.path.join(self._path, "res/icon-off.png"))
|
||||
|
@ -99,6 +100,9 @@ class UIService(ui_pb2_grpc.UIServicer, QtWidgets.QGraphicsObject):
|
|||
self.red_image = QtGui.QPixmap(os.path.join(self._path, "res/icon-red.png"))
|
||||
self.red_icon = QtGui.QIcon()
|
||||
self.red_icon.addPixmap(self.red_image, QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.alert_image = QtGui.QPixmap(os.path.join(self._path, "res/icon-alert.png"))
|
||||
self.alert_icon = QtGui.QIcon()
|
||||
self.alert_icon.addPixmap(self.alert_image, QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
|
||||
self._app.setWindowIcon(self.white_icon)
|
||||
self._prompt_dialog.setWindowIcon(self.white_icon)
|
||||
|
@ -106,14 +110,21 @@ class UIService(ui_pb2_grpc.UIServicer, QtWidgets.QGraphicsObject):
|
|||
def _setup_tray(self):
|
||||
self._menu = QtWidgets.QMenu()
|
||||
self._stats_action = self._menu.addAction("Statistics")
|
||||
self._stats_action.triggered.connect(lambda: self._stats_dialog.show())
|
||||
self._menu.addAction("Close").triggered.connect(self._on_exit)
|
||||
|
||||
self._tray = QtWidgets.QSystemTrayIcon(self.off_icon)
|
||||
self._tray.setContextMenu(self._menu)
|
||||
|
||||
self._stats_action.triggered.connect(self._show_stats_dialog)
|
||||
self._menu.addAction("Close").triggered.connect(self._on_exit)
|
||||
|
||||
self._tray.show()
|
||||
if not self._tray.isSystemTrayAvailable():
|
||||
self._stats_dialog.show()
|
||||
|
||||
def _show_stats_dialog(self):
|
||||
self._tray.setIcon(self.white_icon)
|
||||
self._stats_dialog.show()
|
||||
|
||||
@QtCore.pyqtSlot()
|
||||
def _on_status_change(self):
|
||||
self._stats_dialog.daemon_connected = self._connected
|
||||
|
@ -147,6 +158,10 @@ class UIService(ui_pb2_grpc.UIServicer, QtWidgets.QGraphicsObject):
|
|||
self._menu.insertAction(self._stats_action, new_act)
|
||||
self._stats_action.setText("Local Statistics")
|
||||
|
||||
@QtCore.pyqtSlot()
|
||||
def _on_stats_dialog_shown(self):
|
||||
self._tray.setIcon(self.white_icon)
|
||||
|
||||
def _on_remote_stats_menu(self, address):
|
||||
self._remote_stats[address].show()
|
||||
|
||||
|
@ -295,7 +310,15 @@ class UIService(ui_pb2_grpc.UIServicer, QtWidgets.QGraphicsObject):
|
|||
|
||||
def AskRule(self, request, context):
|
||||
self._asking = True
|
||||
rule = self._prompt_dialog.promptUser(request, self._is_local_request(context), context.peer())
|
||||
rule, timeout_triggered = self._prompt_dialog.promptUser(request, self._is_local_request(context), context.peer())
|
||||
if timeout_triggered:
|
||||
_title = request.process_path
|
||||
if _title == "":
|
||||
_title = "%s:%d (%s)" % (request.dst_host, request.dst_port, request.protocol)
|
||||
|
||||
self._tray.setIcon(self.alert_icon)
|
||||
self._tray.showMessage(_title, "%s action applied\nArguments: %s" % (rule.action, request.process_args), QtWidgets.QSystemTrayIcon.Warning, 0)
|
||||
|
||||
self._last_ping = datetime.now()
|
||||
self._asking = False
|
||||
return rule
|
||||
|
|
Loading…
Add table
Reference in a new issue