diff --git a/ui/bin/opensnitch-ui b/ui/bin/opensnitch-ui index 97e15ed8bd..9f825f25c3 100755 --- a/ui/bin/opensnitch-ui +++ b/ui/bin/opensnitch-ui @@ -1,6 +1,8 @@ #!/usr/bin/env python3 from PyQt5 import QtWidgets, QtGui, QtCore +from opensnitch.config import Config +from opensnitch.utils import Utils import sys import os @@ -66,6 +68,18 @@ if __name__ == '__main__': thm = Themes.instance() thm.load_theme(app) + Utils.create_socket_dirs() + if args.socket == "unix:///tmp/osui.sock": + cfg = Config.get() + addr = cfg.getSettings(Config.DEFAULT_SERVER_ADDR) + if addr != None and addr != "" and addr.startswith("unix://"): + if not os.path.exists(os.path.dirname(addr[7:])): + print("WARNING: unix socket path does not exist, using unix:///tmp/osui.sock, ", addr) + else: + args.socket = addr + + print("Using server address:", args.socket) + service = UIService(app, on_exit) # @doc: https://grpc.github.io/grpc/python/grpc.html#server-object server = grpc.server(futures.ThreadPoolExecutor(), diff --git a/ui/opensnitch/dialogs/preferences.py b/ui/opensnitch/dialogs/preferences.py index 70075db12e..cd7df51020 100644 --- a/ui/opensnitch/dialogs/preferences.py +++ b/ui/opensnitch/dialogs/preferences.py @@ -107,6 +107,15 @@ def showEvent(self, event): self._hide_status_label() self.comboNodes.clear() + self.comboNodeAddress.clear() + run_path = "/run/user/{0}/opensnitch/".format(os.getuid()) + var_run_path = "/var{0}".format(run_path) + self.comboNodeAddress.addItem("unix:///tmp/osui.sock") + if os.path.exists(run_path): + self.comboNodeAddress.addItem("unix://%s/osui.sock" % run_path) + if os.path.exists(var_run_path): + self.comboNodeAddress.addItem("unix://%s/osui.sock" % var_run_path) + self._node_list = self._nodes.get() for addr in self._node_list: self.comboNodes.addItem(addr) @@ -265,8 +274,7 @@ def _load_node_config(self, addr): if node_config.get('Server') != None: # skip setting Server Address if we're applying the config to all nodes - if self.checkApplyToNodes.isChecked(): - node_config['Server']['Address'] = self.comboNodeAddress.currentText() + node_config['Server']['Address'] = self.comboNodeAddress.currentText() node_config['Server']['LogFile'] = self.comboNodeLogFile.currentText() else: print(addr, " doesn't have Server item") @@ -442,13 +450,18 @@ def _save_node_config(self, notifObject, addr): if error != None: return error - if addr.startswith("unix://"): - self._cfg.setSettings(self._cfg.DEFAULT_DEFAULT_SERVER_ADDR, self.comboNodeAddress.currentText()) - else: - self._nodes.save_node_config(addr, notifObject.data) - nid = self._nodes.send_notification(addr, notifObject, self._notification_callback) + if addr.startswith("unix:/"): + if self._cfg.getSettings(Config.DEFAULT_SERVER_ADDR) != self.comboNodeAddress.currentText(): + Message.ok( + QC.translate("preferences", "Ok"), + QC.translate("preferences", "Restart the GUI in order changes to take effect"), + QtWidgets.QMessageBox.Information) + + self._cfg.setSettings(Config.DEFAULT_SERVER_ADDR, self.comboNodeAddress.currentText()) - self._notifications_sent[nid] = notifObject + self._nodes.save_node_config(addr, notifObject.data) + nid = self._nodes.send_notification(addr, notifObject, self._notification_callback) + self._notifications_sent[nid] = notifObject except Exception as e: print(self.LOG_TAG + "exception saving node config on %s: " % addr, e) self._set_status_error(QC.translate("Exception saving node config {0}: {1}").format((addr, str(e)))) diff --git a/ui/opensnitch/utils.py b/ui/opensnitch/utils.py index a9e6115274..d6c6bd88c4 100644 --- a/ui/opensnitch/utils.py +++ b/ui/opensnitch/utils.py @@ -278,6 +278,21 @@ def get_interfaces(): ))[0] return names.tobytes(), outbytes + @staticmethod + def create_socket_dirs(): + """https://www.linuxbase.org/betaspecs/fhs/fhs.html#runRuntimeVariableData + """ + run_path = "/run/user/{0}".format(os.getuid()) + var_run_path = "/var{0}".format(run_path) + + try: + if os.path.exists(run_path): + os.makedirs(run_path + "/opensnitch/") + if os.path.exists(var_run_path): + os.makedirs(var_run_path + "/opensnitch/") + except: + pass + class Message(): @staticmethod