26 lines
893 B
Python
26 lines
893 B
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', '')
|
|
tokens['CAPTIVE_SPLASH_TEXT'] = cp.get('splash_text', '')
|
|
tokens['CAPTIVE_TERMS'] = json.dumps(cp.get('terms', []))
|
|
|
|
return tokens
|