diff --git a/src/modules/WireguardConfiguration.py b/src/modules/WireguardConfiguration.py index 20debfda..8eb07003 100644 --- a/src/modules/WireguardConfiguration.py +++ b/src/modules/WireguardConfiguration.py @@ -501,15 +501,24 @@ class WireguardConfiguration: with self.engine.begin() as conn: for tempPeer in self.Peers: if tempPeer.status == "running": - endpoint = tempPeer.endpoint.rsplit(":", 1) + 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() - }) - ) + exist = conn.execute( + self.peersHistoryEndpointTable.select().where( + sqlalchemy.and_( + self.peersHistoryEndpointTable.c.id == tempPeer.id, + self.peersHistoryEndpointTable.c.endpoint == endpoint[0] + ) + ) + ).mappings().fetchone() + if not exist: + conn.execute( + self.peersHistoryEndpointTable.insert().values({ + "id": tempPeer.id, + "endpoint": endpoint[0], + "time": datetime.now() + }) + ) def addPeers(self, peers: list) -> tuple[bool, list, str]: result = {