Development

This commit is contained in:
Matthew Grotke 2026-06-09 09:54:47 -04:00
parent 49dd4a2cf8
commit e33133df1e
9 changed files with 412 additions and 414 deletions

View file

@ -370,20 +370,13 @@ def _dry_run_conflicting_services(data):
def _dry_run_blocklists(data):
print("Blocklists (dry-run) ================================================")
for entry in data.get("dns_blocking", {}).get("blocklists", []):
print(f" Would download: {entry['description']}")
print(f" URL: {entry['url']}")
seen = {}
for vlan in data["vlans"]:
for vlan in data.get("vlans", []):
names = vlan.get("use_blocklists", [])
if names:
h = dnsmasq.combo_hash(names)
if h not in seen:
seen[h] = sorted(names)
path = dnsmasq.merged_path(h)
action = "update" if path.exists() else "create"
print(f" Would {action} merged blocklist: {path}")
print(f" Sources: {', '.join(sorted(names))}")
f = dnsmasq.vlan_hosts_file(vlan)
action = "update" if f.exists() else "create"
print(f" Would {action}: {f}")
print(f" Sources: {', '.join(sorted(names))}")
def _dry_run_timer(data):
print("Timer (dry-run) =====================================================")
@ -751,7 +744,7 @@ 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 dns-blocklists.py")
print(" Run: sudo python3 dl_blocklists.py")
dnsmasq.apply_dnsmasq_instances(data, start_if_needed=True)
print()
@ -856,7 +849,8 @@ def main():
" sudo python3 core.py --disable --dry-run\n"
)
)
parser.add_argument("--apply", action="store_true", help="Apply full config: services, networkd, dnsmasq, nftables, timer, boot service")
parser.add_argument("--apply", action="store_true", help="Apply full config: services, networkd, dnsmasq, nftables, timer, boot service")
parser.add_argument("--merge-blocklists", action="store_true", help="Merge downloaded blocklists and reload dnsmasq via SIGHUP (no restart)")
parser.add_argument("--dry-run", action="store_true", help="Preview all actions without making changes (combine with --apply or --disable)")
parser.add_argument("--status", action="store_true", help="Show service and timer status")
parser.add_argument("--view-configs", action="store_true", help="Show active per-VLAN dnsmasq config files")
@ -870,7 +864,7 @@ def main():
args = parser.parse_args()
if not any([args.apply,
if not any([args.apply, args.merge_blocklists,
args.dry_run, args.status, args.view_configs, args.view_leases,
args.view_rules, args.disable, args.view_metrics,
args.reset_leases]):
@ -924,6 +918,22 @@ def main():
cmd_disable(data, dry_run=args.dry_run)
return
if args.merge_blocklists:
if not shared.is_root():
die("This script must be run as root (sudo).")
general = data.get("dns_blocking", {}).get("general", {})
dnsmasq.setup_blocklist_logging(general)
print("Merging blocklists ==================================================")
success = dnsmasq.update_blocklist_hosts(data)
print()
if success:
print("Reloading dnsmasq instances =========================================")
dnsmasq.sighup_all_instances()
else:
print("WARNING: Some blocklists failed -- reloading anyway with available data.")
dnsmasq.sighup_all_instances()
return
if args.apply:
cmd_apply(data, dry_run=args.dry_run)
return