| Server IP : 172.67.133.75 / Your IP : 162.159.115.9 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/WordPress/ |
Upload File : |
<?php
namespace Cloudflare\APO\WordPress;
use Cloudflare\APO\API\APIInterface;
use Cloudflare\APO\API\Request;
use Cloudflare\APO\Integration\DefaultIntegration;
use Cloudflare\APO\IntlUtil;
class ClientActions
{
private $api;
private $config;
private $wordpressAPI;
private $dataStore;
private $logger;
private $request;
/**
* @param DefaultIntegration $defaultIntegration
* @param APIInterface $api
* @param Request $request
*/
public function __construct(DefaultIntegration $defaultIntegration, APIInterface $api, Request $request)
{
$this->api = $api;
$this->config = $defaultIntegration->getConfig();
$this->wordpressAPI = $defaultIntegration->getIntegrationAPI();
$this->dataStore = $defaultIntegration->getDataStore();
$this->logger = $defaultIntegration->getLogger();
$this->request = $request;
}
/**
* GET /zones.
*
* @return mixed
*/
public function returnWordPressDomain()
{
// Call GET /zones
$response = $this->api->callAPI($this->request);
// We tried to fetch a zone but it's possible we're using an API token,
// So try again with a zone name filtered API call
if (!$this->api->responseOk($response)) {
$zoneRequest = new Request(
'GET',
'zones/',
array(
'name' => IntlUtil::idn_to_ascii($this->wordpressAPI->getOriginalDomain(), IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46),
'status' => 'active',
),
null
);
$zoneResponse = $this->api->callAPI($zoneRequest);
return $zoneResponse;
}
// Cache the domain for subdomains
$this->cacheDomainName($response);
// Get zone information
$cfZonesList = $this->filterZones($response);
return $cfZonesList;
}
private function filterZones($response)
{
$cfZonesList = $response;
$wpDomainList = $this->wordpressAPI->getDomainList();
$wpDomain = $wpDomainList[0];
$domainList = array();
if ($this->api->responseOk($cfZonesList)) {
$found = false;
foreach ($cfZonesList['result'] as $zone) {
if (IntlUtil::idn_to_ascii($zone['name'], IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) === IntlUtil::idn_to_ascii($wpDomain, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46)) {
$found = true;
array_push($domainList, $zone);
}
}
if ($found === false) {
array_push($domainList, array(
'name' => $wpDomain,
'plan' => array('name' => ''),
'type' => '',
'status' => 'inactive',
));
}
}
$cfZonesList['result'] = $domainList;
return $cfZonesList;
}
public function cacheDomainName($response)
{
// Check if domain name needs to be cached
$wpDomain = $this->wordpressAPI->getOriginalDomain();
$cachedDomainList = $this->wordpressAPI->getDomainList();
$cachedDomain = isset($cachedDomainList[0]) ? $cachedDomainList[0] : '';
if (Utils::getRegistrableDomain($wpDomain) !== $cachedDomain) {
// If it's not a subdomain cache the current domain
$domainName = $wpDomain;
// Get cloudflare zones to find if the current domain is a
// subdomain of any cloudflare zones registered
$validDomainName = $this->wordpressAPI->checkIfValidCloudflareSubdomain($response, $wpDomain);
// Check if it's a subdomain, if it is cache the zone instead of the
// subdomain
if ($this->api->responseOK($response) && $validDomainName) {
$domainName = Utils::getRegistrableDomain($wpDomain);
}
$this->wordpressAPI->setDomainNameCache($domainName);
// Log for debugging
$this->logger->debug("Current domain -> $wpDomain");
$this->logger->debug("Valid domain -> $validDomainName");
$this->logger->debug("Cached domain -> $domainName");
return $domainName;
}
return $cachedDomain;
}
}