Development
This commit is contained in:
parent
563d82daf3
commit
70ccfe2c29
48 changed files with 549 additions and 578 deletions
|
|
@ -3,24 +3,13 @@
|
|||
from flask import session
|
||||
from markupsafe import Markup
|
||||
import json, re, sys, html as html_mod, os, subprocess
|
||||
from config_utils import (
|
||||
config_hash, load_config, CONFIGS_DIR, WWW_DIR, APP_DIR,
|
||||
ACCOUNTS_FILE, HEALTH_FILE, BLOCKLISTS_DIR,
|
||||
fmt_timestamp, relative_time, fmt_bytes, resolve_iface,
|
||||
WEB_APP_DISPLAY_NAME,
|
||||
)
|
||||
from config_utils import (
|
||||
get_pending_entries, get_dashboard_pending, _find_cmd_in_queues,
|
||||
_apply_changes_immediately, _seconds_until_next_run, _format_timing,
|
||||
_is_locked, _lock_mtime, _entry_ts_from_queue,
|
||||
)
|
||||
import config_utils
|
||||
import settings
|
||||
|
||||
import settings as settings
|
||||
|
||||
PAGES_DIR = os.path.join(APP_DIR, 'pages')
|
||||
NAVBAR_FILE = os.path.join(APP_DIR, 'navbar.json')
|
||||
CSS_FILE = os.path.join(WWW_DIR, 'styles.css')
|
||||
COMMON_JS_FILE = os.path.join(WWW_DIR, 'common.js')
|
||||
PAGES_DIR = os.path.join(config_utils.APP_DIR, 'pages')
|
||||
NAVBAR_FILE = os.path.join(config_utils.APP_DIR, 'navbar.json')
|
||||
CSS_FILE = os.path.join(config_utils.WWW_DIR, 'styles.css')
|
||||
COMMON_JS_FILE = os.path.join(config_utils.WWW_DIR, 'common.js')
|
||||
|
||||
|
||||
def _file_version(path):
|
||||
|
|
@ -55,7 +44,7 @@ VALIDATION_FLAGS = {
|
|||
|
||||
def _restricted_vlan_subnets():
|
||||
"""Return list of 'subnet/prefix' strings for all restricted VLANs."""
|
||||
vlans = load_config().get('vlans', [])
|
||||
vlans = config_utils.load_config().get('vlans', [])
|
||||
result = []
|
||||
for v in vlans:
|
||||
if v.get('restricted_vlan') in ('q', 'c') and v.get('subnet') and v.get('subnet_mask') is not None:
|
||||
|
|
@ -73,10 +62,10 @@ def load_json(path):
|
|||
return {}
|
||||
|
||||
def load_ddns():
|
||||
return load_config().get('ddns', {})
|
||||
return config_utils.load_config().get('ddns', {})
|
||||
|
||||
def load_accounts():
|
||||
return load_json(ACCOUNTS_FILE)
|
||||
return load_json(config_utils.ACCOUNTS_FILE)
|
||||
|
||||
def run(cmd):
|
||||
try:
|
||||
|
|
@ -94,7 +83,7 @@ def load_css():
|
|||
|
||||
def load_icon(name):
|
||||
try:
|
||||
with open(f'{WWW_DIR}/icons/{name}.svg') as f:
|
||||
with open(f'{config_utils.WWW_DIR}/icons/{name}.svg') as f:
|
||||
return f.read().strip()
|
||||
except Exception:
|
||||
return ''
|
||||
|
|
@ -1036,7 +1025,7 @@ def build_table(item, tokens, rows, inherited_req=None):
|
|||
columns = item.get('columns', [])
|
||||
empty = e(item.get('empty_message', 'No data.'))
|
||||
row_actions = item.get('row_actions', [])
|
||||
hash_val = config_hash()
|
||||
hash_val = config_utils.config_hash()
|
||||
|
||||
toolbar_html = ''
|
||||
toolbar = item.get('toolbar')
|
||||
|
|
@ -1245,7 +1234,7 @@ def build_item(item, tokens, inherited_req=None):
|
|||
'<button type="button" class="btn btn-ghost btn-sm stat-card-edit-btn">Edit</button>'
|
||||
'</div>'
|
||||
f'<form class="stat-card-edit-form hidden" action="{e(edit_action)}" method="post">'
|
||||
f'<input type="hidden" name="config_hash" value="{e(config_hash())}"/>'
|
||||
f'<input type="hidden" name="config_hash" value="{e(config_utils.config_hash())}"/>'
|
||||
f'{input_wrap}'
|
||||
'<div class="stat-card-edit-actions">'
|
||||
'<button type="submit" class="btn btn-primary btn-sm" disabled>Save</button>'
|
||||
|
|
@ -1331,7 +1320,7 @@ def build_item(item, tokens, inherited_req=None):
|
|||
action = e(apply_tokens(item.get('action', ''), tokens))
|
||||
method = e(item.get('method', 'post'))
|
||||
inner = build_items(item.get('items', []), tokens, req)
|
||||
hash_field = f'<input type="hidden" name="config_hash" value="{e(config_hash())}"/>'
|
||||
hash_field = f'<input type="hidden" name="config_hash" value="{e(config_utils.config_hash())}"/>'
|
||||
originals = collect_form_originals(item.get('items', []), tokens)
|
||||
orig_field = (
|
||||
f'<input type="hidden" name="original_values" value="{e(json.dumps(originals))}"/>'
|
||||
|
|
@ -1530,21 +1519,21 @@ def build_item(item, tokens, inherited_req=None):
|
|||
|
||||
def render_layout(view_id, content_html, tokens, page_name=None):
|
||||
level = client_level()
|
||||
has_pending_alert = not _apply_changes_immediately() and bool(get_dashboard_pending())
|
||||
titlebar_html = f'<div class="titlebar"><span class="titlebar-brand">{WEB_APP_DISPLAY_NAME}</span></div>'
|
||||
has_pending_alert = not config_utils._apply_changes_immediately() and bool(config_utils.get_dashboard_pending())
|
||||
titlebar_html = f'<div class="titlebar"><span class="titlebar-brand">{config_utils.WEB_APP_DISPLAY_NAME}</span></div>'
|
||||
navbar_html = build_navbar(view_id, level, tokens, pending_alert=has_pending_alert)
|
||||
footer_html = f'<footer class="footer">{WEB_APP_DISPLAY_NAME}</footer>'
|
||||
footer_html = f'<footer class="footer">{config_utils.WEB_APP_DISPLAY_NAME}</footer>'
|
||||
|
||||
page_hash = config_hash()
|
||||
page_hash = config_utils.config_hash()
|
||||
lan_iface = e(tokens.get('GENERAL_LAN_INTERFACE', ''))
|
||||
vpn_count = tokens.get('VPN_VLAN_COUNT', '0')
|
||||
current_user = session.get('email_address', '')
|
||||
pending = get_pending_entries()
|
||||
pending = config_utils.get_pending_entries()
|
||||
my_uuid = next((u for u, t, c, usr in pending if usr == current_user and c != 'fix problems'), None)
|
||||
|
||||
secs = _seconds_until_next_run()
|
||||
locked = _is_locked()
|
||||
lock_mtime = _lock_mtime()
|
||||
secs = config_utils._seconds_until_next_run()
|
||||
locked = config_utils._is_locked()
|
||||
lock_mtime = config_utils._lock_mtime()
|
||||
other_bars = ''
|
||||
seen_other_users = set()
|
||||
for o_uuid, o_ts, o_cmd, o_user in pending:
|
||||
|
|
@ -1558,7 +1547,7 @@ def render_layout(view_id, content_html, tokens, page_name=None):
|
|||
text = f'{display_user}\'s changes are being applied now...'
|
||||
cls = 'info-bar-warning info-bar-running'
|
||||
else:
|
||||
timing = _format_timing(secs)
|
||||
timing = config_utils._format_timing(secs)
|
||||
text = (
|
||||
f'{display_user} has pending changes which will be applied {timing}.'
|
||||
if timing else
|
||||
|
|
@ -1570,7 +1559,7 @@ def render_layout(view_id, content_html, tokens, page_name=None):
|
|||
problem_bars = ''
|
||||
if level >= LEVEL_RANK['viewer']:
|
||||
try:
|
||||
st = json.load(open(HEALTH_FILE))
|
||||
st = json.load(open(config_utils.HEALTH_FILE))
|
||||
problems = []
|
||||
for section in ('configurations', 'logs'):
|
||||
for item in st.get(section, []):
|
||||
|
|
@ -1598,17 +1587,17 @@ def render_layout(view_id, content_html, tokens, page_name=None):
|
|||
if level < LEVEL_RANK['administrator']:
|
||||
fix_suffix = 'Please contact an administrator.'
|
||||
else:
|
||||
fix_uuid, fix_ts = _find_cmd_in_queues('fix problems')
|
||||
if _apply_changes_immediately():
|
||||
if _is_locked():
|
||||
mtime = _lock_mtime()
|
||||
fix_uuid, fix_ts = config_utils._find_cmd_in_queues('fix problems')
|
||||
if config_utils._apply_changes_immediately():
|
||||
if config_utils._is_locked():
|
||||
mtime = config_utils._lock_mtime()
|
||||
fix_suffix = (
|
||||
'Fix is being applied now...'
|
||||
if fix_ts and mtime and fix_ts < mtime
|
||||
else 'Fix will be applied on the next run.'
|
||||
)
|
||||
else:
|
||||
timing = _format_timing(_seconds_until_next_run())
|
||||
timing = config_utils._format_timing(config_utils._seconds_until_next_run())
|
||||
fix_suffix = (
|
||||
f'Fix will be applied {timing}.'
|
||||
if timing else
|
||||
|
|
@ -1628,7 +1617,7 @@ def render_layout(view_id, content_html, tokens, page_name=None):
|
|||
)
|
||||
uuid_attr = (
|
||||
f' data-health-uuid="{e(fix_uuid)}"'
|
||||
if fix_uuid and _entry_ts_from_queue(fix_uuid) is not None else ''
|
||||
if fix_uuid and config_utils._entry_ts_from_queue(fix_uuid) is not None else ''
|
||||
)
|
||||
fix_html = (
|
||||
f'<div style="margin-top:0.5em"{uuid_attr}>{fix_suffix}</div>'
|
||||
|
|
@ -1665,7 +1654,7 @@ def render_layout(view_id, content_html, tokens, page_name=None):
|
|||
'<!DOCTYPE html>\n<html lang="en">\n<head>\n'
|
||||
' <meta charset="UTF-8"/>\n'
|
||||
' <meta name="viewport" content="width=device-width, initial-scale=1.0"/>\n'
|
||||
f' <title>{WEB_APP_DISPLAY_NAME}</title>\n'
|
||||
f' <title>{config_utils.WEB_APP_DISPLAY_NAME}</title>\n'
|
||||
f'{css_tag}'
|
||||
'</head>\n<body>\n'
|
||||
f'{titlebar_html}\n'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue