mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-10-03 07:46:18 +00:00
Added IP logging for #525
This commit is contained in:
@@ -1519,6 +1519,7 @@ def peerInformationBackgroundThread():
|
|||||||
c.getPeers()
|
c.getPeers()
|
||||||
if delay == 6:
|
if delay == 6:
|
||||||
c.logPeersTraffic()
|
c.logPeersTraffic()
|
||||||
|
c.logPeersHistoryEndpoint()
|
||||||
c.getRestrictedPeersList()
|
c.getRestrictedPeersList()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[WGDashboard] Background Thread #1 Error: {str(e)}", flush=True)
|
print(f"[WGDashboard] Background Thread #1 Error: {str(e)}", flush=True)
|
||||||
|
@@ -452,9 +452,10 @@ class DashboardClients:
|
|||||||
with self.engine.connect() as conn:
|
with self.engine.connect() as conn:
|
||||||
t = conn.execute(
|
t = conn.execute(
|
||||||
self.dashboardClientsPasswordResetLinkTable.select().where(
|
self.dashboardClientsPasswordResetLinkTable.select().where(
|
||||||
self.dashboardClientsPasswordResetLinkTable.c.ClientID == ClientID,
|
db.and_(self.dashboardClientsPasswordResetLinkTable.c.ClientID == ClientID,
|
||||||
self.dashboardClientsPasswordResetLinkTable.c.ResetToken == Token,
|
self.dashboardClientsPasswordResetLinkTable.c.ResetToken == Token,
|
||||||
self.dashboardClientsPasswordResetLinkTable.c.ExpiryDate > datetime.datetime.now()
|
self.dashboardClientsPasswordResetLinkTable.c.ExpiryDate > datetime.datetime.now())
|
||||||
|
|
||||||
)
|
)
|
||||||
).mappings().fetchone()
|
).mappings().fetchone()
|
||||||
return t is not None
|
return t is not None
|
||||||
@@ -465,8 +466,8 @@ class DashboardClients:
|
|||||||
self.dashboardClientsPasswordResetLinkTable.update().values({
|
self.dashboardClientsPasswordResetLinkTable.update().values({
|
||||||
"ExpiryDate": datetime.datetime.now()
|
"ExpiryDate": datetime.datetime.now()
|
||||||
}).where(
|
}).where(
|
||||||
self.dashboardClientsPasswordResetLinkTable.c.ClientID == ClientID,
|
db.and_(self.dashboardClientsPasswordResetLinkTable.c.ClientID == ClientID,
|
||||||
self.dashboardClientsPasswordResetLinkTable.c.ResetToken == Token
|
self.dashboardClientsPasswordResetLinkTable.c.ResetToken == Token)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
@@ -291,6 +291,16 @@ class WireguardConfiguration:
|
|||||||
server_default=sqlalchemy.func.now()),
|
server_default=sqlalchemy.func.now()),
|
||||||
extend_existing=True
|
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(
|
self.peersDeletedTable = sqlalchemy.Table(
|
||||||
f'{dbName}_deleted', self.metadata,
|
f'{dbName}_deleted', self.metadata,
|
||||||
sqlalchemy.Column('id', sqlalchemy.String(255), nullable=False, primary_key=True),
|
sqlalchemy.Column('id', sqlalchemy.String(255), nullable=False, primary_key=True),
|
||||||
@@ -454,7 +464,6 @@ class WireguardConfiguration:
|
|||||||
with self.engine.begin() as conn:
|
with self.engine.begin() as conn:
|
||||||
for tempPeer in self.Peers:
|
for tempPeer in self.Peers:
|
||||||
if tempPeer.status == "running":
|
if tempPeer.status == "running":
|
||||||
print(tempPeer.id + " running")
|
|
||||||
conn.execute(
|
conn.execute(
|
||||||
self.peersTransferTable.insert().values({
|
self.peersTransferTable.insert().values({
|
||||||
"id": tempPeer.id,
|
"id": tempPeer.id,
|
||||||
@@ -467,8 +476,24 @@ class WireguardConfiguration:
|
|||||||
"time": datetime.now()
|
"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]:
|
def addPeers(self, peers: list) -> tuple[bool, dict]:
|
||||||
result = {
|
result = {
|
||||||
"message": None,
|
"message": None,
|
||||||
@@ -792,7 +817,7 @@ class WireguardConfiguration:
|
|||||||
)
|
)
|
||||||
count += 2
|
count += 2
|
||||||
|
|
||||||
def toggleConfiguration(self) -> [bool, str]:
|
def toggleConfiguration(self) -> tuple[bool, str] | tuple[bool, None]:
|
||||||
self.getStatus()
|
self.getStatus()
|
||||||
if self.Status:
|
if self.Status:
|
||||||
try:
|
try:
|
||||||
|
Reference in New Issue
Block a user