]> git.ipfire.org Git - dnsbl.git/commitdiff
dnsbl: export-all: Create a tarball with all lists for squidGuard
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Dec 2025 12:16:22 +0000 (12:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Dec 2025 12:16:22 +0000 (12:16 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dnsbl/exporters.py
src/scripts/dnsbl.in

index 28a2339a914a0a82c1493378c0484ff9abaa0eb7..504a72b19aeb0854913e529e73fe2d47844e4c97 100644 (file)
@@ -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)
index 81357803ee1d9ec005aaf3569b89cac87ed44372..303fadfc8e8bfd27f8c52813fc6d294dbc36d1cc 100644 (file)
@@ -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