'.$txt.'';
} elseif (strpos($line, "query[A") || strpos($line, "query[DHCP")) {
$txt = ''.$txt.'';
} else {
$txt = ''.$txt.'';
}
return $txt;
}
// Not using SplFileObject here, since direct
// usage of f-streams will be much faster for
// files as large as the pihole.log
if (isset($_GET["FTL"])) {
$file = fopen("/var/log/pihole/FTL.log","r");
} else {
$file = fopen("/var/log/pihole/pihole.log","r");
}
if (!$file) {
die(json_encode(array("offset" => 0, "lines" => array("Failed to open log file. Check permissions!\n"))));
}
if (isset($_GET["offset"])) {
$offset = intval($_GET['offset']);
if ($offset > 0) {
// Seeks on the file pointer where we want to continue reading is known
fseek($file, $offset);
$lines = [];
while (!feof($file)) {
array_push($lines, formatLine(fgets($file)));
}
die(json_encode(array("offset" => ftell($file), "lines" => $lines)));
}
}
// Locate the current position of the file read/write pointer
fseek($file, -1, SEEK_END);
// Add one to skip the very last "\n" in the log file
die(json_encode(array("offset" => ftell($file)+1)));
?>