diff --git a/Pihole/Pihole.php b/Pihole/Pihole.php index fb74979b5f..f0e8e2bc93 100644 --- a/Pihole/Pihole.php +++ b/Pihole/Pihole.php @@ -29,12 +29,14 @@ public function test() if ($test["valid"]) { echo "Successfully communicated with the API"; } else { - echo "Error while communicating with the API"; + echo "Error while communicating with the API: " . $test["message"]; } } } public function livestats() { + $data = []; + $status = "inactive"; $version = $this->config->version; if ($version == 5) { @@ -48,12 +50,6 @@ public function livestats() $details->ads_percentage_today, 1 ); - $data["gravity"] = number_format( - $details->domains_being_blocked, - 0, - '', - '.' - ); $status = "active"; } @@ -62,11 +58,12 @@ public function livestats() if ($version == 6) { $results = $this->getInfo(); - $data["ads_blocked"] = $results["queries"]; - $data["ads_percentage"] = $results["percent"]; - $data["gravity"] = $results["gravity"]; + if ($results["valid"]) { + $data["ads_blocked"] = $results["queries"]; + $data["ads_percentage"] = $results["percent"]; - $status = "active"; + $status = "active"; + } } return parent::getLiveStats($status, $data); } @@ -113,10 +110,23 @@ public function getInfo() ]; } - // Create session and retreave data + // Create session and retrieve data $response = parent::execute($this->url("api/auth"), $attrs, null, "POST"); $auth = json_decode($response->getBody()); + if (!$auth->session->valid) { + + $data = [ + 'valid' => false, + 'validity' => -1, + 'message' => $auth->session->message, + 'queries' => 0, + 'percent' => 0 + ]; + + return $data; + } + if ($ignoreTls) { $attrsid = [ "body" => json_encode(['sid' => $auth->session->sid]), @@ -149,17 +159,21 @@ public function getInfo() $valid = $auth->session->valid; $validity = $auth->session->validity; $message = $auth->session->message; - $queriesblocked = $datasummary->queries->blocked; - $percentblocked = round($datasummary->queries->percent_blocked, 2); - $gravity = number_format($datasummary->gravity->domains_being_blocked, 0, '', '.'); + + if (!$auth->session->valid) { + $queriesblocked = 0; + $percentblocked = 0; + } else { + $queriesblocked = $datasummary->queries->blocked; + $percentblocked = round($datasummary->queries->percent_blocked, 2); + } $data = [ 'valid' => $valid, 'validity' => $validity, 'message' => $message, 'queries' => $queriesblocked, - 'percent' => $percentblocked, - 'gravity' => $gravity + 'percent' => $percentblocked ]; return $data; } diff --git a/Pihole/config.blade.php b/Pihole/config.blade.php index 8b289559dc..3d8eff4bea 100644 --- a/Pihole/config.blade.php +++ b/Pihole/config.blade.php @@ -2,7 +2,7 @@
- + {!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}