From 84d4e0fe7493a4bfd62993064a042f1696d64f08 Mon Sep 17 00:00:00 2001 From: theonlynexus Date: Thu, 21 Jul 2022 06:02:30 +0000 Subject: [PATCH] Fixed bulk delete of peers --- src/rest_routes.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/rest_routes.py b/src/rest_routes.py index 389bfa6..832c0f2 100644 --- a/src/rest_routes.py +++ b/src/rest_routes.py @@ -608,19 +608,24 @@ 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" + + for id in delete_keys: + 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() - return "true" + if n_peers == 1: + return "Peer does not exist." + return "true" @app.route("/add_peer_bulk/", methods=["POST"]) def add_peer_bulk(interface_name):