Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions Pihole/Pihole.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -56,10 +58,12 @@ public function livestats()
if ($version == 6) {
$results = $this->getInfo();

$data["ads_blocked"] = $results["queries"];
$data["ads_percentage"] = $results["percent"];
if ($results["valid"]) {
$data["ads_blocked"] = $results["queries"];
$data["ads_percentage"] = $results["percent"];

$status = "active";
$status = "active";
}
}
return parent::getLiveStats($status, $data);
}
Expand Down Expand Up @@ -106,10 +110,21 @@ 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]),
Expand Down Expand Up @@ -142,8 +157,14 @@ 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);

if (!$auth->session->valid) {
$queriesblocked = 0;
$percentblocked = 0;
} else {
$queriesblocked = $datasummary->queries->blocked;
$percentblocked = round($datasummary->queries->percent_blocked, 2);
}

$data = [
'valid' => $valid,
Expand Down
2 changes: 1 addition & 1 deletion Pihole/config.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="items">
<input type="hidden" data-config="dataonly" class="config-item" name="config[dataonly]" value="1" />
<div class="input">
<label>{{ strtoupper(__('app.url')) }} (for v6 use https)</label>
<label>{{ strtoupper(__('app.url')) }}</label>
{!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
</div>
<div class="input">
Expand Down