From 230b2b18fe83d0e716fa1e9c9ed7c395a18e6557 Mon Sep 17 00:00:00 2001 From: DaanSelen Date: Mon, 2 Mar 2026 14:06:50 +0100 Subject: [PATCH] feat: init setup reading ini config --- GUIDELINES.MD | 6 +++ assets/wg-config.ini | 0 config.ini | 61 +++++++++++++++++++++++++++ src/main.py | 14 +++++++ src/modules/config/reader.py | 24 +++++++++++ src/modules/config/utilities.py | 67 ++++++++++++++++++++++++++++++ src/modules/database/database.py | 2 + src/modules/database/schema.py | 2 + src/modules/database/utilities.py | 9 ++++ src/modules/wireguard/utilities.py | 1 + src/requirements.txt | 1 + 11 files changed, 187 insertions(+) create mode 100644 GUIDELINES.MD create mode 100644 assets/wg-config.ini create mode 100644 config.ini create mode 100644 src/main.py create mode 100644 src/modules/config/reader.py create mode 100644 src/modules/config/utilities.py create mode 100644 src/modules/database/database.py create mode 100644 src/modules/database/schema.py create mode 100644 src/modules/database/utilities.py create mode 100644 src/modules/wireguard/utilities.py create mode 100644 src/requirements.txt diff --git a/GUIDELINES.MD b/GUIDELINES.MD new file mode 100644 index 0000000..35cb3bb --- /dev/null +++ b/GUIDELINES.MD @@ -0,0 +1,6 @@ +# WGDashboard Coding Guidelines + +## Rules: + +- Utility functions should ALWAYS use DEBUG statements. +- Code as verbose as possible and where reason allows it. \ No newline at end of file diff --git a/assets/wg-config.ini b/assets/wg-config.ini new file mode 100644 index 0000000..e69de29 diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..0ead698 --- /dev/null +++ b/config.ini @@ -0,0 +1,61 @@ +[Peers] +remote_endpoint = 89.20.90.254 +peer_global_dns = 9.9.9.9 +peer_endpoint_allowed_ip = 0.0.0.0/0 +peer_display_mode = grid +peer_mtu = 1420 +peer_keep_alive = 21 + +[Server] +app_port = 10086 +wg_conf_path = /etc/wireguard +awg_conf_path = /etc/amnezia/amneziawg +app_prefix = +app_ip = 0.0.0.0 +auth_req = true +version = v4.3.2 +dashboard_refresh_interval = 60000 +dashboard_peer_list_display = grid +dashboard_sort = status +dashboard_theme = dark +dashboard_api_key = false +dashboard_language = en-US + +[Account] +username = admin +password = $2b$12$1VN62Q7CS/BJcAahHAWsA.3CD6zPqWTmE/HN/AJqwP0zds2l25Fqe +enable_totp = false +totp_verified = false +totp_key = ZSI2Z4QHSGVAK6TFVMZXORFDWKHDN4TQ + +[Other] +welcome_session = true + +[Database] +type = sqlite +host = +port = +username = +password = + +[Email] +server = +port = +encryption = +username = +email_password = +authentication_required = true +send_from = +email_template = + +[OIDC] +admin_enable = false +client_enable = false + +[Clients] +enable = true +sign_up = true + +[WireGuardConfiguration] +autostart = +peer_tracking = false \ No newline at end of file diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..ff99939 --- /dev/null +++ b/src/main.py @@ -0,0 +1,14 @@ +#!/bin/env python3 + +import logging as log + +from modules.config.reader import reader + +if __name__ == '__main__': + log.basicConfig(level=log.DEBUG) + + config_contents = reader.read_config() + log.info(config_contents) + input() + config_contents = reader.refresh_config(config_contents) + log.info(config_contents) \ No newline at end of file diff --git a/src/modules/config/reader.py b/src/modules/config/reader.py new file mode 100644 index 0000000..dcba80a --- /dev/null +++ b/src/modules/config/reader.py @@ -0,0 +1,24 @@ +#!/bin/env python3 + +import logging as log + +from .utilities import preflight_checks + +class reader(): + def read_config() -> dict: + ''' + check some basic things and then return the dict containing the config data + ''' + + ok, candidate_path = preflight_checks.search_known_paths() + if not ok: + return {} + ok, config_contents = preflight_checks.verify_contents(candidate_path) + if not ok: + return {} + + return config_contents + + def refresh_config(config_contents: dict) -> dict: + log.debug(f'refreshing config values') + return reader.read_config() \ No newline at end of file diff --git a/src/modules/config/utilities.py b/src/modules/config/utilities.py new file mode 100644 index 0000000..da909e1 --- /dev/null +++ b/src/modules/config/utilities.py @@ -0,0 +1,67 @@ +#!/bin/env python3 + +import logging as log + +import configparser as cp +import os + +class preflight_checks(): + def search_known_paths() -> tuple[bool, str]: + ''' + Look at predefined paths on the filesystem for a config file + ''' + + possible_config_locations = [ + "./config.ini", + f"{os.getenv('HOME')}/.config/wgdashboard/config.ini", + "/etc/wgdashboard/config.ini", + ] + + try: + log.debug('searching predefined locations for the config file, takes first one.') + + for path in possible_config_locations: + log.debug(f'testing path: {path}') + + if os.path.exists(path): + log.debug(f'found a file at: {path}') + return True, path + else: + continue + return False, '' + + except Exception as err: + log.error(f'error occured while searching for the config file: {err}') + return False, '' + + def verify_contents(config_path: str) -> tuple[bool, dict]: + ''' + Check the existing config file for contents + ''' + config = cp.ConfigParser() + + try: + log.debug('looking through the given config file') + + config.read(config_path) + + if len(config.sections()) == 0: + log.error('empty config, no sections') + return False, {} + + for section in config.sections(): + log.debug(f'checking integrity of section: {section}') + + if len(config.items(section)) == 0: + log.error('empty section, no keys or values') + return False, {} + + return True, dict(config.items()) + + except cp.ParsingError as err: + log.error(f'error parsing the ini config file: {err}') + return False, {} + + except Exception as err: + log.error(f'error occured while looking through the config file: {err}') + return False, {} \ No newline at end of file diff --git a/src/modules/database/database.py b/src/modules/database/database.py new file mode 100644 index 0000000..92bc4e7 --- /dev/null +++ b/src/modules/database/database.py @@ -0,0 +1,2 @@ +#!/bin/env python3 + diff --git a/src/modules/database/schema.py b/src/modules/database/schema.py new file mode 100644 index 0000000..92bc4e7 --- /dev/null +++ b/src/modules/database/schema.py @@ -0,0 +1,2 @@ +#!/bin/env python3 + diff --git a/src/modules/database/utilities.py b/src/modules/database/utilities.py new file mode 100644 index 0000000..d992f48 --- /dev/null +++ b/src/modules/database/utilities.py @@ -0,0 +1,9 @@ +#!/bin/env python3 + +class db_setup(): + ''' + This class functions as a collection of function to prepare a connection to a database. + ''' + + def compile_connection_string() -> string: + return "The Connection string" \ No newline at end of file diff --git a/src/modules/wireguard/utilities.py b/src/modules/wireguard/utilities.py new file mode 100644 index 0000000..7557381 --- /dev/null +++ b/src/modules/wireguard/utilities.py @@ -0,0 +1 @@ +#!/bin/env python3 \ No newline at end of file diff --git a/src/requirements.txt b/src/requirements.txt new file mode 100644 index 0000000..3b77bc9 --- /dev/null +++ b/src/requirements.txt @@ -0,0 +1 @@ +configparser==7.2.0 \ No newline at end of file