From b46a2f80f5e3e5539d918747d21000f9653dfa2f Mon Sep 17 00:00:00 2001 From: Michael Markoski Date: Tue, 21 May 2019 16:02:08 -0500 Subject: [PATCH] add new methods --- src/Endpoints/Crypto.php | 229 +++++++++++++++++++++++++++++++++++++++ src/Endpoints/TLS.php | 62 +++-------- 2 files changed, 245 insertions(+), 46 deletions(-) create mode 100644 src/Endpoints/Crypto.php diff --git a/src/Endpoints/Crypto.php b/src/Endpoints/Crypto.php new file mode 100644 index 0000000..43ae35a --- /dev/null +++ b/src/Endpoints/Crypto.php @@ -0,0 +1,229 @@ +adapter = $adapter; + } + + /** + * Get the SSL setting for the zone + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getSSLSetting($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/ssl' + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result->value; + } + + return false; + } + + /** + * Get SSL Verification Info for a Zone + * + * @param string $zoneID The ID of the zone + * @return array|false + */ + public function getSSLVerificationStatus($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/ssl/verification' + ); + $body = json_decode($return->getBody()); + + if ($body->result) { + return $body->result; + } + + return false; + } + + /** + * Get the Opportunistic Encryption feature for a zone. + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getOpportunisticEncryptionSetting($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/opportunistic_encryption' + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result->value; + } + + return false; + } + + /** + * Get the Onion Routing feature for a zone. + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getOnionRoutingSetting($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/opportunistic_onion' + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result; + } + + return false; + } + + public function getHTTPSRedirectSetting($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/always_use_https' + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result->value; + } + + return false; + } + + public function getHTTPSRewritesSetting($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/automatic_https_rewrites' + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result->value; + } + + return false; + } + + /** + * Update the SSL setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateSSLSetting($zoneID, $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/ssl', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return true; + } + + return false; + } + + /** + * Update the HTTPS Redirect setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateHTTPSRedirectSetting($zoneID, $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/always_use_https', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return true; + } + + return false; + } + + /** + * Update the HTTPS Rewrite setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateHTTPSRewritesSetting($zoneID, $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/automatic_https_rewrites', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return true; + } + + return false; + } + + public function updateOpportunisticEncryptionSetting($zoneID, $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/opportunistic_encryption', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return true; + } + + return false; + } + + public function updateOnionRoutingSetting($zoneID, $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/opportunistic_onion', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return true; + } + + return false; + } +} diff --git a/src/Endpoints/TLS.php b/src/Endpoints/TLS.php index 46c960e..9e98295 100644 --- a/src/Endpoints/TLS.php +++ b/src/Endpoints/TLS.php @@ -19,6 +19,20 @@ class TLS implements API $this->adapter = $adapter; } + public function getTLSClientAuth($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/tls_client_auth' + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result->value; + } + + return false; + } + public function enableTLS13($zoneID) { $return = $this->adapter->patch( @@ -67,38 +81,10 @@ class TLS implements API return false; } - public function getHTTPSRedirectSetting($zoneID) - { - $return = $this->adapter->get( - 'zones/' . $zoneID . '/settings/always_use_https' - ); - $body = json_decode($return->getBody()); - - if ($body->success) { - return $body->result->value; - } - - return false; - } - - public function getHTTPSRewritesSetting($zoneID) - { - $return = $this->adapter->get( - 'zones/' . $zoneID . '/settings/automatic_https_rewrites' - ); - $body = json_decode($return->getBody()); - - if ($body->success) { - return $body->result->value; - } - - return false; - } - - public function updateHTTPSRedirectStatus($zoneID, $value) + public function updateTLSClientAuth($zoneID, $value) { $return = $this->adapter->patch( - 'zones/' . $zoneID . '/settings/always_use_https', + 'zones/' . $zoneID . '/settings/tls_client_auth', [ 'value' => $value, ] @@ -112,20 +98,4 @@ class TLS implements API return false; } - public function updateHTTPSRewritesStatus($zoneID, $value) - { - $return = $this->adapter->patch( - 'zones/' . $zoneID . '/settings/automatic_https_rewrites', - [ - 'value' => $value, - ] - ); - $body = json_decode($return->getBody()); - - if ($body->success) { - return true; - } - - return false; - } }