mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2024-11-22 07:10:09 +01:00
Try now
This commit is contained in:
parent
1af708aaea
commit
11421d2d32
142
src/dashboard.py
142
src/dashboard.py
@ -570,78 +570,78 @@ class WireguardConfiguration:
|
|||||||
def __getPeers(self):
|
def __getPeers(self):
|
||||||
|
|
||||||
mt = os.path.getmtime(os.path.join(WG_CONF_PATH, f'{self.Name}.conf'))
|
mt = os.path.getmtime(os.path.join(WG_CONF_PATH, f'{self.Name}.conf'))
|
||||||
if self.__configFileModifiedTime is None or self.__configFileModifiedTime != mt:
|
# if self.__configFileModifiedTime is None or self.__configFileModifiedTime != mt:
|
||||||
self.Peers = []
|
self.Peers = []
|
||||||
with open(os.path.join(WG_CONF_PATH, f'{self.Name}.conf'), 'r') as configFile:
|
with open(os.path.join(WG_CONF_PATH, f'{self.Name}.conf'), 'r') as configFile:
|
||||||
p = []
|
p = []
|
||||||
pCounter = -1
|
pCounter = -1
|
||||||
content = configFile.read().split('\n')
|
content = configFile.read().split('\n')
|
||||||
try:
|
try:
|
||||||
peerStarts = content.index("[Peer]")
|
peerStarts = content.index("[Peer]")
|
||||||
content = content[peerStarts:]
|
content = content[peerStarts:]
|
||||||
for i in content:
|
for i in content:
|
||||||
if not regex_match("#(.*)", i) and not regex_match(";(.*)", i):
|
if not regex_match("#(.*)", i) and not regex_match(";(.*)", i):
|
||||||
if i == "[Peer]":
|
if i == "[Peer]":
|
||||||
pCounter += 1
|
pCounter += 1
|
||||||
p.append({})
|
p.append({})
|
||||||
p[pCounter]["name"] = ""
|
p[pCounter]["name"] = ""
|
||||||
else:
|
else:
|
||||||
if len(i) > 0:
|
if len(i) > 0:
|
||||||
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][split[0]] = split[1]
|
p[pCounter][split[0]] = split[1]
|
||||||
|
|
||||||
if regex_match("#Name# = (.*)", i):
|
|
||||||
split = re.split(r'\s*=\s*', i, 1)
|
|
||||||
print(split)
|
|
||||||
if len(split) == 2:
|
|
||||||
p[pCounter]["name"] = split[1]
|
|
||||||
|
|
||||||
for i in p:
|
if regex_match("#Name# = (.*)", i):
|
||||||
if "PublicKey" in i.keys():
|
split = re.split(r'\s*=\s*', i, 1)
|
||||||
checkIfExist = sqldb.cursor().execute("SELECT * FROM '%s' WHERE id = ?" % self.Name,
|
print(split)
|
||||||
((i['PublicKey']),)).fetchone()
|
if len(split) == 2:
|
||||||
if checkIfExist is None:
|
p[pCounter]["name"] = split[1]
|
||||||
newPeer = {
|
|
||||||
"id": i['PublicKey'],
|
for i in p:
|
||||||
"private_key": "",
|
if "PublicKey" in i.keys():
|
||||||
"DNS": DashboardConfig.GetConfig("Peers", "peer_global_DNS")[1],
|
checkIfExist = sqldb.cursor().execute("SELECT * FROM '%s' WHERE id = ?" % self.Name,
|
||||||
"endpoint_allowed_ip": DashboardConfig.GetConfig("Peers", "peer_endpoint_allowed_ip")[
|
((i['PublicKey']),)).fetchone()
|
||||||
1],
|
if checkIfExist is None:
|
||||||
"name": i.get("name"),
|
newPeer = {
|
||||||
"total_receive": 0,
|
"id": i['PublicKey'],
|
||||||
"total_sent": 0,
|
"private_key": "",
|
||||||
"total_data": 0,
|
"DNS": DashboardConfig.GetConfig("Peers", "peer_global_DNS")[1],
|
||||||
"endpoint": "N/A",
|
"endpoint_allowed_ip": DashboardConfig.GetConfig("Peers", "peer_endpoint_allowed_ip")[
|
||||||
"status": "stopped",
|
1],
|
||||||
"latest_handshake": "N/A",
|
"name": i.get("name"),
|
||||||
"allowed_ip": i.get("AllowedIPs", "N/A"),
|
"total_receive": 0,
|
||||||
"cumu_receive": 0,
|
"total_sent": 0,
|
||||||
"cumu_sent": 0,
|
"total_data": 0,
|
||||||
"cumu_data": 0,
|
"endpoint": "N/A",
|
||||||
"traffic": [],
|
"status": "stopped",
|
||||||
"mtu": DashboardConfig.GetConfig("Peers", "peer_mtu")[1],
|
"latest_handshake": "N/A",
|
||||||
"keepalive": DashboardConfig.GetConfig("Peers", "peer_keep_alive")[1],
|
"allowed_ip": i.get("AllowedIPs", "N/A"),
|
||||||
"remote_endpoint": DashboardConfig.GetConfig("Peers", "remote_endpoint")[1],
|
"cumu_receive": 0,
|
||||||
"preshared_key": i["PresharedKey"] if "PresharedKey" in i.keys() else ""
|
"cumu_sent": 0,
|
||||||
}
|
"cumu_data": 0,
|
||||||
sqldb.cursor().execute(
|
"traffic": [],
|
||||||
"""
|
"mtu": DashboardConfig.GetConfig("Peers", "peer_mtu")[1],
|
||||||
INSERT INTO '%s'
|
"keepalive": DashboardConfig.GetConfig("Peers", "peer_keep_alive")[1],
|
||||||
VALUES (:id, :private_key, :DNS, :endpoint_allowed_ip, :name, :total_receive, :total_sent,
|
"remote_endpoint": DashboardConfig.GetConfig("Peers", "remote_endpoint")[1],
|
||||||
:total_data, :endpoint, :status, :latest_handshake, :allowed_ip, :cumu_receive, :cumu_sent,
|
"preshared_key": i["PresharedKey"] if "PresharedKey" in i.keys() else ""
|
||||||
:cumu_data, :mtu, :keepalive, :remote_endpoint, :preshared_key);
|
}
|
||||||
""" % self.Name
|
sqldb.cursor().execute(
|
||||||
, newPeer)
|
"""
|
||||||
sqldb.commit()
|
INSERT INTO '%s'
|
||||||
self.Peers.append(Peer(newPeer, self))
|
VALUES (:id, :private_key, :DNS, :endpoint_allowed_ip, :name, :total_receive, :total_sent,
|
||||||
else:
|
:total_data, :endpoint, :status, :latest_handshake, :allowed_ip, :cumu_receive, :cumu_sent,
|
||||||
sqldb.cursor().execute("UPDATE '%s' SET allowed_ip = ? WHERE id = ?" % self.Name,
|
:cumu_data, :mtu, :keepalive, :remote_endpoint, :preshared_key);
|
||||||
(i.get("AllowedIPs", "N/A"), i['PublicKey'],))
|
""" % self.Name
|
||||||
sqldb.commit()
|
, newPeer)
|
||||||
self.Peers.append(Peer(checkIfExist, self))
|
sqldb.commit()
|
||||||
except Exception as e:
|
self.Peers.append(Peer(newPeer, self))
|
||||||
print(f"[WGDashboard] {self.Name} Error: {str(e)}")
|
else:
|
||||||
|
sqldb.cursor().execute("UPDATE '%s' SET allowed_ip = ? WHERE id = ?" % self.Name,
|
||||||
|
(i.get("AllowedIPs", "N/A"), i['PublicKey'],))
|
||||||
|
sqldb.commit()
|
||||||
|
self.Peers.append(Peer(checkIfExist, self))
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[WGDashboard] {self.Name} Error: {str(e)}")
|
||||||
self.__configFileModifiedTime = mt
|
self.__configFileModifiedTime = mt
|
||||||
|
|
||||||
def addPeers(self, peers: list):
|
def addPeers(self, peers: list):
|
||||||
|
@ -220,7 +220,7 @@ _checkPythonVersion(){
|
|||||||
else
|
else
|
||||||
printf "[WGDashboard] %s Could not find a compatible version of Python. Current Python is %s.\n" "$heavy_crossmark" "$version"
|
printf "[WGDashboard] %s Could not find a compatible version of Python. Current Python is %s.\n" "$heavy_crossmark" "$version"
|
||||||
printf "[WGDashboard] WGDashboard required Python 3.10, 3.11 or 3.12. Halting install now.\n"
|
printf "[WGDashboard] WGDashboard required Python 3.10, 3.11 or 3.12. Halting install now.\n"
|
||||||
kill $TOP_PID
|
kill $TOP_PID
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user