From 3041a71b59a83b2b981a1f740383ac8b3cca68f6 Mon Sep 17 00:00:00 2001 From: Pedro Buffon Date: Sat, 28 Sep 2024 14:42:57 -0300 Subject: [PATCH] add support to skip tls verification (#781) --- Pihole/Pihole.php | 64 ++++++++++++++++++++++++++++++----------- Pihole/config.blade.php | 41 ++++++++++++++++++-------- 2 files changed, 77 insertions(+), 28 deletions(-) diff --git a/Pihole/Pihole.php b/Pihole/Pihole.php index 1517159aaf..fb74979b5f 100644 --- a/Pihole/Pihole.php +++ b/Pihole/Pihole.php @@ -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"); @@ -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; + } } diff --git a/Pihole/config.blade.php b/Pihole/config.blade.php index 4e63915b53..8b289559dc 100644 --- a/Pihole/config.blade.php +++ b/Pihole/config.blade.php @@ -2,24 +2,41 @@
- + {!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
{!! 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']) !!}
-
-
- - {!! Form::select( - 'config[version]', - ['5' => 'v5', '6' => 'v6'], - isset($item) ? $item->getconfig()->version : null, - ['data-config' => 'version', 'class' => 'form-control config-item'], - ) !!} -
-
+
+
+ + {!! Form::select( + 'config[version]', + ['5' => 'v5', '6' => 'v6'], + isset($item) ? $item->getconfig()->version : null, + ['data-config' => 'version', 'class' => 'form-control config-item'], + ) !!} +
+
+
+ +
+ {!! Form::hidden('config[ignore_tls]', 0, ['class' => 'config-item', 'data-config' => 'ignore_tls']) !!} + +
+