1
0
mirror of https://github.com/janeczku/calibre-web.git synced 2024-11-28 08:58:41 +02:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Ozzieisaacs 2020-04-05 17:31:47 +02:00
commit a194216568
6 changed files with 53 additions and 28 deletions

View File

@ -17,6 +17,9 @@ Steps to reproduce the behavior:
3. Scroll down to '....' 3. Scroll down to '....'
4. See error 4. See error
**Logfile**
Add content of calibre-web.log file or the relevant error, try to reproduce your problem with "debug" log-level to get more output.
**Expected behavior** **Expected behavior**
A clear and concise description of what you expected to happen. A clear and concise description of what you expected to happen.

View File

@ -79,12 +79,12 @@ 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())
showtext = {}
if task in (0, 1): # valid commandos received if task in (0, 1): # valid commandos received
# close all database connections # close all database connections
db.dispose() db.dispose()
ub.dispose() ub.dispose()
showtext = {}
if task == 0: if task == 0:
showtext['text'] = _(u'Server restarted, please reload page') showtext['text'] = _(u'Server restarted, please reload page')
else: else:
@ -96,9 +96,11 @@ def shutdown():
if task == 2: if task == 2:
log.warning("reconnecting to calibre database") log.warning("reconnecting to calibre database")
db.setup_db(config) db.setup_db(config)
return '{}' showtext['text'] = _(u'Reconnect successful')
return json.dumps(showtext)
abort(404) showtext['text'] = _(u'Unknown command')
return json.dumps(showtext), 400
@admi.route("/admin/view") @admi.route("/admin/view")

File diff suppressed because one or more lines are too long

View File

