mirror of
https://github.com/WGDashboard/WGDashboard-PRW.git
synced 2026-08-03 14:32:56 +00:00
feat: init setup reading ini config
This commit is contained in:
@@ -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.
|
||||
+61
@@ -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
|
||||
+14
@@ -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)
|
||||
@@ -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()
|
||||
@@ -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, {}
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/env python3
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/env python3
|
||||
|
||||
@@ -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"
|
||||
@@ -0,0 +1 @@
|
||||
#!/bin/env python3
|
||||
@@ -0,0 +1 @@
|
||||
configparser==7.2.0
|
||||
Reference in New Issue
Block a user