Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Thellimist/pi 721 #103

Merged
merged 16 commits into from
Aug 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5,065 changes: 3,982 additions & 1,083 deletions compiled.js

Large diffs are not rendered by default.

306 changes: 226 additions & 80 deletions composer.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
"featureManagerIsScanEnabled": false,
"featureManagerIsSecurityLevelEnabled": true,
"featureManagerIsSSLEnabled": false,
"useHostAPILogin": true,
"homePageCards": ["DNSManagementPage"],
"moreSettingsCards": {
"container.moresettings.security": ["SecurityLevelCard", "ChallengePassageCard", "BrowserIntegrityCheckCard"],
"container.moresettings.speed": ["AlwaysOnlineCard", "IPV6Card", "CacheLevelCard", "MinifyCard", "RailgunCard", "DevelopmentModeCard", "BrowserCacheTTLCard", "PurgeCacheCard"]
},
"locale": "en",
"integrationName": "cpanel",
"version": "6.0.5"
Expand Down
51 changes: 50 additions & 1 deletion lang/en.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"component.clientLogin.form.email": "Email",
"component.clientLogin.form.apiKeyHelp": "Where can I find my API key?",
"component.clientLogin.form.apiKey": "API Key",
"component.clientLogin.form.button": "Save API Credentials",
"component.clientLogin.form.signUp": "Sign up",
"component.clientLogin.form.title": "Enter CloudFlare API Credentials",
"component.clientLogin.cloudflare.description": "New to CloudFlare? Sign up at",
"component.customcardcontrol.upgrade": "Upgrade to",
"component.login.form.email": "Email",
"component.login.form.forgotPassword": "Forgot your password?",
"component.login.form.password": "Password",
Expand All @@ -21,6 +29,9 @@
"container.activationCheckCard.title": "Activation Check",
"container.activationCheckCard.status": "Status: {status}",
"container.activationCheckCard.success": "Your domain is now queued up to be rescanned. Please check back in a few hours.",
"container.advanceddos.title": "Advance DDoS",
"container.advanceddos.description": "CloudFlare will stand in front of your website regardless of attack size or duration.",
"container.advanceddos.value": "Visit Cloudflare.com",
"container.alwaysOnlineCard.title": "Always Online™",
"container.alwaysOnlineCard.description": "If your server goes down, CloudFlare will serve your website's static pages from our cache.",
"containers.analyticsPage.cached": "Cached",
Expand All @@ -33,6 +44,16 @@
"container.analyticsPage.tabs.threats": "Threats",
"container.analyticsPage.title": "Analytics",
"container.App.version": "Version: {version}",
"container.applydefaultsettingscard.title": "Apply Default Settings",
"container.applydefaultsettingscard.description": "We recommend you to use default settings",
"container.applydefaultsettingscard.button": "Apply",
"container.applydefaultsettingscard.success": "Your default settings have been successfully set.",
"container.applydefaultsettingscard.modal.title": "Are you sure?",
"container.applydefaultsettingscard.modal.description": "Applying default settings will overwrite some of the settings you've set through Cloudflare Dashboard.",
"container.applydefaultsettingscard.modal.buttonCancel": "Cancel",
"container.applydefaultsettingscard.modal.button": "I'm sure",
"container.appNavigation.home": "Home",
"container.appNavigation.moresettings": "More Settings",
"container.appNavigation.domainsOverview": "Domains Overview",
"container.appNavigation.analytics": "Analytics",
"container.appNavigation.performance": "Performance",
Expand Down Expand Up @@ -98,19 +119,38 @@
"container.dnsManagementPage.thead.changePlan": "Change",
"container.ipv6Card.title": "IPv6 Compatibility",
"container.ipv6Card.description": "Enable IPv6 support and gateway.",
"container.homePage.title": "Home",
"container.minifyCard.title": "Auto Minify",
"container.minifyCard.description": "Reduce the file size of source code on your website.",
"container.minifyCard.css": "CSS",
"container.minifyCard.html": "HTML",
"container.minifyCard.javascript": "JavaScript",
"container.moresettings.speed": "Speed",
"container.moresettings.security": "Security",
"container.performancePage.title": "Performance",
"container.pluginSpecificCacheCard.title": "Automatic Cache Management",
"container.pluginSpecificCacheCard.description": "Purge CloudFlare cache automatically on updating site appearance.",
"container.pluginSpecificCacheCard.button.enable": "Enable",
"container.pluginSpecificCacheCard.button.disable": "Disable",
"container.pluginSpecificCacheCard.modal.title": "Confirm Enabling Automatic Cache",
"container.pluginSpecificCacheCard.modal.description": "Enabling automatic cache purge will clear the entire CloudFlare cache when your site appearance is updated",
"container.pluginSpecificCacheCard.modal.button": "I'm sure",
"container.pluginSpecificCacheCard.modal.buttonCancel": "Cancel",
"container.protocolRewrite.title": "Protocol Rewriting",
"container.protocolRewrite.description": "Protocol rewriting in this context convert links within your WordPress site to images, stylesheets, and scripts from using either \"http://\" or \"https://\" to using just \"//\". This rewrite tells your browser to load all of these assets using the same protocol as the base page loaded.",
"container.purgeCacheCard.dropdown": "Purge Cache",
"container.purgeCacheCard.button": "Purge Everything",
"container.purgeCacheCard.title": "Purge Cache",
"container.purgeCacheCard.description": "Clear cached files to force CloudFlare to fetch a fresh version of those files from your web server.",
"container.purgeCacheCard.description": "Clear cached files to force CloudFlare to fetch a fresh version of those files from your web server. You can purge files selectively or all at once.",
"container.purgeCacheCard.success": "Cache was successfully purged.",
"container.purgeCacheCard.modal.title" : "Confirm Purge All",
"container.purgeCacheCard.modal.description": "Note: Purging your cache may slow your website temporarily.",
"container.purgeCacheCard.modal.buttonCancel": "Cancel",
"container.purgeCacheByURLCard.button": "Purge Individual Files",
"container.purgeCacheByURLCard.success": "Successfully requested 1 file(s) to be purged. Please allow up to 30 seconds for changes to take effect.",
"container.purgeCacheByURLCard.modal.title" : "Confirm Individual Files",
"container.purgeCacheByURLCard.modal.description": "You can purge up to 30 files at a time. Note: Wildcards are not supported with single file purge at this time. You will need to specify the full path to the file. Separate URL(s) with spaces, or list one per line",
"container.purgeCacheByURLCard.modal.buttonCancel": "Cancel",
"container.railgunCard.title":"Railgun™",
"container.railgunCard.description":"Accelerate delivery of dynamic content. Note: Requires software installation at your host.",
"container.railgunCard.table.name":"Name",
Expand Down Expand Up @@ -160,5 +200,14 @@
"container.zoneProvision.modal.title": "Delete Website",
"container.zoneProvision.modal.description": "Are you sure you want to delete {zoneName}? To temporarily disable CloudFlare service and save your website settings, pause your website instead.",
"container.zoneProvision.modal.buttonCancel": "Cancel",
"container.ipRewrite.title": "IP Rewrite",
"container.ipRewrite.description": "Rewrite CloudFlare IP Addresses for actual end-user IP Addresses at the application layer.",
"container.imageOptimization.title": "Image Optimization",
"container.imageOptimization.description": "Improve image load time and for pages that include images on mobile devices with slow network connections",
"container.waf.title": "Web Application Firewall",
"container.waf.description": "Set rules to protect your website from web vulnerabilities.",
"constants.plans.pro": "Pro plan",
"constants.plans.biz": "Business plan",
"constants.plans.ent": "Enterprise plan",
"errors.noActiveZoneSelected": "Please select a domain that is provisioned with CloudFlare."
}
68 changes: 28 additions & 40 deletions proxy.live.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
require_once("cloudflare/vendor/autoload.php");
require_once("/usr/local/cpanel/php/cpanel.php");

