Development

This commit is contained in:
Matthew Grotke 2026-06-09 02:23:57 -04:00
parent d5dfb637fc
commit 2e4921ab73
4 changed files with 48 additions and 1 deletions

View file

@ -731,7 +731,7 @@ def config_datasource(name):
row['local_entries'] = '' row['local_entries'] = ''
row['source_display'] = row.get('url', '') row['source_display'] = row.get('url', '')
vlan_names = used_by.get(bl.get('name', ''), []) vlan_names = used_by.get(bl.get('name', ''), [])
row['used_by'] = json.dumps([{'n': n, 'd': n} for n in vlan_names]) row['used_by'] = json.dumps([{'n': n, 'd': ''} for n in vlan_names])
rows.append(row) rows.append(row)
return rows return rows

View file

@ -89,6 +89,13 @@ def blocklists_delete():
before = copy.deepcopy(items[idx]) before = copy.deepcopy(items[idx])
name = before.get('name', str(idx)) name = before.get('name', str(idx))
items.pop(idx) items.pop(idx)
for vlan in cfg.get('vlans', []):
current = set(vlan.get('use_blocklists', []))
if name in current:
current.discard(name)
vlan['use_blocklists'] = sorted(current)
errors = validate.validate_config(cfg) errors = validate.validate_config(cfg)
if errors: if errors:
for msg in errors: for msg in errors:
@ -152,6 +159,19 @@ def blocklists_edit():
items[idx]['save_as'] = _save_as_from_name(fields['name'], 'conf') items[idx]['save_as'] = _save_as_from_name(fields['name'], 'conf')
items[idx].pop('local_lines', None) items[idx].pop('local_lines', None)
old_name = before.get('name', '')
used_by_vlans = set(request.form.getlist('used_by_vlans'))
for vlan in cfg.get('vlans', []):
vlan_name = vlan.get('name', '')
current = set(vlan.get('use_blocklists', []))
if old_name and old_name != fields['name']:
current.discard(old_name)
if vlan_name in used_by_vlans:
current.add(fields['name'])
else:
current.discard(fields['name'])
vlan['use_blocklists'] = sorted(current)
errors = validate.validate_config(cfg) errors = validate.validate_config(cfg)
if errors: if errors:
for msg in errors: for msg in errors:
@ -202,6 +222,17 @@ def addblocklist_add():
} }
blocklists.append(entry) blocklists.append(entry)
used_by_vlans = set(request.form.getlist('used_by_vlans'))
for vlan in cfg.get('vlans', []):
vlan_name = vlan.get('name', '')
current = set(vlan.get('use_blocklists', []))
if vlan_name in used_by_vlans:
current.add(fields['name'])
else:
current.discard(fields['name'])
vlan['use_blocklists'] = sorted(current)
errors = validate.validate_config(cfg) errors = validate.validate_config(cfg)
if errors: if errors:
for msg in errors: for msg in errors:

View file

@ -146,6 +146,10 @@
"type": "raw_html", "type": "raw_html",
"html": "</div>" "html": "</div>"
}, },
{
"type": "raw_html",
"html": "%VLAN_USED_BY_CHECKBOXES%"
},
{ {
"type": "button_row", "type": "button_row",
"items": [ "items": [

View file

@ -99,6 +99,18 @@ def collect_tokens(cfg):
tokens['DNS_LOG_TAIL'], tokens['DNS_LOG_SUMMARY'] = _dnsblocking_log_tail(cfg) tokens['DNS_LOG_TAIL'], tokens['DNS_LOG_SUMMARY'] = _dnsblocking_log_tail(cfg)
blocklists = cfg.get('dns_blocking', {}).get('blocklists', []) blocklists = cfg.get('dns_blocking', {}).get('blocklists', [])
tokens['BLOCKLIST_EXISTING_NAMES_JS'] = json.dumps([bl.get('name', '') for bl in blocklists]) tokens['BLOCKLIST_EXISTING_NAMES_JS'] = json.dumps([bl.get('name', '') for bl in blocklists])
vlans = cfg.get('vlans', [])
vlan_checkboxes = ''.join(
f'<label class="form-checkbox-row">'
f'<input type="checkbox" name="used_by_vlans" value="{factory.e(v["name"])}" class="form-checkbox">'
f' <span class="form-checkbox-label">{factory.e(v["name"])}</span>'
f'</label>'
for v in vlans if v.get('name')
)
tokens['VLAN_USED_BY_CHECKBOXES'] = (
f'<div class="form-group"><label class="form-label">Used By</label>'
f'<div>{vlan_checkboxes}</div></div>'
) if vlan_checkboxes else ''
content = factory.load_json(f'{factory.PAGES_DIR}/dnsblocking/content.json') content = factory.load_json(f'{factory.PAGES_DIR}/dnsblocking/content.json')
for table_item in factory.iter_table_items(content.get('items', [])): for table_item in factory.iter_table_items(content.get('items', [])):
ds = table_item.get('datasource', '') ds = table_item.get('datasource', '')