From b85b86e6de8c6b0d134a24122ae1b1a6f8e1d3a7 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 16 Nov 2020 12:03:41 +0100 Subject: [PATCH] Add download zonefile button to external DNS page (#1853) Co-authored-by: Joshua Tauberer --- api/mailinabox.yml | 27 +++++++++++++++++ management/daemon.py | 8 ++++++ management/dns_update.py | 11 +++++++ management/templates/custom-dns.html | 2 +- management/templates/external-dns.html | 40 ++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 1 deletion(-) diff --git a/api/mailinabox.yml b/api/mailinabox.yml index a9a2c12..6358afb 100644 --- a/api/mailinabox.yml +++ b/api/mailinabox.yml @@ -743,6 +743,31 @@ paths: text/html: schema: type: string + /dns/zonefile/{zone}: + get: + tags: + - DNS + summary: Get DNS zonefile + description: Returns an array of all managed top-level domains. + operationId: getDnsZonefile + x-codeSamples: + - lang: curl + source: | + curl -X GET "https://{host}/admin/dns/zonefile/" \ + -u ":" + responses: + 200: + description: Successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/DNSZonefileResponse' + 403: + description: Forbidden + content: + text/html: + schema: + type: string /dns/update: post: tags: @@ -2050,6 +2075,8 @@ components: items: $ref: '#/components/schemas/Hostname' description: DNS zones response. + DNSZonefileResponse: + type: string DNSSecondaryNameserverResponse: type: object required: diff --git a/management/daemon.py b/management/daemon.py index ffc6d5d..3c19367 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -1,3 +1,5 @@ +#!/usr/local/lib/mailinabox/env/bin/python3 + import os, os.path, re, json, time import multiprocessing.pool, subprocess @@ -338,6 +340,12 @@ def dns_get_dump(): from dns_update import build_recommended_dns return json_response(build_recommended_dns(env)) +@app.route('/dns/zonefile/') +@authorized_personnel_only +def dns_get_zonefile(zone): + from dns_update import get_dns_zonefile + return Response(get_dns_zonefile(zone, env), status=200, mimetype='text/plain') + # SSL @app.route('/ssl/status') diff --git a/management/dns_update.py b/management/dns_update.py index 748f87f..ccca69c 100755 --- a/management/dns_update.py +++ b/management/dns_update.py @@ -564,6 +564,17 @@ $TTL 1800 ; default time to live return True # file is updated +def get_dns_zonefile(zone, env): + for domain, fn in get_dns_zones(env): + if zone == domain: + break + else: + raise ValueError("%s is not a domain name that corresponds to a zone." % zone) + + nsd_zonefile = "/etc/nsd/zones/" + fn + with open(nsd_zonefile, "r") as f: + return f.read() + ######################################################################## def write_nsd_conf(zonefiles, additional_records, env): diff --git a/management/templates/custom-dns.html b/management/templates/custom-dns.html index 6984b08..b1b98b9 100644 --- a/management/templates/custom-dns.html +++ b/management/templates/custom-dns.html @@ -89,7 +89,7 @@

- Multiple secondary servers can be separated with commas or spaces (i.e., ns2.hostingcompany.com ns3.hostingcompany.com). + Multiple secondary servers can be separated with commas or spaces (i.e., ns2.hostingcompany.com ns3.hostingcompany.com). To enable zone transfers to additional servers without listing them as secondary nameservers, add an IP address or subnet using xfr:10.20.30.40 or xfr:10.0.0.0/8.

+

Download zonefile

+

You can download your zonefiles here or use the table of records below.

+
+
+
+ + +
+ +
+
+ +

Records

@@ -57,6 +70,18 @@