Commit 9f1d633a authored by Joshua Tauberer's avatar Joshua Tauberer

re-do the custom DNS get/set routines so it is possible to store more than one...

re-do the custom DNS get/set routines so it is possible to store more than one record for a qname-rtype pair, like multiple TXT records
parent f0118963
...@@ -221,8 +221,8 @@ def dns_update(): ...@@ -221,8 +221,8 @@ def dns_update():
@app.route('/dns/secondary-nameserver') @app.route('/dns/secondary-nameserver')
@authorized_personnel_only @authorized_personnel_only
def dns_get_secondary_nameserver(): def dns_get_secondary_nameserver():
from dns_update import get_custom_dns_config from dns_update import get_custom_dns_config, get_secondary_dns
return json_response({ "hostname": get_custom_dns_config(env).get("_secondary_nameserver") }) return json_response({ "hostname": get_secondary_dns(get_custom_dns_config(env)) })
@app.route('/dns/secondary-nameserver', methods=['POST']) @app.route('/dns/secondary-nameserver', methods=['POST'])
@authorized_personnel_only @authorized_personnel_only
...@@ -236,14 +236,12 @@ def dns_set_secondary_nameserver(): ...@@ -236,14 +236,12 @@ def dns_set_secondary_nameserver():
@app.route('/dns/set') @app.route('/dns/set')
@authorized_personnel_only @authorized_personnel_only
def dns_get_records(): def dns_get_records():
from dns_update import get_custom_dns_config, get_custom_records from dns_update import get_custom_dns_config
additional_records = get_custom_dns_config(env)
records = get_custom_records(None, additional_records, env)
return json_response([{ return json_response([{
"qname": r[0], "qname": r[0],
"rtype": r[1], "rtype": r[1],
"value": r[2], "value": r[2],
} for r in records]) } for r in get_custom_dns_config(env) if r[0] != "_secondary_nameserver"])
@app.route('/dns/set/<qname>', methods=['POST']) @app.route('/dns/set/<qname>', methods=['POST'])
@app.route('/dns/set/<qname>/<rtype>', methods=['POST']) @app.route('/dns/set/<qname>/<rtype>', methods=['POST'])
...@@ -262,8 +260,8 @@ def dns_set_record(qname, rtype="A", value=None): ...@@ -262,8 +260,8 @@ def dns_set_record(qname, rtype="A", value=None):
if value == '' or value == '__delete__': if value == '' or value == '__delete__':
# request deletion # request deletion
value = None value = None
if set_custom_dns_record(qname, rtype, value, env): if set_custom_dns_record(qname, rtype, value, "set", env):
return do_dns_update(env) return do_dns_update(env) or "No Change"
return "OK" return "OK"
except ValueError as e: except ValueError as e:
return (str(e), 400) return (str(e), 400)
......
This diff is collapsed.
...@@ -11,7 +11,7 @@ import sys, os, os.path, re, subprocess, datetime, multiprocessing.pool ...@@ -11,7 +11,7 @@ import sys, os, os.path, re, subprocess, datetime, multiprocessing.pool
import dns.reversename, dns.resolver import dns.reversename, dns.resolver
import dateutil.parser, dateutil.tz import dateutil.parser, dateutil.tz
from dns_update import get_dns_zones, build_tlsa_record, get_custom_dns_config from dns_update import get_dns_zones, build_tlsa_record, get_custom_dns_config, get_secondary_dns
from web_update import get_web_domains, get_domain_ssl_files from web_update import get_web_domains, get_domain_ssl_files
from mailconfig import get_mail_domains, get_mail_aliases from mailconfig import get_mail_domains, get_mail_aliases
...@@ -357,11 +357,11 @@ def check_dns_zone(domain, env, output, dns_zonefiles): ...@@ -357,11 +357,11 @@ def check_dns_zone(domain, env, output, dns_zonefiles):
# the TLD, and so we're not actually checking the TLD. For that we'd need # the TLD, and so we're not actually checking the TLD. For that we'd need
# to do a DNS trace. # to do a DNS trace.
ip = query_dns(domain, "A") ip = query_dns(domain, "A")
custom_dns = get_custom_dns_config(env) secondary_ns = get_secondary_dns(get_custom_dns_config(env)) or "ns2." + env['PRIMARY_HOSTNAME']
existing_ns = query_dns(domain, "NS") existing_ns = query_dns(domain, "NS")
correct_ns = "; ".join(sorted([ correct_ns = "; ".join(sorted([
"ns1." + env['PRIMARY_HOSTNAME'], "ns1." + env['PRIMARY_HOSTNAME'],
custom_dns.get("_secondary_nameserver", "ns2." + env['PRIMARY_HOSTNAME']), secondary_ns,
])) ]))
if existing_ns.lower() == correct_ns.lower(): if existing_ns.lower() == correct_ns.lower():
output.print_ok("Nameservers are set correctly at registrar. [%s]" % correct_ns) output.print_ok("Nameservers are set correctly at registrar. [%s]" % correct_ns)
......
...@@ -230,7 +230,7 @@ function do_set_custom_dns(qname, rtype, value) { ...@@ -230,7 +230,7 @@ function do_set_custom_dns(qname, rtype, value) {
show_current_custom_dns(); show_current_custom_dns();
}, },
function(err) { function(err) {
show_modal_error("Custom DNS", $("<pre/>").text(err)); show_modal_error("Custom DNS (Error)", $("<pre/>").text(err));
}); });
} }
......
...@@ -24,12 +24,9 @@ def get_web_domains(env): ...@@ -24,12 +24,9 @@ def get_web_domains(env):
# ...Unless the domain has an A/AAAA record that maps it to a different # ...Unless the domain has an A/AAAA record that maps it to a different
# IP address than this box. Remove those domains from our list. # IP address than this box. Remove those domains from our list.
dns = get_custom_dns_config(env) dns = get_custom_dns_config(env)
for domain, value in dns.items(): for domain, rtype, value in dns:
if domain not in domains: continue if domain not in domains: continue
if (isinstance(value, str) and (value != "local")) \ if rtype == "CNAME" or (rtype in ("A", "AAAA") and value != "local"):
or (isinstance(value, dict) and ("CNAME" in value)) \
or (isinstance(value, dict) and ("A" in value) and (value["A"] != "local")) \
or (isinstance(value, dict) and ("AAAA" in value) and (value["AAAA"] != "local")):
domains.remove(domain) domains.remove(domain)
# Sort the list. Put PRIMARY_HOSTNAME first so it becomes the # Sort the list. Put PRIMARY_HOSTNAME first so it becomes the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment