Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldzou committed Sep 19, 2024
2 parents 41d91e7 + a97a91b commit b3b3047
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,6 @@ def searchPeer(self, publicKey):
return False, None

def allowAccessPeers(self, listOfPublicKeys):
# numOfAllowedPeers = 0
# numOfFailedToAllowPeers = 0
if not self.getStatus():
self.toggleConfiguration()

Expand All @@ -705,7 +703,15 @@ def allowAccessPeers(self, listOfPublicKeys):
% (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)
Expand Down

0 comments on commit b3b3047

Please sign in to comment.