Development

This commit is contained in:
Matthew Grotke 2026-06-07 00:21:08 -04:00
parent 563d82daf3
commit 70ccfe2c29
48 changed files with 549 additions and 578 deletions

View file

@ -4,11 +4,11 @@ import ipaddress
import json
from flask import Blueprint, request, redirect, flash
from auth import require_level
from config_utils import load_config, record_group, diff_fields, verify_config_hash
import auth
import config_utils
import sanitize
import mod_validation as validate
import settings as settings
import settings
_PAGE = Path(__file__).parent.name
@ -25,14 +25,14 @@ def _row_index():
def _hash_ok():
if not verify_config_hash(request.form.get('config_hash', '')):
if not config_utils.verify_config_hash(request.form.get('config_hash', '')):
flash('Configuration was modified by another session. Please refresh and try again.', 'error')
return False
return True
@bp.route('/action/networklayout/vlans_addedit', methods=['POST'])
@require_level('administrator')
@auth.require_level('administrator')
def vlans_addedit():
_ri = request.form.get('row_index', '').strip()
try:
@ -53,7 +53,7 @@ def vlans_addedit():
restricted_vlan = restricted_vlan_raw if restricted_vlan_raw in ('q', 'c') else ''
use_blocklists = sanitize.filterlist(
request.form.getlist('use_blocklists'),
{b.get('name') for b in load_config().get('dns_blocking', {}).get('blocklists', [])},
{b.get('name') for b in config_utils.load_config().get('dns_blocking', {}).get('blocklists', [])},
)
if restricted_vlan and not PRO_LICENSE:
@ -216,7 +216,7 @@ def vlans_addedit():
if dhcp_overrides:
dhcp_info['explicit_overrides'] = dhcp_overrides
cfg = load_config()
cfg = config_utils.load_config()
vlans = cfg.setdefault('vlans', [])
if is_edit:
@ -284,11 +284,11 @@ def vlans_addedit():
flash(msg, 'error')
return redirect(f'/{_PAGE}')
changes = diff_fields(before, existing)
changes = config_utils.diff_fields(before, existing)
if not changes:
flash('No changes were made.', 'info')
return redirect(f'/{_PAGE}')
flash(record_group(cfg, 'vlans', 'name', name, changes, 'core apply'), 'success')
flash(config_utils.record_group(cfg, 'vlans', 'name', name, changes, 'core apply'), 'success')
else:
is_vpn = 'is_vpn' in request.form
@ -347,14 +347,14 @@ def vlans_addedit():
flash(msg, 'error')
return redirect(f'/{_PAGE}')
changes = diff_fields(None, entry)
flash(record_group(cfg, 'vlans', 'name', name, changes, 'core apply'), 'success')
changes = config_utils.diff_fields(None, entry)
flash(config_utils.record_group(cfg, 'vlans', 'name', name, changes, 'core apply'), 'success')
return redirect(f'/{_PAGE}')
@bp.route('/action/networklayout/vlans_delete', methods=['POST'])
@require_level('administrator')
@auth.require_level('administrator')
def vlans_delete():
idx = _row_index()
if idx is None:
@ -363,7 +363,7 @@ def vlans_delete():
if not _hash_ok():
return redirect(f'/{_PAGE}')
cfg = load_config()
cfg = config_utils.load_config()
vlans = cfg.get('vlans', [])
if idx < 0 or idx >= len(vlans):
flash('VLAN not found.', 'error')
@ -376,6 +376,6 @@ def vlans_delete():
flash(msg, 'error')
return redirect(f'/{_PAGE}')
changes = diff_fields(removed, None)
flash(record_group(cfg, 'vlans', 'name', removed['name'], changes, 'core apply'), 'success')
changes = config_utils.diff_fields(removed, None)
flash(config_utils.record_group(cfg, 'vlans', 'name', removed['name'], changes, 'core apply'), 'success')
return redirect(f'/{_PAGE}')