diff --git a/core/admin/mailu/__init__.py b/core/admin/mailu/__init__.py index af45e1fa..fdb000b9 100644 --- a/core/admin/mailu/__init__.py +++ b/core/admin/mailu/__init__.py @@ -45,7 +45,8 @@ default_config = { 'DISABLE_STATISTICS': 'False', 'WELCOME': 'False', 'WELCOME_SUBJECT': 'Dummy welcome topic', - 'WELCOME_BODY': 'Dummy welcome body' + 'WELCOME_BODY': 'Dummy welcome body', + 'WEB_ADMIN': '/admin' } # Load configuration from the environment if available @@ -78,12 +79,12 @@ def get_locale(): # Login configuration login_manager = flask_login.LoginManager() login_manager.init_app(app) -login_manager.login_view = ".login" +login_manager.login_view = "ui.login" @login_manager.unauthorized_handler def handle_needs_login(): return flask.redirect( - flask.url_for('.login', next=flask.request.endpoint) + flask.url_for('ui.login', next=flask.request.endpoint) ) @app.context_processor diff --git a/core/admin/mailu/internal/views.py b/core/admin/mailu/internal/views.py index dc893b66..b308bd31 100644 --- a/core/admin/mailu/internal/views.py +++ b/core/admin/mailu/internal/views.py @@ -2,6 +2,7 @@ from mailu import db, models, app, limiter from mailu.internal import internal, nginx import flask +import flask_login @internal.route("/auth/email") @@ -17,3 +18,13 @@ def nginx_authentication(): for key, value in headers.items(): response.headers[key] = str(value) return response + + +@internal.route("/auth/admin") +def admin_authentication(): + """ Fails if the user is not an authenticated admin. + """ + if (not flask_login.current_user.is_anonymous + and flask_login.current_user.global_admin): + return "" + return flask.abort(403) diff --git a/core/admin/mailu/ui/templates/sidebar.html b/core/admin/mailu/ui/templates/sidebar.html index f9b94016..5f18e408 100644 --- a/core/admin/mailu/ui/templates/sidebar.html +++ b/core/admin/mailu/ui/templates/sidebar.html @@ -36,7 +36,7 @@ {% trans %}Authentication tokens{% endtrans %} - +