From 9caed31185d03a41f5b98332ac1d2cd03eefb06a Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Fri, 5 Sep 2025 17:57:50 +0800 Subject: [PATCH] Added IP logging for #525 --- src/dashboard.py | 1 + src/modules/DashboardClients.py | 11 +++++----- src/modules/WireguardConfiguration.py | 31 ++++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index 3090dd15..db3ab53b 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -1519,6 +1519,7 @@ def peerInformationBackgroundThread(): c.getPeers() if delay == 6: c.logPeersTraffic() + c.logPeersHistoryEndpoint() c.getRestrictedPeersList() except Exception as e: print(f"[WGDashboard] Background Thread #1 Error: {str(e)}", flush=True) diff --git a/src/modules/DashboardClients.py b/src/modules/DashboardClients.py index f783a4f1..231d0991 100644 --- a/src/modules/DashboardClients.py +++ b/src/modules/DashboardClients.py @@ -452,9 +452,10 @@ class DashboardClients: with self.engine.connect() as conn: t = conn.execute( self.dashboardClientsPasswordResetLinkTable.select().where( - self.dashboardClientsPasswordResetLinkTable.c.ClientID == ClientID, - self.dashboardClientsPasswordResetLinkTable.c.ResetToken == Token, - self.dashboardClientsPasswordResetLinkTable.c.ExpiryDate > datetime.datetime.now() + db.and_(self.dashboardClientsPasswordResetLinkTable.c.ClientID == ClientID, + self.dashboardClientsPasswordResetLinkTable.c.ResetToken == Token, + self.dashboardClientsPasswordResetLinkTable.c.ExpiryDate > datetime.datetime.now()) + ) ).mappings().fetchone() return t is not None @@ -465,8 +466,8 @@ class DashboardClients: self.dashboardClientsPasswordResetLinkTable.update().values({ "ExpiryDate": datetime.datetime.now() }).where( - self.dashboardClientsPasswordResetLinkTable.c.ClientID == ClientID, - self.dashboardClientsPasswordResetLinkTable.c.ResetToken == Token + db.and_(self.dashboardClientsPasswordResetLinkTable.c.ClientID == ClientID, + self.dashboardClientsPasswordResetLinkTable.c.ResetToken == Token) ) ) return True diff --git a/src/modules/WireguardConfiguration.py b/src/modules/WireguardConfiguration.py index 5e740953..744833ae 100644 --- a/src/modules/WireguardConfiguration.py +++ b/src/modules/WireguardConfiguration.py @@ -291,6 +291,16 @@ class WireguardConfiguration: server_default=sqlalchemy.func.now()), extend_existing=True ) + + self.peersHistoryEndpointTable = sqlalchemy.Table( + f'{dbName}_history_endpoint', self.metadata, + sqlalchemy.Column('id', sqlalchemy.String(255), nullable=False), + sqlalchemy.Column('endpoint', sqlalchemy.String(255), nullable=False), + sqlalchemy.Column('time', + (sqlalchemy.DATETIME if self.DashboardConfig.GetConfig("Database", "type")[1] == 'sqlite' else sqlalchemy.TIMESTAMP)), + extend_existing=True + ) + self.peersDeletedTable = sqlalchemy.Table( f'{dbName}_deleted', self.metadata, sqlalchemy.Column('id', sqlalchemy.String(255), nullable=False, primary_key=True), @@ -454,7 +464,6 @@ class WireguardConfiguration: with self.engine.begin() as conn: for tempPeer in self.Peers: if tempPeer.status == "running": - print(tempPeer.id + " running") conn.execute( self.peersTransferTable.insert().values({ "id": tempPeer.id, @@ -467,8 +476,24 @@ class WireguardConfiguration: "time": datetime.now() }) ) - + def logPeersHistoryEndpoint(self): + with self.engine.begin() as conn: + for tempPeer in self.Peers: + if tempPeer.status == "running": + endpoint = tempPeer.endpoint.rsplit(":", 1) + if len(endpoint) == 2 and len(endpoint[0]) > 0: + conn.execute( + self.peersHistoryEndpointTable.insert().values({ + "id": tempPeer.id, + "endpoint": endpoint[0], + "time": datetime.now() + }) + ) + + + + def addPeers(self, peers: list) -> tuple[bool, dict]: result = { "message": None, @@ -792,7 +817,7 @@ class WireguardConfiguration: ) count += 2 - def toggleConfiguration(self) -> [bool, str]: + def toggleConfiguration(self) -> tuple[bool, str] | tuple[bool, None]: self.getStatus() if self.Status: try: