mirror of
https://github.com/WGDashboard/WGDashboard.git
synced 2026-08-04 15:03:02 +00:00
Brand new switch button and toast UI
This commit is contained in:
+32
-1
@@ -1,5 +1,6 @@
|
||||
import re
|
||||
|
||||
import subprocess
|
||||
import dashboard
|
||||
"""
|
||||
Helper Functions
|
||||
"""
|
||||
@@ -79,3 +80,33 @@ def check_remote_endpoint(address):
|
||||
return (check_IP(address) or regex_match("(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z]{0,61}[a-z]",
|
||||
address))
|
||||
|
||||
|
||||
def deletePeers(config_name, delete_keys, cur, db):
|
||||
sql_command = []
|
||||
wg_command = ["wg", "set", config_name]
|
||||
for delete_key in delete_keys:
|
||||
if delete_key not in dashboard.get_conf_peer_key(config_name):
|
||||
return "This key does not exist"
|
||||
sql_command.append("DELETE FROM " + config_name + " WHERE id = '" + delete_key + "';")
|
||||
wg_command.append("peer")
|
||||
wg_command.append(delete_key)
|
||||
wg_command.append("remove")
|
||||
try:
|
||||
print("deleting...")
|
||||
remove_wg = subprocess.check_output(" ".join(wg_command),
|
||||
shell=True, stderr=subprocess.STDOUT)
|
||||
save_wg = subprocess.check_output(f"wg-quick save {config_name}", shell=True, stderr=subprocess.STDOUT)
|
||||
cur.executescript(' '.join(sql_command))
|
||||
db.commit()
|
||||
except subprocess.CalledProcessError as exc:
|
||||
return exc.output.strip()
|
||||
return "true"
|
||||
|
||||
def checkJSONAllParameter(required, data):
|
||||
if len(data) == 0:
|
||||
print("length 0")
|
||||
return False
|
||||
for i in required:
|
||||
if i not in list(data.keys()):
|
||||
return False
|
||||
return True
|
||||
Reference in New Issue
Block a user