From 37d2697096361cdb6d7a35a6676f8a0709369284 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 12 May 2023 15:21:25 +0000 Subject: [PATCH] check platform --- common.php | 15 ++-------- index.php | 55 +++++++++++++++++++++++++++++------- platform/AliyunFC.php | 1 - platform/HuaweiFG_env.php | 1 - platform/HuaweiFG_file.php | 1 - platform/Normal.php | 2 +- platform/TencentSCF_env.php | 1 - platform/TencentSCF_file.php | 1 - platform/Vercel.php | 1 - platform/Vercel_env.php | 1 - 10 files changed, 49 insertions(+), 30 deletions(-) diff --git a/common.php b/common.php index 9767cd7..844b202 100644 --- a/common.php +++ b/common.php @@ -1,5 +1,6 @@ '; $canOneKeyUpate = 0; - if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') { - $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') { + if ('Normal'!=$platform) { $canOneKeyUpate = 1; } else { $tmp = time(); @@ -1920,7 +1911,7 @@ output: } $frame .= ' Github -HIT Gitlab

+ HIT Gitlab

'; if (!$canOneKeyUpate) { $frame .= ' diff --git a/index.php b/index.php index a37587c..f22a386 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,7 @@ '. json_encode($_SERVER, JSON_PRETTY_PRINT).''; //echo '
'. json_encode($_ENV, JSON_PRETTY_PRINT).'
'; -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'; else include 'platform/TencentSCF_env.php'; -} elseif (isset($_SERVER['FC_FUNC_CODE_PATH'])) { +} elseif ('FC'==$platform) { 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'; //else include 'platform/HuaweiFG_env.php'; echo 'FG' . PHP_EOL; -} elseif (isset($_SERVER['BCE_CFC_RUNTIME_NAME']) && $_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') { +} elseif ('CFC'==$platform) { include 'platform/BaiduCFC.php'; -} elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') { +} elseif ('Heroku'==$platform) { include 'platform/Heroku.php'; $path = getpath(); //echo 'path:'. $path; @@ -33,9 +62,11 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') { http_response_code($re['statusCode']); if ($re['isBase64Encoded']) echo base64_decode($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'; else include 'platform/Vercel.php'; + + writebackPlatform('Vercel'); $path = getpath(); //echo 'path:'. $path; $_GET = getGET(); @@ -48,7 +79,7 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') { http_response_code($re['statusCode']); if ($re['isBase64Encoded']) echo base64_decode($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'; $path = getpath(); @@ -98,6 +129,7 @@ function main_handler($event, $context) unset($_GET); unset($_COOKIE); unset($_SERVER); + writebackPlatform('SCF'); GetGlobalVariable($event); //echo '
'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'
'; $path = GetPathSetting($event, $context); @@ -108,7 +140,7 @@ function main_handler($event, $context) // Aliyun FC & Huawei FG & Baidu CFC function handler($event, $context) { - if (isset($_SERVER['FC_FUNC_CODE_PATH'])) { + if ('FC'==$platform) { // Aliyun FC set_error_handler("myErrorHandler"); $tmp = array( @@ -127,6 +159,7 @@ function handler($event, $context) unset($_GET); unset($_COOKIE); unset($_SERVER); + writebackPlatform('FC'); GetGlobalVariable($event); $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'])); - } elseif (isset($_SERVER['RUNTIME_LOG_PATH']) && $_SERVER['RUNTIME_LOG_PATH']=='/home/snuser/log') { + } elseif ('FG'==$platform) { // Huawei FG global $contextUserData; $contextUserData = $context; @@ -149,13 +182,14 @@ function handler($event, $context) unset($_GET); unset($_COOKIE); unset($_SERVER); + writebackPlatform('FG'); GetGlobalVariable($event); //echo '
'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'
'; $path = GetPathSetting($event, $context); return main($path); - } elseif ($_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') { + } elseif ('CFC'==$platform) { // Baidu CFC //$html = '
'. json_encode($event, JSON_PRETTY_PRINT).'
'; //$html .= '
'. json_encode($context, JSON_PRETTY_PRINT).'
'; @@ -169,6 +203,7 @@ function handler($event, $context) unset($_GET); unset($_COOKIE); unset($_SERVER); + writebackPlatform('CFC'); GetGlobalVariable($event); //echo '
'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'
'; $path = GetPathSetting($event, $context); diff --git a/platform/AliyunFC.php b/platform/AliyunFC.php index 65d0c91..c5848a6 100644 --- a/platform/AliyunFC.php +++ b/platform/AliyunFC.php @@ -67,7 +67,6 @@ function GetPathSetting($event, $context) $_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']; $_SERVER['referhost'] = explode('/', $event['headers']['Referer'][0])[2]; $_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']; return $path; //return spurlencode($path, '/'); diff --git a/platform/HuaweiFG_env.php b/platform/HuaweiFG_env.php index f2ecf6b..9cafd61 100644 --- a/platform/HuaweiFG_env.php +++ b/platform/HuaweiFG_env.php @@ -75,7 +75,6 @@ function GetPathSetting($event, $context) $_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f' $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since']; $_SERVER['REQUEST_METHOD'] = $event['httpMethod']; - $_SERVER['RUNTIME_LOG_PATH'] = '/home/snuser/log'; return $path; } diff --git a/platform/HuaweiFG_file.php b/platform/HuaweiFG_file.php index df4e426..48c7e3c 100644 --- a/platform/HuaweiFG_file.php +++ b/platform/HuaweiFG_file.php @@ -75,7 +75,6 @@ function GetPathSetting($event, $context) $_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f' $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since']; $_SERVER['REQUEST_METHOD'] = $event['httpMethod']; - $_SERVER['RUNTIME_LOG_PATH'] = '/home/snuser/log'; return $path; } diff --git a/platform/Normal.php b/platform/Normal.php index 454eb89..9aec393 100644 --- a/platform/Normal.php +++ b/platform/Normal.php @@ -4,7 +4,7 @@ function getpath() { $_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_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_X_FORWARDED_PROTO']!='') { $tmp = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0]; diff --git a/platform/TencentSCF_env.php b/platform/TencentSCF_env.php index 7ba565d..37edbb5 100644 --- a/platform/TencentSCF_env.php +++ b/platform/TencentSCF_env.php @@ -60,7 +60,6 @@ function GetPathSetting($event, $context) $_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f' $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since']; $_SERVER['REQUEST_METHOD'] = $event['httpMethod']; - $_SERVER['USER'] = 'qcloud'; return $path; } diff --git a/platform/TencentSCF_file.php b/platform/TencentSCF_file.php index 8db3f4c..468ef79 100644 --- a/platform/TencentSCF_file.php +++ b/platform/TencentSCF_file.php @@ -60,7 +60,6 @@ function GetPathSetting($event, $context) $_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f' $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since']; $_SERVER['REQUEST_METHOD'] = $event['httpMethod']; - $_SERVER['USER'] = 'qcloud'; return $path; } diff --git a/platform/Vercel.php b/platform/Vercel.php index 3d4239f..a808bc1 100644 --- a/platform/Vercel.php +++ b/platform/Vercel.php @@ -21,7 +21,6 @@ function getpath() if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p); else $path = $_SERVER['REQUEST_URI']; $path = path_format( substr($path, strlen($_SERVER['base_path'])) ); - $_SERVER['DOCUMENT_ROOT'] = '/var/task/user'; return $path; } diff --git a/platform/Vercel_env.php b/platform/Vercel_env.php index c0f3607..38ef0ce 100644 --- a/platform/Vercel_env.php +++ b/platform/Vercel_env.php @@ -21,7 +21,6 @@ function getpath() if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p); else $path = $_SERVER['REQUEST_URI']; $path = path_format( substr($path, strlen($_SERVER['base_path'])) ); - $_SERVER['DOCUMENT_ROOT'] = '/var/task/user'; return $path; }