Flask app progress
This commit is contained in:
parent
c4fe022d42
commit
b0994069ad
38 changed files with 6631 additions and 220 deletions
74
docker/router-dash/app/config_utils.py
Normal file
74
docker/router-dash/app/config_utils.py
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
import json, subprocess, hashlib
|
||||
from markupsafe import Markup
|
||||
|
||||
_APPLY_CMD = 'sudo python3 ~/router/core.py --apply'
|
||||
_APPLY_CMD_VPN = 'sudo python3 ~/router/vpn.py --apply'
|
||||
|
||||
|
||||
def apply_msg(cmd=None):
|
||||
"""Return a Markup flash message for the apply reminder."""
|
||||
command = cmd if cmd is not None else _APPLY_CMD
|
||||
return Markup(
|
||||
f'Configuration updated. To apply changes, run: '
|
||||
f'<code><strong>{command}</strong></code>'
|
||||
)
|
||||
|
||||
CONFIGS_DIR = '/configs'
|
||||
CORE_FILE = f'{CONFIGS_DIR}/core.json'
|
||||
|
||||
|
||||
def load_core():
|
||||
try:
|
||||
with open(CORE_FILE) as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
|
||||
def save_core(data):
|
||||
with open(CORE_FILE, 'w') as f:
|
||||
json.dump(data, f, indent=2)
|
||||
|
||||
|
||||
def core_hash():
|
||||
try:
|
||||
with open(CORE_FILE, 'rb') as f:
|
||||
return hashlib.md5(f.read()).hexdigest()
|
||||
except Exception:
|
||||
return ''
|
||||
|
||||
|
||||
def verify_core_hash(submitted):
|
||||
if not submitted:
|
||||
return True
|
||||
return submitted == core_hash()
|
||||
|
||||
|
||||
def run_apply():
|
||||
try:
|
||||
subprocess.run(
|
||||
['python3', f'{CONFIGS_DIR}/core.py', '--apply'],
|
||||
capture_output=True, timeout=30
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def run_apply_vpn():
|
||||
try:
|
||||
subprocess.run(
|
||||
['python3', f'{CONFIGS_DIR}/vpn.py', '--apply'],
|
||||
capture_output=True, timeout=30
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def run_update_blocklists():
|
||||
try:
|
||||
subprocess.run(
|
||||
['python3', f'{CONFIGS_DIR}/core.py', '--update-blocklists'],
|
||||
capture_output=True, timeout=120
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue