From 6d6b403032a8768c63b4105e592116244b614954 Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Tue, 5 Dec 2023 23:02:49 +0100 Subject: add reverse proxy support use correct version attribute removed some non-localized urls allow loading custom config file --- src/jwebmail/__init__.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/jwebmail/__init__.py') diff --git a/src/jwebmail/__init__.py b/src/jwebmail/__init__.py index 405f35e..26d6ffc 100644 --- a/src/jwebmail/__init__.py +++ b/src/jwebmail/__init__.py @@ -3,6 +3,7 @@ import pwd import sys from os import environ +from werkzeug.middleware.proxy_fix import ProxyFix from flask import Flask, g from flask_babel import Babel, get_locale from flask_login import LoginManager, login_required @@ -54,7 +55,15 @@ def create_app(): app = Flask(__name__) app.jinja_options = dict(undefined=ChainableUndefined) - app.config.from_file("../../jwebmail.toml", load=toml_load, text=False) + if app.config["DEBUG"]: + app.config.from_file("../../jwebmail.toml", load=toml_load, text=False) + else: + print(environ["JWEBMAIL_CONFIG"]) + app.config.from_file(environ["JWEBMAIL_CONFIG"], load=toml_load, text=False) + + if app.config["JWEBMAIL"]["PROXY"]: + app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1) + validate_config(app) DEFAULT_LANGUAGE = app.config["JWEBMAIL"]["DEFAULT_LANGUAGE"] @@ -73,7 +82,7 @@ def create_app(): @app.context_processor def inject_version(): - return {"version": "4.0", "get_locale": get_locale, "format_mail": format_mail} + return {"version": __version__, "get_locale": get_locale, "format_mail": format_mail} @app.url_defaults def add_language_code(endpoint, values): @@ -98,18 +107,13 @@ def route(app): app.add_url_rule("/about", view_func=about) app.add_url_rule("//about", view_func=about) - app.add_url_rule("/logout", view_func=logout) app.add_url_rule("//logout", view_func=logout) dh = login_required(displayheaders) - app.add_url_rule("/home/", view_func=dh) - app.add_url_rule("/home/", view_func=dh) app.add_url_rule("//home/", view_func=dh) app.add_url_rule("//home/", view_func=dh) lr_readmail = login_required(readmail) - app.add_url_rule("/read/", endpoint="read", view_func=lr_readmail) - app.add_url_rule("/read//", endpoint="read", view_func=lr_readmail) app.add_url_rule( "//read/", endpoint="read", view_func=lr_readmail ) @@ -122,7 +126,6 @@ def route(app): app.add_url_rule("/raw//", endpoint="raw", view_func=lr_rawmail) lr_writemail = login_required(writemail) - app.add_url_rule("/write", endpoint="write", view_func=lr_writemail) app.add_url_rule("//write", endpoint="write", view_func=lr_writemail) app.add_url_rule( "/write", endpoint="send", view_func=login_required(sendmail), methods=["POST"] -- cgit v1.2.3