mirror of
https://github.com/WGDashboard/WGDashboard-PRW.git
synced 2026-08-03 22:42:57 +00:00
chore: update files
This commit is contained in:
+3
-2
@@ -13,14 +13,15 @@ debug_enabled = True
|
|||||||
wg_conf_path = /etc/wireguard
|
wg_conf_path = /etc/wireguard
|
||||||
awg_conf_path = /etc/amnezia/amneziawg
|
awg_conf_path = /etc/amnezia/amneziawg
|
||||||
app_prefix =
|
app_prefix =
|
||||||
auth_req = False
|
auth_req = True
|
||||||
version = v5.0.0
|
version = v5.0.0
|
||||||
dashboard_refresh_interval = 60000
|
dashboard_refresh_interval = 60000
|
||||||
dashboard_peer_list_display = grid
|
dashboard_peer_list_display = grid
|
||||||
dashboard_sort = status
|
dashboard_sort = status
|
||||||
dashboard_theme = dark
|
dashboard_theme = dark
|
||||||
wgdashboard_apikey = true
|
wgdashboard_apikey = true
|
||||||
dashboard_language = en-US
|
#wgdashboard_language = nl-NL
|
||||||
|
wgdashboard_language = en-US
|
||||||
log_level = DEBUG
|
log_level = DEBUG
|
||||||
|
|
||||||
[Account]
|
[Account]
|
||||||
|
|||||||
+5
-4
@@ -8,7 +8,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import secrets
|
import secrets
|
||||||
|
|
||||||
from modules.config.reader import reader
|
from modules.config.config import config
|
||||||
from modules.database.database import database
|
from modules.database.database import database
|
||||||
|
|
||||||
from modules.utilities.utilities import utilities as util
|
from modules.utilities.utilities import utilities as util
|
||||||
@@ -18,17 +18,17 @@ from modules.routes.routes import routes
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Read the config file (ini)
|
# Read the config file (ini)
|
||||||
ok, config_contents = reader.read_config()
|
ok, config_contents = config.read()
|
||||||
if not ok:
|
if not ok:
|
||||||
exit(1)
|
exit(1)
|
||||||
found, config_server = util.filter_config(config_contents, 'SERVER')
|
found, config_server = config.filter(config_contents, 'SERVER')
|
||||||
|
|
||||||
# Configure the loglevel of WGDashboard
|
# Configure the loglevel of WGDashboard
|
||||||
wanted_loglevel = config_server.get('log_level', 'DEBUG').upper()
|
wanted_loglevel = config_server.get('log_level', 'DEBUG').upper()
|
||||||
setup_logger(wanted_loglevel)
|
setup_logger(wanted_loglevel)
|
||||||
|
|
||||||
# Get the database configuration from thee config
|
# Get the database configuration from thee config
|
||||||
found, config_database = util.filter_config(config_contents, 'DATABASE')
|
found, config_database = config.filter(config_contents, 'DATABASE')
|
||||||
if not found:
|
if not found:
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
@@ -46,6 +46,7 @@ if __name__ == '__main__':
|
|||||||
app.register_blueprint(routes, url_prefix=prefix)
|
app.register_blueprint(routes, url_prefix=prefix)
|
||||||
|
|
||||||
app.wgd_config = config_contents
|
app.wgd_config = config_contents
|
||||||
|
app.locale_path = './static/locales/'
|
||||||
|
|
||||||
app.secret_key = secrets.token_urlsafe(64)
|
app.secret_key = secrets.token_urlsafe(64)
|
||||||
app.config['SESSION_TYPE'] = 'filesystem'
|
app.config['SESSION_TYPE'] = 'filesystem'
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/env python3
|
||||||
|
|
||||||
|
import logging as log
|
||||||
|
|
||||||
|
from .utilities import config_utilities
|
||||||
|
|
||||||
|
class config():
|
||||||
|
@staticmethod
|
||||||
|
def filter(config_contents: dict, filter_keyword: str) -> tuple[bool, dict]:
|
||||||
|
'''
|
||||||
|
Helper function to grab a specific part of the config
|
||||||
|
'''
|
||||||
|
for section_name, section_values in config_contents.items():
|
||||||
|
if str(section_name).lower() == filter_keyword.lower():
|
||||||
|
if isinstance(section_values, dict):
|
||||||
|
return True, dict(section_values)
|
||||||
|
return False, {}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def read() -> tuple[bool, dict]:
|
||||||
|
'''
|
||||||
|
check some basic things and then return the dict containing the config data
|
||||||
|
'''
|
||||||
|
|
||||||
|
ok, candidate_path = config_utilities.search_known_paths()
|
||||||
|
if not ok:
|
||||||
|
return False, {}
|
||||||
|
ok, config_contents = config_utilities.verify_contents(candidate_path)
|
||||||
|
if not ok:
|
||||||
|
return False, {}
|
||||||
|
|
||||||
|
return True, config_contents
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def update(section: str, key: str, value: str) -> bool:
|
||||||
|
print(config_utilities.search_known_paths())
|
||||||
|
print(section, key, value)
|
||||||
|
return True
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#!/bin/env python3
|
|
||||||
|
|
||||||
import logging as log
|
|
||||||
|
|
||||||
from .utilities import checks
|
|
||||||
|
|
||||||
class reader():
|
|
||||||
@staticmethod
|
|
||||||
def read_config() -> tuple[bool, dict]:
|
|
||||||
'''
|
|
||||||
check some basic things and then return the dict containing the config data
|
|
||||||
'''
|
|
||||||
|
|
||||||
ok, candidate_path = checks.search_known_paths()
|
|
||||||
if not ok:
|
|
||||||
return False, {}
|
|
||||||
ok, config_contents = checks.verify_contents(candidate_path)
|
|
||||||
if not ok:
|
|
||||||
return False, {}
|
|
||||||
|
|
||||||
return True, config_contents
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def refresh_config(config_contents: dict) -> dict:
|
|
||||||
log.debug(f'refreshing config values')
|
|
||||||
return reader.read_config()
|
|
||||||
@@ -5,7 +5,7 @@ import logging as log
|
|||||||
import configparser as cp
|
import configparser as cp
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class checks():
|
class config_utilities():
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def search_known_paths() -> tuple[bool, str]:
|
def search_known_paths() -> tuple[bool, str]:
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#!/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import flask
|
||||||
|
|
||||||
|
from .response import make_resp_obj
|
||||||
|
|
||||||
|
from ..config.config import config
|
||||||
|
|
||||||
|
class localeman:
|
||||||
|
def __init__(self):
|
||||||
|
_, self.wgd_config = config.read()
|
||||||
|
self.locale_path = flask.current_app.locale_path
|
||||||
|
|
||||||
|
try:
|
||||||
|
path = os.path.join(self.locale_path, "supported_locales.json")
|
||||||
|
|
||||||
|
with open(path, "r", encoding="utf-8") as locale_path:
|
||||||
|
self.active_languages = sorted(
|
||||||
|
json.load(locale_path),
|
||||||
|
key=lambda x: x.get("lang_name", "")
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
self.active_languages = []
|
||||||
|
|
||||||
|
def get_language(self):
|
||||||
|
ok, server_config = config.filter(self.wgd_config, "SERVER")
|
||||||
|
if not ok:
|
||||||
|
return None
|
||||||
|
|
||||||
|
lang = server_config.get("wgdashboard_language", "en")
|
||||||
|
if lang.lower() == "en":
|
||||||
|
return None
|
||||||
|
|
||||||
|
path = os.path.join(self.locale_path, f"{lang}.json")
|
||||||
|
if os.path.isfile(path):
|
||||||
|
with open(path, "r", encoding="utf-8") as lang_file:
|
||||||
|
return json.load(lang_file)
|
||||||
|
return None
|
||||||
|
|
||||||
|
# def update_language(self, lang_id):
|
||||||
|
# path = os.path.join(self.locale_path, f"{lang_id}.json")
|
||||||
|
#
|
||||||
|
# if not os.path.isfile(path):
|
||||||
|
# lang_id = "en"
|
||||||
|
#
|
||||||
|
# util.set_config(self.wgd_config, "Server", "dashboard_language", lang_id)
|
||||||
|
# return self.get_language()
|
||||||
@@ -5,27 +5,31 @@ import logging as log
|
|||||||
import flask
|
import flask
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import werkzeug
|
||||||
|
|
||||||
from .response import make_resp_obj
|
from .response import make_resp_obj
|
||||||
from .utilities import helpers
|
from .utilities import helpers
|
||||||
|
from .locale import localeman
|
||||||
|
|
||||||
from ..database.functions import functions
|
from ..database.functions import functions
|
||||||
from ..utilities.utilities import utilities as util
|
from ..config.config import config
|
||||||
|
|
||||||
routes = flask.Blueprint("routes", __name__)
|
routes = flask.Blueprint("routes", __name__)
|
||||||
|
|
||||||
white_list = [
|
white_list = [
|
||||||
|
"/", # we need to whitelist /
|
||||||
"/client",
|
"/client",
|
||||||
"/static/",
|
"/static/",
|
||||||
"/fileDownload",
|
"/fileDownload",
|
||||||
"authenticate",
|
"/api/authenticate",
|
||||||
|
"/api/locale",
|
||||||
"getDashboardConfiguration",
|
"getDashboardConfiguration",
|
||||||
"getDashboardTheme",
|
"getDashboardTheme",
|
||||||
"getDashboardVersion",
|
"getDashboardVersion",
|
||||||
"sharePeer/get",
|
"sharePeer/get",
|
||||||
"isTotpEnabled",
|
"isTotpEnabled",
|
||||||
"locale",
|
|
||||||
"validateAuthentication",
|
"validateAuthentication",
|
||||||
|
"favicon.ico",
|
||||||
]
|
]
|
||||||
|
|
||||||
@routes.before_request
|
@routes.before_request
|
||||||
@@ -33,7 +37,7 @@ def auth_required():
|
|||||||
if flask.request.method.lower() == "options":
|
if flask.request.method.lower() == "options":
|
||||||
return make_resp_obj("", {"status": True}, 200)
|
return make_resp_obj("", {"status": True}, 200)
|
||||||
|
|
||||||
ok, config_server = util.filter_config(flask.current_app.wgd_config, 'SERVER')
|
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
||||||
if not ok:
|
if not ok:
|
||||||
return make_resp_obj("Internal error", {}, 500)
|
return make_resp_obj("Internal error", {}, 500)
|
||||||
|
|
||||||
@@ -62,14 +66,14 @@ def auth_required():
|
|||||||
|
|
||||||
@routes.route('/api/authenticate', methods=["POST"])
|
@routes.route('/api/authenticate', methods=["POST"])
|
||||||
def api_authenticate():
|
def api_authenticate():
|
||||||
ok, config_server = util.filter_config(flask.current_app.wgd_config, 'SERVER')
|
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
||||||
if not ok:
|
if not ok:
|
||||||
return make_resp_obj("Internal error", {}, 500)
|
return make_resp_obj("Internal error", {}, 500)
|
||||||
|
|
||||||
auth_required_flag = config_server.get('auth_req', True)
|
auth_required_flag = config_server.get('auth_req', True)
|
||||||
|
|
||||||
if not auth_required_flag:
|
if not auth_required_flag:
|
||||||
ok, config_other = util.filter_config(flask.current_app.wgd_config, 'OTHER')
|
ok, config_other = config.filter(flask.current_app.wgd_config, 'OTHER')
|
||||||
if not ok:
|
if not ok:
|
||||||
return make_resp_obj("Internal error", {}, 500)
|
return make_resp_obj("Internal error", {}, 500)
|
||||||
|
|
||||||
@@ -89,23 +93,23 @@ def api_authenticate():
|
|||||||
@routes.route('/<path:path>')
|
@routes.route('/<path:path>')
|
||||||
def index_handler(path):
|
def index_handler(path):
|
||||||
static_folder = flask.current_app.static_folder
|
static_folder = flask.current_app.static_folder
|
||||||
template_folder = flask.current_app.template_folder
|
try:
|
||||||
|
safe_path = werkzeug.utils.safe_join(static_folder, path)
|
||||||
safe_path = os.path.normpath(path)
|
if not safe_path or not os.path.exists(safe_path):
|
||||||
|
raise Exception()
|
||||||
if safe_path.startswith('..'):
|
rel_path = os.path.relpath(safe_path, static_folder)
|
||||||
return make_resp_obj("Invalid request", {}, 400)
|
return flask.send_from_directory(flask.current_app.static_folder, rel_path)
|
||||||
|
|
||||||
file_path = os.path.join(static_folder, safe_path)
|
|
||||||
if os.path.isfile(file_path):
|
|
||||||
return flask.send_from_directory(static_folder, safe_path)
|
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
print(f"ROUTE NOT INPLEMENTED: {path}")
|
||||||
return flask.send_from_directory(flask.current_app.static_folder, "index.html")
|
return flask.send_from_directory(flask.current_app.static_folder, "index.html")
|
||||||
|
|
||||||
@routes.route("/client")
|
@routes.route('/api/locale')
|
||||||
@routes.route("/clients")
|
def api_locale_handler():
|
||||||
def client_handler():
|
locale_manager = localeman()
|
||||||
return flask.send_from_directory(CLIENT_DIST, "client.html")
|
locale_data = locale_manager.get_language()
|
||||||
|
|
||||||
|
return make_resp_obj("", locale_data, 200)
|
||||||
|
|
||||||
@routes.route('/health', methods=["GET"])
|
@routes.route('/health', methods=["GET"])
|
||||||
@routes.route('/healthz', methods=["GET"])
|
@routes.route('/healthz', methods=["GET"])
|
||||||
|
|||||||
@@ -5,17 +5,6 @@ import logging as log
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
class utilities():
|
class utilities():
|
||||||
@staticmethod
|
|
||||||
def filter_config(config_contents: dict, filter_keyword: str) -> tuple[bool, dict]:
|
|
||||||
'''
|
|
||||||
Helper function to grab a specific part of the config
|
|
||||||
'''
|
|
||||||
for section_name, section_values in config_contents.items():
|
|
||||||
if str(section_name).lower() == filter_keyword.lower():
|
|
||||||
if isinstance(section_values, dict):
|
|
||||||
return True, dict(section_values)
|
|
||||||
return False, {}
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ensure_directory(path: str) -> bool:
|
def ensure_directory(path: str) -> bool:
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
configparser==7.2.0
|
configparser==7.2.0
|
||||||
Flask==3.1.3
|
|
||||||
sqlalchemy==2.0.48
|
sqlalchemy==2.0.48
|
||||||
|
Flask==3.1.3
|
||||||
|
Werkzeug==3.1.6
|
||||||
Reference in New Issue
Block a user