Development
This commit is contained in:
parent
6f23a57220
commit
4f5f2a8071
5 changed files with 157 additions and 9 deletions
|
|
@ -1,7 +1,8 @@
|
|||
import copy
|
||||
from pathlib import Path
|
||||
from flask import Blueprint, redirect, flash
|
||||
from flask import Blueprint, request, redirect, flash
|
||||
from auth import require_level
|
||||
from config_utils import CONFIGS_DIR
|
||||
from config_utils import CONFIGS_DIR, load_config, record_group, diff_fields
|
||||
|
||||
_PAGE = Path(__file__).parent.name
|
||||
|
||||
|
|
@ -9,6 +10,11 @@ bp = Blueprint(_PAGE, __name__)
|
|||
|
||||
RADIUS_SECRET_FILE = Path(CONFIGS_DIR) / '.radius-secret'
|
||||
|
||||
_VALID_MAC_FORMATS = {
|
||||
'aabbccddeeff', 'aa-bb-cc-dd-ee-ff', 'aa:bb:cc:dd:ee:ff',
|
||||
'AABBCCDDEEFF', 'AA-BB-CC-DD-EE-FF', 'AA:BB:CC:DD:EE:FF',
|
||||
}
|
||||
|
||||
|
||||
@bp.route('/action/radius/regenerate', methods=['POST'])
|
||||
@require_level('administrator')
|
||||
|
|
@ -20,3 +26,27 @@ def regenerate():
|
|||
return redirect(f'/{_PAGE}')
|
||||
flash('Secret deleted. A new secret will be generated when the pending command is applied.', 'success')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
|
||||
@bp.route('/action/radius/options_save', methods=['POST'])
|
||||
@require_level('administrator')
|
||||
def options_save():
|
||||
mac_format = request.form.get('mac_format', 'aabbccddeeff')
|
||||
apply_to = request.form.get('apply_to', 'all')
|
||||
logging = 'logging' in request.form
|
||||
|
||||
if mac_format not in _VALID_MAC_FORMATS:
|
||||
flash('Invalid MAC format.', 'error')
|
||||
return redirect(f'/{_PAGE}')
|
||||
if apply_to not in ('all', 'wireless'):
|
||||
flash('Invalid apply_to value.', 'error')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
cfg = load_config()
|
||||
before = copy.deepcopy(cfg.get('radius_options', {}))
|
||||
after = {'mac_format': mac_format, 'apply_to': apply_to, 'logging': logging}
|
||||
cfg['radius_options'] = after
|
||||
|
||||
changes = diff_fields(before, after)
|
||||
flash(record_group(cfg, 'radius_options', 'setting', 'radius_options', changes, 'core apply'), 'success')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue