1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-26 01:50:31 +00:00

Final fix for #86 (reverse proxy error)

renamed admin_user to admin
added configuration infos inm admin panel
This commit is contained in:
OzzieIsaacs 2017-01-02 18:52:33 +01:00
parent 0bcdbc4a82
commit 453d04b566
6 changed files with 61 additions and 32 deletions

4
cps.py
View File

@ -20,10 +20,6 @@ from tornado.ioloop import IOLoop
global title_sort global title_sort
def title_sort(title):
return title
def start_calibreweb(messagequeue): def start_calibreweb(messagequeue):
web.global_queue = messagequeue web.global_queue = messagequeue
if config.DEVELOPMENT: if config.DEVELOPMENT:

View File

@ -1,7 +1,7 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% block body %} {% block body %}
<div class="discover"> <div class="discover">
<h2>{{title}}</h2> <h2>{{_('User list')}}</h2>
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<th>{{_('Nickname')}}</th> <th>{{_('Nickname')}}</th>
@ -52,5 +52,29 @@
<div class="btn btn-default"><a href="{{url_for('edit_mailsettings')}}">{{_('Change SMTP settings')}}</a></div> <div class="btn btn-default"><a href="{{url_for('edit_mailsettings')}}">{{_('Change SMTP settings')}}</a></div>
<h2>{{_('Configuration')}}</h2>
<table class="table table-striped">
<tr>
<th>{{_('Log File')}}</th>
<th>{{_('Log Level')}}</th>
<th>{{_('Port')}}</th>
<th>{{_('Books per page')}}</th>
<th>{{_('Uploading')}}</th>
<th>{{_('Public registration')}}</th>
<th>{{_('Anonymous browsing')}}</th>
</tr>
<tr>
<td>{{config.LOG_DIR}}</td>
<td>{{config.LOG_DIR}}</td>
<td>{{config.PORT}}</td>
<td>{{config.NEWEST_BOOKS}}</td>
<td>{% if config.UPLOADING %}<span class="glyphicon glyphicon-ok"></span>{% else %}<span class="glyphicon glyphicon-remove"></span>{% endif %}</td>
<td>{% if config.PUBLIC_REG %}<span class="glyphicon glyphicon-ok"></span>{% else %}<span class="glyphicon glyphicon-remove"></span>{% endif %}</td>
<td>{% if config.ANON_BROWSE %}<span class="glyphicon glyphicon-ok"></span>{% else %}<span class="glyphicon glyphicon-remove"></span>{% endif %}</td>
</table>
<h2>{{_('Administration')}}</h2>
{% if not config.DEVELOPMENT %}
<div class="btn btn-default"><a href="{{url_for('shutdown')}}">{{_('Restart Calibre-web')}}</a></div>
{% endif %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -29,7 +29,7 @@
</div> </div>
<button type="submit" name="submit" value="submit" class="btn btn-default">{{_('Save settings')}}</button> <button type="submit" name="submit" value="submit" class="btn btn-default">{{_('Save settings')}}</button>
<button type="submit" name="test" value="test" class="btn btn-default">{{_('Save settings and send Test E-Mail')}}</button> <button type="submit" name="test" value="test" class="btn btn-default">{{_('Save settings and send Test E-Mail')}}</button>
<a href="{{ url_for('user_list') }}" class="btn btn-default">{{_('Back')}}</a> <a href="{{ url_for('admin') }}" class="btn btn-default">{{_('Back')}}</a>
</form> </form>
</div> </div>

View File

@ -81,15 +81,15 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if g.user.role_admin() %} {% if g.user.role_admin() %}
<li><a href="{{url_for('user_list')}}"><span class="glyphicon glyphicon-dashboard"></span> {{_('Admin')}}</a></li> <li><a href="{{url_for('admin')}}"><span class="glyphicon glyphicon-dashboard"></span> {{_('Admin')}}</a></li>
{% endif %} {% endif %}
<li><a href="{{url_for('profile')}}"><span class="glyphicon glyphicon-user"></span> {{g.user.nickname}}</a></li> <li><a href="{{url_for('profile')}}"><span class="glyphicon glyphicon-user"></span> {{g.user.nickname}}</a></li>
{% if not g.user.is_anonymous() %} {% if not g.user.is_anonymous() %}
<li><a href="{{url_for('logout', next='%s%s' % (request.script_root, request.path))}}"><span class="glyphicon glyphicon-log-out"></span> {{_('Logout')}}</a></li> <li><a href="{{url_for('logout')}}"><span class="glyphicon glyphicon-log-out"></span> {{_('Logout')}}</a></li>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if g.allow_registration and not g.user.is_authenticated %} {% if g.allow_registration and not g.user.is_authenticated %}
<li><a href="{{url_for('login', next='%s%s' % (request.script_root, request.path))}}"><span class="glyphicon glyphicon-log-in"></span> {{_('Login')}}</a></li> <li><a href="{{url_for('login')}}"><span class="glyphicon glyphicon-log-in"></span> {{_('Login')}}</a></li>
<li><a href="{{url_for('register')}}"><span class="glyphicon glyphicon-user"></span> {{_('Register')}}</a></li> <li><a href="{{url_for('register')}}"><span class="glyphicon glyphicon-user"></span> {{_('Register')}}</a></li>
{% endif %} {% endif %}
</ul> </ul>

