Development

This commit is contained in:
Matthew Grotke 2026-06-09 12:07:38 -04:00
parent eae133f18e
commit 66be049f14
2 changed files with 11 additions and 11 deletions

View file

@ -49,8 +49,12 @@ def _last_dl_time():
def blocklist_stats_html(cfg):
db_rows = config_utils._bl_db_rows()
last_dl = _last_dl_time()
db_rows = config_utils._bl_db_rows()
last_dl = _last_dl_time()
bl_vlans = {}
for vlan in cfg.get('vlans', []):
for bl_name in vlan.get('use_blocklists', []):
bl_vlans.setdefault(bl_name, []).append(vlan['name'])
rows = ''
for bl in cfg.get('dns_blocking', {}).get('blocklists', []):
name = bl.get('name', '')
@ -90,12 +94,15 @@ def blocklist_stats_html(cfg):
warn = WARN_ICON
else:
warn = ''
vlan_names = bl_vlans.get(name, [])
used_by = ', '.join(factory.e(v) for v in vlan_names) if vlan_names else '<span class="text-muted">Not used by any VLANs</span>'
rows += (
'<tr>'
f'<td class="table-cell">{factory.e(name)}</td>'
f'<td class="table-cell">{entries}</td>'
f'<td class="table-cell">{size_str}</td>'
f'<td class="table-cell">{factory.e(last_refreshed)}{warn}</td>'
f'<td class="table-cell">{used_by}</td>'
'</tr>'
)
if not rows:
@ -106,6 +113,7 @@ def blocklist_stats_html(cfg):
'<th class="table-header">Entries</th>'
'<th class="table-header">Size</th>'
'<th class="table-header">Last Refreshed</th>'
'<th class="table-header">Used by VLAN(s)</th>'
'</tr></thead>'
f'<tbody>{rows}</tbody></table>'
)

View file

@ -225,18 +225,10 @@ def update_blocklist_hosts(data):
db = _open_db()
bl_library = {bl["name"]: bl for bl in data.get("dns_blocking", {}).get("blocklists", [])}
needed = set()
for vlan in data.get("vlans", []):
needed.update(vlan.get("use_blocklists", []))
changed = set()
any_fail = False
for name in needed:
if name not in bl_library:
_log.warning(f"Blocklist '{name}' referenced by a VLAN but not defined -- skipping")
continue
entry = bl_library[name]
for name, entry in bl_library.items():
is_local = entry.get("bl_type") == "local"
save_as = entry.get("save_as", "")