Skip to content

Commit b3b3047

Browse files
committed
2 parents 41d91e7 + a97a91b commit b3b3047

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/dashboard.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,6 @@ def searchPeer(self, publicKey):
693693
return False, None
694694

695695
def allowAccessPeers(self, listOfPublicKeys):
696-
# numOfAllowedPeers = 0
697-
# numOfFailedToAllowPeers = 0
698696
if not self.getStatus():
699697
self.toggleConfiguration()
700698

@@ -705,7 +703,15 @@ def allowAccessPeers(self, listOfPublicKeys):
705703
% (self.Name, self.Name,), (p['id'],))
706704
sqlUpdate("DELETE FROM '%s_restrict_access' WHERE id = ?"
707705
% self.Name, (p['id'],))
708-
subprocess.check_output(f"wg set {self.Name} peer {p['id']} allowed-ips {p['allowed_ip']}",
706+
707+
presharedKeyExist = len(p['preshared_key']) > 0
708+
rd = random.Random()
709+
uid = uuid.UUID(int=rd.getrandbits(128), version=4)
710+
if presharedKeyExist:
711+
with open(f"{uid}", "w+") as f:
712+
f.write(p['preshared_key'])
713+
714+
subprocess.check_output(f"wg set {self.Name} peer {p['id']} allowed-ips {p['allowed_ip']}{f' preshared-key {uid}' if presharedKeyExist else ''}",
709715
shell=True, stderr=subprocess.STDOUT)
710716
else:
711717
return ResponseObject(False, "Failed to allow access of peer " + i)

0 commit comments

Comments
 (0)