From f4cde611481b320a2cda3a7b6fecc9dd2b012998 Mon Sep 17 00:00:00 2001 From: Diman0 Date: Fri, 24 Sep 2021 15:29:28 +0200 Subject: [PATCH] Make header translatable. More finishing touches. --- core/admin/mailu/sso/forms.py | 2 +- core/admin/mailu/sso/templates/login.html | 8 -------- core/admin/mailu/sso/views/base.py | 12 +++++++----- core/nginx/conf/nginx.conf | 19 ++++++++++++------- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/core/admin/mailu/sso/forms.py b/core/admin/mailu/sso/forms.py index 8b5f4cba..d5124804 100644 --- a/core/admin/mailu/sso/forms.py +++ b/core/admin/mailu/sso/forms.py @@ -11,7 +11,7 @@ LOCALPART_REGEX = "^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_` class LoginForm(flask_wtf.FlaskForm): class Meta: csrf = False - target = fields.SelectField( u'Go to' ) + target = fields.SelectField( _('Go to') ) email = fields.StringField(_('E-mail'), [validators.Email()]) pw = fields.PasswordField(_('Password'), [validators.DataRequired()]) submit = fields.SubmitField(_('Sign in')) diff --git a/core/admin/mailu/sso/templates/login.html b/core/admin/mailu/sso/templates/login.html index e1ad6045..c727e01e 100644 --- a/core/admin/mailu/sso/templates/login.html +++ b/core/admin/mailu/sso/templates/login.html @@ -3,11 +3,3 @@ {%- block title %} {% trans %}Sign in{% endtrans %} {%- endblock %} - -{%- block subtitle %} -{%- if endpoint == 'ui.index' %} -{% trans %}to access the configuration page{% endtrans %} -{%- elif endpoint == 'ui.webmail' %} -{% trans %}to access the webmail page{% endtrans %} -{%- endif %} -{%- endblock %} diff --git a/core/admin/mailu/sso/views/base.py b/core/admin/mailu/sso/views/base.py index 9f4c1904..f3d60fd0 100644 --- a/core/admin/mailu/sso/views/base.py +++ b/core/admin/mailu/sso/views/base.py @@ -12,18 +12,18 @@ def login(): endpoint = flask.request.args.get('next', 'ui.index') if str(app.config['WEBMAIL']).upper != 'NONE' and str(app.config['ADMIN']).upper != 'NONE' and endpoint != 'ui.webmail': - form.target.choices = [('Configuration page', 'Configuration page'), ('Webmail', 'Webmail')] + form.target.choices = [('Admin', 'Admin'), ('Webmail', 'Webmail')] elif str(app.config['WEBMAIL']).upper != 'NONE' and str(app.config['ADMIN']).upper != 'NONE' and endpoint == 'ui.webmail': - form.target.choices = [('Webmail', 'Webmail'), ('Configuration page', 'Configuration page')] + form.target.choices = [('Webmail', 'Webmail'), ('Admin', 'Admin')] elif str(app.config['WEBMAIL']).upper != 'NONE' and str(app.config['ADMIN']).upper == 'NONE': form.target.choices = [('Webmail', 'Webmail')] elif str(app.config['WEBMAIL']).upper == 'NONE' and str(app.config['ADMIN']).upper != 'NONE': - form.target.choices = [('Configuration page', 'Configuration page')] + form.target.choices = [('Admin', 'Admin')] if form.validate_on_submit(): - if form.target.data == 'Configuration page': + if str(form.target.data) == 'Admin': endpoint = 'ui.index' - elif form.target.data == 'webmail': + elif str(form.target.data) == 'Webmail': endpoint = 'ui.webmail' user = models.User.login(form.email.data, form.pw.data) @@ -33,5 +33,7 @@ def login(): return flask.redirect(flask.url_for(endpoint)) else: flask.flash('Wrong e-mail or password', 'error') + client_ip = flask.request.headers["X-Real-IP"] if 'X-Real-IP' in flask.request.headers else flask.request.remote_addr + flask.current_app.logger.warn(f'Login failed for {str(form.email.data)} from {client_ip}.') return flask.render_template('login.html', form=form, endpoint=endpoint) \ No newline at end of file diff --git a/core/nginx/conf/nginx.conf b/core/nginx/conf/nginx.conf index 7fa6d788..a5e1a51a 100644 --- a/core/nginx/conf/nginx.conf +++ b/core/nginx/conf/nginx.conf @@ -136,21 +136,26 @@ http { include /etc/nginx/proxy.conf; return 302 {{ WEB_WEBMAIL }}; } + + {% if ADMIN == 'true' %} location ^~ /ui { include /etc/nginx/proxy.conf; rewrite ^/ui/(.*) {{ WEB_ADMIN }}/ui/$1 redirect; - #return 302 {{ WEB_ADMIN }}/ui/; } + {% endif %} + + {% if ADMIN == 'true' or WEBMAIL != 'none' %} location ^~ /sso { include /etc/nginx/proxy.conf; proxy_pass http://$admin; } -# location ^~ /(ui|static) { -# rewrite ^{{ WEB_ADMIN }}/(.*) /$1 break; -# include /etc/nginx/proxy.conf; -# proxy_set_header X-Forwarded-Prefix {{ WEB_ADMIN }}; -# proxy_pass http://$admin; -# } + location ^~ /ui/language { + include /etc/nginx/proxy.conf; + proxy_set_header X-Forwarded-Prefix {{ WEB_ADMIN }}; + proxy_pass http://$admin; + expires $expires; + } + {% endif %} {% if WEB_WEBMAIL != '/' and WEBROOT_REDIRECT != 'none' %} location / {