From 809651054e975aaa309a994ebb0c07b17e659380 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Thu, 5 Sep 2024 16:17:56 +0800 Subject: [PATCH] Update dashboard.py --- src/dashboard.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index c3cd6f1..4378511 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -659,7 +659,8 @@ class WireguardConfiguration: (i.get("AllowedIPs", "N/A"), i['PublicKey'],)) self.Peers.append(Peer(checkIfExist, self)) except Exception as e: - print(f"[WGDashboard] {self.Name} Error: {str(e)}") + if __name__ == '__main__': + print(f"[WGDashboard] {self.Name} Error: {str(e)}") else: self.Peers.clear() checkIfExist = sqlSelect("SELECT * FROM '%s'" % self.Name).fetchall() @@ -1363,7 +1364,10 @@ def _getWireguardConfigurationAvailableIP(configName: str, all: bool = False) -> add = p.allowed_ip.split(',') for i in add: a, c = i.split('/') - existedAddress.append(ipaddress.ip_address(a.replace(" ", ""))) + try: + existedAddress.append(ipaddress.ip_address(a.replace(" ", ""))) + except ValueError as error: + print(f"[WGDashboard] Error: {configName} peer {p.id} have invalid ip") for p in configuration.getRestrictedPeersList(): if len(p.allowed_ip) > 0: @@ -1402,8 +1406,8 @@ def sqlSelect(statement: str, paramters: tuple = ()) -> sqlite3.Cursor: def sqlUpdate(statement: str, paramters: tuple = ()) -> sqlite3.Cursor: with sqldb: cursor = sqldb.cursor() - cursor.execute(statement, paramters) try: + cursor.execute(statement, paramters) sqldb.commit() except sqlite3.OperationalError as error: print("[WGDashboard] SQLite Error:" + str(error))