linuxrouter/docker/routlin-dash/app/pages/captiveportal/view.py
2026-06-07 15:11:40 -04:00

42 lines
1.6 KiB
Python

import json
import config_utils
import factory
def collect_tokens(cfg):
tokens = config_utils.collect_layout_tokens(cfg)
cp = cfg.get('captive_portal', {})
captive_vlans = [v for v in cfg.get('vlans', []) if v.get('restricted_vlan') == 'c']
if captive_vlans:
names = ', '.join(v['name'] for v in captive_vlans)
tokens['CAPTIVE_STATUS_TEXT'] = f"Captive portal active on: {names}."
else:
tokens['CAPTIVE_STATUS_TEXT'] = (
'No captive portal VLANs configured. '
'Set Restricted VLAN = Captive Portal on the Network Layout page.'
)
tokens['CAPTIVE_HTTP_PORT'] = str(cp.get('http_port', 8081))
tokens['CAPTIVE_HTTPS_DOMAIN'] = cp.get('https_domain', '')
display_rows = []
for vlan in captive_vlans:
terms = vlan.get('portal_terms', [])
n = len(terms)
display_rows.append({
'vlan_name': vlan['name'],
'portal_splash_title': vlan.get('portal_splash_title', ''),
'portal_splash_text': vlan.get('portal_splash_text', ''),
'portal_terms': terms,
'portal_terms_display': f'{n} term{"s" if n != 1 else ""}' if n else '--',
})
content = factory.load_json(f'{factory.PAGES_DIR}/captiveportal/content.json')
for table_item in factory.iter_table_items(content.get('items', [])):
ds = table_item.get('datasource', '')
data = display_rows if ds == 'captive_portals' else []
tokens[factory.table_token_key(ds)] = factory.build_table(table_item, tokens, data)
return tokens