Implemented tailLog into FTL API

This commit is contained in:
DL6ER
2017-02-23 15:03:53 +01:00
parent a6a4c944b0
commit 874ec8c9db
2 changed files with 27 additions and 2 deletions

View File

@@ -249,6 +249,31 @@ elseif (isset($_GET['disable'], $_GET['token']) && $auth) {
$data = array_merge($data, array("status" => "disabled"));
}
if (isset($_GET['tailLog']) && $auth) {
// Not using SplFileObject here, since direct
// usage of f-streams will be much faster for
// files as large as the pihole.log
$file = fopen("/var/log/pihole.log","r");
$offset = intval($_GET['tailLog']);
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,fgets($file));
$data = array_merge($data, array("offset" => ftell($file), "lines" => $lines));
}
else
{
// 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
$data = array_merge($data, array("offset" => ftell($file)+1));
}
fclose($file);
}
if(isset($_GET["recentBlocked"]))
{
sendRequestFTL("recentBlocked");