raspap-webgui-mirror/api/modules/wireguard.py

26 lines
1.1 KiB
Python
Raw Normal View History

2024-02-08 22:24:30 +00:00
import subprocess
def configs():
#ignore symlinks, because wg0.conf is in production the main config, but in insiders it is a symlink
return subprocess.run("find /etc/wireguard/ -type f | wc -l", shell=True, capture_output=True, text=True).stdout.strip()
def client_config_names():
config_names_list = []
output = subprocess.run('''ls /etc/wireguard/ | grep -v "^wg0.conf$"''', shell=True, capture_output=True, text=True).stdout.strip()
lines = output.split("\n")
for client in lines:
config_names_dict ={'config':client}
config_names_list.append(config_names_dict)
return config_names_list
def client_config_active():
output = subprocess.run('''ls -al /etc/wireguard/ | grep "wg0.conf -"''', shell=True, capture_output=True, text=True).stdout.strip()
active_config = output.split("/etc/wireguard/")
return(active_config[1])
def client_config_list(client_config):
output = subprocess.run(f"cat /etc/wireguard/{client_config}", shell=True, capture_output=True, text=True).stdout.strip()
return output.split('\n')
#TODO: where is the logfile??
#TODO: is service connected?