From b83aec49654782372247ea37bc173c070bc6e46b Mon Sep 17 00:00:00 2001 From: Donald Cheng Hong Zou Date: Tue, 4 May 2021 02:10:06 -0400 Subject: [PATCH] v2.0-beta-2 Commit --- .gitignore | 2 ++ requirements.txt | 3 +-- src/dashboard.py | 36 +++++++++++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index a1d27d0..3758fd9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ wg.db src/test.py tmp __pycache__ +src/wg-dashboard.ini +src/wg-dashboard.ini diff --git a/requirements.txt b/requirements.txt index 10b3a2f..85ee367 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ Flask==1.1.2 tinydb==4.3.0 -ifcfg==0.21 -configparser==5.0.2 \ No newline at end of file +ifcfg==0.21 \ No newline at end of file diff --git a/src/dashboard.py b/src/dashboard.py index d6a6edb..be237a8 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -7,12 +7,13 @@ from operator import itemgetter import secrets import hashlib import json, urllib.request - +import configparser # PIP installed library import ifcfg from tinydb import TinyDB, Query -import configparser + +dashboard_version = 'v2.0' dashboard_conf = 'wg-dashboard.ini' conf_location = "/etc/wireguard" app = Flask("Wireguard Dashboard") @@ -491,10 +492,39 @@ def get_peer_name(config_name): result = db.search(peers.id == id) return result[0]['name'] +def init_dashboard(): + # Set Default INI File + conf = configparser.ConfigParser(strict=False) + if os.path.isfile("wg-dashboard.ini") == False: + conf_file = open("wg-dashboard.ini", "w+") + config = configparser.ConfigParser(strict=False) + config.read(dashboard_conf) + + if "Account" not in config: + config['Account'] = {} + if "username" not in config['Account']: + config['Account']['username'] = 'admin' + if "password" not in config['Account']: + config['Account']['password'] = '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918' + + if "Server" not in config: + config['Server'] = {} + if 'app_ip' not in config['Server']: + config['Server']['app_ip'] = '0.0.0.0' + if 'app_port' not in config['Server']: + config['Server']['app_port'] = '10086' + if 'auth_req' not in config['Server']: + config['Server']['auth_req'] = 'true' + if 'version' not in config['Server'] or config['Server']['version'] != dashboard_version: + config['Server']['version'] = dashboard_version + config.write(open(dashboard_conf, "w")) + if __name__ == "__main__": + init_dashboard() config = configparser.ConfigParser(strict=False) config.read('wg-dashboard.ini') app_ip = config.get("Server", "app_ip") app_port = config.get("Server", "app_port") config.clear() - app.run(host=app_ip, debug=False, port=app_port) \ No newline at end of file + app.run(host=app_ip, debug=False, port=app_port) +