Development

This commit is contained in:
Matthew Grotke 2026-06-09 11:00:37 -04:00
parent 909030bace
commit 721670469e
3 changed files with 43 additions and 17 deletions

View file

@ -64,11 +64,16 @@ def download_blocklists(data):
return not any_fail
LAST_DL_FILE = BLOCKLIST_DIR / ".last-dl"
def main():
check_root()
data = load_config()
print("Downloading blocklists ==============================================")
success = download_blocklists(data)
BLOCKLIST_DIR.mkdir(exist_ok=True)
LAST_DL_FILE.write_text(str(int(__import__('time').time())))
if not success:
print("WARNING: One or more downloads failed.")
sys.exit(1)

View file

@ -515,27 +515,30 @@ def check_configurations(data):
pass
# --- Blocklist file freshness ---
now = datetime.now(timezone.utc).timestamp()
now = datetime.now(timezone.utc).timestamp()
bl_library = {bl["name"]: bl for bl in data.get("dns_blocking", {}).get("blocklists", [])}
needed = set()
for vlan in vlans:
names = vlan.get("use_blocklists", [])
if not names:
needed.update(vlan.get("use_blocklists", []))
for name in sorted(needed):
bl = bl_library.get(name)
if not bl or bl.get("bl_type") == "local":
continue
vlan_name = vlan["name"]
path = _vlan_hosts_file(vlan)
label = ", ".join(sorted(names))
if not path.exists():
save_as = bl.get("save_as", "")
path = BLOCKLIST_DIR / save_as if save_as else None
if not path or 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`."))
f"blocklist_{name}", f"blocklist ({name})", "warning",
f"Blocklist file for '{name}' has not been downloaded.",
"Run `sudo python3 dl_blocklists.py`."))
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`."))
f"blocklist_{name}", f"blocklist ({name})", "warning",
f"Blocklist '{name}' is {age_h}h old (threshold 36h).",
"Run `sudo python3 dl_blocklists.py`."))
else:
results.append(ok(f"blocklist_{vlan_name}", f"blocklist ({vlan_name})"))
results.append(ok(f"blocklist_{name}", f"blocklist ({name})"))
# --- Disk space ---
try: