From 5786bb3e1bed73266a44b41290dcaa5186519713 Mon Sep 17 00:00:00 2001 From: kaiyou Date: Sat, 21 Oct 2017 15:22:40 +0200 Subject: [PATCH] Return the server address dynamically --- admin/mailu/internal/nginx.py | 16 +++++++++++----- admin/mailu/internal/views.py | 1 - 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/admin/mailu/internal/nginx.py b/admin/mailu/internal/nginx.py index 6fcb3b2b..a7a8c5b4 100644 --- a/admin/mailu/internal/nginx.py +++ b/admin/mailu/internal/nginx.py @@ -1,5 +1,7 @@ from mailu import db, models +import socket + SUPPORTED_AUTH_METHODS = ["none", "plain"] @@ -12,6 +14,12 @@ STATUSES = { } +SERVER_MAP = { + "imap": ("imap", 143), + "smtp": ("smtp", 25) +} + + def handle_authentication(headers): """ Handle an HTTP nginx authentication request See: http://nginx.org/en/docs/mail/ngx_mail_auth_http_module.html#protocol @@ -57,8 +65,6 @@ def get_status(protocol, status): def get_server(protocol): - servers = { - "imap": ("172.18.0.12", 143), - "smtp": ("172.18.0.9", 25) - } - return servers[protocol] + hostname, port = SERVER_MAP[protocol] + address = socket.gethostbyname(hostname) + return address, port diff --git a/admin/mailu/internal/views.py b/admin/mailu/internal/views.py index f1dd9d19..04d3268a 100644 --- a/admin/mailu/internal/views.py +++ b/admin/mailu/internal/views.py @@ -11,4 +11,3 @@ def nginx_authentication(): for key, value in headers.items(): response.headers[key] = str(value) return response -