Beispiel #1
0
def get_web_domains(env):
	# What domains should we serve websites for?
	domains = set()

	# At the least it's the PRIMARY_HOSTNAME so we can serve webmail
	# as well as Z-Push for Exchange ActiveSync.
	domains.add(env['PRIMARY_HOSTNAME'])

	# Also serve web for all mail domains so that we might at least
	# provide auto-discover of email settings, and also a static website
	# if the user wants to make one. These will require an SSL cert.
	domains |= get_mail_domains(env)

	# ...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.
	dns = get_custom_dns_config(env)
	for domain, rtype, value in dns:
		if domain not in domains: continue
		if rtype == "CNAME" or (rtype in ("A", "AAAA") and value != "local"):
			domains.remove(domain)

	# Sort the list. Put PRIMARY_HOSTNAME first so it becomes the
	# default server (nginx's default_server).
	domains = sort_domains(domains, env)

	return domains
Beispiel #2
0
def get_web_domains(env):
	# What domains should we serve websites for?
	domains = set()

	# At the least it's the PRIMARY_HOSTNAME so we can serve webmail
	# as well as Z-Push for Exchange ActiveSync.
	domains.add(env['PRIMARY_HOSTNAME'])

	# Also serve web for all mail domains so that we might at least
	# provide Webfinger and ActiveSync auto-discover of email settings
	# (though the latter isn't really working). These will require that
	# an SSL cert be installed.
	domains |= get_mail_domains(env)

	# ...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.
	dns = get_custom_dns_config(env)
	for domain, value in dns.items():
		if domain not in domains: continue
		if (isinstance(value, str) and (value != "local")) \
		  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)

	# Sort the list. Put PRIMARY_HOSTNAME first so it becomes the
	# default server (nginx's default_server).
	domains = sort_domains(domains, env)

	return domains
Beispiel #3
0
def get_domains_with_a_records(env):
    domains = set()
    dns = get_custom_dns_config(env)
    for domain, rtype, value in dns:
        if rtype == "CNAME" or (rtype in ("A", "AAAA") and value not in ("local", env['PUBLIC_IP'])):
            domains.add(domain)
    return domains
Beispiel #4
0
def check_dns_zone(domain, env, output, dns_zonefiles):
	# If a DS record is set at the registrar, check DNSSEC first because it will affect the NS query.
	# If it is not set, we suggest it last.
	if query_dns(domain, "DS", nxdomain=None) is not None:
		check_dnssec(domain, env, output, dns_zonefiles)

	# We provide a DNS zone for the domain. It should have NS records set up
	# at the domain name's registrar pointing to this box. The secondary DNS
	# server may be customized. Unfortunately this may not check the domain's
	# whois information -- we may be getting the NS records from us rather than
	# the TLD, and so we're not actually checking the TLD. For that we'd need
	# to do a DNS trace.
	ip = query_dns(domain, "A")
	secondary_ns = get_secondary_dns(get_custom_dns_config(env)) or "ns2." + env['PRIMARY_HOSTNAME']
	existing_ns = query_dns(domain, "NS")
	correct_ns = "; ".join(sorted([
		"ns1." + env['PRIMARY_HOSTNAME'],
		secondary_ns,
		]))
	if existing_ns.lower() == correct_ns.lower():
		output.print_ok("Nameservers are set correctly at registrar. [%s]" % correct_ns)
	elif ip == env['PUBLIC_IP']:
		# The domain resolves correctly, so maybe the user is using External DNS.
		output.print_warning("""The nameservers set on this domain at your domain name registrar should be %s. They are currently %s.
			If you are using External DNS, this may be OK."""
				% (correct_ns, existing_ns) )
	else:
		output.print_error("""The nameservers set on this domain are incorrect. They are currently %s. Use your domain name registrar's
			control panel to set the nameservers to %s."""
				% (existing_ns, correct_ns) )
