diff --git a/api.php b/api.php index 150dc9e2f..70dbc110c 100644 --- a/api.php +++ b/api.php @@ -70,7 +70,16 @@ } elseif (isset($_GET['disable'], $_GET['token']) && $auth) { check_csrf($_GET['token']); - exec('sudo pihole disable'); + $disable = intval($_GET['disable']); + // intval returns the integer value on success, or 0 on failure + if($disable > 0) + { + exec("sudo pihole disable ".$disable."s"); + } + else + { + exec('sudo pihole disable'); + } $data = array_merge($data, Array( "status" => "disabled" )); @@ -80,6 +89,10 @@ $data = array_merge($data, getGravity()); } + if (isset($_GET['tailLog'])) { + $data = array_merge($data, tailPiholeLog($_GET['tailLog'])); + } + function filterArray(&$inArray) { $outArray = array(); foreach ($inArray as $key=>$value) { diff --git a/data.php b/data.php index 5cc0fdfde..2e7ec3976 100644 --- a/data.php +++ b/data.php @@ -293,6 +293,33 @@ function getAllQueries($orderBy) { return $allQueries; } + function tailPiholeLog($param) { + // Not using SplFileObject here, since direct + // usage of f-streams will be much faster for + // files as large as the pihole.log + global $logListName; + $file = fopen($logListName,"r"); + $offset = intval($param); + 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)); + } + return ["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 + return ["offset" => ftell($file)+1]; + } + fclose($file); + } + /******** Private Members ********/ function gravityCount() { global $gravityListName,$blackListFile; diff --git a/header.php b/header.php index 391469679..d968902fd 100644 --- a/header.php +++ b/header.php @@ -314,55 +314,114 @@ +