Development
This commit is contained in:
parent
eae133f18e
commit
66be049f14
2 changed files with 11 additions and 11 deletions
|
|
@ -51,6 +51,10 @@ def _last_dl_time():
|
||||||
def blocklist_stats_html(cfg):
|
def blocklist_stats_html(cfg):
|
||||||
db_rows = config_utils._bl_db_rows()
|
db_rows = config_utils._bl_db_rows()
|
||||||
last_dl = _last_dl_time()
|
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 = ''
|
rows = ''
|
||||||
for bl in cfg.get('dns_blocking', {}).get('blocklists', []):
|
for bl in cfg.get('dns_blocking', {}).get('blocklists', []):
|
||||||
name = bl.get('name', '')
|
name = bl.get('name', '')
|
||||||
|
|
@ -90,12 +94,15 @@ def blocklist_stats_html(cfg):
|
||||||
warn = WARN_ICON
|
warn = WARN_ICON
|
||||||
else:
|
else:
|
||||||
warn = ''
|
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 += (
|
rows += (
|
||||||
'<tr>'
|
'<tr>'
|
||||||
f'<td class="table-cell">{factory.e(name)}</td>'
|
f'<td class="table-cell">{factory.e(name)}</td>'
|
||||||
f'<td class="table-cell">{entries}</td>'
|
f'<td class="table-cell">{entries}</td>'
|
||||||
f'<td class="table-cell">{size_str}</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">{factory.e(last_refreshed)}{warn}</td>'
|
||||||
|
f'<td class="table-cell">{used_by}</td>'
|
||||||
'</tr>'
|
'</tr>'
|
||||||
)
|
)
|
||||||
if not rows:
|
if not rows:
|
||||||
|
|
@ -106,6 +113,7 @@ def blocklist_stats_html(cfg):
|
||||||
'<th class="table-header">Entries</th>'
|
'<th class="table-header">Entries</th>'
|
||||||
'<th class="table-header">Size</th>'
|
'<th class="table-header">Size</th>'
|
||||||
'<th class="table-header">Last Refreshed</th>'
|
'<th class="table-header">Last Refreshed</th>'
|
||||||
|
'<th class="table-header">Used by VLAN(s)</th>'
|
||||||
'</tr></thead>'
|
'</tr></thead>'
|
||||||
f'<tbody>{rows}</tbody></table>'
|
f'<tbody>{rows}</tbody></table>'
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -225,18 +225,10 @@ def update_blocklist_hosts(data):
|
||||||
db = _open_db()
|
db = _open_db()
|
||||||
bl_library = {bl["name"]: bl for bl in data.get("dns_blocking", {}).get("blocklists", [])}
|
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()
|
changed = set()
|
||||||
any_fail = False
|
any_fail = False
|
||||||
|
|
||||||
for name in needed:
|
for name, entry in bl_library.items():
|
||||||
if name not in bl_library:
|
|
||||||
_log.warning(f"Blocklist '{name}' referenced by a VLAN but not defined -- skipping")
|
|
||||||
continue
|
|
||||||
entry = bl_library[name]
|
|
||||||
is_local = entry.get("bl_type") == "local"
|
is_local = entry.get("bl_type") == "local"
|
||||||
save_as = entry.get("save_as", "")
|
save_as = entry.get("save_as", "")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue