mirror of
https://github.com/pi-hole/web.git
synced 2026-04-27 04:04:00 +01:00
Add highlighting to tailLog.php
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
@@ -9,40 +9,48 @@
|
||||
require "password.php";
|
||||
if(!$auth) die("Not authorized");
|
||||
|
||||
function formatLine($line){
|
||||
if (strpos($line, "blacklisted") || strpos($line, "gravity blocked")) {
|
||||
$txt = '<b class="log-red">'.htmlspecialchars($line).'</b>';
|
||||
} elseif (strpos($line, "query[A") || strpos($line, "query[DHCP")) {
|
||||
$txt = '<b>'.htmlspecialchars($line).'</b>';
|
||||
} else {
|
||||
$txt = '<span class="text-muted">'.htmlspecialchars($line).'</span>';
|
||||
}
|
||||
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 (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 (!$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, htmlspecialchars(fgets($file)));
|
||||
die(json_encode(array("offset" => ftell($file), "lines" => $lines)));
|
||||
}
|
||||
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)));
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user