diff --git a/cps/cli.py b/cps/cli.py index 07b719d2..d7dc596b 100644 --- a/cps/cli.py +++ b/cps/cli.py @@ -71,7 +71,7 @@ if args.c: if os.path.isfile(args.c): certfilepath = args.c else: - print("Certfilepath is invalid. Exiting...") + print("Certfile path is invalid. Exiting...") sys.exit(1) if args.c == "": @@ -81,7 +81,7 @@ if args.k: if os.path.isfile(args.k): keyfilepath = args.k else: - print("Keyfilepath is invalid. Exiting...") + print("Keyfile path is invalid. Exiting...") sys.exit(1) if (args.k and not args.c) or (not args.k and args.c): @@ -91,29 +91,29 @@ if (args.k and not args.c) or (not args.k and args.c): if args.k == "": keyfilepath = "" -# handle and check ipadress argument -ipadress = args.i or None -if ipadress: +# handle and check ip address argument +ip_address = args.i or None +if ip_address: try: # try to parse the given ip address with socket if hasattr(socket, 'inet_pton'): - if ':' in ipadress: - socket.inet_pton(socket.AF_INET6, ipadress) + if ':' in ip_address: + socket.inet_pton(socket.AF_INET6, ip_address) else: - socket.inet_pton(socket.AF_INET, ipadress) + socket.inet_pton(socket.AF_INET, ip_address) else: # on windows python < 3.4, inet_pton is not available # inet_atom only handles IPv4 addresses - socket.inet_aton(ipadress) + socket.inet_aton(ip_address) except socket.error as err: - print(ipadress, ':', err) + print(ip_address, ':', err) sys.exit(1) # handle and check user password argument user_credentials = args.s or None if user_credentials and ":" not in user_credentials: - print("No valid username:password format") + print("No valid 'username:password' format") sys.exit(3) -# Handles enableing of filepicker +# Handles enabling of filepicker filepicker = args.f or None diff --git a/cps/config_sql.py b/cps/config_sql.py index f7419ec9..ef90aee4 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -192,7 +192,7 @@ class _ConfigSQL(object): @staticmethod def get_config_ipaddress(): - return cli.ipadress or "" + return cli.ip_address or "" def _has_role(self, role_flag): return constants.has_flag(self.config_default_role, role_flag) diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index 4c262661..13f83bd5 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -257,7 +257,12 @@ def getEbooksFolderId(drive=None): log.error('Error gDrive, root ID not found') gDriveId.path = '/' session.merge(gDriveId) - session.commit() + try: + session.commit() + except OperationalError as ex: + log.error("gdrive.db DB is not Writeable") + log.debug('Database error: %s', ex) + session.rollback() return gDriveId.gdrive_id @@ -272,37 +277,42 @@ def getFile(pathId, fileName, drive): def getFolderId(path, drive): # drive = getDrive(drive) - currentFolderId = getEbooksFolderId(drive) - sqlCheckPath = path if path[-1] == '/' else path + '/' - storedPathName = session.query(GdriveId).filter(GdriveId.path == sqlCheckPath).first() - - if not storedPathName: - dbChange = False - s = path.split('/') - for i, x in enumerate(s): - if len(x) > 0: - currentPath = "/".join(s[:i+1]) - if currentPath[-1] != '/': - currentPath = currentPath + '/' - storedPathName = session.query(GdriveId).filter(GdriveId.path == currentPath).first() - if storedPathName: - currentFolderId = storedPathName.gdrive_id - else: - currentFolder = getFolderInFolder(currentFolderId, x, drive) - if currentFolder: - gDriveId = GdriveId() - gDriveId.gdrive_id = currentFolder['id'] - gDriveId.path = currentPath - session.merge(gDriveId) - dbChange = True - currentFolderId = currentFolder['id'] + try: + currentFolderId = getEbooksFolderId(drive) + sqlCheckPath = path if path[-1] == '/' else path + '/' + storedPathName = session.query(GdriveId).filter(GdriveId.path == sqlCheckPath).first() + + if not storedPathName: + dbChange = False + s = path.split('/') + for i, x in enumerate(s): + if len(x) > 0: + currentPath = "/".join(s[:i+1]) + if currentPath[-1] != '/': + currentPath = currentPath + '/' + storedPathName = session.query(GdriveId).filter(GdriveId.path == currentPath).first() + if storedPathName: + currentFolderId = storedPathName.gdrive_id else: - currentFolderId = None - break - if dbChange: - session.commit() - else: - currentFolderId = storedPathName.gdrive_id + currentFolder = getFolderInFolder(currentFolderId, x, drive) + if currentFolder: + gDriveId = GdriveId() + gDriveId.gdrive_id = currentFolder['id'] + gDriveId.path = currentPath + session.merge(gDriveId) + dbChange = True + currentFolderId = currentFolder['id'] + else: + currentFolderId = None + break + if dbChange: + session.commit() + else: + currentFolderId = storedPathName.gdrive_id + except OperationalError as ex: + log.error("gdrive.db DB is not Writeable") + log.debug('Database error: %s', ex) + session.rollback() return currentFolderId @@ -346,7 +356,7 @@ def moveGdriveFolderRemote(origin_file, target_folder): addParents=gFileTargetDir['id'], removeParents=previous_parents, fields='id, parents').execute() - # if previous_parents has no childs anymore, delete original fileparent + # if previous_parents has no children anymore, delete original fileparent if len(children['items']) == 1: deleteDatabaseEntry(previous_parents) drive.auth.service.files().delete(fileId=previous_parents).execute() @@ -507,9 +517,10 @@ def deleteDatabaseOnChange(): try: session.query(GdriveId).delete() session.commit() - except (OperationalError, InvalidRequestError): + except (OperationalError, InvalidRequestError) as ex: session.rollback() - log.info(u"GDrive DB is not Writeable") + log.debug('Database error: %s', ex) + log.error(u"GDrive DB is not Writeable") def updateGdriveCalibreFromLocal(): @@ -524,13 +535,23 @@ def updateDatabaseOnEdit(ID,newPath): storedPathName = session.query(GdriveId).filter(GdriveId.gdrive_id == ID).first() if storedPathName: storedPathName.path = sqlCheckPath - session.commit() + try: + session.commit() + except OperationalError as ex: + log.error("gdrive.db DB is not Writeable") + log.debug('Database error: %s', ex) + session.rollback() # Deletes the hashes in database of deleted book def deleteDatabaseEntry(ID): session.query(GdriveId).filter(GdriveId.gdrive_id == ID).delete() - session.commit() + try: + session.commit() + except OperationalError as ex: + log.error("gdrive.db DB is not Writeable") + log.debug('Database error: %s', ex) + session.rollback() # Gets cover file from gdrive @@ -547,7 +568,12 @@ def get_cover_via_gdrive(cover_path): permissionAdded = PermissionAdded() permissionAdded.gdrive_id = df['id'] session.add(permissionAdded) - session.commit() + try: + session.commit() + except OperationalError as ex: + log.error("gdrive.db DB is not Writeable") + log.debug('Database error: %s', ex) + session.rollback() return df.metadata.get('webContentLink') else: return None diff --git a/cps/opds.py b/cps/opds.py index 85a978a7..e444302a 100644 --- a/cps/opds.py +++ b/cps/opds.py @@ -546,8 +546,8 @@ def check_auth(username, 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) + ip_Address = request.headers.get('X-Forwarded-For', request.remote_addr) + log.warning('OPDS Login failed for user "%s" IP-address: %s', username.decode('utf-8'), ip_Address) return False diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 2ccee233..117f7c53 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -682,7 +682,7 @@ function move_header_elements() { handleListServerResponse(data); }, error: function (data) { - handleListServerResponse({type:"danger", message:data.responseText}) + handleListServerResponse([{type:"danger", message:data.responseText}]) }, }); } @@ -721,7 +721,7 @@ function move_header_elements() { handleListServerResponse(data); }, error: function (data) { - handleListServerResponse({type:"danger", message:data.responseText}) + handleListServerResponse([{type:"danger", message:data.responseText}]) }, }); } @@ -750,7 +750,7 @@ function checkboxChange(checkbox, userId, field, field_index) { url: window.location.pathname + "/../../ajax/editlistusers/" + field, data: {"pk": userId, "field_index": field_index, "value": checkbox.checked}, error: function(data) { - handleListServerResponse({type:"danger", message:data.responseText}) + handleListServerResponse([{type:"danger", message:data.responseText}]) }, success: handleListServerResponse }); @@ -765,7 +765,7 @@ function selectHeader(element, field) { url: window.location.pathname + "/../../ajax/editlistusers/" + field, data: {"pk": result, "value": element.value}, error: function (data) { - handleListServerResponse({type:"danger", message:data.responseText}) + handleListServerResponse([{type:"danger", message:data.responseText}]) }, success: handleListServerResponse, }); @@ -783,7 +783,7 @@ function checkboxHeader(CheckboxState, field, field_index) { url: window.location.pathname + "/../../ajax/editlistusers/" + field, data: {"pk": result, "field_index": field_index, "value": CheckboxState}, error: function (data) { - handleListServerResponse({type:"danger", message:data.responseText}, true) + handleListServerResponse([{type:"danger", message:data.responseText}]) }, success: function (data) { handleListServerResponse (data, true) @@ -812,7 +812,7 @@ function deleteUser(a,id){ handleListServerResponse(data); }, error: function (data) { - handleListServerResponse({type:"danger", message:data.responseText}) + handleListServerResponse([{type:"danger", message:data.responseText}]) }, }); } diff --git a/cps/translations/zh_Hans_CN/LC_MESSAGES/messages.po b/cps/translations/zh_Hans_CN/LC_MESSAGES/messages.po index e436e774..0279ad2b 100644 --- a/cps/translations/zh_Hans_CN/LC_MESSAGES/messages.po +++ b/cps/translations/zh_Hans_CN/LC_MESSAGES/messages.po @@ -82,7 +82,7 @@ msgstr "显示全部" #: cps/admin.py:353 cps/admin.py:1275 msgid "Guest Name can't be changed" -msgstr "" +msgstr "访客名称无法更改" #: cps/admin.py:362 msgid "Guest can't have this role" @@ -1488,32 +1488,32 @@ msgstr "在书库" #: cps/templates/author.html:26 cps/templates/index.html:68 #: cps/templates/search.html:29 cps/templates/shelf.html:16 msgid "Sort according to book date, newest first" -msgstr "" +msgstr "按图书日期排序,最新优先" #: cps/templates/author.html:27 cps/templates/index.html:69 #: cps/templates/search.html:30 cps/templates/shelf.html:17 msgid "Sort according to book date, oldest first" -msgstr "" +msgstr "按图书日期排序,最旧优先" #: cps/templates/author.html:28 cps/templates/index.html:70 #: cps/templates/search.html:31 cps/templates/shelf.html:18 msgid "Sort title in alphabetical order" -msgstr "" +msgstr "按标题按字母顺序排序" #: cps/templates/author.html:29 cps/templates/index.html:71 #: cps/templates/search.html:32 cps/templates/shelf.html:19 msgid "Sort title in reverse alphabetical order" -msgstr "" +msgstr "按标题逆字母顺序排序" #: cps/templates/author.html:30 cps/templates/index.html:74 #: cps/templates/search.html:35 cps/templates/shelf.html:22 msgid "Sort according to publishing date, newest first" -msgstr "" +msgstr "按出版日期排序,最新优先" #: cps/templates/author.html:31 cps/templates/index.html:75 #: cps/templates/search.html:36 cps/templates/shelf.html:23 msgid "Sort according to publishing date, oldest first" -msgstr "" +msgstr "按出版日期排序,最旧优先" #: cps/templates/author.html:57 cps/templates/author.html:117 #: cps/templates/discover.html:30 cps/templates/index.html:29 @@ -2044,7 +2044,7 @@ msgstr "" #: cps/templates/config_edit.html:344 msgid "Autodetect" -msgstr "" +msgstr "自动检测" #: cps/templates/config_edit.html:345 msgid "Custom Filter" diff --git a/cps/ub.py b/cps/ub.py index a85f7404..d8d65bd0 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -713,9 +713,12 @@ def init_db(app_db_path): create_anonymous_user(session) if cli.user_credentials: - username, password = cli.user_credentials.split(':') + username, password = cli.user_credentials.split(':', 1) user = session.query(User).filter(func.lower(User.name) == username.lower()).first() if user: + if not password: + print("Empty password is not allowed") + sys.exit(4) user.password = generate_password_hash(password) if session_commit() == "": print("Password for user '{}' changed".format(username)) diff --git a/cps/web.py b/cps/web.py index 9b56babf..4203a812 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1487,23 +1487,23 @@ def login(): log.info(error) flash(_(u"Could not login: %(message)s", message=error), category="error") else: - ipAdress = request.headers.get('X-Forwarded-For', request.remote_addr) - log.warning('LDAP Login failed for user "%s" IP-address: %s', form['username'], ipAdress) + ip_Address = request.headers.get('X-Forwarded-For', request.remote_addr) + log.warning('LDAP Login failed for user "%s" IP-address: %s', form['username'], ip_Address) flash(_(u"Wrong Username or Password"), category="error") else: - ipAdress = request.headers.get('X-Forwarded-For', request.remote_addr) + ip_Address = request.headers.get('X-Forwarded-For', request.remote_addr) if 'forgot' in form and form['forgot'] == 'forgot': if user != None and user.name != "Guest": ret, __ = reset_password(user.id) if ret == 1: flash(_(u"New Password was send to your email address"), category="info") - log.info('Password reset for user "%s" IP-address: %s', form['username'], ipAdress) + log.info('Password reset for user "%s" IP-address: %s', form['username'], ip_Address) else: log.error(u"An unknown error occurred. Please try again later") flash(_(u"An unknown error occurred. Please try again later."), category="error") else: flash(_(u"Please enter valid username to reset password"), category="error") - log.warning('Username missing for password reset IP-address: %s', ipAdress) + log.warning('Username missing for password reset IP-address: %s', ip_Address) else: if user and check_password_hash(str(user.password), form['password']) and user.name != "Guest": login_user(user, remember=bool(form.get('remember_me'))) @@ -1512,7 +1512,7 @@ def login(): config.config_is_initial = False return redirect_back(url_for("web.index")) else: - log.warning('Login failed for user "%s" IP-address: %s', form['username'], ipAdress) + log.warning('Login failed for user "%s" IP-address: %s', form['username'], ip_Address) flash(_(u"Wrong Username or Password"), category="error") next_url = request.args.get('next', default=url_for("web.index"), type=str) diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index 0376c51f..5f2e97ad 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
-

