From: Michael Tremer Date: Wed, 17 Dec 2025 12:05:33 +0000 (+0000) Subject: export: Write a SOA for all DNS zones X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0f31ebd9a06cbf314e38e41cb5ca3dec34bdc04;p=location%2Flibloc.git export: Write a SOA for all DNS zones Signed-off-by: Michael Tremer --- diff --git a/src/python/location/export.py b/src/python/location/export.py index ce97fdc..5b1845f 100644 --- a/src/python/location/export.py +++ b/src/python/location/export.py @@ -302,11 +302,13 @@ class Exporter(object): class ZoneExporter(object): - def __init__(self, db, format, origin, ttl=None): + def __init__(self, db, format, origin, ttl=None, master=None, zonemaster=None): self.db = db self.format = format self.origin = origin - self.ttl = ttl + self.ttl = ttl or 86400 + self.master = master or "invalid." + self.zonemaster = zonemaster or "zonemaster.invalid." try: self.write = self.formats[format] @@ -329,9 +331,13 @@ class ZoneExporter(object): f.write("Updated At: %s\n" % created_at.isoformat()) f.write(";##############################################################################\n") - f.write("$ORIGIN %s" % self.origin) + f.write("$ORIGIN %s\n" % self.origin) if self.ttl: - f.write("$TTL %s" % self.ttl) + f.write("$TTL %s\n" % self.ttl) + + # Write the SOA + f.write("@ IN SOA %s %s %s 3600 600 3600000 %s\n" % \ + (self.master, self.zonemaster, self.db.created_at, self.ttl)) # Write all records self.write(self, f) diff --git a/src/scripts/location.in b/src/scripts/location.in index 535fe5f..16881bc 100644 --- a/src/scripts/location.in +++ b/src/scripts/location.in @@ -200,6 +200,8 @@ class CLI(object): export_zone.add_argument("--origin", required=True, help=_("The origin of the DNS zone")) export_zone.add_argument("--ttl", help=_("The TTL of the DNS zone")) + export_zone.add_argument("--master", help=_("The zone master")) + export_zone.add_argument("--zonemaster", help=_("The email address of the zone's administrator")) export_zone.set_defaults(func=self.handle_export_zone) args = parser.parse_args() @@ -622,7 +624,13 @@ class CLI(object): """ Exports the database in DNS zone format """ - e = location.export.ZoneExporter(db, format=ns.type, origin=ns.origin, ttl=ns.ttl) + e = location.export.ZoneExporter(db, + format = ns.type, + origin = ns.origin, + ttl = ns.ttl, + master = ns.master, + zonemaster = ns.zonemaster, + ) e.export(ns.output)