50 lines
2.1 KiB
Python
50 lines
2.1 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', 25328))
|
|
tokens['CAPTIVE_HTTPS_DOMAIN'] = cp.get('https_domain', '')
|
|
|
|
display_rows = []
|
|
for vlan in captive_vlans:
|
|
cp = vlan.get('captive_portal', {})
|
|
title = cp.get('portal_splash_title', vlan.get('portal_splash_title', ''))
|
|
text = cp.get('portal_splash_text', vlan.get('portal_splash_text', ''))
|
|
terms = cp.get('portal_terms', vlan.get('portal_terms', []))
|
|
require_upw = cp.get('require_username_password', vlan.get('require_username_password', False))
|
|
duration = cp.get('default_duration_seconds', vlan.get('default_duration_seconds', 0))
|
|
n = len(terms)
|
|
display_rows.append({
|
|
'vlan_name': vlan['name'],
|
|
'portal_splash_title': title,
|
|
'portal_splash_text': text,
|
|
'portal_terms': terms,
|
|
'portal_terms_display': f'{n} term{"s" if n != 1 else ""}' if n else '--',
|
|
'require_upw': require_upw,
|
|
'require_username_password': require_upw,
|
|
'default_duration_seconds': duration,
|
|
})
|
|
|
|
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
|