forked from cloudflare/Cloudflare-CPanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.live.php
60 lines (52 loc) · 2.31 KB
/
proxy.live.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
use CF\API\Client;
require_once 'cloudflare/vendor/autoload.php';
require_once '/usr/local/cpanel/php/cpanel.php';
session_start();
header('Content-Type: application/json');
/*
* The Cpanel UAPI must be instantiated once and only once from a *.live.php file. After its instantiated we can pass
* it around to non *.live.php files and we wrap it to try to contain the cpanel specific logic from the rest of the
* application.
*/
$cpanel = new CPANEL();
$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\Integration\DefaultIntegration($config, $cpanelAPI, $dataStore, $logger);
$partialZoneSet = new \CF\Cpanel\Zone\Partial($cpanelAPI, $dataStore, $logger);
$requestRouter = new \CF\Router\RequestRouter($cpanelIntegration);
$clientAPI = new \CF\API\Client($cpanelIntegration);
$requestRouter->addRouter($clientAPI, \CF\Cpanel\ClientV4APIRoutes::$routes);
$pluginAPI = new \CF\API\Plugin($cpanelIntegration);
$requestRouter->addRouter($pluginAPI, \CF\Cpanel\PluginRoutes::getRoutes(\CF\API\PluginRoutes::$routes));
$hostAPI = new \CF\API\Host($cpanelIntegration);
$requestRouter->addRouter($hostAPI, \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']);
unset($parameters['proxyURL']);
unset($body['proxyURL']);
$request = new \CF\API\Request($method, $path, $parameters, $body);
$isCSRFTokenValid = (($request->getMethod() === 'GET') ? true : \CF\SecurityUtil::csrfTokenValidate($cpanelAPI->getHostAPIKey(), $cpanelAPI->getUserId(), $request->getBody()['cfCSRFToken']));
unset($body['cfCSRFToken']);
if ($isCSRFTokenValid) {
$response = $requestRouter->route($request);
} else {
$message = 'CSRF Token not valid.';
$response = array(
'result' => null,
'success' => false,
'errors' => array(
array(
'code' => '',
'message' => $message,
),
),
'messages' => array(),
);
}
echo json_encode($response);
$cpanel->end();