1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2025-04-20 02:52:11 +00:00

Move zonefile download to the external dns page, fix filename, response format

This commit is contained in:
Joshua Tauberer 2020-11-15 11:55:41 -05:00
parent db676576ab
commit b4496213b1
4 changed files with 54 additions and 44 deletions

View File

@ -1,3 +1,5 @@
#!/usr/local/lib/mailinabox/env/bin/python3
import os, os.path, re, json, time
import multiprocessing.pool, subprocess
@ -342,7 +344,10 @@ def dns_get_dump():
@authorized_personnel_only
def dns_get_zonefile(zone):
from dns_update import get_dns_zonefile
return json_response(get_dns_zonefile(zone, env))
zonefile = get_dns_zonefile(zone, env)
response = make_response(zonefile, 200)
response.mimetype = "text/plain"
return response
# SSL

View File

@ -569,9 +569,9 @@ def get_dns_zonefile(zone, 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)
raise ValueError("%s is not a domain name that corresponds to a zone." % zone)
nsd_zonefile = "/etc/nsd/zones/" + zone + ".txt"
nsd_zonefile = "/etc/nsd/zones/" + fn
with open(nsd_zonefile, "r") as f:
return f.read()

View File

@ -99,23 +99,6 @@
</div>
</form>
<h3>Download zonefile</h3>
<p>You can download your zonefiles here, for example if you want to host your DNS somewhere else.</p>
<form class="form-horizontal" role="form" onsubmit="do_download_zonefile(); return false;">
<div class="form-group">
<label for="downloadZonefile" class="col-sm-1 control-label">Zone</label>
<div class="col-sm-10">
<select id="downloadZonefile" class="form-control"> </select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-11">
<button type="submit" class="btn btn-primary">Download</button>
</div>
</div>
</form>
<h3>Custom DNS API</h3>
@ -189,12 +172,9 @@ function show_custom_dns() {
"GET",
{ },
function(data) {
var selects = ['#customdnsZone', '#downloadZonefile']
for (var i = 0; i < selects.length; i++) {
$(selects[i]).text('');
for (var j = 0; j < data.length; j++) {
$(selects[i]).append($('<option/>').text(data[j]));
}
$('#customdnsZone').text('');
for (var i = 0; i < data.length; i++) {
$('#customdnsZone').append($('<option/>').text(data[i]));
}
});
@ -294,22 +274,6 @@ function do_set_custom_dns(qname, rtype, value, method) {
});
}
function do_download_zonefile() {
var zone = $('#downloadZonefile').val();
api(
"/dns/zonefile/"+ zone,
"GET",
{},
function(data) {
if (data == "") return; // nothing updated
show_modal_error("Download Zonefile", $("<pre/>").text(data));
},
function(err) {
show_modal_error("Download Zonefile (Error)", $("<pre/>").text(err));
});
}
function show_customdns_rtype_hint() {
$('#customdnsTypeHint').text($("#customdnsType").find('option:selected').attr('data-hint'));
}

View File

@ -42,6 +42,19 @@
You may need to adopt this technique when adding DomainKeys. Use a tool like <code>named-checkzone</code> to validate your zone file.
</p>
<h3>Download zonefile</h3>
<p>You can download your zonefiles here or use the table of records below.</p>
<form class="form-inline" role="form" onsubmit="do_download_zonefile(); return false;">
<div class="form-group">
<div class="form-group">
<label for="downloadZonefile" class="control-label sr-only">Zone</label>
<select id="downloadZonefile" class="form-control" style="width: auto"> </select>
</div>
<button type="submit" class="btn btn-primary">Download</button>
</div>
</form>
<h3>Records</h3>
<table id="external_dns_settings" class="table">
<thead>
@ -57,6 +70,18 @@
<script>
function show_external_dns() {
api(
"/dns/zones",
"GET",
{ },
function(data) {
var zones = $('#downloadZonefile');
zones.text('');
for (var j = 0; j < data.length; j++) {
zones.append($('<option/>').text(data[j]));
}
});
$('#external_dns_settings tbody').html("<tr><td colspan='2' class='text-muted'>Loading...</td></tr>")
api(
"/dns/dump",
@ -84,4 +109,20 @@ function show_external_dns() {
}
})
}
function do_download_zonefile() {
var zone = $('#downloadZonefile').val();
api(
"/dns/zonefile/"+ zone,
"GET",
{},
function(data) {
if (data == "") return; // nothing updated
show_modal_error("Download Zonefile", $("<pre/>").text(data));
},
function(err) {
show_modal_error("Download Zonefile (Error)", $("<pre/>").text(err));
});
}
</script>