check platform

pull/690/head
root 2023-05-12 15:21:25 +00:00
parent bb7c865cc3
commit 37d2697096
10 changed files with 49 additions and 30 deletions

View File

@ -1,5 +1,6 @@
<?php <?php
global $platform;
global $timezones; global $timezones;
global $slash; global $slash;
global $drive; global $drive;
@ -1899,17 +1900,7 @@ output:
</script>'; </script>';
$canOneKeyUpate = 0; $canOneKeyUpate = 0;
if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') { if ('Normal'!=$platform) {
$canOneKeyUpate = 1;
} elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') {
$canOneKeyUpate = 1;
} elseif (isset($_SERVER['FC_FUNC_CODE_PATH'])) {
$canOneKeyUpate = 1;
} elseif (isset($_SERVER['BCE_CFC_RUNTIME_NAME'])&&$_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') {
$canOneKeyUpate = 1;
} elseif (isset($_SERVER['RUNTIME_LOG_PATH']) && $_SERVER['RUNTIME_LOG_PATH']=='/home/snuser/log') {
$canOneKeyUpate = 1;
} elseif (isset($_SERVER['DOCUMENT_ROOT'])&&$_SERVER['DOCUMENT_ROOT']==='/var/task/user') {
$canOneKeyUpate = 1; $canOneKeyUpate = 1;
} else { } else {
$tmp = time(); $tmp = time();
@ -1920,7 +1911,7 @@ output:
} }
$frame .= ' $frame .= '
<a href="https://github.com/qkqpttgf/OneManager-php" target="_blank">Github</a> <a href="https://github.com/qkqpttgf/OneManager-php" target="_blank">Github</a>
<a href="https://git.hit.edu.cn/ysun/OneManager-php" target="_blank">HIT Gitlab</a><br><br> <a href="https://git.hit.edu.cn/ysun/OneManager-php" target="_blank">HIT Gitlab</a><br><br>
'; ';
if (!$canOneKeyUpate) { if (!$canOneKeyUpate) {
$frame .= ' $frame .= '

View File

@ -1,6 +1,7 @@
<?php <?php
//error_reporting(E_ALL & ~E_NOTICE); //error_reporting(E_ALL & ~E_NOTICE);
error_reporting(0); error_reporting(0);
include 'vendor/autoload.php'; include 'vendor/autoload.php';
include 'conststr.php'; include 'conststr.php';
include 'common.php'; include 'common.php';
@ -8,18 +9,46 @@ include 'common.php';
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
//echo '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>'; //echo '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
//echo '<pre>'. json_encode($_ENV, JSON_PRETTY_PRINT).'</pre>'; //echo '<pre>'. json_encode($_ENV, JSON_PRETTY_PRINT).'</pre>';
if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') { 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) {
if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/TencentSCF_file.php'; if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/TencentSCF_file.php';
else include 'platform/TencentSCF_env.php'; else include 'platform/TencentSCF_env.php';
} elseif (isset($_SERVER['FC_FUNC_CODE_PATH'])) { } elseif ('FC'==$platform) {
include 'platform/AliyunFC.php'; include 'platform/AliyunFC.php';
} elseif (isset($_SERVER['RUNTIME_LOG_PATH']) && $_SERVER['RUNTIME_LOG_PATH']=='/home/snuser/log') { } elseif ('FG'==$platform) {
//if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/HuaweiFG_file.php'; //if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/HuaweiFG_file.php';
//else include 'platform/HuaweiFG_env.php'; //else include 'platform/HuaweiFG_env.php';
echo 'FG' . PHP_EOL; echo 'FG' . PHP_EOL;
} elseif (isset($_SERVER['BCE_CFC_RUNTIME_NAME']) && $_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') { } elseif ('CFC'==$platform) {
include 'platform/BaiduCFC.php'; include 'platform/BaiduCFC.php';
} elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') { } elseif ('Heroku'==$platform) {
include 'platform/Heroku.php'; include 'platform/Heroku.php';
$path = getpath(); $path = getpath();
//echo 'path:'. $path; //echo 'path:'. $path;
@ -33,9 +62,11 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
http_response_code($re['statusCode']); http_response_code($re['statusCode']);
if ($re['isBase64Encoded']) echo base64_decode($re['body']); if ($re['isBase64Encoded']) echo base64_decode($re['body']);
else echo $re['body']; else echo $re['body'];
} elseif (isset($_SERVER['DOCUMENT_ROOT'])&&$_SERVER['DOCUMENT_ROOT']==='/var/task/user') { } elseif ('Vercel'==$platform) {
if (getenv('ONEMANAGER_CONFIG_SAVE')=='env') include 'platform/Vercel_env.php'; if (getenv('ONEMANAGER_CONFIG_SAVE')=='env') include 'platform/Vercel_env.php';
else include 'platform/Vercel.php'; else include 'platform/Vercel.php';
writebackPlatform('Vercel');
$path = getpath(); $path = getpath();
//echo 'path:'. $path; //echo 'path:'. $path;
$_GET = getGET(); $_GET = getGET();
@ -48,7 +79,7 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
http_response_code($re['statusCode']); http_response_code($re['statusCode']);
if ($re['isBase64Encoded']) echo base64_decode($re['body']); if ($re['isBase64Encoded']) echo base64_decode($re['body']);
else echo $re['body']; else echo $re['body'];
} elseif (isset($_SERVER['DOCUMENT_ROOT'])&&substr($_SERVER['DOCUMENT_ROOT'], 0, 13)==='/home/runner/') { } elseif ('Replit'==$platform) {
include 'platform/Replit.php'; include 'platform/Replit.php';
$path = getpath(); $path = getpath();
@ -98,6 +129,7 @@ function main_handler($event, $context)
unset($_GET); unset($_GET);
unset($_COOKIE); unset($_COOKIE);
unset($_SERVER); unset($_SERVER);
writebackPlatform('SCF');
GetGlobalVariable($event); GetGlobalVariable($event);
//echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>'; //echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>';
$path = GetPathSetting($event, $context); $path = GetPathSetting($event, $context);
@ -108,7 +140,7 @@ function main_handler($event, $context)
// Aliyun FC & Huawei FG & Baidu CFC // Aliyun FC & Huawei FG & Baidu CFC
function handler($event, $context) function handler($event, $context)
{ {
if (isset($_SERVER['FC_FUNC_CODE_PATH'])) { if ('FC'==$platform) {
// Aliyun FC // Aliyun FC
set_error_handler("myErrorHandler"); set_error_handler("myErrorHandler");
$tmp = array( $tmp = array(
@ -127,6 +159,7 @@ function handler($event, $context)
unset($_GET); unset($_GET);
unset($_COOKIE); unset($_COOKIE);
unset($_SERVER); unset($_SERVER);
writebackPlatform('FC');
GetGlobalVariable($event); GetGlobalVariable($event);
$path = GetPathSetting($event, $context); $path = GetPathSetting($event, $context);
@ -134,7 +167,7 @@ function handler($event, $context)
return new RingCentral\Psr7\Response($re['statusCode'], $re['headers'], ($re['isBase64Encoded']?base64_decode($re['body']):$re['body'])); return new RingCentral\Psr7\Response($re['statusCode'], $re['headers'], ($re['isBase64Encoded']?base64_decode($re['body']):$re['body']));
} elseif (isset($_SERVER['RUNTIME_LOG_PATH']) && $_SERVER['RUNTIME_LOG_PATH']=='/home/snuser/log') { } elseif ('FG'==$platform) {
// Huawei FG // Huawei FG
global $contextUserData; global $contextUserData;
$contextUserData = $context; $contextUserData = $context;
@ -149,13 +182,14 @@ function handler($event, $context)
unset($_GET); unset($_GET);
unset($_COOKIE); unset($_COOKIE);
unset($_SERVER); unset($_SERVER);
writebackPlatform('FG');
GetGlobalVariable($event); GetGlobalVariable($event);
//echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>'; //echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>';
$path = GetPathSetting($event, $context); $path = GetPathSetting($event, $context);
return main($path); return main($path);
} elseif ($_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') { } elseif ('CFC'==$platform) {
// Baidu CFC // Baidu CFC
//$html = '<pre>'. json_encode($event, JSON_PRETTY_PRINT).'</pre>'; //$html = '<pre>'. json_encode($event, JSON_PRETTY_PRINT).'</pre>';
//$html .= '<pre>'. json_encode($context, JSON_PRETTY_PRINT).'</pre>'; //$html .= '<pre>'. json_encode($context, JSON_PRETTY_PRINT).'</pre>';
@ -169,6 +203,7 @@ function handler($event, $context)
unset($_GET); unset($_GET);
unset($_COOKIE); unset($_COOKIE);
unset($_SERVER); unset($_SERVER);
writebackPlatform('CFC');
GetGlobalVariable($event); GetGlobalVariable($event);
//echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>'; //echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>';
$path = GetPathSetting($event, $context); $path = GetPathSetting($event, $context);

View File

@ -67,7 +67,6 @@ function GetPathSetting($event, $context)
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']; $_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
$_SERVER['referhost'] = explode('/', $event['headers']['Referer'][0])[2]; $_SERVER['referhost'] = explode('/', $event['headers']['Referer'][0])[2];
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['If-Modified-Since'][0]; $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['If-Modified-Since'][0];
$_SERVER['FC_FUNC_CODE_PATH'] = getenv('FC_FUNC_CODE_PATH');
$_SERVER['REQUEST_METHOD'] = $event['method']; $_SERVER['REQUEST_METHOD'] = $event['method'];
return $path; return $path;
//return spurlencode($path, '/'); //return spurlencode($path, '/');

View File

@ -75,7 +75,6 @@ function GetPathSetting($event, $context)
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f' $_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since']; $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since'];
$_SERVER['REQUEST_METHOD'] = $event['httpMethod']; $_SERVER['REQUEST_METHOD'] = $event['httpMethod'];
$_SERVER['RUNTIME_LOG_PATH'] = '/home/snuser/log';
return $path; return $path;
} }

View File

@ -75,7 +75,6 @@ function GetPathSetting($event, $context)
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f' $_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since']; $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since'];
$_SERVER['REQUEST_METHOD'] = $event['httpMethod']; $_SERVER['REQUEST_METHOD'] = $event['httpMethod'];
$_SERVER['RUNTIME_LOG_PATH'] = '/home/snuser/log';
return $path; return $path;
} }

View File

@ -4,7 +4,7 @@ function getpath()
{ {
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($_SERVER['HTTP_ACCEPT_LANGUAGE'],';')[0],',')[0]); $_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($_SERVER['HTTP_ACCEPT_LANGUAGE'],';')[0],',')[0]);
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR']; if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
if (isset($_SERVER['HTTP_FLY_CLIENT_IP'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_FLY_CLIENT_IP']; if (isset($_SERVER['HTTP_FLY_CLIENT_IP'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_FLY_CLIENT_IP']; // Glitch
if ($_SERVER['HTTP_FLY_FORWARDED_PROTO']!='') $_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_FLY_FORWARDED_PROTO']; if ($_SERVER['HTTP_FLY_FORWARDED_PROTO']!='') $_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_FLY_FORWARDED_PROTO'];
if ($_SERVER['HTTP_X_FORWARDED_PROTO']!='') { if ($_SERVER['HTTP_X_FORWARDED_PROTO']!='') {
$tmp = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0]; $tmp = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0];

View File

@ -60,7 +60,6 @@ function GetPathSetting($event, $context)
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f' $_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since']; $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since'];
$_SERVER['REQUEST_METHOD'] = $event['httpMethod']; $_SERVER['REQUEST_METHOD'] = $event['httpMethod'];
$_SERVER['USER'] = 'qcloud';
return $path; return $path;
} }

View File

@ -60,7 +60,6 @@ function GetPathSetting($event, $context)
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f' $_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since']; $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since'];
$_SERVER['REQUEST_METHOD'] = $event['httpMethod']; $_SERVER['REQUEST_METHOD'] = $event['httpMethod'];
$_SERVER['USER'] = 'qcloud';
return $path; return $path;
} }

View File

@ -21,7 +21,6 @@ function getpath()
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p); if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
else $path = $_SERVER['REQUEST_URI']; else $path = $_SERVER['REQUEST_URI'];
$path = path_format( substr($path, strlen($_SERVER['base_path'])) ); $path = path_format( substr($path, strlen($_SERVER['base_path'])) );
$_SERVER['DOCUMENT_ROOT'] = '/var/task/user';
return $path; return $path;
} }

View File

@ -21,7 +21,6 @@ function getpath()
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p); if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
else $path = $_SERVER['REQUEST_URI']; else $path = $_SERVER['REQUEST_URI'];
$path = path_format( substr($path, strlen($_SERVER['base_path'])) ); $path = path_format( substr($path, strlen($_SERVER['base_path'])) );
$_SERVER['DOCUMENT_ROOT'] = '/var/task/user';
return $path; return $path;
} }