Renaming ipadress - ip_address

Bugfix user table
Result testrun
Updated cn translation
pull/1972/head
Ozzie Isaacs 3 years ago
parent 4e3a5ca33b
commit 144c2b5fc7

@ -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

@ -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)

@ -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

@ -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

@ -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}])
},
});
}

@ -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"

@ -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))

@ -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)

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save