From: Michael Tremer Date: Wed, 10 Dec 2025 12:16:22 +0000 (+0000) Subject: dnsbl: export-all: Create a tarball with all lists for squidGuard X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3baa02b0fac9a5da3048135aa650d1e39ffb74a;p=dnsbl.git dnsbl: export-all: Create a tarball with all lists for squidGuard Signed-off-by: Michael Tremer --- diff --git a/src/dnsbl/exporters.py b/src/dnsbl/exporters.py index 28a2339..504a72b 100644 --- a/src/dnsbl/exporters.py +++ b/src/dnsbl/exporters.py @@ -245,17 +245,17 @@ class SquidGuardExporter(Exporter): # Create a tar file with tarfile.open(fileobj=f, mode="w|gz") as tarball: # Write the list - self._write_list(tarball, self.list) + self._write_list(tarball) - def _write_list(self, tarball, list): + def _write_list(self, tarball): # Create a new - file = tarfile.TarInfo(name="%s/domains" % list.slug) + file = tarfile.TarInfo(name="%s/domains" % self.list.slug) # Write the payload to memory f = io.BytesIO() # Create a domain exporter - exporter = DomainsExporter(self.backend, list) + exporter = DomainsExporter(self.backend, self.list) # Write all domains to the buffer exporter(f) @@ -267,11 +267,26 @@ class SquidGuardExporter(Exporter): file.size = f.tell() # Set the mtime - if self.list.updated_at: - file.mtime = self.list.updated_at.timestamp() + file.mtime = self.list.updated_at.timestamp() # Reset the buffer f.seek(0) # Write the buffer to the tarball tarball.addfile(file, fileobj=f) + + +class CombinedSquidGuardExporter(object): + """ + This is a special exporter which combines all lists into a single tarball + """ + def __init__(self, backend, lists): + self.backend = backend + self.lists = lists + + def __call__(self, f): + # Create a tar file + with tarfile.open(fileobj=f, mode="w|gz") as tarball: + for list in self.lists: + exporter = SquidGuardExporter(self.backend, list) + exporter._write_list(tarball) diff --git a/src/scripts/dnsbl.in b/src/scripts/dnsbl.in index 8135780..303fadf 100644 --- a/src/scripts/dnsbl.in +++ b/src/scripts/dnsbl.in @@ -21,6 +21,7 @@ import argparse import dnsbl +import dnsbl.exporters import logging import os import pathlib @@ -348,6 +349,11 @@ class CLI(object): # Once the output has been written in full, we will rename the file os.link(f.name, name) + # Write all lists as one tarball for squidGuard + exporter = dnsbl.exporters.CombinedSquidGuardExporter(backend, backend.lists) + with open(root / "squidguard.tar.gz", "wb") as f: + exporter(f) + def __add_source(self, backend, args): """ Adds a new source to a list