Added support for custom DNS-only zones
- Updated dropdown list for domains, - Added free text input for writing down domain addresses, - Updated backend with support of custom zones Signed-off-by: Bernard `Guyzmo` Pratz <guyzmo+github@m0g.net>
This commit is contained in:
parent
4e2b109a72
commit
5a3af9525a
|
@ -22,7 +22,9 @@ def get_dns_domains(env):
|
||||||
def get_dns_zones(env):
|
def get_dns_zones(env):
|
||||||
# What domains should we create DNS zones for? Never create a zone for
|
# What domains should we create DNS zones for? Never create a zone for
|
||||||
# a domain & a subdomain of that domain.
|
# a domain & a subdomain of that domain.
|
||||||
domains = get_dns_domains(env)
|
domains_mail = get_dns_domains(env)
|
||||||
|
domains_custom = set([n for n, *_ in get_custom_dns_config(env)])
|
||||||
|
domains = domains_mail | domains_custom
|
||||||
|
|
||||||
# Exclude domains that are subdomains of other domains we know. Proceed
|
# Exclude domains that are subdomains of other domains we know. Proceed
|
||||||
# by looking at shorter domains first.
|
# by looking at shorter domains first.
|
||||||
|
@ -727,16 +729,16 @@ def write_custom_dns_config(config, env):
|
||||||
f.write(config_yaml)
|
f.write(config_yaml)
|
||||||
|
|
||||||
def set_custom_dns_record(qname, rtype, value, action, env):
|
def set_custom_dns_record(qname, rtype, value, action, env):
|
||||||
# validate qname
|
# # validate qname
|
||||||
for zone, fn in get_dns_zones(env):
|
# for zone, fn in get_dns_zones(env):
|
||||||
# It must match a zone apex or be a subdomain of a zone
|
# # It must match a zone apex or be a subdomain of a zone
|
||||||
# that we are otherwise hosting.
|
# # that we are otherwise hosting.
|
||||||
if qname == zone or qname.endswith("."+zone):
|
# if qname == zone or qname.endswith("."+zone):
|
||||||
break
|
# break
|
||||||
else:
|
# else:
|
||||||
# No match.
|
# # No match.
|
||||||
if qname != "_secondary_nameserver":
|
# if qname != "_secondary_nameserver":
|
||||||
raise ValueError("%s is not a domain name or a subdomain of a domain name managed by this box." % qname)
|
# raise ValueError("%s is not a domain name or a subdomain of a domain name managed by this box." % qname)
|
||||||
|
|
||||||
# validate rtype
|
# validate rtype
|
||||||
rtype = rtype.upper()
|
rtype = rtype.upper()
|
||||||
|
|
|
@ -23,6 +23,13 @@
|
||||||
<input type="text" class="form-control" id="customdnsQname" placeholder="subdomain">
|
<input type="text" class="form-control" id="customdnsQname" placeholder="subdomain">
|
||||||
</td><td style="padding: 0 1em; font-weight: bold;">.</td><td>
|
</td><td style="padding: 0 1em; font-weight: bold;">.</td><td>
|
||||||
<select id="customdnsZone" class="form-control"> </select>
|
<select id="customdnsZone" class="form-control"> </select>
|
||||||
|
<div class="input-group" id="customdnsZoneFree">
|
||||||
|
<input type="text" class="form-control" placeholder="new-domain.tld" class="hidden">
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<button class="btn btn-default" type="button" onclick="reset_zone_free(); return false;">X</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
</td></tr></table>
|
</td></tr></table>
|
||||||
<div class="text-info" style="margin-top: .5em">Leave the left field blank to set a record on the chosen domain name, or enter a subdomain.</div>
|
<div class="text-info" style="margin-top: .5em">Leave the left field blank to set a record on the chosen domain name, or enter a subdomain.</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -163,19 +170,69 @@ function show_custom_dns() {
|
||||||
$('#secondarydns-clear-instructions').toggle(data.hostnames.length > 0);
|
$('#secondarydns-clear-instructions').toggle(data.hostnames.length > 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#customdnsZone').text('');
|
||||||
|
var dns_list_domains = $('<optgroup/>').attr('label', 'Domains');
|
||||||
|
var dns_list_customs = $('<optgroup/>').attr('label', 'Custom');
|
||||||
|
var dns_list_advanced = $('<optgroup/>').attr('label', 'Advanced');
|
||||||
|
|
||||||
|
$('#customdnsZone').append(dns_list_domains);
|
||||||
|
$('#customdnsZone').append(dns_list_customs);
|
||||||
|
$('#customdnsZone').append(dns_list_advanced);
|
||||||
|
|
||||||
|
dns_list_advanced.append($('<option/>').text("New domain..."));
|
||||||
|
|
||||||
|
// Append all domains offered by mail
|
||||||
api(
|
api(
|
||||||
"/dns/zones",
|
"/dns/zones",
|
||||||
"GET",
|
"GET",
|
||||||
{ },
|
{ },
|
||||||
function(data) {
|
function(zones) {
|
||||||
$('#customdnsZone').text('');
|
for (var i = 0; i < zones.length; i++) {
|
||||||
for (var i = 0; i < data.length; i++) {
|
dns_list_domains.append($('<option/>').text(zones[i]));
|
||||||
$('#customdnsZone').append($('<option/>').text(data[i]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Append all custom domains that are not offering mail
|
||||||
|
api(
|
||||||
|
"/dns/custom",
|
||||||
|
"GET",
|
||||||
|
{ },
|
||||||
|
function(customs) {
|
||||||
|
seen = [];
|
||||||
|
for (var i = 0; i < customs.length; i++) {
|
||||||
|
fqdn = customs[i].qname.replace(/.*\.(?=[^.]*\.[^.]*$)/, "");
|
||||||
|
console.log(fqdn, seen);
|
||||||
|
if ($.inArray(fqdn, seen) == -1) {
|
||||||
|
seen.push(fqdn);
|
||||||
|
dns_list_customs.append($('<option/>').text(fqdn));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$('#customdnsZone')[0].selectedIndex = 0;
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
show_current_custom_dns();
|
show_current_custom_dns();
|
||||||
show_customdns_rtype_hint();
|
show_customdns_rtype_hint();
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
$('#customdnsZone').on('change', function(){
|
||||||
|
var selected = $(this).find("option:selected").val();
|
||||||
|
if (selected === "New domain...") {
|
||||||
|
$('#customdnsZoneFree').removeClass('hidden');
|
||||||
|
$('#customdnsZone').addClass('hidden');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
reset_zone_free();
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset_zone_free() {
|
||||||
|
$('#customdnsZoneFree').addClass('hidden');
|
||||||
|
$('#customdnsZone').removeClass('hidden');
|
||||||
|
$('#customdnsZone')[0].selectedIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_current_custom_dns() {
|
function show_current_custom_dns() {
|
||||||
|
@ -235,6 +292,14 @@ function do_set_custom_dns(qname, rtype, value, method) {
|
||||||
qname = $('#customdnsQname').val() + '.' + $('#customdnsZone').val();
|
qname = $('#customdnsQname').val() + '.' + $('#customdnsZone').val();
|
||||||
else
|
else
|
||||||
qname = $('#customdnsZone').val();
|
qname = $('#customdnsZone').val();
|
||||||
|
|
||||||
|
if ($('#customdnsZone').val() === 'New domain...') {
|
||||||
|
if ($('#customdnsQname').val() != '')
|
||||||
|
qname = $('#customdnsQname').val() + '.' + $('#customdnsZoneFree input').val();
|
||||||
|
else
|
||||||
|
qname = $('#customdnsZoneFree input').val();
|
||||||
|
}
|
||||||
|
|
||||||
rtype = $('#customdnsType').val();
|
rtype = $('#customdnsType').val();
|
||||||
value = $('#customdnsValue').val();
|
value = $('#customdnsValue').val();
|
||||||
method = 'POST';
|
method = 'POST';
|
||||||
|
|
Loading…
Reference in New Issue