diff --git a/application/forms/Config/BackendForm.php b/application/forms/Config/BackendForm.php index 6583691..90e0af2 100644 --- a/application/forms/Config/BackendForm.php +++ b/application/forms/Config/BackendForm.php @@ -45,6 +45,14 @@ class BackendForm extends ConfigForm 'label' => $this->translate('Graphite Web password'), 'description' => $this->translate('The above user\'s password') ] + ], + [ + 'checkbox', + 'graphite_insecure', + [ + 'label' => $this->translate('Connect insecurely'), + 'description' => $this->translate('Check this to not verify the remote\'s TLS certificate') + ] ] ]); } diff --git a/library/Graphite/Graphing/GraphingTrait.php b/library/Graphite/Graphing/GraphingTrait.php index 62e54df..03922bf 100644 --- a/library/Graphite/Graphing/GraphingTrait.php +++ b/library/Graphite/Graphing/GraphingTrait.php @@ -69,6 +69,7 @@ trait GraphingTrait (new GraphiteWebClient(Url::fromPath($graphite->url))) ->setUser($graphite->user) ->setPassword($graphite->password) + ->setInsecure($graphite->insecure) ); } diff --git a/library/Graphite/Graphing/GraphiteWebClient.php b/library/Graphite/Graphing/GraphiteWebClient.php index 1b489a3..f88f58d 100644 --- a/library/Graphite/Graphing/GraphiteWebClient.php +++ b/library/Graphite/Graphing/GraphiteWebClient.php @@ -33,6 +33,13 @@ class GraphiteWebClient */ protected $password; + /** + * Don't verify the remote's TLS certificate + * + * @var bool + */ + protected $insecure = false; + /** * HTTP client * @@ -74,7 +81,12 @@ class GraphiteWebClient ->getAbsoluteUrl(); // TODO(ak): keep connections alive (TCP handshakes are a bit expensive and TLS handshakes are very expensive) - return (string) $this->httpClient->send(new Request($method, $url, $headers, $body))->getBody(); + return (string) $this->httpClient->send( + new Request($method, $url, $headers, $body), + ['curl' => [ + CURLOPT_SSL_VERIFYPEER => ! $this->insecure + ]] + )->getBody(); } /** @@ -148,4 +160,28 @@ class GraphiteWebClient return $this; } + + /** + * Get whether not to verify the remote's TLS certificate + * + * @return bool + */ + public function getInsecure() + { + return $this->insecure; + } + + /** + * Set whether not to verify the remote's TLS certificate + * + * @param bool $insecure + * + * @return $this + */ + public function setInsecure($insecure = true) + { + $this->insecure = $insecure; + + return $this; + } }