diff --git a/common.php b/common.php index f7ead2891be2fbcde5798fc88ab77118125ca471..c0746cdff98223bc141fc4ec2098100ee3260112 100644 --- a/common.php +++ b/common.php @@ -198,6 +198,13 @@ function main($path) $url = path_format($_SERVER['PHP_SELF'] . '/'); return output('', 302, [ 'Location' => $url ]); } + if (isset($_GET['WaitFunction'])) { + $response = WaitFunction($_GET['WaitFunction']); + //var_dump($response); + if ($response===true) return output("ok", 200); + elseif ($response===false) return output("", 206); + else return $response; + } $_SERVER['sitename'] = getConfig('sitename'); if (empty($_SERVER['sitename'])) $_SERVER['sitename'] = getconstStr('defaultSitename'); @@ -295,6 +302,7 @@ function main($path) return $drive->bigfileupload($path1); } } + if ($_SERVER['admin']) { $tmp = adminoperate($path); if ($tmp['statusCode'] > 0) { @@ -800,9 +808,9 @@ function get_timezone($timezone = '8') return $timezones[$timezone]; } -function message($message, $title = 'Message', $statusCode = 200) +function message($message, $title = 'Message', $statusCode = 200, $wainstat = 0) { - return output(' + $html = ' @@ -810,14 +818,61 @@ function message($message, $title = 'Message', $statusCode = 200)

' . $title . '

' . getconstStr('Back') . getconstStr('Home') . ' -

+

'; + if ($wainstat) { + $html .= ' +
+ '; + } else { + $html .= ' + '; + } + $html .= ' -', $statusCode); +'; + return output($html, $statusCode); } function needUpdate() @@ -1109,12 +1164,13 @@ function EnvOpt($needUpdate = 0) if (api_error($response)) { $html = api_error_msg($response); $title = 'Error'; + return message($html, $title, 400); } else { //WaitSCFStat(); - $html .= getconstStr('UpdateSuccess') . '
' . getconstStr('Back') . ''; + $html .= getconstStr('UpdateSuccess') . '
' . getconstStr('Back') . ''; $title = getconstStr('Setup'); + return message($html, $title, 202, 1); } - return message($html, $title); } if (isset($_POST['submit1'])) { $_SERVER['disk_oprating'] = ''; @@ -1127,11 +1183,11 @@ function EnvOpt($needUpdate = 0) $f = substr($v, 0, 1); if (strlen($v)==1) $v .= '_'; if (isCommonEnv($v)) { - return message('Do not input ' . $envs . '
' . getconstStr('Back') . '', 'Error', 201); + return message('Do not input ' . $envs . '
' . getconstStr('Back') . '', 'Error', 400); } elseif (!(('a'<=$f && $f<='z') || ('A'<=$f && $f<='Z'))) { - return message('' . getconstStr('Back') . '', 'Please start with letters', 201); + return message('' . getconstStr('Back') . '', 'Please start with letters', 400); } elseif (getConfig($v)) { - return message('' . getconstStr('Back') . '', 'Same tag', 201); + return message('' . getconstStr('Back') . '', 'Same tag', 400); } else { $tmp[$k] = $v; } @@ -1139,7 +1195,7 @@ function EnvOpt($needUpdate = 0) if ($k=='disktag_sort') { $td = implode('|', json_decode($v)); if (strlen($td)==strlen(getConfig('disktag'))) $tmp['disktag'] = $td; - else return message('Something wrong.'); + else return message('Something wrong.', 'ERROR', 400); } if ($k == 'disk') $_SERVER['disk_oprating'] = $v; } @@ -1156,12 +1212,16 @@ function EnvOpt($needUpdate = 0) if (api_error($response)) { $html = api_error_msg($response); $title = 'Error'; + return message($html, $title, 409); } else { $html .= getconstStr('Success') . '!
- ' . getconstStr('Back') . ''; + ' . getconstStr('Back') . ' + '; $title = getconstStr('Setup'); + return message($html, $title, 200, 1); } - return message($html, $title); } if (isset($_POST['config_b'])) { if (!$_POST['pass']) return output("{\"Error\": \"No admin pass\"}", 403); @@ -1233,7 +1293,7 @@ function EnvOpt($needUpdate = 0) if (api_error($response)) { return message(api_error_msg($response) . "" . getconstStr('Back') . "", "Error", 403); } else { - return message("Success" . getconstStr('Back') . "", "Success", 200); + return message("Success" . getconstStr('Back') . "", "Success", 200, 1); } } else { return message("Old pass error" . getconstStr('Back') . "", "Error", 403); diff --git a/conststr.php b/conststr.php index 6a3af61f945e8dcce767c8cc2312b2493c14ff3e..2df6ef5d67535fd3d54a9ec790e9a90468b6edcf 100644 --- a/conststr.php +++ b/conststr.php @@ -1072,11 +1072,11 @@ $constStr = [ 'ar-sa' => 'أكد بي إتش بي قابل للكتابة', ], 'MakesuerRewriteOn' => [ - 'en-us' => 'Plase make sure the RewriteEngine is On.', - 'zh-cn' => '确认重写(伪静态)功能启用。', - 'zh-tw' => '確認重寫(偽靜態)功能啟用。', - 'ja' => '書き換え(擬似静的)機能が有効になっていることを確認します。', - 'ko-kr' => '다시 쓰기 (의사 정적) 기능이 활성화되어 있는지 확인하십시오.', + 'en-us' => 'Plase make sure the RewriteEngine is On', + 'zh-cn' => '确认重写(伪静态)功能启用', + 'zh-tw' => '確認重寫(偽靜態)功能啟用', + 'ja' => '書き換え(擬似静的)機能が有効になっていることを確認します', + 'ko-kr' => '다시 쓰기 (의사 정적) 기능이 활성화되어 있는지 확인하십시오', 'fa' => 'لطفاً مطمئن شوید که RewriteEngine روشن است.', 'ar-sa' => 'يؤكد أن الكتابة يمكن أن تكون وظيفة شبه استاتي', ], diff --git a/disk/Aliyundrive.php b/disk/Aliyundrive.php index 8dfa7313025c4812559df9a28b9309e7a29711b0..148b375c7f3cc8c62f0783da4b95be3f308b32c4 100644 --- a/disk/Aliyundrive.php +++ b/disk/Aliyundrive.php @@ -629,8 +629,19 @@ class Aliyundrive { $title = 'Error'; return message($html, $title, 201); } else { - $str .= ''; - return message($str, getconstStr('WaitJumpIndex'), 201); + $str .= ' +'; + return message($str, getconstStr('WaitJumpIndex'), 201, 1); } } if (isset($_GET['SelectDrive'])) { @@ -691,17 +702,18 @@ class Aliyundrive { + return true; + } + '; - return message($html, $title, 201); + return message($html, $title, 201, 1); } if (isset($_GET['install0']) && $_POST['disktag_add']!='') { $_POST['disktag_add'] = preg_replace('/[^0-9a-zA-Z|_]/i', '', $_POST['disktag_add']); @@ -737,7 +749,7 @@ class Aliyundrive { if (api_error($response)) { $html = api_error_msg($response); $title = 'Error'; - return message($html, $title, 201); + return message($html, $title, 400); } else { $title = 'Refresh token'; $html = ' @@ -756,9 +768,10 @@ class Aliyundrive { } return true; } + var status = "' . $response['status'] . '"; '; - return message($html, $title, 201); + return message($html, $title, 201, 1); } } diff --git a/disk/Onedrive.php b/disk/Onedrive.php index 426397da66fdc0358923cf2b290852049f834d72..2efcfb89618223dae49e50b4003deb3b7668a60a 100644 --- a/disk/Onedrive.php +++ b/disk/Onedrive.php @@ -504,14 +504,23 @@ class Onedrive { $title = 'Error'; return message($html, $title, 201); } else { - $str .= ' - '; - return message($str, getconstStr('WaitJumpIndex'), 201); + return message($html, getconstStr('WaitJumpIndex'), 201, 1); } } @@ -607,9 +616,19 @@ class Onedrive { return message($html, $title, 201); } else { savecache('access_token', $ret['access_token'], $this->disktag, $ret['expires_in'] - 60); - $str .= ' - '; - return message($str, getconstStr('Wait') . ' 3s', 201); + $html .= ''; + return message($html, getconstStr('Wait') . ' 3s', 201, 1); } } return message('
' . json_encode(json_decode($tmp['body']), JSON_PRETTY_PRINT) . '
', $tmp['stat']); @@ -639,7 +658,7 @@ class Onedrive { $f = substr($_POST['disktag_add'], 0, 1); if (strlen($_POST['disktag_add'])==1) $_POST['disktag_add'] .= '_'; if (isCommonEnv($_POST['disktag_add'])) { - return message('Do not input ' . $envs . '
', 'Error', 201); + return message('Do not input ' . $envs . '
', 'Error', 400); } elseif (!(('a'<=$f && $f<='z') || ('A'<=$f && $f<='Z'))) { return message('Please start with letters
', 'Error', 201); + ', 'Error', 400); } $tmp = null; @@ -673,12 +692,26 @@ class Onedrive { if (api_error($response)) { $html = api_error_msg($response); $title = 'Error'; + return message($html, $title, 400); } else { $title = getconstStr('MayinEnv'); - $html = getconstStr('Wait') . ' 3s'; - if ($_POST['Drive_ver']=='Sharelink') $html = getconstStr('Wait') . ' 3s'; + $html = getconstStr('Wait'); + if ($_POST['Drive_ver']!='Sharelink') $url .= '?install1&disktag=' . $_GET['disktag'] . '&AddDisk=' . $_POST['Drive_ver']; + $html .= ''; + return message($html, $title, 201, 1); } - return message($html, $title, 201); + } } diff --git a/platform/AliyunFC.php b/platform/AliyunFC.php index 2f05deb096c3838f9bbcd210666a49045f096284..ad27a9c2b68427e9c9dab4bae7b9fb096ceb54bf 100644 --- a/platform/AliyunFC.php +++ b/platform/AliyunFC.php @@ -497,3 +497,7 @@ function myErrorHandler($errno, $errstr, $errfile, $errline) { } return true; } + +function WaitFunction() { + return true; +} diff --git a/platform/BaiduCFC.php b/platform/BaiduCFC.php index 6fc4db26ffb5033cd272cf2e5be24929a6ab28b3..e9fbcbbcb47a1e9a82c1fa99147fde01e0497ca8 100644 --- a/platform/BaiduCFC.php +++ b/platform/BaiduCFC.php @@ -431,3 +431,7 @@ function addFileToZip($zip, $rootpath, $path = '') } @closedir($path); } + +function WaitFunction() { + return true; +} diff --git a/platform/Heroku.php b/platform/Heroku.php index d06801e2eb996ee432b500db1143d604a5890f30..a096efa6c6b6fa8b44c8ff26e820367dd59bb63e 100644 --- a/platform/Heroku.php +++ b/platform/Heroku.php @@ -1,4 +1,5 @@ 'success' ] ); } + +function WaitFunction() { + return true; +} diff --git a/platform/TencentSCF_env.php b/platform/TencentSCF_env.php index 49bb0f89101c0864e430222c399e8addeb25488a..5bcc2df2918441ff8a1963dc52c931f06aea4b35 100644 --- a/platform/TencentSCF_env.php +++ b/platform/TencentSCF_env.php @@ -454,6 +454,14 @@ function setConfigResponse($response) return json_decode( $response, true )['Response']; } +function WaitFunction() { + //$trynum = 0; + //while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']!='Active' ) echo ' +//'.++$trynum; + if ( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']=='Active' ) return true; + else return false; +} + function updateProgram($function_name, $Region, $Namespace, $SecretId, $SecretKey, $source) { $secretId = $SecretId; diff --git a/platform/TencentSCF_file.php b/platform/TencentSCF_file.php index 3ffea06aeaa7159199bf6336b43a5dc00d834377..1a0f25634c7c62c70bf2cbd042dc096a971d61e3 100644 --- a/platform/TencentSCF_file.php +++ b/platform/TencentSCF_file.php @@ -645,3 +645,8 @@ function addFileToZip($zip, $rootpath, $path = '') } @closedir($path); } + +function WaitFunction() { + if ( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']=='Active' ) return true; + else return false; +} diff --git a/platform/Vercel.php b/platform/Vercel.php index 3f380872eec105d8eccccdc6d6dbb44027449fc9..7963add13fc0fface660d1150ae017e45db0f894 100644 --- a/platform/Vercel.php +++ b/platform/Vercel.php @@ -75,7 +75,7 @@ function getConfig($str, $disktag = '') if (isset($env[$str])) { if (isBase64Env($str)) return base64y_decode($env[$str]); else return $env[$str]; - } + } } else { if (isBase64Env($str)) return base64y_decode(getenv($str)); else return getenv($str); @@ -112,7 +112,9 @@ function setConfig($arr, $disktag = '') $operatedisk = 1; } elseif ($k=='disktag_copy') { $newtag = $v . '_' . date("Ymd_His"); - $tmp[$newtag] = getConfig($v); + $tagvalue = getConfig($v); + if (is_array($tagvalue)) $tmp[$newtag] = json_encode($tagvalue); + else $tmp[$newtag] = $tagvalue; array_push($disktags, $newtag); $operatedisk = 1; } elseif ($k=='disktag_rename' || $k=='disktag_newname') { @@ -134,7 +136,9 @@ function setConfig($arr, $disktag = '') else array_push($tags, $tag); } $tmp['disktag'] = implode('|', $tags); - $tmp[$arr['disktag_newname']] = getConfig($arr['disktag_rename']); + $tagvalue = getConfig($arr['disktag_rename']); + if (is_array($tagvalue)) $tmp[$arr['disktag_newname']] = json_encode($tagvalue); + else $tmp[$arr['disktag_newname']] = $tagvalue; $tmp[$arr['disktag_rename']] = null; } else { $disktags = array_unique($disktags); @@ -157,49 +161,39 @@ function install() $tmp['admin'] = $_POST['admin']; //$tmp['language'] = $_POST['language']; $tmp['timezone'] = $_COOKIE['timezone']; - $APIKey = getConfig('APIKey'); - if ($APIKey=='') { - $APIKey = $_POST['APIKey']; - $tmp['APIKey'] = $APIKey; - } - - $projectPath = splitlast(__DIR__, "/")[0]; - //$html .= file_get_contents($projectPath . "/.data/config.php") . "
";GET /v5/now/deployments /v8/projects/:id/env - $token = $tmp['APIKey']; - $header["Authorization"] = "Bearer " . $token; - $header["Content-Type"] = "application/json"; - $aliases = json_decode(curl("GET", "https://api.vercel.com/v3/now/aliases", "", $header)['body'], true); - $host = splitfirst($_SERVER["host"], "//")[1]; - foreach ($aliases["aliases"] as $key => $aliase) { - if ($host==$aliase["alias"]) $projectId = $aliase["projectId"]; - } - //$envs = json_decode(curl("GET", "https://api.vercel.com/v8/projects/" . $projectId . "/env", "", $header)['body'], true); + $APIKey = $_POST['APIKey']; + //if ($APIKey=='') { + // $APIKey = getConfig('APIKey'); + //} + $tmp['APIKey'] = $APIKey; + $token = $APIKey; + $header["Authorization"] = "Bearer " . $token; + $header["Content-Type"] = "application/json"; + $aliases = json_decode(curl("GET", "https://api.vercel.com/v3/now/aliases", "", $header)['body'], true); + $host = splitfirst($_SERVER["host"], "//")[1]; + foreach ($aliases["aliases"] as $key => $aliase) { + if ($host==$aliase["alias"]) $projectId = $aliase["projectId"]; + } $tmp['HerokuappId'] = $projectId; - $response = json_decode(setVercelConfig($tmp, $projectId, $APIKey)['body'], true); + + $response = json_decode(setVercelConfig($tmp, $projectId, $APIKey), true); if (api_error($response)) { $html = api_error_msg($response); $title = 'Error'; + return message($html, $title, 400); } else { - return output(' - - ', 302); + '; + return message($html, $title, 201, 1);*/ + $data["dplId"] = $response['status']; + return output(json_encode($data), 201); } - return message($html, $title, 201); } } if ($_GET['install0']) { @@ -210,14 +204,16 @@ language:
'; $html .= '
'; } - if (getConfig('APIKey')=='') $html .= ' + //if (getConfig('APIKey')=='') + $html .= '
' . getconstStr('Create') . ' token
-
'; +
'; $html .= '

'; $html .= ' +
'; $title = getconstStr('SelectLanguage'); return message($html, $title, 201); } - if (substr($_SERVER["host"], -10)=="vercel.app") { - $html .= '' . getconstStr('ClickInstall') . ', ' . getconstStr('LogintoBind'); - $html .= "
Remember: you MUST wait 30-60s after each operate / do some change, that make sure Vercel has done the building
" ; - } else { - $html.= "Please visit form *.vercel.app"; - } + if (substr($_SERVER["host"], -10)=="vercel.app") { + $html .= '' . getconstStr('ClickInstall') . ', ' . getconstStr('LogintoBind'); + $html .= "
Remember: you MUST wait 30-60s after each operate / do some change, that make sure Vercel has done the building
" ; + } else { + $html.= "Please visit form *.vercel.app"; + } $title = 'Install'; return message($html, $title, 201); } @@ -265,52 +305,54 @@ language:
'; // POST /v8/projects/:id/env function setVercelConfig($envs, $appId, $token) { - $url = "https://api.vercel.com/v8/projects/" . $appId . "/env"; - $header["Authorization"] = "Bearer " . $token; - $header["Content-Type"] = "application/json"; - $response = curl("GET", $url, "", $header); - $result = json_decode($response['body'], true); - foreach ($result["envs"] as $key => $value) { - $existEnvs[$value["key"]] = $value["id"]; - } - $response = null; - foreach ($envs as $key => $value) { - $tmp = null; - $tmp["type"] = "encrypted"; - $tmp["key"] = $key; - $tmp["value"] = $value; - $tmp["target"] = [ "development", "production", "preview" ]; - if (isset($existEnvs[$key])) { - if ($value) $response = curl("PATCH", $url . "/" . $existEnvs[$key], json_encode($tmp), $header); - else $response = curl("DELETE", $url . "/" . $existEnvs[$key], "", $header); - } else { - if ($value) $response = curl("POST", $url, json_encode($tmp), $header); - } - //echo $key . ":" . $value . ", " . json_encode($response, JSON_PRETTY_PRINT) . "
"; - } - return VercelUpdate($appId, $token); - //return $response; + $url = "https://api.vercel.com/v8/projects/" . $appId . "/env"; + $header["Authorization"] = "Bearer " . $token; + $header["Content-Type"] = "application/json"; + $response = curl("GET", $url, "", $header); + $result = json_decode($response['body'], true); + foreach ($result["envs"] as $key => $value) { + $existEnvs[$value["key"]] = $value["id"]; + } + $response = null; + foreach ($envs as $key => $value) { + $tmp = null; + $tmp["type"] = "encrypted"; + $tmp["key"] = $key; + $tmp["value"] = $value; + $tmp["target"] = [ "development", "production", "preview" ]; + if (isset($existEnvs[$key])) { + if ($value) $response = curl("PATCH", $url . "/" . $existEnvs[$key], json_encode($tmp), $header); + else $response = curl("DELETE", $url . "/" . $existEnvs[$key], "", $header); + } else { + if ($value) $response = curl("POST", $url, json_encode($tmp), $header); + } + //echo $key . ":" . $value . ", " . json_encode($response, JSON_PRETTY_PRINT) . "
"; + } + return VercelUpdate($appId, $token); + //return $response; } function VercelUpdate($appId, $token, $sourcePath = "") { - $url = "https://api.vercel.com/v12/now/deployments"; - $header["Authorization"] = "Bearer " . $token; - $header["Content-Type"] = "application/json"; - $data["name"] = "OneManager"; - $data["project"] = $appId; - $data["target"] = "production"; - $data["routes"][0]["src"] = "/(.*)"; - $data["routes"][0]["dest"] = "/api/index.php"; - $data["functions"]["api/index.php"]["runtime"] = "vercel-php@0.4.0"; - if ($sourcePath=="") $sourcePath = splitlast(splitlast(__DIR__, "/")[0], "/")[0]; - //echo $sourcePath . "
"; - getEachFiles($file, $sourcePath); - $data["files"] = $file; + $url = "https://api.vercel.com/v12/now/deployments"; + $header["Authorization"] = "Bearer " . $token; + $header["Content-Type"] = "application/json"; + $data["name"] = "OneManager"; + $data["project"] = $appId; + $data["target"] = "production"; + $data["routes"][0]["src"] = "/(.*)"; + $data["routes"][0]["dest"] = "/api/index.php"; + $data["functions"]["api/index.php"]["runtime"] = "vercel-php@0.4.0"; + if ($sourcePath=="") $sourcePath = splitlast(splitlast(__DIR__, "/")[0], "/")[0]; + //echo $sourcePath . "
"; + getEachFiles($file, $sourcePath); + $data["files"] = $file; - //echo json_encode($data, JSON_PRETTY_PRINT) . " ,data
"; - $response = curl("POST", $url, json_encode($data), $header); - return $response["body"]; + //echo json_encode($data, JSON_PRETTY_PRINT) . " ,data
"; + $response = curl("POST", $url, json_encode($data), $header); + $result = json_decode($response["body"], true); + $result['status'] = $result['id']; + return json_encode($result); } function getEachFiles(&$file, $base, $path = "") @@ -321,13 +363,13 @@ function getEachFiles(&$file, $base, $path = "") while($filename=readdir($handler)) { if($filename != '.' && $filename != '..' && $filename != '.git'){ $fromfile = path_format($base . "/" . $path . "/" . $filename); - //echo $fromfile . "
"; + //echo $fromfile . "
"; if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归 $response = getEachFiles($file, $base, path_format($path . "/" . $filename)); if (api_error(setConfigResponse($response))) return $response; }else{ - $tmp['file'] = path_format($path . "/" . $filename); - $tmp['data'] = file_get_contents($fromfile); + $tmp['file'] = path_format($path . "/" . $filename); + $tmp['data'] = file_get_contents($fromfile); $file[] = $tmp; } } @@ -379,9 +421,25 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = break; } } - //echo $outPath . "
"; + //echo $outPath . "
"; //error_log1($outPath); if ($outPath=='') return '{"error":{"message":"no outpath"}}'; return VercelUpdate(getConfig('HerokuappId'), getConfig('APIKey'), $outPath); } + +function WaitFunction($deployid) { + $header["Authorization"] = "Bearer " . getConfig('APIKey'); + $header["Content-Type"] = "application/json"; + $url = "https://api.vercel.com/v11/now/deployments/" . $deployid; + $response = curl("GET", $url, "", $header); + if ($response['stat']==200) { + $result = json_decode($response['body'], true); + if ($result['readyState']=="READY") return true; + if ($result['readyState']=="ERROR") return $response; + return false; + } else { + $response['body'] .= $url; + return $response; + } +}