Add new Pi-hole diagnostics page.

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2020-05-11 01:00:59 +02:00
committed by XhmikosR
parent 7d409ad76c
commit b0f54f5451
7 changed files with 228 additions and 14 deletions

View File

@@ -93,6 +93,22 @@ function piholeChange(action, duration) {
}
}
function check_messages() {
$.getJSON("api_db.php?status", function(data) {
if ("message_count" in data && data.message_count > 0) {
var title;
if (data.message_count > 1) {
title = "There are " + data.message_count + " warnings. Click for further details.";
} else {
title = "There is one warning. Click for further details.";
}
$("#pihole-diagnosis").prop("title", title);
$("#pihole-diagnosis-count").text(data.message_count);
$("#pihole-diagnosis").removeClass("hidden");
}
});
}
$(document).ready(function () {
var enaT = $("#enableTimer");
var target = new Date(parseInt(enaT.html()));
@@ -111,6 +127,10 @@ $(document).ready(function () {
radioClass: "iradio_" + checkbox_theme,
increaseArea: "20%"
});
// Run check immediately after page loading ...
check_messages();
// ... and once again with five seconds delay
setTimeout(check_messages, 5000);
});
// Handle Enable/Disable

View File

@@ -68,7 +68,7 @@ function showAlert(type, icon, title, message) {
}
function datetime(date) {
return moment.unix(Math.floor(date)).format("Y-MM-DD HH:mm:ss z");
return moment.unix(Math.floor(date)).format("Y-MM-DD [<br class='hidden-lg'>]HH:mm:ss z");
}
function disableAll() {

View File

@@ -0,0 +1,98 @@
/* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
/* global utils:false */
var table;
var token = $("#token").html();
function render_timestamp(data, type) {
// Display and search content
if (type === "display" || type === "filter") {
return utils.datetime(data);
}
// Sorting content
return data;
}
function render_message(data, type, row) {
// Display and search content
switch (row["type"]) {
case "REGEX":
return "Encountered an error when processing <a href=\"groups-domains.php?domainid=" + row["blob3"] + "\">" + row["blob1"] + " regex filter with ID " + row["blob3"] + "</a>:<pre>"+row["blob2"]+"</pre>Error message: <pre>"+row["message"]+"</pre>";
default:
return "Unknown message type<pre>" + JSON.stringify(row) + "</pre>";
}
return data;
}
$(document).ready(function() {
table = $("#messagesTable").DataTable({
ajax: {
url: "api_db.php?messages",
data: { token: token },
type: "POST",
dataSrc: "messages"
},
order: [[0, "asc"]],
columns: [
{ data: "id", visible: false },
{ data: "timestamp",
width: "8%",
render: render_timestamp
},
{ data: "type", width: "8%" },
{ data: "message", orderable: false, render: render_message },
{ data: "blob1", visible: false },
{ data: "blob2", visible: false },
{ data: "blob3", visible: false },
{ data: "blob4", visible: false },
{ data: "blob5", visible: false },
],
dom:
"<'row'<'col-sm-4'l><'col-sm-8'f>>" +
"<'row'<'col-sm-12'<'table-responsive'tr>>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
lengthMenu: [
[10, 25, 50, 100, -1],
[10, 25, 50, 100, "All"]
],
language: {
emptyTable: "No issues found."
},
stateSave: true,
stateSaveCallback: function(settings, data) {
// Store current state in client's local storage area
localStorage.setItem("messages-table", JSON.stringify(data));
},
stateLoadCallback: function() {
// Receive previous state from client's local storage area
var data = localStorage.getItem("messages-table");
// Return if not available
if (data === null) {
return null;
}
// Parse loaded data
data = JSON.parse(data);
// Always start on the first page to show most recent queries
data.start = 0;
// Always start with empty search field
data.search.search = "";
// Reset visibility of ID and blob columns
var hiddenCols = [0,4,5,6,7,8];
for (var key in hiddenCols) {
if (hiddenCols.hasOwnProperty(key)) {
data.columns[hiddenCols[key]].visible = false;
}
}
// Apply loaded state to table
return data;
}
});
});

View File

@@ -271,6 +271,12 @@ if($auth) {
</a>
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
<li id="pihole-diagnosis" class="hidden">
<a href="messages.php">
<i class="fa fa-exclamation-triangle"></i>
<span class="label label-warning" id="pihole-diagnosis-count"></span>
</a>
</li>
<li>
<a style="pointer-events:none;">
<span class="hidden-xs hidden-sm">hostname:</span>
@@ -487,6 +493,12 @@ if($auth) {
<i class="fa fa-ban"></i> <span>Blacklist</span>
</a>
</li>
<!-- Local DNS Records -->
<li<?php if($scriptname === "dns_records.php"){ ?> class="active"<?php } ?>>
<a href="dns_records.php">
<i class="fa fa-address-book"></i> <span>Local DNS Records</span>
</a>
</li>
<!-- Group Management -->
<li class="treeview<?php if(in_array($scriptname, array("groups.php", "groups-clients.php", "groups-domains.php", "groups-adlists.php"))){ ?> active<?php } ?>">
<a href="#">
@@ -564,7 +576,7 @@ if($auth) {
</a>
</li>
<!-- Tools -->
<li class="treeview<?php if(in_array($scriptname, array("gravity.php", "queryads.php", "auditlog.php", "taillog.php", "taillog-FTL.php", "debug.php"))){ ?> active<?php } ?>">
<li class="treeview<?php if(in_array($scriptname, array("messages.php", "gravity.php", "queryads.php", "auditlog.php", "taillog.php", "taillog-FTL.php", "debug.php", "network.php"))){ ?> active<?php } ?>">
<a href="#">
<i class="fa fa-folder"></i> <span>Tools</span>
<span class="pull-right-container">
@@ -572,6 +584,12 @@ if($auth) {
</span>
</a>
<ul class="treeview-menu">
<!-- Pi-hole diagnosis -->
<li<?php if($scriptname === "messages.php"){ ?> class="active"<?php } ?>>
<a href="messages.php">
<i class="fa fa-stethoscope"></i> <span>Pi-hole diagnosis</span>
</a>
</li>
<!-- Run gravity.sh -->
<li<?php if($scriptname === "gravity.php"){ ?> class="active"<?php } ?>>
<a href="gravity.php">
@@ -608,26 +626,20 @@ if($auth) {
<i class="fa fa-ambulance"></i> Generate debug log
</a>
</li>
<!-- Network -->
<li<?php if($scriptname === "network.php"){ ?> class="active"<?php } ?>>
<a href="network.php">
<i class="fa fa-network-wired"></i> <span>Network</span>
</a>
</li>
</ul>
</li>
<!-- Network -->
<li<?php if($scriptname === "network.php"){ ?> class="active"<?php } ?>>
<a href="network.php">
<i class="fa fa-network-wired"></i> <span>Network</span>
</a>
</li>
<!-- Settings -->
<li<?php if($scriptname === "settings.php"){ ?> class="active"<?php } ?>>
<a href="settings.php">
<i class="fa fa-cogs"></i> <span>Settings</span>
</a>
</li>
<!-- Local DNS Records -->
<li<?php if($scriptname === "dns_records.php"){ ?> class="active"<?php } ?>>
<a href="dns_records.php">
<i class="fa fa-address-book"></i> <span>Local DNS Records</span>
</a>
</li>
<!-- Logout -->
<?php
// Show Logout button if $auth is set and authorization is required