|
|
@ -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
|
|
|
@ -40,21 +41,16 @@ from sqlalchemy import and_
|
|
|
|
from sqlalchemy.exc import IntegrityError
|
|
|
|
from sqlalchemy.exc import IntegrityError
|
|
|
|
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 +59,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 +82,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,12 +95,12 @@ 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -133,8 +127,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,82 +136,58 @@ 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():
|
|
|
|
|
|
|
|
readColumn = db.session.query(db.Custom_Columns)\
|
|
|
|
|
|
|
|
.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,
|
|
|
|
|
|
|
|
title=_(u"UI Configuration"), page="uiconfig")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admi.route("/admin/viewconfig", methods=["POST"])
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
@admin_required
|
|
|
|
|
|
|
|
def update_view_configuration():
|
|
|
|
reboot_required = False
|
|
|
|
reboot_required = False
|
|
|
|
if request.method == "POST":
|
|
|
|
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
content = ub.session.query(ub.Settings).first()
|
|
|
|
|
|
|
|
if "config_calibre_web_title" in to_save:
|
|
|
|
_config_string = lambda x: config.set_from_dictionary(to_save, x, lambda y: y.strip() if y else y)
|
|
|
|
content.config_calibre_web_title = to_save["config_calibre_web_title"]
|
|
|
|
_config_int = lambda x: config.set_from_dictionary(to_save, x, int)
|
|
|
|
if "config_columns_to_ignore" in to_save:
|
|
|
|
|
|
|
|
content.config_columns_to_ignore = to_save["config_columns_to_ignore"]
|
|
|
|
_config_string("config_calibre_web_title")
|
|
|
|
if "config_read_column" in to_save:
|
|
|
|
_config_string("config_columns_to_ignore")
|
|
|
|
content.config_read_column = int(to_save["config_read_column"])
|
|
|
|
_config_string("config_mature_content_tags")
|
|
|
|
if "config_theme" in to_save:
|
|
|
|
reboot_required |= _config_string("config_title_regex")
|
|
|
|
content.config_theme = int(to_save["config_theme"])
|
|
|
|
|
|
|
|
if "config_title_regex" in to_save:
|
|
|
|
_config_int("config_read_column")
|
|
|
|
if content.config_title_regex != to_save["config_title_regex"]:
|
|
|
|
_config_int("config_theme")
|
|
|
|
content.config_title_regex = to_save["config_title_regex"]
|
|
|
|
_config_int("config_random_books")
|
|
|
|
reboot_required = True
|
|
|
|
_config_int("config_books_per_page")
|
|
|
|
if "config_random_books" in to_save:
|
|
|
|
_config_int("config_authors_max")
|
|
|
|
content.config_random_books = int(to_save["config_random_books"])
|
|
|
|
|
|
|
|
if "config_books_per_page" in to_save:
|
|
|
|
config.config_default_role = constants.selected_roles(to_save)
|
|
|
|
content.config_books_per_page = int(to_save["config_books_per_page"])
|
|
|
|
config.config_default_role &= ~constants.ROLE_ANONYMOUS
|
|
|
|
# Mature Content configuration
|
|
|
|
|
|
|
|
if "config_mature_content_tags" in to_save:
|
|
|
|
config.config_default_show = sum(int(k[5:]) for k in to_save if k.startswith('show_'))
|
|
|
|
content.config_mature_content_tags = to_save["config_mature_content_tags"].strip()
|
|
|
|
|
|
|
|
if "Show_mature_content" in to_save:
|
|
|
|
if "Show_mature_content" in to_save:
|
|
|
|
content.config_default_show |= constants.MATURE_CONTENT
|
|
|
|
config.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()
|
|
|
|
config.save()
|
|
|
|
flash(_(u"Calibre-Web configuration updated"), category="success")
|
|
|
|
flash(_(u"Calibre-Web configuration updated"), category="success")
|
|
|
|
config.loadSettings()
|
|
|
|
|
|
|
|
before_request()
|
|
|
|
before_request()
|
|
|
|
if reboot_required:
|
|
|
|
if reboot_required:
|
|
|
|
# db.engine.dispose() # ToDo verify correct
|
|
|
|
db.dispose()
|
|
|
|
# ub.session.close()
|
|
|
|
ub.dispose()
|
|
|
|
# ub.engine.dispose()
|
|
|
|
|
|
|
|
# stop Server
|
|
|
|
|
|
|
|
web_server.stop(True)
|
|
|
|
web_server.stop(True)
|
|
|
|
log.info('Reboot required, restarting')
|
|
|
|
|
|
|
|
readColumn = db.session.query(db.Custom_Columns)\
|
|
|
|
return view_configuration()
|
|
|
|
.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,
|
|
|
|
|
|
|
|
title=_(u"UI Configuration"), page="uiconfig")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admi.route("/ajax/editdomain", methods=['POST'])
|
|
|
|
@admi.route("/ajax/editdomain", methods=['POST'])
|
|
|
@ -280,281 +250,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
|
|
|
|
|
|
|
|
filedata = None
|
|
|
|
|
|
|
|
if not feature_support['gdrive']:
|
|
|
|
|
|
|
|
gdriveError = _('Import of optional Google Drive requirements missing')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
if not os.path.isfile(gdriveutils.CLIENT_SECRETS):
|
|
|
|
|
|
|
|
gdriveError = _('client_secrets.json is missing or not readable')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
with open(gdriveutils.CLIENT_SECRETS, 'r') as settings:
|
|
|
|
|
|
|
|
filedata = json.load(settings)
|
|
|
|
|
|
|
|
if 'web' not in filedata:
|
|
|
|
|
|
|
|
gdriveError = _('client_secrets.json is not configured for web application')
|
|
|
|
|
|
|
|
if request.method == "POST":
|
|
|
|
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
content = ub.session.query(ub.Settings).first() # type: ub.Settings
|
|
|
|
|
|
|
|
if "config_calibre_dir" in to_save:
|
|
|
|
_config_string = lambda x: config.set_from_dictionary(to_save, x, lambda y: y.strip() if y else y)
|
|
|
|
if content.config_calibre_dir != to_save["config_calibre_dir"]:
|
|
|
|
_config_int = lambda x: config.set_from_dictionary(to_save, x, int)
|
|
|
|
content.config_calibre_dir = to_save["config_calibre_dir"]
|
|
|
|
_config_checkbox = lambda x: config.set_from_dictionary(to_save, x, lambda y: y == "on", False)
|
|
|
|
db_change = True
|
|
|
|
_config_checkbox_int = lambda x: config.set_from_dictionary(to_save, x, lambda y: 1 if (y == "on") else 0, 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db_change |= _config_string("config_calibre_dir")
|
|
|
|
|
|
|
|
|
|
|
|
# Google drive setup
|
|
|
|
# Google drive setup
|
|
|
|
if not os.path.isfile(gdriveutils.SETTINGS_YAML):
|
|
|
|
if not os.path.isfile(gdriveutils.SETTINGS_YAML):
|
|
|
|
content.config_use_google_drive = False
|
|
|
|
config.config_use_google_drive = False
|
|
|
|
if "config_use_google_drive" in to_save and not content.config_use_google_drive and not gdriveError:
|
|
|
|
|
|
|
|
if filedata:
|
|
|
|
gdrive_secrets = {}
|
|
|
|
if filedata['web']['redirect_uris'][0].endswith('/'):
|
|
|
|
gdriveError = gdriveutils.get_error_text(gdrive_secrets)
|
|
|
|
filedata['web']['redirect_uris'][0] = filedata['web']['redirect_uris'][0][:-1]
|
|
|
|
if "config_use_google_drive" in to_save and not config.config_use_google_drive and not gdriveError:
|
|
|
|
with open(gdriveutils.SETTINGS_YAML, 'w') as f:
|
|
|
|
if not gdrive_secrets:
|
|
|
|
yaml = "client_config_backend: settings\nclient_config_file: %(client_file)s\n" \
|
|
|
|
return _configuration_result('client_secrets.json is not configured for web application')
|
|
|
|
"client_config:\n" \
|
|
|
|
gdriveutils.update_settings(
|
|
|
|
" client_id: %(client_id)s\n client_secret: %(client_secret)s\n" \
|
|
|
|
gdrive_secrets['client_id'],
|
|
|
|
" redirect_uri: %(redirect_uri)s\n\nsave_credentials: True\n" \
|
|
|
|
gdrive_secrets['client_secret'],
|
|
|
|
"save_credentials_backend: file\nsave_credentials_file: %(credential)s\n\n" \
|
|
|
|
gdrive_secrets['redirect_uris'][0]
|
|
|
|
"get_refresh_token: True\n\noauth_scope:\n" \
|
|
|
|
)
|
|
|
|
" - https://www.googleapis.com/auth/drive\n"
|
|
|
|
|
|
|
|
f.write(yaml % {'client_file': gdriveutils.CLIENT_SECRETS,
|
|
|
|
|
|
|
|
'client_id': filedata['web']['client_id'],
|
|
|
|
|
|
|
|
'client_secret': filedata['web']['client_secret'],
|
|
|
|
|
|
|
|
'redirect_uri': filedata['web']['redirect_uris'][0],
|
|
|
|
|
|
|
|
'credential': gdriveutils.CREDENTIALS})
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
flash(_(u'client_secrets.json is not configured for web application'), category="error")
|
|
|
|
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
|
|
|
|
gdriveError=gdriveError,
|
|
|
|
|
|
|
|
gfeature_support=feature_support, title=_(u"Basic Configuration"),
|
|
|
|
|
|
|
|
page="config")
|
|
|
|
|
|
|
|
# always show google drive settings, but in case of error deny support
|
|
|
|
# always show google drive settings, but in case of error deny support
|
|
|
|
if "config_use_google_drive" in to_save and not gdriveError:
|
|
|
|
config.config_use_google_drive = (not gdriveError) and ("config_use_google_drive" in to_save)
|
|
|
|
content.config_use_google_drive = "config_use_google_drive" in to_save
|
|
|
|
if _config_string("config_google_drive_folder"):
|
|
|
|
else:
|
|
|
|
gdriveutils.deleteDatabaseOnChange()
|
|
|
|
content.config_use_google_drive = 0
|
|
|
|
|
|
|
|
if "config_google_drive_folder" in to_save:
|
|
|
|
reboot_required |= _config_int("config_port")
|
|
|
|
if content.config_google_drive_folder != to_save["config_google_drive_folder"]:
|
|
|
|
|
|
|
|
content.config_google_drive_folder = to_save["config_google_drive_folder"]
|
|
|
|
reboot_required |= _config_string("config_keyfile")
|
|
|
|
deleteDatabaseOnChange()
|
|
|
|
if config.config_keyfile and not os.path.isfile(config.config_keyfile):
|
|
|
|
|
|
|
|
return _configuration_result('Keyfile location is not valid, please enter correct path', gdriveError)
|
|
|
|
if "config_port" in to_save:
|
|
|
|
|
|
|
|
if content.config_port != int(to_save["config_port"]):
|
|
|
|
reboot_required |= _config_string("config_certfile")
|
|
|
|
content.config_port = int(to_save["config_port"])
|
|
|
|
if config.config_certfile and not os.path.isfile(config.config_certfile):
|
|
|
|
reboot_required = True
|
|
|
|
return _configuration_result('Certfile location is not valid, please enter correct path', gdriveError)
|
|
|
|
if "config_keyfile" in to_save:
|
|
|
|
|
|
|
|
if content.config_keyfile != to_save["config_keyfile"]:
|
|
|
|
_config_checkbox_int("config_uploading")
|
|
|
|
if os.path.isfile(to_save["config_keyfile"]) or to_save["config_keyfile"] is u"":
|
|
|
|
_config_checkbox_int("config_anonbrowse")
|
|
|
|
content.config_keyfile = to_save["config_keyfile"]
|
|
|
|
_config_checkbox_int("config_public_reg")
|
|
|
|
reboot_required = True
|
|
|
|
|
|
|
|
else:
|
|
|
|
_config_int("config_ebookconverter")
|
|
|
|
ub.session.commit()
|
|
|
|
_config_string("config_calibre")
|
|
|
|
flash(_(u'Keyfile location is not valid, please enter correct path'), category="error")
|
|
|
|
_config_string("config_converterpath")
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
|
|
|
|
gdriveError=gdriveError,
|
|
|
|
if _config_int("config_login_type"):
|
|
|
|
feature_support=feature_support, title=_(u"Basic Configuration"),
|
|
|
|
reboot_required |= config.config_login_type != constants.LOGIN_STANDARD
|
|
|
|
page="config")
|
|
|
|
|
|
|
|
if "config_certfile" in to_save:
|
|
|
|
|
|
|
|
if content.config_certfile != to_save["config_certfile"]:
|
|
|
|
|
|
|
|
if os.path.isfile(to_save["config_certfile"]) or to_save["config_certfile"] is u"":
|
|
|
|
|
|
|
|
content.config_certfile = to_save["config_certfile"]
|
|
|
|
|
|
|
|
reboot_required = True
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
|
|
|
flash(_(u'Certfile 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_uploading = 0
|
|
|
|
|
|
|
|
content.config_anonbrowse = 0
|
|
|
|
|
|
|
|
content.config_public_reg = 0
|
|
|
|
|
|
|
|
if "config_uploading" in to_save and to_save["config_uploading"] == "on":
|
|
|
|
|
|
|
|
content.config_uploading = 1
|
|
|
|
|
|
|
|
if "config_anonbrowse" in to_save and to_save["config_anonbrowse"] == "on":
|
|
|
|
|
|
|
|
content.config_anonbrowse = 1
|
|
|
|
|
|
|
|
if "config_public_reg" in to_save and to_save["config_public_reg"] == "on":
|
|
|
|
|
|
|
|
content.config_public_reg = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if "config_converterpath" in to_save:
|
|
|
|
|
|
|
|
content.config_converterpath = to_save["config_converterpath"].strip()
|
|
|
|
|
|
|
|
if "config_calibre" in to_save:
|
|
|
|
|
|
|
|
content.config_calibre = to_save["config_calibre"].strip()
|
|
|
|
|
|
|
|
if "config_ebookconverter" in to_save:
|
|
|
|
|
|
|
|
content.config_ebookconverter = int(to_save["config_ebookconverter"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#LDAP configurator,
|
|
|
|
#LDAP configurator,
|
|
|
|
if "config_login_type" in to_save and to_save["config_login_type"] == "1":
|
|
|
|
if config.config_login_type == constants.LOGIN_LDAP:
|
|
|
|
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_string("config_ldap_provider_url")
|
|
|
|
ub.session.commit()
|
|
|
|
_config_int("config_ldap_port")
|
|
|
|
flash(_(u'Please enter a LDAP provider, port, DN and user object identifier'), category="error")
|
|
|
|
_config_string("config_ldap_schema")
|
|
|
|
return render_title_template("config_edit.html", content=config, origin=origin,
|
|
|
|
_config_string("config_ldap_dn")
|
|
|
|
gdrive=gdriveutils.gdrive_support, gdriveError=gdriveError,
|
|
|
|
_config_string("config_ldap_user_object")
|
|
|
|
feature_support=feature_support, title=_(u"Basic Configuration"),
|
|
|
|
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:
|
|
|
|
page="config")
|
|
|
|
return _configuration_result('Please enter a LDAP provider, port, DN and user object identifier', gdriveError)
|
|
|
|
elif not to_save["config_ldap_serv_username"] or not to_save["config_ldap_serv_password"]:
|
|
|
|
|
|
|
|
ub.session.commit()
|
|
|
|
_config_string("config_ldap_serv_username")
|
|
|
|
flash(_(u'Please enter a LDAP service account and password'), category="error")
|
|
|
|
if not config.config_ldap_serv_username or "config_ldap_serv_password" not in to_save:
|
|
|
|
return render_title_template("config_edit.html", content=config, origin=origin,
|
|
|
|
return _configuration_result('Please enter a LDAP service account and password', gdriveError)
|
|
|
|
gdrive=gdriveutils.gdrive_support, gdriveError=gdriveError,
|
|
|
|
config.set_from_dictionary(to_save, "config_ldap_serv_password", base64.b64encode)
|
|
|
|
feature_support=feature_support, title=_(u"Basic Configuration"),
|
|
|
|
|
|
|
|
page="config")
|
|
|
|
_config_checkbox("config_ldap_use_ssl")
|
|
|
|
else:
|
|
|
|
_config_checkbox("config_ldap_use_tls")
|
|
|
|
content.config_use_ldap = 1
|
|
|
|
_config_checkbox("config_ldap_openldap")
|
|
|
|
content.config_ldap_provider_url = to_save["config_ldap_provider_url"]
|
|
|
|
_config_checkbox("config_ldap_require_cert")
|
|
|
|
content.config_ldap_port = to_save["config_ldap_port"]
|
|
|
|
_config_string("config_ldap_cert_path")
|
|
|
|
content.config_ldap_schema = to_save["config_ldap_schema"]
|
|
|
|
if config.config_ldap_cert_path and not os.path.isfile(config.config_ldap_cert_path):
|
|
|
|
content.config_ldap_serv_username = to_save["config_ldap_serv_username"]
|
|
|
|
return _configuration_result('LDAP Certfile location is not valid, please enter correct path', gdriveError)
|
|
|
|
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
|
|
|
|
|
|
|
|
content.config_ldap_use_ssl = 0
|
|
|
|
|
|
|
|
content.config_ldap_use_tls = 0
|
|
|
|
|
|
|
|
content.config_ldap_require_cert = 0
|
|
|
|
|
|
|
|
content.config_ldap_openldap = 0
|
|
|
|
|
|
|
|
if "config_ldap_use_ssl" in to_save and to_save["config_ldap_use_ssl"] == "on":
|
|
|
|
|
|
|
|
content.config_ldap_use_ssl = 1
|
|
|
|
|
|
|
|
if "config_ldap_use_tls" in to_save and to_save["config_ldap_use_tls"] == "on":
|
|
|
|
|
|
|
|
content.config_ldap_use_tls = 1
|
|
|
|
|
|
|
|
if "config_ldap_require_cert" in to_save and to_save["config_ldap_require_cert"] == "on":
|
|
|
|
|
|
|
|
content.config_ldap_require_cert = 1
|
|
|
|
|
|
|
|
if "config_ldap_openldap" in to_save and to_save["config_ldap_openldap"] == "on":
|
|
|
|
|
|
|
|
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 "]:
|
|
|
|
|
|
|
|
if os.path.isfile(to_save["config_ldap_cert_path "]) or to_save["config_ldap_cert_path "] is u"":
|
|
|
|
|
|
|
|
content.config_certfile = to_save["config_ldap_cert_path "]
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
|
|
|
flash(_(u'Certfile location is not valid, please enter correct path'), category="error")
|
|
|
|
|
|
|
|
return render_title_template("config_edit.html", content=config, origin=origin,
|
|
|
|
|
|
|
|
gdrive=gdriveutils.gdrive_support, gdriveError=gdriveError,
|
|
|
|
|
|
|
|
feature_support=feature_support, title=_(u"Basic Configuration"),
|
|
|
|
|
|
|
|
page="config")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Remote login configuration
|
|
|
|
# Remote login configuration
|
|
|
|
content.config_remote_login = ("config_remote_login" in to_save and to_save["config_remote_login"] == "on")
|
|
|
|
_config_checkbox("config_remote_login")
|
|
|
|
if not content.config_remote_login:
|
|
|
|
if not config.config_remote_login:
|
|
|
|
ub.session.query(ub.RemoteAuthToken).delete()
|
|
|
|
ub.session.query(ub.RemoteAuthToken).delete()
|
|
|
|
|
|
|
|
|
|
|
|
# Goodreads configuration
|
|
|
|
# Goodreads configuration
|
|
|
|
content.config_use_goodreads = ("config_use_goodreads" in to_save and to_save["config_use_goodreads"] == "on")
|
|
|
|
_config_checkbox("config_use_goodreads")
|
|
|
|
if "config_goodreads_api_key" in to_save:
|
|
|
|
_config_string("config_goodreads_api_key")
|
|
|
|
content.config_goodreads_api_key = to_save["config_goodreads_api_key"]
|
|
|
|
_config_string("config_goodreads_api_secret")
|
|
|
|
if "config_goodreads_api_secret" in to_save:
|
|
|
|
if services.goodreads:
|
|
|
|
content.config_goodreads_api_secret = to_save["config_goodreads_api_secret"]
|
|
|
|
services.goodreads.connect(config.config_goodreads_api_key, config.config_goodreads_api_secret, config.config_use_goodreads)
|
|
|
|
if "config_updater" in to_save:
|
|
|
|
|
|
|
|
content.config_updatechannel = int(to_save["config_updater"])
|
|
|
|
_config_int("config_updatechannel")
|
|
|
|
|
|
|
|
|
|
|
|
# GitHub OAuth configuration
|
|
|
|
# GitHub OAuth configuration
|
|
|
|
if "config_login_type" in to_save and to_save["config_login_type"] == "2":
|
|
|
|
if config.config_login_type == constants.LOGIN_OAUTH_GITHUB:
|
|
|
|
if to_save["config_github_oauth_client_id"] == u'' or to_save["config_github_oauth_client_secret"] == u'':
|
|
|
|
_config_string("config_github_oauth_client_id")
|
|
|
|
ub.session.commit()
|
|
|
|
_config_string("config_github_oauth_client_secret")
|
|
|
|
flash(_(u'Please enter Github oauth credentials'), category="error")
|
|
|
|
if not config.config_github_oauth_client_id or not config.config_github_oauth_client_secret:
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
return _configuration_result('Please enter Github oauth credentials', gdriveError)
|
|
|
|
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
|
|
|
|
# Google OAuth configuration
|
|
|
|
if "config_login_type" in to_save and to_save["config_login_type"] == "3":
|
|
|
|
if config.config_login_type == constants.LOGIN_OAUTH_GOOGLE:
|
|
|
|
if to_save["config_google_oauth_client_id"] == u'' or to_save["config_google_oauth_client_secret"] == u'':
|
|
|
|
_config_string("config_google_oauth_client_id")
|
|
|
|
ub.session.commit()
|
|
|
|
_config_string("config_google_oauth_client_secret")
|
|
|
|
flash(_(u'Please enter Google oauth credentials'), category="error")
|
|
|
|
if not config.config_google_oauth_client_id or not config.config_google_oauth_client_secret:
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
return _configuration_result('Please enter Google oauth credentials', gdriveError)
|
|
|
|
gdriveError=gdriveError, feature_support=feature_support,
|
|
|
|
|
|
|
|
title=_(u"Basic Configuration"), page="config")
|
|
|
|
_config_int("config_log_level")
|
|
|
|
else:
|
|
|
|
_config_string("config_logfile")
|
|
|
|
content.config_login_type = constants.LOGIN_OAUTH_GOOGLE
|
|
|
|
if not logger.is_valid_logfile(config.config_logfile):
|
|
|
|
content.config_google_oauth_client_id = to_save["config_google_oauth_client_id"]
|
|
|
|
return _configuration_result('Logfile location is not valid, please enter correct path', gdriveError)
|
|
|
|
content.config_google_oauth_client_secret = to_save["config_google_oauth_client_secret"]
|
|
|
|
|
|
|
|
reboot_required = True
|
|
|
|
reboot_required |= _config_checkbox_int("config_access_log")
|
|
|
|
|
|
|
|
reboot_required |= _config_string("config_access_logfile")
|
|
|
|
if "config_login_type" in to_save and to_save["config_login_type"] == "0":
|
|
|
|
if not logger.is_valid_logfile(config.config_access_logfile):
|
|
|
|
content.config_login_type = constants.LOGIN_STANDARD
|
|
|
|
return _configuration_result('Access Logfile location is not valid, please enter correct path', gdriveError)
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
# Rarfile Content configuration
|
|
|
|
if "config_rarfile_location" in to_save and to_save['config_rarfile_location'] is not u"":
|
|
|
|
_config_string("config_rarfile_location")
|
|
|
|
check = check_unrar(to_save["config_rarfile_location"].strip())
|
|
|
|
unrar_status = helper.check_unrar(config.config_rarfile_location)
|
|
|
|
if not check[0] :
|
|
|
|
if unrar_status:
|
|
|
|
content.config_rarfile_location = to_save["config_rarfile_location"].strip()
|
|
|
|
return _configuration_result(unrar_status, gdriveError)
|
|
|
|
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:
|
|
|
|
try:
|
|
|
|
if content.config_use_google_drive and is_gdrive_ready() and not \
|
|
|
|
metadata_db = os.path.join(config.config_calibre_dir, "metadata.db")
|
|
|
|
os.path.exists(os.path.join(content.config_calibre_dir, "metadata.db")):
|
|
|
|
if config.config_use_google_drive and is_gdrive_ready() and not os.path.exists(metadata_db):
|
|
|
|
downloadFile(None, "metadata.db", config.config_calibre_dir + "/metadata.db")
|
|
|
|
gdriveutils.downloadFile(None, "metadata.db", metadata_db)
|
|
|
|
if db_change:
|
|
|
|
db_change = True
|
|
|
|
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:
|
|
|
|
except Exception as e:
|
|
|
|
flash(e, category="error")
|
|
|
|
return _configuration_result('%s' % e, gdriveError)
|
|
|
|
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:
|
|
|
|
if db_change:
|
|
|
|
reload(db)
|
|
|
|
# reload(db)
|
|
|
|
if not db.setup_db():
|
|
|
|
if not db.setup_db(config):
|
|
|
|
flash(_(u'DB location is not valid, please enter correct path'), category="error")
|
|
|
|
return _configuration_result('DB location is not valid, please enter correct path', gdriveError)
|
|
|
|
return render_title_template("config_edit.html", config=config, origin=origin,
|
|
|
|
|
|
|
|
gdriveError=gdriveError, feature_support=feature_support,
|
|
|
|
config.save()
|
|
|
|
title=_(u"Basic Configuration"), page="config")
|
|
|
|
flash(_(u"Calibre-Web configuration updated"), category="success")
|
|
|
|
if reboot_required:
|
|
|
|
if reboot_required:
|
|
|
|
# stop Server
|
|
|
|
|
|
|
|
web_server.stop(True)
|
|
|
|
web_server.stop(True)
|
|
|
|
log.info('Reboot required, restarting')
|
|
|
|
|
|
|
|
if origin:
|
|
|
|
return _configuration_result(None, gdriveError)
|
|
|
|
success = True
|
|
|
|
|
|
|
|
if is_gdrive_ready() and feature_support['gdrive'] is True and config.config_use_google_drive == True:
|
|
|
|
|
|
|
|
gdrivefolders = listRootFolders()
|
|
|
|
def _configuration_result(error_flash=None, gdriveError=None):
|
|
|
|
|
|
|
|
gdrive_authenticate = not is_gdrive_ready()
|
|
|
|
|
|
|
|
gdrivefolders = []
|
|
|
|
|
|
|
|
if gdriveError is None:
|
|
|
|
|
|
|
|
gdriveError = gdriveutils.get_error_text()
|
|
|
|
|
|
|
|
if gdriveError:
|
|
|
|
|
|
|
|
gdriveError = _(gdriveError)
|
|
|
|
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 +431,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,
|
|
|
@ -637,24 +478,35 @@ 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)
|
|
|
|
|
|
|
|
return render_title_template("email_edit.html", content=content, title=_(u"Edit e-mail server settings"),
|
|
|
|
|
|
|
|
page="mailset")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admi.route("/admin/mailsettings", methods=["POST"])
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
@admin_required
|
|
|
|
|
|
|
|
def update_mailsettings():
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
content.mail_server = to_save["mail_server"]
|
|
|
|
log.debug("update_mailsettings %r", to_save)
|
|
|
|
content.mail_port = int(to_save["mail_port"])
|
|
|
|
|
|
|
|
content.mail_login = to_save["mail_login"]
|
|
|
|
_config_string = lambda x: config.set_from_dictionary(to_save, x, lambda y: y.strip() if y else y)
|
|
|
|
content.mail_password = to_save["mail_password"]
|
|
|
|
_config_int = lambda x: config.set_from_dictionary(to_save, x, int)
|
|
|
|
content.mail_from = to_save["mail_from"]
|
|
|
|
|
|
|
|
content.mail_use_ssl = int(to_save["mail_use_ssl"])
|
|
|
|
_config_string("mail_server")
|
|
|
|
try:
|
|
|
|
_config_int("mail_port")
|
|
|
|
ub.session.commit()
|
|
|
|
_config_int("mail_use_ssl")
|
|
|
|
except Exception as e:
|
|
|
|
_config_string("mail_login")
|
|
|
|
flash(e, category="error")
|
|
|
|
_config_string("mail_password")
|
|
|
|
if "test" in to_save and to_save["test"]:
|
|
|
|
_config_string("mail_from")
|
|
|
|
|
|
|
|
config.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if to_save.get("test"):
|
|
|
|
if current_user.kindle_mail:
|
|
|
|
if current_user.kindle_mail:
|
|
|
|
result = send_test_mail(current_user.kindle_mail, current_user.nickname)
|
|
|
|
result = send_test_mail(current_user.kindle_mail, current_user.nickname)
|
|
|
|
if result is None:
|
|
|
|
if result is None:
|
|
|
@ -666,8 +518,8 @@ def edit_mailsettings():
|
|
|
|
flash(_(u"Please configure your kindle e-mail address first..."), category="error")
|
|
|
|
flash(_(u"Please configure your kindle e-mail address first..."), category="error")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
flash(_(u"E-mail server settings updated"), category="success")
|
|
|
|
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"),
|
|
|
|
|
|
|
|
page="mailset")
|
|
|
|
return edit_mailsettings()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admi.route("/admin/user/<int:user_id>", methods=["GET", "POST"])
|
|
|
|
@admi.route("/admin/user/<int:user_id>", methods=["GET", "POST"])
|
|
|
@ -703,53 +555,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
|
|
|
|