]> git.ipfire.org Git - dbl.git/commitdiff
exporters: Create expressions and urls files for squidguard
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Dec 2025 17:20:29 +0000 (17:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Dec 2025 17:20:29 +0000 (17:20 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dnsbl/exporters.py

index c2ffd331db30902969d2b8f5ecb2cb10f8cae33f..d41305403a4217e0657d507bc7feda015cecae09 100644 (file)
@@ -270,17 +270,32 @@ class SquidGuardExporter(Exporter):
                # Write all domains to the buffer
                exporter(f)
 
+               # Write the file
+               self._write_file(tarball, file, f)
+
+               # squidguard is also expecting some more files
+               for name in ("expressions", "urls"):
+                       file = tarfile.TarInfo(name="%s/%s" % (self.list.slug, name))
+
+                       self._write_file(tarball, file)
+
+       def _write_file(self, tarball, file, f=None):
+               """
+                       A helper function to set some commonly used metadata
+               """
                # Assign the list to be owned by nobody
                file.uname = file.gname = "nobody"
 
-               # Set the length
-               file.size = f.tell()
-
                # Set the mtime
                file.mtime = self.list.updated_at.timestamp()
 
-               # Reset the buffer
-               f.seek(0)
+               # Set the length
+               if f:
+                       file.size = f.tell()
+
+               # Ensure we read the payload from the beginning
+               if f:
+                       f.seek(0)
 
                # Write the buffer to the tarball
                tarball.addfile(file, fileobj=f)