Skip to content

Commit

Permalink
Fix api.php?status ( replicate #2031 and pi-hole/pi-hole#4485) (#2052)
Browse files Browse the repository at this point in the history
* Replicating changes made by other PRs

(#2031 and pi-hole/pi-hole#4485)

Signed-off-by: rdwebdesign <github@rdwebdesign.com.br>

* Use the same messages used in #2031

Signed-off-by: rdwebdesign <github@rdwebdesign.com.br>

* Keep the old responses to avoid break things

Signed-off-by: rdwebdesign <github@rdwebdesign.com.br>

* More comments less variables

Signed-off-by: rdwebdesign <github@rdwebdesign.com.br>
  • Loading branch information
rdwebdesign committed Jan 6, 2022
1 parent 031f839 commit 7bb82d0
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,30 @@
$data = array();

// Common API functions
if (isset($_GET['status']))
{
$pistatus = pihole_execute('status web');
if(isset($pistatus[0]))
{
$pistatus = $pistatus[0];
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;
}
else
{
$pistatus = null;

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"));
}
if ($pistatus === "1")
{
$data = array_merge($data, array("status" => "enabled"));
}
else
{
$data = array_merge($data, array("status" => "disabled"));
}
}
elseif (isset($_GET['enable']) && $auth)
{

} elseif (isset($_GET['enable']) && $auth) {
if(isset($_GET["auth"]))
{
if($_GET["auth"] !== $pwhash)
Expand Down Expand Up @@ -165,12 +167,9 @@
require("api_FTL.php");

header('Content-type: application/json');
if(isset($_GET["jsonForceObject"]))
{
echo json_encode($data, JSON_FORCE_OBJECT);
}
else
{
echo json_encode($data);
if(isset($_GET["jsonForceObject"])) {
echo json_encode($data, JSON_FORCE_OBJECT);
} else {
echo json_encode($data);
}
?>

0 comments on commit 7bb82d0

Please sign in to comment.