Development
This commit is contained in:
parent
df08cec23f
commit
0cd648729e
2 changed files with 25 additions and 32 deletions
|
|
@ -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()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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:
|
|
||||||
combos = {}
|
|
||||||
for vlan in vlans:
|
for vlan in vlans:
|
||||||
names = vlan.get("use_blocklists", [])
|
names = vlan.get("use_blocklists", [])
|
||||||
if names:
|
if not names:
|
||||||
combos[_combo_hash(names)] = names
|
continue
|
||||||
now = datetime.now(timezone.utc).timestamp()
|
vlan_name = vlan["name"]
|
||||||
for h, names in combos.items():
|
path = _vlan_hosts_file(vlan)
|
||||||
path = _merged_path(h)
|
label = ", ".join(sorted(names))
|
||||||
label = ", ".join(names)
|
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
results.append(problem(
|
results.append(problem(
|
||||||
f"blocklist_{h}", f"blocklist ({label})", "warning",
|
f"blocklist_{vlan_name}", f"blocklist ({vlan_name})", "warning",
|
||||||
f"Merged blocklist file for '{label}' does not exist.",
|
f"Blocklist hosts file for '{vlan_name}' does not exist.",
|
||||||
"Run `sudo python3 dl_blocklists.py` to download blocklists."))
|
"Run `sudo python3 dl_blocklists.py && sudo python3 core.py --merge-blocklists`."))
|
||||||
elif now - path.stat().st_mtime > BLOCKLIST_STALE_SECS:
|
elif now - path.stat().st_mtime > BLOCKLIST_STALE_SECS:
|
||||||
age_h = int((now - path.stat().st_mtime) / 3600)
|
age_h = int((now - path.stat().st_mtime) / 3600)
|
||||||
results.append(problem(
|
results.append(problem(
|
||||||
f"blocklist_{h}", f"blocklist ({label})", "warning",
|
f"blocklist_{vlan_name}", f"blocklist ({vlan_name})", "warning",
|
||||||
f"Merged blocklist for '{label}' is {age_h}h old (threshold 36h).",
|
f"Blocklist hosts file for '{vlan_name}' is {age_h}h old (threshold 36h).",
|
||||||
"Run `sudo python3 dl_blocklists.py` to refresh."))
|
"Run `sudo python3 dl_blocklists.py && sudo python3 core.py --merge-blocklists`."))
|
||||||
else:
|
else:
|
||||||
results.append(ok(f"blocklist_{h}", f"blocklist ({label})"))
|
results.append(ok(f"blocklist_{vlan_name}", f"blocklist ({vlan_name})"))
|
||||||
|
|
||||||
# --- Disk space ---
|
# --- Disk space ---
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue