mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2024-11-06 16:00:28 +01:00
Added to parse name in .conf
file
This commit is contained in:
parent
1a70acc6f2
commit
42fa89db7a
@ -578,23 +578,32 @@ class WireguardConfiguration:
|
|||||||
if i == "[Peer]":
|
if i == "[Peer]":
|
||||||
pCounter += 1
|
pCounter += 1
|
||||||
p.append({})
|
p.append({})
|
||||||
|
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:
|
for i in p:
|
||||||
if "PublicKey" in i.keys():
|
if "PublicKey" in i.keys():
|
||||||
checkIfExist = sqldb.cursor().execute("SELECT * FROM '%s' WHERE id = ?" % self.Name,
|
checkIfExist = sqldb.cursor().execute("SELECT * FROM '%s' WHERE id = ?" % self.Name,
|
||||||
((i['PublicKey']),)).fetchone()
|
((i['PublicKey']),)).fetchone()
|
||||||
if checkIfExist is None:
|
if checkIfExist is None:
|
||||||
|
print(i)
|
||||||
newPeer = {
|
newPeer = {
|
||||||
"id": i['PublicKey'],
|
"id": i['PublicKey'],
|
||||||
"private_key": "",
|
"private_key": "",
|
||||||
"DNS": DashboardConfig.GetConfig("Peers", "peer_global_DNS")[1],
|
"DNS": DashboardConfig.GetConfig("Peers", "peer_global_DNS")[1],
|
||||||
"endpoint_allowed_ip": DashboardConfig.GetConfig("Peers", "peer_endpoint_allowed_ip")[
|
"endpoint_allowed_ip": DashboardConfig.GetConfig("Peers", "peer_endpoint_allowed_ip")[
|
||||||
1],
|
1],
|
||||||
"name": "",
|
"name": i.get("name"),
|
||||||
"total_receive": 0,
|
"total_receive": 0,
|
||||||
"total_sent": 0,
|
"total_sent": 0,
|
||||||
"total_data": 0,
|
"total_data": 0,
|
||||||
@ -611,6 +620,7 @@ class WireguardConfiguration:
|
|||||||
"remote_endpoint": DashboardConfig.GetConfig("Peers", "remote_endpoint")[1],
|
"remote_endpoint": DashboardConfig.GetConfig("Peers", "remote_endpoint")[1],
|
||||||
"preshared_key": i["PresharedKey"] if "PresharedKey" in i.keys() else ""
|
"preshared_key": i["PresharedKey"] if "PresharedKey" in i.keys() else ""
|
||||||
}
|
}
|
||||||
|
print(newPeer)
|
||||||
sqldb.cursor().execute(
|
sqldb.cursor().execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO '%s'
|
INSERT INTO '%s'
|
||||||
@ -626,8 +636,8 @@ class WireguardConfiguration:
|
|||||||
(i.get("AllowedIPs", "N/A"), i['PublicKey'],))
|
(i.get("AllowedIPs", "N/A"), i['PublicKey'],))
|
||||||
sqldb.commit()
|
sqldb.commit()
|
||||||
self.Peers.append(Peer(checkIfExist, self))
|
self.Peers.append(Peer(checkIfExist, self))
|
||||||
except ValueError:
|
except Exception as e:
|
||||||
pass
|
print(f"[WGDashboard] {self.Name} Error: {str(e)}")
|
||||||
|
|
||||||
def addPeers(self, peers: list):
|
def addPeers(self, peers: list):
|
||||||
for p in peers:
|
for p in peers:
|
||||||
@ -1627,8 +1637,6 @@ def API_resetPeerData(configName):
|
|||||||
return ResponseObject(False, "Configuration/Peer does not exist")
|
return ResponseObject(False, "Configuration/Peer does not exist")
|
||||||
return ResponseObject(status=peer.resetDataUsage(type))
|
return ResponseObject(status=peer.resetDataUsage(type))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route(f'{APP_PREFIX}/api/deletePeers/<configName>', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/deletePeers/<configName>', methods=['POST'])
|
||||||
def API_deletePeers(configName: str) -> ResponseObject:
|
def API_deletePeers(configName: str) -> ResponseObject:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
@ -1867,7 +1875,6 @@ def API_savePeerScheduleJob():
|
|||||||
return ResponseObject(s, data=p)
|
return ResponseObject(s, data=p)
|
||||||
return ResponseObject(s, message=p)
|
return ResponseObject(s, message=p)
|
||||||
|
|
||||||
|
|
||||||
@app.route(f'{APP_PREFIX}/api/deletePeerScheduleJob/', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/deletePeerScheduleJob/', methods=['POST'])
|
||||||
def API_deletePeerScheduleJob():
|
def API_deletePeerScheduleJob():
|
||||||
data = request.json
|
data = request.json
|
||||||
|
Loading…
Reference in New Issue
Block a user