mirror of
https://github.com/pi-hole/web.git
synced 2025-12-24 04:38:28 +00:00
Merge pull request #1266 from pi-hole/new/diagnostics
Add new Pi-hole diagnostics system
This commit is contained in:
31
api_db.php
31
api_db.php
@@ -413,6 +413,37 @@ if (isset($_GET['getGraphData']) && $auth)
|
||||
$data = array_merge($data, $result);
|
||||
}
|
||||
|
||||
if (isset($_GET['status']))
|
||||
{
|
||||
$results = $db->query('SELECT COUNT(*) FROM message;');
|
||||
|
||||
if(!is_bool($results))
|
||||
$result = array('message_count' => $results->fetchArray()[0]);
|
||||
else
|
||||
$result = array();
|
||||
|
||||
$data = array_merge($data, $result);
|
||||
}
|
||||
|
||||
if(isset($_GET["messages"]) && $auth)
|
||||
{
|
||||
$messages = array();
|
||||
$results = $db->query('SELECT * FROM message');
|
||||
|
||||
while($results !== false && $res = $results->fetchArray(SQLITE3_ASSOC))
|
||||
{
|
||||
// Convert string to to UTF-8 encoding to ensure php-json can handle it.
|
||||
// Furthermore, convert special characters to HTML entities to prevent XSS attacks.
|
||||
foreach ($res as $key => $value) {
|
||||
if (is_string($value))
|
||||
$res[$key] = htmlspecialchars(utf8_encode($value));
|
||||
}
|
||||
array_push($messages, $res);
|
||||
}
|
||||
|
||||
$data = array_merge($data, array('messages' => $messages));
|
||||
}
|
||||
|
||||
if(isset($_GET["jsonForceObject"]))
|
||||
{
|
||||
echo json_encode($data, JSON_FORCE_OBJECT);
|
||||
|
||||
49
messages.php
Normal file
49
messages.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php /*
|
||||
* Pi-hole: A black hole for Internet advertisements
|
||||
* (c) 2020 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. */
|
||||
require "scripts/pi-hole/php/header.php";
|
||||
?>
|
||||
|
||||
<!-- Title -->
|
||||
<div class="page-header">
|
||||
<h1>Pi-hole diagnosis</h1>
|
||||
<small>On this page, you can see messages from your Pi-hole concerning possible issues.</small>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="box" id="messages-list">
|
||||
<!-- /.box-header -->
|
||||
<div class="box-body">
|
||||
<table id="messagesTable" class="display table table-striped table-bordered" cellspacing="0" width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Time</th>
|
||||
<th>Type</th>
|
||||
<th>Message</th>
|
||||
<th>Data1</th>
|
||||
<th>Data2</th>
|
||||
<th>Data3</th>
|
||||
<th>Data4</th>
|
||||
<th>Data5</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
</div>
|
||||
<!-- /.box -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="scripts/pi-hole/js/groups-common.js"></script>
|
||||
<script src="scripts/pi-hole/js/messages.js"></script>
|
||||
|
||||
<?php
|
||||
require "scripts/pi-hole/php/footer.php";
|
||||
?>
|
||||
@@ -93,6 +93,23 @@ 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("d-none");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
var enaT = $("#enableTimer");
|
||||
var target = new Date(parseInt(enaT.html()));
|
||||
@@ -111,6 +128,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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
127
scripts/pi-hole/js/messages.js
Normal file
127
scripts/pi-hole/js/messages.js
Normal file
@@ -0,0 +1,127 @@
|
||||
/* 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 token = $("#token").text();
|
||||
|
||||
function render_timestamp(data, type) {
|
||||
// Display and search content
|
||||
if (type === "display" || type === "filter") {
|
||||
return utils.datetime(data);
|
||||
}
|
||||
|
||||
// Sorting content
|
||||
return data;
|
||||
}
|
||||
|
||||
function multline(input) {
|
||||
return input.split(",").join("\n");
|
||||
}
|
||||
|
||||
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>"
|
||||
);
|
||||
|
||||
case "SUBNET":
|
||||
return (
|
||||
"Client <code>" +
|
||||
row.message +
|
||||
"</code> is managed by " +
|
||||
row.blob1 +
|
||||
" groups (database IDs [" +
|
||||
row.blob3 +
|
||||
"]):<pre>" +
|
||||
multline(row.blob2) +
|
||||
"</pre>" +
|
||||
"FTL chose the most recent entry <pre>" +
|
||||
row.blob4 +
|
||||
"</pre> to get the group configuration for this client."
|
||||
);
|
||||
|
||||
default:
|
||||
return "Unknown message type<pre>" + JSON.stringify(row) + "</pre>";
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#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 (Object.prototype.hasOwnProperty.call(hiddenCols, key)) {
|
||||
data.columns[hiddenCols[key]].visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply loaded state to table
|
||||
return data;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -271,6 +271,12 @@ if($auth) {
|
||||
</a>
|
||||
<div class="navbar-custom-menu">
|
||||
<ul class="nav navbar-nav">
|
||||
<li id="pihole-diagnosis" class="d-none">
|
||||
<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> Pi-hole diagnosis
|
||||
</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> Network
|
||||
</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
|
||||
|
||||
@@ -275,3 +275,7 @@
|
||||
.input-group-addon {
|
||||
padding: 0 12px;
|
||||
}
|
||||
|
||||
.d-none {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user