/* 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 moment: false, apiFailure: false, utils: false, REFRESH_INTERVAL: false */
var nextID = 0;
var lastPID = -1;
// Maximum number of lines to display
const maxlines = 5000;
// Fade in new lines
const fadeIn = true;
// Mark new lines with a red line above them
const markUpdates = true;
// Format a line of the dnsmasq log
function formatLine(line) {
// Remove dnsmasq + PID
let txt = line.replaceAll(/ dnsmasq\[\d*]/g, "");
if (line.includes("denied") || line.includes("gravity blocked")) {
// Red bold text for blocked domains
txt = `${txt}`;
} else if (line.includes("query[A") || line.includes("query[DHCP")) {
// Bold text for initial query lines
txt = `${txt}`;
} else {
// Grey text for all other lines
txt = `${txt}`;
}
return txt;
}
// Function that asks the API for new data
function getData() {
// Only update when spinner is spinning
if (!$("#feed-icon").hasClass("fa-play")) {
utils.setTimer(getData, REFRESH_INTERVAL.logs);
return;
}
var GETDict = utils.parseQueryString();
if (!("file" in GETDict)) {
window.location.href += "?file=dnsmasq";
return;
}
$.ajax({
url: "/api/logs/" + GETDict.file + "?nextID=" + nextID,
timeout: 5000,
method: "GET",
})
.done(function (data) {
// Check if we have a new PID -> FTL was restarted
if (lastPID !== data.pid) {
if (lastPID !== -1) {
$("#output").append("*** FTL restarted ***
");
}
// Remember PID
lastPID = data.pid;
// Reset nextID
nextID = 0;
getData();
return;
}
// Set placeholder text if log file is empty and we have no new lines
if (data.log.length === 0) {
if (nextID === 0) {
$("#output").html("*** Log file is empty ***");
}
utils.setTimer(getData, REFRESH_INTERVAL.logs);
return;
}
// We have new lines
if (markUpdates && nextID > 0) {
// Add red fading out background to new lines
$("#output").append('