From db676576ab04dd2f5ce400f94baa7cf76207dc16 Mon Sep 17 00:00:00 2001 From: Victor Lap Date: Sat, 31 Oct 2020 17:33:33 +0100 Subject: [PATCH] Add download zonefile --- api/mailinabox.yml | 27 ++++++++++++++++ management/daemon.py | 6 ++++ management/dns_update.py | 11 +++++++ management/templates/custom-dns.html | 48 ++++++++++++++++++++++++---- 4 files changed, 86 insertions(+), 6 deletions(-) diff --git a/api/mailinabox.yml b/api/mailinabox.yml index a9a2c124..6358afb4 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 ffc6d5d5..ceabd3a9 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -338,6 +338,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 json_response(get_dns_zonefile(zone, env)) + # SSL @app.route('/ssl/status') diff --git a/management/dns_update.py b/management/dns_update.py index 748f87f1..01d81121 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 or a subdomain of a domain name managed by this box." % zone) + + nsd_zonefile = "/etc/nsd/zones/" + zone + ".txt" + 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 6984b081..224fa3d3 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, for example if you want to host your DNS somewhere else.

+ +
+
+ +
+ +
+
+
+
+ +
+
+

Custom DNS API

@@ -172,10 +189,13 @@ function show_custom_dns() { "GET", { }, function(data) { - $('#customdnsZone').text(''); - for (var i = 0; i < data.length; i++) { - $('#customdnsZone').append($('