require_once 'cloudflare/vendor/autoload.php';
require_once '/usr/local/cpanel/php/cpanel.php';
session_start();
header('Content-Type: application/json');

Expand All @@ -10,59 +11,46 @@
* application.
*/
$cpanel = new CPANEL();
$config = new CF\Integration\DefaultConfig(file_get_contents("config.js"));
$logger = new CF\Integration\DefaultLogger($config->getValue("debug"));
$config = new CF\Integration\DefaultConfig(file_get_contents('config.js'));
$logger = new CF\Integration\DefaultLogger($config->getValue('debug'));
$cpanelAPI = new CF\Cpanel\CpanelAPI($cpanel, $logger);
$dataStore = new CF\Cpanel\DataStore($cpanelAPI, $logger);
$cpanelIntegration = new CF\Cpanel\CpanelIntegration($config, $cpanelAPI, $dataStore, $logger);
$cpanelIntegration = new CF\Integration\DefaultIntegration($config, $cpanelAPI, $dataStore, $logger);
$partialZoneSet = new \CF\Cpanel\Zone\Partial($cpanelAPI, $dataStore, $logger);
$clientAPIClient = new CF\API\Client($cpanelIntegration);
$clientAPIClientRoutes = \CF\Cpanel\ClientV4APIRoutes::$routes;
$hostAPIClient = new CF\API\Host($cpanelIntegration);
$hostAPIClientRoutes = \CF\Cpanel\HostRoutes::$routes;
$requestRouter = new \CF\Router\RequestRouter($cpanelIntegration);
$requestRouter->addRouter('\CF\API\Client', \CF\Cpanel\ClientV4APIRoutes::$routes);
$requestRouter->addRouter('\CF\API\Plugin', \CF\Cpanel\PluginRoutes::getRoutes(\CF\API\PluginRoutes::$routes));
$requestRouter->addRouter('\CF\API\Host', \CF\Cpanel\HostRoutes::$routes);

