From f1c577ab76ac8264a2a934ba906dd50147da6da9 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Tue, 17 Sep 2024 14:42:25 +0800 Subject: [PATCH] Fixed issue mentioned in #391 --- src/dashboard.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index 2db77be..0e51eea 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -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)