Skip to content

Commit e7c36e2

Browse files
ui,prefs: improved node management
Added better alerts when changing nodes or server address.
1 parent 5b67e2e commit e7c36e2

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

ui/opensnitch/dialogs/preferences.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def _load_node_settings(self):
519519
print(self.LOG_TAG + "exception loading config: ", e)
520520
self._set_status_error(QC.translate("preferences", "Error loading config {0}: {1}".format(addr, e)))
521521

522-
def _load_node_config(self, addr):
522+
def _build_node_config(self, addr):
523523
"""load the config of a node before sending it back to the node"""
524524
try:
525525
if self.comboNodeAddress.currentText() == "":
@@ -534,7 +534,7 @@ def _load_node_config(self, addr):
534534
node_duration = Config.DURATION_ONCE
535535

536536
node_conf = self._nodes.get_node_config(addr)
537-
if node_conf == None:
537+
if node_conf is None:
538538
return None, " "
539539
node_config = json.loads(node_conf)
540540
node_config['DefaultAction'] = node_action
@@ -631,6 +631,11 @@ def _load_node_auth_settings(self, config):
631631
config['Authentication'] = {}
632632
auth = config.get('Authentication')
633633

634+
self.lineNodeCACertFile.blockSignals(True)
635+
self.lineNodeServerCertFile.blockSignals(True)
636+
self.lineNodeCertFile.blockSignals(True)
637+
self.lineNodeCertKeyFile.blockSignals(True)
638+
634639
self.lineNodeCACertFile.setEnabled(authtype_idx >= 0)
635640
self.lineNodeServerCertFile.setEnabled(authtype_idx >= 0)
636641
self.lineNodeCertFile.setEnabled(authtype_idx >= 0)
@@ -661,6 +666,12 @@ def _load_node_auth_settings(self, config):
661666
print("[prefs] load node auth options exception:", e)
662667
self._set_status_error(QC.translate("preferences", "Error loading node auth config: {0}".format(e)))
663668

669+
finally:
670+
self.lineNodeCACertFile.blockSignals(False)
671+
self.lineNodeServerCertFile.blockSignals(False)
672+
self.lineNodeCertFile.blockSignals(False)
673+
self.lineNodeCertKeyFile.blockSignals(False)
674+
664675
def _save_node_auth_config(self, config):
665676
try:
666677
auth = config.get('Authentication')
@@ -952,17 +963,23 @@ def _save_node_config(self, notifObject, addr):
952963
try:
953964
if self._nodes.count() == 0:
954965
return
966+
if not self._nodes.is_connected(addr):
967+
return
955968
self._set_status_message(QC.translate("preferences", "Applying configuration on {0} ...").format(addr))
956-
notifObject.data, error = self._load_node_config(addr)
969+
notifObject.data, error = self._build_node_config(addr)
957970
if error != None:
958971
return error
959972

960973
# exclude this message if there're more than one node connected
961974
# XXX: unix:/local is a special name for the node, when the gRPC
962975
# does not return the correct address of the node.
963-
naddr = self.get_node_addr()
964-
if (naddr != "unix:/local" and naddr != self.comboNodeAddress.currentText()) or \
965-
self.comboServerAddr.currentText() != self.comboNodeAddress.currentText():
976+
current_node = self.get_node_addr()
977+
node_address = self.comboNodeAddress.currentText()
978+
server_addr = self.comboServerAddr.currentText()
979+
if server_addr.startswith("unix:") and (current_node != node_address or \
980+
server_addr != node_address):
981+
self._changes_needs_restart = QC.translate("preferences", "Node address changed (update GUI address if needed)")
982+
if node_address.startswith("unix:") and server_addr.startswith("unix:") is False:
966983
self._changes_needs_restart = QC.translate("preferences", "Node address changed (update GUI address if needed)")
967984

968985
self._nodes.save_node_config(addr, notifObject.data)
@@ -971,7 +988,11 @@ def _save_node_config(self, notifObject, addr):
971988

972989
except Exception as e:
973990
print(self.LOG_TAG + "exception saving node config on %s: " % addr, e)
974-
self._set_status_error(QC.translate("preferences", "Exception saving node config {0}: {1}").format((addr, str(e))))
991+
self._set_status_error(
992+
QC.translate("preferences", "Exception saving node config {0}: {1}").format(
993+
addr, str(e)
994+
)
995+
)
975996
return addr + ": " + str(e)
976997

977998
return None

0 commit comments

Comments
 (0)