mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-10-03 07:46:18 +00:00
Update WireguardConfiguration.py
Resolved bug where peer is not added when mtu and keepalive is empty
This commit is contained in:
@@ -406,41 +406,45 @@ class WireguardConfiguration:
|
|||||||
split = re.split(r'\s*=\s*', i, 1)
|
split = re.split(r'\s*=\s*', i, 1)
|
||||||
if len(split) == 2:
|
if len(split) == 2:
|
||||||
p[pCounter]["name"] = split[1]
|
p[pCounter]["name"] = split[1]
|
||||||
with self.engine.begin() as conn:
|
|
||||||
for i in p:
|
for i in p:
|
||||||
if "PublicKey" in i.keys():
|
if "PublicKey" in i.keys():
|
||||||
|
with self.engine.connect() as conn:
|
||||||
tempPeer = conn.execute(
|
tempPeer = conn.execute(
|
||||||
self.peersTable.select().where(
|
self.peersTable.select().where(
|
||||||
self.peersTable.columns.id == i['PublicKey']
|
self.peersTable.columns.id == i['PublicKey']
|
||||||
)
|
)
|
||||||
).mappings().fetchone()
|
).mappings().fetchone()
|
||||||
if tempPeer is None:
|
|
||||||
tempPeer = {
|
if tempPeer is None:
|
||||||
"id": i['PublicKey'],
|
tempPeer = {
|
||||||
"private_key": "",
|
"id": i['PublicKey'],
|
||||||
"DNS": self.DashboardConfig.GetConfig("Peers", "peer_global_DNS")[1],
|
"private_key": "",
|
||||||
"endpoint_allowed_ip": self.DashboardConfig.GetConfig("Peers", "peer_endpoint_allowed_ip")[
|
"DNS": self.DashboardConfig.GetConfig("Peers", "peer_global_DNS")[1],
|
||||||
1],
|
"endpoint_allowed_ip": self.DashboardConfig.GetConfig("Peers", "peer_endpoint_allowed_ip")[
|
||||||
"name": i.get("name"),
|
1],
|
||||||
"total_receive": 0,
|
"name": i.get("name"),
|
||||||
"total_sent": 0,
|
"total_receive": 0,
|
||||||
"total_data": 0,
|
"total_sent": 0,
|
||||||
"endpoint": "N/A",
|
"total_data": 0,
|
||||||
"status": "stopped",
|
"endpoint": "N/A",
|
||||||
"latest_handshake": "N/A",
|
"status": "stopped",
|
||||||
"allowed_ip": i.get("AllowedIPs", "N/A"),
|
"latest_handshake": "N/A",
|
||||||
"cumu_receive": 0,
|
"allowed_ip": i.get("AllowedIPs", "N/A"),
|
||||||
"cumu_sent": 0,
|
"cumu_receive": 0,
|
||||||
"cumu_data": 0,
|
"cumu_sent": 0,
|
||||||
"mtu": self.DashboardConfig.GetConfig("Peers", "peer_mtu")[1],
|
"cumu_data": 0,
|
||||||
"keepalive": self.DashboardConfig.GetConfig("Peers", "peer_keep_alive")[1],
|
"mtu": self.DashboardConfig.GetConfig("Peers", "peer_mtu")[1] if len(self.DashboardConfig.GetConfig("Peers", "peer_mtu")[1]) > 0 else None,
|
||||||
"remote_endpoint": self.DashboardConfig.GetConfig("Peers", "remote_endpoint")[1],
|
"keepalive": self.DashboardConfig.GetConfig("Peers", "peer_keep_alive")[1] if len(self.DashboardConfig.GetConfig("Peers", "peer_keep_alive")[1]) > 0 else None,
|
||||||
"preshared_key": i["PresharedKey"] if "PresharedKey" in i.keys() else ""
|
"remote_endpoint": self.DashboardConfig.GetConfig("Peers", "remote_endpoint")[1],
|
||||||
}
|
"preshared_key": i["PresharedKey"] if "PresharedKey" in i.keys() else ""
|
||||||
|
}
|
||||||
|
with self.engine.begin() as conn:
|
||||||
conn.execute(
|
conn.execute(
|
||||||
self.peersTable.insert().values(tempPeer)
|
self.peersTable.insert().values(tempPeer)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
with self.engine.begin() as conn:
|
||||||
conn.execute(
|
conn.execute(
|
||||||
self.peersTable.update().values({
|
self.peersTable.update().values({
|
||||||
"allowed_ip": i.get("AllowedIPs", "N/A")
|
"allowed_ip": i.get("AllowedIPs", "N/A")
|
||||||
@@ -448,11 +452,11 @@ class WireguardConfiguration:
|
|||||||
self.peersTable.columns.id == i['PublicKey']
|
self.peersTable.columns.id == i['PublicKey']
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
tmpList.append(Peer(tempPeer, self))
|
tmpList.append(Peer(tempPeer, self))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if __name__ == '__main__':
|
print(f"[WGDashboard] {self.Name} getPeers() Error: {str(e)}")
|
||||||
print(f"[WGDashboard] {self.Name} getPeers() Error: {str(e)}")
|
|
||||||
else:
|
else:
|
||||||
with self.engine.connect() as conn:
|
with self.engine.connect() as conn:
|
||||||
existingPeers = conn.execute(self.peersTable.select()).mappings().fetchall()
|
existingPeers = conn.execute(self.peersTable.select()).mappings().fetchall()
|
||||||
|
Reference in New Issue
Block a user