linuxrouter/docker/routlin-dash/app/pages/networklayout/view.py
2026-06-07 00:21:08 -04:00

37 lines
1.7 KiB
Python

import json
import config_utils
import factory
import settings
PRO_LICENSE = settings.is_pro()
def collect_tokens(cfg):
tokens = config_utils.collect_layout_tokens(cfg)
vlans = cfg.get('vlans', [])
dv = next((v for v in vlans if v.get('radius_default')), None)
tokens['EXISTING_VLAN_IDS_JSON'] = json.dumps([v.get('vlan_id') for v in vlans])
tokens['EXISTING_VLAN_NAMES_JSON'] = json.dumps([v.get('name') for v in vlans])
tokens['RADIUS_DEFAULT_VLAN'] = f'"{dv["name"]}" (VLAN {dv["vlan_id"]})' if dv else 'none set'
tokens['PRO_LICENSE_JS'] = 'true' if PRO_LICENSE else ''
if PRO_LICENSE:
tokens['RESTRICTED_VLAN_OPTIONS'] = json.dumps([
{'value': '', 'label': 'Unrestricted'},
{'value': 'q', 'label': 'Quarantined'},
{'value': 'c', 'label': 'Captive Portal'},
])
else:
tokens['RESTRICTED_VLAN_OPTIONS'] = json.dumps([
{'value': '', 'label': 'Unrestricted'},
{'value': 'q', 'label': 'Quarantined (PRO REQUIRED)', 'disabled': True},
{'value': 'c', 'label': 'Captive Portal (PRO REQUIRED)', 'disabled': True},
])
tokens['BLOCKLIST_NAME_OPTIONS'] = json.dumps([
{'value': bl.get('name', ''), 'label': bl.get('description', bl.get('name', ''))}
for bl in cfg.get('dns_blocking', {}).get('blocklists', [])
])
content = factory.load_json(f'{factory.PAGES_DIR}/networklayout/content.json')
for table_item in factory.iter_table_items(content.get('items', [])):
ds = table_item.get('datasource', '')
tokens[factory.table_token_key(ds)] = factory.build_table(table_item, tokens, config_utils.load_datasource(ds))
return tokens