OneManager-php/index.php

216 lines
7.8 KiB
PHP
Raw Normal View History

2019-12-30 14:15:35 +00:00
<?php
2021-01-17 06:53:16 +00:00
//error_reporting(E_ALL & ~E_NOTICE);
error_reporting(0);
2023-05-12 15:21:25 +00:00
2020-01-18 12:12:21 +00:00
include 'vendor/autoload.php';
2019-12-30 14:15:35 +00:00
include 'conststr.php';
include 'common.php';
2019-12-30 14:15:35 +00:00
2022-01-27 03:51:04 +00:00
date_default_timezone_set('UTC');
2020-01-18 12:12:21 +00:00
//echo '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
2021-08-04 07:26:13 +00:00
//echo '<pre>'. json_encode($_ENV, JSON_PRETTY_PRINT).'</pre>';
2023-05-12 15:21:25 +00:00
global $platform;
$platform = checkPlatform();
function checkPlatform() {
if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud')
return 'SCF';
if (isset($_SERVER['FC_FUNC_CODE_PATH']))
return 'FC';
if (isset($_SERVER['RUNTIME_LOG_PATH']) && $_SERVER['RUNTIME_LOG_PATH']=='/home/snuser/log')
return 'FG';
if (isset($_SERVER['BCE_CFC_RUNTIME_NAME']) && $_SERVER['BCE_CFC_RUNTIME_NAME']=='php7')
return 'CFC';
if (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app')
return 'Heroku';
if (isset($_SERVER['DOCUMENT_ROOT'])&&$_SERVER['DOCUMENT_ROOT']==='/var/task/user')
return 'Vercel';
if (isset($_SERVER['DOCUMENT_ROOT'])&&substr($_SERVER['DOCUMENT_ROOT'], 0, 13)==='/home/runner/')
return 'Replit';
return 'Normal';
}
function writebackPlatform($p) {
if ('SCF'==$p) $_SERVER['USER']='qcloud';
if ('FC'==$p) $_SERVER['FC_FUNC_CODE_PATH']=getenv('FC_FUNC_CODE_PATH');
if ('FG'==$p) $_SERVER['RUNTIME_LOG_PATH']='/home/snuser/log';
if ('CFC'==$p) $_SERVER['BCE_CFC_RUNTIME_NAME']='php7';
//if ('Heroku'==$p) $_SERVER['HEROKU_APP_DIR']='/app';
if ('Vercel'==$p) $_SERVER['DOCUMENT_ROOT']='/var/task/user';
//if ('Replit'==$p) $_SERVER['DOCUMENT_ROOT']='/home/runner/';
}
if ('SCF'==$platform) {
2020-08-06 02:46:11 +00:00
if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/TencentSCF_file.php';
else include 'platform/TencentSCF_env.php';
2023-05-12 15:21:25 +00:00
} elseif ('FC'==$platform) {
include 'platform/AliyunFC.php';
2023-05-12 15:21:25 +00:00
} elseif ('FG'==$platform) {
2020-08-08 03:19:10 +00:00
//if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/HuaweiFG_file.php';
//else include 'platform/HuaweiFG_env.php';
echo 'FG' . PHP_EOL;
2023-05-12 15:21:25 +00:00
} elseif ('CFC'==$platform) {
2020-08-16 03:40:42 +00:00
include 'platform/BaiduCFC.php';
2023-05-12 15:21:25 +00:00
} elseif ('Heroku'==$platform) {
include 'platform/Heroku.php';
2020-01-18 12:12:21 +00:00
$path = getpath();
//echo 'path:'. $path;
$_GET = getGET();
//echo '<pre>'. json_encode($_GET, JSON_PRETTY_PRINT).'</pre>';
$re = main($path);
$sendHeaders = array();
foreach ($re['headers'] as $headerName => $headerVal) {
header($headerName . ': ' . $headerVal, true);
}
http_response_code($re['statusCode']);
2021-09-08 05:03:36 +00:00
if ($re['isBase64Encoded']) echo base64_decode($re['body']);
else echo $re['body'];
2023-05-12 15:21:25 +00:00
} elseif ('Vercel'==$platform) {
2021-08-20 10:09:16 +00:00
if (getenv('ONEMANAGER_CONFIG_SAVE')=='env') include 'platform/Vercel_env.php';
else include 'platform/Vercel.php';
2023-05-12 15:21:25 +00:00
writebackPlatform('Vercel');
2021-08-04 07:26:13 +00:00
$path = getpath();
//echo 'path:'. $path;
$_GET = getGET();
//echo '<pre>'. json_encode($_GET, JSON_PRETTY_PRINT).'</pre>';
2021-12-12 09:22:28 +00:00
$re = main($path);
$sendHeaders = array();
foreach ($re['headers'] as $headerName => $headerVal) {
header($headerName . ': ' . $headerVal, true);
}
http_response_code($re['statusCode']);
if ($re['isBase64Encoded']) echo base64_decode($re['body']);
else echo $re['body'];
2023-05-12 15:21:25 +00:00
} elseif ('Replit'==$platform) {
2021-12-12 09:22:28 +00:00
include 'platform/Replit.php';
$path = getpath();
//echo 'path:'. $path;
$_GET = getGET();
//echo '<pre>'. json_encode($_GET, JSON_PRETTY_PRINT).'</pre>';
2021-08-04 07:26:13 +00:00
$re = main($path);
$sendHeaders = array();
foreach ($re['headers'] as $headerName => $headerVal) {
header($headerName . ': ' . $headerVal, true);
}
http_response_code($re['statusCode']);
2021-09-08 05:03:36 +00:00
if ($re['isBase64Encoded']) echo base64_decode($re['body']);
else echo $re['body'];
2020-01-18 12:12:21 +00:00
} else {
include 'platform/Normal.php';
if (!function_exists('curl_init')) {
http_response_code(500);
echo '<font color="red">Need curl</font>, please install php-curl.';
exit(1);
}
2020-01-18 12:12:21 +00:00
$path = getpath();
//echo 'path:'. $path;
$_GET = getGET();
//echo '<pre>'. json_encode($_GET, JSON_PRETTY_PRINT).'</pre>';
$re = main($path);
$sendHeaders = array();
foreach ($re['headers'] as $headerName => $headerVal) {
header($headerName . ': ' . $headerVal, true);
2019-12-30 14:15:35 +00:00
}
2020-01-18 12:12:21 +00:00
http_response_code($re['statusCode']);
2021-09-08 05:03:36 +00:00
if ($re['isBase64Encoded']) echo base64_decode($re['body']);
else echo $re['body'];
2020-01-18 12:12:21 +00:00
}
// Tencent SCF
2020-01-18 12:12:21 +00:00
function main_handler($event, $context)
{
$event = json_decode(json_encode($event), true);
$context = json_decode(json_encode($context), true);
printInput($event, $context);
2022-01-09 06:05:25 +00:00
if ( $event['requestContext']['serviceId'] === substr($event['headers']['host'], 0, strlen($event['requestContext']['serviceId'])) ) {
if ($event['path']==='/' . $context['function_name']) return output('add / at last.', 308, ['Location'=>'/'.$event['requestContext']['stage'].'/'.$context['function_name'].'/']);
}
2020-01-18 12:12:21 +00:00
unset($_POST);
unset($_GET);
unset($_COOKIE);
unset($_SERVER);
2023-05-12 15:21:25 +00:00
writebackPlatform('SCF');
2020-01-18 12:12:21 +00:00
GetGlobalVariable($event);
2020-01-20 04:49:55 +00:00
//echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>';
2020-01-18 12:12:21 +00:00
$path = GetPathSetting($event, $context);
2020-02-20 03:59:58 +00:00
2020-01-18 12:12:21 +00:00
return main($path);
}
2020-08-16 03:40:42 +00:00
// Aliyun FC & Huawei FG & Baidu CFC
2020-07-13 09:36:17 +00:00
function handler($event, $context)
{
2023-05-20 15:00:19 +00:00
global $platform;
2023-05-12 15:21:25 +00:00
if ('FC'==$platform) {
2020-07-13 09:36:17 +00:00
// Aliyun FC
set_error_handler("myErrorHandler");
$tmp = array(
'method' => $event->getMethod(),
'clientIP' => $event->getAttribute("clientIP"),
2020-09-22 11:41:50 +00:00
'requestURI' => $event->getAttribute("requestURI"),
2020-07-13 09:36:17 +00:00
'path' => spurlencode($event->getAttribute("path"), '/'),
'queryString' => $event->getQueryParams(),
'headers' => $event->getHeaders(),
'body' => $event->getBody()->getContents(),
);
$event = $tmp;
$context = json_decode(json_encode($context), true);
printInput($event, $context);
unset($_POST);
unset($_GET);
unset($_COOKIE);
unset($_SERVER);
2023-05-12 15:21:25 +00:00
writebackPlatform('FC');
2020-07-13 09:36:17 +00:00
GetGlobalVariable($event);
$path = GetPathSetting($event, $context);
2020-07-13 09:36:17 +00:00
$re = main($path);
2022-01-27 06:50:09 +00:00
return new RingCentral\Psr7\Response($re['statusCode'], $re['headers'], ($re['isBase64Encoded']?base64_decode($re['body']):$re['body']));
2023-05-12 15:21:25 +00:00
} elseif ('FG'==$platform) {
2020-07-13 09:36:17 +00:00
// Huawei FG
global $contextUserData;
$contextUserData = $context;
2020-08-08 03:19:10 +00:00
if ($context->getUserData('ONEMANAGER_CONFIG_SAVE')=='file') include_once 'platform/HuaweiFG_file.php';
else include_once 'platform/HuaweiFG_env.php';
2020-07-13 09:36:17 +00:00
$event = json_decode(json_encode($event), true);
if ($event['isBase64Encoded']) $event['body'] = base64_decode($event['body']);
printInput($event, $context);
unset($_POST);
unset($_GET);
unset($_COOKIE);
unset($_SERVER);
2023-05-12 15:21:25 +00:00
writebackPlatform('FG');
2020-07-13 09:36:17 +00:00
GetGlobalVariable($event);
//echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>';
$path = GetPathSetting($event, $context);
return main($path);
2020-08-08 03:19:10 +00:00
2023-05-12 15:21:25 +00:00
} elseif ('CFC'==$platform) {
2020-08-16 03:40:42 +00:00
// Baidu CFC
//$html = '<pre>'. json_encode($event, JSON_PRETTY_PRINT).'</pre>';
//$html .= '<pre>'. json_encode($context, JSON_PRETTY_PRINT).'</pre>';
//$html .= '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
//$html .= $event['path'];
//$html .= $context['functionBrn'];
//return json_encode(output($html), JSON_FORCE_OBJECT);
printInput($event, $context);
unset($_POST);
unset($_GET);
unset($_COOKIE);
unset($_SERVER);
2023-05-12 15:21:25 +00:00
writebackPlatform('CFC');
2020-08-16 03:40:42 +00:00
GetGlobalVariable($event);
//echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>';
$path = GetPathSetting($event, $context);
return json_encode(main($path), JSON_FORCE_OBJECT);
2020-07-13 09:36:17 +00:00
}
}