26 lines
1.3 KiB
Python
26 lines
1.3 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 license
|
|
|
|
PRO_LICENSE = license.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['RESTRICTED_VLAN_LABEL'] = 'Restricted VLAN' if PRO_LICENSE else 'Restricted VLAN (PRO FEATURE)'
|
|
tokens['RESTRICTED_VLAN_DISABLED'] = '' if PRO_LICENSE else '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
|