]> git.ipfire.org Git - dbl.git/commitdiff
dnsbl: Add a header to all exports
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 6 Dec 2025 19:30:02 +0000 (19:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 6 Dec 2025 19:30:02 +0000 (19:30 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dnsbl/lists.py

index 887053dcd31fb962de836306a9e78c2b62e5bad9..b2c94e7d444b27d9b7d366a80cbb011023e416e8 100644 (file)
@@ -232,11 +232,18 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
 
                # Write the domains as they are
                if format == "domains":
+                       # Write the header
+                       self._write_header(f)
+
+                       # Write all domains
                        for domain in self.domains:
                                f.write("%s\n" % domain)
 
                # Write a RPZ zone file
                elif format == "rpz":
+                       # Write the header
+                       self._write_header(f, ";")
+
                        # Write the SOA
                        f.write("%s\n" % " ".join((
                                self.zone,
@@ -263,3 +270,41 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
                # the underlying file handle.
                if detach:
                        f.detach()
+
+       def _write_header(self, f, delim="#"):
+               """
+                       Writes a header
+               """
+               lines = [
+                       "##############################################################################",
+                       " DNS Blocklist for IPFire",
+                       "##############################################################################",
+                       "",
+                       " This file contains domains that are part of the official IPFire DNS",
+                       " Blocklist Project. It is intended for use with DNS servers and firewalls",
+                       " that support blocklisting of known malicious or unwanted domains.",
+                       "",
+                       " List    : %s" % self.name,
+                       " License : %s" % self.license,
+                       " Copyright (C) %s - IPFire Team" % self.updated_at.strftime("%Y"),
+                       "",
+                       " For more information or to contribute:",
+                       "   https://dnsbl.ipfire.org/",
+                       "",
+                       "##############################################################################",
+                       "",
+                       " This list contains data from these sources:",
+                       "",
+               ]
+
+               # Append all sources
+               for source in self.sources:
+                       lines.append("   * %s (%s)" % (source.name, source.license))
+                       lines.append("     %s" % source.url)
+
+               # Newline
+               lines.append("")
+
+               # Write everything to the output file
+               for line in lines:
+                       f.write("%s%s\n" % (delim, line))