linuxrouter/docker/routlin-dash/app/pages/networklayout/view.py
2026-06-06 17:14:01 -04:00

37 lines
1.7 KiB
Python

import json
from config_utils import collect_layout_tokens, load_datasource
from factory import load_json, build_table, table_token_key, iter_table_items, PAGES_DIR
import settings as settings
PRO_LICENSE = settings.is_pro()
def collect_tokens(cfg):
tokens = 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 = load_json(f'{PAGES_DIR}/networklayout/content.json')
for table_item in iter_table_items(content.get('items', [])):
ds = table_item.get('datasource', '')
tokens[table_token_key(ds)] = build_table(table_item, tokens, load_datasource(ds))
return tokens