@ -76,7 +76,7 @@ $(function() {
function cleanUp() { function cleanUp() {
clearInterval(updateTimerID); clearInterval(updateTimerID);
$("#spinner2").hide(); $("#spinner2").hide();
$("#updateFinished").removeClass("hidden"); $("#DialogFinished").removeClass("hidden");
$("#check_for_update").removeClass("hidden"); $("#check_for_update").removeClass("hidden");
$("#perform_update").addClass("hidden"); $("#perform_update").addClass("hidden");
$("#message").alert("close"); $("#message").alert("close");
@ -93,13 +93,13 @@ $(function() {
url: window.location.pathname + "/../../get_updater_status", url: window.location.pathname + "/../../get_updater_status",
success: function success(data) { success: function success(data) {
// console.log(data.status); // console.log(data.status);
$("#Updatecontent").html(updateText[data.status]); $("#DialogContent").html(updateText[data.status]);
if (data.status > 6) { if (data.status > 6) {
cleanUp(); cleanUp();
} }
}, },
error: function error() { error: function error() {
$("#Updatecontent").html(updateText[7]); $("#DialogContent").html(updateText[7]);
cleanUp(); cleanUp();
}, },
timeout: 2000 timeout: 2000
@ -158,8 +158,8 @@ $(function() {
var $this = $(this); var $this = $(this);
var buttonText = $this.html(); var buttonText = $this.html();
$this.html("..."); $this.html("...");
$("#Updatecontent").html(""); $("#DialogContent").html("");
$("#updateFinished").addClass("hidden"); $("#DialogFinished").addClass("hidden");
$("#update_error").addClass("hidden"); $("#update_error").addClass("hidden");
if ($("#message").length) { if ($("#message").length) {
$("#message").alert("close"); $("#message").alert("close");
@ -201,13 +201,24 @@ $(function() {
}); });
}); });
$("#restart_database").click(function() { $("#restart_database").click(function() {
$("#DialogHeader").addClass("hidden");
$("#DialogFinished").addClass("hidden");
$("#DialogContent").html("");
$("#spinner2").show();
$.ajax({ $.ajax({
dataType: "json", dataType: "json",
url: window.location.pathname + "/../../shutdown", url: window.location.pathname + "/../../shutdown",
data: {"parameter":2} data: {"parameter":2},
success: function success(data) {
$("#spinner2").hide();
ResultText = data.text;
$("#DialogContent").html(ResultText);
$("#DialogFinished").removeClass("hidden");
}
}); });
}); });
$("#perform_update").click(function() { $("#perform_update").click(function() {
$("#DialogHeader").removeClass("hidden");
$("#spinner2").show(); $("#spinner2").show();
$.ajax({ $.ajax({
type: "POST", type: "POST",
@ -216,7 +227,7 @@ $(function() {
url: window.location.pathname + "/../../get_updater_status", url: window.location.pathname + "/../../get_updater_status",
success: function success(data) { success: function success(data) {
updateText = data.text; updateText = data.text;
$("#Updatecontent").html(updateText[data.status]); $("#DialogContent").html(updateText[data.status]);
// console.log(data.status); // console.log(data.status);
updateTimerID = setInterval(updateTimer, 2000); updateTimerID = setInterval(updateTimer, 2000);
} }
@ -288,17 +299,23 @@ $(function() {
}); });
$('#import_ldap_users').click(function() { $('#import_ldap_users').click(function() {
$("#DialogHeader").addClass("hidden");
$("#DialogFinished").addClass("hidden");
$("#DialogContent").html("");
$("#spinner2").show();
var pathname = document.getElementsByTagName("script"), src = pathname[pathname.length - 1].src; var pathname = document.getElementsByTagName("script"), src = pathname[pathname.length - 1].src;
var path = src.substring(0, src.lastIndexOf("/")); var path = src.substring(0, src.lastIndexOf("/"));
/*$.ajax({ $.ajax({
method:"get", method:"get",
dataType: "json",
url: path + "/../../import_ldap_users", url: path + "/../../import_ldap_users",
});*/ success: function success(data) {
$.getJSON(path + "/../../import_ldap_users", $("#spinner2").hide();
function(data) { ResultText = data.text;
location.reload(); $("#DialogContent").html(ResultText);
$("#DialogFinished").removeClass("hidden");
} }
); });
}); });
$(".author-expand").click(function() { $(".author-expand").click(function() {

View File

@ -38,7 +38,7 @@
{% if not (config.config_login_type == 1) %} {% if not (config.config_login_type == 1) %}
<div class="btn btn-default" id="admin_new_user"><a href="{{url_for('admin.new_user')}}">{{_('Add New User')}}</a></div> <div class="btn btn-default" id="admin_new_user"><a href="{{url_for('admin.new_user')}}">{{_('Add New User')}}</a></div>
{% else %} {% else %}
<div class="btn btn-default" id="import_ldap_users">{{_('Import LDAP Users')}}</div> <div class="btn btn-default" id="import_ldap_users" data-toggle="modal" data-target="#StatusDialog">{{_('Import LDAP Users')}}</div>
<!--a href="#" id="import_ldap_users" name="import_ldap_users"><button type="submit" class="btn btn-default">{{_('Import LDAP Users')}}</button></a--> <!--a href="#" id="import_ldap_users" name="import_ldap_users"><button type="submit" class="btn btn-default">{{_('Import LDAP Users')}}</button></a-->
{% endif %} {% endif %}
</div> </div>
@ -125,7 +125,7 @@
<div class="col"> <div class="col">
<h2>{{_('Administration')}}</h2> <h2>{{_('Administration')}}</h2>
<div class="btn btn-default"><a id="logfile" href="{{url_for('admin.view_logfile')}}">{{_('View Logs')}}</a></div> <div class="btn btn-default"><a id="logfile" href="{{url_for('admin.view_logfile')}}">{{_('View Logs')}}</a></div>
<div class="btn btn-default" id="restart_database">{{_('Reconnect Calibre Database')}}</div> <div class="btn btn-default" id="restart_database" data-toggle="modal" data-target="#StatusDialog">{{_('Reconnect Calibre Database')}}</div>
<div class="btn btn-default" id="admin_restart" data-toggle="modal" data-target="#RestartDialog">{{_('Restart')}}</div> <div class="btn btn-default" id="admin_restart" data-toggle="modal" data-target="#RestartDialog">{{_('Restart')}}</div>
<div class="btn btn-default" id="admin_stop" data-toggle="modal" data-target="#ShutdownDialog">{{_('Shutdown')}}</div> <div class="btn btn-default" id="admin_stop" data-toggle="modal" data-target="#ShutdownDialog">{{_('Shutdown')}}</div>
</div> </div>
@ -151,7 +151,7 @@
<div class="hidden" id="update_error"> <span>{{update_error}}</span></div> <div class="hidden" id="update_error"> <span>{{update_error}}</span></div>
<div class="btn btn-default" id="check_for_update">{{_('Check for Update')}}</div> <div class="btn btn-default" id="check_for_update">{{_('Check for Update')}}</div>
<div class="btn btn-default hidden" id="perform_update" data-toggle="modal" data-target="#UpdateprogressDialog">{{_('Perform Update')}}</div> <div class="btn btn-default hidden" id="perform_update" data-toggle="modal" data-target="#StatusDialog">{{_('Perform Update')}}</div>
</div> </div>
</div> </div>
</div> </div>
@ -188,21 +188,21 @@
</div> </div>
</div> </div>
</div> </div>
<div id="UpdateprogressDialog" class="modal fade" role="dialog"> <div id="StatusDialog" class="modal fade" role="dialog">
<div class="modal-dialog modal-sm"> <div class="modal-dialog modal-sm">
<!-- Modal content--> <!-- Modal content-->
<div class="modal-content"> <div class="modal-content">
<div class="modal-header bg-info text-center"> <div class="modal-header bg-info text-center">
<span>{{_('Updating, please do not reload this page')}}</span> <span id="DialogHeader">{{_('Updating, please do not reload this page')}}</span>
</div> </div>
<div class="modal-body text-center"> <div class="modal-body text-center">
<div id="spinner2" class="spinner2" style="display:none;"> <div id="spinner2" class="spinner2" style="display:none;">
<img id="img-spinner2" src="{{ url_for('static', filename='css/libs/images/loading-icon.gif') }}"/> <img id="img-spinner2" src="{{ url_for('static', filename='css/libs/images/loading-icon.gif') }}"/>
</div> </div>
<p></p> <p></p>
<div id="Updatecontent"></div> <div id="DialogContent"></div>
<p></p> <p></p>
<button type="button" class="btn btn-default hidden" id="updateFinished" data-dismiss="modal">{{_('OK')}}</button> <button type="button" class="btn btn-default hidden" id="DialogFinished" data-dismiss="modal">{{_('OK')}}</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -275,13 +275,13 @@ def before_request():
@app.route('/import_ldap_users') @app.route('/import_ldap_users')
def import_ldap_users(): def import_ldap_users():
showtext = {}
try: try:
new_users = services.ldap.get_group_members(config.config_ldap_group_name) new_users = services.ldap.get_group_members(config.config_ldap_group_name)
except services.ldap.LDAPException as e: except services.ldap.LDAPException as e:
log.debug(e) log.debug(e)
return "" showtext['text'] = _(u'Error : %(ldaperror)s', ldaperror=e)
except Exception as e: return json.dumps(showtext)
print('pass')
for username in new_users: for username in new_users:
user_data = services.ldap.get_object_details(user=username, group=None, query_filter=None, dn_only=False) user_data = services.ldap.get_object_details(user=username, group=None, query_filter=None, dn_only=False)
@ -300,7 +300,10 @@ def import_ldap_users():
except Exception as e: except Exception as e:
log.warning("Failed to create LDAP user: %s - %s", username, e) log.warning("Failed to create LDAP user: %s - %s", username, e)
ub.session.rollback() ub.session.rollback()
return "" showtext['text'] = _(u'Failed to create at least one LDAP user')
if not showtext:
showtext['text'] = _(u'User successfully imported')
return json.dumps(showtext)
# ################################### data provider functions ######################################################### # ################################### data provider functions #########################################################