53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
import copy
|
|
|
|
from flask import Blueprint, request, redirect, flash
|
|
import auth
|
|
import config_utils
|
|
import sanitize
|
|
|
|
_PAGE = 'captiveportal'
|
|
|
|
bp = Blueprint(_PAGE, __name__)
|
|
|
|
|
|
@bp.route('/action/captiveportal/options_save', methods=['POST'])
|
|
@auth.require_level('administrator')
|
|
def options_save():
|
|
cfg = config_utils.load_config()
|
|
before = copy.deepcopy(cfg.get('captive_portal', {}))
|
|
|
|
try:
|
|
http_port = int(request.form.get('http_port', '8081'))
|
|
if not (1024 <= http_port <= 65535):
|
|
raise ValueError
|
|
except (ValueError, TypeError):
|
|
flash('HTTP port must be between 1024 and 65535.', 'error')
|
|
return redirect(f'/{_PAGE}')
|
|
|
|
https_domain = sanitize.description(request.form.get('https_domain', ''))
|
|
|
|
after = {**before, 'http_port': http_port, 'https_domain': https_domain}
|
|
cfg.setdefault('captive_portal', {}).update(after)
|
|
changes = config_utils.diff_fields(before, after)
|
|
flash(config_utils.record_group(
|
|
cfg, 'captive_portal', 'setting', 'captive_portal', changes, 'core apply'
|
|
), 'success')
|
|
return redirect(f'/{_PAGE}')
|
|
|
|
|
|
@bp.route('/action/captiveportal/splash_save', methods=['POST'])
|
|
@auth.require_level('administrator')
|
|
def splash_save():
|
|
cfg = config_utils.load_config()
|
|
before = copy.deepcopy(cfg.get('captive_portal', {}))
|
|
|
|
splash_text = sanitize.description(request.form.get('splash_text', ''))
|
|
terms = [t.strip() for t in request.form.getlist('terms') if t.strip()]
|
|
|
|
after = {**before, 'splash_text': splash_text, 'terms': terms}
|
|
cfg.setdefault('captive_portal', {}).update(after)
|
|
changes = config_utils.diff_fields(before, after)
|
|
flash(config_utils.record_group(
|
|
cfg, 'captive_portal', 'setting', 'captive_portal', changes, 'core apply'
|
|
), 'success')
|
|
return redirect(f'/{_PAGE}')
|