Start Time: 2021-04-21 07:09:48

+

Start Time: 2021-04-26 08:28:54

-

Stop Time: 2021-04-21 09:55:49

+

Stop Time: 2021-04-26 11:26:09

-

Duration: 2h 16 min

+

Duration: 2h 24 min

@@ -234,13 +234,13 @@ - + TestCli 8 - 7 + 8 + 0 0 0 - 1 Detail @@ -268,7 +268,7 @@ -
TestCli - test_cli_SSL_files
+
TestCli - test_change_password
PASS @@ -277,7 +277,7 @@ -
TestCli - test_cli_different_folder
+
TestCli - test_cli_SSL_files
PASS @@ -286,35 +286,18 @@ -
TestCli - test_cli_different_settings_database
+
TestCli - test_cli_different_folder
PASS - + -
TestCli - test_cli_gdrive_location
- - -
- SKIP -
- - - +
TestCli - test_cli_different_settings_database
+ PASS @@ -338,6 +321,39 @@ + + TestCliGdrivedb + 2 + 2 + 0 + 0 + 0 + + Detail + + + + + + + +
TestCliGdrivedb - test_cli_gdrive_location
+ + PASS + + + + + + +
TestCliGdrivedb - test_gdrive_db_nonwrite
+ + PASS + + + + + TestCoverEditBooks 1 @@ -346,13 +362,13 @@ 0 0 - Detail + Detail - +
TestCoverEditBooks - test_upload_jpg
@@ -370,13 +386,13 @@ 0 0 - Detail + Detail - +
TestDeleteDatabase - test_delete_books_in_database
@@ -394,13 +410,13 @@ 0 0 - Detail + Detail - +
TestEbookConvertCalibre - test_convert_deactivate
@@ -409,7 +425,7 @@ - +
TestEbookConvertCalibre - test_convert_email
@@ -418,7 +434,7 @@ - +
TestEbookConvertCalibre - test_convert_failed_and_email
@@ -427,7 +443,7 @@ - +
TestEbookConvertCalibre - test_convert_only
@@ -436,7 +452,7 @@ - +
TestEbookConvertCalibre - test_convert_parameter
@@ -445,7 +461,7 @@ - +
TestEbookConvertCalibre - test_convert_wrong_excecutable
@@ -454,7 +470,7 @@ - +
TestEbookConvertCalibre - test_email_failed
@@ -463,7 +479,7 @@ - +
TestEbookConvertCalibre - test_email_only
@@ -472,7 +488,7 @@ - +
TestEbookConvertCalibre - test_kindle_send_not_configured
@@ -481,7 +497,7 @@ - +
TestEbookConvertCalibre - test_ssl_smtp_setup_error
@@ -490,7 +506,7 @@ - +
TestEbookConvertCalibre - test_starttls_smtp_setup_error
@@ -508,13 +524,13 @@ 0 0 - Detail + Detail - +
TestEbookConvertCalibreGDrive - test_convert_email
@@ -523,7 +539,7 @@ - +
TestEbookConvertCalibreGDrive - test_convert_failed_and_email
@@ -532,7 +548,7 @@ - +
TestEbookConvertCalibreGDrive - test_convert_only
@@ -541,7 +557,7 @@ - +
TestEbookConvertCalibreGDrive - test_convert_parameter
@@ -550,7 +566,7 @@ - +
TestEbookConvertCalibreGDrive - test_email_failed
@@ -559,7 +575,7 @@ - +
TestEbookConvertCalibreGDrive - test_email_only
@@ -577,13 +593,13 @@ 0 0 - Detail + Detail - +
TestEbookConvertKepubify - test_convert_deactivate
@@ -592,7 +608,7 @@ - +
TestEbookConvertKepubify - test_convert_only
@@ -601,7 +617,7 @@ - +
TestEbookConvertKepubify - test_convert_wrong_excecutable
@@ -619,13 +635,13 @@ 0 0 - Detail + Detail - +
TestEbookConvertGDriveKepubify - test_convert_deactivate
@@ -634,7 +650,7 @@ - +
TestEbookConvertGDriveKepubify - test_convert_only
@@ -643,7 +659,7 @@ - +
TestEbookConvertGDriveKepubify - test_convert_wrong_excecutable
@@ -661,13 +677,13 @@ 0 1 - Detail + Detail - +
TestEditAdditionalBooks - test_change_upload_formats
@@ -676,7 +692,7 @@ - +
TestEditAdditionalBooks - test_delete_book
@@ -685,7 +701,7 @@ - +
TestEditAdditionalBooks - test_delete_role
@@ -694,7 +710,7 @@ - +
TestEditAdditionalBooks - test_edit_book_identifier
@@ -703,7 +719,7 @@ - +
TestEditAdditionalBooks - test_edit_book_identifier_capital
@@ -712,7 +728,7 @@ - +
TestEditAdditionalBooks - test_edit_book_identifier_standard
@@ -721,7 +737,7 @@ - +
TestEditAdditionalBooks - test_edit_special_book_identifier
@@ -730,7 +746,7 @@ - +
TestEditAdditionalBooks - test_title_sort
@@ -739,7 +755,7 @@ - +
TestEditAdditionalBooks - test_upload_edit_role
@@ -748,7 +764,7 @@ - +
TestEditAdditionalBooks - test_upload_metadata_cbr
@@ -757,7 +773,7 @@ - +
TestEditAdditionalBooks - test_upload_metadata_cbt
@@ -766,19 +782,19 @@ - +
TestEditAdditionalBooks - test_writeonly_calibre_database
- SKIP + SKIP
-