Beispiel #5
0
def check_dns_zone(domain, env, output, dns_zonefiles):
    # If a DS record is set at the registrar, check DNSSEC first because it will affect the NS query.
    # If it is not set, we suggest it last.
    if query_dns(domain, "DS", nxdomain=None) is not None:
        check_dnssec(domain, env, output, dns_zonefiles)

    # We provide a DNS zone for the domain. It should have NS records set up
    # at the domain name's registrar pointing to this box. The secondary DNS
    # server may be customized.
    # (I'm not sure whether this necessarily tests the TLD's configuration,
    # as it should, or if one successful NS line at the TLD will result in
    # this query being answered by the box, which would mean the test is only
    # half working.)

    custom_dns_records = list(get_custom_dns_config(env))  # generator => list so we can reuse it
    correct_ip = get_custom_dns_record(custom_dns_records, domain, "A") or env['PUBLIC_IP']
    custom_secondary_ns = get_secondary_dns(custom_dns_records, mode="NS")
    secondary_ns = custom_secondary_ns or ["ns2." + env['PRIMARY_HOSTNAME']]

    existing_ns = query_dns(domain, "NS")
    correct_ns = "; ".join(sorted(["ns1." + env['PRIMARY_HOSTNAME']] + secondary_ns))
    ip = query_dns(domain, "A")

    probably_external_dns = False

    if existing_ns.lower() == correct_ns.lower():
        output.print_ok("Nameservers are set correctly at registrar. [%s]" % correct_ns)
    elif ip == correct_ip:
        # The domain resolves correctly, so maybe the user is using External DNS.
        output.print_warning("""The nameservers set on this domain at your domain name registrar should be %s. They are currently %s.
			If you are using External DNS, this may be OK."""
                             % (correct_ns, existing_ns))
        probably_external_dns = True
    else:
        output.print_error("""The nameservers set on this domain are incorrect. They are currently %s. Use your domain name registrar's
			control panel to set the nameservers to %s."""
                           % (existing_ns, correct_ns))

    # Check that each custom secondary nameserver resolves the IP address.

    if custom_secondary_ns and not probably_external_dns:
        for ns in custom_secondary_ns:
            # We must first resolve the nameserver to an IP address so we can query it.
            ns_ip = query_dns(ns, "A")
            if not ns_ip:
                output.print_error("Secondary nameserver %s is not valid (it doesn't resolve to an IP address)." % ns)
                continue

            # Now query it to see what it says about this domain.
            ip = query_dns(domain, "A", at=ns_ip, nxdomain=None)
            if ip == correct_ip:
                output.print_ok("Secondary nameserver %s resolved the domain correctly." % ns)
            elif ip is None:
                output.print_error("Secondary nameserver %s is not configured to resolve this domain." % ns)
            else:
                output.print_error(
                    "Secondary nameserver %s is not configured correctly. (It resolved this domain as %s. It should be %s.)" % (
                    ns, ip, correct_ip))
Beispiel #6
0
def dns_get_records():
	from dns_update import get_custom_dns_config, get_custom_records
	additional_records = get_custom_dns_config(env)
	records = get_custom_records(None, additional_records, env)
	return json_response([{
		"qname": r[0],
		"rtype": r[1],
		"value": r[2],
		} for r in records])
Beispiel #7
0
def dns_get_records(qname=None, rtype=None):
    from dns_update import get_custom_dns_config

    return json_response(
        [
            {"qname": r[0], "rtype": r[1], "value": r[2]}
            for r in get_custom_dns_config(env)
            if r[0] != "_secondary_nameserver" and (not qname or r[0] == qname) and (not rtype or r[1] == rtype)
        ]
    )
Beispiel #8
0
def check_dns_zone(domain, env, dns_zonefiles):
	# If a DS record is set at the registrar, check DNSSEC first because it will affect the NS query.
	# If it is not set, we suggest it last.
	if query_dns(domain, "DS", nxdomain=None) is not None:
		check_dnssec(domain, env, dns_zonefiles)

	# We provide a DNS zone for the domain. It should have NS records set up
	# at the domain name's registrar pointing to this box. The secondary DNS
	# server may be customized. Unfortunately this may not check the domain's
	# whois information -- we may be getting the NS records from us rather than
	# the TLD, and so we're not actually checking the TLD. For that we'd need
	# to do a DNS trace.
	custom_dns = get_custom_dns_config(env)
	existing_ns = query_dns(domain, "NS")
	correct_ns = "; ".join(sorted([
		"ns1." + env['PRIMARY_HOSTNAME'],
		custom_dns.get("_secondary_nameserver", "ns2." + env['PRIMARY_HOSTNAME']),
		]))
	if existing_ns.lower() == correct_ns.lower():
		env['out'].print_ok("Nameservers are set correctly at registrar. [%s]" % correct_ns)
	else:
		env['out'].print_error("""The nameservers set on this domain are incorrect. They are currently %s. Use your domain name registrar's
			control panel to set the nameservers to %s."""
				% (existing_ns, correct_ns) )
