mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
Change pihole status in api_FTL.php (#2059)
Using "pihole status web" info Signed-off-by: rdwebdesign <github@rdwebdesign.com.br>
This commit is contained in:
@@ -19,28 +19,7 @@ $data = array();
|
||||
|
||||
// Common API functions
|
||||
if (isset($_GET['status'])) {
|
||||
// Receive the return of "pihole status web"
|
||||
$pistatus = pihole_execute('status web');
|
||||
|
||||
if (isset($pistatus[0])) {
|
||||
$pistatus = intval($pistatus[0]);
|
||||
} else {
|
||||
// If no response, status="Unknown" (-2)
|
||||
$pistatus = -2;
|
||||
}
|
||||
|
||||
switch ($pistatus) {
|
||||
case -2: // Unkown
|
||||
case -1: // DNS service not running"
|
||||
case 0: // Offline
|
||||
$data = array_merge($data, array("status" => "disabled"));
|
||||
break;
|
||||
|
||||
default:
|
||||
// DNS service on port $returncode
|
||||
$data = array_merge($data, array("status" => "enabled"));
|
||||
}
|
||||
|
||||
$data = array_merge($data, array("status" => piholeStatusAPI()));
|
||||
} elseif (isset($_GET['enable']) && $auth) {
|
||||
if(isset($_GET["auth"]))
|
||||
{
|
||||
|
||||
+7
-6
@@ -29,21 +29,22 @@ else
|
||||
$data["version"] = 3;
|
||||
}
|
||||
|
||||
if (isset($_GET['summary']) || isset($_GET['summaryRaw']) || !count($_GET))
|
||||
{
|
||||
if (isset($_GET['summary']) || isset($_GET['summaryRaw']) || !count($_GET)) {
|
||||
require_once("scripts/pi-hole/php/gravity.php");
|
||||
sendRequestFTL("stats");
|
||||
$return = getResponseFTL();
|
||||
|
||||
$stats = [];
|
||||
foreach($return as $line)
|
||||
{
|
||||
foreach($return as $line) {
|
||||
$tmp = explode(" ",$line);
|
||||
|
||||
if(($tmp[0] === "domains_being_blocked" && !is_numeric($tmp[1])) || $tmp[0] === "status")
|
||||
if($tmp[0] === "domains_being_blocked" && !is_numeric($tmp[1])) {
|
||||
$stats[$tmp[0]] = $tmp[1]; // Expect string response
|
||||
else
|
||||
} elseif ($tmp[0] === "status") {
|
||||
$stats[$tmp[0]] = piholeStatusAPI();
|
||||
} else {
|
||||
$stats[$tmp[0]] = floatval($tmp[1]); // Expect float response
|
||||
}
|
||||
}
|
||||
$stats['gravity_last_updated'] = gravity_last_update(true);
|
||||
$data = array_merge($data,$stats);
|
||||
|
||||
@@ -483,4 +483,31 @@ function getQueryTypeStr($querytype)
|
||||
return "TYPE".($qtype - 100);
|
||||
}
|
||||
|
||||
// Returns an integer representing pihole blocking status
|
||||
function piholeStatus()
|
||||
{
|
||||
// Receive the return of "pihole status web"
|
||||
$pistatus = pihole_execute('status web');
|
||||
return isset($pistatus[0]) ? intval($pistatus[0]) : -2;
|
||||
}
|
||||
|
||||
// Returns pihole status, using only valid API responses (enabled/disabled)
|
||||
function piholeStatusAPI()
|
||||
{
|
||||
// Receive the return of "pihole status web"
|
||||
$pistatus = piholeStatus();
|
||||
|
||||
switch ($pistatus) {
|
||||
case -2: // Unkown
|
||||
case -1: // DNS service not running"
|
||||
case 0: // Offline
|
||||
$response = "disabled";
|
||||
break;
|
||||
|
||||
default:
|
||||
// DNS service running on port $returncode
|
||||
$response = "enabled";
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user