From 184c9bc56682ccde1cf3bc28f7810acc10f23bdc Mon Sep 17 00:00:00 2001 From: Florent Daigniere Date: Tue, 15 Mar 2022 10:26:29 +0100 Subject: [PATCH] Add json redirect --- core/admin/mailu/internal/views/autoconfig.py | 10 ++++++++++ core/nginx/conf/nginx.conf | 5 +++++ docs/reverse.rst | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/admin/mailu/internal/views/autoconfig.py b/core/admin/mailu/internal/views/autoconfig.py index a9a1925a..a4816f22 100644 --- a/core/admin/mailu/internal/views/autoconfig.py +++ b/core/admin/mailu/internal/views/autoconfig.py @@ -40,6 +40,16 @@ def autoconfig_mozilla(): \r\n''' return flask.Response(xml, mimetype='text/xml', status=200) +@internal.route("/autoconfig/microsoft.json") +def autoconfig_microsoft_json(): + proto = flask.request.args.get('Protocol', 'Autodiscoverv1') + if proto == 'Autodiscoverv1': + hostname = app.config['HOSTNAME'] + json = f'{"Protocol":"Autodiscoverv1","Url":"https://{hostname}/autodiscover/autodiscover.xml"}' + return flask.Response(json, mimetype='application/json', status=200) + else + return flask.abort(404) + @internal.route("/autoconfig/microsoft", methods=['GET', 'POST']) def autoconfig_microsoft(): # https://docs.microsoft.com/en-us/previous-versions/office/office-2010/cc511507(v=office.14)?redirectedfrom=MSDN#Anchor_3 diff --git a/core/nginx/conf/nginx.conf b/core/nginx/conf/nginx.conf index 3e0ae94c..66b1a673 100644 --- a/core/nginx/conf/nginx.conf +++ b/core/nginx/conf/nginx.conf @@ -127,6 +127,11 @@ http { proxy_pass http://$admin; } # microsoft autoconfiguration + location ~* ^/Autodiscover/Autodiscover.json { + rewrite ^ /internal/autoconfig/microsoft.json break; + include /etc/nginx/proxy.conf; + proxy_pass http://$admin; + } location ~* ^/Autodiscover/Autodiscover.xml { rewrite ^ /internal/autoconfig/microsoft break; include /etc/nginx/proxy.conf; diff --git a/docs/reverse.rst b/docs/reverse.rst index 80ca1829..f9b73e8f 100644 --- a/docs/reverse.rst +++ b/docs/reverse.rst @@ -66,7 +66,7 @@ Because the admin interface is served as ``/admin``, the Webmail as ``/webmail`` server { # [...] here goes your standard configuration - location ~* ^/(admin|sso|static|webdav|webmail|(apple\.)?mobileconfig|(\.well\-known/autoconfig/)?mail/|Autodiscover/Autodiscover.xml) { + location ~* ^/(admin|sso|static|webdav|webmail|(apple\.)?mobileconfig|(\.well\-known/autoconfig/)?mail/|Autodiscover/Autodiscover) { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr proxy_pass https://localhost:8443;