|
@@ -19,29 +19,25 @@ do not record this information in the registry. For the last field, we use
|
|
|
|
|
|
import sys
|
|
|
import time
|
|
|
+import argparse
|
|
|
|
|
|
from registry import AutNum
|
|
|
|
|
|
-REGISTRYPATH = "/home/zorun/net.dn42.registry"
|
|
|
-OUT = "/home/zorun/tmp/asn.dn42.zone"
|
|
|
-
|
|
|
-ORIGIN = "asn.dn42."
|
|
|
-TTL = "1h"
|
|
|
-NS = ["tuxmachine.polynome.dn42.", "ns1.allowed.dn42.", "ns1.pyropeter.dn42.", "beta.synhacx.dn42."]
|
|
|
-
|
|
|
-def gen_zone(registrypath, out):
|
|
|
+def gen_zone(args):
|
|
|
+ out = args.output
|
|
|
|
|
|
- out.write("$ORIGIN {}\n".format(ORIGIN))
|
|
|
- out.write("$TTL {}\n".format(TTL))
|
|
|
+ out.write("$ORIGIN {}\n".format(args.zone))
|
|
|
+ out.write("$TTL {}\n".format(args.ttl))
|
|
|
serial = int(time.time())
|
|
|
- out.write("@ IN SOA tuxmachine.polynome.dn42. dn42.polyno.me. ({} 1d 1h 1w 5m)\n".format(serial))
|
|
|
-
|
|
|
+ out.write("@ IN SOA {0.ns[0]} {0.rname} "
|
|
|
+ "({1} {0.refresh} {0.retry} {0.expire} {0.negative})\n".format(args,
|
|
|
+ serial))
|
|
|
|
|
|
- for ns in NS:
|
|
|
+ for ns in args.ns:
|
|
|
out.write("@ NS {}\n".format(ns))
|
|
|
|
|
|
|
|
|
- autnum = AutNum(registrypath)
|
|
|
+ autnum = AutNum(args.registry)
|
|
|
for (asn, data) in autnum.data.items():
|
|
|
comment = ""
|
|
|
if "as-name" in data:
|
|
@@ -51,6 +47,42 @@ def gen_zone(registrypath, out):
|
|
|
comment.replace('"', '')
|
|
|
out.write('{} TXT "{} | DN42 | dn42 | | {}"\n'.format(asn, asn[2:], comment))
|
|
|
|
|
|
+def cleanup(args):
|
|
|
+ def final_dot(s):
|
|
|
+ if not s.endswith('.'):
|
|
|
+ return s + "."
|
|
|
+ else:
|
|
|
+ return s
|
|
|
+ args.zone = final_dot(args.zone)
|
|
|
+ args.rname.replace("@", ".")
|
|
|
+ args.rname = final_dot(args.rname)
|
|
|
+ for (i, ns) in enumerate(args.ns):
|
|
|
+ args.ns[i] = final_dot(ns)
|
|
|
+
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
- with open(OUT, "w") as f:
|
|
|
- gen_zone(REGISTRYPATH, f)
|
|
|
+ parser = argparse.ArgumentParser(description=__doc__)
|
|
|
+ parser.add_argument("-n", "--ns", action="append", required=True,
|
|
|
+ help="name server, can be passed multiple times (the first one will be listed as master in the SOA)")
|
|
|
+ parser.add_argument("-r", "--rname", required=True,
|
|
|
+ help="contact email of the administrator of the zone")
|
|
|
+ parser.add_argument("-o", "--output", default=sys.stdout, type=argparse.FileType('w'),
|
|
|
+ help="output file (default: stdout)")
|
|
|
+ parser.add_argument("registry", help="path to the monotone registry")
|
|
|
+ opt = parser.add_argument_group("Zone options")
|
|
|
+ opt.add_argument("-z", "--zone", default="asn.dn42.",
|
|
|
+ help="zone to generate data for (default: %(default)s)")
|
|
|
+ opt.add_argument("-t", "--ttl", default="1h",
|
|
|
+ help="TTL for all records (default: %(default)s)")
|
|
|
+ opt.add_argument("--refresh", default="1d",
|
|
|
+ help="refresh timer for slaves (default: %(default)s)")
|
|
|
+ opt.add_argument("--retry", default="1h",
|
|
|
+ help="retry timer for slaves (default: %(default)s)")
|
|
|
+ opt.add_argument("--expire", default="4w",
|
|
|
+ help="expire time for slaves (default: %(default)s)")
|
|
|
+ opt.add_argument("--negative", default="5m",
|
|
|
+ help="negative TTL (default: %(default)s)")
|
|
|
+ args = parser.parse_args()
|
|
|
+
|
|
|
+ cleanup(args)
|
|
|
+ gen_zone(args)
|