From 147947662ca606f26a3ae0a05e61e5e5de4fcf11 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Mon, 17 Jun 2019 23:46:38 +0200 Subject: [PATCH 1/4] Base64 --- cps/admin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cps/admin.py b/cps/admin.py index f6fd838f..0f553035 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -25,6 +25,7 @@ from __future__ import division, print_function, unicode_literals import os import json import time +import base64 from datetime import datetime, timedelta try: from imp import reload From 3d0beba26172489e68c9cdd9a53ca1d3c6000b0e Mon Sep 17 00:00:00 2001 From: Krakinou Date: Mon, 17 Jun 2019 23:47:35 +0200 Subject: [PATCH 2/4] Base64 --- cps/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cps/admin.py b/cps/admin.py index 0f553035..c641f3a0 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -25,7 +25,7 @@ from __future__ import division, print_function, unicode_literals import os import json import time -import base64 +import base64 from datetime import datetime, timedelta try: from imp import reload From e5b9da5201d7ed1e597e2a8884fbd5f59b0ffb4b Mon Sep 17 00:00:00 2001 From: Krakinou Date: Mon, 1 Jul 2019 21:44:58 +0200 Subject: [PATCH 3/4] Error management --- cps/web.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/cps/web.py b/cps/web.py index 3f8964d4..1ae1aa86 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1098,19 +1098,15 @@ def login(): flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname), category="success") return redirect_back(url_for("web.index")) - except ldap.ldap.INVALID_CREDENTIALS as e: - log.error('Login Error: ' + str(e)) - ipAdress = request.headers.get('X-Forwarded-For', request.remote_addr) - log.info('LDAP Login failed for user "%s" IP-adress: %s', form['username'], ipAdress) - flash(_(u"Wrong Username or Password"), category="error") - except ldap.ldap.SERVER_DOWN: - log.info('LDAP Login failed, LDAP Server down') - flash(_(u"Could not login. LDAP server down, please contact your administrator"), category="error") - '''except LDAPException as exception: - app.logger.error('Login Error: ' + str(exception)) - ipAdress = request.headers.get('X-Forwarded-For', request.remote_addr) - app.logger.info('LDAP Login failed for user "' + form['username'] + ', IP-address :' + ipAdress) - flash(_(u"Wrong Username or Password"), category="error")''' + except Exception as exception: + app.logger.info('Login Error: ' + str(exception)) + if str(exception) == 'Invalid credentials': + ipAdress = request.headers.get('X-Forwarded-For', request.remote_addr) + app.logger.info('LDAP Login failed for user "' + form['username'] + ', IP-address :' + ipAdress) + flash(_(u"Wrong Username or Password"), category="error") + if str(exception) == 'Server down': + log.info('LDAP Login failed, LDAP Server down') + flash(_(u"Could not login. LDAP server down, please contact your administrator"), category="error") else: if user and check_password_hash(user.password, form['password']) and user.nickname is not "Guest": login_user(user, remember=True) From 00a29f3d8840e285cc17e6d929d7616715612110 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Mon, 1 Jul 2019 21:45:35 +0200 Subject: [PATCH 4/4] Check for change before encoding --- cps/admin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index c641f3a0..9c08d2d4 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -413,12 +413,13 @@ def configuration_helper(origin): goodreads=goodreads_support, title=_(u"Basic Configuration"), page="config") else: - content.config_use_ldap = 1 + content.config_login_type = 1 content.config_ldap_provider_url = to_save["config_ldap_provider_url"] content.config_ldap_port = to_save["config_ldap_port"] content.config_ldap_schema = to_save["config_ldap_schema"] content.config_ldap_serv_username = to_save["config_ldap_serv_username"] - content.config_ldap_serv_password = base64.b64encode(to_save["config_ldap_serv_password"]) + if content.config_ldap_serv_password != to_save["config_ldap_serv_password"]: + content.config_ldap_serv_password = base64.b64encode(to_save["config_ldap_serv_password"]) content.config_ldap_dn = to_save["config_ldap_dn"] content.config_ldap_user_object = to_save["config_ldap_user_object"] reboot_required = True