mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2024-11-23 07:30:11 +01:00
Fixed bulk delete of peers
This commit is contained in:
parent
311314e5e6
commit
84d4e0fe74
@ -608,18 +608,23 @@ def register_routes(app):
|
||||
data = request.get_json()
|
||||
delete_keys = data["peer_ids"]
|
||||
keys = wg.get_interface_peer_public_keys(interface_name)
|
||||
n_peers = len(delete_keys)
|
||||
if not isinstance(keys, list):
|
||||
return interface_name + " is not running."
|
||||
else:
|
||||
|
||||
for id in delete_keys:
|
||||
if id not in keys:
|
||||
return "This key does not exist"
|
||||
try:
|
||||
db.delete_peer(interface_name, id)
|
||||
except:
|
||||
if n_peers == 1:
|
||||
return "Peer does not exist."
|
||||
if id in keys:
|
||||
try:
|
||||
wg.remove_peer_from_interface(interface_name, id)
|
||||
wg.quick_save_interface_config(interface_name, g.WG_CONF_PATH)
|
||||
except subprocess.CalledProcessError as exc:
|
||||
return exc.output.strip()
|
||||
if n_peers == 1:
|
||||
return "Peer does not exist."
|
||||
return "true"
|
||||
|
||||
@app.route("/add_peer_bulk/<interface_name>", methods=["POST"])
|
||||
|
Loading…
Reference in New Issue
Block a user