diff --git a/management/dns_update.py b/management/dns_update.py
index c978a834..ac4a3f7d 100755
--- a/management/dns_update.py
+++ b/management/dns_update.py
@@ -22,7 +22,9 @@ def get_dns_domains(env):
def get_dns_zones(env):
# What domains should we create DNS zones for? Never create a zone for
# 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
# by looking at shorter domains first.
@@ -727,16 +729,16 @@ def write_custom_dns_config(config, env):
f.write(config_yaml)
def set_custom_dns_record(qname, rtype, value, action, env):
- # validate qname
- for zone, fn in get_dns_zones(env):
- # It must match a zone apex or be a subdomain of a zone
- # that we are otherwise hosting.
- if qname == zone or qname.endswith("."+zone):
- break
- else:
- # No match.
- if qname != "_secondary_nameserver":
- raise ValueError("%s is not a domain name or a subdomain of a domain name managed by this box." % qname)
+ # # validate qname
+ # for zone, fn in get_dns_zones(env):
+ # # It must match a zone apex or be a subdomain of a zone
+ # # that we are otherwise hosting.
+ # if qname == zone or qname.endswith("."+zone):
+ # break
+ # else:
+ # # No match.
+ # if qname != "_secondary_nameserver":
+ # raise ValueError("%s is not a domain name or a subdomain of a domain name managed by this box." % qname)
# validate rtype
rtype = rtype.upper()
diff --git a/management/templates/custom-dns.html b/management/templates/custom-dns.html
index f1244810..30ad5af9 100644
--- a/management/templates/custom-dns.html
+++ b/management/templates/custom-dns.html
@@ -23,6 +23,13 @@
.
+
+
+
+
+
+
+
Leave the left field blank to set a record on the chosen domain name, or enter a subdomain.
@@ -163,19 +170,69 @@ function show_custom_dns() {
$('#secondarydns-clear-instructions').toggle(data.hostnames.length > 0);
});
+ $('#customdnsZone').text('');
+ var dns_list_domains = $('').attr('label', 'Domains');
+ var dns_list_customs = $('').attr('label', 'Custom');
+ var dns_list_advanced = $('').attr('label', 'Advanced');
+
+ $('#customdnsZone').append(dns_list_domains);
+ $('#customdnsZone').append(dns_list_customs);
+ $('#customdnsZone').append(dns_list_advanced);
+
+ dns_list_advanced.append($('').text("New domain..."));
+
+ // Append all domains offered by mail
api(
"/dns/zones",
"GET",
{ },
- function(data) {
- $('#customdnsZone').text('');
- for (var i = 0; i < data.length; i++) {
- $('#customdnsZone').append($('').text(data[i]));
+ function(zones) {
+ for (var i = 0; i < zones.length; i++) {
+ dns_list_domains.append($('').text(zones[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($('').text(fqdn));
+ }
+ }
+ $('#customdnsZone')[0].selectedIndex = 0;
+ });
+
});
show_current_custom_dns();
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() {
@@ -235,6 +292,14 @@ function do_set_custom_dns(qname, rtype, value, method) {
qname = $('#customdnsQname').val() + '.' + $('#customdnsZone').val();
else
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();
value = $('#customdnsValue').val();
method = 'POST';