| Server IP : 104.21.13.219 / Your IP : 104.23.197.161 Web Server : nginx/1.26.1 System : Linux HE9229 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 User : www ( 1000) PHP Version : 8.0.26 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/jl3_ph_com/wp-content/plugins/cloudflare/src/API/ |
Upload File : |
<?php
namespace Cloudflare\APO\API;
use Cloudflare\APO\Integration\IntegrationInterface;
use Cloudflare\APO\WordPress\Utils;
class Client extends AbstractAPIClient
{
const CLIENT_API_NAME = 'CLIENT API';
const ENDPOINT = 'https://api.cloudflare.com/client/v4/';
const X_AUTH_KEY = 'X-Auth-Key';
const X_AUTH_EMAIL = 'X-Auth-Email';
const AUTHORIZATION = 'Authorization';
const AUTH_KEY_LEN = 37;
const USER_AGENT = 'User-Agent';
/**
* @param Request $request
*
* @return Request
*/
public function beforeSend(Request $request)
{
$key = $this->data_store->getClientV4APIKey();
$headers = array(
self::CONTENT_TYPE_KEY => self::APPLICATION_JSON_KEY,
);
$composer = Utils::getComposerJson();
$version = $composer['version'] ?? 'unknown';
$wp_version = $GLOBALS['wp_version'] ?? 'unknown';
$headers[self::USER_AGENT] = 'wordpress/' . $wp_version . '; cloudflare-wordpress-plugin/' . $version;
// Determine authentication method from key format. Global API keys are
// always returned in hexadecimal format, while API Tokens are encoded
// using a wider range of characters.
if (strlen($key) === self::AUTH_KEY_LEN && preg_match('/^[0-9a-f]+$/', $key)) {
$headers[self::X_AUTH_EMAIL] = $this->data_store->getCloudFlareEmail();
$headers[self::X_AUTH_KEY] = $key;
} else {
$headers[self::AUTHORIZATION] = "Bearer {$key}";
}
$request->setHeaders($headers);
// Remove cfCSRFToken (a custom header) to save bandwidth
$body = $request->getBody();
unset($body['cfCSRFToken']);
$request->setBody($body);
return $request;
}
/**
* @param $message
*
* @return array
*/
public function createAPIError($message)
{
$this->logger->error($message);
return array(
'result' => null,
'success' => false,
'errors' => array(
array(
'code' => '',
'message' => $message,
),
),
'messages' => array(),
);
}
/**
* @param error
*
* @return string
*/
public function getErrorMessage($error)
{
$jsonResponse = json_decode($error->getResponse()->getBody(), true);
$errorMessage = $error->getMessage();
if (count($jsonResponse['errors']) > 0) {
$errorMessage = $jsonResponse['errors'][0]['message'];
}
return $errorMessage;
}
/**
* @param $response
*
* @return bool
*/
public function responseOk($response)
{
return isset($response['success']) ? $response['success'] : false;
}
/**
* @return string
*/
public function getEndpoint()
{
return self::ENDPOINT;
}
/**
* @return string
*/
public function getAPIClientName()
{
return self::CLIENT_API_NAME;
}
/**
* GET /zones/:id.
*
* @param $zone_tag
*
* @return string
*/
public function zoneGetDetails($zone_tag)
{
$request = new Request('GET', 'zones/'.$zone_tag, array(), array());
return $this->callAPI($request);
}
}