Compare commits

...

4 commits

Author SHA1 Message Date
Martin 6ec5e7e6ef
Merge e35f942964 into a97a91b844 2024-09-19 14:36:02 +08:00
Donald Zou a97a91b844
Merge pull request #395 from donaldzou/fix-#391
Fixed issue where Preshared Key is not added when unrestricted peers
2024-09-19 14:31:41 +08:00
Donald Zou f1c577ab76 Fixed issue mentioned in #391 2024-09-19 14:21:38 +08:00
Martin e35f942964
Update dashboard.py - sort WG configurations
Sort WG configurations alphabetically
2024-09-04 14:40:04 +02:00

View file

@ -693,8 +693,6 @@ class WireguardConfiguration:
return False, None
def allowAccessPeers(self, listOfPublicKeys):
# numOfAllowedPeers = 0
# numOfFailedToAllowPeers = 0
if not self.getStatus():
self.toggleConfiguration()
@ -705,7 +703,15 @@ class WireguardConfiguration:
% (self.Name, self.Name,), (p['id'],))
sqlUpdate("DELETE FROM '%s_restrict_access' WHERE id = ?"
% self.Name, (p['id'],))
subprocess.check_output(f"wg set {self.Name} peer {p['id']} allowed-ips {p['allowed_ip']}",
presharedKeyExist = len(p['preshared_key']) > 0
rd = random.Random()
uid = uuid.UUID(int=rd.getrandbits(128), version=4)
if presharedKeyExist:
with open(f"{uid}", "w+") as f:
f.write(p['preshared_key'])
subprocess.check_output(f"wg set {self.Name} peer {p['id']} allowed-ips {p['allowed_ip']}{f' preshared-key {uid}' if presharedKeyExist else ''}",
shell=True, stderr=subprocess.STDOUT)
else:
return ResponseObject(False, "Failed to allow access of peer " + i)
@ -1297,7 +1303,9 @@ def _regexMatch(regex, text):
def _getConfigurationList():
# configurations = {}
for i in os.listdir(WG_CONF_PATH):
items = os.listdir(WG_CONF_PATH)
items.sort()
for i in items:
if _regexMatch("^(.{1,}).(conf)$", i):
i = i.replace('.conf', '')
try: