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,19 +608,24 @@ def register_routes(app):
|
|||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
delete_keys = data["peer_ids"]
|
delete_keys = data["peer_ids"]
|
||||||
keys = wg.get_interface_peer_public_keys(interface_name)
|
keys = wg.get_interface_peer_public_keys(interface_name)
|
||||||
|
n_peers = len(delete_keys)
|
||||||
if not isinstance(keys, list):
|
if not isinstance(keys, list):
|
||||||
return interface_name + " is not running."
|
return interface_name + " is not running."
|
||||||
else:
|
|
||||||
for id in delete_keys:
|
for id in delete_keys:
|
||||||
if id not in keys:
|
try:
|
||||||
return "This key does not exist"
|
|
||||||
db.delete_peer(interface_name, id)
|
db.delete_peer(interface_name, id)
|
||||||
|
except:
|
||||||
|
if n_peers == 1:
|
||||||
|
return "Peer does not exist."
|
||||||
|
if id in keys:
|
||||||
try:
|
try:
|
||||||
wg.remove_peer_from_interface(interface_name, id)
|
wg.remove_peer_from_interface(interface_name, id)
|
||||||
wg.quick_save_interface_config(interface_name, g.WG_CONF_PATH)
|
wg.quick_save_interface_config(interface_name, g.WG_CONF_PATH)
|
||||||
except subprocess.CalledProcessError as exc:
|
except subprocess.CalledProcessError as exc:
|
||||||
return exc.output.strip()
|
if n_peers == 1:
|
||||||
return "true"
|
return "Peer does not exist."
|
||||||
|
return "true"
|
||||||
|
|
||||||
@app.route("/add_peer_bulk/<interface_name>", methods=["POST"])
|
@app.route("/add_peer_bulk/<interface_name>", methods=["POST"])
|
||||||
def add_peer_bulk(interface_name):
|
def add_peer_bulk(interface_name):
|
||||||
|
Loading…
Reference in New Issue
Block a user