power-mailinabox/management/templates/system-status.html

218 lines
4.8 KiB
HTML

<h2>System Status Checks</h2>
<style>
#system-checks .message {
display: inline;
}
#system-checks .icon {
min-width: 2em;
}
#system-checks .heading {
font-weight: bold;
font-size: 180%;
padding-top: 1.75em;
}
#system-checks .heading.first {
border-top: none;
padding-top: 0;
}
.status-error .fas {
color: rgb(190, 0, 0);
}
.status-error.sym {
color: rgb(190, 0, 0);
}
.status-error .status-text {
color: rgb(70, 0, 0);
}
.status-warning .fas {
color: rgb(191, 150, 0);
}
.status-warning.sym {
color: rgb(191, 150, 0);
}
.status-warning .status-text {
color: rgb(69, 54, 0);
}
.status-ok .fas {
color: rgb(0, 190, 0);
}
.status-ok.sym {
color: rgb(0, 190, 0);
}
.status-ok .status-text {
color: rgb(0, 70, 0);
}
.status-na .fas {
color: rgb(100, 100, 100);
}
.status-na.sym {
color: rgb(100, 100, 100);
}
.status-na .status-text {
color: rgb(100, 100, 100);
}
div.extra {
display: none;
margin-top: 1em;
word-wrap: break-word;
}
#system-checks .showhide {
display: block;
font-size: 85%;
}
#system-checks .pre {
margin: 1em;
font-family: monospace;
white-space: pre-wrap;
}
</style>
<div id="system-reboot-required" style="display: none; margin-bottom: 1em;">
<button type="button" class="btn btn-danger" onclick="confirm_reboot(); return false;">Reboot Box</button>
<div>No reboot is necessary.</div>
</div>
<div id="system-privacy-setting" style="display: none">
<div><a onclick="return enable_privacy(!current_privacy_setting)" href="#"><span>Enable/Disable</span>
New-Version Check</a></div>
<p style="line-height: 125%"><small>(When enabled, status checks phone-home to check for a new release of
Mail-in-a-Box.)</small></p>
</div>
<div id="system-checks">
</div>
<script>
function show_system_status() {
$('#system-checks').html("")
api(
"/system/privacy",
"GET",
{},
function (r) {
current_privacy_setting = r;
$('#system-privacy-setting').show();
$('#system-privacy-setting a span').text(r ? "Enable" : "Disable");
$('#system-privacy-setting p').toggle(r);
});
api(
"/system/reboot",
"GET",
{},
function (r) {
$('#system-reboot-required').show(); // show when r becomes available
$('#system-reboot-required').find('button').toggle(r);
$('#system-reboot-required').find('div').toggle(!r);
});
api(
"/system/status",
"POST",
{},
function (r) {
for (let i = 0; i < r.length; i++) {
let n = $("<div class='col-12'><div class='icon'></div><p class='message status-text' style='margin: 0'/>");
if (i == 0) n.addClass('first')
if (r[i].type == "heading") {
n.addClass(r[i].type)
} else {
n.addClass("status-" + r[i].type)
n.find(".icon").addClass("fas")
}
if (r[i].type == "ok") n.find(".icon").addClass("fa-check")
if (r[i].type == "error") n.find(".icon").addClass("fa-times")
if (r[i].type == "warning") n.find(".icon").addClass("fa-exclamation-triangle")
n.find('p.status-text').text(r[i].text)
if (r[i].extra.length > 0) {
let open = false
n.append("<p class='showhide btn btn-light mt-3' href='#'>Show More</p><div class='extra ps-4 col-12'></div>")
n.find('.showhide').click(function () {
let extra = $(this).parent().find('.extra')
if (open) {
$(this).html("Show More");
extra.fadeOut();
} else {
$(this).html("Show Less");
extra.fadeIn();
}
open = !open
return false;
});
}
for (var j = 0; j < r[i].extra.length; j++) {
var m = $("<div/>").text(r[i].extra[j].text)
if (r[i].extra[j].monospace)
m.addClass("pre");
n.find('.extra').append(m);
}
$('#system-checks').append(n);
if (i < r.length - 1) {
$('#system-checks').append($("<hr>"));
}
}
})
}
var current_privacy_setting = null;
function enable_privacy(status) {
api(
"/system/privacy",
"POST",
{
value: (status ? "private" : "off")
},
function (res) {
show_system_status();
});
return false; // disable link
}
function confirm_reboot() {
show_modal_confirm(
"Reboot",
$("<p>This will reboot your Mail-in-a-Box <code>{{hostname}}</code>.</p> <p>Until the machine is fully restarted, your users will not be able to send and receive email, and you will not be able to connect to this control panel or with SSH. The reboot cannot be cancelled.</p>"),
"Reboot Now",
function () {
api(
"/system/reboot",
"POST",
{},
function (r) {
var msg = "<p>Please reload this page after a minute or so.</p>";
if (r) msg = "<p>The reboot command said:</p> <pre>" + $("<pre/>").text(r).html() + "</pre>"; // successful reboots don't produce any output; the output must be HTML-escaped
show_modal_error("Reboot", msg);
});
});
}
</script>