Update dashboard.py

This commit is contained in:
Donald Zou 2024-09-05 16:17:56 +08:00
parent 2e965ceb9e
commit 809651054e

View File

@ -659,6 +659,7 @@ class WireguardConfiguration:
(i.get("AllowedIPs", "N/A"), i['PublicKey'],)) (i.get("AllowedIPs", "N/A"), i['PublicKey'],))
self.Peers.append(Peer(checkIfExist, self)) self.Peers.append(Peer(checkIfExist, self))
except Exception as e: except Exception as e:
if __name__ == '__main__':
print(f"[WGDashboard] {self.Name} Error: {str(e)}") print(f"[WGDashboard] {self.Name} Error: {str(e)}")
else: else:
self.Peers.clear() self.Peers.clear()
@ -1363,7 +1364,10 @@ def _getWireguardConfigurationAvailableIP(configName: str, all: bool = False) ->
add = p.allowed_ip.split(',') add = p.allowed_ip.split(',')
for i in add: for i in add:
a, c = i.split('/') a, c = i.split('/')
try:
existedAddress.append(ipaddress.ip_address(a.replace(" ", ""))) 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(): for p in configuration.getRestrictedPeersList():
if len(p.allowed_ip) > 0: 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: def sqlUpdate(statement: str, paramters: tuple = ()) -> sqlite3.Cursor:
with sqldb: with sqldb:
cursor = sqldb.cursor() cursor = sqldb.cursor()
cursor.execute(statement, paramters)
try: try:
cursor.execute(statement, paramters)
sqldb.commit() sqldb.commit()
except sqlite3.OperationalError as error: except sqlite3.OperationalError as error:
print("[WGDashboard] SQLite Error:" + str(error)) print("[WGDashboard] SQLite Error:" + str(error))