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 os, os.path, re, json, time
import multiprocessing.pool, subprocess import multiprocessing.pool, subprocess
@ -342,7 +344,10 @@ def dns_get_dump():
@authorized_personnel_only @authorized_personnel_only
def dns_get_zonefile(zone): def dns_get_zonefile(zone):
from dns_update import get_dns_zonefile 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 # SSL

View File

@ -569,9 +569,9 @@ def get_dns_zonefile(zone, env):
if zone == domain: if zone == domain:
break break
else: 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: with open(nsd_zonefile, "r") as f:
return f.read() return f.read()

View File

@ -99,23 +99,6 @@
</div> </div>
</form> </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> <h3>Custom DNS API</h3>
@ -189,13 +172,10 @@ function show_custom_dns() {
"GET", "GET",
{ }, { },
function(data) { function(data) {
var selects = ['#customdnsZone', '#downloadZonefile'] $('#customdnsZone').text('');
for (var i = 0; i < selects.length; i++) { for (var i = 0; i < data.length; i++) {
$(selects[i]).text(''); $('#customdnsZone').append($('<option/>').text(data[i]));
for (var j = 0; j < data.length; j++) { }
$(selects[i]).append($('<option/>').text(data[j]));
}
}
}); });
show_current_custom_dns(); show_current_custom_dns();
@ -212,7 +192,7 @@ function show_current_custom_dns() {
$('#custom-dns-current').fadeIn(); $('#custom-dns-current').fadeIn();
else else
$('#custom-dns-current').fadeOut(); $('#custom-dns-current').fadeOut();
var reverse_fqdn = function(el) { var reverse_fqdn = function(el) {
el.qname = el.qname.split('.').reverse().join('.'); el.qname = el.qname.split('.').reverse().join('.');
return el; return el;
@ -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() { function show_customdns_rtype_hint() {
$('#customdnsTypeHint').text($("#customdnsType").find('option:selected').attr('data-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. You may need to adopt this technique when adding DomainKeys. Use a tool like <code>named-checkzone</code> to validate your zone file.
</p> </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"> <table id="external_dns_settings" class="table">
<thead> <thead>
@ -57,6 +70,18 @@
<script> <script>
function show_external_dns() { 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>") $('#external_dns_settings tbody').html("<tr><td colspan='2' class='text-muted'>Loading...</td></tr>")
api( api(
"/dns/dump", "/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> </script>