Development

This commit is contained in:
Matthew Grotke 2026-06-07 21:32:46 -04:00
parent bb07e67d53
commit 69b5f00d5b
8 changed files with 165 additions and 26 deletions

View file

@ -17,7 +17,7 @@ def options_save():
before = copy.deepcopy(cfg.get('captive_portal', {}))
try:
http_port = int(request.form.get('http_port', '8081'))
http_port = int(request.form.get('http_port', '25328'))
if not (1024 <= http_port <= 65535):
raise ValueError
except (ValueError, TypeError):
@ -46,25 +46,32 @@ def portal_save():
flash('Captive portal VLAN not found.', 'error')
return redirect(f'/{_PAGE}')
before = {
'portal_splash_title': vlan.get('portal_splash_title', ''),
'portal_splash_text': vlan.get('portal_splash_text', ''),
'portal_terms': vlan.get('portal_terms', []),
}
existing = vlan.get('captive_portal', {})
before = dict(existing)
splash_title = sanitize.description(request.form.get('portal_splash_title', ''))
splash_text = sanitize.description(request.form.get('portal_splash_text', ''))
terms = [t.strip() for t in request.form.getlist('portal_terms') if t.strip()]
require_upw = 'require_username_password' in request.form
vlan['portal_splash_title'] = splash_title
vlan['portal_splash_text'] = splash_text
vlan['portal_terms'] = terms
try:
dur_n = int(request.form.get('default_duration_value', '0').strip() or '0')
dur_unit = request.form.get('default_duration_unit', 'hours')
mult = {'hours': 3600, 'days': 86400}.get(dur_unit, 3600)
duration = dur_n * mult if dur_n > 0 else 0
except (ValueError, TypeError):
duration = 0
after = {
'portal_splash_title': splash_title,
'portal_splash_text': splash_text,
'portal_terms': terms,
**existing,
'portal_splash_title': splash_title,
'portal_splash_text': splash_text,
'portal_terms': terms,
'require_username_password': require_upw,
'default_duration_seconds': duration,
}
vlan['captive_portal'] = after
changes = config_utils.diff_fields(before, after)
flash(config_utils.record_group(
cfg, 'vlans', 'portal', vlan_name, changes, 'core apply'