import abc
import datetime
-import dns.name
-import dns.rdataclass
-import dns.zone
import io
import tarfile
class ZoneExporter(TextExporter):
- def export(self, f, ttl=60, rpz_action="."):
+ def export(self, f, ttl=60):
# Write the header
self.write_header(f, ";")
- # Create the origin
- origin = dns.name.from_text(self.list.zone)
-
- # Create a new zone
- zone = dns.zone.Zone(origin)
-
# Make the serial
serial = self.list.updated_at.strftime("%s")
- # Create the SOA
- soa = dns.rdataset.from_text(
- dns.rdataclass.IN,
- dns.rdatatype.SOA,
- ttl,
- " ".join((
- "master.lwldns.net.",
- "hostmaster.ipfire.org.",
- serial,
- "3600",
- "600",
- "3600000",
- "%s" % ttl,
- )),
- )
- zone.replace_rdataset(origin, soa)
+ # Write $ORIGIN
+ f.write("$ORIGIN %s\n" % self.list.zone)
+
+ # Set the TTL
+ f.write("$TTL %s\n" % ttl)
+
+ # Write the SOA
+ f.write(" ".join((
+ "@",
+ "IN",
+ "SOA",
+ "master.lwldns.net.",
+ "hostmaster.ipfire.org.",
+ serial,
+ "3600",
+ "600",
+ "3600000",
+ "%s" % ttl,
+ )))
+ f.write("\n")
# XXX Add NS
-
- # Compute the rrset
- rrset = dns.rdataset.from_text(
- dns.rdataclass.IN, self.type, ttl, self.content,
- )
+ f.write("@ IN NS master.lwldns.net.\n")
# Write all domains
for domain in self.list.domains:
- zone.replace_rdataset(
- dns.name.from_text(
- "%s.%s" % (domain, self.list.zone), origin=origin,
- ),
- rrset,
- )
-
- # Add ZONEMD
- self.add_zonemd(zone, ttl)
-
- # Write the zone to file
- zone.to_file(f)
-
- def add_zonemd(self, zone, ttl):
- """
- Adds ZONEMD records to the zone
- """
- # Create a new ZONEMD record
- rrset = dns.rdataset.Rdataset(
- dns.rdataclass.IN, dns.rdatatype.ZONEMD, ttl=ttl,
- )
-
- # Compute the digest for SHA-512 and SHA-384
- algorithms = (
- dns.zone.DigestHashAlgorithm.SHA512,
- dns.zone.DigestHashAlgorithm.SHA384,
- )
-
- # Compute the digests
- for algorithm in algorithms:
- rrset.add(
- zone.compute_digest(algorithm),
- )
-
- # Add the ZONEMD record
- zone.replace_rdataset(zone.origin, rrset)
+ f.write("%s IN %s %s\n" % (domain, self.type, self.content))
class BlocklistExporter(ZoneExporter):
"""
Exports the list as a regular DNSBL zone file
"""
- type = dns.rdatatype.A
+ type = "A"
content = "127.0.0.2"
"""
Exports the list as a RPZ zone file
"""
- type = dns.rdatatype.CNAME
+ type = "CNAME"
content = "."