1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-10-31 15:16:20 +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
def title_sort(title):
return title
def start_calibreweb(messagequeue):
web.global_queue = messagequeue
if config.DEVELOPMENT:

View File

@ -1,7 +1,7 @@
{% extends "layout.html" %}
{% block body %}
<div class="discover">
<h2>{{title}}</h2>
<h2>{{_('User list')}}</h2>
<table class="table table-striped">
<tr>
<th>{{_('Nickname')}}</th>
@ -52,5 +52,29 @@
<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>
{% endblock %}

View File

@ -29,7 +29,7 @@
</div>
<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>
<a href="{{ url_for('user_list') }}" class="btn btn-default">{{_('Back')}}</a>
<a href="{{ url_for('admin') }}" class="btn btn-default">{{_('Back')}}</a>
</form>
</div>

View File

@ -81,15 +81,15 @@
{% endif %}
{% endif %}
{% 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 %}
<li><a href="{{url_for('profile')}}"><span class="glyphicon glyphicon-user"></span> {{g.user.nickname}}</a></li>
{% 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 %}
{% 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>
{% endif %}
</ul>

View File

@ -93,7 +93,7 @@
{% endif %}
<button type="submit" class="btn btn-default">{{_('Submit')}}</button>
{% 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 %}
</form>

View File

@ -809,7 +809,7 @@ def series(name, page):
title=_(u"Series: %(serie)s", serie=name))
else:
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")
@ -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)
else:
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
def admin():
# return "Admin ONLY!"
def admin_forbidden():
return "Admin ONLY!"
abort(403)
@ -938,11 +938,11 @@ def stats():
@app.route("/shutdown")
def shutdown():
logout_user()
# logout_user()
# add restart command to queue
global_queue.put("something")
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"])
@ -1100,7 +1100,7 @@ def read_book(book_id, format):
else:
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>")
@ -1133,7 +1133,7 @@ def register():
if not config.PUBLIC_REG:
abort(404)
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":
to_save = request.form.to_dict()
@ -1157,7 +1157,7 @@ def register():
flash(_(u"An unknown error occured. Please try again later."), category="error")
return render_template('register.html', title="register")
flash("Your account has been created. Please login.", category="success")
return redirect(url_for('login', _external=True))
return redirect(url_for('login'))
else:
flash(_(u"This username or email address is already in use."), category="error")
return render_template('register.html', title="register")
@ -1170,7 +1170,7 @@ def login():
error = None
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":
form = request.form.to_dict()
@ -1179,7 +1179,8 @@ def login():
if user and check_password_hash(user.password, form['password']):
login_user(user, remember=True)
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:
flash(_(u"Wrong Username or Password"), category="error")
@ -1191,7 +1192,7 @@ def login():
def logout():
if current_user is not None and current_user.is_authenticated:
logout_user()
return redirect('/login' or url_for("login", _external=True))
return redirect(url_for('login'))
@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()
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)
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()
if maxO[0] is None:
maxOrder = 0
@ -1435,13 +1436,21 @@ def profile():
downloads=downloads, title=_(u"%(name)s's profile", name=current_user.nickname))
@app.route("/admin/user")
@app.route("/admin/view")
@login_required
@admin_required
def user_list():
def admin():
content = ub.session.query(ub.User).all()
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"])
@ -1456,7 +1465,7 @@ def new_user():
lang.name = cur_l.get_language_name(get_locale())
except:
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":
to_save = request.form.to_dict()
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.commit()
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:
ub.session.rollback()
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")
@app.route("/admin/user/mailsettings", methods=["GET", "POST"])
@app.route("/admin/mailsettings", methods=["GET", "POST"])
@login_required
@admin_required
def edit_mailsettings():
@ -1557,7 +1566,7 @@ def edit_user(user_id):
if "delete" in to_save:
ub.session.delete(content)
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:
if 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)
else:
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"])