From f8dffe5a19cac4fea79bbc55de0a064b296385f6 Mon Sep 17 00:00:00 2001 From: Ionut Filip Date: Fri, 25 Jan 2019 13:28:24 +0200 Subject: [PATCH] Resolve hosts in admin --- core/admin/Dockerfile | 3 ++- core/admin/mailu/configuration.py | 10 ++++++++-- core/admin/mailu/internal/nginx.py | 4 +--- core/nginx/config.py | 8 ++++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/admin/Dockerfile b/core/admin/Dockerfile index 33c0bde7..4f887ff2 100644 --- a/core/admin/Dockerfile +++ b/core/admin/Dockerfile @@ -1,8 +1,9 @@ FROM alpine:3.8 # python3 shared with most images RUN apk add --no-cache \ - python3 py3-pip \ + python3 py3-pip git \ && pip3 install --upgrade pip +RUN pip3 install git+https://github.com/usrpro/MailuStart.git#egg=mailustart # Image specific layers under this line RUN mkdir -p /app WORKDIR /app diff --git a/core/admin/mailu/configuration.py b/core/admin/mailu/configuration.py index a8cd3e25..55093479 100644 --- a/core/admin/mailu/configuration.py +++ b/core/admin/mailu/configuration.py @@ -1,5 +1,5 @@ import os - +from mailustart import resolve DEFAULT_CONFIG = { # Specific to the admin UI @@ -60,7 +60,6 @@ DEFAULT_CONFIG = { 'POD_ADDRESS_RANGE': None } - class ConfigManager(dict): """ Naive configuration manager that uses environment only """ @@ -74,6 +73,12 @@ class ConfigManager(dict): def __init__(self): self.config = dict() + def resolve_host(self): + self.config['HOST_IMAP'] = resolve(self.config['HOST_IMAP']) + self.config['HOST_POP3'] = resolve(self.config['HOST_POP3']) + self.config['HOST_AUTHSMTP'] = resolve(self.config['HOST_AUTHSMTP']) + self.config['HOST_SMTP'] = resolve(self.config['HOST_SMTP']) + def __coerce_value(self, value): if isinstance(value, str) and value.lower() in ('true','yes'): return True @@ -88,6 +93,7 @@ class ConfigManager(dict): key: self.__coerce_value(os.environ.get(key, value)) for key, value in DEFAULT_CONFIG.items() }) + self.resolve_host() # automatically set the sqlalchemy string if self.config['DB_FLAVOR']: diff --git a/core/admin/mailu/internal/nginx.py b/core/admin/mailu/internal/nginx.py index 460719f2..2dac4db1 100644 --- a/core/admin/mailu/internal/nginx.py +++ b/core/admin/mailu/internal/nginx.py @@ -2,7 +2,6 @@ from mailu import models from flask import current_app as app import re -import socket import urllib @@ -89,5 +88,4 @@ def get_server(protocol, authenticated=False): hostname, port = extract_host_port(app.config['HOST_AUTHSMTP'], 10025) else: hostname, port = extract_host_port(app.config['HOST_SMTP'], 25) - address = socket.gethostbyname(hostname) - return address, port + return hostname, port diff --git a/core/nginx/config.py b/core/nginx/config.py index 82b02519..78c76345 100755 --- a/core/nginx/config.py +++ b/core/nginx/config.py @@ -14,10 +14,14 @@ with open("/etc/resolv.conf") as handle: content = handle.read().split() args["RESOLVER"] = content[content.index("nameserver") + 1] -args["HOST_WEBMAIL"] = resolve(args.get("HOST_WEBMAIL", "webmail")) args["HOST_ADMIN"] = resolve(args.get("HOST_ADMIN", "admin")) -args["HOST_WEBDAV"] = resolve(args.get("HOST_WEBDAV", "webdav:5232")) args["HOST_ANTISPAM"] = resolve(args.get("HOST_ANTISPAM", "antispam:11334")) +args["HOST_WEBMAIL"] = args.get("HOST_WEBMAIL", "webmail") +if args["WEBMAIL"] != "none": + args["HOST_WEBMAIL"] = resolve(args.get("HOST_WEBMAIL")) +args["HOST_WEBDAV"] = args.get("HOST_WEBDAV", "webdav:5232") +if args["WEBDAV"] != "none": + args["HOST_WEBDAV"] = resolve(args.get("HOST_WEBDAV")) # TLS configuration cert_name = os.getenv("TLS_CERT_FILENAME", default="cert.pem")