Development
This commit is contained in:
parent
563d82daf3
commit
70ccfe2c29
48 changed files with 549 additions and 578 deletions
|
|
@ -3,8 +3,8 @@ import copy
|
|||
import ipaddress
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ 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
|
||||
|
|
@ -59,7 +59,7 @@ def _check_ip_in_vlan_subnet(ip, vlan):
|
|||
|
||||
|
||||
@bp.route('/action/dhcpreservations/addreservation_add', methods=['POST'])
|
||||
@require_level('administrator')
|
||||
@auth.require_level('administrator')
|
||||
def addreservation_add():
|
||||
vlan_name = sanitize.name(request.form.get('vlan_name', ''))
|
||||
description = sanitize.text(request.form.get('description', ''))
|
||||
|
|
@ -79,7 +79,7 @@ def addreservation_add():
|
|||
if not _hash_ok():
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
cfg = load_config()
|
||||
cfg = config_utils.load_config()
|
||||
vlans = cfg.get('vlans', [])
|
||||
vlan = next((v for v in vlans if v.get('name') == vlan_name), None)
|
||||
if vlan is None:
|
||||
|
|
@ -113,13 +113,13 @@ def addreservation_add():
|
|||
flash(msg, 'error')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
changes = diff_fields(None, entry)
|
||||
flash(record_group(cfg, 'dhcp_reservations', 'mac', mac, changes, 'core apply'), 'success')
|
||||
changes = config_utils.diff_fields(None, entry)
|
||||
flash(config_utils.record_group(cfg, 'dhcp_reservations', 'mac', mac, changes, 'core apply'), 'success')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
|
||||
@bp.route('/action/dhcpreservations/reservations_toggle', methods=['POST'])
|
||||
@require_level('administrator')
|
||||
@auth.require_level('administrator')
|
||||
def reservations_toggle():
|
||||
idx = _row_index()
|
||||
if idx is None:
|
||||
|
|
@ -128,7 +128,7 @@ def reservations_toggle():
|
|||
if not _hash_ok():
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
cfg = load_config()
|
||||
cfg = config_utils.load_config()
|
||||
items = cfg.get('dhcp_reservations', [])
|
||||
if idx < 0 or idx >= len(items):
|
||||
flash('Entry not found.', 'error')
|
||||
|
|
@ -144,13 +144,13 @@ def reservations_toggle():
|
|||
flash(msg, 'error')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
changes = diff_fields(before, res)
|
||||
flash(record_group(cfg, 'dhcp_reservations', 'mac', res['mac'], changes, 'core apply'), 'success')
|
||||
changes = config_utils.diff_fields(before, res)
|
||||
flash(config_utils.record_group(cfg, 'dhcp_reservations', 'mac', res['mac'], changes, 'core apply'), 'success')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
|
||||
@bp.route('/action/dhcpreservations/reservations_edit', methods=['POST'])
|
||||
@require_level('administrator')
|
||||
@auth.require_level('administrator')
|
||||
def reservations_edit():
|
||||
idx = _row_index()
|
||||
if idx is None:
|
||||
|
|
@ -171,7 +171,7 @@ def reservations_edit():
|
|||
if not _hash_ok():
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
cfg = load_config()
|
||||
cfg = config_utils.load_config()
|
||||
items = cfg.get('dhcp_reservations', [])
|
||||
if idx < 0 or idx >= len(items):
|
||||
flash('Entry not found.', 'error')
|
||||
|
|
@ -208,13 +208,13 @@ def reservations_edit():
|
|||
flash(msg, 'error')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
changes = diff_fields(before, res)
|
||||
flash(record_group(cfg, 'dhcp_reservations', 'mac', mac, changes, 'core apply'), 'success')
|
||||
changes = config_utils.diff_fields(before, res)
|
||||
flash(config_utils.record_group(cfg, 'dhcp_reservations', 'mac', mac, changes, 'core apply'), 'success')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
|
||||
@bp.route('/action/dhcpreservations/reservations_delete', methods=['POST'])
|
||||
@require_level('administrator')
|
||||
@auth.require_level('administrator')
|
||||
def reservations_delete():
|
||||
idx = _row_index()
|
||||
if idx is None:
|
||||
|
|
@ -223,7 +223,7 @@ def reservations_delete():
|
|||
if not _hash_ok():
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
cfg = load_config()
|
||||
cfg = config_utils.load_config()
|
||||
items = cfg.get('dhcp_reservations', [])
|
||||
if idx < 0 or idx >= len(items):
|
||||
flash('Entry not found.', 'error')
|
||||
|
|
@ -236,6 +236,6 @@ def reservations_delete():
|
|||
flash(msg, 'error')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
changes = diff_fields(removed, None)
|
||||
flash(record_group(cfg, 'dhcp_reservations', 'mac', removed['mac'], changes, 'core apply'), 'success')
|
||||
changes = config_utils.diff_fields(removed, None)
|
||||
flash(config_utils.record_group(cfg, 'dhcp_reservations', 'mac', removed['mac'], changes, 'core apply'), 'success')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
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 config_utils
|
||||
import factory
|
||||
|
||||
|
||||
def collect_tokens(cfg):
|
||||
tokens = collect_layout_tokens(cfg)
|
||||
tokens = config_utils.collect_layout_tokens(cfg)
|
||||
vlans = cfg.get('vlans', [])
|
||||
vlan_names = [v.get('name', '') for v in vlans]
|
||||
res_ips_by_vlan, res_hosts_by_vlan = {}, {}
|
||||
|
|
@ -26,8 +26,8 @@ def collect_tokens(cfg):
|
|||
})
|
||||
tokens['RESERVATION_IPS_BY_VLAN_JSON'] = json.dumps(res_ips_by_vlan)
|
||||
tokens['RESERVATION_HOSTNAMES_BY_VLAN_JSON'] = json.dumps(res_hosts_by_vlan)
|
||||
content = load_json(f'{PAGES_DIR}/dhcpreservations/content.json')
|
||||
for table_item in iter_table_items(content.get('items', [])):
|
||||
content = factory.load_json(f'{factory.PAGES_DIR}/dhcpreservations/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