$method = $_SERVER['REQUEST_METHOD'];
$parameters = $_GET;
$body = json_decode(file_get_contents('php://input'),true);
$path = (strtoupper($method === "GET") ? $_GET['proxyURL'] : $body['proxyURL']);
$body = json_decode(file_get_contents('php://input'), true);
$path = (strtoupper($method === 'GET') ? $_GET['proxyURL'] : $body['proxyURL']);

unset($parameters['proxyURL']);
unset($body['proxyURL']);
$request = new \CF\API\Request($method, $path, $parameters, $body);

//only check CSRF if its not a GET request
$isCSRFTokenValid = (($request->getMethod() === "GET") ? true : \CF\SecurityUtil::csrfTokenValidate($cpanelAPI->getHostAPIKey(), $cpanelAPI->getUserId(), $request->getBody()['cfCSRFToken']));
$isCSRFTokenValid = (($request->getMethod() === 'GET') ? true : \CF\SecurityUtil::csrfTokenValidate($cpanelAPI->getHostAPIKey(), $cpanelAPI->getUserId(), $request->getBody()['cfCSRFToken']));
unset($body['cfCSRFToken']);
$apiResponse = "";
$apiRouter;

if(isHostAPI($request->getUrl())) {
$apiRouter = new CF\Router\HostAPIRouter($cpanelIntegration, $hostAPIClient, $hostAPIClientRoutes);
} else if(isClientAPI($request->getUrl())) {
$apiRouter = new CF\Router\DefaultRestAPIRouter($cpanelIntegration, $clientAPIClient, $clientAPIClientRoutes);
}
if($isCSRFTokenValid) {
$apiResponse = $apiRouter->route($request);
if ($isCSRFTokenValid) {
$response = $requestRouter->route($request);
} else {
$apiResponse = $apiRouter->getAPIClient()->createAPIError("CSRF Token not valid.");
$message = 'CSRF Token not valid.';
$response = array(
'result' => null,
'success' => false,
'errors' => array(
array(
'code' => '',
'message' => $message,
),
),
'messages' => array(),
);
}

echo json_encode($apiResponse);
echo json_encode($response);

$cpanel->end();

/**
* @param $path
* @return bool
*/
function isClientAPI($path) {
return (strpos($path, \CF\API\Client::ENDPOINT) !== false);
}

/**
* @param $path
* @return bool
*/
function isHostAPI($path) {
return ($path === \CF\API\Host::ENDPOINT);
}
11 changes: 6 additions & 5 deletions src/Cpanel/ClientActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use CF\API\APIInterface;
use CF\API\Request;
use CF\Cpanel\Zone\Partial;
use CF\Integration\DefaultIntegration;

class ClientActions
{
Expand All @@ -17,11 +18,11 @@ class ClientActions
private $request;

/**
* @param CpanelIntegration $cpanelIntegration
* @param APIInterface $api
* @param Request $request
* @param DefaultIntegration $cpanelIntegration
* @param APIInterface $api
* @param Request $request
*/
public function __construct(CpanelIntegration $cpanelIntegration, APIInterface $api, Request $request)
public function __construct(DefaultIntegration $cpanelIntegration, APIInterface $api, Request $request)
{
$this->api = $api;
$this->config = $cpanelIntegration->getConfig();
Expand Down Expand Up @@ -143,7 +144,7 @@ public function patchDNSRecord()
*/
public function deleteZone()
{
if(!$this->cpanelAPI->isAdvancedZoneEditEnabled()) {
if (!$this->cpanelAPI->isAdvancedZoneEditEnabled()) {
return $this->api->createAPIError(Partial::ADVANCED_ZONE_EDIT_DISABLED_ERROR);
}

Expand Down
Loading