Development
This commit is contained in:
parent
563d82daf3
commit
70ccfe2c29
48 changed files with 549 additions and 578 deletions
|
|
@ -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}')
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import json
|
||||
from config_utils import collect_layout_tokens, load_datasource
|
||||
from factory import load_json, build_table, table_token_key, iter_table_items, PAGES_DIR
|
||||
import settings as settings
|
||||
import config_utils
|
||||
import factory
|
||||
import settings
|
||||
|
||||
PRO_LICENSE = settings.is_pro()
|
||||
|
||||
|
||||
def collect_tokens(cfg):
|
||||
tokens = collect_layout_tokens(cfg)
|
||||
tokens = config_utils.collect_layout_tokens(cfg)
|
||||
vlans = cfg.get('vlans', [])
|
||||
dv = next((v for v in vlans if v.get('radius_default')), None)
|
||||
tokens['EXISTING_VLAN_IDS_JSON'] = json.dumps([v.get('vlan_id') for v in vlans])
|
||||
|
|
@ -30,8 +30,8 @@ def collect_tokens(cfg):
|
|||
{'value': bl.get('name', ''), 'label': bl.get('description', bl.get('name', ''))}
|
||||
for bl in cfg.get('dns_blocking', {}).get('blocklists', [])
|
||||
])
|
||||
content = load_json(f'{PAGES_DIR}/networklayout/content.json')
|
||||
for table_item in iter_table_items(content.get('items', [])):
|
||||
content = factory.load_json(f'{factory.PAGES_DIR}/networklayout/content.json')
|
||||
for table_item in factory.iter_table_items(content.get('items', [])):
|
||||
ds = table_item.get('datasource', '')
|
||||
tokens[table_token_key(ds)] = build_table(table_item, tokens, load_datasource(ds))
|
||||
tokens[factory.table_token_key(ds)] = factory.build_table(table_item, tokens, config_utils.load_datasource(ds))
|
||||
return tokens
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue