From f361e178f1bf71ad21b908fa1e1b79d732d220d5 Mon Sep 17 00:00:00 2001 From: donaldzou Date: Sat, 26 Dec 2020 23:42:41 -0500 Subject: [PATCH] Added the function to remove peers --- src/dashboard.py | 28 ++++++++++++++++++----- src/templates/configuration.html | 38 +++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index f455f2c..60033e2 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -196,13 +196,29 @@ def add_peer(config_name): if public_key in keys: return "Key already exist." else: + status = "" try: - status = subprocess.check_output("wg set "+config_name+" peer "+public_key+" allowed-ips "+allowed_ips, shell=True) - status = subprocess.check_output("wg-quick save "+config_name, shell=True) - return "Good" - except Exception: return redirect('/configuration/'+config_name) + status = subprocess.check_output("wg set "+config_name+" peer "+public_key+" allowed-ips "+allowed_ips, shell=True, stderr=subprocess.STDOUT) + status = subprocess.check_output("wg-quick save "+config_name, shell=True, stderr=subprocess.STDOUT) + return "true" + except subprocess.CalledProcessError as exc: + return exc.output.strip() -# @app.route('/remove_peer//', methods=['POST']) -# def remove_peer(config_name, peer_id): + # return redirect('/configuration/'+config_name) + +@app.route('/remove_peer/', methods=['POST']) +def remove_peer(config_name): + data = request.get_json() + delete_key = data['peer_id'] + keys = get_conf_peer_key(config_name) + if delete_key not in keys: + return "This key does not exist" + else: + try: + status = subprocess.check_output("wg set "+config_name+" peer "+delete_key+" remove", shell=True, stderr=subprocess.STDOUT) + status = subprocess.check_output("wg-quick save "+config_name, shell=True, stderr=subprocess.STDOUT) + return "true" + except subprocess.CalledProcessError as exc: + return exc.output.strip() app.run(host='0.0.0.0',debug=False, port=10086) \ No newline at end of file diff --git a/src/templates/configuration.html b/src/templates/configuration.html index 122d7be..a7759b3 100644 --- a/src/templates/configuration.html +++ b/src/templates/configuration.html @@ -99,7 +99,7 @@
PEER -
{{i}}
+
{{i}}
@@ -153,6 +153,11 @@