From 34a474101fa2b3dd97046f5febc84cb10ac9c27b Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Thu, 28 Jan 2021 20:05:58 +0100 Subject: [PATCH] Fix #1838 (Log message on failed OPDS login) --- cps/helper.py | 3 ++- cps/opds.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cps/helper.py b/cps/helper.py index 50e24636..77d292eb 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -32,7 +32,7 @@ from tempfile import gettempdir import requests from babel.dates import format_datetime from babel.units import format_unit -from flask import send_from_directory, make_response, redirect, abort, url_for +from flask import send_from_directory, make_response, redirect, abort, url_for, request from flask_babel import gettext as _ from flask_login import current_user from sqlalchemy.sql.expression import true, false, and_, text @@ -68,6 +68,7 @@ try: except (ImportError, RuntimeError) as e: log.debug('Cannot import Image, generating covers from non jpg files will not work: %s', e) use_IM = False + MissingDelegateError = BaseException # Convert existing book entry to new format diff --git a/cps/opds.py b/cps/opds.py index 1ae7010c..c66ee836 100644 --- a/cps/opds.py +++ b/cps/opds.py @@ -430,7 +430,12 @@ def check_auth(username, password): username = username.encode('utf-8') user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == username.decode('utf-8').lower()).first() - return bool(user and check_password_hash(str(user.password), password)) + if bool(user and check_password_hash(str(user.password), password)): + return True + else: + ipAdress = request.headers.get('X-Forwarded-For', request.remote_addr) + log.warning('OPDS Login failed for user "%s" IP-address: %s', username.decode('utf-8'), ipAdress) + return False def authenticate():