Development

This commit is contained in:
Matthew Grotke 2026-06-09 10:31:37 -04:00
parent df08cec23f
commit 0cd648729e
2 changed files with 25 additions and 32 deletions

View file

@ -743,8 +743,8 @@ def cmd_apply(data, dry_run=False):
print("dnsmasq instances ===================================================") print("dnsmasq instances ===================================================")
if not dnsmasq.blocklists_available(data): if not dnsmasq.blocklists_available(data):
print(" NOTE: No merged blocklist files found -- blocklist rules will be absent.") print(" NOTE: No blocklist hosts files found -- blocklist rules will be absent.")
print(" Run: sudo python3 dl_blocklists.py") print(" Run: sudo python3 dl_blocklists.py && sudo python3 core.py --merge-blocklists")
dnsmasq.apply_dnsmasq_instances(data, start_if_needed=True) dnsmasq.apply_dnsmasq_instances(data, start_if_needed=True)
print() print()

View file

@ -72,12 +72,8 @@ def _avahi_interfaces(data):
if v.get("mdns_reflection") is True and not validation.is_wg(v) if v.get("mdns_reflection") is True and not validation.is_wg(v)
] ]
def _combo_hash(names): def _vlan_hosts_file(vlan):
key = ",".join(sorted(names)) return shared.DNSMASQ_CONF_DIR / f"for-{vlan['name']}.hosts"
return hashlib.sha256(key.encode()).hexdigest()[:8]
def _merged_path(h):
return BLOCKLIST_DIR / f"merged-{h}.conf"
def _gateway_ips(data): def _gateway_ips(data):
"""Return set of all gateway IPs across all VLANs.""" """Return set of all gateway IPs across all VLANs."""
@ -519,30 +515,27 @@ def check_configurations(data):
pass pass
# --- Blocklist file freshness --- # --- Blocklist file freshness ---
blocklists = data.get("dns_blocking", {}).get("blocklists", []) now = datetime.now(timezone.utc).timestamp()
if blocklists: for vlan in vlans:
combos = {} names = vlan.get("use_blocklists", [])
for vlan in vlans: if not names:
names = vlan.get("use_blocklists", []) continue
if names: vlan_name = vlan["name"]
combos[_combo_hash(names)] = names path = _vlan_hosts_file(vlan)
now = datetime.now(timezone.utc).timestamp() label = ", ".join(sorted(names))
for h, names in combos.items(): if not path.exists():
path = _merged_path(h) results.append(problem(
label = ", ".join(names) f"blocklist_{vlan_name}", f"blocklist ({vlan_name})", "warning",
if not path.exists(): f"Blocklist hosts file for '{vlan_name}' does not exist.",
results.append(problem( "Run `sudo python3 dl_blocklists.py && sudo python3 core.py --merge-blocklists`."))
f"blocklist_{h}", f"blocklist ({label})", "warning", elif now - path.stat().st_mtime > BLOCKLIST_STALE_SECS:
f"Merged blocklist file for '{label}' does not exist.", age_h = int((now - path.stat().st_mtime) / 3600)
"Run `sudo python3 dl_blocklists.py` to download blocklists.")) results.append(problem(
elif now - path.stat().st_mtime > BLOCKLIST_STALE_SECS: f"blocklist_{vlan_name}", f"blocklist ({vlan_name})", "warning",
age_h = int((now - path.stat().st_mtime) / 3600) f"Blocklist hosts file for '{vlan_name}' is {age_h}h old (threshold 36h).",
results.append(problem( "Run `sudo python3 dl_blocklists.py && sudo python3 core.py --merge-blocklists`."))
f"blocklist_{h}", f"blocklist ({label})", "warning", else:
f"Merged blocklist for '{label}' is {age_h}h old (threshold 36h).", results.append(ok(f"blocklist_{vlan_name}", f"blocklist ({vlan_name})"))
"Run `sudo python3 dl_blocklists.py` to refresh."))
else:
results.append(ok(f"blocklist_{h}", f"blocklist ({label})"))
# --- Disk space --- # --- Disk space ---
try: try: