Skip to content

Commit

Permalink
add support to skip tls verification
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroBuffon committed Sep 28, 2024
1 parent 66a4866 commit 069779f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 28 deletions.
64 changes: 48 additions & 16 deletions Pihole/Pihole.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,53 @@ public function url($endpoint)

public function getInfo()
{
$attrs = [
"body" => json_encode(['password' => $this->config->apikey]),
"cookies" => $this->jar,
"headers" => [
"Content-Type" => "application/json",
"Accept" => "application/json",
],
];
$ignoreTls = $this->getConfigValue("ignore_tls", false);
if ($ignoreTls) {
$attrs = [
"body" => json_encode(['password' => $this->config->apikey]),
"cookies" => $this->jar,
"verify" => false,
"headers" => [
"Content-Type" => "application/json",
"Accept" => "application/json",
],
];
$attrsid["verify"] = false;
} else {
$attrs = [
"body" => json_encode(['password' => $this->config->apikey]),
"cookies" => $this->jar,
"headers" => [
"Content-Type" => "application/json",
"Accept" => "application/json",
],
];
}

// Create session and retreave data
$response = parent::execute($this->url("api/auth"), $attrs, null, "POST");
$auth = json_decode($response->getBody());

$attrsid = [
"body" => json_encode(['sid' => $auth->session->sid]),
"cookies" => $this->jar,
"headers" => [
"Content-Type" => "application/json",
"Accept" => "application/json",
],
];
if ($ignoreTls) {
$attrsid = [
"body" => json_encode(['sid' => $auth->session->sid]),
"cookies" => $this->jar,
"verify" => false,
"headers" => [
"Content-Type" => "application/json",
"Accept" => "application/json",
],
];
} else {
$attrsid = [
"body" => json_encode(['sid' => $auth->session->sid]),
"cookies" => $this->jar,
"headers" => [
"Content-Type" => "application/json",
"Accept" => "application/json",
],
];
}

// Get queries data
$responsesummary = parent::execute($this->url("api/stats/summary"), $attrsid, null, "GET");
Expand All @@ -137,4 +163,10 @@ public function getInfo()
];
return $data;
}
public function getConfigValue($key, $default = null)
{
return isset($this->config) && isset($this->config->$key)
? $this->config->$key
: $default;
}
}
41 changes: 29 additions & 12 deletions Pihole/config.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,41 @@
<div class="items">
<input type="hidden" data-config="dataonly" class="config-item" name="config[dataonly]" value="1" />
<div class="input">
<label>{{ strtoupper(__('app.url')) }}</label>
<label>{{ strtoupper(__('app.url')) }} (for v6 use https)</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">
<label>Api Key(v5)/App Password(v6)</label>
{!! Form::text('config[apikey]', isset($item) && property_exists($item->getconfig(), 'apikey') ? $item->getconfig()->apikey : null, ['placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item']) !!}
</div>
<div class="items">
<div class="input">
<label>Version</label>
{!! Form::select(
'config[version]',
['5' => 'v5', '6' => 'v6'],
isset($item) ? $item->getconfig()->version : null,
['data-config' => 'version', 'class' => 'form-control config-item'],
) !!}
</div>
</div>
<div class="items" style="max-width: 100px;">
<div class="input">
<label>Version</label>
{!! Form::select(
'config[version]',
['5' => 'v5', '6' => 'v6'],
isset($item) ? $item->getconfig()->version : null,
['data-config' => 'version', 'class' => 'form-control config-item'],
) !!}
</div>
</div>
<div class="input" style="max-width: 150px;">
<label>Skip TLS verification</label>
<div class="toggleinput" style="margin-top: 26px; padding-left: 15px;">
{!! Form::hidden('config[ignore_tls]', 0, ['class' => 'config-item', 'data-config' => 'ignore_tls']) !!}
<label class="switch">
<?php
$checked = false;
if (isset($item) && !empty($item) && isset($item->getconfig()->ignore_tls)) {
$checked = $item->getconfig()->ignore_tls;
}
$set_checked = $checked ? ' checked="checked"' : '';
?>
<input type="checkbox" class="config-item" data-config="ignore_tls" name="config[ignore_tls]" value="1" <?php echo $set_checked; ?> />
<span class="slider round"></span>
</label>
</div>
</div>
<div class="input">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
</div>
Expand Down

0 comments on commit 069779f

Please sign in to comment.