Development
This commit is contained in:
parent
d0cfffac52
commit
adcfe55c7c
24 changed files with 405 additions and 359 deletions
|
|
@ -2,7 +2,7 @@ import copy
|
|||
|
||||
from flask import Blueprint, request, redirect, flash
|
||||
from auth import require_level
|
||||
from config_utils import load_core, save_core_with_snapshot, verify_core_hash
|
||||
from config_utils import load_config, save_config_with_snapshot, verify_config_hash
|
||||
import sanitize
|
||||
import validation as validate
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ def _row_index():
|
|||
|
||||
|
||||
def _hash_ok():
|
||||
if not verify_core_hash(request.form.get('config_hash', '')):
|
||||
if not 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
|
||||
|
|
@ -40,7 +40,7 @@ def add_vlan():
|
|||
dnsmasq_log_queries = 'dnsmasq_log_queries' in request.form
|
||||
use_blocklists = sanitize.filterlist(
|
||||
request.form.getlist('use_blocklists'),
|
||||
{b.get('name') for b in load_core().get('dns_blocking', {}).get('blocklists', [])},
|
||||
{b.get('name') for b in load_config().get('dns_blocking', {}).get('blocklists', [])},
|
||||
)
|
||||
|
||||
if not name:
|
||||
|
|
@ -61,8 +61,8 @@ def add_vlan():
|
|||
if not _hash_ok():
|
||||
return redirect(VIEW)
|
||||
|
||||
core = load_core()
|
||||
vlans = core.setdefault('vlans', [])
|
||||
cfg = load_config()
|
||||
vlans = cfg.setdefault('vlans', [])
|
||||
|
||||
if any(validate.derive_vlan_id(v.get('subnet', ''), v.get('subnet_mask', 24)) == vlan_id for v in vlans):
|
||||
flash(f'VLAN {vlan_id} (derived from subnet) already exists.', 'error')
|
||||
|
|
@ -86,14 +86,14 @@ def add_vlan():
|
|||
else:
|
||||
entry['reservations'] = []
|
||||
vlans.append(entry)
|
||||
errors = validate.validate_config(core)
|
||||
errors = validate.validate_config(cfg)
|
||||
if errors:
|
||||
for msg in errors:
|
||||
flash(msg, 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
flash(save_core_with_snapshot(
|
||||
core,
|
||||
flash(save_config_with_snapshot(
|
||||
cfg,
|
||||
path='vlans', key=name, operation='add',
|
||||
before=None, after={k: entry[k] for k in _VLAN_FIELDS if k in entry},
|
||||
description=f'Added VLAN: {name} ({subnet}/{subnet_mask})',
|
||||
|
|
@ -116,7 +116,7 @@ def edit_vlan():
|
|||
dnsmasq_log_queries = 'dnsmasq_log_queries' in request.form
|
||||
use_blocklists = sanitize.filterlist(
|
||||
request.form.getlist('use_blocklists'),
|
||||
{b.get('name') for b in load_core().get('dns_blocking', {}).get('blocklists', [])},
|
||||
{b.get('name') for b in load_config().get('dns_blocking', {}).get('blocklists', [])},
|
||||
)
|
||||
|
||||
subnet_mask_raw = request.form.get('subnet_mask')
|
||||
|
|
@ -137,8 +137,8 @@ def edit_vlan():
|
|||
if not _hash_ok():
|
||||
return redirect(VIEW)
|
||||
|
||||
core = load_core()
|
||||
vlans = core.get('vlans', [])
|
||||
cfg = load_config()
|
||||
vlans = cfg.get('vlans', [])
|
||||
if idx < 0 or idx >= len(vlans):
|
||||
flash('VLAN not found.', 'error')
|
||||
return redirect(VIEW)
|
||||
|
|
@ -179,14 +179,14 @@ def edit_vlan():
|
|||
'mdns_reflection': mdns_reflection,
|
||||
'use_blocklists': use_blocklists,
|
||||
})
|
||||
errors = validate.validate_config(core)
|
||||
errors = validate.validate_config(cfg)
|
||||
if errors:
|
||||
for msg in errors:
|
||||
flash(msg, 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
flash(save_core_with_snapshot(
|
||||
core,
|
||||
flash(save_config_with_snapshot(
|
||||
cfg,
|
||||
path='vlans', key=name, operation='edit',
|
||||
before=before, after={k: existing.get(k) for k in _VLAN_FIELDS},
|
||||
description=f'Edited VLAN: {name}',
|
||||
|
|
@ -204,21 +204,21 @@ def delete_vlan():
|
|||
if not _hash_ok():
|
||||
return redirect(VIEW)
|
||||
|
||||
core = load_core()
|
||||
vlans = core.get('vlans', [])
|
||||
cfg = load_config()
|
||||
vlans = cfg.get('vlans', [])
|
||||
if idx < 0 or idx >= len(vlans):
|
||||
flash('VLAN not found.', 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
removed = vlans.pop(idx)
|
||||
errors = validate.validate_config(core)
|
||||
errors = validate.validate_config(cfg)
|
||||
if errors:
|
||||
for msg in errors:
|
||||
flash(msg, 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
flash(save_core_with_snapshot(
|
||||
core,
|
||||
flash(save_config_with_snapshot(
|
||||
cfg,
|
||||
path='vlans', key=removed['name'], operation='delete',
|
||||
before={k: removed.get(k) for k in _VLAN_FIELDS},
|
||||
after=None,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue