diff --git a/messages.php b/messages.php index 4fc0abf3..7f07a6fc 100644 --- a/messages.php +++ b/messages.php @@ -30,16 +30,11 @@ require 'scripts/pi-hole/php/header_authenticated.php'; Time Type Message - Data1 - Data2 - Data3 - Data4 - Data5   -

Note: If errors are shown, you can generate a debug log, which will do a thorough Pi-hole evaluation.

+

Note: If errors are shown, you generate a debug log (use pihole -d), which will do a thorough Pi-hole evaluation.

diff --git a/scripts/pi-hole/js/messages.js b/scripts/pi-hole/js/messages.js index ee49085b..dc952d34 100644 --- a/scripts/pi-hole/js/messages.js +++ b/scripts/pi-hole/js/messages.js @@ -19,141 +19,19 @@ function renderTimestamp(data, type) { return data; } -function multiline(input) { - return input.split(",").join("\n"); -} - -function renderMessage(data, type, row) { - // Display and search content - switch (row.type) { - case "REGEX": - return ( - 'Encountered an error when processing ' + - row.blob1 + - " regex filter with ID " + - row.blob3 + - ":
" +
-        row.blob2 +
-        "
Error message:
" +
-        row.message +
-        "
" - ); - - case "SUBNET": - return ( - "Client " + - row.message + - " is managed by " + - row.blob1 + - " groups (database IDs [" + - row.blob3 + - "]):
" +
-        multiline(row.blob2) +
-        "
" + - "FTL chose the most recent entry
" +
-        row.blob4 +
-        "
to get the group configuration for this client." - ); - - case "HOSTNAME": - // eslint-disable-next-line unicorn/no-new-array - var hint = new Array(row.blob2 + row.message.length + 3).join(" "); - return ( - "Hostname contains invalid character " + - decodeURIComponent(escape(row.blob1))[row.blob2] + - ":
" +
-        hint +
-        "↓\n" +
-        row.message +
-        ": " +
-        decodeURIComponent(escape(row.blob1)) +
-        "\n" +
-        hint +
-        "↑
" - ); - - case "DNSMASQ_CONFIG": - return "FTL failed to start due to " + row.message; - - case "RATE_LIMIT": - return ( - "Client " + - row.message + - " has been rate-limited (current config allows up to " + - parseInt(row.blob1, 10) + - " queries in " + - parseInt(row.blob2, 10) + - " seconds)" - ); - - case "DNSMASQ_WARN": - return ( - "Warning in dnsmasq core:
" +
-        row.message +
-        '
Check out our documentation for further information.' - ); - - case "LOAD": - return ( - "Long-term load (15min avg) larger than number of processors: " + - parseFloat(row.blob1).toFixed(1) + - " > " + - parseInt(row.blob2, 10) + - "
This may slow down DNS resolution and can cause bottlenecks." - ); - - case "SHMEM": - return ( - "RAM shortage (" + - utils.escapeHtml(row.message) + - ") ahead: " + - parseInt(row.blob1, 10) + - "% used
" +
-        utils.escapeHtml(row.blob2) +
-        "
" - ); - - case "DISK": - return ( - "Disk shortage (" + - utils.escapeHtml(row.message) + - ") ahead: " + - parseInt(row.blob1, 10) + - "% used
" +
-        utils.escapeHtml(row.blob2) +
-        "
" - ); - - case "ADLIST": - return ( - '' + - "Adlist with ID " + - parseInt(row.blob1, 10) + - " was inaccessible during last gravity run." + - "
" +
-        utils.escapeHtml(row.message) +
-        "
" - ); - - default: - return "Unknown message type
" + JSON.stringify(row) + "
"; - } +function htmlPass(data, type) { + return data; } $(function () { - return; var ignoreNonfatal = localStorage ? localStorage.getItem("hideNonfatalDnsmasqWarnings_chkbox") === "true" : false; + var url = "/api/info/messages" + (ignoreNonfatal ? "?filter_dnsmasq_warnings=true" : ""); table = $("#messagesTable").DataTable({ ajax: { - url: "api_db.php?messages" + (ignoreNonfatal ? "&ignore=DNSMASQ_WARN" : ""), - data: { token: token }, - type: "POST", + url: url, + type: "GET", dataSrc: "messages", }, order: [[0, "asc"]], @@ -162,12 +40,7 @@ $(function () { { data: null, visible: true, width: "15px" }, { data: "timestamp", width: "8%", render: renderTimestamp }, { data: "type", width: "8%" }, - { data: "message", orderable: false, render: renderMessage }, - { data: "blob1", visible: false }, - { data: "blob2", visible: false }, - { data: "blob3", visible: false }, - { data: "blob4", visible: false }, - { data: "blob5", visible: false }, + { data: "html", orderable: false, render: htmlPass }, { data: null, width: "22px", orderable: false }, ], columnDefs: [ @@ -275,13 +148,8 @@ $(function () { return null; } - // Reset visibility of ID and blob columns - var hiddenCols = [0, 5, 6, 7, 8, 9]; - for (var key in hiddenCols) { - if (Object.prototype.hasOwnProperty.call(hiddenCols, key)) { - data.columns[hiddenCols[key]].visible = false; - } - } + // Reset visibility of ID column + data.columns[0].visible = false; // Apply loaded state to table return data; @@ -325,42 +193,37 @@ $.fn.dataTable.Buttons.defaults.dom.container.className = "dt-buttons"; function deleteMessage() { // Passes the button data-del-id attribute as ID var ids = [parseInt($(this).attr("data-del-id"), 10)]; - delMsg(ids); -} -function delMsg(ids) { // Check input validity if (!Array.isArray(ids)) return; // Exploit prevention: Return early for non-numeric IDs for (var id in ids) { if (Object.hasOwnProperty.call(ids, id) && typeof ids[id] !== "number") return; + delMsg(ids); } +} + +function delMsg(id) { utils.disableAll(); - var idstring = ids.join(", "); - utils.showAlert("info", "", "Deleting message(s)..."); + utils.showAlert("info", "", "Deleting message..."); $.ajax({ - url: "scripts/pi-hole/php/message.php", - method: "post", - dataType: "json", - data: { action: "delete_message", id: JSON.stringify(ids), token: token }, + url: "/api/info/messages/" + id, + method: "DELETE" }) .done(function (response) { utils.enableAll(); - if (response.success) { - utils.showAlert("success", "far fa-trash-alt", "Successfully deleted message(s)", ""); - for (var id in ids) { - if (Object.hasOwnProperty.call(ids, id)) { - table.row(id).remove().draw(false).ajax.reload(null, false); - } - } + console.log(response); + if (response === undefined) { + utils.showAlert("success", "far fa-trash-alt", "Successfully deleted message", ""); + table.row(id).remove().draw(false).ajax.reload(null, false); } else { utils.showAlert( "error", "", - "Error while deleting message(s): " + idstring, + "Error while deleting message: " + id, response.message ); } @@ -377,7 +240,7 @@ function delMsg(ids) { utils.showAlert( "error", "", - "Error while deleting message(s): " + idstring, + "Error while deleting message: " + id, jqXHR.responseText ); console.log(exception); // eslint-disable-line no-console diff --git a/scripts/pi-hole/js/utils.js b/scripts/pi-hole/js/utils.js index 5235e8fe..fac36809 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -361,20 +361,21 @@ function colorBar(percentage, total, cssClass) { } function checkMessages() { - return; var ignoreNonfatal = localStorage ? localStorage.getItem("hideNonfatalDnsmasqWarnings_chkbox") === "true" : false; - $.getJSON("api_db.php?status" + (ignoreNonfatal ? "&ignore=DNSMASQ_WARN" : ""), function (data) { - if ("message_count" in data && data.message_count > 0) { + var url = "/api/info/messages" + (ignoreNonfatal ? "?filter_dnsmasq_warnings=true" : ""); + $.getJSON(url, function (data) { + console.log(data); + if (data.messages.length > 0) { var more = '\nAccess "Tools/Pi-hole diganosis" for further details.'; var title = - data.message_count > 1 - ? "There are " + data.message_count + " warnings." + more + data.messages.length > 1 + ? "There are " + data.messages.length + " warnings." + more : "There is one warning." + more; $(".warning-count").prop("title", title); - $(".warning-count").text(data.message_count); + $(".warning-count").text(data.messages.length); $(".warning-count").removeClass("hidden"); } else { $(".warning-count").addClass("hidden");