]> git.ipfire.org Git - dbl.git/commitdiff
exporters: Support exporting lists that have never been updated
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Dec 2025 12:10:35 +0000 (12:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Dec 2025 12:10:35 +0000 (12:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dnsbl/exporters.py
src/scripts/dnsbl.in

index 76f17c25fb9afe7a15eacfb6fad3fa5002011a38..4ff304cbbe496df382a0efb3612ceefab7d6b967 100644 (file)
@@ -19,6 +19,7 @@
 ###############################################################################
 
 import abc
+import datetime
 import dns.name
 import dns.rdataclass
 import dns.zone
@@ -69,6 +70,8 @@ class TextExporter(Exporter):
                """
                        Writes a header
                """
+               now = datetime.datetime.now()
+
                lines = [
                        "##############################################################################",
                        " DNS Blocklist for IPFire",
@@ -89,11 +92,20 @@ class TextExporter(Exporter):
                                "",
                        ]
 
+               # Add the license
                lines += [
                        " License : %s" % self.list.license,
-                       " Updated : %s" % self.list.updated_at.isoformat(),
+               ]
+
+               # Add the update timestamp
+               if self.list.updated_at:
+                       lines += [
+                               " Updated : %s" % self.list.updated_at.isoformat(),
+                       ]
+
+               lines += [
                        "",
-                       " Copyright (C) %s - IPFire Team" % self.list.updated_at.strftime("%Y"),
+                       " Copyright (C) %s - IPFire Team" % now.strftime("%Y"),
                        "",
                        " For more information or to contribute:",
                        "   https://dnsbl.ipfire.org/",
@@ -157,7 +169,10 @@ class ZoneExporter(TextExporter):
                zone = dns.zone.Zone(origin)
 
                # Make the serial
-               serial = self.list.updated_at.strftime("%s")
+               if self.list.updated_at:
+                       serial = self.list.updated_at.strftime("%s")
+               else:
+                       serial = "0"
 
                # Create the SOA
                soa = dns.rdataset.from_text(
@@ -264,7 +279,8 @@ class SquidGuardExporter(Exporter):
                file.size = f.tell()
 
                # Set the mtime
-               file.mtime = list.updated_at.timestamp()
+               if self.list.updated_at:
+                       file.mtime = self.list.updated_at.timestamp()
 
                # Reset the buffer
                f.seek(0)
index ec0196bfc31d4675511649ea8641f3b5b42d16df..81357803ee1d9ec005aaf3569b89cac87ed44372 100644 (file)
@@ -336,7 +336,11 @@ class CLI(object):
 
                                        # Set the modification time (so that clients won't download again
                                        # just because we have done a re-export)
-                                       os.utime(f.name, (list.updated_at.timestamp(), list.updated_at.timestamp()))
+                                       if list.updated_at:
+                                               os.utime(f.name, (
+                                                       list.updated_at.timestamp(),
+                                                       list.updated_at.timestamp(),
+                                               ))
 
                                        # Fix permissions
                                        os.chmod(f.name, 0o644)