Beispiel #9
0
def dns_get_secondary_nameserver():
	from dns_update import get_custom_dns_config, get_secondary_dns
	return json_response({ "hostnames": get_secondary_dns(get_custom_dns_config(env), mode=None) })
Beispiel #10
0
def dns_get_secondary_nameserver():
	from dns_update import get_custom_dns_config
	return json_response({ "hostname": get_custom_dns_config(env).get("_secondary_nameserver") })
Beispiel #11
0
def dns_get_secondary_nameserver():
	from dns_update import get_custom_dns_config, get_secondary_dns
	return json_response({ "hostnames": get_secondary_dns(get_custom_dns_config(env), mode=None) })
Beispiel #12
0
def dns_get_secondary_nameserver():
    from dns_update import get_custom_dns_config
    return json_response(
        {"hostname": get_custom_dns_config(env).get("_secondary_nameserver")})
Beispiel #13
0
def check_dns_zone(domain, env, output, dns_zonefiles):
    # If a DS record is set at the registrar, check DNSSEC first because it will affect the NS query.
    # If it is not set, we suggest it last.
    if query_dns(domain, "DS", nxdomain=None) is not None:
        check_dnssec(domain, env, output, dns_zonefiles)

    # We provide a DNS zone for the domain. It should have NS records set up
    # at the domain name's registrar pointing to this box. The secondary DNS
    # server may be customized.
    # (I'm not sure whether this necessarily tests the TLD's configuration,
    # as it should, or if one successful NS line at the TLD will result in
    # this query being answered by the box, which would mean the test is only
    # half working.)

    custom_dns_records = list(
        get_custom_dns_config(env))  # generator => list so we can reuse it
    correct_ip = get_custom_dns_record(custom_dns_records, domain,
                                       "A") or env['PUBLIC_IP']
    custom_secondary_ns = get_secondary_dns(custom_dns_records, mode="NS")
    secondary_ns = custom_secondary_ns or ["ns2." + env['PRIMARY_HOSTNAME']]

    existing_ns = query_dns(domain, "NS")
    correct_ns = "; ".join(
        sorted(["ns1." + env['PRIMARY_HOSTNAME']] + secondary_ns))
    ip = query_dns(domain, "A")

    probably_external_dns = False

    if existing_ns.lower() == correct_ns.lower():
        output.print_ok("Nameservers are set correctly at registrar. [%s]" %
                        correct_ns)
    elif ip == correct_ip:
        # The domain resolves correctly, so maybe the user is using External DNS.
        output.print_warning(
            """The nameservers set on this domain at your domain name registrar should be %s. They are currently %s.
			If you are using External DNS, this may be OK.""" %
            (correct_ns, existing_ns))
        probably_external_dns = True
    else:
        output.print_error(
            """The nameservers set on this domain are incorrect. They are currently %s. Use your domain name registrar's
			control panel to set the nameservers to %s.""" % (existing_ns, correct_ns))

    # Check that each custom secondary nameserver resolves the IP address.

    if custom_secondary_ns and not probably_external_dns:
        for ns in custom_secondary_ns:
            # We must first resolve the nameserver to an IP address so we can query it.
            ns_ip = query_dns(ns, "A")
            if not ns_ip:
                output.print_error(
                    "Secondary nameserver %s is not valid (it doesn't resolve to an IP address)."
                    % ns)
                continue

            # Now query it to see what it says about this domain.
            ip = query_dns(domain, "A", at=ns_ip, nxdomain=None)
            if ip == correct_ip:
                output.print_ok(
                    "Secondary nameserver %s resolved the domain correctly." %
                    ns)
            elif ip is None:
                output.print_error(
                    "Secondary nameserver %s is not configured to resolve this domain."
                    % ns)
            else:
                output.print_error(
                    "Secondary nameserver %s is not configured correctly. (It resolved this domain as %s. It should be %s.)"
                    % (ns, ip, correct_ip))