1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2025-06-09 19:10:54 +00:00

added normalize_ip

This commit is contained in:
Jonathan Chun 2016-12-31 23:12:50 -05:00
parent 5b718bac9d
commit e97d753e5a
2 changed files with 10 additions and 6 deletions

View File

@ -6,7 +6,6 @@ import os, os.path, re, shutil
from utils import shell, safe_domain_name, sort_domains
import idna
import ipaddress
# SELECTING SSL CERTIFICATES FOR USE IN WEB
@ -250,11 +249,10 @@ def get_certificates_to_provision(env, show_extended_problems=True, force_domain
s = r.to_text()
if isinstance(s, bytes):
s = s.decode('utf-8')
s = str(ipaddress.ip_address(s))
return s
# END HOTFIX
if len(response) != 1 or rdata__str__(response[0]) != value:
if len(response) != 1 or normalize_ip(rdata__str__(response[0])) != normalize_ip(value):
problems[domain] = "Domain control validation cannot be performed for this domain because DNS points the domain to another machine (%s %s)." % (rtype, ", ".join(rdata__str__(r) for r in response))
return False
@ -804,6 +802,10 @@ def get_certificate_domains(cert):
return names, cn
def normalize_ip(ip):
import ipaddress
return str(ipaddress.ip_address(ip))
if __name__ == "__main__":
# Provision certificates.
provision_certificates_cmdline()

View File

@ -10,7 +10,6 @@ import dns.reversename, dns.resolver
import dateutil.parser, dateutil.tz
import idna
import psutil
import ipaddress
from dns_update import get_dns_zones, build_tlsa_record, get_custom_dns_config, get_secondary_dns, get_custom_dns_records
from web_update import get_web_domains, get_domains_with_a_records
@ -394,7 +393,7 @@ def check_primary_hostname_dns(domain, env, output, dns_domains, dns_zonefiles):
# Check that PRIMARY_HOSTNAME resolves to PUBLIC_IP[V6] in public DNS.
ipv6 = query_dns(domain, "AAAA") if env.get("PUBLIC_IPV6") else None
if ip == env['PUBLIC_IP'] and ipv6 in (None, env['PUBLIC_IPV6']):
if ip == env['PUBLIC_IP'] and normalize_ip(ipv6) in (None, normalize_ip(env['PUBLIC_IPV6'])):
output.print_ok("Domain resolves to box's IP address. [%s%s]" % (env['PRIMARY_HOSTNAME'], my_ips))
else:
output.print_error("""This domain must resolve to your box's IP address (%s) in public DNS but it currently resolves
@ -704,7 +703,6 @@ def query_dns(qname, rtype, nxdomain='[Not Set]', at=None):
s = r.to_text()
if isinstance(s, bytes):
s = s.decode('utf-8')
s = str(ipaddress.ip_address(s))
response_new.append(s)
response = response_new
@ -886,6 +884,10 @@ def run_and_output_changes(env, pool):
with open(cache_fn, "w") as f:
json.dump(cur.buf, f, indent=True)
def normalize_ip(ip):
import ipaddress
return str(ipaddress.ip_address(ip))
class FileOutput:
def __init__(self, buf, width):
self.buf = buf