From: Michael Tremer Date: Wed, 10 Dec 2025 12:10:35 +0000 (+0000) Subject: exporters: Support exporting lists that have never been updated X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6de831f0bd6f92cbebce60f401cddb9966709b1c;p=dbl.git exporters: Support exporting lists that have never been updated Signed-off-by: Michael Tremer --- diff --git a/src/dnsbl/exporters.py b/src/dnsbl/exporters.py index 76f17c2..4ff304c 100644 --- a/src/dnsbl/exporters.py +++ b/src/dnsbl/exporters.py @@ -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) diff --git a/src/scripts/dnsbl.in b/src/scripts/dnsbl.in index ec0196b..8135780 100644 --- a/src/scripts/dnsbl.in +++ b/src/scripts/dnsbl.in @@ -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)