diff --git a/routlin/core.py b/routlin/core.py index d812416..81ca128 100644 --- a/routlin/core.py +++ b/routlin/core.py @@ -743,8 +743,8 @@ def cmd_apply(data, dry_run=False): print("dnsmasq instances ===================================================") if not dnsmasq.blocklists_available(data): - print(" NOTE: No merged blocklist files found -- blocklist rules will be absent.") - print(" Run: sudo python3 dl_blocklists.py") + print(" NOTE: No blocklist hosts files found -- blocklist rules will be absent.") + print(" Run: sudo python3 dl_blocklists.py && sudo python3 core.py --merge-blocklists") dnsmasq.apply_dnsmasq_instances(data, start_if_needed=True) print() diff --git a/routlin/health.py b/routlin/health.py index 8597c44..282a46d 100644 --- a/routlin/health.py +++ b/routlin/health.py @@ -72,12 +72,8 @@ def _avahi_interfaces(data): if v.get("mdns_reflection") is True and not validation.is_wg(v) ] -def _combo_hash(names): - key = ",".join(sorted(names)) - return hashlib.sha256(key.encode()).hexdigest()[:8] - -def _merged_path(h): - return BLOCKLIST_DIR / f"merged-{h}.conf" +def _vlan_hosts_file(vlan): + return shared.DNSMASQ_CONF_DIR / f"for-{vlan['name']}.hosts" def _gateway_ips(data): """Return set of all gateway IPs across all VLANs.""" @@ -519,30 +515,27 @@ def check_configurations(data): pass # --- Blocklist file freshness --- - blocklists = data.get("dns_blocking", {}).get("blocklists", []) - if blocklists: - combos = {} - for vlan in vlans: - names = vlan.get("use_blocklists", []) - if names: - combos[_combo_hash(names)] = names - now = datetime.now(timezone.utc).timestamp() - for h, names in combos.items(): - path = _merged_path(h) - label = ", ".join(names) - if not path.exists(): - results.append(problem( - f"blocklist_{h}", f"blocklist ({label})", "warning", - f"Merged blocklist file for '{label}' does not exist.", - "Run `sudo python3 dl_blocklists.py` to download blocklists.")) - elif now - path.stat().st_mtime > BLOCKLIST_STALE_SECS: - age_h = int((now - path.stat().st_mtime) / 3600) - results.append(problem( - f"blocklist_{h}", f"blocklist ({label})", "warning", - f"Merged blocklist for '{label}' is {age_h}h old (threshold 36h).", - "Run `sudo python3 dl_blocklists.py` to refresh.")) - else: - results.append(ok(f"blocklist_{h}", f"blocklist ({label})")) + now = datetime.now(timezone.utc).timestamp() + for vlan in vlans: + names = vlan.get("use_blocklists", []) + if not names: + continue + vlan_name = vlan["name"] + path = _vlan_hosts_file(vlan) + label = ", ".join(sorted(names)) + if not path.exists(): + results.append(problem( + f"blocklist_{vlan_name}", f"blocklist ({vlan_name})", "warning", + f"Blocklist hosts file for '{vlan_name}' does not exist.", + "Run `sudo python3 dl_blocklists.py && sudo python3 core.py --merge-blocklists`.")) + elif now - path.stat().st_mtime > BLOCKLIST_STALE_SECS: + age_h = int((now - path.stat().st_mtime) / 3600) + results.append(problem( + f"blocklist_{vlan_name}", f"blocklist ({vlan_name})", "warning", + f"Blocklist hosts file for '{vlan_name}' is {age_h}h old (threshold 36h).", + "Run `sudo python3 dl_blocklists.py && sudo python3 core.py --merge-blocklists`.")) + else: + results.append(ok(f"blocklist_{vlan_name}", f"blocklist ({vlan_name})")) # --- Disk space --- try: