1
0
mirror of https://github.com/donaldzou/WGDashboard.git synced 2024-11-18 21:40:12 +01:00

wg_conf_path is global variable

This commit is contained in:
Galonza Peter 2022-01-01 03:20:30 +03:00
parent 72151ac6a3
commit a5bc2cd48f

View File

@ -32,6 +32,8 @@ from util import regex_match, check_DNS, check_Allowed_IPs, check_remote_endpoin
# Dashboard Version # Dashboard Version
DASHBOARD_VERSION = 'v3.0' DASHBOARD_VERSION = 'v3.0'
# WireGuard configuration path
WG_CONF_PATH = None
# Dashboard Config Name # Dashboard Config Name
configuration_path = os.getenv('CONFIGURATION_PATH', '.') configuration_path = os.getenv('CONFIGURATION_PATH', '.')
DB_PATH = os.path.join(configuration_path, 'db') DB_PATH = os.path.join(configuration_path, 'db')
@ -104,7 +106,7 @@ def get_conf_running_peer_number(config_name):
# Read [Interface] section from configuration file # Read [Interface] section from configuration file
def read_conf_file_interface(config_name): def read_conf_file_interface(config_name):
conf_location = wg_conf_path + "/" + config_name + ".conf" conf_location = WG_CONF_PATH + "/" + config_name + ".conf"
with open(conf_location, 'r', encoding='utf-8') as file_object: with open(conf_location, 'r', encoding='utf-8') as file_object:
file = file_object.read().split("\n") file = file_object.read().split("\n")
data = {} data = {}
@ -121,7 +123,7 @@ def read_conf_file_interface(config_name):
# Read the whole configuration file # Read the whole configuration file
def read_conf_file(config_name): def read_conf_file(config_name):
# Read Configuration File Start # Read Configuration File Start
conf_location = wg_conf_path + "/" + config_name + ".conf" conf_location = WG_CONF_PATH + "/" + config_name + ".conf"
f = open(conf_location, 'r') f = open(conf_location, 'r')
file = f.read().split("\n") file = f.read().split("\n")
conf_peer_data = { conf_peer_data = {
@ -358,7 +360,7 @@ def get_peers(config_name, search, sort_t):
def get_conf_pub_key(config_name): def get_conf_pub_key(config_name):
try: try:
conf = configparser.ConfigParser(strict=False) conf = configparser.ConfigParser(strict=False)
conf.read(wg_conf_path + "/" + config_name + ".conf") conf.read(WG_CONF_PATH + "/" + config_name + ".conf")
pri = conf.get("Interface", "PrivateKey") pri = conf.get("Interface", "PrivateKey")
pub = subprocess.run(f"echo '{pri}' | wg pubkey", check=True, shell=True, capture_output=True).stdout pub = subprocess.run(f"echo '{pri}' | wg pubkey", check=True, shell=True, capture_output=True).stdout
conf.clear() conf.clear()
@ -370,7 +372,7 @@ def get_conf_pub_key(config_name):
# Get configuration listen port # Get configuration listen port
def get_conf_listen_port(config_name): def get_conf_listen_port(config_name):
conf = configparser.ConfigParser(strict=False) conf = configparser.ConfigParser(strict=False)
conf.read(wg_conf_path + "/" + config_name + ".conf") conf.read(WG_CONF_PATH + "/" + config_name + ".conf")
port = "" port = ""
try: try:
port = conf.get("Interface", "ListenPort") port = conf.get("Interface", "ListenPort")
@ -416,7 +418,7 @@ def get_conf_status(config_name):
# Get all configuration as a list # Get all configuration as a list
def get_conf_list(): def get_conf_list():
conf = [] conf = []
for i in os.listdir(wg_conf_path): for i in os.listdir(WG_CONF_PATH):
if regex_match("^(.{1,}).(conf)$", i): if regex_match("^(.{1,}).(conf)$", i):
i = i.replace('.conf', '') i = i.replace('.conf', '')
temp = {"conf": i, "status": get_conf_status(i), "public_key": get_conf_pub_key(i)} temp = {"conf": i, "status": get_conf_status(i), "public_key": get_conf_pub_key(i)}
@ -1454,6 +1456,6 @@ if __name__ == "__main__":
configuration_settings = get_dashboard_conf() configuration_settings = get_dashboard_conf()
app_ip = configuration_settings.get("Server", "app_ip") app_ip = configuration_settings.get("Server", "app_ip")
app_port = int(configuration_settings.get("Server", "app_port")) app_port = int(configuration_settings.get("Server", "app_port"))
wg_conf_path = configuration_settings.get("Server", "wg_conf_path") WG_CONF_PATH = configuration_settings.get("Server", "wg_conf_path")
configuration_settings.clear() configuration_settings.clear()
app.run(host=app_ip, debug=False, port=app_port) app.run(host=app_ip, debug=False, port=app_port)