|
|
@ -23,13 +23,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import division, print_function, unicode_literals
|
|
|
|
from __future__ import division, print_function, unicode_literals
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
|
|
|
|
import base64
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
try:
|
|
|
|
# try:
|
|
|
|
from imp import reload
|
|
|
|
# from imp import reload
|
|
|
|
except ImportError:
|
|
|
|
# except ImportError:
|
|
|
|
pass
|
|
|
|
# pass
|
|
|
|
|
|
|
|
|
|
|
|
from babel import Locale as LC
|
|
|
|
from babel import Locale as LC
|
|
|
|
from babel.dates import format_datetime
|
|
|
|
from babel.dates import format_datetime
|
|
|
@ -38,23 +39,19 @@ from flask_login import login_required, current_user, logout_user
|
|
|
|
from flask_babel import gettext as _
|
|
|
|
from flask_babel import gettext as _
|
|
|
|
from sqlalchemy import and_
|
|
|
|
from sqlalchemy import and_
|
|
|
|
from sqlalchemy.exc import IntegrityError
|
|
|
|
from sqlalchemy.exc import IntegrityError
|
|
|
|
|
|
|
|
from sqlalchemy.sql.expression import func
|
|
|
|
from werkzeug.security import generate_password_hash
|
|
|
|
from werkzeug.security import generate_password_hash
|
|
|
|
|
|
|
|
|
|
|
|
from . import constants, logger, ldap1
|
|
|
|
from . import constants, logger, helper, services
|
|
|
|
from . import db, ub, web_server, get_locale, config, updater_thread, babel, gdriveutils
|
|
|
|
from . import db, ub, web_server, get_locale, config, updater_thread, babel, gdriveutils
|
|
|
|
from .helper import speaking_language, check_valid_domain, check_unrar, send_test_mail, generate_random_password, \
|
|
|
|
from .helper import speaking_language, check_valid_domain, send_test_mail, generate_random_password, send_registration_mail
|
|
|
|
send_registration_mail
|
|
|
|
from .gdriveutils import is_gdrive_ready, gdrive_support
|
|
|
|
from .gdriveutils import is_gdrive_ready, gdrive_support, downloadFile, deleteDatabaseOnChange, listRootFolders
|
|
|
|
from .web import admin_required, render_title_template, before_request, unconfigured, login_required_if_no_ano
|
|
|
|
from .web import admin_required, render_title_template, before_request, unconfigured, login_required_if_no_ano
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
feature_support = dict()
|
|
|
|
feature_support = {
|
|
|
|
feature_support['ldap'] = ldap1.ldap_supported()
|
|
|
|
'ldap': bool(services.ldap),
|
|
|
|
|
|
|
|
'goodreads': bool(services.goodreads)
|
|
|
|
try:
|
|
|
|
}
|
|
|
|
from goodreads.client import GoodreadsClient
|
|
|
|
|
|
|
|
feature_support['goodreads'] = True
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
feature_support['goodreads'] = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# try:
|
|
|
|
# try:
|
|
|
|
# import rarfile
|
|
|
|
# import rarfile
|
|
|
@ -63,7 +60,7 @@ except ImportError:
|
|
|
|
# feature_support['rar'] = False
|
|
|
|
# feature_support['rar'] = False
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from oauth_bb import oauth_check
|
|
|
|
from .oauth_bb import oauth_check
|
|
|
|
feature_support['oauth'] = True
|
|
|
|
feature_support['oauth'] = True
|
|
|
|
except ImportError:
|
|
|
|
except ImportError:
|
|
|
|
feature_support['oauth'] = False
|
|
|
|
feature_support['oauth'] = False
|
|
|
@ -86,12 +83,10 @@ def admin_forbidden():
|
|
|
|
@admin_required
|
|
|
|
@admin_required
|
|
|
|
def shutdown():
|
|
|
|
def shutdown():
|
|
|
|
task = int(request.args.get("parameter").strip())
|
|
|
|
task = int(request.args.get("parameter").strip())
|
|
|
|
if task == 1 or task == 0: # valid commandos received
|
|
|
|
if task in (0, 1): # valid commandos received
|
|
|
|
# close all database connections
|
|
|
|
# close all database connections
|
|
|
|
db.session.close()
|
|
|
|
db.dispose()
|
|
|
|
db.engine.dispose()
|
|
|
|
ub.dispose()
|
|
|
|
ub.session.close()
|
|
|
|
|
|
|
|
ub.engine.dispose()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showtext = {}
|
|
|
|
showtext = {}
|
|
|
|
if task == 0:
|
|
|
|
if task == 0:
|
|
|
@ -101,13 +96,13 @@ def shutdown():
|
|
|
|
# stop gevent/tornado server
|
|
|
|
# stop gevent/tornado server
|
|
|
|
web_server.stop(task == 0)
|
|
|
|
web_server.stop(task == 0)
|
|
|
|
return json.dumps(showtext)
|
|
|
|
return json.dumps(showtext)
|
|
|
|
else:
|
|
|
|
|
|
|
|
if task == 2:
|
|
|
|
if task == 2:
|
|
|
|
db.session.close()
|
|
|
|
log.warning("reconnecting to calibre database")
|
|
|
|
db.engine.dispose()
|
|
|
|
db.setup_db(config)
|
|
|
|
db.setup_db()
|
|
|
|
return '{}'
|
|
|
|
return json.dumps({})
|
|
|
|
|
|
|
|
abort(404)
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admi.route("/admin/view")
|
|
|
|
@admi.route("/admin/view")
|
|
|
@ -133,8 +128,8 @@ def admin():
|
|
|
|
commit = version['version']
|
|
|
|
commit = version['version']
|
|
|
|
|
|
|
|
|
|
|
|
allUser = ub.session.query(ub.User).all()
|
|
|
|
allUser = ub.session.query(ub.User).all()
|
|
|
|
settings = ub.session.query(ub.Settings).first()
|
|
|
|
email_settings = config.get_mail_settings()
|
|
|
|
return render_title_template("admin.html", allUser=allUser, email=settings, config=config, commit=commit,
|
|
|
|
return render_title_template("admin.html", allUser=allUser, email=email_settings, config=config, commit=commit,
|
|
|
|
title=_(u"Admin page"), page="admin")
|
|
|
|
title=_(u"Admin page"), page="admin")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -142,84 +137,60 @@ def admin():
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
@admin_required
|
|
|
|
@admin_required
|
|
|
|
def configuration():
|
|
|
|
def configuration():
|
|
|
|
return configuration_helper(0)
|
|
|
|
if request.method == "POST":
|
|
|
|
|
|
|
|
return _configuration_update_helper()
|
|
|
|
|
|
|
|
return _configuration_result()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admi.route("/admin/viewconfig", methods=["GET", "POST"])
|
|
|
|
@admi.route("/admin/viewconfig")
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
@admin_required
|
|
|
|
@admin_required
|
|
|
|
def view_configuration():
|
|
|
|
def view_configuration():
|
|
|
|
reboot_required = False
|
|
|
|
|
|
|
|
if request.method == "POST":
|
|
|
|
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
|
|
|
|
content = ub.session.query(ub.Settings).first()
|
|
|
|
|
|
|
|
if "config_calibre_web_title" in to_save:
|
|
|
|
|
|
|
|
content.config_calibre_web_title = to_save["config_calibre_web_title"]
|
|
|
|
|
|
|
|
if "config_columns_to_ignore" in to_save:
|
|
|
|
|
|
|
|
content.config_columns_to_ignore = to_save["config_columns_to_ignore"]
|
|
|
|
|
|
|
|
if "config_read_column" in to_save:
|
|
|
|
|
|
|
|
content.config_read_column = int(to_save["config_read_column"])
|
|
|
|
|
|
|
|
if "config_theme" in to_save:
|
|
|
|
|
|
|
|
content.config_theme = int(to_save["config_theme"])
|
|
|
|
|
|
|
|
if "config_title_regex" in to_save:
|
|
|
|
|
|
|
|
if content.config_title_regex != to_save["config_title_regex"]:
|
|
|
|
|
|
|
|
content.config_title_regex = to_save["config_title_regex"]
|
|
|
|
|
|
|
|
reboot_required = True
|
|
|
|
|
|
|
|
if "config_random_books" in to_save:
|
|
|
|
|
|
|
|
content.config_random_books = int(to_save["config_random_books"])
|
|
|
|
|
|
|
|
if "config_books_per_page" in to_save:
|
|
|
|
|
|
|
|
content.config_books_per_page = int(to_save["config_books_per_page"])
|
|
|
|
|
|
|
|
# Mature Content configuration
|
|
|
|
|
|
|
|
if "config_mature_content_tags" in to_save:
|
|
|
|
|
|
|
|
content.config_mature_content_tags = to_save["config_mature_content_tags"].strip()
|
|
|
|
|
|
|
|
if "Show_mature_content" in to_save:
|
|
|
|
|
|
|
|
content.config_default_show |= constants.MATURE_CONTENT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if "config_authors_max" in to_save:
|
|
|
|
|
|
|
|
content.config_authors_max = int(to_save["config_authors_max"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Default user configuration
|
|
|
|
|
|
|
|
content.config_default_role = 0
|
|
|
|
|
|
|
|
if "admin_role" in to_save:
|
|
|
|
|
|
|
|
content.config_default_role |= constants.ROLE_ADMIN
|
|
|
|
|
|
|
|
if "download_role" in to_save:
|
|
|
|
|
|
|
|
content.config_default_role |= constants.ROLE_DOWNLOAD
|
|
|
|
|
|
|
|
if "viewer_role" in to_save:
|
|
|
|
|
|
|
|
content.config_default_role |= constants.ROLE_VIEWER
|
|
|
|
|
|
|
|
if "upload_role" in to_save:
|
|
|
|
|
|
|
|
content.config_default_role |= constants.ROLE_UPLOAD
|
|
|
|
|
|
|
|
if "edit_role" in to_save:
|
|
|
|
|
|
|
|
content.config_default_role |= constants.ROLE_EDIT
|
|
|
|
|
|
|
|
if "delete_role" in to_save:
|
|
|
|
|
|
|
|
content.config_default_role |= constants.ROLE_DELETE_BOOKS
|
|
|
|
|
|
|
|
if "passwd_role" in to_save:
|
|
|
|
|
|
|
|
content.config_default_role |= constants.ROLE_PASSWD
|
|
|
|
|
|
|
|
if "edit_shelf_role" in to_save:
|
|
|
|
|
|
|
|
content.config_default_role |= constants.ROLE_EDIT_SHELFS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val = 0
|
|
|
|
|
|
|
|
for key, __ in to_save.items():
|
|
|
|
|
|
|
|
if key.startswith('show'):
|
|
|
|
|
|
|
|
val |= int(key[5:])
|
|
|
|
|
|
|
|
content.config_default_show = val
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
|
|
|
flash(_(u"Calibre-Web configuration updated"), category="success")
|
|
|
|
|
|
|
|
config.loadSettings()
|
|
|
|
|
|
|
|
before_request()
|
|
|
|
|
|
|
|
if reboot_required:
|
|
|
|
|
|
|
|
# db.engine.dispose() # ToDo verify correct
|
|
|
|
|
|
|
|
# ub.session.close()
|
|
|
|
|
|
|
|
# ub.engine.dispose()
|
|
|
|
|
|
|
|
# stop Server
|
|
|
|
|
|
|
|
web_server.stop(True)
|
|
|
|
|
|
|
|
log.info('Reboot required, restarting')
|
|
|
|
|
|
|
|
readColumn = db.session.query(db.Custom_Columns)\
|
|
|
|
readColumn = db.session.query(db.Custom_Columns)\
|
|
|
|
.filter(and_(db.Custom_Columns.datatype == 'bool',db.Custom_Columns.mark_for_delete == 0)).all()
|
|
|
|
.filter(and_(db.Custom_Columns.datatype == 'bool',db.Custom_Columns.mark_for_delete == 0)).all()
|
|
|
|
return render_title_template("config_view_edit.html", conf=config, readColumns=readColumn,
|
|
|
|
return render_title_template("config_view_edit.html", conf=config, readColumns=readColumn,
|
|
|
|
title=_(u"UI Configuration"), page="uiconfig")
|
|
|
|
title=_(u"UI Configuration"), page="uiconfig")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admi.route("/admin/viewconfig", methods=["POST"])
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
@admin_required
|
|
|
|
|
|
|
|
def update_view_configuration():
|
|
|
|
|
|
|
|
reboot_required = False
|
|
|
|
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_config_string = lambda x: config.set_from_dictionary(to_save, x, lambda y: y.strip() if y else y)
|
|
|
|
|
|
|
|
_config_int = lambda x: config.set_from_dictionary(to_save, x, int)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_config_string("config_calibre_web_title")
|
|
|
|
|
|
|
|
_config_string("config_columns_to_ignore")
|
|
|
|
|
|
|
|
_config_string("config_mature_content_tags")
|
|
|
|
|
|
|
|
reboot_required |= _config_string("config_title_regex")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_config_int("config_read_column")
|
|
|
|
|
|
|
|
_config_int("config_theme")
|
|
|
|
|
|
|
|
_config_int("config_random_books")
|
|
|
|
|
|
|
|
_config_int("config_books_per_page")
|
|
|
|
|
|
|
|
_config_int("config_authors_max")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.config_default_role = constants.selected_roles(to_save)
|
|
|
|
|
|
|
|
config.config_default_role &= ~constants.ROLE_ANONYMOUS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.config_default_show = sum(int(k[5:]) for k in to_save if k.startswith('show_'))
|
|
|
|
|
|
|
|
if "Show_mature_content" in to_save:
|
|
|
|
|
|
|
|
config.config_default_show |= constants.MATURE_CONTENT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.save()
|
|
|
|
|
|
|
|
flash(_(u"Calibre-Web configuration updated"), category="success")
|
|
|
|
|
|
|
|
before_request()
|
|
|
|
|
|
|
|
if reboot_required:
|
|
|
|
|
|
|
|
db.dispose()
|
|
|
|
|
|
|
|
ub.dispose()
|
|
|
|
|
|
|
|
web_server.stop(True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return view_configuration()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admi.route("/ajax/editdomain", methods=['POST'])
|
|
|
|
@admi.route("/ajax/editdomain", methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
@admin_required
|
|
|
|
@admin_required
|
|
|
@ -280,281 +251,172 @@ def list_domain():
|
|
|
|
@unconfigured
|
|
|
|
@unconfigured
|
|
|
|
def basic_configuration():
|
|
|
|
def basic_configuration():
|
|
|
|
logout_user()
|
|
|
|
logout_user()
|
|
|
|
return configuration_helper(1)
|
|
|
|
if request.method == "POST":
|
|
|
|
|
|
|
|
return _configuration_update_helper()
|
|
|
|
|
|
|
|
return _configuration_result()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def configuration_helper(origin):
|
|
|
|
def _configuration_update_helper():
|
|
|
|
reboot_required = False
|
|
|
|
reboot_required = False
|
|
|
|
gdriveError = None
|
|
|
|
|
|
|
|
db_change = False
|
|
|
|
db_change = False
|
|
|
|
success = False
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
filedata = None
|
|
|
|
|
|
|
|
if not feature_support['gdrive']:
|
|
|
|
_config_string = lambda x: config.set_from_dictionary(to_save, x, lambda y: y.strip() if y else y)
|
|
|
|
gdriveError = _('Import of optional Google Drive requirements missing')
|
|
|
|
_config_int = lambda x: config.set_from_dictionary(to_save, x, int)
|
|
|
|
else:
|
|
|
|
_config_checkbox = lambda x: config.set_from_dictionary(to_save, x, lambda y: y == "on", False)
|
|
|
|
if not os.path.isfile(gdriveutils.CLIENT_SECRETS):
|
|
|
|
_config_checkbox_int = lambda x: config.set_from_dictionary(to_save, x, lambda y: 1 if (y == "on") else 0, 0)
|
|
|
|
gdriveError = _('client_secrets.json is missing or not readable')
|
|
|
|
|
|
|
|
else:
|
|
|
|
db_change |= _config_string("config_calibre_dir")
|
|
|
|
with open(gdriveutils.CLIENT_SECRETS, 'r') as settings:
|
|
|
|
|
|
|
|
filedata = json.load(settings)
|
|
|
|
# Google drive setup
|
|
|
|
if 'web' not in filedata:
|
|
|
|
if not os.path.isfile(gdriveutils.SETTINGS_YAML):
|
|
|
|
gdriveError = _('client_secrets.json is not configured for web application')
|
|
|
|
config.config_use_google_drive = False
|
|
|
|
if request.method == "POST":
|
|
|
|
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
gdrive_secrets = {}
|
|
|
|
content = ub.session.query(ub.Settings).first() # type: ub.Settings
|
|
|
|
gdriveError = gdriveutils.get_error_text(gdrive_secrets)
|
|
|
|
if "config_calibre_dir" in to_save:
|
|
|
|
if "config_use_google_drive" in to_save and not config.config_use_google_drive and not gdriveError:
|
|
|
|
if content.config_calibre_dir != to_save["config_calibre_dir"]:
|
|
|
|
if not gdrive_secrets:
|
|
|
|
content.config_calibre_dir = to_save["config_calibre_dir"]
|
|
|
|
return _configuration_result('client_secrets.json is not configured for web application')
|
|
|
|
db_change = True
|
|
|
|
gdriveutils.update_settings(
|
|
|
|
# Google drive setup
|
|
|
|
gdrive_secrets['client_id'],
|
|
|
|
if not os.path.isfile(gdriveutils.SETTINGS_YAML):
|
|
|
|
gdrive_secrets['client_secret'],
|
|
|
|
content.config_use_google_drive = False
|
|
|
|
gdrive_secrets['redirect_uris'][0]
|
|
|
|
if "config_use_google_drive" in to_save and not content.config_use_google_drive and not gdriveError:
|
|
|
|
)
|
|
|
|
if filedata:
|
|
|
|
|
|
|
|
if filedata['web']['redirect_uris'][0].endswith('/'):
|
|
|
|
# always show google drive settings, but in case of error deny support
|
|
|
|
filedata['web']['redirect_uris'][0] = filedata['web']['redirect_uris'][0][:-1]
|
|
|
|
config.config_use_google_drive = (not gdriveError) and ("config_use_google_drive" in to_save)
|
|
|
|
with open(gdriveutils.SETTINGS_YAML, 'w') as f:
|
|
|
|
if _config_string("config_google_drive_folder"):
|
|
|
|
yaml = "client_config_backend: settings\nclient_config_file: %(client_file)s\n" \
|
|
|
|
gdriveutils.deleteDatabaseOnChange()
|
|
|
|
"client_config:\n" \
|
|
|
|
|
|
|
|
" client_id: %(client_id)s\n client_secret: %(client_secret)s\n" \
|
|
|
|
reboot_required |= _config_int("config_port")
|
|
|
|
" redirect_uri: %(redirect_uri)s\n\nsave_credentials: True\n" \
|
|
|
|
|
|
|
|
"save_credentials_backend: file\nsave_credentials_file: %(credential)s\n\n" \
|
|
|
|
reboot_required |= _config_string("config_keyfile")
|
|
|
|
"get_refresh_token: True\n\noauth_scope:\n" \
|
|
|
|
if config.config_keyfile and not os.path.isfile(config.config_keyfile):
|
|
|
|
" - https://www.googleapis.com/auth/drive\n"
|
|
|
|
return _configuration_result('Keyfile location is not valid, please enter correct path', gdriveError)
|
|
|
|
f.write(yaml % {'client_file': gdriveutils.CLIENT_SECRETS,
|
|
|
|
|
|
|
|
'client_id': filedata['web']['client_id'],
|
|
|
|
reboot_required |= _config_string("config_certfile")
|
|
|
|
'client_secret': filedata['web']['client_secret'],
|
|
|
|
if config.config_certfile and not os.path.isfile(config.config_certfile):
|
|
|
|
'redirect_uri': filedata['web']['redirect_uris'][0],
|
|
|
|
return _configuration_result('Certfile location is not valid, please enter correct path', gdriveError)
|
|
|
|
'credential': gdriveutils.CREDENTIALS})
|
|
|
|
|
|
|
|
else:
|
|
|
|
_config_checkbox_int("config_uploading")
|
|
|
|
flash(_(u'client_secrets.json is not configured for web application'), category="error")
|
|
|
|
_config_checkbox_int("config_anonbrowse")
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
_config_checkbox_int("config_public_reg")
|
|
|
|
gdriveError=gdriveError,
|
|
|
|
|
|
|
|
gfeature_support=feature_support, title=_(u"Basic Configuration"),
|
|
|
|
_config_int("config_ebookconverter")
|
|
|
|
page="config")
|
|
|
|
_config_string("config_calibre")
|
|
|
|
# always show google drive settings, but in case of error deny support
|
|
|
|
_config_string("config_converterpath")
|
|
|
|
if "config_use_google_drive" in to_save and not gdriveError:
|
|
|
|
|
|
|
|
content.config_use_google_drive = "config_use_google_drive" in to_save
|
|
|
|
if _config_int("config_login_type"):
|
|
|
|
else:
|
|
|
|
reboot_required |= config.config_login_type != constants.LOGIN_STANDARD
|
|
|
|
content.config_use_google_drive = 0
|
|
|
|
|
|
|
|
if "config_google_drive_folder" in to_save:
|
|
|
|
#LDAP configurator,
|
|
|
|
if content.config_google_drive_folder != to_save["config_google_drive_folder"]:
|
|
|
|
if config.config_login_type == constants.LOGIN_LDAP:
|
|
|
|
content.config_google_drive_folder = to_save["config_google_drive_folder"]
|
|
|
|
_config_string("config_ldap_provider_url")
|
|
|
|
deleteDatabaseOnChange()
|
|
|
|
_config_int("config_ldap_port")
|
|
|
|
|
|
|
|
_config_string("config_ldap_schema")
|
|
|
|
if "config_port" in to_save:
|
|
|
|
_config_string("config_ldap_dn")
|
|
|
|
if content.config_port != int(to_save["config_port"]):
|
|
|
|
_config_string("config_ldap_user_object")
|
|
|
|
content.config_port = int(to_save["config_port"])
|
|
|
|
if not config.config_ldap_provider_url or not config.config_ldap_port or not config.config_ldap_dn or not config.config_ldap_user_object:
|
|
|
|
reboot_required = True
|
|
|
|
return _configuration_result('Please enter a LDAP provider, port, DN and user object identifier', gdriveError)
|
|
|
|
if "config_keyfile" in to_save:
|
|
|
|
|
|
|
|
if content.config_keyfile != to_save["config_keyfile"]:
|
|
|
|
_config_string("config_ldap_serv_username")
|
|
|
|
if os.path.isfile(to_save["config_keyfile"]) or to_save["config_keyfile"] is u"":
|
|
|
|
if not config.config_ldap_serv_username or "config_ldap_serv_password" not in to_save:
|
|
|
|
content.config_keyfile = to_save["config_keyfile"]
|
|
|
|
return _configuration_result('Please enter a LDAP service account and password', gdriveError)
|
|
|
|
reboot_required = True
|
|
|
|
config.set_from_dictionary(to_save, "config_ldap_serv_password", base64.b64encode)
|
|
|
|
else:
|
|
|
|
|
|
|
|
ub.session.commit()
|
|
|
|
_config_checkbox("config_ldap_use_ssl")
|
|
|
|
flash(_(u'Keyfile location is not valid, please enter correct path'), category="error")
|
|
|
|
_config_checkbox("config_ldap_use_tls")
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
_config_checkbox("config_ldap_openldap")
|
|
|
|
gdriveError=gdriveError,
|
|
|
|
_config_checkbox("config_ldap_require_cert")
|
|
|
|
feature_support=feature_support, title=_(u"Basic Configuration"),
|
|
|
|
_config_string("config_ldap_cert_path")
|
|
|
|
page="config")
|
|
|
|
if config.config_ldap_cert_path and not os.path.isfile(config.config_ldap_cert_path):
|
|
|
|
if "config_certfile" in to_save:
|
|
|
|
return _configuration_result('LDAP Certfile location is not valid, please enter correct path', gdriveError)
|
|
|
|
if content.config_certfile != to_save["config_certfile"]:
|
|
|
|
|
|
|
|
if os.path.isfile(to_save["config_certfile"]) or to_save["config_certfile"] is u"":
|
|
|
|
# Remote login configuration
|
|
|
|
content.config_certfile = to_save["config_certfile"]
|
|
|
|
_config_checkbox("config_remote_login")
|
|
|
|
reboot_required = True
|
|
|
|
if not config.config_remote_login:
|
|
|
|
else:
|
|
|
|
ub.session.query(ub.RemoteAuthToken).delete()
|
|
|
|
ub.session.commit()
|
|
|
|
|
|
|
|
flash(_(u'Certfile location is not valid, please enter correct path'), category="error")
|
|
|
|
# Goodreads configuration
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
_config_checkbox("config_use_goodreads")
|
|
|
|
gdriveError=gdriveError, feature_support=feature_support,
|
|
|
|
_config_string("config_goodreads_api_key")
|
|
|
|
title=_(u"Basic Configuration"), page="config")
|
|
|
|
_config_string("config_goodreads_api_secret")
|
|
|
|
content.config_uploading = 0
|
|
|
|
if services.goodreads:
|
|
|
|
content.config_anonbrowse = 0
|
|
|
|
services.goodreads.connect(config.config_goodreads_api_key, config.config_goodreads_api_secret, config.config_use_goodreads)
|
|
|
|
content.config_public_reg = 0
|
|
|
|
|
|
|
|
if "config_uploading" in to_save and to_save["config_uploading"] == "on":
|
|
|
|
_config_int("config_updatechannel")
|
|
|
|
content.config_uploading = 1
|
|
|
|
|
|
|
|
if "config_anonbrowse" in to_save and to_save["config_anonbrowse"] == "on":
|
|
|
|
# GitHub OAuth configuration
|
|
|
|
content.config_anonbrowse = 1
|
|
|
|
if config.config_login_type == constants.LOGIN_OAUTH_GITHUB:
|
|
|
|
if "config_public_reg" in to_save and to_save["config_public_reg"] == "on":
|
|
|
|
_config_string("config_github_oauth_client_id")
|
|
|
|
content.config_public_reg = 1
|
|
|
|
_config_string("config_github_oauth_client_secret")
|
|
|
|
|
|
|
|
if not config.config_github_oauth_client_id or not config.config_github_oauth_client_secret:
|
|
|
|
if "config_converterpath" in to_save:
|
|
|
|
return _configuration_result('Please enter Github oauth credentials', gdriveError)
|
|
|
|
content.config_converterpath = to_save["config_converterpath"].strip()
|
|
|
|
|
|
|
|
if "config_calibre" in to_save:
|
|
|
|
# Google OAuth configuration
|
|
|
|
content.config_calibre = to_save["config_calibre"].strip()
|
|
|
|
if config.config_login_type == constants.LOGIN_OAUTH_GOOGLE:
|
|
|
|
if "config_ebookconverter" in to_save:
|
|
|
|
_config_string("config_google_oauth_client_id")
|
|
|
|
content.config_ebookconverter = int(to_save["config_ebookconverter"])
|
|
|
|
_config_string("config_google_oauth_client_secret")
|
|
|
|
|
|
|
|
if not config.config_google_oauth_client_id or not config.config_google_oauth_client_secret:
|
|
|
|
#LDAP configurator,
|
|
|
|
return _configuration_result('Please enter Google oauth credentials', gdriveError)
|
|
|
|
if "config_login_type" in to_save and to_save["config_login_type"] == "1":
|
|
|
|
|
|
|
|
if not to_save["config_ldap_provider_url"] or not to_save["config_ldap_port"] or not to_save["config_ldap_dn"] or not to_save["config_ldap_user_object"]:
|
|
|
|
_config_int("config_log_level")
|
|
|
|
ub.session.commit()
|
|
|
|
_config_string("config_logfile")
|
|
|
|
flash(_(u'Please enter a LDAP provider, port, DN and user object identifier'), category="error")
|
|
|
|
if not logger.is_valid_logfile(config.config_logfile):
|
|
|
|
return render_title_template("config_edit.html", content=config, origin=origin,
|
|
|
|
return _configuration_result('Logfile location is not valid, please enter correct path', gdriveError)
|
|
|
|
gdrive=gdriveutils.gdrive_support, gdriveError=gdriveError,
|
|
|
|
|
|
|
|
feature_support=feature_support, title=_(u"Basic Configuration"),
|
|
|
|
reboot_required |= _config_checkbox_int("config_access_log")
|
|
|
|
page="config")
|
|
|
|
reboot_required |= _config_string("config_access_logfile")
|
|
|
|
elif not to_save["config_ldap_serv_username"] or not to_save["config_ldap_serv_password"]:
|
|
|
|
if not logger.is_valid_logfile(config.config_access_logfile):
|
|
|
|
ub.session.commit()
|
|
|
|
return _configuration_result('Access Logfile location is not valid, please enter correct path', gdriveError)
|
|
|
|
flash(_(u'Please enter a LDAP service account and password'), category="error")
|
|
|
|
|
|
|
|
return render_title_template("config_edit.html", content=config, origin=origin,
|
|
|
|
# Rarfile Content configuration
|
|
|
|
gdrive=gdriveutils.gdrive_support, gdriveError=gdriveError,
|
|
|
|
_config_string("config_rarfile_location")
|
|
|
|
feature_support=feature_support, title=_(u"Basic Configuration"),
|
|
|
|
unrar_status = helper.check_unrar(config.config_rarfile_location)
|
|
|
|
page="config")
|
|
|
|
if unrar_status:
|
|
|
|
else:
|
|
|
|
return _configuration_result(unrar_status, gdriveError)
|
|
|
|
content.config_use_ldap = 1
|
|
|
|
|
|
|
|
content.config_ldap_provider_url = to_save["config_ldap_provider_url"]
|
|
|
|
try:
|
|
|
|
content.config_ldap_port = to_save["config_ldap_port"]
|
|
|
|
metadata_db = os.path.join(config.config_calibre_dir, "metadata.db")
|
|
|
|
content.config_ldap_schema = to_save["config_ldap_schema"]
|
|
|
|
if config.config_use_google_drive and is_gdrive_ready() and not os.path.exists(metadata_db):
|
|
|
|
content.config_ldap_serv_username = to_save["config_ldap_serv_username"]
|
|
|
|
gdriveutils.downloadFile(None, "metadata.db", metadata_db)
|
|
|
|
content.config_ldap_serv_password = base64.b64encode(to_save["config_ldap_serv_password"])
|
|
|
|
db_change = True
|
|
|
|
content.config_ldap_dn = to_save["config_ldap_dn"]
|
|
|
|
except Exception as e:
|
|
|
|
content.config_ldap_user_object = to_save["config_ldap_user_object"]
|
|
|
|
return _configuration_result('%s' % e, gdriveError)
|
|
|
|
reboot_required = True
|
|
|
|
|
|
|
|
content.config_ldap_use_ssl = 0
|
|
|
|
if db_change:
|
|
|
|
content.config_ldap_use_tls = 0
|
|
|
|
# reload(db)
|
|
|
|
content.config_ldap_require_cert = 0
|
|
|
|
if not db.setup_db(config):
|
|
|
|
content.config_ldap_openldap = 0
|
|
|
|
return _configuration_result('DB location is not valid, please enter correct path', gdriveError)
|
|
|
|
if "config_ldap_use_ssl" in to_save and to_save["config_ldap_use_ssl"] == "on":
|
|
|
|
|
|
|
|
content.config_ldap_use_ssl = 1
|
|
|
|
config.save()
|
|
|
|
if "config_ldap_use_tls" in to_save and to_save["config_ldap_use_tls"] == "on":
|
|
|
|
flash(_(u"Calibre-Web configuration updated"), category="success")
|
|
|
|
content.config_ldap_use_tls = 1
|
|
|
|
if reboot_required:
|
|
|
|
if "config_ldap_require_cert" in to_save and to_save["config_ldap_require_cert"] == "on":
|
|
|
|
web_server.stop(True)
|
|
|
|
content.config_ldap_require_cert = 1
|
|
|
|
|
|
|
|
if "config_ldap_openldap" in to_save and to_save["config_ldap_openldap"] == "on":
|
|
|
|
return _configuration_result(None, gdriveError)
|
|
|
|
content.config_ldap_openldap = 1
|
|
|
|
|
|
|
|
if "config_ldap_cert_path " in to_save:
|
|
|
|
|
|
|
|
if content.config_ldap_cert_path != to_save["config_ldap_cert_path "]:
|
|
|
|
def _configuration_result(error_flash=None, gdriveError=None):
|
|
|
|
if os.path.isfile(to_save["config_ldap_cert_path "]) or to_save["config_ldap_cert_path "] is u"":
|
|
|
|
gdrive_authenticate = not is_gdrive_ready()
|
|
|
|
content.config_certfile = to_save["config_ldap_cert_path "]
|
|
|
|
gdrivefolders = []
|
|
|
|
else:
|
|
|
|
if gdriveError is None:
|
|
|
|
ub.session.commit()
|
|
|
|
gdriveError = gdriveutils.get_error_text()
|
|
|
|
flash(_(u'Certfile location is not valid, please enter correct path'), category="error")
|
|
|
|
if gdriveError:
|
|
|
|
return render_title_template("config_edit.html", content=config, origin=origin,
|
|
|
|
gdriveError = _(gdriveError)
|
|
|
|
gdrive=gdriveutils.gdrive_support, gdriveError=gdriveError,
|
|
|
|
|
|
|
|
feature_support=feature_support, title=_(u"Basic Configuration"),
|
|
|
|
|
|
|
|
page="config")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Remote login configuration
|
|
|
|
|
|
|
|
content.config_remote_login = ("config_remote_login" in to_save and to_save["config_remote_login"] == "on")
|
|
|
|
|
|
|
|
if not content.config_remote_login:
|
|
|
|
|
|
|
|
ub.session.query(ub.RemoteAuthToken).delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Goodreads configuration
|
|
|
|
|
|
|
|
content.config_use_goodreads = ("config_use_goodreads" in to_save and to_save["config_use_goodreads"] == "on")
|
|
|
|
|
|
|
|
if "config_goodreads_api_key" in to_save:
|
|
|
|
|
|
|
|
content.config_goodreads_api_key = to_save["config_goodreads_api_key"]
|
|
|
|
|
|
|
|
if "config_goodreads_api_secret" in to_save:
|
|
|
|
|
|
|
|
content.config_goodreads_api_secret = to_save["config_goodreads_api_secret"]
|
|
|
|
|
|
|
|
if "config_updater" in to_save:
|
|
|
|
|
|
|
|
content.config_updatechannel = int(to_save["config_updater"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# GitHub OAuth configuration
|
|
|
|
|
|
|
|
if "config_login_type" in to_save and to_save["config_login_type"] == "2":
|
|
|
|
|
|
|
|
if to_save["config_github_oauth_client_id"] == u'' or to_save["config_github_oauth_client_secret"] == u'':
|
|
|
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
|
|
|
flash(_(u'Please enter Github oauth credentials'), category="error")
|
|
|
|
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
|
|
|
|
gdriveError=gdriveError, feature_support=feature_support,
|
|
|
|
|
|
|
|
title=_(u"Basic Configuration"), page="config")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
content.config_login_type = constants.LOGIN_OAUTH_GITHUB
|
|
|
|
|
|
|
|
content.config_github_oauth_client_id = to_save["config_github_oauth_client_id"]
|
|
|
|
|
|
|
|
content.config_github_oauth_client_secret = to_save["config_github_oauth_client_secret"]
|
|
|
|
|
|
|
|
reboot_required = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Google OAuth configuration
|
|
|
|
|
|
|
|
if "config_login_type" in to_save and to_save["config_login_type"] == "3":
|
|
|
|
|
|
|
|
if to_save["config_google_oauth_client_id"] == u'' or to_save["config_google_oauth_client_secret"] == u'':
|
|
|
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
|
|
|
flash(_(u'Please enter Google oauth credentials'), category="error")
|
|
|
|
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
|
|
|
|
gdriveError=gdriveError, feature_support=feature_support,
|
|
|
|
|
|
|
|
title=_(u"Basic Configuration"), page="config")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
content.config_login_type = constants.LOGIN_OAUTH_GOOGLE
|
|
|
|
|
|
|
|
content.config_google_oauth_client_id = to_save["config_google_oauth_client_id"]
|
|
|
|
|
|
|
|
content.config_google_oauth_client_secret = to_save["config_google_oauth_client_secret"]
|
|
|
|
|
|
|
|
reboot_required = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if "config_login_type" in to_save and to_save["config_login_type"] == "0":
|
|
|
|
|
|
|
|
content.config_login_type = constants.LOGIN_STANDARD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if "config_log_level" in to_save:
|
|
|
|
|
|
|
|
content.config_log_level = int(to_save["config_log_level"])
|
|
|
|
|
|
|
|
if content.config_logfile != to_save["config_logfile"]:
|
|
|
|
|
|
|
|
# check valid path, only path or file
|
|
|
|
|
|
|
|
if not logger.is_valid_logfile(to_save["config_logfile"]):
|
|
|
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
|
|
|
flash(_(u'Logfile location is not valid, please enter correct path'), category="error")
|
|
|
|
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
|
|
|
|
gdriveError=gdriveError, feature_support=feature_support,
|
|
|
|
|
|
|
|
title=_(u"Basic Configuration"), page="config")
|
|
|
|
|
|
|
|
content.config_logfile = to_save["config_logfile"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
content.config_access_log = 0
|
|
|
|
|
|
|
|
if "config_access_log" in to_save and to_save["config_access_log"] == "on":
|
|
|
|
|
|
|
|
content.config_access_log = 1
|
|
|
|
|
|
|
|
reboot_required = True
|
|
|
|
|
|
|
|
if "config_access_log" not in to_save and config.config_access_log:
|
|
|
|
|
|
|
|
reboot_required = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if content.config_access_logfile != to_save["config_access_logfile"]:
|
|
|
|
|
|
|
|
# check valid path, only path or file
|
|
|
|
|
|
|
|
if not logger.is_valid_logfile(to_save["config_access_logfile"]):
|
|
|
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
|
|
|
flash(_(u'Access Logfile location is not valid, please enter correct path'), category="error")
|
|
|
|
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
|
|
|
|
gdriveError=gdriveError, feature_support=feature_support,
|
|
|
|
|
|
|
|
title=_(u"Basic Configuration"), page="config")
|
|
|
|
|
|
|
|
content.config_access_logfile = to_save["config_access_logfile"]
|
|
|
|
|
|
|
|
reboot_required = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Rarfile Content configuration
|
|
|
|
|
|
|
|
if "config_rarfile_location" in to_save and to_save['config_rarfile_location'] is not u"":
|
|
|
|
|
|
|
|
check = check_unrar(to_save["config_rarfile_location"].strip())
|
|
|
|
|
|
|
|
if not check[0] :
|
|
|
|
|
|
|
|
content.config_rarfile_location = to_save["config_rarfile_location"].strip()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
flash(check[1], category="error")
|
|
|
|
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
|
|
|
|
feature_support=feature_support, title=_(u"Basic Configuration"))
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
if content.config_use_google_drive and is_gdrive_ready() and not \
|
|
|
|
|
|
|
|
os.path.exists(os.path.join(content.config_calibre_dir, "metadata.db")):
|
|
|
|
|
|
|
|
downloadFile(None, "metadata.db", config.config_calibre_dir + "/metadata.db")
|
|
|
|
|
|
|
|
if db_change:
|
|
|
|
|
|
|
|
if config.db_configured:
|
|
|
|
|
|
|
|
db.session.close()
|
|
|
|
|
|
|
|
db.engine.dispose()
|
|
|
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
|
|
|
flash(_(u"Calibre-Web configuration updated"), category="success")
|
|
|
|
|
|
|
|
config.loadSettings()
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
flash(e, category="error")
|
|
|
|
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
|
|
|
|
gdriveError=gdriveError, feature_support=feature_support,
|
|
|
|
|
|
|
|
title=_(u"Basic Configuration"), page="config")
|
|
|
|
|
|
|
|
if db_change:
|
|
|
|
|
|
|
|
reload(db)
|
|
|
|
|
|
|
|
if not db.setup_db():
|
|
|
|
|
|
|
|
flash(_(u'DB location is not valid, please enter correct path'), category="error")
|
|
|
|
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
|
|
|
|
gdriveError=gdriveError, feature_support=feature_support,
|
|
|
|
|
|
|
|
title=_(u"Basic Configuration"), page="config")
|
|
|
|
|
|
|
|
if reboot_required:
|
|
|
|
|
|
|
|
# stop Server
|
|
|
|
|
|
|
|
web_server.stop(True)
|
|
|
|
|
|
|
|
log.info('Reboot required, restarting')
|
|
|
|
|
|
|
|
if origin:
|
|
|
|
|
|
|
|
success = True
|
|
|
|
|
|
|
|
if is_gdrive_ready() and feature_support['gdrive'] is True and config.config_use_google_drive == True:
|
|
|
|
|
|
|
|
gdrivefolders = listRootFolders()
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
gdrivefolders = list()
|
|
|
|
gdrivefolders = gdriveutils.listRootFolders()
|
|
|
|
return render_title_template("config_edit.html", origin=origin, success=success, config=config,
|
|
|
|
|
|
|
|
show_authenticate_google_drive=not is_gdrive_ready(),
|
|
|
|
show_back_button = current_user.is_authenticated
|
|
|
|
|
|
|
|
show_login_button = config.db_configured and not current_user.is_authenticated
|
|
|
|
|
|
|
|
if error_flash:
|
|
|
|
|
|
|
|
config.load()
|
|
|
|
|
|
|
|
flash(_(error_flash), category="error")
|
|
|
|
|
|
|
|
show_login_button = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return render_title_template("config_edit.html", config=config,
|
|
|
|
|
|
|
|
show_back_button=show_back_button, show_login_button=show_login_button,
|
|
|
|
|
|
|
|
show_authenticate_google_drive=gdrive_authenticate,
|
|
|
|
gdriveError=gdriveError, gdrivefolders=gdrivefolders, feature_support=feature_support,
|
|
|
|
gdriveError=gdriveError, gdrivefolders=gdrivefolders, feature_support=feature_support,
|
|
|
|
title=_(u"Basic Configuration"), page="config")
|
|
|
|
title=_(u"Basic Configuration"), page="config")
|
|
|
|
|
|
|
|
|
|
|
@ -570,34 +432,14 @@ def new_user():
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
content.default_language = to_save["default_language"]
|
|
|
|
content.default_language = to_save["default_language"]
|
|
|
|
content.mature_content = "Show_mature_content" in to_save
|
|
|
|
content.mature_content = "Show_mature_content" in to_save
|
|
|
|
if "locale" in to_save:
|
|
|
|
content.locale = to_save.get("locale", content.locale)
|
|
|
|
content.locale = to_save["locale"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val = 0
|
|
|
|
|
|
|
|
for key, __ in to_save.items():
|
|
|
|
|
|
|
|
if key.startswith('show'):
|
|
|
|
|
|
|
|
val += int(key[5:])
|
|
|
|
|
|
|
|
content.sidebar_view = val
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
content.sidebar_view = sum(int(key[5:]) for key in to_save if key.startswith('show_'))
|
|
|
|
if "show_detail_random" in to_save:
|
|
|
|
if "show_detail_random" in to_save:
|
|
|
|
content.sidebar_view |= constants.DETAIL_RANDOM
|
|
|
|
content.sidebar_view |= constants.DETAIL_RANDOM
|
|
|
|
|
|
|
|
|
|
|
|
content.role = 0
|
|
|
|
content.role = constants.selected_roles(to_save)
|
|
|
|
if "admin_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_ADMIN
|
|
|
|
|
|
|
|
if "download_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_DOWNLOAD
|
|
|
|
|
|
|
|
if "upload_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_UPLOAD
|
|
|
|
|
|
|
|
if "edit_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_EDIT
|
|
|
|
|
|
|
|
if "delete_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_DELETE_BOOKS
|
|
|
|
|
|
|
|
if "passwd_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_PASSWD
|
|
|
|
|
|
|
|
if "edit_shelf_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_EDIT_SHELFS
|
|
|
|
|
|
|
|
if not to_save["nickname"] or not to_save["email"] or not to_save["password"]:
|
|
|
|
if not to_save["nickname"] or not to_save["email"] or not to_save["password"]:
|
|
|
|
flash(_(u"Please fill out all fields!"), category="error")
|
|
|
|
flash(_(u"Please fill out all fields!"), category="error")
|
|
|
|
return render_title_template("user_edit.html", new_user=1, content=content, translations=translations,
|
|
|
|
return render_title_template("user_edit.html", new_user=1, content=content, translations=translations,
|
|
|
@ -608,13 +450,13 @@ def new_user():
|
|
|
|
existing_email = ub.session.query(ub.User).filter(ub.User.email == to_save["email"].lower())\
|
|
|
|
existing_email = ub.session.query(ub.User).filter(ub.User.email == to_save["email"].lower())\
|
|
|
|
.first()
|
|
|
|
.first()
|
|
|
|
if not existing_user and not existing_email:
|
|
|
|
if not existing_user and not existing_email:
|
|
|
|
content.nickname = to_save["nickname"]
|
|
|
|
content.nickname = to_save["nickname"]
|
|
|
|
if config.config_public_reg and not check_valid_domain(to_save["email"]):
|
|
|
|
if config.config_public_reg and not check_valid_domain(to_save["email"]):
|
|
|
|
flash(_(u"E-mail is not from valid domain"), category="error")
|
|
|
|
flash(_(u"E-mail is not from valid domain"), category="error")
|
|
|
|
return render_title_template("user_edit.html", new_user=1, content=content, translations=translations,
|
|
|
|
return render_title_template("user_edit.html", new_user=1, content=content, translations=translations,
|
|
|
|
registered_oauth=oauth_check, title=_(u"Add new user"))
|
|
|
|
registered_oauth=oauth_check, title=_(u"Add new user"))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
content.email = to_save["email"]
|
|
|
|
content.email = to_save["email"]
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
flash(_(u"Found an existing account for this e-mail address or nickname."), category="error")
|
|
|
|
flash(_(u"Found an existing account for this e-mail address or nickname."), category="error")
|
|
|
|
return render_title_template("user_edit.html", new_user=1, content=content, translations=translations,
|
|
|
|
return render_title_template("user_edit.html", new_user=1, content=content, translations=translations,
|
|
|
@ -637,39 +479,50 @@ def new_user():
|
|
|
|
registered_oauth=oauth_check)
|
|
|
|
registered_oauth=oauth_check)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admi.route("/admin/mailsettings", methods=["GET", "POST"])
|
|
|
|
@admi.route("/admin/mailsettings")
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
@admin_required
|
|
|
|
@admin_required
|
|
|
|
def edit_mailsettings():
|
|
|
|
def edit_mailsettings():
|
|
|
|
content = ub.session.query(ub.Settings).first()
|
|
|
|
content = config.get_mail_settings()
|
|
|
|
if request.method == "POST":
|
|
|
|
# log.debug("edit_mailsettings %r", content)
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
|
|
|
|
content.mail_server = to_save["mail_server"]
|
|
|
|
|
|
|
|
content.mail_port = int(to_save["mail_port"])
|
|
|
|
|
|
|
|
content.mail_login = to_save["mail_login"]
|
|
|
|
|
|
|
|
content.mail_password = to_save["mail_password"]
|
|
|
|
|
|
|
|
content.mail_from = to_save["mail_from"]
|
|
|
|
|
|
|
|
content.mail_use_ssl = int(to_save["mail_use_ssl"])
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
flash(e, category="error")
|
|
|
|
|
|
|
|
if "test" in to_save and to_save["test"]:
|
|
|
|
|
|
|
|
if current_user.kindle_mail:
|
|
|
|
|
|
|
|
result = send_test_mail(current_user.kindle_mail, current_user.nickname)
|
|
|
|
|
|
|
|
if result is None:
|
|
|
|
|
|
|
|
flash(_(u"Test e-mail successfully send to %(kindlemail)s", kindlemail=current_user.kindle_mail),
|
|
|
|
|
|
|
|
category="success")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
flash(_(u"There was an error sending the Test e-mail: %(res)s", res=result), category="error")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
flash(_(u"Please configure your kindle e-mail address first..."), category="error")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
flash(_(u"E-mail server settings updated"), category="success")
|
|
|
|
|
|
|
|
return render_title_template("email_edit.html", content=content, title=_(u"Edit e-mail server settings"),
|
|
|
|
return render_title_template("email_edit.html", content=content, title=_(u"Edit e-mail server settings"),
|
|
|
|
page="mailset")
|
|
|
|
page="mailset")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admi.route("/admin/mailsettings", methods=["POST"])
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
@admin_required
|
|
|
|
|
|
|
|
def update_mailsettings():
|
|
|
|
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
|
|
|
|
log.debug("update_mailsettings %r", to_save)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_config_string = lambda x: config.set_from_dictionary(to_save, x, lambda y: y.strip() if y else y)
|
|
|
|
|
|
|
|
_config_int = lambda x: config.set_from_dictionary(to_save, x, int)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_config_string("mail_server")
|
|
|
|
|
|
|
|
_config_int("mail_port")
|
|
|
|
|
|
|
|
_config_int("mail_use_ssl")
|
|
|
|
|
|
|
|
_config_string("mail_login")
|
|
|
|
|
|
|
|
_config_string("mail_password")
|
|
|
|
|
|
|
|
_config_string("mail_from")
|
|
|
|
|
|
|
|
config.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if to_save.get("test"):
|
|
|
|
|
|
|
|
if current_user.kindle_mail:
|
|
|
|
|
|
|
|
result = send_test_mail(current_user.kindle_mail, current_user.nickname)
|
|
|
|
|
|
|
|
if result is None:
|
|
|
|
|
|
|
|
flash(_(u"Test e-mail successfully send to %(kindlemail)s", kindlemail=current_user.kindle_mail),
|
|
|
|
|
|
|
|
category="success")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
flash(_(u"There was an error sending the Test e-mail: %(res)s", res=result), category="error")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
flash(_(u"Please configure your kindle e-mail address first..."), category="error")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
flash(_(u"E-mail server settings updated"), category="success")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return edit_mailsettings()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admi.route("/admin/user/<int:user_id>", methods=["GET", "POST"])
|
|
|
|
@admi.route("/admin/user/<int:user_id>", methods=["GET", "POST"])
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
@admin_required
|
|
|
|
@admin_required
|
|
|
@ -703,53 +556,21 @@ def edit_user(user_id):
|
|
|
|
if "password" in to_save and to_save["password"]:
|
|
|
|
if "password" in to_save and to_save["password"]:
|
|
|
|
content.password = generate_password_hash(to_save["password"])
|
|
|
|
content.password = generate_password_hash(to_save["password"])
|
|
|
|
|
|
|
|
|
|
|
|
if "admin_role" in to_save:
|
|
|
|
anonymous = content.is_anonymous
|
|
|
|
content.role |= constants.ROLE_ADMIN
|
|
|
|
content.role = constants.selected_roles(to_save)
|
|
|
|
else:
|
|
|
|
if anonymous:
|
|
|
|
content.role &= ~constants.ROLE_ADMIN
|
|
|
|
content.role |= constants.ROLE_ANONYMOUS
|
|
|
|
|
|
|
|
|
|
|
|
if "download_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_DOWNLOAD
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
content.role &= ~constants.ROLE_DOWNLOAD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if "viewer_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_VIEWER
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
content.role &= ~constants.ROLE_VIEWER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if "upload_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_UPLOAD
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
content.role &= ~constants.ROLE_UPLOAD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if "edit_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_EDIT
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
content.role &= ~constants.ROLE_EDIT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if "delete_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_DELETE_BOOKS
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
content.role &= ~constants.ROLE_DELETE_BOOKS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if "passwd_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_PASSWD
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
content.role &= ~constants.ROLE_PASSWD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if "edit_shelf_role" in to_save:
|
|
|
|
|
|
|
|
content.role |= constants.ROLE_EDIT_SHELFS
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
content.role &= ~constants.ROLE_EDIT_SHELFS
|
|
|
|
content.role &= ~constants.ROLE_ANONYMOUS
|
|
|
|
|
|
|
|
|
|
|
|
val = [int(k[5:]) for k, __ in to_save.items() if k.startswith('show_')]
|
|
|
|
val = [int(k[5:]) for k in to_save if k.startswith('show_')]
|
|
|
|
sidebar = ub.get_sidebar_config()
|
|
|
|
sidebar = ub.get_sidebar_config()
|
|
|
|
for element in sidebar:
|
|
|
|
for element in sidebar:
|
|
|
|
if element['visibility'] in val and not content.check_visibility(element['visibility']):
|
|
|
|
value = element['visibility']
|
|
|
|
content.sidebar_view |= element['visibility']
|
|
|
|
if value in val and not content.check_visibility(value):
|
|
|
|
elif not element['visibility'] in val and content.check_visibility(element['visibility']):
|
|
|
|
content.sidebar_view |= value
|
|
|
|
content.sidebar_view &= ~element['visibility']
|
|
|
|
elif not value in val and content.check_visibility(value):
|
|
|
|
|
|
|
|
content.sidebar_view &= ~value
|
|
|
|
|
|
|
|
|
|
|
|
if "Show_detail_random" in to_save:
|
|
|
|
if "Show_detail_random" in to_save:
|
|
|
|
content.sidebar_view |= constants.DETAIL_RANDOM
|
|
|
|
content.sidebar_view |= constants.DETAIL_RANDOM
|
|
|
|