View File

@ -93,7 +93,7 @@
{% endif %} {% endif %}
<button type="submit" class="btn btn-default">{{_('Submit')}}</button> <button type="submit" class="btn btn-default">{{_('Submit')}}</button>
{% if not profile %} {% if not profile %}
<a href="{{ url_for('user_list') }}" class="btn btn-default">{{_('Back')}}</a> <a href="{{ url_for('admin') }}" class="btn btn-default">{{_('Back')}}</a>
{% endif %} {% endif %}
</form> </form>

View File

@ -809,7 +809,7 @@ def series(name, page):
title=_(u"Series: %(serie)s", serie=name)) title=_(u"Series: %(serie)s", serie=name))
else: else:
flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error") flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error")
return redirect('/' or url_for("index", _external=True)) return redirect(url_for("index"))
@app.route("/language") @app.route("/language")
@ -905,13 +905,13 @@ def show_book(id):
return render_template('detail.html', entry=entries, cc=cc, title=entries.title, books_shelfs=book_in_shelfs) return render_template('detail.html', entry=entries, cc=cc, title=entries.title, books_shelfs=book_in_shelfs)
else: else:
flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error") flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error")
return redirect('/' or url_for("index", _external=True)) return redirect(url_for("index"))
@app.route("/admin/") @app.route("/admin")
@login_required @login_required
def admin(): def admin_forbidden():
# return "Admin ONLY!" return "Admin ONLY!"
abort(403) abort(403)
@ -938,11 +938,11 @@ def stats():
@app.route("/shutdown") @app.route("/shutdown")
def shutdown(): def shutdown():
logout_user() # logout_user()
# add restart command to queue # add restart command to queue
global_queue.put("something") global_queue.put("something")
flash(_(u"Server restarts"), category="info") flash(_(u"Server restarts"), category="info")
return redirect('/' or url_for("index", _external=True)) return redirect(url_for("index", _external=True))
@app.route("/search", methods=["GET"]) @app.route("/search", methods=["GET"])
@ -1100,7 +1100,7 @@ def read_book(book_id, format):
else: else:
flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error") flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error")
return redirect('/' or url_for("index", _external=True)) return redirect(url_for("index"))
@app.route("/download/<int:book_id>/<format>") @app.route("/download/<int:book_id>/<format>")
@ -1133,7 +1133,7 @@ def register():
if not config.PUBLIC_REG: if not config.PUBLIC_REG:
abort(404) abort(404)
if current_user is not None and current_user.is_authenticated: if current_user is not None and current_user.is_authenticated:
return redirect(url_for('index', _external=True)) return redirect(url_for('index'))
if request.method == "POST": if request.method == "POST":
to_save = request.form.to_dict() to_save = request.form.to_dict()
@ -1157,7 +1157,7 @@ def register():
flash(_(u"An unknown error occured. Please try again later."), category="error") flash(_(u"An unknown error occured. Please try again later."), category="error")
return render_template('register.html', title="register") return render_template('register.html', title="register")
flash("Your account has been created. Please login.", category="success") flash("Your account has been created. Please login.", category="success")
return redirect(url_for('login', _external=True)) return redirect(url_for('login'))
else: else:
flash(_(u"This username or email address is already in use."), category="error") flash(_(u"This username or email address is already in use."), category="error")
return render_template('register.html', title="register") return render_template('register.html', title="register")
@ -1170,7 +1170,7 @@ def login():
error = None error = None
if current_user is not None and current_user.is_authenticated: if current_user is not None and current_user.is_authenticated:
return redirect(url_for('index', _external=True)) return redirect(url_for('index'))
if request.method == "POST": if request.method == "POST":
form = request.form.to_dict() form = request.form.to_dict()
@ -1179,7 +1179,8 @@ def login():
if user and check_password_hash(user.password, form['password']): if user and check_password_hash(user.password, form['password']):
login_user(user, remember=True) login_user(user, remember=True)
flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname), category="success") flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname), category="success")
return redirect('/' or url_for("index", _external=True)) # test=
return redirect(url_for("index"))
else: else:
flash(_(u"Wrong Username or Password"), category="error") flash(_(u"Wrong Username or Password"), category="error")
@ -1191,7 +1192,7 @@ def login():
def logout(): def logout():
if current_user is not None and current_user.is_authenticated: if current_user is not None and current_user.is_authenticated:
logout_user() logout_user()
return redirect('/login' or url_for("login", _external=True)) return redirect(url_for('login'))
@app.route('/send/<int:book_id>') @app.route('/send/<int:book_id>')
@ -1220,7 +1221,7 @@ def add_to_shelf(shelf_id, book_id):
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first() shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first()
if not shelf.is_public and not shelf.user_id == int(current_user.id): if not shelf.is_public and not shelf.user_id == int(current_user.id):
flash("Sorry you are not allowed to add a book to the the shelf: %s" % shelf.name) flash("Sorry you are not allowed to add a book to the the shelf: %s" % shelf.name)
return redirect(url_for('index', _external=True)) return redirect(url_for('index'))
maxO = ub.session.query(func.max(ub.BookShelf.order)).filter(ub.BookShelf.shelf == shelf_id).first() maxO = ub.session.query(func.max(ub.BookShelf.order)).filter(ub.BookShelf.shelf == shelf_id).first()
if maxO[0] is None: if maxO[0] is None:
maxOrder = 0 maxOrder = 0
@ -1435,13 +1436,21 @@ def profile():
downloads=downloads, title=_(u"%(name)s's profile", name=current_user.nickname)) downloads=downloads, title=_(u"%(name)s's profile", name=current_user.nickname))
@app.route("/admin/user") @app.route("/admin/view")
@login_required @login_required
@admin_required @admin_required
def user_list(): def admin():
content = ub.session.query(ub.User).all() content = ub.session.query(ub.User).all()
settings = ub.session.query(ub.Settings).first() settings = ub.session.query(ub.Settings).first()
return render_template("user_list.html", content=content, email=settings, title=_(u"User list")) return render_template("admin.html", content=content, email=settings, config=config, title=_(u"Admin page"))
@app.route("/admin/config")
@login_required
@admin_required
def configuration():
content = ub.session.query(ub.User).all()
settings = ub.session.query(ub.Settings).first()
return render_template("admin.html", content=content, email=settings, config=config, title=_(u"Admin page"))
@app.route("/admin/user/new", methods=["GET", "POST"]) @app.route("/admin/user/new", methods=["GET", "POST"])
@ -1456,7 +1465,7 @@ def new_user():
lang.name = cur_l.get_language_name(get_locale()) lang.name = cur_l.get_language_name(get_locale())
except: except:
lang.name = _(isoLanguages.get(part3=lang.lang_code).name) lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
translations = babel.list_translations() + [LC('en')] translations = [LC('en')] + babel.list_translations()
if request.method == "POST": if request.method == "POST":
to_save = request.form.to_dict() to_save = request.form.to_dict()
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"]:
@ -1495,7 +1504,7 @@ def new_user():
ub.session.add(content) ub.session.add(content)
ub.session.commit() ub.session.commit()
flash(_("User '%(user)s' created", user=content.nickname), category="success") flash(_("User '%(user)s' created", user=content.nickname), category="success")
return redirect(url_for('user_list', _external=True)) return redirect(url_for('admin', _external=True))
except IntegrityError: except IntegrityError:
ub.session.rollback() ub.session.rollback()
flash(_(u"Found an existing account for this email address or nickname."), category="error") flash(_(u"Found an existing account for this email address or nickname."), category="error")
@ -1503,7 +1512,7 @@ def new_user():
languages=languages, title="Add new user") languages=languages, title="Add new user")
@app.route("/admin/user/mailsettings", methods=["GET", "POST"]) @app.route("/admin/mailsettings", methods=["GET", "POST"])
@login_required @login_required
@admin_required @admin_required
def edit_mailsettings(): def edit_mailsettings():
@ -1557,7 +1566,7 @@ def edit_user(user_id):
if "delete" in to_save: if "delete" in to_save:
ub.session.delete(content) ub.session.delete(content)
flash(_(u"User '%(nick)s' deleted", nick=content.nickname), category="success") flash(_(u"User '%(nick)s' deleted", nick=content.nickname), category="success")
return redirect(url_for('user_list', _external=True)) return redirect(url_for('admin', _external=True))
else: else:
if to_save["password"]: if to_save["password"]:
content.password = generate_password_hash(to_save["password"]) content.password = generate_password_hash(to_save["password"])
@ -1825,7 +1834,7 @@ def edit_book(book_id):
return render_template('edit_book.html', book=book, authors=author_names, cc=cc) return render_template('edit_book.html', book=book, authors=author_names, cc=cc)
else: else:
flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error") flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error")
return redirect('/' or url_for("index", _external=True)) return redirect(url_for("index", _external=True))
@app.route("/upload", methods=["GET", "POST"]) @app.route("/upload", methods=["GET", "POST"])