Delete platform directory
parent
544035b07a
commit
791bcabe64
|
@ -1,547 +0,0 @@
|
||||||
<?php
|
|
||||||
// https://help.aliyun.com/document_detail/53252.html
|
|
||||||
// https://github.com/aliyun/fc-php-sdk/blob/master/src/AliyunFC/Client.php
|
|
||||||
|
|
||||||
function printInput($event, $context)
|
|
||||||
{
|
|
||||||
if (strlen(json_encode($event['body']))>500) $event['body']=substr($event['body'],0,strpos($event['body'],'base64')+30) . '...Too Long!...' . substr($event['body'],-50);
|
|
||||||
echo urldecode(json_encode($event, JSON_PRETTY_PRINT)) . '
|
|
||||||
|
|
||||||
' . urldecode(json_encode($context, JSON_PRETTY_PRINT)) . '
|
|
||||||
|
|
||||||
';
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetGlobalVariable($event)
|
|
||||||
{
|
|
||||||
$_GET = $event['queryString'];
|
|
||||||
foreach ($_GET as $k => $v) {
|
|
||||||
if ($v=='') $_GET[$k] = true;
|
|
||||||
}
|
|
||||||
$postbody = explode("&",$event['body']);
|
|
||||||
foreach ($postbody as $postvalues) {
|
|
||||||
$pos = strpos($postvalues,"=");
|
|
||||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
|
||||||
}
|
|
||||||
$cookiebody = explode("; ",$event['headers']['Cookie'][0]);
|
|
||||||
foreach ($cookiebody as $cookievalues) {
|
|
||||||
$pos = strpos($cookievalues,"=");
|
|
||||||
$_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetPathSetting($event, $context)
|
|
||||||
{
|
|
||||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($event['headers']['Accept-Language'][0],';')[0],',')[0]);
|
|
||||||
$_SERVER['accountId'] = $context['accountId'];
|
|
||||||
$_SERVER['region'] = $context['region'];
|
|
||||||
$_SERVER['service_name'] = $context['service']['name'];
|
|
||||||
$_SERVER['function_name'] = $context['function']['name'];
|
|
||||||
//$path = str_replace('%5D', ']', str_replace('%5B', '[', $event['path']));//%5B
|
|
||||||
//$path = $event['path'];
|
|
||||||
$path = $event['requestURI'];
|
|
||||||
if (strpos($path, '?')) $path = substr($path, 0, strpos($path, '?'));
|
|
||||||
$tmp = urldecode($event['requestURI']);
|
|
||||||
if (strpos($tmp, '?')) $tmp = substr($tmp, 0, strpos($tmp, '?'));
|
|
||||||
if ($path=='/'||$path=='') {
|
|
||||||
$_SERVER['base_path'] = $tmp;
|
|
||||||
} else {
|
|
||||||
$tmp = str_replace('&', '&', $tmp);
|
|
||||||
while ($tmp!=urldecode($tmp)) $tmp = urldecode($tmp);
|
|
||||||
$tmp1 = urldecode($event['path']);
|
|
||||||
while ($tmp1!=urldecode($tmp1)) $tmp1 = urldecode($tmp1);
|
|
||||||
$_SERVER['base_path'] = substr($tmp, 0, strlen($tmp)-strlen($tmp1)+1);
|
|
||||||
//$_SERVER['base_path'] = substr($tmp, 0, strlen(urldecode($event['path'])));
|
|
||||||
}
|
|
||||||
$_SERVER['base_path'] = spurlencode($_SERVER['base_path'], '/');
|
|
||||||
//$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
|
|
||||||
$_SERVER['REMOTE_ADDR'] = $event['clientIP'];
|
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = $event['headers']['X-Requested-With'][0];
|
|
||||||
if (isset($event['headers']['Authorization'])) {
|
|
||||||
$basicAuth = splitfirst(base64_decode(splitfirst($event['headers']['Authorization'][0], 'Basic ')[1]), ':');
|
|
||||||
$_SERVER['PHP_AUTH_USER'] = $basicAuth[0];
|
|
||||||
$_SERVER['PHP_AUTH_PW'] = $basicAuth[1];
|
|
||||||
}
|
|
||||||
$_SERVER['HTTP_HOST'] = $event['headers']['Host'][0];
|
|
||||||
$_SERVER['REQUEST_SCHEME'] = $event['headers']['X-Forwarded-Proto'][0];
|
|
||||||
$_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_SERVER_PATH'] = '/var/fc/runtime/php7.2';
|
|
||||||
return $path;
|
|
||||||
//return spurlencode($path, '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfig($str, $disktag = '')
|
|
||||||
{
|
|
||||||
if (isInnerEnv($str)) {
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$env = json_decode(getenv($disktag), true);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfig($arr, $disktag = '')
|
|
||||||
{
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$disktags = explode("|", getConfig('disktag'));
|
|
||||||
$diskconfig = json_decode(getenv($disktag), true);
|
|
||||||
$tmp = [];
|
|
||||||
$indisk = 0;
|
|
||||||
$operatedisk = 0;
|
|
||||||
foreach ($arr as $k => $v) {
|
|
||||||
if (isCommonEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
|
||||||
else $tmp[$k] = $v;
|
|
||||||
} elseif (isInnerEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
|
||||||
else $diskconfig[$k] = $v;
|
|
||||||
$indisk = 1;
|
|
||||||
} elseif ($k=='disktag_add') {
|
|
||||||
array_push($disktags, $v);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_del') {
|
|
||||||
$disktags = array_diff($disktags, [ $v ]);
|
|
||||||
$tmp[$v] = '';
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_copy') {
|
|
||||||
$newtag = $v . '_' . date("Ymd_His");
|
|
||||||
$tmp[$newtag] = getConfig($v);
|
|
||||||
array_push($disktags, $newtag);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
|
||||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
|
||||||
} else {
|
|
||||||
$tmp[$k] = json_encode($v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($indisk) {
|
|
||||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
|
||||||
ksort($diskconfig);
|
|
||||||
$tmp[$disktag] = json_encode($diskconfig);
|
|
||||||
}
|
|
||||||
if ($operatedisk) {
|
|
||||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
|
||||||
$tags = [];
|
|
||||||
foreach ($disktags as $tag) {
|
|
||||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
|
||||||
else array_push($tags, $tag);
|
|
||||||
}
|
|
||||||
$tmp['disktag'] = implode('|', $tags);
|
|
||||||
$tmp[$arr['disktag_newname']] = getConfig($arr['disktag_rename']);
|
|
||||||
$tmp[$arr['disktag_rename']] = '';
|
|
||||||
} else {
|
|
||||||
$disktags = array_unique($disktags);
|
|
||||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
|
||||||
if ($disktag_s!='') $tmp['disktag'] = substr($disktag_s, 0, -1);
|
|
||||||
else $tmp['disktag'] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// echo '正式设置:'.json_encode($tmp,JSON_PRETTY_PRINT).'
|
|
||||||
//';
|
|
||||||
$response = updateEnvironment($tmp, $_SERVER['accountId'], $_SERVER['region'], $_SERVER['service_name'], $_SERVER['function_name'], getConfig('AccessKeyID'), getConfig('AccessKeySecret'));
|
|
||||||
//WaitSCFStat();
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function install()
|
|
||||||
{
|
|
||||||
global $constStr;
|
|
||||||
if ($_GET['install2']) {
|
|
||||||
$tmp['admin'] = $_POST['admin'];
|
|
||||||
$response = setConfigResponse( setConfig($tmp) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
if (needUpdate()) {
|
|
||||||
OnekeyUpate();
|
|
||||||
return message('update to github version, reinstall.
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
</script>
|
|
||||||
<meta http-equiv="refresh" content="3;URL=' . $url . '">', 'Program updating', 201);
|
|
||||||
}
|
|
||||||
return output('Jump
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
</script>
|
|
||||||
<meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
|
|
||||||
}
|
|
||||||
if ($_GET['install1']) {
|
|
||||||
//if ($_POST['admin']!='') {
|
|
||||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
|
||||||
//$AccessKeyID = getConfig('AccessKeyID');
|
|
||||||
//if ($AccessKeyID=='') {
|
|
||||||
$AccessKeyID = $_POST['AccessKeyID'];
|
|
||||||
$tmp['AccessKeyID'] = $AccessKeyID;
|
|
||||||
//}
|
|
||||||
//$AccessKeySecret = getConfig('AccessKeySecret');
|
|
||||||
//if ($AccessKeySecret=='') {
|
|
||||||
$AccessKeySecret = $_POST['AccessKeySecret'];
|
|
||||||
$tmp['AccessKeySecret'] = $AccessKeySecret;
|
|
||||||
//}
|
|
||||||
$response = setConfigResponse( SetbaseConfig($tmp, $_SERVER['accountId'], $_SERVER['region'], $_SERVER['service_name'], $_SERVER['function_name'], $AccessKeyID, $AccessKeySecret) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
} else {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
|
||||||
<label>'.getconstStr('SetAdminPassword').':<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.admin.value==\'\') {
|
|
||||||
alert(\''.getconstStr('SetAdminPassword').'\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SetAdminPassword');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
if ($_GET['install0']) {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install1" method="post" onsubmit="return notnull(this);">
|
|
||||||
language:<br>';
|
|
||||||
foreach ($constStr['languages'] as $key1 => $value1) {
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
|
||||||
}
|
|
||||||
//if (getConfig('AccessKeyID')==''||getConfig('AccessKeySecret')=='')
|
|
||||||
$html .= '
|
|
||||||
<a href="https://usercenter.console.aliyun.com/?#/manage/ak" target="_blank">' . getconstStr('Create') . ' AccessKeyID & AccessKeySecret</a><br>
|
|
||||||
<label>AccessKeyID:<input name="AccessKeyID" type="text" placeholder="" size=""></label><br>
|
|
||||||
<label>AccessKeySecret:<input name="AccessKeySecret" type="password" placeholder="" size=""></label><br>';
|
|
||||||
$html .= '
|
|
||||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
var nowtime= new Date();
|
|
||||||
var timezone = 0-nowtime.getTimezoneOffset()/60;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie="timezone="+timezone+"; path=/; "+expires;
|
|
||||||
function changelanguage(str)
|
|
||||||
{
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=\'+str+\'; path=/; \'+expires;
|
|
||||||
location.href = location.href;
|
|
||||||
}
|
|
||||||
function notnull(t)
|
|
||||||
{';
|
|
||||||
//if (getConfig('AccessKeyID')==''||getConfig('AccessKeySecret')=='')
|
|
||||||
$html .= '
|
|
||||||
if (t.AccessKeyID.value==\'\') {
|
|
||||||
alert(\'input AccessKeyID\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.AccessKeySecret.value==\'\') {
|
|
||||||
alert(\'input SecretKey\');
|
|
||||||
return false;
|
|
||||||
}';
|
|
||||||
$html .= '
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SelectLanguage');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
$html .= '<a href="?install0">' . getconstStr('ClickInstall').'</a>, ' . getconstStr('LogintoBind');
|
|
||||||
$title = 'Install';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
function FCAPI2016($config, $Method, $data = '')
|
|
||||||
{
|
|
||||||
$accountId = $config['accountId'];
|
|
||||||
$region = $config['region'];
|
|
||||||
$service_name = $config['service_name'];
|
|
||||||
$function_name = $config['function_name'];
|
|
||||||
$AccessKeyID = $config['AccessKeyID'];
|
|
||||||
$AccessKeySecret = $config['AccessKeySecret'];
|
|
||||||
|
|
||||||
$host = $accountId . '.' . $region . '-internal.fc.aliyuncs.com';
|
|
||||||
$path = '/2016-08-15/services/' . $service_name . '/functions/' . $function_name;
|
|
||||||
$url = 'https://' . $host . $path;
|
|
||||||
|
|
||||||
$ContentMd5 = '';
|
|
||||||
$ContentType = 'application/json';
|
|
||||||
date_default_timezone_set('UTC'); // unset last timezone setting
|
|
||||||
$Date = substr(gmdate("r", time()), 0, -5) . 'GMT';
|
|
||||||
$CanonicalizedFCHeaders = '';
|
|
||||||
$CanonicalizedResource = $path;
|
|
||||||
|
|
||||||
$signaturestr = $Method . "\n" . $ContentMd5 . "\n" . $ContentType . "\n" . $Date . "\n" . $CanonicalizedFCHeaders . $CanonicalizedResource;
|
|
||||||
$signature = base64_encode(hash_hmac('sha256', $signaturestr, $AccessKeySecret, true));
|
|
||||||
|
|
||||||
$header['Host'] = $host;
|
|
||||||
$header['Date'] = $Date;
|
|
||||||
$header['Content-Type'] = $ContentType;
|
|
||||||
$header['Authorization'] = 'FC ' . $AccessKeyID . ':' . $signature;
|
|
||||||
$header['Content-Length'] = strlen($data);
|
|
||||||
|
|
||||||
//return curl($Method, $url, $data, $header)['body'];
|
|
||||||
$p = 0;
|
|
||||||
while ($response['stat']==0 && $p<3) {
|
|
||||||
$response = curl($Method, $url, $data, $header);
|
|
||||||
$p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($response['stat']==0) {
|
|
||||||
$tmp['ErrorCode'] = 'Network Error';
|
|
||||||
$tmp['ErrorMessage'] = 'Can not connect ' . $host;
|
|
||||||
return json_encode($tmp);
|
|
||||||
}
|
|
||||||
if ($response['stat']!=200) {
|
|
||||||
$tmp = json_decode($response['body'], true);
|
|
||||||
$tmp['ErrorMessage'] .= '<br>' . $response['stat'] . '<br>' . $signaturestr . '<br>' . json_encode($header) . PHP_EOL;
|
|
||||||
return json_encode($tmp);
|
|
||||||
}
|
|
||||||
return $response['body'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getfunctioninfo($config)
|
|
||||||
{
|
|
||||||
return FCAPI2016($config, 'GET');
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateEnvironment($Envs, $accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)
|
|
||||||
{
|
|
||||||
//print_r($Envs);
|
|
||||||
$config['accountId'] = $accountId;
|
|
||||||
$config['region'] = $region;
|
|
||||||
$config['service_name'] = $service_name;
|
|
||||||
$config['function_name'] = $function_name;
|
|
||||||
$config['AccessKeyID'] = $AccessKeyID;
|
|
||||||
$config['AccessKeySecret'] = $AccessKeySecret;
|
|
||||||
|
|
||||||
$tmp = json_decode(getfunctioninfo($config), true);
|
|
||||||
foreach ($tmp['environmentVariables'] as $key => $value ) {
|
|
||||||
$tmp_env[$key] = $value;
|
|
||||||
}
|
|
||||||
foreach ($Envs as $key1 => $value1) {
|
|
||||||
$tmp_env[$key1] = $value1;
|
|
||||||
}
|
|
||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
|
||||||
//ksort($tmp_env);
|
|
||||||
sortConfig($tmp_env);
|
|
||||||
|
|
||||||
$tmpdata['environmentVariables'] = $tmp_env;
|
|
||||||
return FCAPI2016($config, 'PUT', json_encode($tmpdata));
|
|
||||||
}
|
|
||||||
|
|
||||||
function SetbaseConfig($Envs, $accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)
|
|
||||||
{
|
|
||||||
$config['accountId'] = $accountId;
|
|
||||||
$config['region'] = $region;
|
|
||||||
$config['service_name'] = $service_name;
|
|
||||||
$config['function_name'] = $function_name;
|
|
||||||
$config['AccessKeyID'] = $AccessKeyID;
|
|
||||||
$config['AccessKeySecret'] = $AccessKeySecret;
|
|
||||||
|
|
||||||
$tmp = json_decode(getfunctioninfo($config), true);
|
|
||||||
foreach ($tmp['environmentVariables'] as $key => $value ) {
|
|
||||||
$tmp_env[$key] = $value;
|
|
||||||
}
|
|
||||||
foreach ($Envs as $key1 => $value1) {
|
|
||||||
$tmp_env[$key1] = $value1;
|
|
||||||
}
|
|
||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
|
||||||
ksort($tmp_env);
|
|
||||||
|
|
||||||
$tmpdata['description'] = 'Onedrive index and manager in Aliyun FC.';
|
|
||||||
$tmpdata['memorySize'] = 128;
|
|
||||||
$tmpdata['timeout'] = 30;
|
|
||||||
$tmpdata['environmentVariables'] = $tmp_env;
|
|
||||||
|
|
||||||
return FCAPI2016($config, 'PUT', json_encode($tmpdata));
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateProgram($accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret, $source)
|
|
||||||
{
|
|
||||||
$config['accountId'] = $accountId;
|
|
||||||
$config['region'] = $region;
|
|
||||||
$config['service_name'] = $service_name;
|
|
||||||
$config['function_name'] = $function_name;
|
|
||||||
$config['AccessKeyID'] = $AccessKeyID;
|
|
||||||
$config['AccessKeySecret'] = $AccessKeySecret;
|
|
||||||
|
|
||||||
$tmp = json_decode(getfunctioninfo($config), true);
|
|
||||||
|
|
||||||
$tmpdata['code']['zipFile'] = base64_encode( file_get_contents($source) );
|
|
||||||
|
|
||||||
return FCAPI2016($config, 'PUT', json_encode($tmpdata));
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error($response)
|
|
||||||
{
|
|
||||||
return isset($response['ErrorMessage']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error_msg($response)
|
|
||||||
{
|
|
||||||
return $response['ErrorCode'] . '<br>
|
|
||||||
' . $response['ErrorMessage'] . '<br><br>
|
|
||||||
|
|
||||||
accountId:' . $_SERVER['accountId'] . '<br>
|
|
||||||
region:' . $_SERVER['region'] . '<br>
|
|
||||||
service_name:' . $_SERVER['service_name'] . '<br>
|
|
||||||
function_name:' . $_SERVER['function_name'] . '<br>
|
|
||||||
|
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfigResponse($response)
|
|
||||||
{
|
|
||||||
return json_decode($response, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
|
||||||
{
|
|
||||||
$source = '/tmp/code.zip';
|
|
||||||
$outPath = '/tmp/';
|
|
||||||
|
|
||||||
if ($GitSource=='Github') {
|
|
||||||
// 从github下载对应tar.gz,并解压
|
|
||||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
|
||||||
} elseif ($GitSource=='HITGitlab') {
|
|
||||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
|
||||||
} else return json_encode(['ErrorMessage'=>'Git Source input Error!']);
|
|
||||||
$tarfile = '/tmp/github.tar.gz';
|
|
||||||
file_put_contents($tarfile, file_get_contents($url));
|
|
||||||
$phar = new PharData($tarfile);
|
|
||||||
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
|
||||||
|
|
||||||
// 获取解压出的目录名
|
|
||||||
$outPath = findIndexPath($outPath);
|
|
||||||
|
|
||||||
// 将目录中文件打包成zip
|
|
||||||
$zip = new ZipArchive();
|
|
||||||
if($zip->open($source, ZipArchive::CREATE)){
|
|
||||||
addFileToZip($zip, $outPath); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
|
|
||||||
$zip->close(); //关闭处理的zip文件
|
|
||||||
}
|
|
||||||
|
|
||||||
return updateProgram($_SERVER['accountId'], $_SERVER['region'], $_SERVER['service_name'], $_SERVER['function_name'], getConfig('AccessKeyID'), getConfig('AccessKeySecret'), $source);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addFileToZip($zip, $rootpath, $path = '')
|
|
||||||
{
|
|
||||||
if (substr($rootpath,-1)=='/') $rootpath = substr($rootpath, 0, -1);
|
|
||||||
if (substr($path,0,1)=='/') $path = substr($path, 1);
|
|
||||||
$handler=opendir(path_format($rootpath.'/'.$path)); //打开当前文件夹由$path指定。
|
|
||||||
while($filename=readdir($handler)){
|
|
||||||
if($filename != "." && $filename != ".."){//文件夹文件名字为'.'和‘..’,不要对他们进行操作
|
|
||||||
$nowname = path_format($rootpath.'/'.$path."/".$filename);
|
|
||||||
if(is_dir($nowname)){// 如果读取的某个对象是文件夹,则递归
|
|
||||||
addFileToZip($zip, $rootpath, $path."/".$filename);
|
|
||||||
}else{ //将文件加入zip对象
|
|
||||||
$zip->addFile($nowname);
|
|
||||||
$newname = $path."/".$filename;
|
|
||||||
if (substr($newname,0,1)=='/') $newname = substr($newname, 1);
|
|
||||||
$zip->renameName($nowname, $newname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@closedir($handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
function myErrorHandler($errno, $errstr, $errfile, $errline) {
|
|
||||||
if (!(error_reporting() & $errno)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
switch ($errno) {
|
|
||||||
case E_USER_ERROR:
|
|
||||||
$errInfo = array(
|
|
||||||
"errorMessage" => $errstr,
|
|
||||||
"errorType" => \ServerlessFC\friendly_error_type($errno),
|
|
||||||
"stackTrace" => array(
|
|
||||||
"file" => $errfile,
|
|
||||||
"line" => $errline,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
|
|
||||||
break;
|
|
||||||
default: // E_USER_WARNING | E_USER_NOTICE
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function WaitFunction() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeAuthKey() {
|
|
||||||
if ($_POST['AccessKeyID']!=''&&$_POST['AccessKeySecret']!='') {
|
|
||||||
$tmp['AccessKeyID'] = $_POST['AccessKeyID'];
|
|
||||||
$tmp['AccessKeySecret'] = $_POST['AccessKeySecret'];
|
|
||||||
$response = setConfigResponse( SetbaseConfig($tmp, $_SERVER['accountId'], $_SERVER['region'], $_SERVER['service_name'], $_SERVER['function_name'], $tmp['AccessKeyID'], $tmp['AccessKeySecret']) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 400);
|
|
||||||
} else {
|
|
||||||
$html = getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var i = 0;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$html = '
|
|
||||||
<form action="" method="post" onsubmit="return notnull(this);">
|
|
||||||
<a href="https://usercenter.console.aliyun.com/?#/manage/ak" target="_blank">' . getconstStr('Create') . ' AccessKeyID & AccessKeySecret</a><br>
|
|
||||||
<label>AccessKeyID:<input name="AccessKeyID" type="text" placeholder="" size=""></label><br>
|
|
||||||
<label>AccessKeySecret:<input name="AccessKeySecret" type="password" placeholder="" size=""></label><br>
|
|
||||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.AccessKeyID.value==\'\') {
|
|
||||||
alert(\'input AccessKeyID\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.AccessKeySecret.value==\'\') {
|
|
||||||
alert(\'input SecretKey\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
return message($html, 'Change platform Auth token or key', 200);
|
|
||||||
}
|
|
|
@ -1,486 +0,0 @@
|
||||||
<?php
|
|
||||||
// https://cloud.baidu.com/doc/CFC/s/jjwvz45ex
|
|
||||||
// https://cloud.baidu.com/doc/CFC/s/2jwvz44ns
|
|
||||||
|
|
||||||
function printInput($event, $context)
|
|
||||||
{
|
|
||||||
if (strlen(json_encode($event['body']))>500) $event['body']=substr($event['body'],0,strpos($event['body'],'base64')+30) . '...Too Long!...' . substr($event['body'],-50);
|
|
||||||
echo urldecode(json_encode($event, JSON_PRETTY_PRINT)) . '
|
|
||||||
|
|
||||||
' . urldecode(json_encode($context, JSON_PRETTY_PRINT)) . '
|
|
||||||
|
|
||||||
';
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetGlobalVariable($event)
|
|
||||||
{
|
|
||||||
$_GET = $event['queryStringParameters'];
|
|
||||||
foreach ($_GET as $k => $v) {
|
|
||||||
if ($v == '') $_GET[$k] = true;
|
|
||||||
}
|
|
||||||
$postbody = explode("&",$event['body']);
|
|
||||||
foreach ($postbody as $postvalues) {
|
|
||||||
$pos = strpos($postvalues,"=");
|
|
||||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
|
||||||
}
|
|
||||||
$cookiebody = explode("; ",$event['headers']['Cookie']);
|
|
||||||
foreach ($cookiebody as $cookievalues) {
|
|
||||||
$pos = strpos($cookievalues,"=");
|
|
||||||
$_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetPathSetting($event, $context)
|
|
||||||
{
|
|
||||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($event['headers']['Accept-Language'],';')[0],',')[0]);
|
|
||||||
$_SERVER['functionBrn'] = $context['functionBrn'];
|
|
||||||
$_SERVER['base_path'] = '/';
|
|
||||||
$path = $event['path'];
|
|
||||||
//$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
|
|
||||||
$_SERVER['REMOTE_ADDR'] = $event['requestContext']['sourceIp'];
|
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = $event['headers']['X-Requested-With'];
|
|
||||||
$_SERVER['HTTP_USER_AGENT'] = $event['headers']['User-Agent'];
|
|
||||||
if (isset($event['headers']['authorization'])) {
|
|
||||||
$basicAuth = splitfirst(base64_decode(splitfirst($event['headers']['authorization'], 'Basic ')[1]), ':');
|
|
||||||
$_SERVER['PHP_AUTH_USER'] = $basicAuth[0];
|
|
||||||
$_SERVER['PHP_AUTH_PW'] = $basicAuth[1];
|
|
||||||
}
|
|
||||||
$_SERVER['HTTP_HOST'] = $event['headers']['Host'];
|
|
||||||
$_SERVER['REQUEST_SCHEME'] = $event['headers']['X-Forwarded-Proto'];
|
|
||||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
|
||||||
$_SERVER['referhost'] = explode('/', $event['headers']['Referer'])[2];
|
|
||||||
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
|
|
||||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['If-Modified-Since'];
|
|
||||||
$_SERVER['BCE_CFC_RUNTIME_NAME'] = 'php7';
|
|
||||||
return $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfig($str, $disktag = '')
|
|
||||||
{
|
|
||||||
if (isInnerEnv($str)) {
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$env = json_decode(getenv($disktag), true);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfig($arr, $disktag = '')
|
|
||||||
{
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$disktags = explode("|",getConfig('disktag'));
|
|
||||||
$diskconfig = json_decode(getenv($disktag), true);
|
|
||||||
$tmp = [];
|
|
||||||
$indisk = 0;
|
|
||||||
$operatedisk = 0;
|
|
||||||
foreach ($arr as $k => $v) {
|
|
||||||
if (isCommonEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
|
||||||
else $tmp[$k] = $v;
|
|
||||||
} elseif (isInnerEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
|
||||||
else $diskconfig[$k] = $v;
|
|
||||||
$indisk = 1;
|
|
||||||
} elseif ($k=='disktag_add') {
|
|
||||||
array_push($disktags, $v);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_del') {
|
|
||||||
$disktags = array_diff($disktags, [ $v ]);
|
|
||||||
$tmp[$v] = '';
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_copy') {
|
|
||||||
$newtag = $v . '_' . date("Ymd_His");
|
|
||||||
$tmp[$newtag] = getConfig($v);
|
|
||||||
array_push($disktags, $newtag);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
|
||||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
|
||||||
} else {
|
|
||||||
$tmp[$k] = json_encode($v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($indisk) {
|
|
||||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
|
||||||
ksort($diskconfig);
|
|
||||||
$tmp[$disktag] = json_encode($diskconfig);
|
|
||||||
}
|
|
||||||
if ($operatedisk) {
|
|
||||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
|
||||||
$tags = [];
|
|
||||||
foreach ($disktags as $tag) {
|
|
||||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
|
||||||
else array_push($tags, $tag);
|
|
||||||
}
|
|
||||||
$tmp['disktag'] = implode('|', $tags);
|
|
||||||
$tmp[$arr['disktag_newname']] = getConfig($arr['disktag_rename']);
|
|
||||||
$tmp[$arr['disktag_rename']] = '';
|
|
||||||
} else {
|
|
||||||
$disktags = array_unique($disktags);
|
|
||||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
|
||||||
if ($disktag_s!='') $tmp['disktag'] = substr($disktag_s, 0, -1);
|
|
||||||
else $tmp['disktag'] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// echo '正式设置:'.json_encode($tmp,JSON_PRETTY_PRINT).'
|
|
||||||
//';
|
|
||||||
$response = updateEnvironment($tmp, getConfig('SecretId'), getConfig('SecretKey'));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function install()
|
|
||||||
{
|
|
||||||
global $constStr;
|
|
||||||
if ($_GET['install2']) {
|
|
||||||
$tmp['admin'] = $_POST['admin'];
|
|
||||||
$response = setConfigResponse( setConfig($tmp) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
if (needUpdate()) {
|
|
||||||
OnekeyUpate();
|
|
||||||
return message('update to github version, reinstall.
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
</script>
|
|
||||||
<meta http-equiv="refresh" content="3;URL=' . $url . '">', 'Program updating', 201);
|
|
||||||
}
|
|
||||||
return output('Jump
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
</script>
|
|
||||||
<meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
|
|
||||||
}
|
|
||||||
if ($_GET['install1']) {
|
|
||||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
|
||||||
//$SecretId = getConfig('SecretId');
|
|
||||||
//if ($SecretId=='') {
|
|
||||||
$SecretId = $_POST['SecretId'];
|
|
||||||
$tmp['SecretId'] = $SecretId;
|
|
||||||
//}
|
|
||||||
//$SecretKey = getConfig('SecretKey');
|
|
||||||
//if ($SecretKey=='') {
|
|
||||||
$SecretKey = $_POST['SecretKey'];
|
|
||||||
$tmp['SecretKey'] = $SecretKey;
|
|
||||||
//}
|
|
||||||
$response = setConfigResponse(SetbaseConfig($tmp, $SecretId, $SecretKey));
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
} else {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
|
||||||
<label>'.getconstStr('SetAdminPassword').':<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.admin.value==\'\') {
|
|
||||||
alert(\''.getconstStr('SetAdminPassword').'\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SetAdminPassword');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($_GET['install0']) {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install1" method="post" onsubmit="return notnull(this);">
|
|
||||||
language:<br>';
|
|
||||||
foreach ($constStr['languages'] as $key1 => $value1) {
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
|
||||||
}
|
|
||||||
//if (getConfig('SecretId')==''||getConfig('SecretKey')=='')
|
|
||||||
$html .= '
|
|
||||||
<a href="https://console.bce.baidu.com/iam/#/iam/accesslist" target="_blank">' . getconstStr('Create') . ' Access Key & Secret Key</a><br>
|
|
||||||
<label>Access Key:<input name="SecretId" type="text" placeholder="" size=""></label><br>
|
|
||||||
<label>Secret Key:<input name="SecretKey" type="password" placeholder="" size=""></label><br>';
|
|
||||||
$html .= '
|
|
||||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
var nowtime= new Date();
|
|
||||||
var timezone = 0-nowtime.getTimezoneOffset()/60;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie="timezone="+timezone+"; path=/; "+expires;
|
|
||||||
function changelanguage(str)
|
|
||||||
{
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=\'+str+\'; path=/; \'+expires;
|
|
||||||
location.href = location.href;
|
|
||||||
}
|
|
||||||
function notnull(t)
|
|
||||||
{';
|
|
||||||
//if (getConfig('SecretId')==''||getConfig('SecretKey')=='')
|
|
||||||
$html .= '
|
|
||||||
if (t.SecretId.value==\'\') {
|
|
||||||
alert(\'input Access Key\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.SecretKey.value==\'\') {
|
|
||||||
alert(\'input Secret Key\');
|
|
||||||
return false;
|
|
||||||
}';
|
|
||||||
$html .= '
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SelectLanguage');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
$html .= '<a href="?install0">'.getconstStr('ClickInstall').'</a>, '.getconstStr('LogintoBind');
|
|
||||||
$title = 'Install';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
function CFCAPIv1($Brn, $AccessKey, $SecretKey, $Method, $End, $data = '')
|
|
||||||
{
|
|
||||||
// brn:bce:cfc:bj:c094b1ca1XXXXXXXXb8dea6ab482:function:fdsa:$LATEST
|
|
||||||
$BRN = explode(':', $Brn);
|
|
||||||
if ( !($BRN[0]=='brn' && $BRN[1]=='bce' && $BRN[2]=='cfc') ) {
|
|
||||||
$tmp['code'] = 'BRN Error';
|
|
||||||
$tmp['message'] = 'The BRN expect start with "brn:bce:cfc:", given: ' . $Brn . ' .';
|
|
||||||
return json_encode($tmp);
|
|
||||||
}
|
|
||||||
$Region = $BRN[3];
|
|
||||||
//$project_id = $BRN[4];
|
|
||||||
$FunctionName = $BRN[6];
|
|
||||||
$host = 'cfc.' . $Region . '.baidubce.com';
|
|
||||||
date_default_timezone_set('UTC'); // unset last timezone setting
|
|
||||||
$timestamp = date('Y-m-d\TH:i:s\Z');
|
|
||||||
//date_default_timezone_set(get_timezone($_SERVER['timezone']));
|
|
||||||
$authStringPrefix = 'bce-auth-v1/' . $AccessKey . '/' . $timestamp . '/1800' ;
|
|
||||||
$path = '/v1/functions/' . $FunctionName . '/' . $End;
|
|
||||||
$CanonicalURI = spurlencode($path, '/');
|
|
||||||
$CanonicalQueryString = '';
|
|
||||||
$CanonicalHeaders = 'host:' . $host;
|
|
||||||
$CanonicalRequest = $Method . "\n" . $CanonicalURI . "\n" . $CanonicalQueryString . "\n" . $CanonicalHeaders;
|
|
||||||
$SigningKey = hash_hmac('sha256', $authStringPrefix, $SecretKey);
|
|
||||||
$Signature = hash_hmac('sha256', $CanonicalRequest, $SigningKey);
|
|
||||||
$authorization = $authStringPrefix . '/host/' . $Signature;
|
|
||||||
|
|
||||||
$p = 0;
|
|
||||||
while ($response['stat']==0 && $p<3) {
|
|
||||||
$response = curl(
|
|
||||||
$Method,
|
|
||||||
'https://' . $host . $path,
|
|
||||||
$data,
|
|
||||||
[
|
|
||||||
'Authorization' => $authorization,
|
|
||||||
'Content-type' => 'application/json'
|
|
||||||
]
|
|
||||||
);
|
|
||||||
$p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($response['stat']==0) {
|
|
||||||
$tmp['code'] = 'Network Error';
|
|
||||||
$tmp['message'] = 'Can not connect ' . $host;
|
|
||||||
return json_encode($tmp);
|
|
||||||
}
|
|
||||||
if ($response['stat']!=200) {
|
|
||||||
$tmp = json_decode($response['body'], true);
|
|
||||||
$tmp['message'] .= '<br>' . $response['stat'] . '<br>' . $timestamp . PHP_EOL;
|
|
||||||
return json_encode($tmp);
|
|
||||||
}
|
|
||||||
return $response['body'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getfunctioninfo($SecretId, $SecretKey)
|
|
||||||
{
|
|
||||||
return CFCAPIv1($_SERVER['functionBrn'], $SecretId, $SecretKey, 'GET', 'configuration');
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateEnvironment($Envs, $SecretId, $SecretKey)
|
|
||||||
{
|
|
||||||
$FunctionConfig = json_decode(getfunctioninfo($SecretId, $SecretKey), true);
|
|
||||||
$tmp_env = $FunctionConfig['Environment']['Variables'];
|
|
||||||
foreach ($Envs as $key1 => $value1) {
|
|
||||||
$tmp_env[$key1] = $value1;
|
|
||||||
}
|
|
||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
|
||||||
//ksort($tmp_env);
|
|
||||||
sortConfig($tmp_env);
|
|
||||||
|
|
||||||
$tmp['Environment']['Variables'] = $tmp_env;
|
|
||||||
$data = json_encode($tmp);
|
|
||||||
|
|
||||||
return CFCAPIv1($_SERVER['functionBrn'], $SecretId, $SecretKey, 'PUT', 'configuration', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
function SetbaseConfig($Envs, $SecretId, $SecretKey)
|
|
||||||
{
|
|
||||||
$FunctionConfig = json_decode(getfunctioninfo($SecretId, $SecretKey), true);
|
|
||||||
$tmp_env = $FunctionConfig['Environment']['Variables'];
|
|
||||||
foreach ($Envs as $key1 => $value1) {
|
|
||||||
$tmp_env[$key1] = $value1;
|
|
||||||
}
|
|
||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
|
||||||
ksort($tmp_env);
|
|
||||||
|
|
||||||
$tmp['Timeout'] = 30;
|
|
||||||
$tmp['Description'] = 'Onedrive index and manager in Baidu CFC.';
|
|
||||||
$tmp['Environment']['Variables'] = $tmp_env;
|
|
||||||
$data = json_encode($tmp);
|
|
||||||
|
|
||||||
return CFCAPIv1($_SERVER['functionBrn'], $SecretId, $SecretKey, 'PUT', 'configuration', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateProgram($SecretId, $SecretKey, $source)
|
|
||||||
{
|
|
||||||
$tmp['ZipFile'] = base64_encode( file_get_contents($source) );
|
|
||||||
$data = json_encode($tmp);
|
|
||||||
return CFCAPIv1($_SERVER['functionBrn'], $SecretId, $SecretKey, 'PUT', 'code', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error($response)
|
|
||||||
{
|
|
||||||
//return isset($response['code']);
|
|
||||||
return !(isset($response['FunctionBrn']) && $response['FunctionBrn'] == $_SERVER['functionBrn']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error_msg($response)
|
|
||||||
{
|
|
||||||
if (isset($response['code'])) $html = $response['code'] . '<br>
|
|
||||||
' . $response['message'];
|
|
||||||
else $html = json_encode($response, JSON_PRETTY_PRINT);
|
|
||||||
return $html . '<br><br>
|
|
||||||
BRN: ' . $_SERVER['functionBrn'] . '<br>
|
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfigResponse($response)
|
|
||||||
{
|
|
||||||
//return $response;
|
|
||||||
return json_decode( $response, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
|
||||||
{
|
|
||||||
$source = '/tmp/code.zip';
|
|
||||||
$outPath = '/tmp/';
|
|
||||||
|
|
||||||
if ($GitSource=='Github') {
|
|
||||||
// 从github下载对应tar.gz,并解压
|
|
||||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
|
||||||
} elseif ($GitSource=='HITGitlab') {
|
|
||||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
|
||||||
} else return json_encode(['FunctionBrn'=>$_SERVER['functionBrn'], 'code'=>'Git Source input Error!']);
|
|
||||||
$tarfile = '/tmp/github.tar.gz';
|
|
||||||
file_put_contents($tarfile, file_get_contents($url));
|
|
||||||
$phar = new PharData($tarfile);
|
|
||||||
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
|
||||||
|
|
||||||
// 获取解压出的目录名
|
|
||||||
$outPath = findIndexPath($outPath);
|
|
||||||
|
|
||||||
// 将目录中文件打包成zip
|
|
||||||
//$zip=new ZipArchive();
|
|
||||||
$zip=new PharData($source);
|
|
||||||
//if($zip->open($source, ZipArchive::CREATE)){
|
|
||||||
addFileToZip($zip, $outPath); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
|
|
||||||
// $zip->close(); //关闭处理的zip文件
|
|
||||||
//}
|
|
||||||
|
|
||||||
return updateProgram(getConfig('SecretId'), getConfig('SecretKey'), $source);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addFileToZip($zip, $rootpath, $path = '')
|
|
||||||
{
|
|
||||||
if (substr($rootpath,-1)=='/') $rootpath = substr($rootpath, 0, -1);
|
|
||||||
if (substr($path,0,1)=='/') $path = substr($path, 1);
|
|
||||||
$handler=opendir(path_format($rootpath.'/'.$path)); //打开当前文件夹由$path指定。
|
|
||||||
while($filename=readdir($handler)){
|
|
||||||
if($filename != "." && $filename != ".."){//文件夹文件名字为'.'和‘..’,不要对他们进行操作
|
|
||||||
$nowname = path_format($rootpath.'/'.$path."/".$filename);
|
|
||||||
if(is_dir($nowname)){// 如果读取的某个对象是文件夹,则递归
|
|
||||||
$zip->addEmptyDir($path."/".$filename);
|
|
||||||
addFileToZip($zip, $rootpath, $path."/".$filename);
|
|
||||||
}else{ //将文件加入zip对象
|
|
||||||
$newname = $path."/".$filename;
|
|
||||||
if (substr($newname,0,1)=='/') $newname = substr($newname, 1);
|
|
||||||
$zip->addFile($nowname, $newname);
|
|
||||||
//$zip->renameName($nowname, $newname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@closedir($handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
function WaitFunction() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeAuthKey() {
|
|
||||||
if ($_POST['SecretId']!=''&&$_POST['SecretKey']!='') {
|
|
||||||
$SecretId = $_POST['SecretId'];
|
|
||||||
$tmp['SecretId'] = $SecretId;
|
|
||||||
$SecretKey = $_POST['SecretKey'];
|
|
||||||
$tmp['SecretKey'] = $SecretKey;
|
|
||||||
$response = setConfigResponse(SetbaseConfig($tmp, $SecretId, $SecretKey));
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 400);
|
|
||||||
} else {
|
|
||||||
$html = getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var i = 0;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$html = '
|
|
||||||
<form action="" method="post" onsubmit="return notnull(this);">
|
|
||||||
<a href="https://console.bce.baidu.com/iam/#/iam/accesslist" target="_blank">' . getconstStr('Create') . ' Access Key & Secret Key</a><br>
|
|
||||||
<label>Access Key:<input name="SecretId" type="text" placeholder="" size=""></label><br>
|
|
||||||
<label>Secret Key:<input name="SecretKey" type="password" placeholder="" size=""></label><br>
|
|
||||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.SecretId.value==\'\') {
|
|
||||||
alert(\'input Access Key\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.SecretKey.value==\'\') {
|
|
||||||
alert(\'input Secret Key\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
return message($html, 'Change platform Auth token or key', 200);
|
|
||||||
}
|
|
|
@ -1,417 +0,0 @@
|
||||||
<?php
|
|
||||||
// https://devcenter.heroku.com/articles/platform-api-reference#build-create
|
|
||||||
|
|
||||||
function getpath()
|
|
||||||
{
|
|
||||||
if (getConfig('function_name') && getConfig('APIKey')) {
|
|
||||||
$APIKey = getConfig('APIKey');
|
|
||||||
$res = HerokuAPI('GET', 'https://api.heroku.com/apps/' . getConfig('function_name'), '', $APIKey);
|
|
||||||
$response = json_decode($res['body'], true);
|
|
||||||
if (isset($response['build_stack'])) {
|
|
||||||
$tmp['HerokuappId'] = $response['id'];
|
|
||||||
$tmp['function_name'] = null;
|
|
||||||
} else {
|
|
||||||
error_log1('Something error' . 'Get Heroku app id: ' . json_encode($res, JSON_PRETTY_PRINT));
|
|
||||||
//return message('Get Heroku app id: ' . json_encode($res, JSON_PRETTY_PRINT), 'Something error', 500);
|
|
||||||
}
|
|
||||||
$response = json_decode(setHerokuConfig($tmp, $tmp['HerokuappId'], $APIKey)['body'], true);
|
|
||||||
$title = 'Change function_name to HerokuappId';
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$stat = 500;
|
|
||||||
error_log1('Change function_name to HerokuappId' . $html);
|
|
||||||
} else {
|
|
||||||
$html = getconstStr('Wait') . ' 5s, jump to index.
|
|
||||||
<meta http-equiv="refresh" content="5;URL=/">';
|
|
||||||
$stat = 201;
|
|
||||||
}
|
|
||||||
//return message($html, $title, $stat);
|
|
||||||
}
|
|
||||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($_SERVER['HTTP_ACCEPT_LANGUAGE'],';')[0],',')[0]);
|
|
||||||
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
||||||
$_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_X_FORWARDED_PROTO'];
|
|
||||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
|
||||||
$_SERVER['referhost'] = explode('/', $_SERVER['HTTP_REFERER'])[2];
|
|
||||||
$_SERVER['base_path'] = path_format(substr($_SERVER['SCRIPT_NAME'], 0, -10) . '/');
|
|
||||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
|
||||||
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
|
||||||
else $path = $_SERVER['REQUEST_URI'];
|
|
||||||
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
|
||||||
return substr($path, 1);
|
|
||||||
//return spurlencode($path, '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getGET()
|
|
||||||
{
|
|
||||||
//error_log1('POST:' . json_encode($_POST));
|
|
||||||
if (!$_POST) {
|
|
||||||
if (!!$HTTP_RAW_POST_DATA) {
|
|
||||||
$tmpdata = $HTTP_RAW_POST_DATA;
|
|
||||||
//error_log1('RAW:' . $tmpdata);
|
|
||||||
} else {
|
|
||||||
$tmpdata = file_get_contents('php://input');
|
|
||||||
//error_log1('PHPINPUT:' . $tmpdata);
|
|
||||||
}
|
|
||||||
if (!!$tmpdata) {
|
|
||||||
$postbody = explode("&", $tmpdata);
|
|
||||||
foreach ($postbody as $postvalues) {
|
|
||||||
$pos = strpos($postvalues,"=");
|
|
||||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
|
||||||
}
|
|
||||||
//error_log1('POSTformPHPINPUT:' . json_encode($_POST));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
|
||||||
if ($p>0) {
|
|
||||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
|
||||||
$getstrarr = explode("&",$getstr);
|
|
||||||
foreach ($getstrarr as $getvalues) {
|
|
||||||
if ($getvalues != '') {
|
|
||||||
$pos = strpos($getvalues, "=");
|
|
||||||
//echo $pos;
|
|
||||||
if ($pos > 0) {
|
|
||||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
|
||||||
} else {
|
|
||||||
$getarry[urldecode($getvalues)] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($getarry)) {
|
|
||||||
return $getarry;
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfig($str, $disktag = '')
|
|
||||||
{
|
|
||||||
if (isInnerEnv($str)) {
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$env = json_decode(getenv($disktag), true);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfig($arr, $disktag = '')
|
|
||||||
{
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$disktags = explode("|",getConfig('disktag'));
|
|
||||||
if ($disktag!='') $diskconfig = json_decode(getenv($disktag), true);
|
|
||||||
$tmp = [];
|
|
||||||
$indisk = 0;
|
|
||||||
$operatedisk = 0;
|
|
||||||
foreach ($arr as $k => $v) {
|
|
||||||
if (isCommonEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
|
||||||
else $tmp[$k] = $v;
|
|
||||||
} elseif (isInnerEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
|
||||||
else $diskconfig[$k] = $v;
|
|
||||||
$indisk = 1;
|
|
||||||
} elseif ($k=='disktag_add') {
|
|
||||||
array_push($disktags, $v);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_del') {
|
|
||||||
$disktags = array_diff($disktags, [ $v ]);
|
|
||||||
$tmp[$v] = '';
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_copy') {
|
|
||||||
$newtag = $v . '_' . date("Ymd_His");
|
|
||||||
$tmp[$newtag] = getConfig($v);
|
|
||||||
array_push($disktags, $newtag);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
|
||||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
|
||||||
} else {
|
|
||||||
$tmp[$k] = json_encode($v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($indisk) {
|
|
||||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
|
||||||
ksort($diskconfig);
|
|
||||||
$tmp[$disktag] = json_encode($diskconfig);
|
|
||||||
}
|
|
||||||
if ($operatedisk) {
|
|
||||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
|
||||||
$tags = [];
|
|
||||||
foreach ($disktags as $tag) {
|
|
||||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
|
||||||
else array_push($tags, $tag);
|
|
||||||
}
|
|
||||||
$tmp['disktag'] = implode('|', $tags);
|
|
||||||
$tmp[$arr['disktag_newname']] = getConfig($arr['disktag_rename']);
|
|
||||||
$tmp[$arr['disktag_rename']] = null;
|
|
||||||
} else {
|
|
||||||
$disktags = array_unique($disktags);
|
|
||||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
|
||||||
if ($disktag_s!='') $tmp['disktag'] = substr($disktag_s, 0, -1);
|
|
||||||
else $tmp['disktag'] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($tmp as $key => $val) if ($val=='') $tmp[$key]=null;
|
|
||||||
|
|
||||||
return setHerokuConfig($tmp, getConfig('HerokuappId'), getConfig('APIKey'));
|
|
||||||
error_log1(json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($tmp, JSON_PRETTY_PRINT));
|
|
||||||
}
|
|
||||||
|
|
||||||
function install()
|
|
||||||
{
|
|
||||||
global $constStr;
|
|
||||||
if ($_GET['install1']) {
|
|
||||||
if ($_POST['admin']!='') {
|
|
||||||
$tmp['admin'] = $_POST['admin'];
|
|
||||||
//$tmp['language'] = $_POST['language'];
|
|
||||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
|
||||||
$APIKey = $_POST['APIKey'];
|
|
||||||
$tmp['APIKey'] = $APIKey;
|
|
||||||
$HerokuappId = getConfig('HerokuappId');
|
|
||||||
if ($HerokuappId=='') {
|
|
||||||
$function_name = getConfig('function_name');
|
|
||||||
if ($function_name=='') {
|
|
||||||
$tmp1 = substr($_SERVER['HTTP_HOST'], 0, strrpos($_SERVER['HTTP_HOST'], '.'));
|
|
||||||
$maindomain = substr($tmp1, strrpos($tmp1, '.')+1);
|
|
||||||
if ($maindomain=='herokuapp') $function_name = substr($tmp1, 0, strrpos($tmp1, '.'));
|
|
||||||
else return message('Please visit from xxxx.herokuapp.com', '', 500);
|
|
||||||
$res = HerokuAPI('GET', 'https://api.heroku.com/apps/' . $function_name, '', $APIKey);
|
|
||||||
$response = json_decode($res['body'], true);
|
|
||||||
if (isset($response['build_stack'])) {
|
|
||||||
$HerokuappId = $response['id'];
|
|
||||||
} else {
|
|
||||||
return message('Get Heroku app id: ' . json_encode($res, JSON_PRETTY_PRINT), 'Something error', 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$tmp['HerokuappId'] = $HerokuappId;
|
|
||||||
$response = json_decode(setHerokuConfig($tmp, $HerokuappId, $APIKey)['body'], true);
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 400);
|
|
||||||
} else {
|
|
||||||
$html = getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+1000);
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
var status = "' . $response['DplStatus'] . '";
|
|
||||||
var i = 0;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($_GET['install0']) {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install1" method="post" onsubmit="return notnull(this);">
|
|
||||||
language:<br>';
|
|
||||||
foreach ($constStr['languages'] as $key1 => $value1) {
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
|
||||||
}
|
|
||||||
$html .= '
|
|
||||||
<a href="https://dashboard.heroku.com/account" target="_blank">' . getconstStr('Create') . ' API Key</a><br>
|
|
||||||
<label>API Key:<input name="APIKey" type="password" placeholder="" size=""></label><br>';
|
|
||||||
$html .= '
|
|
||||||
<label>Set admin password:<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>';
|
|
||||||
$html .= '
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
var nowtime= new Date();
|
|
||||||
var timezone = 0-nowtime.getTimezoneOffset()/60;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie="timezone="+timezone+"; path=/; "+expires;
|
|
||||||
function changelanguage(str)
|
|
||||||
{
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=\'+str+\'; path=/; \'+expires;
|
|
||||||
location.href = location.href;
|
|
||||||
}
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.admin.value==\'\') {
|
|
||||||
alert(\'input admin\');
|
|
||||||
return false;
|
|
||||||
}';
|
|
||||||
$html .= '
|
|
||||||
if (t.APIKey.value==\'\') {
|
|
||||||
alert(\'input API Key\');
|
|
||||||
return false;
|
|
||||||
}';
|
|
||||||
$html .= '
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SelectLanguage');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
$html .= '<a href="?install0">'.getconstStr('ClickInstall').'</a>, '.getconstStr('LogintoBind');
|
|
||||||
$title = 'Install';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
function HerokuAPI($method, $url, $data = '', $apikey)
|
|
||||||
{
|
|
||||||
if ($method=='PATCH'||$method=='POST') {
|
|
||||||
$headers['Content-Type'] = 'application/json';
|
|
||||||
}
|
|
||||||
$headers['Authorization'] = 'Bearer ' . $apikey;
|
|
||||||
$headers['Accept'] = 'application/vnd.heroku+json; version=3';
|
|
||||||
//if (!isset($headers['Accept'])) $headers['Accept'] = '*/*';
|
|
||||||
//if (!isset($headers['Referer'])) $headers['Referer'] = $url;
|
|
||||||
$sendHeaders = array();
|
|
||||||
foreach ($headers as $headerName => $headerVal) {
|
|
||||||
$sendHeaders[] = $headerName . ': ' . $headerVal;
|
|
||||||
}
|
|
||||||
error_log1($method . $url . $data . $apikey);
|
|
||||||
$ch = curl_init();
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,$method);
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
|
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
|
||||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders);
|
|
||||||
$response['body'] = curl_exec($ch);
|
|
||||||
$response['stat'] = curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
|
||||||
curl_close($ch);
|
|
||||||
error_log1($response['stat'].'
|
|
||||||
'.$response['body'].'
|
|
||||||
');
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getHerokuConfig($HerokuappId, $apikey)
|
|
||||||
{
|
|
||||||
return HerokuAPI('GET', 'https://api.heroku.com/apps/' . $HerokuappId . '/config-vars', '', $apikey);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setHerokuConfig($env, $HerokuappId, $apikey)
|
|
||||||
{
|
|
||||||
$data = json_encode($env);
|
|
||||||
if (substr($data, 0, 1)=='{') return HerokuAPI('PATCH', 'https://api.heroku.com/apps/' . $HerokuappId . '/config-vars', $data, $apikey);
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateHerokuapp($HerokuappId, $apikey, $source)
|
|
||||||
{
|
|
||||||
$tmp['source_blob']['url'] = $source;
|
|
||||||
$data = json_encode($tmp);
|
|
||||||
$response = HerokuAPI('POST', 'https://api.heroku.com/apps/' . $HerokuappId . '/builds', $data, $apikey);
|
|
||||||
$result = json_decode( $response['body'], true );
|
|
||||||
$result['DplStatus'] = $result['id'];
|
|
||||||
$response['body'] = json_encode($result);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error($response)
|
|
||||||
{
|
|
||||||
return isset($response['id'])&&isset($response['message']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error_msg($response)
|
|
||||||
{
|
|
||||||
return $response['id'] . '<br>
|
|
||||||
' . $response['message'] . '<br><br>
|
|
||||||
function_name:' . $_SERVER['function_name'] . '<br>
|
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
|
||||||
{
|
|
||||||
if ($GitSource=='Github') {
|
|
||||||
//'https://github.com/qkqpttgf/OneManager-php/tarball/master/';
|
|
||||||
$source = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
|
||||||
} elseif ($GitSource=='HITGitlab') {
|
|
||||||
$source = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
|
||||||
} else return ['stat'=>403, 'body'=>json_encode(['id'=>'Error', 'message'=>'Git Source input Error!'])];
|
|
||||||
|
|
||||||
return updateHerokuapp(getConfig('HerokuappId'), getConfig('APIKey'), $source);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfigResponse($response)
|
|
||||||
{
|
|
||||||
return json_decode( $response['body'], true );
|
|
||||||
}
|
|
||||||
|
|
||||||
function WaitFunction($buildId = '') {
|
|
||||||
// GET /apps/{app_id_or_name}/builds/{build_id}
|
|
||||||
if ($buildId=='1') return true;
|
|
||||||
$response = HerokuAPI('GET', 'https://api.heroku.com/apps/' . getConfig('HerokuappId') . '/builds/' . $buildId, '', getConfig('APIKey'));
|
|
||||||
if ($response['stat']==200) {
|
|
||||||
$result = json_decode($response['body'], true);
|
|
||||||
if ($result['status']=="succeeded") return true;
|
|
||||||
else return false;
|
|
||||||
} else {
|
|
||||||
$response['body'] .= $url;
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeAuthKey() {
|
|
||||||
if ($_POST['APIKey']!='') {
|
|
||||||
$APIKey = $_POST['APIKey'];
|
|
||||||
$tmp['APIKey'] = $APIKey;
|
|
||||||
$response = setConfigResponse( setHerokuConfig($tmp, getConfig('HerokuappId'), $APIKey) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 400);
|
|
||||||
} else {
|
|
||||||
$html = getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var status = "' . $response['DplStatus'] . '";
|
|
||||||
var i = 0;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$html = '
|
|
||||||
<form action="" method="post" onsubmit="return notnull(this);">
|
|
||||||
<a href="https://dashboard.heroku.com/account" target="_blank">'.getconstStr('Create').' API Key</a><br>
|
|
||||||
<label>API Key:<input name="APIKey" type="password" placeholder="" size=""></label><br>
|
|
||||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.APIKey.value==\'\') {
|
|
||||||
alert(\'input API Key\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
return message($html, 'Change platform Auth token or key', 200);
|
|
||||||
}
|
|
|
@ -1,537 +0,0 @@
|
||||||
<?php
|
|
||||||
// https://support.huaweicloud.com/api-functiongraph/functiongraph_06_0110.html
|
|
||||||
// https://support.huaweicloud.com/api-functiongraph/functiongraph_06_0111.html
|
|
||||||
|
|
||||||
global $contextUserData;
|
|
||||||
|
|
||||||
function printInput($event, $context)
|
|
||||||
{
|
|
||||||
$tmp['eventID'] = $context->geteventID();
|
|
||||||
$tmp['RemainingTimeInMilliSeconds'] = $context->getRemainingTimeInMilliSeconds();
|
|
||||||
$tmp['AccessKey'] = $context->getAccessKey();
|
|
||||||
$tmp['SecretKey'] = $context->getSecretKey();
|
|
||||||
$tmp['UserData']['HW_urn'] = $context->getUserData('HW_urn');
|
|
||||||
$tmp['FunctionName'] = $context->getFunctionName();
|
|
||||||
$tmp['RunningTimeInSeconds'] = $context->getRunningTimeInSeconds();
|
|
||||||
$tmp['Version'] = $context->getVersion();
|
|
||||||
$tmp['MemorySize'] = $context->getMemorySize();
|
|
||||||
$tmp['CPUNumber'] = $context->getCPUNumber();
|
|
||||||
$tmp['ProjectID'] = $context->getProjectID();
|
|
||||||
$tmp['Package'] = $context->Package();
|
|
||||||
$tmp['Token'] = $context->getToken();
|
|
||||||
$tmp['Logger'] = $context->getLogger();
|
|
||||||
|
|
||||||
if (strlen(json_encode($event['body']))>500) $event['body']=substr($event['body'],0,strpos($event['body'],'base64')+30) . '...Too Long!...' . substr($event['body'],-50);
|
|
||||||
echo urldecode(json_encode($event, JSON_PRETTY_PRINT)) . '
|
|
||||||
|
|
||||||
' . urldecode(json_encode($tmp, JSON_PRETTY_PRINT)) . '
|
|
||||||
|
|
||||||
';
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetGlobalVariable($event)
|
|
||||||
{
|
|
||||||
$_GET = $event['queryStringParameters'];
|
|
||||||
$postbody = explode("&",$event['body']);
|
|
||||||
foreach ($postbody as $postvalues) {
|
|
||||||
$pos = strpos($postvalues,"=");
|
|
||||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
|
||||||
}
|
|
||||||
$cookiebody = explode("; ",$event['headers']['cookie']);
|
|
||||||
foreach ($cookiebody as $cookievalues) {
|
|
||||||
$pos = strpos($cookievalues,"=");
|
|
||||||
$_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetPathSetting($event, $context)
|
|
||||||
{
|
|
||||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($event['headers']['accept-language'],';')[0],',')[0]);
|
|
||||||
$_SERVER['function_name'] = $context->getFunctionName();
|
|
||||||
$_SERVER['ProjectID'] = $context->getProjectID();
|
|
||||||
$host_name = $event['headers']['host'];
|
|
||||||
$_SERVER['HTTP_HOST'] = $host_name;
|
|
||||||
$path = path_format($event['pathParameters'][''].'/');
|
|
||||||
$path = str_replace('+', '%2B', $path);
|
|
||||||
$_SERVER['base_path'] = path_format($event['path'].'/');
|
|
||||||
if ( $_SERVER['base_path'] == $path ) {
|
|
||||||
$_SERVER['base_path'] = '/';
|
|
||||||
} else {
|
|
||||||
$_SERVER['base_path'] = substr($_SERVER['base_path'], 0, -strlen($path));
|
|
||||||
if ($_SERVER['base_path']=='') $_SERVER['base_path'] = '/';
|
|
||||||
}
|
|
||||||
//$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
|
|
||||||
$_SERVER['REMOTE_ADDR'] = $event['headers']['x-real-ip'];
|
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = $event['headers']['x-requested-with'];
|
|
||||||
$_SERVER['HTTP_USER_AGENT'] = $event['headers']['user-agent'];
|
|
||||||
if (isset($event['headers']['authorization'])) {
|
|
||||||
$basicAuth = splitfirst(base64_decode(splitfirst($event['headers']['authorization'], 'Basic ')[1]), ':');
|
|
||||||
$_SERVER['PHP_AUTH_USER'] = $basicAuth[0];
|
|
||||||
$_SERVER['PHP_AUTH_PW'] = $basicAuth[1];
|
|
||||||
}
|
|
||||||
$_SERVER['REQUEST_SCHEME'] = $event['headers']['x-forwarded-proto'];
|
|
||||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
|
||||||
$_SERVER['referhost'] = explode('/', $event['headers']['referer'])[2];
|
|
||||||
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
|
|
||||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since'];
|
|
||||||
$_SERVER['_APP_SHARE_DIR'] = '/var/share/CFF/processrouter';
|
|
||||||
return $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfig($str, $disktag = '')
|
|
||||||
{
|
|
||||||
global $contextUserData;
|
|
||||||
if (isInnerEnv($str)) {
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$env = json_decode($contextUserData->getUserData($disktag), true);
|
|
||||||
if (isset($env[$str])) {
|
|
||||||
if (isBase64Env($str)) return base64y_decode($env[$str]);
|
|
||||||
else return $env[$str];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isBase64Env($str)) return base64y_decode($contextUserData->getUserData($str));
|
|
||||||
else return $contextUserData->getUserData($str);
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfig($arr, $disktag = '')
|
|
||||||
{
|
|
||||||
global $contextUserData;
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$disktags = explode("|",getConfig('disktag'));
|
|
||||||
$diskconfig = json_decode($contextUserData->getUserData($disktag), true);
|
|
||||||
$tmp = [];
|
|
||||||
$indisk = 0;
|
|
||||||
$operatedisk = 0;
|
|
||||||
foreach ($arr as $k => $v) {
|
|
||||||
if (isCommonEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
|
||||||
else $tmp[$k] = $v;
|
|
||||||
} elseif (isInnerEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
|
||||||
else $diskconfig[$k] = $v;
|
|
||||||
$indisk = 1;
|
|
||||||
} elseif ($k=='disktag_add') {
|
|
||||||
array_push($disktags, $v);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_del') {
|
|
||||||
$disktags = array_diff($disktags, [ $v ]);
|
|
||||||
$tmp[$v] = '';
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_copy') {
|
|
||||||
$newtag = $v . '_' . date("Ymd_His");
|
|
||||||
$tmp[$newtag] = getConfig($v);
|
|
||||||
array_push($disktags, $newtag);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
|
||||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
|
||||||
} else {
|
|
||||||
$tmp[$k] = json_encode($v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($indisk) {
|
|
||||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
|
||||||
ksort($diskconfig);
|
|
||||||
$tmp[$disktag] = json_encode($diskconfig);
|
|
||||||
}
|
|
||||||
if ($operatedisk) {
|
|
||||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
|
||||||
$tags = [];
|
|
||||||
foreach ($disktags as $tag) {
|
|
||||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
|
||||||
else array_push($tags, $tag);
|
|
||||||
}
|
|
||||||
$tmp['disktag'] = implode('|', $tags);
|
|
||||||
$tmp[$arr['disktag_newname']] = getConfig($arr['disktag_rename']);
|
|
||||||
$tmp[$arr['disktag_rename']] = '';
|
|
||||||
} else {
|
|
||||||
$disktags = array_unique($disktags);
|
|
||||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
|
||||||
if ($disktag_s!='') $tmp['disktag'] = substr($disktag_s, 0, -1);
|
|
||||||
else $tmp['disktag'] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// echo '正式设置:'.json_encode($tmp,JSON_PRETTY_PRINT).'
|
|
||||||
//';
|
|
||||||
$response = updateEnvironment($tmp, getConfig('HW_urn'), getConfig('HW_key'), getConfig('HW_secret'));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function install()
|
|
||||||
{
|
|
||||||
global $constStr;
|
|
||||||
global $contextUserData;
|
|
||||||
if ($_GET['install2']) {
|
|
||||||
$tmp['admin'] = $_POST['admin'];
|
|
||||||
$response = setConfigResponse( setConfig($tmp) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
if (needUpdate()) {
|
|
||||||
OnekeyUpate();
|
|
||||||
return message('update to github version, reinstall.
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
</script>
|
|
||||||
<meta http-equiv="refresh" content="3;URL=' . $url . '">', 'Program updating', 201);
|
|
||||||
}
|
|
||||||
return output('Jump
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
</script>
|
|
||||||
<meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
|
|
||||||
}
|
|
||||||
if ($_GET['install1']) {
|
|
||||||
//if ($_POST['admin']!='') {
|
|
||||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
|
||||||
$tmp['HW_urn'] = $_POST['HW_urn'];
|
|
||||||
$tmp['HW_key'] = $_POST['HW_key'];
|
|
||||||
$tmp['HW_secret'] = $_POST['HW_secret'];
|
|
||||||
$tmp['ONEMANAGER_CONFIG_SAVE'] = $_POST['ONEMANAGER_CONFIG_SAVE'];
|
|
||||||
//$response = json_decode(SetbaseConfig($tmp, $HW_urn, $HW_name, $HW_pwd), true)['Response'];
|
|
||||||
$response = setConfigResponse( SetbaseConfig($tmp, $tmp['HW_urn'], $tmp['HW_key'], $tmp['HW_secret']) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
} else {
|
|
||||||
if ($tmp['ONEMANAGER_CONFIG_SAVE'] == 'file') {
|
|
||||||
$html = getconstStr('ONEMANAGER_CONFIG_SAVE_FILE') . '<br><a href="' . $_SERVER['base_path'] . '">' . getconstStr('Home') . '</a>';
|
|
||||||
$title = 'Reinstall';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
$html .= '
|
|
||||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
|
||||||
<label>'.getconstStr('SetAdminPassword').':<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.admin.value==\'\') {
|
|
||||||
alert(\''.getconstStr('SetAdminPassword').'\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SetAdminPassword');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
if ($_GET['install0']) {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install1" method="post" onsubmit="return notnull(this);">
|
|
||||||
language:<br>';
|
|
||||||
foreach ($constStr['languages'] as $key1 => $value1) {
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
|
||||||
}
|
|
||||||
//if (getConfig('HW_urn')==''||getConfig('HW_key')==''||getConfig('HW_secret')=='')
|
|
||||||
$html .= '
|
|
||||||
在函数代码操作页上方找到URN,鼠标放上去后显示URN,复制填入:<br>
|
|
||||||
<label>URN:<input name="HW_urn" type="text" placeholder="" size=""></label><br>
|
|
||||||
<a href="https://console.huaweicloud.com/iam/#/mine/accessKey" target="_blank">点击链接</a>,新增访问密钥,
|
|
||||||
在下载的credentials.csv文件中找到对应信息,填入:<br>
|
|
||||||
<label>Access Key Id:<input name="HW_key" type="text" placeholder="" size=""></label><br>
|
|
||||||
<label>Secret Access Key:<input name="HW_secret" type="password" placeholder="" size=""></label><br>';
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="ONEMANAGER_CONFIG_SAVE" value="" ' . ('file'==$contextUserData->getUserData('ONEMANAGER_CONFIG_SAVE')?'':'checked') . '>' . getconstStr('ONEMANAGER_CONFIG_SAVE_ENV') . '</label><br>
|
|
||||||
<label><input type="radio" name="ONEMANAGER_CONFIG_SAVE" value="file" ' . ('file'==$contextUserData->getUserData('ONEMANAGER_CONFIG_SAVE')?'checked':'') . '>' . getconstStr('ONEMANAGER_CONFIG_SAVE_FILE') . '</label><br>';
|
|
||||||
$html .= '
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
var nowtime= new Date();
|
|
||||||
var timezone = 0-nowtime.getTimezoneOffset()/60;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie="timezone="+timezone+"; path=/; "+expires;
|
|
||||||
function changelanguage(str)
|
|
||||||
{
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=\'+str+\'; path=/; \'+expires;
|
|
||||||
location.href = location.href;
|
|
||||||
}
|
|
||||||
function notnull(t)
|
|
||||||
{';
|
|
||||||
//if (getConfig('HW_urn')==''||getConfig('HW_key')==''||getConfig('HW_secret')=='')
|
|
||||||
$html .= '
|
|
||||||
if (t.HW_urn.value==\'\') {
|
|
||||||
alert(\'input URN\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.HW_key.value==\'\') {
|
|
||||||
alert(\'input name\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.HW_secret.value==\'\') {
|
|
||||||
alert(\'input pwd\');
|
|
||||||
return false;
|
|
||||||
}';
|
|
||||||
$html .= '
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SelectLanguage');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
$html .= '<a href="?install0">'.getconstStr('ClickInstall').'</a>, '.getconstStr('LogintoBind');
|
|
||||||
$title = 'Install';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
function FGAPIV2($HW_urn, $HW_key, $HW_secret, $Method, $End, $data = '')
|
|
||||||
{
|
|
||||||
if ($HW_urn==''||$HW_key==''||$HW_secret=='') {
|
|
||||||
$tmp['error_code'] = 'Config Error';
|
|
||||||
$tmp['error_msg'] = 'HW urn or access key id or secret is empty.';
|
|
||||||
return json_encode($tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
$URN = explode(':', $HW_urn);
|
|
||||||
$Region = $URN[2];
|
|
||||||
$project_id = $URN[3];
|
|
||||||
|
|
||||||
$host = 'functiongraph.' . $Region . '.myhuaweicloud.com';
|
|
||||||
$path = '/v2/' . $project_id . '/fgs/functions/' . $HW_urn . '/' . $End;
|
|
||||||
$url = 'https://' . $host . $path;
|
|
||||||
$CanonicalURI = spurlencode($path, '/') . '/';
|
|
||||||
$CanonicalQueryString = '';
|
|
||||||
|
|
||||||
date_default_timezone_set('UTC'); // unset last timezone setting
|
|
||||||
$timestamp = date('Ymd\THis\Z');
|
|
||||||
$header['X-Sdk-Date'] = $timestamp;
|
|
||||||
$header['Host'] = $host;
|
|
||||||
$header['Content-Type'] = 'application/json;charset=utf8';
|
|
||||||
ksort($header);
|
|
||||||
$CanonicalHeaders = '';
|
|
||||||
$SignedHeaders = '';
|
|
||||||
foreach ($header as $key => $value) {
|
|
||||||
$CanonicalHeaders .= strtolower($key) . ':' . $value . "\n";
|
|
||||||
$SignedHeaders .= strtolower($key) . ';';
|
|
||||||
}
|
|
||||||
$SignedHeaders = substr($SignedHeaders, 0, -1);
|
|
||||||
$Hashedbody = hash("sha256", $data);
|
|
||||||
$CanonicalRequest = $Method . "\n" . $CanonicalURI . "\n" . $CanonicalQueryString . "\n" . $CanonicalHeaders . "\n" . $SignedHeaders . "\n" . $Hashedbody;
|
|
||||||
$HashedCanonicalRequest = hash("sha256", $CanonicalRequest);
|
|
||||||
$Algorithm = 'SDK-HMAC-SHA256';
|
|
||||||
$StringToSign = $Algorithm . "\n" . $timestamp . "\n" . $HashedCanonicalRequest;
|
|
||||||
$signature = hash_hmac("sha256", $StringToSign, $HW_secret);
|
|
||||||
$Authorization = "$Algorithm Access=$HW_key, SignedHeaders=$SignedHeaders, Signature=$signature";
|
|
||||||
$header['Authorization'] = $Authorization;
|
|
||||||
|
|
||||||
//return curl($Method, $url, $data, $header)['body']; // . $CanonicalRequest;
|
|
||||||
$p = 0;
|
|
||||||
while ($response['stat']==0 && $p<3) {
|
|
||||||
$response = curl($Method, $url, $data, $header);
|
|
||||||
$p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($response['stat']==0) {
|
|
||||||
$tmp['error_code'] = 'Network Error';
|
|
||||||
$tmp['error_msg'] = 'Can not connect ' . $host;
|
|
||||||
return json_encode($tmp);
|
|
||||||
}
|
|
||||||
if ($response['stat']!=200) {
|
|
||||||
$tmp = json_decode($response['body'], true);
|
|
||||||
$tmp['error_code'] .= '.';
|
|
||||||
$tmp['error_msg'] .= '<br>' . $response['stat'] . '<br>' . $CanonicalRequest . '<br>' . json_encode($header) . PHP_EOL;
|
|
||||||
return json_encode($tmp);
|
|
||||||
}
|
|
||||||
return $response['body'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getfunctioninfo($HW_urn, $HW_key, $HW_secret)
|
|
||||||
{
|
|
||||||
return FGAPIV2($HW_urn, $HW_key, $HW_secret, 'GET', 'config');
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateEnvironment($Envs, $HW_urn, $HW_key, $HW_secret)
|
|
||||||
{
|
|
||||||
//echo json_encode($Envs,JSON_PRETTY_PRINT);
|
|
||||||
global $contextUserData;
|
|
||||||
$tmp_env = json_decode(json_decode(getfunctioninfo($HW_urn, $HW_key, $HW_secret),true)['user_data'],true);
|
|
||||||
foreach ($Envs as $key1 => $value1) {
|
|
||||||
$tmp_env[$key1] = $value1;
|
|
||||||
}
|
|
||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
|
||||||
//ksort($tmp_env);
|
|
||||||
sortConfig($tmp_env);
|
|
||||||
|
|
||||||
$tmpdata['handler'] = 'index.handler';
|
|
||||||
$tmpdata['memory_size'] = $contextUserData->getMemorySize()+1-1;
|
|
||||||
$tmpdata['runtime'] = 'PHP7.3';
|
|
||||||
$tmpdata['timeout'] = $contextUserData->getRunningTimeInSeconds()+1-1;
|
|
||||||
$tmpdata['user_data'] = json_encode($tmp_env);
|
|
||||||
|
|
||||||
return FGAPIV2($HW_urn, $HW_key, $HW_secret, 'PUT', 'config', json_encode($tmpdata));
|
|
||||||
}
|
|
||||||
|
|
||||||
function SetbaseConfig($Envs, $HW_urn, $HW_key, $HW_secret)
|
|
||||||
{
|
|
||||||
//echo json_encode($Envs,JSON_PRETTY_PRINT);
|
|
||||||
if ($Envs['ONEMANAGER_CONFIG_SAVE'] == 'file') $Envs = Array( 'ONEMANAGER_CONFIG_SAVE' => 'file' );
|
|
||||||
$tmp_env = json_decode(json_decode(getfunctioninfo($HW_urn, $HW_key, $HW_secret),true)['user_data'],true);
|
|
||||||
foreach ($Envs as $key1 => $value1) {
|
|
||||||
$tmp_env[$key1] = $value1;
|
|
||||||
}
|
|
||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
|
||||||
ksort($tmp_env);
|
|
||||||
|
|
||||||
$tmpdata['handler'] = 'index.handler';
|
|
||||||
$tmpdata['memory_size'] = 128;
|
|
||||||
$tmpdata['runtime'] = 'PHP7.3';
|
|
||||||
$tmpdata['timeout'] = 30;
|
|
||||||
$tmpdata['description'] = 'Onedrive index and manager in Huawei FG.';
|
|
||||||
$tmpdata['user_data'] = json_encode($tmp_env);
|
|
||||||
|
|
||||||
return FGAPIV2($HW_urn, $HW_key, $HW_secret, 'PUT', 'config', json_encode($tmpdata));
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateProgram($HW_urn, $HW_key, $HW_secret, $source)
|
|
||||||
{
|
|
||||||
$tmpdata['code_type'] = 'zip';
|
|
||||||
$tmpdata['func_code']['file'] = base64_encode( file_get_contents($source) );
|
|
||||||
|
|
||||||
return FGAPIV2($HW_urn, $HW_key, $HW_secret, 'PUT', 'code', json_encode($tmpdata));
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error($response)
|
|
||||||
{
|
|
||||||
return isset($response['error_msg']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error_msg($response)
|
|
||||||
{
|
|
||||||
return $response['error_code'] . '<br>
|
|
||||||
' . $response['error_msg'] . '<br>
|
|
||||||
request_id: ' . $response['request_id'] . '<br><br>
|
|
||||||
function_name: ' . $_SERVER['function_name'] . '<br>
|
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfigResponse($response)
|
|
||||||
{
|
|
||||||
return json_decode( $response, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
|
||||||
{
|
|
||||||
$source = '/tmp/code.zip';
|
|
||||||
$outPath = '/tmp/';
|
|
||||||
|
|
||||||
if ($GitSource=='Github') {
|
|
||||||
// 从github下载对应tar.gz,并解压
|
|
||||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
|
||||||
} elseif ($GitSource=='HITGitlab') {
|
|
||||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
|
||||||
} else return json_encode(['error_code'=>'Error', 'error_msg'=>'Git Source input Error!']);
|
|
||||||
$tarfile = '/tmp/github.tar.gz';
|
|
||||||
file_put_contents($tarfile, file_get_contents($url));
|
|
||||||
$phar = new PharData($tarfile);
|
|
||||||
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
|
||||||
|
|
||||||
// 获取解压出的目录名
|
|
||||||
$outPath = findIndexPath($outPath);
|
|
||||||
|
|
||||||
// 将目录中文件打包成zip
|
|
||||||
//$zip=new ZipArchive();
|
|
||||||
$zip=new PharData($source);
|
|
||||||
//if($zip->open($source, ZipArchive::CREATE)){
|
|
||||||
addFileToZip($zip, $outPath); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
|
|
||||||
// $zip->close(); //关闭处理的zip文件
|
|
||||||
//}
|
|
||||||
|
|
||||||
return updateProgram(getConfig('HW_urn'), getConfig('HW_key'), getConfig('HW_secret'), $source);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addFileToZip($zip, $rootpath, $path = '')
|
|
||||||
{
|
|
||||||
if (substr($rootpath,-1)=='/') $rootpath = substr($rootpath, 0, -1);
|
|
||||||
if (substr($path,0,1)=='/') $path = substr($path, 1);
|
|
||||||
$handler=opendir(path_format($rootpath.'/'.$path)); //打开当前文件夹由$path指定。
|
|
||||||
while($filename=readdir($handler)){
|
|
||||||
if($filename != "." && $filename != ".."){//文件夹文件名字为'.'和‘..’,不要对他们进行操作
|
|
||||||
$nowname = path_format($rootpath.'/'.$path."/".$filename);
|
|
||||||
if(is_dir($nowname)){// 如果读取的某个对象是文件夹,则递归
|
|
||||||
$zip->addEmptyDir($path."/".$filename);
|
|
||||||
addFileToZip($zip, $rootpath, $path."/".$filename);
|
|
||||||
}else{ //将文件加入zip对象
|
|
||||||
$newname = $path."/".$filename;
|
|
||||||
if (substr($newname,0,1)=='/') $newname = substr($newname, 1);
|
|
||||||
$zip->addFile($nowname, $newname);
|
|
||||||
//$zip->renameName($nowname, $newname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@closedir($handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
function WaitFunction() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeAuthKey() {
|
|
||||||
if ($_POST['HW_key']!=''&&$_POST['HW_secret']!='') {
|
|
||||||
$tmp['HW_key'] = $_POST['HW_key'];
|
|
||||||
$tmp['HW_secret'] = $_POST['HW_secret'];
|
|
||||||
$response = setConfigResponse( SetbaseConfig($tmp, getConfig('HW_urn'), $tmp['HW_key'], $tmp['HW_secret']) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 400);
|
|
||||||
} else {
|
|
||||||
$html = getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var status = "' . $response['DplStatus'] . '";
|
|
||||||
var i = 0;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$html = '
|
|
||||||
<form action="" method="post" onsubmit="return notnull(this);">
|
|
||||||
<a href="https://console.huaweicloud.com/iam/#/mine/accessKey" target="_blank">点击链接</a>,新增访问密钥,
|
|
||||||
在下载的credentials.csv文件中找到对应信息,填入:<br>
|
|
||||||
<label>Access Key Id:<input name="HW_key" type="text" placeholder="" size=""></label><br>
|
|
||||||
<label>Secret Access Key:<input name="HW_secret" type="password" placeholder="" size=""></label><br>
|
|
||||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.HW_key.value==\'\') {
|
|
||||||
alert(\'input Access Key Id\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.HW_secret.value==\'\') {
|
|
||||||
alert(\'input Secret Access Key\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
return message($html, 'Change platform Auth token or key', 200);
|
|
||||||
}
|
|
|
@ -1,903 +0,0 @@
|
||||||
<?php
|
|
||||||
// https://support.huaweicloud.com/api-functiongraph/functiongraph_06_0110.html
|
|
||||||
// https://support.huaweicloud.com/api-functiongraph/functiongraph_06_0111.html
|
|
||||||
|
|
||||||
global $contextUserData;
|
|
||||||
|
|
||||||
function printInput($event, $context)
|
|
||||||
{
|
|
||||||
$tmp['eventID'] = $context->geteventID();
|
|
||||||
$tmp['RemainingTimeInMilliSeconds'] = $context->getRemainingTimeInMilliSeconds();
|
|
||||||
$tmp['AccessKey'] = $context->getAccessKey();
|
|
||||||
$tmp['SecretKey'] = $context->getSecretKey();
|
|
||||||
$tmp['UserData']['HW_urn'] = $context->getUserData('HW_urn');
|
|
||||||
$tmp['FunctionName'] = $context->getFunctionName();
|
|
||||||
$tmp['RunningTimeInSeconds'] = $context->getRunningTimeInSeconds();
|
|
||||||
$tmp['Version'] = $context->getVersion();
|
|
||||||
$tmp['MemorySize'] = $context->getMemorySize();
|
|
||||||
$tmp['CPUNumber'] = $context->getCPUNumber();
|
|
||||||
$tmp['ProjectID'] = $context->getProjectID();
|
|
||||||
$tmp['Package'] = $context->Package();
|
|
||||||
$tmp['Token'] = $context->getToken();
|
|
||||||
$tmp['Logger'] = $context->getLogger();
|
|
||||||
|
|
||||||
if (strlen(json_encode($event['body']))>500) $event['body']=substr($event['body'],0,strpos($event['body'],'base64')+30) . '...Too Long!...' . substr($event['body'],-50);
|
|
||||||
echo urldecode(json_encode($event, JSON_PRETTY_PRINT)) . '
|
|
||||||
|
|
||||||
' . urldecode(json_encode($tmp, JSON_PRETTY_PRINT)) . '
|
|
||||||
|
|
||||||
';
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetGlobalVariable($event)
|
|
||||||
{
|
|
||||||
$_GET = $event['queryStringParameters'];
|
|
||||||
$postbody = explode("&",$event['body']);
|
|
||||||
foreach ($postbody as $postvalues) {
|
|
||||||
$pos = strpos($postvalues,"=");
|
|
||||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
|
||||||
}
|
|
||||||
$cookiebody = explode("; ",$event['headers']['cookie']);
|
|
||||||
foreach ($cookiebody as $cookievalues) {
|
|
||||||
$pos = strpos($cookievalues,"=");
|
|
||||||
$_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetPathSetting($event, $context)
|
|
||||||
{
|
|
||||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($event['headers']['accept-language'],';')[0],',')[0]);
|
|
||||||
$_SERVER['function_name'] = $context->getFunctionName();
|
|
||||||
$_SERVER['ProjectID'] = $context->getProjectID();
|
|
||||||
$host_name = $event['headers']['host'];
|
|
||||||
$_SERVER['HTTP_HOST'] = $host_name;
|
|
||||||
$path = path_format($event['pathParameters'][''].'/');
|
|
||||||
$path = str_replace('+', '%2B', $path);
|
|
||||||
$_SERVER['base_path'] = path_format($event['path'].'/');
|
|
||||||
if ( $_SERVER['base_path'] == $path ) {
|
|
||||||
$_SERVER['base_path'] = '/';
|
|
||||||
} else {
|
|
||||||
$_SERVER['base_path'] = substr($_SERVER['base_path'], 0, -strlen($path));
|
|
||||||
if ($_SERVER['base_path']=='') $_SERVER['base_path'] = '/';
|
|
||||||
}
|
|
||||||
//$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
|
|
||||||
$_SERVER['REMOTE_ADDR'] = $event['headers']['x-real-ip'];
|
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = $event['headers']['x-requested-with'];
|
|
||||||
$_SERVER['HTTP_USER_AGENT'] = $event['headers']['user-agent'];
|
|
||||||
if (isset($event['headers']['authorization'])) {
|
|
||||||
$basicAuth = splitfirst(base64_decode(splitfirst($event['headers']['authorization'], 'Basic ')[1]), ':');
|
|
||||||
$_SERVER['PHP_AUTH_USER'] = $basicAuth[0];
|
|
||||||
$_SERVER['PHP_AUTH_PW'] = $basicAuth[1];
|
|
||||||
}
|
|
||||||
$_SERVER['REQUEST_SCHEME'] = $event['headers']['x-forwarded-proto'];
|
|
||||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
|
||||||
$_SERVER['referhost'] = explode('/', $event['headers']['referer'])[2];
|
|
||||||
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
|
|
||||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since'];
|
|
||||||
$_SERVER['_APP_SHARE_DIR'] = '/var/share/CFF/processrouter';
|
|
||||||
return $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfig($str, $disktag = '')
|
|
||||||
{
|
|
||||||
$projectPath = splitlast(__DIR__, '/')[0];
|
|
||||||
$configPath = $projectPath . '/.data/config.php';
|
|
||||||
$s = file_get_contents($configPath);
|
|
||||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
|
||||||
if ($configs!='') {
|
|
||||||
$envs = json_decode($configs, true);
|
|
||||||
if (isInnerEnv($str)) {
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
if (isset($envs[$disktag][$str])) {
|
|
||||||
if (isBase64Env($str)) return base64y_decode($envs[$disktag][$str]);
|
|
||||||
else return $envs[$disktag][$str];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isset($envs[$str])) {
|
|
||||||
if (isBase64Env($str)) return base64y_decode($envs[$str]);
|
|
||||||
else return $envs[$str];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfig($arr, $disktag = '')
|
|
||||||
{
|
|
||||||
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$projectPath = splitlast(__DIR__, '/')[0];
|
|
||||||
$configPath = $projectPath . '/.data/config.php';
|
|
||||||
$s = file_get_contents($configPath);
|
|
||||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
|
||||||
if ($configs!='') $envs = json_decode($configs, true);
|
|
||||||
$disktags = explode("|",getConfig('disktag'));
|
|
||||||
$indisk = 0;
|
|
||||||
$operatedisk = 0;
|
|
||||||
foreach ($arr as $k => $v) {
|
|
||||||
if (isCommonEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $envs[$k] = base64y_encode($v);
|
|
||||||
else $envs[$k] = $v;
|
|
||||||
} elseif (isInnerEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v);
|
|
||||||
else $envs[$disktag][$k] = $v;
|
|
||||||
$indisk = 1;
|
|
||||||
} elseif ($k=='disktag_add') {
|
|
||||||
array_push($disktags, $v);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_del') {
|
|
||||||
$disktags = array_diff($disktags, [ $v ]);
|
|
||||||
$envs[$v] = '';
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_copy') {
|
|
||||||
$newtag = $v . '_' . date("Ymd_His");
|
|
||||||
$envs[$newtag] = $envs[$v];
|
|
||||||
array_push($disktags, $newtag);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
|
||||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
|
||||||
} else {
|
|
||||||
$envs[$k] = $v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($indisk) {
|
|
||||||
$diskconfig = $envs[$disktag];
|
|
||||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
|
||||||
ksort($diskconfig);
|
|
||||||
$envs[$disktag] = $diskconfig;
|
|
||||||
}
|
|
||||||
if ($operatedisk) {
|
|
||||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
|
||||||
$tags = [];
|
|
||||||
foreach ($disktags as $tag) {
|
|
||||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
|
||||||
else array_push($tags, $tag);
|
|
||||||
}
|
|
||||||
$envs['disktag'] = implode('|', $tags);
|
|
||||||
$envs[$arr['disktag_newname']] = $envs[$arr['disktag_rename']];
|
|
||||||
$envs[$arr['disktag_rename']] = '';
|
|
||||||
} else {
|
|
||||||
$disktags = array_unique($disktags);
|
|
||||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
|
||||||
if ($disktag_s!='') $envs['disktag'] = substr($disktag_s, 0, -1);
|
|
||||||
else $envs['disktag'] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
|
||||||
//ksort($envs);
|
|
||||||
$response = updateEnvironment($envs, getConfig('HW_urn'), getConfig('HW_key'), getConfig('HW_secret'));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function install()
|
|
||||||
{
|
|
||||||
global $constStr;
|
|
||||||
global $contextUserData;
|
|
||||||
if ($_GET['install2']) {
|
|
||||||
$tmp['admin'] = $_POST['admin'];
|
|
||||||
$response = setConfigResponse( setConfig($tmp) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
if (needUpdate()) {
|
|
||||||
OnekeyUpate();
|
|
||||||
return message('update to github version, reinstall.
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
</script>
|
|
||||||
<meta http-equiv="refresh" content="3;URL=' . $url . '">', 'Program updating', 201);
|
|
||||||
}
|
|
||||||
return output('Jump
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
</script>
|
|
||||||
<meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
|
|
||||||
}
|
|
||||||
if ($_GET['install1']) {
|
|
||||||
//if ($_POST['admin']!='') {
|
|
||||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
|
||||||
$tmp['HW_urn'] = $_POST['HW_urn'];
|
|
||||||
$tmp['HW_key'] = $_POST['HW_key'];
|
|
||||||
$tmp['HW_secret'] = $_POST['HW_secret'];
|
|
||||||
$tmp['ONEMANAGER_CONFIG_SAVE'] = $_POST['ONEMANAGER_CONFIG_SAVE'];
|
|
||||||
//return message($html, $title, 201);
|
|
||||||
$response = setConfigResponse( SetbaseConfig($tmp, $tmp['HW_urn'], $tmp['HW_key'], $tmp['HW_secret']) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
} else {
|
|
||||||
if ($tmp['ONEMANAGER_CONFIG_SAVE'] != 'file') {
|
|
||||||
$html = getconstStr('ONEMANAGER_CONFIG_SAVE_ENV') . '<br><a href="' . $_SERVER['base_path'] . '">' . getconstStr('Home') . '</a>';
|
|
||||||
$title = 'Reinstall';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
$html .= '
|
|
||||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
|
||||||
<label>'.getconstStr('SetAdminPassword').':<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.admin.value==\'\') {
|
|
||||||
alert(\''.getconstStr('SetAdminPassword').'\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SetAdminPassword');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
if ($_GET['install0']) {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install1" method="post" onsubmit="return notnull(this);">
|
|
||||||
language:<br>';
|
|
||||||
foreach ($constStr['languages'] as $key1 => $value1) {
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
|
||||||
}
|
|
||||||
//if (getConfig('HW_urn')==''||getConfig('HW_key')==''||getConfig('HW_secret')=='')
|
|
||||||
$html .= '
|
|
||||||
在函数代码操作页上方找到URN,鼠标放上去后显示URN,复制填入:<br>
|
|
||||||
<label>URN:<input name="HW_urn" type="text" placeholder="urn:fss:ap-XXXXXXXX:XXXXXXXXXXXXXXXXXXXXc01a1e9caXXX:function:default:XXXXX:latest" size=""></label><br>
|
|
||||||
<a href="https://console.huaweicloud.com/iam/#/mine/accessKey" target="_blank">点击链接</a>,新增访问密钥,
|
|
||||||
在下载的credentials.csv文件中找到对应信息,填入:<br>
|
|
||||||
<label>Access Key Id:<input name="HW_key" type="text" placeholder="" size=""></label><br>
|
|
||||||
<label>Secret Access Key:<input name="HW_secret" type="password" placeholder="" size=""></label><br>';
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="ONEMANAGER_CONFIG_SAVE" value="" ' . ('file'==$contextUserData->getUserData('ONEMANAGER_CONFIG_SAVE')?'':'checked') . '>' . getconstStr('ONEMANAGER_CONFIG_SAVE_ENV') . '</label><br>
|
|
||||||
<label><input type="radio" name="ONEMANAGER_CONFIG_SAVE" value="file" ' . ('file'==$contextUserData->getUserData('ONEMANAGER_CONFIG_SAVE')?'checked':'') . '>' . getconstStr('ONEMANAGER_CONFIG_SAVE_FILE') . '</label><br>';
|
|
||||||
$html .= '
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
var nowtime= new Date();
|
|
||||||
var timezone = 0-nowtime.getTimezoneOffset()/60;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie="timezone="+timezone+"; path=/; "+expires;
|
|
||||||
function changelanguage(str)
|
|
||||||
{
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=\'+str+\'; path=/; \'+expires;
|
|
||||||
location.href = location.href;
|
|
||||||
}
|
|
||||||
function notnull(t)
|
|
||||||
{';
|
|
||||||
//if (getConfig('HW_urn')==''||getConfig('HW_key')==''||getConfig('HW_secret')=='')
|
|
||||||
$html .= '
|
|
||||||
if (t.HW_urn.value==\'\') {
|
|
||||||
alert(\'input URN\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.HW_key.value==\'\') {
|
|
||||||
alert(\'input Access Key Id\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.HW_secret.value==\'\') {
|
|
||||||
alert(\'input Secret Access Key\');
|
|
||||||
return false;
|
|
||||||
}';
|
|
||||||
$html .= '
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SelectLanguage');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
$html .= '<a href="?install0">'.getconstStr('ClickInstall').'</a>, '.getconstStr('LogintoBind');
|
|
||||||
$title = 'Install';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getfunctioninfo($HW_urn, $HW_key, $HW_secret)
|
|
||||||
{
|
|
||||||
$URN = explode(':', $HW_urn);
|
|
||||||
$Region = $URN[2];
|
|
||||||
$project_id = $URN[3];
|
|
||||||
$url = 'https://functiongraph.' . $Region . '.myhuaweicloud.com/v2/' . $project_id . '/fgs/functions/' . $HW_urn . '/config';
|
|
||||||
$signer = new Signer();
|
|
||||||
$signer->Key = $HW_key;
|
|
||||||
$signer->Secret = $HW_secret;
|
|
||||||
$req = new Request('GET', $url);
|
|
||||||
$req->headers = array(
|
|
||||||
'content-type' => 'application/json;charset=utf8',
|
|
||||||
);
|
|
||||||
$req->body = '';
|
|
||||||
$curl = $signer->Sign($req);
|
|
||||||
$response = curl_exec($curl);
|
|
||||||
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
||||||
curl_close($curl);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getfunctioncode($HW_urn, $HW_key, $HW_secret)
|
|
||||||
{
|
|
||||||
$URN = explode(':', $HW_urn);
|
|
||||||
$Region = $URN[2];
|
|
||||||
$project_id = $URN[3];
|
|
||||||
$url = 'https://functiongraph.' . $Region . '.myhuaweicloud.com/v2/' . $project_id . '/fgs/functions/' . $HW_urn . '/code';
|
|
||||||
$signer = new Signer();
|
|
||||||
$signer->Key = $HW_key;
|
|
||||||
$signer->Secret = $HW_secret;
|
|
||||||
$req = new Request('GET', $url);
|
|
||||||
$req->headers = array(
|
|
||||||
'content-type' => 'application/json;charset=utf8',
|
|
||||||
);
|
|
||||||
$req->body = '';
|
|
||||||
$curl = $signer->Sign($req);
|
|
||||||
$response = curl_exec($curl);
|
|
||||||
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
||||||
curl_close($curl);
|
|
||||||
//return $response;
|
|
||||||
$url = json_decode($response, true)['func_code']['link'];
|
|
||||||
// return $url;
|
|
||||||
|
|
||||||
|
|
||||||
$bucket = splitfirst( splitfirst($url, '//')[1], '.')[0];
|
|
||||||
$path = splitfirst( splitfirst($url, '//')[1], '/')[1];
|
|
||||||
$date = gmdate('D, d M Y H:i:s') . ' GMT';
|
|
||||||
//$date = 'Wed, 05 Aug 2020 06:34:50 GMT';
|
|
||||||
$StringToSign = 'GET
|
|
||||||
' . '
|
|
||||||
' . '
|
|
||||||
' . '
|
|
||||||
' . 'x-obs-date:' . $date . '
|
|
||||||
' . '/' . $bucket . '/' . $path;
|
|
||||||
|
|
||||||
$signature = base64_encode(hash_hmac('sha1', $StringToSign, $HW_secret, true));
|
|
||||||
$response = curl('GET', $url, false, [ 'Authorization' => 'OBS ' . $HW_key . ':' . $signature, 'x-obs-date' => $date, 'Content-Type' => '' ]);
|
|
||||||
//if ($response['stat']==200) return $response['body'];
|
|
||||||
if ($response['stat']==0) return json_encode( [ 'error_code' => 'Network', 'error_msg' => 'Network error in getting code.' ] );
|
|
||||||
else return $response['body'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function copyFolder($from, $to)
|
|
||||||
{
|
|
||||||
if (substr($from, -1)=='/') $from = substr($from, 0, -1);
|
|
||||||
if (substr($to, -1)=='/') $to = substr($to, 0, -1);
|
|
||||||
if (!file_exists($to)) mkdir($to, 0777);
|
|
||||||
$handler=opendir($from);
|
|
||||||
while($filename=readdir($handler)) {
|
|
||||||
if($filename != '.' && $filename != '..'){
|
|
||||||
$fromfile = $from.'/'.$filename;
|
|
||||||
$tofile = $to.'/'.$filename;
|
|
||||||
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
|
||||||
copyFolder($fromfile, $tofile);
|
|
||||||
}else{
|
|
||||||
copy($fromfile, $tofile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir($handler);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateEnvironment($Envs, $HW_urn, $HW_key, $HW_secret)
|
|
||||||
{
|
|
||||||
sortConfig($Envs);
|
|
||||||
//echo json_encode($Envs,JSON_PRETTY_PRINT);
|
|
||||||
$source = '/tmp/code.zip';
|
|
||||||
$outPath = '/tmp/code/';
|
|
||||||
$oldcode = '/tmp/oldcode.zip';
|
|
||||||
|
|
||||||
// 获取当前代码,并解压
|
|
||||||
$coderoot = __DIR__ . '/../';
|
|
||||||
|
|
||||||
copyFolder($coderoot, $outPath);
|
|
||||||
|
|
||||||
// 将配置写入
|
|
||||||
$prestr = '<?php $configs = \'' . PHP_EOL;
|
|
||||||
$aftstr = PHP_EOL . '\';';
|
|
||||||
file_put_contents($outPath . '.data/config.php', $prestr . json_encode($Envs, JSON_PRETTY_PRINT) . $aftstr);
|
|
||||||
|
|
||||||
// 将目录中文件打包成zip
|
|
||||||
//$zip=new ZipArchive();
|
|
||||||
$zip=new PharData($source);
|
|
||||||
//if($zip->open($source, ZipArchive::CREATE)){
|
|
||||||
addFileToZip($zip, $outPath); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
|
|
||||||
// $zip->close(); //关闭处理的zip文件
|
|
||||||
//}
|
|
||||||
|
|
||||||
return updateProgram($HW_urn, $HW_key, $HW_secret, $source);
|
|
||||||
}
|
|
||||||
|
|
||||||
function SetbaseConfig($Envs, $HW_urn, $HW_key, $HW_secret)
|
|
||||||
{
|
|
||||||
//echo json_encode($Envs,JSON_PRETTY_PRINT);
|
|
||||||
if ($Envs['ONEMANAGER_CONFIG_SAVE'] == 'file') $envs = Array( 'ONEMANAGER_CONFIG_SAVE' => 'file' );
|
|
||||||
else {
|
|
||||||
$Envs['ONEMANAGER_CONFIG_SAVE'] == '';
|
|
||||||
$envs = $Envs;
|
|
||||||
$tmp_env = json_decode(json_decode(getfunctioninfo($HW_urn, $HW_key, $HW_secret),true)['user_data'],true);
|
|
||||||
foreach ($envs as $key1 => $value1) {
|
|
||||||
$tmp_env[$key1] = $value1;
|
|
||||||
}
|
|
||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
|
||||||
ksort($tmp_env);
|
|
||||||
$envs = $tmp_env;
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://functiongraph.cn-north-4.myhuaweicloud.com/v2/{project_id}/fgs/functions/{function_urn}/config
|
|
||||||
$URN = explode(':', $HW_urn);
|
|
||||||
$Region = $URN[2];
|
|
||||||
$project_id = $URN[3];
|
|
||||||
$url = 'https://functiongraph.' . $Region . '.myhuaweicloud.com/v2/' . $project_id . '/fgs/functions/' . $HW_urn . '/config';
|
|
||||||
$signer = new Signer();
|
|
||||||
$signer->Key = $HW_key;
|
|
||||||
$signer->Secret = $HW_secret;
|
|
||||||
$req = new Request('PUT', $url);
|
|
||||||
$req->headers = array(
|
|
||||||
'content-type' => 'application/json;charset=utf8',
|
|
||||||
);
|
|
||||||
$tmpdata['handler'] = 'index.handler';
|
|
||||||
$tmpdata['memory_size'] = 128;
|
|
||||||
$tmpdata['runtime'] = 'PHP7.3';
|
|
||||||
$tmpdata['timeout'] = 30;
|
|
||||||
$tmpdata['description'] = 'Onedrive index and manager in Huawei FG.';
|
|
||||||
$tmpdata['user_data'] = json_encode($envs);
|
|
||||||
$req->body = json_encode($tmpdata);
|
|
||||||
$curl = $signer->Sign($req);
|
|
||||||
$response = curl_exec($curl);
|
|
||||||
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
||||||
curl_close($curl);
|
|
||||||
//return $response;
|
|
||||||
if (api_error(setConfigResponse($response))) {
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
$projectPath = splitlast(__DIR__, '/')[0];
|
|
||||||
$configPath = $projectPath . '/.data/config.php';
|
|
||||||
$s = file_get_contents($configPath);
|
|
||||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
|
||||||
if ($configs!='') $tmp_env = json_decode($configs, true);
|
|
||||||
foreach ($Envs as $k => $v) {
|
|
||||||
$tmp_env[$k] = $v;
|
|
||||||
}
|
|
||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null');
|
|
||||||
//ksort($tmp_env);
|
|
||||||
$response = updateEnvironment($tmp_env, $HW_urn, $HW_key, $HW_secret);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateProgram($HW_urn, $HW_key, $HW_secret, $source)
|
|
||||||
{
|
|
||||||
$URN = explode(':', $HW_urn);
|
|
||||||
$Region = $URN[2];
|
|
||||||
$project_id = $URN[3];
|
|
||||||
$url = 'https://functiongraph.' . $Region . '.myhuaweicloud.com/v2/' . $project_id . '/fgs/functions/' . $HW_urn . '/code';
|
|
||||||
$signer = new Signer();
|
|
||||||
$signer->Key = $HW_key;
|
|
||||||
$signer->Secret = $HW_secret;
|
|
||||||
$req = new Request('PUT', $url);
|
|
||||||
$req->headers = array(
|
|
||||||
'content-type' => 'application/json;charset=utf8',
|
|
||||||
);
|
|
||||||
$tmpdata['code_type'] = 'zip';
|
|
||||||
$tmpdata['func_code']['file'] = base64_encode( file_get_contents($source) );
|
|
||||||
$req->body = json_encode($tmpdata);
|
|
||||||
$curl = $signer->Sign($req);
|
|
||||||
$response = curl_exec($curl);
|
|
||||||
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
||||||
curl_close($curl);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error($response)
|
|
||||||
{
|
|
||||||
return isset($response['error_code']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error_msg($response)
|
|
||||||
{
|
|
||||||
return $response['error_code'] . '<br>
|
|
||||||
' . $response['error_msg'] . '<br>
|
|
||||||
request_id: ' . $response['request_id'] . '<br><br>
|
|
||||||
function_name: ' . $_SERVER['function_name'] . '<br>
|
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfigResponse($response)
|
|
||||||
{
|
|
||||||
return json_decode( $response, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
|
||||||
{
|
|
||||||
$source = '/tmp/code.zip';
|
|
||||||
$outPath = '/tmp/';
|
|
||||||
|
|
||||||
if ($GitSource=='Github') {
|
|
||||||
// 从github下载对应tar.gz,并解压
|
|
||||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
|
||||||
} elseif ($GitSource=='HITGitlab') {
|
|
||||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
|
||||||
} else return json_encode(['error_code'=>'Error', 'error_msg'=>'Git Source input Error!']);
|
|
||||||
$tarfile = '/tmp/github.tar.gz';
|
|
||||||
file_put_contents($tarfile, file_get_contents($url));
|
|
||||||
$phar = new PharData($tarfile);
|
|
||||||
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
|
||||||
|
|
||||||
// 获取解压出的目录名
|
|
||||||
$outPath = findIndexPath($outPath);
|
|
||||||
|
|
||||||
// 放入配置文件
|
|
||||||
file_put_contents($outPath . '/.data/config.php', file_get_contents(__DIR__ . '/../.data/config.php'));
|
|
||||||
|
|
||||||
// 将目录中文件打包成zip
|
|
||||||
//$zip=new ZipArchive();
|
|
||||||
$zip=new PharData($source);
|
|
||||||
//if($zip->open($source, ZipArchive::CREATE)){
|
|
||||||
addFileToZip($zip, $outPath); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
|
|
||||||
// $zip->close(); //关闭处理的zip文件
|
|
||||||
//}
|
|
||||||
|
|
||||||
return updateProgram(getConfig('HW_urn'), getConfig('HW_key'), getConfig('HW_secret'), $source);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addFileToZip($zip, $rootpath, $path = '')
|
|
||||||
{
|
|
||||||
if (substr($rootpath,-1)=='/') $rootpath = substr($rootpath, 0, -1);
|
|
||||||
if (substr($path,0,1)=='/') $path = substr($path, 1);
|
|
||||||
$handler=opendir(path_format($rootpath.'/'.$path)); //打开当前文件夹由$path指定。
|
|
||||||
while($filename=readdir($handler)){
|
|
||||||
if($filename != "." && $filename != ".."){//文件夹文件名字为'.'和‘..’,不要对他们进行操作
|
|
||||||
$nowname = path_format($rootpath.'/'.$path."/".$filename);
|
|
||||||
if(is_dir($nowname)){// 如果读取的某个对象是文件夹,则递归
|
|
||||||
$zip->addEmptyDir($path."/".$filename);
|
|
||||||
addFileToZip($zip, $rootpath, $path."/".$filename);
|
|
||||||
}else{ //将文件加入zip对象
|
|
||||||
$newname = $path."/".$filename;
|
|
||||||
if (substr($newname,0,1)=='/') $newname = substr($newname, 1);
|
|
||||||
$zip->addFile($nowname, $newname);
|
|
||||||
//$zip->renameName($nowname, $newname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@closedir($handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
define("BasicDateFormat", "Ymd\THis\Z");
|
|
||||||
define("Algorithm", "SDK-HMAC-SHA256");
|
|
||||||
define("HeaderXDate", "X-Sdk-Date");
|
|
||||||
define("HeaderHost", "host");
|
|
||||||
define("HeaderAuthorization", "Authorization");
|
|
||||||
define("HeaderContentSha256", "X-Sdk-Content-Sha256");
|
|
||||||
|
|
||||||
class Request
|
|
||||||
{
|
|
||||||
public $method = '';
|
|
||||||
public $scheme = '';
|
|
||||||
public $host = '';
|
|
||||||
public $uri = '';
|
|
||||||
public $query = array();
|
|
||||||
public $headers = array();
|
|
||||||
public $body = '';
|
|
||||||
|
|
||||||
function __construct()
|
|
||||||
{
|
|
||||||
$args = func_get_args();
|
|
||||||
$i = count($args);
|
|
||||||
if ($i == 0) {
|
|
||||||
$this->construct(NULL, NULL, NULL, NULL);
|
|
||||||
} elseif ($i == 1) {
|
|
||||||
$this->construct($args[0], NULL, NULL, NULL);
|
|
||||||
} elseif ($i == 2) {
|
|
||||||
$this->construct($args[0], $args[1], NULL, NULL);
|
|
||||||
} elseif ($i == 3) {
|
|
||||||
$this->construct($args[0], $args[1], $args[2], NULL);
|
|
||||||
} else {
|
|
||||||
$this->construct($args[0], $args[1], $args[2], $args[3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function construct($method, $url, $headers, $body)
|
|
||||||
{
|
|
||||||
if ($method != NULL) {
|
|
||||||
$this->method = $method;
|
|
||||||
}
|
|
||||||
if ($url != NULL) {
|
|
||||||
$spl = explode("://", $url, 2);
|
|
||||||
$scheme = 'http';
|
|
||||||
if (count($spl) > 1) {
|
|
||||||
$scheme = $spl[0];
|
|
||||||
$url = $spl[1];
|
|
||||||
}
|
|
||||||
$spl = explode("?", $url, 2);
|
|
||||||
$url = $spl[0];
|
|
||||||
$query = array();
|
|
||||||
if (count($spl) > 1) {
|
|
||||||
foreach (explode("&", $spl[1]) as $kv) {
|
|
||||||
$spl = explode("=", $kv, 2);
|
|
||||||
$key = $spl[0];
|
|
||||||
if (count($spl) == 1) {
|
|
||||||
$value = "";
|
|
||||||
} else {
|
|
||||||
$value = $spl[1];
|
|
||||||
}
|
|
||||||
if ($key != "") {
|
|
||||||
$key = urldecode($key);
|
|
||||||
$value = urldecode($value);
|
|
||||||
if (array_key_exists($key, $query)) {
|
|
||||||
array_push($query[$key], $value);
|
|
||||||
} else {
|
|
||||||
$query[$key] = array($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$spl = explode("/", $url, 2);
|
|
||||||
$host = $spl[0];
|
|
||||||
if (count($spl) == 1) {
|
|
||||||
$url = "/";
|
|
||||||
} else {
|
|
||||||
$url = "/" . $spl[1];
|
|
||||||
}
|
|
||||||
$this->scheme = $scheme;
|
|
||||||
$this->host = $host;
|
|
||||||
$this->uri = urldecode($url);
|
|
||||||
$this->query = $query;
|
|
||||||
}
|
|
||||||
if ($headers != NULL) {
|
|
||||||
$this->headers = $headers;
|
|
||||||
}
|
|
||||||
if ($body != NULL) {
|
|
||||||
$this->body = $body;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Signer
|
|
||||||
{
|
|
||||||
public $Key = '';
|
|
||||||
public $Secret = '';
|
|
||||||
|
|
||||||
function escape($string)
|
|
||||||
{
|
|
||||||
$entities = array('+', "%7E");
|
|
||||||
$replacements = array('%20', "~");
|
|
||||||
return str_replace($entities, $replacements, urlencode($string));
|
|
||||||
}
|
|
||||||
|
|
||||||
function findHeader($r, $header)
|
|
||||||
{
|
|
||||||
foreach ($r->headers as $key => $value) {
|
|
||||||
if (!strcasecmp($key, $header)) {
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build a CanonicalRequest from a regular request string
|
|
||||||
//
|
|
||||||
// CanonicalRequest =
|
|
||||||
// HTTPRequestMethod + '\n' +
|
|
||||||
// CanonicalURI + '\n' +
|
|
||||||
// CanonicalQueryString + '\n' +
|
|
||||||
// CanonicalHeaders + '\n' +
|
|
||||||
// SignedHeaders + '\n' +
|
|
||||||
// HexEncode(Hash(RequestPayload))
|
|
||||||
function CanonicalRequest($r, $signedHeaders)
|
|
||||||
{
|
|
||||||
$CanonicalURI = $this->CanonicalURI($r);
|
|
||||||
$CanonicalQueryString = $this->CanonicalQueryString($r);
|
|
||||||
$canonicalHeaders = $this->CanonicalHeaders($r, $signedHeaders);
|
|
||||||
$signedHeadersString = join(";", $signedHeaders);
|
|
||||||
$hash = $this->findHeader($r, HeaderContentSha256);
|
|
||||||
if (!$hash) {
|
|
||||||
$hash = hash("sha256", $r->body);
|
|
||||||
}
|
|
||||||
return "$r->method\n$CanonicalURI\n$CanonicalQueryString\n$canonicalHeaders\n$signedHeadersString\n$hash";
|
|
||||||
}
|
|
||||||
|
|
||||||
// CanonicalURI returns request uri
|
|
||||||
function CanonicalURI($r)
|
|
||||||
{
|
|
||||||
$pattens = explode("/", $r->uri);
|
|
||||||
$uri = array();
|
|
||||||
foreach ($pattens as $v) {
|
|
||||||
array_push($uri, $this->escape($v));
|
|
||||||
}
|
|
||||||
$urlpath = join("/", $uri);
|
|
||||||
if (substr($urlpath, -1) != "/") {
|
|
||||||
$urlpath = $urlpath . "/";
|
|
||||||
}
|
|
||||||
return $urlpath;
|
|
||||||
}
|
|
||||||
|
|
||||||
// CanonicalQueryString
|
|
||||||
function CanonicalQueryString($r)
|
|
||||||
{
|
|
||||||
$keys = array();
|
|
||||||
foreach ($r->query as $key => $value) {
|
|
||||||
array_push($keys, $key);
|
|
||||||
}
|
|
||||||
sort($keys);
|
|
||||||
$a = array();
|
|
||||||
foreach ($keys as $key) {
|
|
||||||
$k = $this->escape($key);
|
|
||||||
$value = $r->query[$key];
|
|
||||||
if (is_array($value)) {
|
|
||||||
sort($value);
|
|
||||||
foreach ($value as $v) {
|
|
||||||
$kv = "$k=" . $this->escape($v);
|
|
||||||
array_push($a, $kv);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$kv = "$k=" . $this->escape($value);
|
|
||||||
array_push($a, $kv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return join("&", $a);
|
|
||||||
}
|
|
||||||
|
|
||||||
// CanonicalHeaders
|
|
||||||
function CanonicalHeaders($r, $signedHeaders)
|
|
||||||
{
|
|
||||||
$headers = array();
|
|
||||||
foreach ($r->headers as $key => $value) {
|
|
||||||
$headers[strtolower($key)] = trim($value);
|
|
||||||
}
|
|
||||||
$a = array();
|
|
||||||
foreach ($signedHeaders as $key) {
|
|
||||||
array_push($a, $key . ':' . $headers[$key]);
|
|
||||||
}
|
|
||||||
return join("\n", $a) . "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
function curlHeaders($r)
|
|
||||||
{
|
|
||||||
$header = array();
|
|
||||||
foreach ($r->headers as $key => $value) {
|
|
||||||
array_push($header, strtolower($key) . ':' . trim($value));
|
|
||||||
}
|
|
||||||
return $header;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SignedHeaders
|
|
||||||
function SignedHeaders($r)
|
|
||||||
{
|
|
||||||
$a = array();
|
|
||||||
foreach ($r->headers as $key => $value) {
|
|
||||||
array_push($a, strtolower($key));
|
|
||||||
}
|
|
||||||
sort($a);
|
|
||||||
return $a;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a "String to Sign".
|
|
||||||
function StringToSign($canonicalRequest, $t)
|
|
||||||
{
|
|
||||||
date_default_timezone_set('UTC');
|
|
||||||
$date = date(BasicDateFormat, $t);
|
|
||||||
$hash = hash("sha256", $canonicalRequest);
|
|
||||||
return "SDK-HMAC-SHA256\n$date\n$hash";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the HWS Signature.
|
|
||||||
function SignStringToSign($stringToSign, $signingKey)
|
|
||||||
{
|
|
||||||
return hash_hmac("sha256", $stringToSign, $signingKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the finalized value for the "Authorization" header. The signature parameter is the output from SignStringToSign
|
|
||||||
function AuthHeaderValue($signature, $accessKey, $signedHeaders)
|
|
||||||
{
|
|
||||||
$signedHeadersString = join(";", $signedHeaders);
|
|
||||||
return "SDK-HMAC-SHA256 Access=$accessKey, SignedHeaders=$signedHeadersString, Signature=$signature";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Sign($r)
|
|
||||||
{
|
|
||||||
date_default_timezone_set('UTC');
|
|
||||||
$date = $this->findHeader($r, HeaderXDate);
|
|
||||||
if ($date) {
|
|
||||||
$t = date_timestamp_get(date_create_from_format(BasicDateFormat, $date));
|
|
||||||
}
|
|
||||||
if (!@$t) {
|
|
||||||
$t = time();
|
|
||||||
$r->headers[HeaderXDate] = date(BasicDateFormat, $t);
|
|
||||||
}
|
|
||||||
$queryString = $this->CanonicalQueryString($r);
|
|
||||||
if ($queryString != "") {
|
|
||||||
$queryString = "?" . $queryString;
|
|
||||||
}
|
|
||||||
$signedHeaders = $this->SignedHeaders($r);
|
|
||||||
$canonicalRequest = $this->CanonicalRequest($r, $signedHeaders);
|
|
||||||
$stringToSign = $this->StringToSign($canonicalRequest, $t);
|
|
||||||
$signature = $this->SignStringToSign($stringToSign, $this->Secret);
|
|
||||||
$authValue = $this->AuthHeaderValue($signature, $this->Key, $signedHeaders);
|
|
||||||
$r->headers[HeaderAuthorization] = $authValue;
|
|
||||||
|
|
||||||
$curl = curl_init();
|
|
||||||
$uri = str_replace(array("%2F"), array("/"), rawurlencode($r->uri));
|
|
||||||
$url = $r->scheme . '://' . $r->host . $uri . $queryString;
|
|
||||||
$headers = $this->curlHeaders($r);
|
|
||||||
curl_setopt($curl, CURLOPT_URL, $url);
|
|
||||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
|
||||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $r->method);
|
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $r->body);
|
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
|
|
||||||
curl_setopt($curl, CURLOPT_NOBODY, FALSE);
|
|
||||||
return $curl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function WaitFunction() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeAuthKey() {
|
|
||||||
if ($_POST['HW_key']!=''&&$_POST['HW_secret']!='') {
|
|
||||||
$tmp['HW_key'] = $_POST['HW_key'];
|
|
||||||
$tmp['HW_secret'] = $_POST['HW_secret'];
|
|
||||||
$response = setConfigResponse( SetbaseConfig($tmp, getConfig('HW_urn'), $tmp['HW_key'], $tmp['HW_secret']) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 400);
|
|
||||||
} else {
|
|
||||||
$html = getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var status = "' . $response['DplStatus'] . '";
|
|
||||||
var i = 0;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$html = '
|
|
||||||
<form action="" method="post" onsubmit="return notnull(this);">
|
|
||||||
<a href="https://console.huaweicloud.com/iam/#/mine/accessKey" target="_blank">点击链接</a>,新增访问密钥,
|
|
||||||
在下载的credentials.csv文件中找到对应信息,填入:<br>
|
|
||||||
<label>Access Key Id:<input name="HW_key" type="text" placeholder="" size=""></label><br>
|
|
||||||
<label>Secret Access Key:<input name="HW_secret" type="password" placeholder="" size=""></label><br>
|
|
||||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.HW_key.value==\'\') {
|
|
||||||
alert(\'input Access Key Id\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.HW_secret.value==\'\') {
|
|
||||||
alert(\'input Secret Access Key\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
return message($html, 'Change platform Auth token or key', 200);
|
|
||||||
}
|
|
|
@ -1,394 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
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 ($_SERVER['REQUEST_SCHEME']!='http'&&$_SERVER['REQUEST_SCHEME']!='https') {
|
|
||||||
if ($_SERVER['HTTP_X_FORWARDED_PROTO']!='') {
|
|
||||||
$tmp = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0];
|
|
||||||
if ($tmp=='http'||$tmp=='https') $_SERVER['REQUEST_SCHEME'] = $tmp;
|
|
||||||
}
|
|
||||||
if ($_SERVER['HTTP_FLY_FORWARDED_PROTO']!='') $_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_FLY_FORWARDED_PROTO'];
|
|
||||||
}
|
|
||||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
|
||||||
$_SERVER['referhost'] = explode('/', $_SERVER['HTTP_REFERER'])[2];
|
|
||||||
if (isset($_SERVER['DOCUMENT_ROOT'])&&$_SERVER['DOCUMENT_ROOT']==='/app') $_SERVER['base_path'] = '/';
|
|
||||||
else $_SERVER['base_path'] = path_format(substr($_SERVER['SCRIPT_NAME'], 0, -10) . '/');
|
|
||||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
|
||||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
|
||||||
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
|
||||||
else $path = $_SERVER['REQUEST_URI'];
|
|
||||||
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
|
||||||
return $path;
|
|
||||||
//return substr($path, 1);
|
|
||||||
//return spurlencode($path, '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getGET()
|
|
||||||
{
|
|
||||||
if (!$_POST) {
|
|
||||||
if (!!$HTTP_RAW_POST_DATA) {
|
|
||||||
$tmpdata = $HTTP_RAW_POST_DATA;
|
|
||||||
} else {
|
|
||||||
$tmpdata = file_get_contents('php://input');
|
|
||||||
}
|
|
||||||
if (!!$tmpdata) {
|
|
||||||
$postbody = explode("&", $tmpdata);
|
|
||||||
foreach ($postbody as $postvalues) {
|
|
||||||
$pos = strpos($postvalues,"=");
|
|
||||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
|
||||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
|
||||||
if ($p>0) {
|
|
||||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
|
||||||
$getstrarr = explode("&",$getstr);
|
|
||||||
foreach ($getstrarr as $getvalues) {
|
|
||||||
if ($getvalues != '') {
|
|
||||||
$pos = strpos($getvalues, "=");
|
|
||||||
//echo $pos;
|
|
||||||
if ($pos > 0) {
|
|
||||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
|
||||||
} else {
|
|
||||||
$getarry[urldecode($getvalues)] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($getarry)) {
|
|
||||||
return $getarry;
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfig($str, $disktag = '')
|
|
||||||
{
|
|
||||||
global $slash;
|
|
||||||
$projectPath = splitlast(__DIR__, $slash)[0];
|
|
||||||
$configPath = $projectPath . $slash . '.data' . $slash . 'config.php';
|
|
||||||
$s = file_get_contents($configPath);
|
|
||||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
|
||||||
if ($configs!='') {
|
|
||||||
$envs = json_decode($configs, true);
|
|
||||||
if (isInnerEnv($str)) {
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
if (isset($envs[$disktag][$str])) {
|
|
||||||
if (isBase64Env($str)) return base64y_decode($envs[$disktag][$str]);
|
|
||||||
else return $envs[$disktag][$str];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isset($envs[$str])) {
|
|
||||||
if (isBase64Env($str)) return base64y_decode($envs[$str]);
|
|
||||||
else return $envs[$str];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfig($arr, $disktag = '')
|
|
||||||
{
|
|
||||||
global $slash;
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$projectPath = splitlast(__DIR__, $slash)[0];
|
|
||||||
$configPath = $projectPath . $slash . '.data' . $slash . 'config.php';
|
|
||||||
$s = file_get_contents($configPath);
|
|
||||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
|
||||||
if ($configs!='') $envs = json_decode($configs, true);
|
|
||||||
$disktags = explode("|", getConfig('disktag'));
|
|
||||||
$indisk = 0;
|
|
||||||
$operatedisk = 0;
|
|
||||||
foreach ($arr as $k => $v) {
|
|
||||||
if (isCommonEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $envs[$k] = base64y_encode($v);
|
|
||||||
else $envs[$k] = $v;
|
|
||||||
} elseif (isInnerEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v);
|
|
||||||
else $envs[$disktag][$k] = $v;
|
|
||||||
$indisk = 1;
|
|
||||||
} elseif ($k=='disktag_add') {
|
|
||||||
array_push($disktags, $v);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_del') {
|
|
||||||
$disktags = array_diff($disktags, [ $v ]);
|
|
||||||
$envs[$v] = '';
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_copy') {
|
|
||||||
$newtag = $v . '_' . date("Ymd_His");
|
|
||||||
$envs[$newtag] = $envs[$v];
|
|
||||||
array_push($disktags, $newtag);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
|
||||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
|
||||||
} else {
|
|
||||||
//$tmpdisk = json_decode($v, true);
|
|
||||||
//var_dump($tmpdisk);
|
|
||||||
//error_log(json_encode($tmpdisk));
|
|
||||||
//if ($tmpdisk===null)
|
|
||||||
$envs[$k] = $v;
|
|
||||||
//else $envs[$k] = $tmpdisk;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($indisk) {
|
|
||||||
$diskconfig = $envs[$disktag];
|
|
||||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
|
||||||
ksort($diskconfig);
|
|
||||||
$envs[$disktag] = $diskconfig;
|
|
||||||
}
|
|
||||||
if ($operatedisk) {
|
|
||||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
|
||||||
$tags = [];
|
|
||||||
foreach ($disktags as $tag) {
|
|
||||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
|
||||||
else array_push($tags, $tag);
|
|
||||||
}
|
|
||||||
$envs['disktag'] = implode('|', $tags);
|
|
||||||
$envs[$arr['disktag_newname']] = $envs[$arr['disktag_rename']];
|
|
||||||
unset($envs[$arr['disktag_rename']]);
|
|
||||||
} else {
|
|
||||||
$disktags = array_unique($disktags);
|
|
||||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
|
||||||
if ($disktag_s!='') $envs['disktag'] = substr($disktag_s, 0, -1);
|
|
||||||
else $envs['disktag'] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
|
||||||
//ksort($envs);
|
|
||||||
sortConfig($envs);
|
|
||||||
|
|
||||||
//echo '<pre>'. json_encode($envs, JSON_PRETTY_PRINT).'</pre>';
|
|
||||||
$prestr = '<?php $configs = \'' . PHP_EOL;
|
|
||||||
$aftstr = PHP_EOL . '\';';
|
|
||||||
$response = file_put_contents($configPath, $prestr . json_encode($envs, JSON_PRETTY_PRINT) . $aftstr);
|
|
||||||
if ($response>0) return json_encode( [ 'response' => 'success' ] );
|
|
||||||
return json_encode( [ 'message' => 'Failed to write config.', 'code' => 'failed' ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
function install()
|
|
||||||
{
|
|
||||||
global $constStr;
|
|
||||||
if ($_GET['install2']) {
|
|
||||||
if ($_POST['admin']!='') {
|
|
||||||
$tmp['admin'] = $_POST['admin'];
|
|
||||||
//$tmp['language'] = $_COOKIE['language'];
|
|
||||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
|
||||||
$response = setConfigResponse( setConfig($tmp) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
} else {
|
|
||||||
return output('Jump
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
</script>
|
|
||||||
<meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($_GET['install1']) {
|
|
||||||
if (!ConfigWriteable()) {
|
|
||||||
$html .= getconstStr('MakesuerWriteable');
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
/*if (!RewriteEngineOn()) {
|
|
||||||
$html .= getconstStr('MakesuerRewriteOn');
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}*/
|
|
||||||
$html .= '<button id="checkrewritebtn" onclick="checkrewrite();">'.getconstStr('MakesuerRewriteOn').'</button>
|
|
||||||
<div id="formdiv" style="display: none">
|
|
||||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
|
||||||
<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"><br>
|
|
||||||
<input id="submitbtn" type="submit" value="'.getconstStr('Submit').'" disabled>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var nowtime= new Date();
|
|
||||||
var timezone = 0-nowtime.getTimezoneOffset()/60;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie="timezone="+timezone+"; path=/; "+expires;
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.admin.value==\'\') {
|
|
||||||
alert(\''.getconstStr('SetAdminPassword').'\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
function checkrewrite()
|
|
||||||
{
|
|
||||||
url=location.protocol + "//" + location.host;
|
|
||||||
//if (location.port!="") url += ":" + location.port;
|
|
||||||
url += location.pathname;
|
|
||||||
if (url.substr(-1)!="/") url += "/";
|
|
||||||
url += "app.json";
|
|
||||||
url += "?" + Date.now();
|
|
||||||
var xhr4 = new XMLHttpRequest();
|
|
||||||
xhr4.open("GET", url);
|
|
||||||
xhr4.setRequestHeader("x-requested-with","XMLHttpRequest");
|
|
||||||
xhr4.send(null);
|
|
||||||
xhr4.onload = function(e){
|
|
||||||
console.log(xhr4.responseText+","+xhr4.status);
|
|
||||||
if (xhr4.status==201) {
|
|
||||||
document.getElementById("checkrewritebtn").style.display = "none";
|
|
||||||
document.getElementById("submitbtn").disabled = false;
|
|
||||||
document.getElementById("formdiv").style.display = "";
|
|
||||||
} else {
|
|
||||||
alert("' . getconstStr('MakesuerRewriteOn') . '?\nfalse\n\nUrl: " + url + "\nExpect http code 201, but received " + xhr4.status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SetAdminPassword');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
if ($_GET['install0']) {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install1" method="post">
|
|
||||||
language:<br>';
|
|
||||||
foreach ($constStr['languages'] as $key1 => $value1) {
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
|
||||||
}
|
|
||||||
$html .= '
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function changelanguage(str)
|
|
||||||
{
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=\'+str+\'; path=/; \'+expires;
|
|
||||||
location.href = location.href;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SelectLanguage');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
$title = 'Install';
|
|
||||||
$html = '<a href="?install0">' . getconstStr('ClickInstall') . '</a>, ' . getconstStr('LogintoBind');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ConfigWriteable()
|
|
||||||
{
|
|
||||||
$t = md5( md5(time()).rand(1000,9999) );
|
|
||||||
$r = setConfig([ 'tmp' => $t ]);
|
|
||||||
$tmp = getConfig('tmp');
|
|
||||||
setConfig([ 'tmp' => '' ]);
|
|
||||||
if ($tmp == $t) return true;
|
|
||||||
if ($r) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error($response)
|
|
||||||
{
|
|
||||||
return isset($response['message']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error_msg($response)
|
|
||||||
{
|
|
||||||
return $response['code'] . '<br>
|
|
||||||
' . $response['message'] . '<br>
|
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfigResponse($response)
|
|
||||||
{
|
|
||||||
return json_decode($response, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
|
||||||
{
|
|
||||||
global $slash;
|
|
||||||
// __DIR__ is xxx/platform
|
|
||||||
$projectPath = splitlast(__DIR__, $slash)[0];
|
|
||||||
|
|
||||||
if ($GitSource=='Github') {
|
|
||||||
// 从github下载对应tar.gz,并解压
|
|
||||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
|
||||||
} elseif ($GitSource=='HITGitlab') {
|
|
||||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
|
||||||
} else return 0;
|
|
||||||
$tarfile = $projectPath . $slash .'github.tar.gz';
|
|
||||||
$githubfile = file_get_contents($url);
|
|
||||||
if (!$githubfile) return 0;
|
|
||||||
file_put_contents($tarfile, $githubfile);
|
|
||||||
|
|
||||||
if (splitfirst(PHP_VERSION, '.')[0] > '5') {
|
|
||||||
$phar = new PharData($tarfile); // need php5.3, 7, 8
|
|
||||||
$phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖
|
|
||||||
} else {
|
|
||||||
ob_start();
|
|
||||||
passthru('tar -xzvf ' . $tarfile, $stat);
|
|
||||||
ob_get_clean();
|
|
||||||
}
|
|
||||||
unlink($tarfile);
|
|
||||||
|
|
||||||
$outPath = '';
|
|
||||||
$outPath = findIndexPath($projectPath);
|
|
||||||
//error_log1($outPath);
|
|
||||||
if ($outPath=='') return 0;
|
|
||||||
|
|
||||||
//unlink($outPath.'/config.php');
|
|
||||||
$response = rename($projectPath . $slash . '.data' . $slash . 'config.php', $outPath . $slash . '.data' . $slash . 'config.php');
|
|
||||||
if (!$response) {
|
|
||||||
$tmp1['code'] = "Move Failed";
|
|
||||||
$tmp1['message'] = "Can not move " . $projectPath . $slash . '.data' . $slash . 'config.php' . " to " . $outPath . $slash . '.data' . $slash . 'config.php';
|
|
||||||
return json_encode($tmp1);
|
|
||||||
}
|
|
||||||
return moveFolder($outPath, $projectPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
function moveFolder($from, $to)
|
|
||||||
{
|
|
||||||
global $slash;
|
|
||||||
if (substr($from, -1)==$slash) $from = substr($from, 0, -1);
|
|
||||||
if (substr($to, -1)==$slash) $to = substr($to, 0, -1);
|
|
||||||
if (!file_exists($to)) mkdir($to, 0777);
|
|
||||||
$handler=opendir($from);
|
|
||||||
while($filename=readdir($handler)) {
|
|
||||||
if($filename != '.' && $filename != '..'){
|
|
||||||
$fromfile = $from . $slash . $filename;
|
|
||||||
$tofile = $to . $slash . $filename;
|
|
||||||
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
|
||||||
$response = moveFolder($fromfile, $tofile);
|
|
||||||
if (api_error(setConfigResponse($response))) return $response;
|
|
||||||
}else{
|
|
||||||
//if (file_exists($tofile)) unlink($tofile);
|
|
||||||
$response = rename($fromfile, $tofile);
|
|
||||||
if (!$response) {
|
|
||||||
$tmp['code'] = "Move Failed";
|
|
||||||
$tmp['message'] = "Can not move " . $fromfile . " to " . $tofile;
|
|
||||||
return json_encode($tmp);
|
|
||||||
}
|
|
||||||
if (file_exists($fromfile)) unlink($fromfile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir($handler);
|
|
||||||
rmdir($from);
|
|
||||||
return json_encode( [ 'response' => 'success' ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
function WaitFunction() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeAuthKey() {
|
|
||||||
return message("Not need.", 'Change platform Auth token or key', 404);
|
|
||||||
}
|
|
|
@ -1,382 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
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 ($_SERVER['REQUEST_SCHEME']!='http'&&$_SERVER['REQUEST_SCHEME']!='https') {
|
|
||||||
if ($_SERVER['HTTP_X_FORWARDED_PROTO']!='') {
|
|
||||||
$tmp = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0];
|
|
||||||
if ($tmp=='http'||$tmp=='https') $_SERVER['REQUEST_SCHEME'] = $tmp;
|
|
||||||
}
|
|
||||||
if ($_SERVER['HTTP_FLY_FORWARDED_PROTO']!='') $_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_FLY_FORWARDED_PROTO'];
|
|
||||||
}
|
|
||||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
|
||||||
$_SERVER['referhost'] = explode('/', $_SERVER['HTTP_REFERER'])[2];
|
|
||||||
$_SERVER['base_path'] = '/';
|
|
||||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
|
||||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
|
||||||
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
|
||||||
else $path = $_SERVER['REQUEST_URI'];
|
|
||||||
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
|
||||||
return $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getGET()
|
|
||||||
{
|
|
||||||
if (!$_POST) {
|
|
||||||
if (!!$HTTP_RAW_POST_DATA) {
|
|
||||||
$tmpdata = $HTTP_RAW_POST_DATA;
|
|
||||||
} else {
|
|
||||||
$tmpdata = file_get_contents('php://input');
|
|
||||||
}
|
|
||||||
if (!!$tmpdata) {
|
|
||||||
$postbody = explode("&", $tmpdata);
|
|
||||||
foreach ($postbody as $postvalues) {
|
|
||||||
$pos = strpos($postvalues,"=");
|
|
||||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
|
||||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
|
||||||
if ($p>0) {
|
|
||||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
|
||||||
$getstrarr = explode("&",$getstr);
|
|
||||||
foreach ($getstrarr as $getvalues) {
|
|
||||||
if ($getvalues != '') {
|
|
||||||
$pos = strpos($getvalues, "=");
|
|
||||||
//echo $pos;
|
|
||||||
if ($pos > 0) {
|
|
||||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
|
||||||
} else {
|
|
||||||
$getarry[urldecode($getvalues)] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($getarry)) {
|
|
||||||
return $getarry;
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function ReplitAPI($op, $key, $value = '') {
|
|
||||||
//error_log1($op . '_' . $key . '_' . $value);
|
|
||||||
$apiurl = getenv('REPLIT_DB_URL');
|
|
||||||
//foreach (explode("\n", curl('GET', $apiurl . '?prefix')['body']) as $a) curl('DELETE', $apiurl . '/' . $a);
|
|
||||||
if ($op === 'r') {
|
|
||||||
if (!($config = getcache('REPLIT_CONFIG'))) {
|
|
||||||
$config = json_decode(curl('GET', $apiurl . '/REPLIT_CONFIG')['body'], true);
|
|
||||||
savecache('REPLIT_CONFIG', $config);
|
|
||||||
}
|
|
||||||
return ['stat'=>200, 'body'=>(is_array($config[$key])?json_encode($config[$key]):$config[$key])];
|
|
||||||
} elseif ($op === 'w') {
|
|
||||||
return curl('POST', $apiurl, 'REPLIT_CONFIG=' . $value, ["Content-Type"=>"application/x-www-form-urlencoded"]);
|
|
||||||
} elseif ($op === 'd') {
|
|
||||||
// not use
|
|
||||||
return curl('DELETE', $apiurl . '/' . $key);
|
|
||||||
} else {
|
|
||||||
return ['stat'=>500, 'body'=>'error option input to function ReplitAPI().'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfig($str, $disktag = '')
|
|
||||||
{
|
|
||||||
if (isInnerEnv($str)) {
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$env = json_decode(ReplitAPI('r', $disktag)['body'], true);
|
|
||||||
if (isset($env[$str])) {
|
|
||||||
if (isBase64Env($str)) return base64y_decode($env[$str]);
|
|
||||||
else return $env[$str];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isBase64Env($str)) return base64y_decode(ReplitAPI('r', $str)['body']);
|
|
||||||
else return ReplitAPI('r', $str)['body'];
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfig($arr, $disktag = '')
|
|
||||||
{
|
|
||||||
if (!($envs = getcache('REPLIT_CONFIG'))) {
|
|
||||||
$envs = json_decode(curl('GET', getenv('REPLIT_DB_URL') . '/REPLIT_CONFIG')['body'], true);
|
|
||||||
savecache('REPLIT_CONFIG', $envs);
|
|
||||||
}
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$disktags = explode("|", getConfig('disktag'));
|
|
||||||
$indisk = 0;
|
|
||||||
$operatedisk = 0;
|
|
||||||
foreach ($arr as $k => $v) {
|
|
||||||
if (isCommonEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $envs[$k] = base64y_encode($v);
|
|
||||||
else $envs[$k] = $v;
|
|
||||||
} elseif (isInnerEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v);
|
|
||||||
else $envs[$disktag][$k] = $v;
|
|
||||||
$indisk = 1;
|
|
||||||
} elseif ($k=='disktag_add') {
|
|
||||||
array_push($disktags, $v);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_del') {
|
|
||||||
$disktags = array_diff($disktags, [ $v ]);
|
|
||||||
$envs[$v] = '';
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_copy') {
|
|
||||||
$newtag = $v . '_' . date("Ymd_His");
|
|
||||||
$envs[$newtag] = $envs[$v];
|
|
||||||
array_push($disktags, $newtag);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
|
||||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
|
||||||
} else {
|
|
||||||
$envs[$k] = $v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($indisk) {
|
|
||||||
$diskconfig = $envs[$disktag];
|
|
||||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
|
||||||
ksort($diskconfig);
|
|
||||||
$envs[$disktag] = $diskconfig;
|
|
||||||
}
|
|
||||||
if ($operatedisk) {
|
|
||||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
|
||||||
$tags = [];
|
|
||||||
foreach ($disktags as $tag) {
|
|
||||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
|
||||||
else array_push($tags, $tag);
|
|
||||||
}
|
|
||||||
$envs['disktag'] = implode('|', $tags);
|
|
||||||
$envs[$arr['disktag_newname']] = $envs[$arr['disktag_rename']];
|
|
||||||
unset($envs[$arr['disktag_rename']]);
|
|
||||||
} else {
|
|
||||||
$disktags = array_unique($disktags);
|
|
||||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
|
||||||
if ($disktag_s!='') $envs['disktag'] = substr($disktag_s, 0, -1);
|
|
||||||
else $envs['disktag'] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
|
||||||
sortConfig($envs);
|
|
||||||
$response = ReplitAPI('w', 'REPLIT_CONFIG', json_encode($envs));
|
|
||||||
//error_log1(json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($envs, JSON_PRETTY_PRINT));
|
|
||||||
savecache('REPLIT_CONFIG', null, '', 0);
|
|
||||||
if (api_error($response)) return ['stat'=>$response['stat'], 'body'=>$response['body'] . "<br>\nError in writting " . $key . "=" . $val];
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function install()
|
|
||||||
{
|
|
||||||
global $constStr;
|
|
||||||
if ($_GET['install2']) {
|
|
||||||
if ($_POST['admin']!='') {
|
|
||||||
$tmp['admin'] = $_POST['admin'];
|
|
||||||
//$tmp['language'] = $_COOKIE['language'];
|
|
||||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
|
||||||
$response = setConfigResponse( setConfig($tmp) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
} else {
|
|
||||||
return output('Jump
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
</script>
|
|
||||||
<meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($_GET['install1']) {
|
|
||||||
/*if (!ConfigWriteable()) {
|
|
||||||
$html .= getconstStr('MakesuerWriteable');
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
if (!RewriteEngineOn()) {
|
|
||||||
$html .= getconstStr('MakesuerRewriteOn');
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}*/
|
|
||||||
$html .= '<button id="checkrewritebtn" onclick="checkrewrite();">'.getconstStr('MakesuerRewriteOn').'</button>
|
|
||||||
<div id="formdiv" style="display: none">
|
|
||||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
|
||||||
<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"><br>
|
|
||||||
<input id="submitbtn" type="submit" value="'.getconstStr('Submit').'" disabled>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var nowtime= new Date();
|
|
||||||
var timezone = 0-nowtime.getTimezoneOffset()/60;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie="timezone="+timezone+"; path=/; "+expires;
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.admin.value==\'\') {
|
|
||||||
alert(\''.getconstStr('SetAdminPassword').'\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
function checkrewrite()
|
|
||||||
{
|
|
||||||
url=location.protocol + "//" + location.host;
|
|
||||||
//if (location.port!="") url += ":" + location.port;
|
|
||||||
url += location.pathname;
|
|
||||||
if (url.substr(-1)!="/") url += "/";
|
|
||||||
url += "app.json";
|
|
||||||
url += "?" + Date.now();
|
|
||||||
var xhr4 = new XMLHttpRequest();
|
|
||||||
xhr4.open("GET", url);
|
|
||||||
xhr4.setRequestHeader("x-requested-with","XMLHttpRequest");
|
|
||||||
xhr4.send(null);
|
|
||||||
xhr4.onload = function(e){
|
|
||||||
console.log(xhr4.responseText+","+xhr4.status);
|
|
||||||
if (xhr4.status==201) {
|
|
||||||
document.getElementById("checkrewritebtn").style.display = "none";
|
|
||||||
document.getElementById("submitbtn").disabled = false;
|
|
||||||
document.getElementById("formdiv").style.display = "";
|
|
||||||
} else {
|
|
||||||
alert("' . getconstStr('MakesuerRewriteOn') . '?\nfalse\n\nUrl: " + url + "\nExpect http code 201, but received " + xhr4.status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SetAdminPassword');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
if ($_GET['install0']) {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install1" method="post">
|
|
||||||
language:<br>';
|
|
||||||
foreach ($constStr['languages'] as $key1 => $value1) {
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
|
||||||
}
|
|
||||||
$html .= '
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function changelanguage(str)
|
|
||||||
{
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=\'+str+\'; path=/; \'+expires;
|
|
||||||
location.href = location.href;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SelectLanguage');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
$title = 'Install';
|
|
||||||
$html = '<a href="?install0">' . getconstStr('ClickInstall') . '</a>, ' . getconstStr('LogintoBind');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ConfigWriteable()
|
|
||||||
{
|
|
||||||
$t = md5( md5(time()).rand(1000,9999) );
|
|
||||||
$r = setConfig([ 'tmp' => $t ]);
|
|
||||||
$tmp = getConfig('tmp');
|
|
||||||
setConfig([ 'tmp' => '' ]);
|
|
||||||
if ($tmp == $t) return true;
|
|
||||||
if ($r) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error($response)
|
|
||||||
{
|
|
||||||
return !($response['stat']==200||$response['stat']==204||$response['stat']==404);
|
|
||||||
//return isset($response['message']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error_msg($response)
|
|
||||||
{
|
|
||||||
return '<pre>'. json_encode($response, JSON_PRETTY_PRINT).'</pre>' . '<br>
|
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfigResponse($response)
|
|
||||||
{
|
|
||||||
return $response;
|
|
||||||
//return json_decode($response, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
|
||||||
{
|
|
||||||
// __DIR__ is xxx/platform
|
|
||||||
$projectPath = splitlast(__DIR__, '/')[0];
|
|
||||||
|
|
||||||
if ($GitSource=='Github') {
|
|
||||||
// 从github下载对应tar.gz,并解压
|
|
||||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
|
||||||
} elseif ($GitSource=='HITGitlab') {
|
|
||||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
|
||||||
} else return ['stat'=>500, 'body'=>'Git Source input Error!'];
|
|
||||||
$tarfile = $projectPath . '/github.tar.gz';
|
|
||||||
$githubfile = file_get_contents($url);
|
|
||||||
if (!$githubfile) return ['stat'=>500, 'body'=>'download error from github.'];
|
|
||||||
file_put_contents($tarfile, $githubfile);
|
|
||||||
if (splitfirst(PHP_VERSION, '.')[0] > '5') {
|
|
||||||
$phar = new PharData($tarfile); // need php5.3, 7, 8
|
|
||||||
$phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖
|
|
||||||
} else {
|
|
||||||
ob_start();
|
|
||||||
passthru('tar -xzvf ' . $tarfile, $stat);
|
|
||||||
ob_get_clean();
|
|
||||||
}
|
|
||||||
unlink($tarfile);
|
|
||||||
|
|
||||||
$outPath = '';
|
|
||||||
$outPath = findIndexPath($projectPath);
|
|
||||||
//error_log1($outPath);
|
|
||||||
if ($outPath=='') return ['stat'=>500, 'body'=>'can\'t find folder after download from github.'];
|
|
||||||
|
|
||||||
return moveFolder($outPath, $projectPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
function moveFolder($from, $to)
|
|
||||||
{
|
|
||||||
if (substr($from, -1)=='/') $from = substr($from, 0, -1);
|
|
||||||
if (substr($to, -1)=='/') $to = substr($to, 0, -1);
|
|
||||||
if (!file_exists($to)) mkdir($to, 0777);
|
|
||||||
$handler=opendir($from);
|
|
||||||
while($filename=readdir($handler)) {
|
|
||||||
if($filename != '.' && $filename != '..'){
|
|
||||||
$fromfile = $from . '/' . $filename;
|
|
||||||
$tofile = $to . '/' . $filename;
|
|
||||||
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
|
||||||
$response = moveFolder($fromfile, $tofile);
|
|
||||||
if (api_error(setConfigResponse($response))) return $response;
|
|
||||||
}else{
|
|
||||||
if (file_exists($tofile)) unlink($tofile);
|
|
||||||
$response = rename($fromfile, $tofile);
|
|
||||||
if (!$response) {
|
|
||||||
$tmp['code'] = "Move Failed";
|
|
||||||
$tmp['message'] = "Can not move " . $fromfile . " to " . $tofile;
|
|
||||||
return ['stat'=>500, 'body'=>json_encode($tmp)];
|
|
||||||
}
|
|
||||||
if (file_exists($fromfile)) unlink($fromfile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir($handler);
|
|
||||||
rmdir($from);
|
|
||||||
return ['stat'=>200, 'body'=>'success.'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function WaitFunction() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeAuthKey() {
|
|
||||||
return message("Not need.", 'Change platform Auth token or key', 404);
|
|
||||||
}
|
|
|
@ -1,379 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
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 ($_SERVER['REQUEST_SCHEME']!='http'&&$_SERVER['REQUEST_SCHEME']!='https') {
|
|
||||||
if ($_SERVER['HTTP_X_FORWARDED_PROTO']!='') {
|
|
||||||
$tmp = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0];
|
|
||||||
if ($tmp=='http'||$tmp=='https') $_SERVER['REQUEST_SCHEME'] = $tmp;
|
|
||||||
}
|
|
||||||
if ($_SERVER['HTTP_FLY_FORWARDED_PROTO']!='') $_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_FLY_FORWARDED_PROTO'];
|
|
||||||
}
|
|
||||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
|
||||||
$_SERVER['referhost'] = explode('/', $_SERVER['HTTP_REFERER'])[2];
|
|
||||||
$_SERVER['base_path'] = '/';
|
|
||||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
|
||||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
|
||||||
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
|
||||||
else $path = $_SERVER['REQUEST_URI'];
|
|
||||||
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
|
||||||
return $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getGET()
|
|
||||||
{
|
|
||||||
if (!$_POST) {
|
|
||||||
if (!!$HTTP_RAW_POST_DATA) {
|
|
||||||
$tmpdata = $HTTP_RAW_POST_DATA;
|
|
||||||
} else {
|
|
||||||
$tmpdata = file_get_contents('php://input');
|
|
||||||
}
|
|
||||||
if (!!$tmpdata) {
|
|
||||||
$postbody = explode("&", $tmpdata);
|
|
||||||
foreach ($postbody as $postvalues) {
|
|
||||||
$pos = strpos($postvalues,"=");
|
|
||||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
|
||||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
|
||||||
if ($p>0) {
|
|
||||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
|
||||||
$getstrarr = explode("&",$getstr);
|
|
||||||
foreach ($getstrarr as $getvalues) {
|
|
||||||
if ($getvalues != '') {
|
|
||||||
$pos = strpos($getvalues, "=");
|
|
||||||
//echo $pos;
|
|
||||||
if ($pos > 0) {
|
|
||||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
|
||||||
} else {
|
|
||||||
$getarry[urldecode($getvalues)] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($getarry)) {
|
|
||||||
return $getarry;
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function ReplitAPI($op, $key, $value = '') {
|
|
||||||
//error_log1($op . '_' . $key . '_' . $value);
|
|
||||||
$apiurl = getenv('REPLIT_DB_URL');
|
|
||||||
if ($op === 'r') {
|
|
||||||
return curl('GET', $apiurl . '/' . $key);
|
|
||||||
} elseif ($op === 'w') {
|
|
||||||
return curl('POST', $apiurl, $key . '=' . $value, ["Content-Type"=>"application/x-www-form-urlencoded"]);
|
|
||||||
} elseif ($op === 'd') {
|
|
||||||
return curl('DELETE', $apiurl . '/' . $key);
|
|
||||||
} else {
|
|
||||||
return ['stat'=>500, 'body'=>'error option input to function ReplitAPI().'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfig($str, $disktag = '')
|
|
||||||
{
|
|
||||||
if (isInnerEnv($str)) {
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$env = json_decode(ReplitAPI('r', $disktag)['body'], true);
|
|
||||||
if (isset($env[$str])) {
|
|
||||||
if (isBase64Env($str)) return base64y_decode($env[$str]);
|
|
||||||
else return $env[$str];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isBase64Env($str)) return base64y_decode(ReplitAPI('r', $str)['body']);
|
|
||||||
else return ReplitAPI('r', $str)['body'];
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfig($arr, $disktag = '')
|
|
||||||
{
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$disktags = explode("|", getConfig('disktag'));
|
|
||||||
if ($disktag!='') $diskconfig = json_decode(ReplitAPI('r', $disktag)['body'], true);
|
|
||||||
$tmp = [];
|
|
||||||
$indisk = 0;
|
|
||||||
$operatedisk = 0;
|
|
||||||
foreach ($arr as $k => $v) {
|
|
||||||
if (isCommonEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
|
||||||
else $tmp[$k] = $v;
|
|
||||||
} elseif (isInnerEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
|
||||||
else $diskconfig[$k] = $v;
|
|
||||||
$indisk = 1;
|
|
||||||
} elseif ($k=='disktag_add') {
|
|
||||||
array_push($disktags, $v);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_del') {
|
|
||||||
$disktags = array_diff($disktags, [ $v ]);
|
|
||||||
$tmp[$v] = '';
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_copy') {
|
|
||||||
$newtag = $v . '_' . date("Ymd_His");
|
|
||||||
$tmp[$newtag] = getConfig($v);
|
|
||||||
array_push($disktags, $newtag);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
|
||||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
|
||||||
} else {
|
|
||||||
$tmp[$k] = json_encode($v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($indisk) {
|
|
||||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
|
||||||
ksort($diskconfig);
|
|
||||||
$tmp[$disktag] = json_encode($diskconfig);
|
|
||||||
}
|
|
||||||
if ($operatedisk) {
|
|
||||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
|
||||||
$tags = [];
|
|
||||||
foreach ($disktags as $tag) {
|
|
||||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
|
||||||
else array_push($tags, $tag);
|
|
||||||
}
|
|
||||||
$tmp['disktag'] = implode('|', $tags);
|
|
||||||
$tmp[$arr['disktag_newname']] = getConfig($arr['disktag_rename']);
|
|
||||||
$tmp[$arr['disktag_rename']] = null;
|
|
||||||
} else {
|
|
||||||
$disktags = array_unique($disktags);
|
|
||||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
|
||||||
if ($disktag_s!='') $tmp['disktag'] = substr($disktag_s, 0, -1);
|
|
||||||
else $tmp['disktag'] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$response = null;
|
|
||||||
foreach ($tmp as $key => $val) {
|
|
||||||
if (!!$val) $response = ReplitAPI('w', $key, $val);
|
|
||||||
else $response = ReplitAPI('d', $key);
|
|
||||||
if (api_error($response)) return ['stat'=>$response['stat'], 'body'=>$response['body'] . "<br>\nError in writting " . $key . "=" . $val];
|
|
||||||
}
|
|
||||||
//error_log1(json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($tmp, JSON_PRETTY_PRINT));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function install()
|
|
||||||
{
|
|
||||||
global $constStr;
|
|
||||||
if ($_GET['install2']) {
|
|
||||||
if ($_POST['admin']!='') {
|
|
||||||
$tmp['admin'] = $_POST['admin'];
|
|
||||||
//$tmp['language'] = $_COOKIE['language'];
|
|
||||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
|
||||||
$response = setConfigResponse( setConfig($tmp) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
} else {
|
|
||||||
return output('Jump
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
</script>
|
|
||||||
<meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($_GET['install1']) {
|
|
||||||
if (!ConfigWriteable()) {
|
|
||||||
$html .= getconstStr('MakesuerWriteable');
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
/*if (!RewriteEngineOn()) {
|
|
||||||
$html .= getconstStr('MakesuerRewriteOn');
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}*/
|
|
||||||
$html .= '<button id="checkrewritebtn" onclick="checkrewrite();">'.getconstStr('MakesuerRewriteOn').'</button>
|
|
||||||
<div id="formdiv" style="display: none">
|
|
||||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
|
||||||
<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"><br>
|
|
||||||
<input id="submitbtn" type="submit" value="'.getconstStr('Submit').'" disabled>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var nowtime= new Date();
|
|
||||||
var timezone = 0-nowtime.getTimezoneOffset()/60;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie="timezone="+timezone+"; path=/; "+expires;
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.admin.value==\'\') {
|
|
||||||
alert(\''.getconstStr('SetAdminPassword').'\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
function checkrewrite()
|
|
||||||
{
|
|
||||||
url=location.protocol + "//" + location.host;
|
|
||||||
//if (location.port!="") url += ":" + location.port;
|
|
||||||
url += location.pathname;
|
|
||||||
if (url.substr(-1)!="/") url += "/";
|
|
||||||
url += "app.json";
|
|
||||||
url += "?" + Date.now();
|
|
||||||
var xhr4 = new XMLHttpRequest();
|
|
||||||
xhr4.open("GET", url);
|
|
||||||
xhr4.setRequestHeader("x-requested-with","XMLHttpRequest");
|
|
||||||
xhr4.send(null);
|
|
||||||
xhr4.onload = function(e){
|
|
||||||
console.log(xhr4.responseText+","+xhr4.status);
|
|
||||||
if (xhr4.status==201) {
|
|
||||||
document.getElementById("checkrewritebtn").style.display = "none";
|
|
||||||
document.getElementById("submitbtn").disabled = false;
|
|
||||||
document.getElementById("formdiv").style.display = "";
|
|
||||||
} else {
|
|
||||||
alert("' . getconstStr('MakesuerRewriteOn') . '?\nfalse\n\nUrl: " + url + "\nExpect http code 201, but received " + xhr4.status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SetAdminPassword');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
if ($_GET['install0']) {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install1" method="post">
|
|
||||||
language:<br>';
|
|
||||||
foreach ($constStr['languages'] as $key1 => $value1) {
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
|
||||||
}
|
|
||||||
$html .= '
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function changelanguage(str)
|
|
||||||
{
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=\'+str+\'; path=/; \'+expires;
|
|
||||||
location.href = location.href;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SelectLanguage');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
$title = 'Install';
|
|
||||||
$html = '<a href="?install0">' . getconstStr('ClickInstall') . '</a>, ' . getconstStr('LogintoBind');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ConfigWriteable()
|
|
||||||
{
|
|
||||||
$t = md5( md5(time()).rand(1000,9999) );
|
|
||||||
$r = setConfig([ 'tmp' => $t ]);
|
|
||||||
$tmp = getConfig('tmp');
|
|
||||||
setConfig([ 'tmp' => '' ]);
|
|
||||||
if ($tmp == $t) return true;
|
|
||||||
if ($r) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error($response)
|
|
||||||
{
|
|
||||||
return !($response['stat']==200||$response['stat']==204||$response['stat']==404);
|
|
||||||
//return isset($response['message']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error_msg($response)
|
|
||||||
{
|
|
||||||
return '<pre>'. json_encode($response, JSON_PRETTY_PRINT).'</pre>' . '<br>
|
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfigResponse($response)
|
|
||||||
{
|
|
||||||
return $response;
|
|
||||||
//return json_decode($response, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
|
||||||
{
|
|
||||||
$slash = '/';
|
|
||||||
if (strpos(__DIR__, ':')) $slash = '\\';
|
|
||||||
// __DIR__ is xxx/platform
|
|
||||||
$projectPath = splitlast(__DIR__, $slash)[0];
|
|
||||||
|
|
||||||
// 从github下载对应tar.gz,并解压
|
|
||||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
|
||||||
$tarfile = $projectPath . $slash .'github.tar.gz';
|
|
||||||
$githubfile = file_get_contents($url);
|
|
||||||
if (!$githubfile) return ['stat'=>500, 'body'=>'download error from github.'];
|
|
||||||
file_put_contents($tarfile, $githubfile);
|
|
||||||
if (splitfirst(PHP_VERSION, '.')[0] > '5') {
|
|
||||||
$phar = new PharData($tarfile); // need php5.3, 7, 8
|
|
||||||
$phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖
|
|
||||||
} else {
|
|
||||||
ob_start();
|
|
||||||
passthru('tar -xzvf ' . $tarfile, $stat);
|
|
||||||
ob_get_clean();
|
|
||||||
}
|
|
||||||
unlink($tarfile);
|
|
||||||
|
|
||||||
$outPath = '';
|
|
||||||
$tmp = scandir($projectPath);
|
|
||||||
$name = $auth . '-' . $project;
|
|
||||||
foreach ($tmp as $f) {
|
|
||||||
if ( substr($f, 0, strlen($name)) == $name) {
|
|
||||||
$outPath = $projectPath . $slash . $f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//error_log1($outPath);
|
|
||||||
if ($outPath=='') return ['stat'=>500, 'body'=>'can\'t find folder after download from github.'];
|
|
||||||
|
|
||||||
return moveFolder($outPath, $projectPath, $slash);
|
|
||||||
}
|
|
||||||
|
|
||||||
function moveFolder($from, $to, $slash)
|
|
||||||
{
|
|
||||||
if (substr($from, -1)==$slash) $from = substr($from, 0, -1);
|
|
||||||
if (substr($to, -1)==$slash) $to = substr($to, 0, -1);
|
|
||||||
if (!file_exists($to)) mkdir($to, 0777);
|
|
||||||
$handler=opendir($from);
|
|
||||||
while($filename=readdir($handler)) {
|
|
||||||
if($filename != '.' && $filename != '..'){
|
|
||||||
$fromfile = $from . $slash . $filename;
|
|
||||||
$tofile = $to . $slash . $filename;
|
|
||||||
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
|
||||||
$response = moveFolder($fromfile, $tofile, $slash);
|
|
||||||
if (api_error(setConfigResponse($response))) return $response;
|
|
||||||
}else{
|
|
||||||
if (file_exists($tofile)) unlink($tofile);
|
|
||||||
$response = rename($fromfile, $tofile);
|
|
||||||
if (!$response) {
|
|
||||||
$tmp['code'] = "Move Failed";
|
|
||||||
$tmp['message'] = "Can not move " . $fromfile . " to " . $tofile;
|
|
||||||
return ['stat'=>500, 'body'=>json_encode($tmp)];
|
|
||||||
}
|
|
||||||
if (file_exists($fromfile)) unlink($fromfile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir($handler);
|
|
||||||
rmdir($from);
|
|
||||||
return ['stat'=>200, 'body'=>'success.'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function WaitFunction() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeAuthKey() {
|
|
||||||
return message("Not need.", 'Change platform Auth token or key', 404);
|
|
||||||
}
|
|
|
@ -1,663 +0,0 @@
|
||||||
<?php
|
|
||||||
// https://cloud.tencent.com/document/product/583/33846
|
|
||||||
// https://cloud.tencent.com/document/product/583/18581
|
|
||||||
// https://cloud.tencent.com/document/product/583/18580
|
|
||||||
|
|
||||||
function printInput($event, $context)
|
|
||||||
{
|
|
||||||
if (strlen(json_encode($event['body']))>500) $event['body']=substr($event['body'],0,strpos($event['body'],'base64')+30) . '...Too Long!...' . substr($event['body'],-50);
|
|
||||||
echo urldecode(json_encode($event, JSON_PRETTY_PRINT)) . '
|
|
||||||
|
|
||||||
' . urldecode(json_encode($context, JSON_PRETTY_PRINT)) . '
|
|
||||||
|
|
||||||
';
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetGlobalVariable($event)
|
|
||||||
{
|
|
||||||
$_GET = $event['queryString'];
|
|
||||||
$postbody = explode("&",$event['body']);
|
|
||||||
foreach ($postbody as $postvalues) {
|
|
||||||
$pos = strpos($postvalues,"=");
|
|
||||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
|
||||||
}
|
|
||||||
$cookiebody = explode("; ",$event['headers']['cookie']);
|
|
||||||
foreach ($cookiebody as $cookievalues) {
|
|
||||||
$pos = strpos($cookievalues,"=");
|
|
||||||
$_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetPathSetting($event, $context)
|
|
||||||
{
|
|
||||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($event['headers']['accept-language'],';')[0],',')[0]);
|
|
||||||
$_SERVER['function_name'] = $context['function_name'];
|
|
||||||
$_SERVER['namespace'] = $context['namespace'];
|
|
||||||
$_SERVER['Region'] = $context['tencentcloud_region'];
|
|
||||||
$host_name = $event['headers']['host'];
|
|
||||||
$_SERVER['HTTP_HOST'] = $host_name;
|
|
||||||
$serviceId = $event['requestContext']['serviceId'];
|
|
||||||
if ( $serviceId === substr($host_name,0,strlen($serviceId)) ) {
|
|
||||||
$_SERVER['base_path'] = '/'.$event['requestContext']['stage'].'/'.$_SERVER['function_name'].'/';
|
|
||||||
$path = substr($event['path'], strlen('/'.$_SERVER['function_name'].'/'));
|
|
||||||
} else {
|
|
||||||
$_SERVER['base_path'] = $event['requestContext']['path'];
|
|
||||||
$path = substr($event['path'], strlen($event['requestContext']['path']));
|
|
||||||
}
|
|
||||||
//$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
|
|
||||||
$_SERVER['REMOTE_ADDR'] = $event['requestContext']['sourceIp'];
|
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = $event['headers']['x-requested-with'];
|
|
||||||
$_SERVER['HTTP_USER_AGENT'] = $event['headers']['user-agent'];
|
|
||||||
if (isset($event['headers']['authorization'])) {
|
|
||||||
$basicAuth = splitfirst(base64_decode(splitfirst($event['headers']['authorization'], 'Basic ')[1]), ':');
|
|
||||||
$_SERVER['PHP_AUTH_USER'] = $basicAuth[0];
|
|
||||||
$_SERVER['PHP_AUTH_PW'] = $basicAuth[1];
|
|
||||||
}
|
|
||||||
$_SERVER['REQUEST_SCHEME'] = $event['headers']['x-api-scheme'];
|
|
||||||
//$_SERVER['REQUEST_SCHEME'] = $event['headers']['x-forwarded-proto'];
|
|
||||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
|
||||||
$_SERVER['referhost'] = explode('/', $event['headers']['referer'])[2];
|
|
||||||
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
|
|
||||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since'];
|
|
||||||
$_SERVER['USER'] = 'qcloud';
|
|
||||||
return $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfig($str, $disktag = '')
|
|
||||||
{
|
|
||||||
if (isInnerEnv($str)) {
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$env = json_decode(getenv($disktag), true);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfig($arr, $disktag = '')
|
|
||||||
{
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$disktags = explode("|",getConfig('disktag'));
|
|
||||||
$diskconfig = json_decode(getenv($disktag), true);
|
|
||||||
$tmp = [];
|
|
||||||
$indisk = 0;
|
|
||||||
$operatedisk = 0;
|
|
||||||
foreach ($arr as $k => $v) {
|
|
||||||
if (isCommonEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
|
||||||
else $tmp[$k] = $v;
|
|
||||||
} elseif (isInnerEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
|
||||||
else $diskconfig[$k] = $v;
|
|
||||||
$indisk = 1;
|
|
||||||
} elseif ($k=='disktag_add') {
|
|
||||||
array_push($disktags, $v);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_del') {
|
|
||||||
$disktags = array_diff($disktags, [ $v ]);
|
|
||||||
$tmp[$v] = '';
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_copy') {
|
|
||||||
$newtag = $v . '_' . date("Ymd_His");
|
|
||||||
$tmp[$newtag] = getConfig($v);
|
|
||||||
array_push($disktags, $newtag);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
|
||||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
|
||||||
} else {
|
|
||||||
$tmp[$k] = json_encode($v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($indisk) {
|
|
||||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
|
||||||
ksort($diskconfig);
|
|
||||||
$tmp[$disktag] = json_encode($diskconfig);
|
|
||||||
}
|
|
||||||
if ($operatedisk) {
|
|
||||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
|
||||||
$tags = [];
|
|
||||||
foreach ($disktags as $tag) {
|
|
||||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
|
||||||
else array_push($tags, $tag);
|
|
||||||
}
|
|
||||||
$tmp['disktag'] = implode('|', $tags);
|
|
||||||
$tmp[$arr['disktag_newname']] = getConfig($arr['disktag_rename']);
|
|
||||||
$tmp[$arr['disktag_rename']] = '';
|
|
||||||
} else {
|
|
||||||
$disktags = array_unique($disktags);
|
|
||||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
|
||||||
if ($disktag_s!='') $tmp['disktag'] = substr($disktag_s, 0, -1);
|
|
||||||
else $tmp['disktag'] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// echo '正式设置:'.json_encode($tmp,JSON_PRETTY_PRINT).'
|
|
||||||
//';
|
|
||||||
$response = updateEnvironment($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'));
|
|
||||||
WaitSCFStat();
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function WaitSCFStat()
|
|
||||||
{
|
|
||||||
$trynum = 0;
|
|
||||||
while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']!='Active' ) echo '
|
|
||||||
'.++$trynum;
|
|
||||||
}
|
|
||||||
|
|
||||||
function install()
|
|
||||||
{
|
|
||||||
global $constStr;
|
|
||||||
if ($_GET['install2']) {
|
|
||||||
$tmp['admin'] = $_POST['admin'];
|
|
||||||
$response = setConfigResponse( setConfig($tmp) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
if (needUpdate()) {
|
|
||||||
OnekeyUpate();
|
|
||||||
return message('update to github version, reinstall.
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
</script>
|
|
||||||
<meta http-equiv="refresh" content="3;URL=' . $url . '">', 'Program updating', 201, 1);
|
|
||||||
}
|
|
||||||
return message(getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
var i = 0;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>', 201, 1);
|
|
||||||
}
|
|
||||||
if ($_GET['install1']) {
|
|
||||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
|
||||||
$SecretId = getConfig('SecretId');
|
|
||||||
if ($SecretId=='') {
|
|
||||||
$SecretId = $_POST['SecretId'];
|
|
||||||
$tmp['SecretId'] = $SecretId;
|
|
||||||
}
|
|
||||||
$SecretKey = getConfig('SecretKey');
|
|
||||||
if ($SecretKey=='') {
|
|
||||||
$SecretKey = $_POST['SecretKey'];
|
|
||||||
$tmp['SecretKey'] = $SecretKey;
|
|
||||||
}
|
|
||||||
$tmp['ONEMANAGER_CONFIG_SAVE'] = $_POST['ONEMANAGER_CONFIG_SAVE'];
|
|
||||||
$response = json_decode(SetbaseConfig($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
} else {
|
|
||||||
if ($tmp['ONEMANAGER_CONFIG_SAVE'] == 'file') {
|
|
||||||
$html = getconstStr('ONEMANAGER_CONFIG_SAVE_FILE') . '<br><a href="' . $_SERVER['base_path'] . '">' . getconstStr('Home') . '</a>';
|
|
||||||
$title = 'Reinstall';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
$html .= '
|
|
||||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
|
||||||
<label>'.getconstStr('SetAdminPassword').':<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.admin.value==\'\') {
|
|
||||||
alert(\''.getconstStr('SetAdminPassword').'\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SetAdminPassword');
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($_GET['install0']) {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install1" method="post" onsubmit="return notnull(this);">
|
|
||||||
language:<br>';
|
|
||||||
foreach ($constStr['languages'] as $key1 => $value1) {
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
|
||||||
}
|
|
||||||
//if (getConfig('SecretId')==''||getConfig('SecretKey')=='')
|
|
||||||
$html .= '
|
|
||||||
<a href="https://console.cloud.tencent.com/cam/capi" target="_blank">' . getconstStr('Create') . ' SecretId & SecretKey</a><br>
|
|
||||||
<label>SecretId:<input name="SecretId" type="text" placeholder="" size=""></label><br>
|
|
||||||
<label>SecretKey:<input name="SecretKey" type="password" placeholder="" size=""></label><br>';
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="ONEMANAGER_CONFIG_SAVE" value="" ' . ('file'==getenv('ONEMANAGER_CONFIG_SAVE')?'':'checked') . '>' . getconstStr('ONEMANAGER_CONFIG_SAVE_ENV') . '</label><br>
|
|
||||||
<label><input type="radio" name="ONEMANAGER_CONFIG_SAVE" value="file" ' . ('file'==getenv('ONEMANAGER_CONFIG_SAVE')?'checked':'') . '>' . getconstStr('ONEMANAGER_CONFIG_SAVE_FILE') . '</label><br>';
|
|
||||||
$html .= '
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
var nowtime= new Date();
|
|
||||||
var timezone = 0-nowtime.getTimezoneOffset()/60;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie="timezone="+timezone+"; path=/; "+expires;
|
|
||||||
function changelanguage(str)
|
|
||||||
{
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=\'+str+\'; path=/; \'+expires;
|
|
||||||
location.href = location.href;
|
|
||||||
}
|
|
||||||
function notnull(t)
|
|
||||||
{';
|
|
||||||
//if (getConfig('SecretId')==''||getConfig('SecretKey')=='')
|
|
||||||
$html .= '
|
|
||||||
if (t.SecretId.value==\'\') {
|
|
||||||
alert(\'input SecretId\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.SecretKey.value==\'\') {
|
|
||||||
alert(\'input SecretKey\');
|
|
||||||
return false;
|
|
||||||
}';
|
|
||||||
$html .= '
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SelectLanguage');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
$html .= '<a href="?install0">'.getconstStr('ClickInstall').'</a>, '.getconstStr('LogintoBind');
|
|
||||||
$title = 'Install';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
function post2url($url, $data)
|
|
||||||
{
|
|
||||||
$ch = curl_init();
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
|
||||||
curl_setopt($ch, CURLOPT_POST, 1);
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
|
||||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
|
||||||
$response = curl_exec($ch);
|
|
||||||
curl_close($ch);
|
|
||||||
//echo $response;
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function ReorganizeDate($arr)
|
|
||||||
{
|
|
||||||
$str = '';
|
|
||||||
ksort($arr);
|
|
||||||
foreach ($arr as $k1 => $v1) {
|
|
||||||
$str .= '&' . $k1 . '=' . $v1;
|
|
||||||
}
|
|
||||||
$str = substr($str, 1); // remove first '&'. 去掉第一个&
|
|
||||||
return $str;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
|
||||||
{
|
|
||||||
//$meth = 'GET';
|
|
||||||
$meth = 'POST';
|
|
||||||
$host = 'scf.tencentcloudapi.com';
|
|
||||||
$tmpdata['Action'] = 'GetFunction';
|
|
||||||
$tmpdata['FunctionName'] = $function_name;
|
|
||||||
$tmpdata['Namespace'] = $Namespace;
|
|
||||||
$tmpdata['Nonce'] = time();
|
|
||||||
$tmpdata['Region'] = $Region;
|
|
||||||
$tmpdata['SecretId'] = $SecretId;
|
|
||||||
$tmpdata['Timestamp'] = time();
|
|
||||||
$tmpdata['Token'] = '';
|
|
||||||
$tmpdata['Version'] = '2018-04-16';
|
|
||||||
$data = ReorganizeDate($tmpdata);
|
|
||||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
|
||||||
//echo urlencode($signStr);
|
|
||||||
//return file_get_contents('https://'.$url.'&Signature='.urlencode($signStr));
|
|
||||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
|
||||||
{
|
|
||||||
//print_r($Envs);
|
|
||||||
WaitSCFStat();
|
|
||||||
//json_decode($a,true)['Response']['Environment']['Variables'][0]['Key']
|
|
||||||
$tmp = json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Environment']['Variables'];
|
|
||||||
foreach ($tmp as $tmp1) {
|
|
||||||
$tmp_env[$tmp1['Key']] = $tmp1['Value'];
|
|
||||||
}
|
|
||||||
foreach ($Envs as $key1 => $value1) {
|
|
||||||
$tmp_env[$key1] = $value1;
|
|
||||||
}
|
|
||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
|
||||||
//$tmp_env['Region'] = $Region;
|
|
||||||
//ksort($tmp_env);
|
|
||||||
sortConfig($tmp_env);
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
foreach ($tmp_env as $key1 => $value1) {
|
|
||||||
$tmpdata['Environment.Variables.'.$i.'.Key'] = $key1;
|
|
||||||
$tmpdata['Environment.Variables.'.$i.'.Value'] = $value1;
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
$meth = 'POST';
|
|
||||||
$host = 'scf.tencentcloudapi.com';
|
|
||||||
$tmpdata['Action'] = 'UpdateFunctionConfiguration';
|
|
||||||
$tmpdata['FunctionName'] = $function_name;
|
|
||||||
$tmpdata['Namespace'] = $Namespace;
|
|
||||||
$tmpdata['Nonce'] = time();
|
|
||||||
$tmpdata['Region'] = $Region;
|
|
||||||
$tmpdata['SecretId'] = $SecretId;
|
|
||||||
$tmpdata['Timestamp'] = time();
|
|
||||||
$tmpdata['Token'] = '';
|
|
||||||
$tmpdata['Version'] = '2018-04-16';
|
|
||||||
$data = ReorganizeDate($tmpdata);
|
|
||||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
|
||||||
//echo urlencode($signStr);
|
|
||||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
|
||||||
}
|
|
||||||
|
|
||||||
function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
|
||||||
{
|
|
||||||
//echo json_encode($Envs,JSON_PRETTY_PRINT);
|
|
||||||
if ($Envs['ONEMANAGER_CONFIG_SAVE'] == 'file') $Envs = Array( 'ONEMANAGER_CONFIG_SAVE' => 'file' );
|
|
||||||
//json_decode($a,true)['Response']['Environment']['Variables'][0]['Key']
|
|
||||||
$tmp = json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Environment']['Variables'];
|
|
||||||
foreach ($tmp as $tmp1) {
|
|
||||||
$tmp_env[$tmp1['Key']] = $tmp1['Value'];
|
|
||||||
}
|
|
||||||
foreach ($Envs as $key1 => $value1) {
|
|
||||||
$tmp_env[$key1] = $value1;
|
|
||||||
}
|
|
||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
|
||||||
//$tmp_env['Region'] = $Region;
|
|
||||||
ksort($tmp_env);
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
foreach ($tmp_env as $key1 => $value1) {
|
|
||||||
$tmpdata['Environment.Variables.'.$i.'.Key'] = $key1;
|
|
||||||
$tmpdata['Environment.Variables.'.$i.'.Value'] = $value1;
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
$meth = 'POST';
|
|
||||||
$host = 'scf.tencentcloudapi.com';
|
|
||||||
$tmpdata['Action'] = 'UpdateFunctionConfiguration';
|
|
||||||
$tmpdata['FunctionName'] = $function_name;
|
|
||||||
$tmpdata['Namespace'] = $Namespace;
|
|
||||||
$tmpdata['Nonce'] = time();
|
|
||||||
$tmpdata['Region'] = $Region;
|
|
||||||
$tmpdata['SecretId'] = $SecretId;
|
|
||||||
$tmpdata['Timestamp'] = time();
|
|
||||||
$tmpdata['Token'] = '';
|
|
||||||
$tmpdata['Version'] = '2018-04-16';
|
|
||||||
$tmpdata['Description'] = 'Onedrive index and manager in Tencent SCF.';
|
|
||||||
$tmpdata['MemorySize'] = 64;
|
|
||||||
$tmpdata['Timeout'] = 30;
|
|
||||||
$data = ReorganizeDate($tmpdata);
|
|
||||||
echo $data;
|
|
||||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
|
||||||
//echo urlencode($signStr);
|
|
||||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateProgram_OLD($function_name, $Region, $Namespace, $SecretId, $SecretKey, $source)
|
|
||||||
{
|
|
||||||
WaitSCFStat();
|
|
||||||
$meth = 'POST';
|
|
||||||
$host = 'scf.tencentcloudapi.com';
|
|
||||||
$tmpdata['Action'] = 'UpdateFunctionCode';
|
|
||||||
$tmpdata['Code.GitUrl'] = $source['url'];
|
|
||||||
$tmpdata['Code.GitBranch'] = $source['branch'];
|
|
||||||
$tmpdata['CodeSource'] = 'Git';
|
|
||||||
$tmpdata['FunctionName'] = $function_name;
|
|
||||||
$tmpdata['Handler'] = 'index.main_handler';
|
|
||||||
$tmpdata['Namespace'] = $Namespace;
|
|
||||||
$tmpdata['Nonce'] = time();
|
|
||||||
$tmpdata['Region'] = $Region;
|
|
||||||
$tmpdata['SecretId'] = $SecretId;
|
|
||||||
$tmpdata['Timestamp'] = time();
|
|
||||||
$tmpdata['Token'] = '';
|
|
||||||
$tmpdata['Version'] = '2018-04-16';
|
|
||||||
$data = ReorganizeDate($tmpdata);
|
|
||||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
|
||||||
//echo urlencode($signStr);
|
|
||||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error($response)
|
|
||||||
{
|
|
||||||
return isset($response['Error']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error_msg($response)
|
|
||||||
{
|
|
||||||
return $response['Error']['Code'] . '<br>
|
|
||||||
' . $response['Error']['Message'] . '<br><br>
|
|
||||||
function_name:' . $_SERVER['function_name'] . '<br>
|
|
||||||
Region:' . $_SERVER['Region'] . '<br>
|
|
||||||
namespace:' . $_SERVER['namespace'] . '<br>
|
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
$secretKey = $SecretKey;
|
|
||||||
$host = 'scf.tencentcloudapi.com';
|
|
||||||
$service = "scf";
|
|
||||||
$version = "2018-04-16";
|
|
||||||
$action = "UpdateFunctionCode";
|
|
||||||
$region = $Region;
|
|
||||||
$timestamp = time();
|
|
||||||
$algorithm = "TC3-HMAC-SHA256";
|
|
||||||
|
|
||||||
// step 1: build canonical request string
|
|
||||||
$httpRequestMethod = "POST";
|
|
||||||
$canonicalUri = "/";
|
|
||||||
$canonicalQueryString = "";
|
|
||||||
$canonicalHeaders = "content-type:application/json; charset=utf-8\n"."host:".$host."\n";
|
|
||||||
$signedHeaders = "content-type;host";
|
|
||||||
|
|
||||||
//$tmpdata['Action'] = 'UpdateFunctionCode';
|
|
||||||
$tmpdata['Code']['ZipFile'] = base64_encode( file_get_contents($source) );
|
|
||||||
$tmpdata['CodeSource'] = 'ZipFile';
|
|
||||||
$tmpdata['FunctionName'] = $function_name;
|
|
||||||
$tmpdata['Handler'] = 'index.main_handler';
|
|
||||||
//$tmpdata['Namespace'] = $Namespace;
|
|
||||||
//$tmpdata['Nonce'] = time();
|
|
||||||
//$tmpdata['Region'] = $Region;
|
|
||||||
//$tmpdata['SecretId'] = $SecretId;
|
|
||||||
//$tmpdata['Timestamp'] = time();
|
|
||||||
//$tmpdata['Token'] = '';
|
|
||||||
//$tmpdata['Version'] = '2018-04-16';
|
|
||||||
$payload = json_encode($tmpdata);
|
|
||||||
//$payload = '{"Limit": 1, "Filters": [{"Values": ["\u672a\u547d\u540d"], "Name": "instance-name"}]}';
|
|
||||||
$hashedRequestPayload = hash("SHA256", $payload);
|
|
||||||
$canonicalRequest = $httpRequestMethod."\n"
|
|
||||||
.$canonicalUri."\n"
|
|
||||||
.$canonicalQueryString."\n"
|
|
||||||
.$canonicalHeaders."\n"
|
|
||||||
.$signedHeaders."\n"
|
|
||||||
.$hashedRequestPayload;
|
|
||||||
//echo $canonicalRequest.PHP_EOL;
|
|
||||||
|
|
||||||
// step 2: build string to sign
|
|
||||||
$date = gmdate("Y-m-d", $timestamp);
|
|
||||||
$credentialScope = $date."/".$service."/tc3_request";
|
|
||||||
$hashedCanonicalRequest = hash("SHA256", $canonicalRequest);
|
|
||||||
$stringToSign = $algorithm."\n"
|
|
||||||
.$timestamp."\n"
|
|
||||||
.$credentialScope."\n"
|
|
||||||
.$hashedCanonicalRequest;
|
|
||||||
//echo $stringToSign.PHP_EOL;
|
|
||||||
|
|
||||||
// step 3: sign string
|
|
||||||
$secretDate = hash_hmac("SHA256", $date, "TC3".$secretKey, true);
|
|
||||||
$secretService = hash_hmac("SHA256", $service, $secretDate, true);
|
|
||||||
$secretSigning = hash_hmac("SHA256", "tc3_request", $secretService, true);
|
|
||||||
$signature = hash_hmac("SHA256", $stringToSign, $secretSigning);
|
|
||||||
//echo $signature.PHP_EOL;
|
|
||||||
|
|
||||||
// step 4: build authorization
|
|
||||||
$authorization = $algorithm
|
|
||||||
." Credential=".$secretId."/".$credentialScope
|
|
||||||
.", SignedHeaders=content-type;host, Signature=".$signature;
|
|
||||||
//echo $authorization.PHP_EOL;
|
|
||||||
|
|
||||||
//$curl = "curl -X POST https://".$host
|
|
||||||
// .' -H "Authorization: '.$authorization.'"'
|
|
||||||
// .' -H "Content-Type: application/json; charset=utf-8"'
|
|
||||||
// .' -H "Host: '.$host.'"'
|
|
||||||
// .' -H "X-TC-Action: '.$action.'"'
|
|
||||||
// .' -H "X-TC-Timestamp: '.$timestamp.'"'
|
|
||||||
// .' -H "X-TC-Version: '.$version.'"'
|
|
||||||
// .' -H "X-TC-Region: '.$region.'"'
|
|
||||||
// ." -d '".$payload."'";
|
|
||||||
//error_log1( $curl.PHP_EOL );
|
|
||||||
//return '{"response": {"Error": {"Message":"' . $curl . '"}}}';
|
|
||||||
$headers['Authorization'] = $authorization;
|
|
||||||
$headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
||||||
$headers['Host'] = $host;
|
|
||||||
$headers['X-TC-Action'] = $action;
|
|
||||||
$headers['X-TC-Timestamp'] = $timestamp;
|
|
||||||
$headers['X-TC-Version'] = $version;
|
|
||||||
$headers['X-TC-Region'] = $region;
|
|
||||||
return curl('POST', 'https://'.$host, $payload, $headers)['body'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
|
||||||
{
|
|
||||||
$source = '/tmp/code.zip';
|
|
||||||
$outPath = '/tmp/';
|
|
||||||
|
|
||||||
if ($GitSource=='Github') {
|
|
||||||
// 从github下载对应tar.gz,并解压
|
|
||||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
|
||||||
} elseif ($GitSource=='HITGitlab') {
|
|
||||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
|
||||||
} else return json_encode(['Response'=>['Error'=>['code'=>'Git Source input Error!']]]);
|
|
||||||
$tarfile = '/tmp/github.tar.gz';
|
|
||||||
file_put_contents($tarfile, file_get_contents($url));
|
|
||||||
$phar = new PharData($tarfile);
|
|
||||||
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
|
||||||
|
|
||||||
// 获取解压出的目录名
|
|
||||||
$outPath = findIndexPath($outPath);
|
|
||||||
|
|
||||||
// 将目录中文件打包成zip
|
|
||||||
//$zip=new ZipArchive();
|
|
||||||
$zip=new PharData($source);
|
|
||||||
//if($zip->open($source, ZipArchive::CREATE)){
|
|
||||||
addFileToZip($zip, $outPath); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
|
|
||||||
// $zip->close(); //关闭处理的zip文件
|
|
||||||
//}
|
|
||||||
|
|
||||||
return updateProgram($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'), $source);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addFileToZip($zip, $rootpath, $path = '')
|
|
||||||
{
|
|
||||||
if (substr($rootpath,-1)=='/') $rootpath = substr($rootpath, 0, -1);
|
|
||||||
if (substr($path,0,1)=='/') $path = substr($path, 1);
|
|
||||||
$handler=opendir(path_format($rootpath.'/'.$path)); //打开当前文件夹由$path指定。
|
|
||||||
while($filename=readdir($handler)){
|
|
||||||
if($filename != "." && $filename != ".."){//文件夹文件名字为'.'和‘..’,不要对他们进行操作
|
|
||||||
$nowname = path_format($rootpath.'/'.$path."/".$filename);
|
|
||||||
if(is_dir($nowname)){// 如果读取的某个对象是文件夹,则递归
|
|
||||||
$zip->addEmptyDir($path."/".$filename);
|
|
||||||
addFileToZip($zip, $rootpath, $path."/".$filename);
|
|
||||||
}else{ //将文件加入zip对象
|
|
||||||
$newname = $path."/".$filename;
|
|
||||||
if (substr($newname,0,1)=='/') $newname = substr($newname, 1);
|
|
||||||
$zip->addFile($nowname, $newname);
|
|
||||||
//$zip->renameName($nowname, $newname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@closedir($handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeAuthKey() {
|
|
||||||
if ($_POST['SecretId']!=''&&$_POST['SecretId']!='') {
|
|
||||||
$tmp['SecretId'] = $_POST['SecretId'];
|
|
||||||
$tmp['SecretKey'] = $_POST['SecretKey'];
|
|
||||||
$response = setConfigResponse( SetbaseConfig($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $tmp['SecretId'], $tmp['SecretKey']) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 400);
|
|
||||||
} else {
|
|
||||||
$html = getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var status = "' . $response['DplStatus'] . '";
|
|
||||||
var i = 0;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$html = '
|
|
||||||
<form action="" method="post" onsubmit="return notnull(this);">
|
|
||||||
<a href="https://console.cloud.tencent.com/cam/capi" target="_blank">' . getconstStr('Create') . ' SecretId & SecretKey</a><br>
|
|
||||||
<label>SecretId:<input name="SecretId" type="text" placeholder="" size=""></label><br>
|
|
||||||
<label>SecretKey:<input name="SecretKey" type="password" placeholder="" size=""></label><br>
|
|
||||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.SecretId.value==\'\') {
|
|
||||||
alert(\'input SecretId\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.SecretKey.value==\'\') {
|
|
||||||
alert(\'input SecretKey\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
return message($html, 'Change platform Auth token or key', 200);
|
|
||||||
}
|
|
|
@ -1,706 +0,0 @@
|
||||||
<?php
|
|
||||||
// https://cloud.tencent.com/document/product/583/33846
|
|
||||||
// https://cloud.tencent.com/document/product/583/18581
|
|
||||||
// https://cloud.tencent.com/document/product/583/18580
|
|
||||||
|
|
||||||
function printInput($event, $context)
|
|
||||||
{
|
|
||||||
if (strlen(json_encode($event['body']))>500) $event['body']=substr($event['body'],0,strpos($event['body'],'base64')+30) . '...Too Long!...' . substr($event['body'],-50);
|
|
||||||
echo urldecode(json_encode($event, JSON_PRETTY_PRINT)) . '
|
|
||||||
|
|
||||||
' . urldecode(json_encode($context, JSON_PRETTY_PRINT)) . '
|
|
||||||
|
|
||||||
';
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetGlobalVariable($event)
|
|
||||||
{
|
|
||||||
$_GET = $event['queryString'];
|
|
||||||
$postbody = explode("&",$event['body']);
|
|
||||||
foreach ($postbody as $postvalues) {
|
|
||||||
$pos = strpos($postvalues,"=");
|
|
||||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
|
||||||
}
|
|
||||||
$cookiebody = explode("; ",$event['headers']['cookie']);
|
|
||||||
foreach ($cookiebody as $cookievalues) {
|
|
||||||
$pos = strpos($cookievalues,"=");
|
|
||||||
$_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetPathSetting($event, $context)
|
|
||||||
{
|
|
||||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($event['headers']['accept-language'],';')[0],',')[0]);
|
|
||||||
$_SERVER['function_name'] = $context['function_name'];
|
|
||||||
$_SERVER['namespace'] = $context['namespace'];
|
|
||||||
$_SERVER['Region'] = $context['tencentcloud_region'];
|
|
||||||
$host_name = $event['headers']['host'];
|
|
||||||
$_SERVER['HTTP_HOST'] = $host_name;
|
|
||||||
$serviceId = $event['requestContext']['serviceId'];
|
|
||||||
if ( $serviceId === substr($host_name,0,strlen($serviceId)) ) {
|
|
||||||
$_SERVER['base_path'] = '/'.$event['requestContext']['stage'].'/'.$_SERVER['function_name'].'/';
|
|
||||||
$path = substr($event['path'], strlen('/'.$_SERVER['function_name'].'/'));
|
|
||||||
} else {
|
|
||||||
$_SERVER['base_path'] = $event['requestContext']['path'];
|
|
||||||
$path = substr($event['path'], strlen($event['requestContext']['path']));
|
|
||||||
}
|
|
||||||
//$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
|
|
||||||
$_SERVER['REMOTE_ADDR'] = $event['requestContext']['sourceIp'];
|
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = $event['headers']['x-requested-with'];
|
|
||||||
$_SERVER['HTTP_USER_AGENT'] = $event['headers']['user-agent'];
|
|
||||||
if (isset($event['headers']['authorization'])) {
|
|
||||||
$basicAuth = splitfirst(base64_decode(splitfirst($event['headers']['authorization'], 'Basic ')[1]), ':');
|
|
||||||
$_SERVER['PHP_AUTH_USER'] = $basicAuth[0];
|
|
||||||
$_SERVER['PHP_AUTH_PW'] = $basicAuth[1];
|
|
||||||
}
|
|
||||||
$_SERVER['REQUEST_SCHEME'] = $event['headers']['x-api-scheme'];
|
|
||||||
//$_SERVER['REQUEST_SCHEME'] = $event['headers']['x-forwarded-proto'];
|
|
||||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
|
||||||
$_SERVER['referhost'] = explode('/', $event['headers']['referer'])[2];
|
|
||||||
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
|
|
||||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since'];
|
|
||||||
$_SERVER['USER'] = 'qcloud';
|
|
||||||
return $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfig($str, $disktag = '')
|
|
||||||
{
|
|
||||||
//include 'config.php';
|
|
||||||
$s = file_get_contents('.data/config.php');
|
|
||||||
//$configs = substr($s, 18, -2);
|
|
||||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
|
||||||
if ($configs!='') {
|
|
||||||
$envs = json_decode($configs, true);
|
|
||||||
if (isInnerEnv($str)) {
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
if (isset($envs[$disktag][$str])) {
|
|
||||||
if (isBase64Env($str)) return base64y_decode($envs[$disktag][$str]);
|
|
||||||
else return $envs[$disktag][$str];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isset($envs[$str])) {
|
|
||||||
if (isBase64Env($str)) return base64y_decode($envs[$str]);
|
|
||||||
else return $envs[$str];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfig($arr, $disktag = '')
|
|
||||||
{
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
//include 'config.php';
|
|
||||||
$s = file_get_contents('.data/config.php');
|
|
||||||
//$configs = substr($s, 18, -2);
|
|
||||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
|
||||||
if ($configs!='') $envs = json_decode($configs, true);
|
|
||||||
$disktags = explode("|",getConfig('disktag'));
|
|
||||||
$indisk = 0;
|
|
||||||
$operatedisk = 0;
|
|
||||||
foreach ($arr as $k => $v) {
|
|
||||||
if (isCommonEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $envs[$k] = base64y_encode($v);
|
|
||||||
else $envs[$k] = $v;
|
|
||||||
} elseif (isInnerEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v);
|
|
||||||
else $envs[$disktag][$k] = $v;
|
|
||||||
$indisk = 1;
|
|
||||||
} elseif ($k=='disktag_add') {
|
|
||||||
array_push($disktags, $v);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_del') {
|
|
||||||
$disktags = array_diff($disktags, [ $v ]);
|
|
||||||
$envs[$v] = '';
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_copy') {
|
|
||||||
$newtag = $v . '_' . date("Ymd_His");
|
|
||||||
$envs[$newtag] = $envs[$v];
|
|
||||||
array_push($disktags, $newtag);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
|
||||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
|
||||||
} else {
|
|
||||||
$envs[$k] = $v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($indisk) {
|
|
||||||
$diskconfig = $envs[$disktag];
|
|
||||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
|
||||||
ksort($diskconfig);
|
|
||||||
$envs[$disktag] = $diskconfig;
|
|
||||||
}
|
|
||||||
if ($operatedisk) {
|
|
||||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
|
||||||
$tags = [];
|
|
||||||
foreach ($disktags as $tag) {
|
|
||||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
|
||||||
else array_push($tags, $tag);
|
|
||||||
}
|
|
||||||
$envs['disktag'] = implode('|', $tags);
|
|
||||||
$envs[$arr['disktag_newname']] = $envs[$arr['disktag_rename']];
|
|
||||||
$envs[$arr['disktag_rename']] = '';
|
|
||||||
} else {
|
|
||||||
$disktags = array_unique($disktags);
|
|
||||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
|
||||||
if ($disktag_s!='') $envs['disktag'] = substr($disktag_s, 0, -1);
|
|
||||||
else $envs['disktag'] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
|
||||||
//ksort($envs);
|
|
||||||
$response = updateEnvironment($envs, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'));
|
|
||||||
WaitSCFStat($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function WaitSCFStat($function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
|
||||||
{
|
|
||||||
$trynum = 0;
|
|
||||||
while( json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Status']!='Active' ) echo '
|
|
||||||
'.++$trynum;
|
|
||||||
}
|
|
||||||
|
|
||||||
function install()
|
|
||||||
{
|
|
||||||
global $constStr;
|
|
||||||
if ($_GET['install2']) {
|
|
||||||
$tmp['admin'] = $_POST['admin'];
|
|
||||||
$response = setConfigResponse( setConfig($tmp) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
if (needUpdate()) {
|
|
||||||
OnekeyUpate();
|
|
||||||
return message('update to github version, reinstall.
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
</script>
|
|
||||||
<meta http-equiv="refresh" content="3;URL=' . $url . '">', 'Program updating', 201, 1);
|
|
||||||
}
|
|
||||||
return message(getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
var i = 0;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>', 201, 1);
|
|
||||||
}
|
|
||||||
if ($_GET['install1']) {
|
|
||||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
|
||||||
$SecretId = $_POST['SecretId'];
|
|
||||||
$tmp['SecretId'] = $SecretId;
|
|
||||||
$SecretKey = $_POST['SecretKey'];
|
|
||||||
$tmp['SecretKey'] = $SecretKey;
|
|
||||||
$tmp['ONEMANAGER_CONFIG_SAVE'] = $_POST['ONEMANAGER_CONFIG_SAVE'];
|
|
||||||
$response = json_decode(SetbaseConfig($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
} else {
|
|
||||||
if ($tmp['ONEMANAGER_CONFIG_SAVE'] != 'file') {
|
|
||||||
$html = getconstStr('ONEMANAGER_CONFIG_SAVE_ENV') . '<br><a href="' . $_SERVER['base_path'] . '">' . getconstStr('Home') . '</a>';
|
|
||||||
$title = 'Reinstall';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
$html .= '
|
|
||||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
|
||||||
<label>'.getconstStr('SetAdminPassword').':<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.admin.value==\'\') {
|
|
||||||
alert(\''.getconstStr('SetAdminPassword').'\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SetAdminPassword');
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($_GET['install0']) {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install1" method="post" onsubmit="return notnull(this);">
|
|
||||||
language:<br>';
|
|
||||||
foreach ($constStr['languages'] as $key1 => $value1) {
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
|
||||||
}
|
|
||||||
//if (getConfig('SecretId')==''||getConfig('SecretKey')=='')
|
|
||||||
$html .= '
|
|
||||||
<a href="https://console.cloud.tencent.com/cam/capi" target="_blank">'.getconstStr('Create').' SecretId & SecretKey</a><br>
|
|
||||||
<label>SecretId:<input name="SecretId" type="text" placeholder="" size=""></label><br>
|
|
||||||
<label>SecretKey:<input name="SecretKey" type="password" placeholder="" size=""></label><br>';
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="ONEMANAGER_CONFIG_SAVE" value="" ' . ('file'==getenv('ONEMANAGER_CONFIG_SAVE')?'':'checked') . '>' . getconstStr('ONEMANAGER_CONFIG_SAVE_ENV') . '</label><br>
|
|
||||||
<label><input type="radio" name="ONEMANAGER_CONFIG_SAVE" value="file" ' . ('file'==getenv('ONEMANAGER_CONFIG_SAVE')?'checked':'') . '>' . getconstStr('ONEMANAGER_CONFIG_SAVE_FILE') . '</label><br>';
|
|
||||||
$html .= '
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
var nowtime= new Date();
|
|
||||||
var timezone = 0-nowtime.getTimezoneOffset()/60;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie="timezone="+timezone+"; path=/; "+expires;
|
|
||||||
function changelanguage(str)
|
|
||||||
{
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=\'+str+\'; path=/; \'+expires;
|
|
||||||
location.href = location.href;
|
|
||||||
}
|
|
||||||
function notnull(t)
|
|
||||||
{';
|
|
||||||
//if (getConfig('SecretId')==''||getConfig('SecretKey')=='')
|
|
||||||
$html .= '
|
|
||||||
if (t.SecretId.value==\'\') {
|
|
||||||
alert(\'input SecretId\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.SecretKey.value==\'\') {
|
|
||||||
alert(\'input SecretKey\');
|
|
||||||
return false;
|
|
||||||
}';
|
|
||||||
$html .= '
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SelectLanguage');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
$html .= '<a href="?install0">'.getconstStr('ClickInstall').'</a>, '.getconstStr('LogintoBind');
|
|
||||||
$title = 'Install';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
function post2url($url, $data)
|
|
||||||
{
|
|
||||||
$ch = curl_init();
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
|
||||||
curl_setopt($ch, CURLOPT_POST, 1);
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
|
||||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
|
||||||
$response = curl_exec($ch);
|
|
||||||
curl_close($ch);
|
|
||||||
//echo $response;
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function ReorganizeDate($arr)
|
|
||||||
{
|
|
||||||
$str = '';
|
|
||||||
ksort($arr);
|
|
||||||
foreach ($arr as $k1 => $v1) {
|
|
||||||
$str .= '&' . $k1 . '=' . $v1;
|
|
||||||
}
|
|
||||||
$str = substr($str, 1); // remove first '&'. 去掉第一个&
|
|
||||||
return $str;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
|
||||||
{
|
|
||||||
//$meth = 'GET';
|
|
||||||
$meth = 'POST';
|
|
||||||
$host = 'scf.tencentcloudapi.com';
|
|
||||||
$tmpdata['Action'] = 'GetFunction';
|
|
||||||
$tmpdata['FunctionName'] = $function_name;
|
|
||||||
$tmpdata['Namespace'] = $Namespace;
|
|
||||||
$tmpdata['Nonce'] = time();
|
|
||||||
$tmpdata['Region'] = $Region;
|
|
||||||
$tmpdata['SecretId'] = $SecretId;
|
|
||||||
$tmpdata['Timestamp'] = time();
|
|
||||||
$tmpdata['Token'] = '';
|
|
||||||
$tmpdata['Version'] = '2018-04-16';
|
|
||||||
$data = ReorganizeDate($tmpdata);
|
|
||||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
|
||||||
//echo urlencode($signStr);
|
|
||||||
//return file_get_contents('https://'.$url.'&Signature='.urlencode($signStr));
|
|
||||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
|
||||||
}
|
|
||||||
|
|
||||||
function getfunctioncodeurl($function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
|
||||||
{
|
|
||||||
//$meth = 'GET';
|
|
||||||
$meth = 'POST';
|
|
||||||
$host = 'scf.tencentcloudapi.com';
|
|
||||||
$tmpdata['Action'] = 'GetFunctionAddress';
|
|
||||||
$tmpdata['FunctionName'] = $function_name;
|
|
||||||
$tmpdata['Namespace'] = $Namespace;
|
|
||||||
$tmpdata['Nonce'] = time();
|
|
||||||
$tmpdata['Region'] = $Region;
|
|
||||||
$tmpdata['SecretId'] = $SecretId;
|
|
||||||
$tmpdata['Timestamp'] = time();
|
|
||||||
$tmpdata['Token'] = '';
|
|
||||||
$tmpdata['Version'] = '2018-04-16';
|
|
||||||
$data = ReorganizeDate($tmpdata);
|
|
||||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
|
||||||
//echo urlencode($signStr);
|
|
||||||
//return file_get_contents('https://'.$url.'&Signature='.urlencode($signStr));
|
|
||||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
|
||||||
}
|
|
||||||
|
|
||||||
function copyFolder($from, $to)
|
|
||||||
{
|
|
||||||
if (substr($from, -1)=='/') $from = substr($from, 0, -1);
|
|
||||||
if (substr($to, -1)=='/') $to = substr($to, 0, -1);
|
|
||||||
if (!file_exists($to)) mkdir($to, 0777);
|
|
||||||
$handler=opendir($from);
|
|
||||||
while($filename=readdir($handler)) {
|
|
||||||
if($filename != '.' && $filename != '..'){
|
|
||||||
$fromfile = $from.'/'.$filename;
|
|
||||||
$tofile = $to.'/'.$filename;
|
|
||||||
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
|
||||||
copyFolder($fromfile, $tofile);
|
|
||||||
}else{
|
|
||||||
copy($fromfile, $tofile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir($handler);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
|
||||||
{
|
|
||||||
sortConfig($Envs);
|
|
||||||
// 获取当前代码并解压
|
|
||||||
//$codeurl = json_decode(getfunctioncodeurl($function_name, $Region, $Namespace, $SecretId, $SecretKey), true)['Response']['Url'];
|
|
||||||
//$codezip = '/tmp/oldcode.zip';
|
|
||||||
$outPath = '/tmp/code/';
|
|
||||||
|
|
||||||
//file_put_contents($codezip, file_get_contents($codeurl));
|
|
||||||
//$zip=new ZipArchive();
|
|
||||||
//$zip->open($codezip);
|
|
||||||
//$html = $zip->extractTo($outPath);
|
|
||||||
|
|
||||||
$coderoot = __DIR__ . '/../';
|
|
||||||
copyFolder($coderoot, $outPath);
|
|
||||||
|
|
||||||
// 将配置写入
|
|
||||||
$prestr = '<?php $configs = \'' . PHP_EOL;
|
|
||||||
$aftstr = PHP_EOL . '\';';
|
|
||||||
file_put_contents($outPath . '.data/config.php', $prestr . json_encode($Envs, JSON_PRETTY_PRINT) . $aftstr);
|
|
||||||
|
|
||||||
// 将目录中文件打包成zip
|
|
||||||
$source = '/tmp/code.zip';
|
|
||||||
//$zip=new ZipArchive();
|
|
||||||
$zip=new PharData($source);
|
|
||||||
//if($zip->open($source, ZipArchive::CREATE)){
|
|
||||||
addFileToZip($zip, $outPath); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
|
|
||||||
// $zip->close(); //关闭处理的zip文件
|
|
||||||
//}
|
|
||||||
|
|
||||||
return updateProgram($function_name, $Region, $namespace, $SecretId, $SecretKey, $source);
|
|
||||||
$tmp1['Response']['Error']['Message'] = $codeurl;
|
|
||||||
error_log1($tmp1['Response']['Error']['Message']);
|
|
||||||
return json_encode($tmp1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
|
||||||
{
|
|
||||||
if ($Envs['ONEMANAGER_CONFIG_SAVE'] == 'file') $tmp_env = Array( 'ONEMANAGER_CONFIG_SAVE' => 'file' );
|
|
||||||
else {
|
|
||||||
$Envs['ONEMANAGER_CONFIG_SAVE'] == '';
|
|
||||||
$tmp = json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Environment']['Variables'];
|
|
||||||
foreach ($tmp as $tmp1) {
|
|
||||||
$tmp_env[$tmp1['Key']] = $tmp1['Value'];
|
|
||||||
}
|
|
||||||
foreach ($Envs as $key1 => $value1) {
|
|
||||||
$tmp_env[$key1] = $value1;
|
|
||||||
}
|
|
||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
|
||||||
ksort($tmp_env);
|
|
||||||
}
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
foreach ($tmp_env as $key1 => $value1) {
|
|
||||||
$tmpdata['Environment.Variables.'.$i.'.Key'] = $key1;
|
|
||||||
$tmpdata['Environment.Variables.'.$i.'.Value'] = $value1;
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$meth = 'POST';
|
|
||||||
$host = 'scf.tencentcloudapi.com';
|
|
||||||
$tmpdata['Action'] = 'UpdateFunctionConfiguration';
|
|
||||||
$tmpdata['FunctionName'] = $function_name;
|
|
||||||
$tmpdata['Namespace'] = $Namespace;
|
|
||||||
$tmpdata['Nonce'] = time();
|
|
||||||
$tmpdata['Region'] = $Region;
|
|
||||||
$tmpdata['SecretId'] = $SecretId;
|
|
||||||
$tmpdata['Timestamp'] = time();
|
|
||||||
$tmpdata['Token'] = '';
|
|
||||||
$tmpdata['Version'] = '2018-04-16';
|
|
||||||
$tmpdata['Description'] = 'Onedrive index and manager in Tencent SCF.';
|
|
||||||
$tmpdata['MemorySize'] = 64;
|
|
||||||
$tmpdata['Timeout'] = 30;
|
|
||||||
$data = ReorganizeDate($tmpdata);
|
|
||||||
//echo $data;
|
|
||||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
|
||||||
//echo urlencode($signStr);
|
|
||||||
$response = post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
|
||||||
if (api_error(setConfigResponse($response))) {
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
if ( json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Timeout'] < 25 ) {
|
|
||||||
$tmp['Response']['Error']['Message'] = 'Operating, please try again.';
|
|
||||||
$tmp['Response']['Error']['Code'] = 'Retry';
|
|
||||||
return json_encode($tmp);
|
|
||||||
}
|
|
||||||
WaitSCFStat($function_name, $Region, $Namespace, $SecretId, $SecretKey);
|
|
||||||
|
|
||||||
$s = file_get_contents('.data/config.php');
|
|
||||||
//$configs = substr($s, 18, -2);
|
|
||||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
|
||||||
if ($configs!='') $envs = json_decode($configs, true);
|
|
||||||
foreach ($Envs as $k => $v) {
|
|
||||||
$envs[$k] = $v;
|
|
||||||
}
|
|
||||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
|
||||||
//ksort($envs);
|
|
||||||
$response = updateEnvironment($envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateProgram($function_name, $Region, $Namespace, $SecretId, $SecretKey, $source)
|
|
||||||
{
|
|
||||||
$secretId = $SecretId;
|
|
||||||
$secretKey = $SecretKey;
|
|
||||||
$host = 'scf.tencentcloudapi.com';
|
|
||||||
$service = "scf";
|
|
||||||
$version = "2018-04-16";
|
|
||||||
$action = "UpdateFunctionCode";
|
|
||||||
$region = $Region;
|
|
||||||
$timestamp = time();
|
|
||||||
$algorithm = "TC3-HMAC-SHA256";
|
|
||||||
|
|
||||||
// step 1: build canonical request string
|
|
||||||
$httpRequestMethod = "POST";
|
|
||||||
$canonicalUri = "/";
|
|
||||||
$canonicalQueryString = "";
|
|
||||||
$canonicalHeaders = "content-type:application/json; charset=utf-8\n"."host:".$host."\n";
|
|
||||||
$signedHeaders = "content-type;host";
|
|
||||||
|
|
||||||
//$tmpdata['Action'] = 'UpdateFunctionCode';
|
|
||||||
$tmpdata['Code']['ZipFile'] = base64_encode( file_get_contents($source) );
|
|
||||||
$tmpdata['CodeSource'] = 'ZipFile';
|
|
||||||
$tmpdata['FunctionName'] = $function_name;
|
|
||||||
$tmpdata['Handler'] = 'index.main_handler';
|
|
||||||
//$tmpdata['Namespace'] = $Namespace;
|
|
||||||
//$tmpdata['Nonce'] = time();
|
|
||||||
//$tmpdata['Region'] = $Region;
|
|
||||||
//$tmpdata['SecretId'] = $SecretId;
|
|
||||||
//$tmpdata['Timestamp'] = time();
|
|
||||||
//$tmpdata['Token'] = '';
|
|
||||||
//$tmpdata['Version'] = '2018-04-16';
|
|
||||||
$payload = json_encode($tmpdata);
|
|
||||||
//$payload = '{"Limit": 1, "Filters": [{"Values": ["\u672a\u547d\u540d"], "Name": "instance-name"}]}';
|
|
||||||
$hashedRequestPayload = hash("SHA256", $payload);
|
|
||||||
$canonicalRequest = $httpRequestMethod."\n"
|
|
||||||
.$canonicalUri."\n"
|
|
||||||
.$canonicalQueryString."\n"
|
|
||||||
.$canonicalHeaders."\n"
|
|
||||||
.$signedHeaders."\n"
|
|
||||||
.$hashedRequestPayload;
|
|
||||||
//echo $canonicalRequest.PHP_EOL;
|
|
||||||
|
|
||||||
// step 2: build string to sign
|
|
||||||
$date = gmdate("Y-m-d", $timestamp);
|
|
||||||
$credentialScope = $date."/".$service."/tc3_request";
|
|
||||||
$hashedCanonicalRequest = hash("SHA256", $canonicalRequest);
|
|
||||||
$stringToSign = $algorithm."\n"
|
|
||||||
.$timestamp."\n"
|
|
||||||
.$credentialScope."\n"
|
|
||||||
.$hashedCanonicalRequest;
|
|
||||||
//echo $stringToSign.PHP_EOL;
|
|
||||||
|
|
||||||
// step 3: sign string
|
|
||||||
$secretDate = hash_hmac("SHA256", $date, "TC3".$secretKey, true);
|
|
||||||
$secretService = hash_hmac("SHA256", $service, $secretDate, true);
|
|
||||||
$secretSigning = hash_hmac("SHA256", "tc3_request", $secretService, true);
|
|
||||||
$signature = hash_hmac("SHA256", $stringToSign, $secretSigning);
|
|
||||||
//echo $signature.PHP_EOL;
|
|
||||||
|
|
||||||
// step 4: build authorization
|
|
||||||
$authorization = $algorithm
|
|
||||||
." Credential=".$secretId."/".$credentialScope
|
|
||||||
.", SignedHeaders=content-type;host, Signature=".$signature;
|
|
||||||
//echo $authorization.PHP_EOL;
|
|
||||||
|
|
||||||
//$curl = "curl -X POST https://".$host
|
|
||||||
// .' -H "Authorization: '.$authorization.'"'
|
|
||||||
// .' -H "Content-Type: application/json; charset=utf-8"'
|
|
||||||
// .' -H "Host: '.$host.'"'
|
|
||||||
// .' -H "X-TC-Action: '.$action.'"'
|
|
||||||
// .' -H "X-TC-Timestamp: '.$timestamp.'"'
|
|
||||||
// .' -H "X-TC-Version: '.$version.'"'
|
|
||||||
// .' -H "X-TC-Region: '.$region.'"'
|
|
||||||
// ." -d '".$payload."'";
|
|
||||||
//error_log1( $curl.PHP_EOL );
|
|
||||||
//return '{"response": {"Error": {"Message":"' . $curl . '"}}}';
|
|
||||||
$headers['Authorization'] = $authorization;
|
|
||||||
$headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
||||||
$headers['Host'] = $host;
|
|
||||||
$headers['X-TC-Action'] = $action;
|
|
||||||
$headers['X-TC-Timestamp'] = $timestamp;
|
|
||||||
$headers['X-TC-Version'] = $version;
|
|
||||||
$headers['X-TC-Region'] = $region;
|
|
||||||
return curl('POST', 'https://'.$host, $payload, $headers)['body'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error($response)
|
|
||||||
{
|
|
||||||
return isset($response['Error']);
|
|
||||||
return ($response==null)||isset($response['Error']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error_msg($response)
|
|
||||||
{
|
|
||||||
return $response['Error']['Code'] . '<br>
|
|
||||||
' . $response['Error']['Message'] . '<br><br>
|
|
||||||
function_name:' . $_SERVER['function_name'] . '<br>
|
|
||||||
Region:' . $_SERVER['Region'] . '<br>
|
|
||||||
namespace:' . $_SERVER['namespace'] . '<br>
|
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfigResponse($response)
|
|
||||||
{
|
|
||||||
return json_decode( $response, true )['Response'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
|
||||||
{
|
|
||||||
$source = '/tmp/code.zip';
|
|
||||||
$outPath = '/tmp/';
|
|
||||||
|
|
||||||
if ($GitSource=='Github') {
|
|
||||||
// 从github下载对应tar.gz,并解压
|
|
||||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
|
||||||
} elseif ($GitSource=='HITGitlab') {
|
|
||||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
|
||||||
} else return json_encode(['Response'=>['Error'=>['code'=>'Git Source input Error!']]]);
|
|
||||||
$tarfile = '/tmp/github.tar.gz';
|
|
||||||
file_put_contents($tarfile, file_get_contents($url));
|
|
||||||
$phar = new PharData($tarfile);
|
|
||||||
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
|
||||||
|
|
||||||
// 获取解压出的目录名
|
|
||||||
$outPath = findIndexPath($outPath);
|
|
||||||
|
|
||||||
// 放入配置文件
|
|
||||||
file_put_contents($outPath . '/.data/config.php', file_get_contents(__DIR__ . '/../.data/config.php'));
|
|
||||||
|
|
||||||
// 将目录中文件打包成zip
|
|
||||||
//$zip=new ZipArchive();
|
|
||||||
$zip=new PharData($source);
|
|
||||||
//if($zip->open($source, ZipArchive::CREATE)){
|
|
||||||
addFileToZip($zip, $outPath); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
|
|
||||||
// $zip->close(); //关闭处理的zip文件
|
|
||||||
//}
|
|
||||||
|
|
||||||
return updateProgram($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'), $source);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addFileToZip($zip, $rootpath, $path = '')
|
|
||||||
{
|
|
||||||
if (substr($rootpath,-1)=='/') $rootpath = substr($rootpath, 0, -1);
|
|
||||||
if (substr($path,0,1)=='/') $path = substr($path, 1);
|
|
||||||
$handler=opendir(path_format($rootpath.'/'.$path)); //打开当前文件夹由$path指定。
|
|
||||||
while($filename=readdir($handler)){
|
|
||||||
if($filename != "." && $filename != ".."){//文件夹文件名字为'.'和‘..’,不要对他们进行操作
|
|
||||||
$nowname = path_format($rootpath.'/'.$path."/".$filename);
|
|
||||||
if(is_dir($nowname)){// 如果读取的某个对象是文件夹,则递归
|
|
||||||
$zip->addEmptyDir($path."/".$filename);
|
|
||||||
addFileToZip($zip, $rootpath, $path."/".$filename);
|
|
||||||
}else{ //将文件加入zip对象
|
|
||||||
$newname = $path."/".$filename;
|
|
||||||
if (substr($newname,0,1)=='/') $newname = substr($newname, 1);
|
|
||||||
$zip->addFile($nowname, $newname);
|
|
||||||
//$zip->renameName($nowname, $newname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@closedir($handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeAuthKey() {
|
|
||||||
if ($_POST['SecretId']!=''&&$_POST['SecretId']!='') {
|
|
||||||
$tmp['SecretId'] = $_POST['SecretId'];
|
|
||||||
$tmp['SecretKey'] = $_POST['SecretKey'];
|
|
||||||
$response = setConfigResponse( SetbaseConfig($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $tmp['SecretId'], $tmp['SecretKey']) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 400);
|
|
||||||
} else {
|
|
||||||
$html = getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var status = "' . $response['DplStatus'] . '";
|
|
||||||
var i = 0;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$html = '
|
|
||||||
<form action="" method="post" onsubmit="return notnull(this);">
|
|
||||||
<a href="https://console.cloud.tencent.com/cam/capi" target="_blank">' . getconstStr('Create') . ' SecretId & SecretKey</a><br>
|
|
||||||
<label>SecretId:<input name="SecretId" type="text" placeholder="" size=""></label><br>
|
|
||||||
<label>SecretKey:<input name="SecretKey" type="password" placeholder="" size=""></label><br>
|
|
||||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.SecretId.value==\'\') {
|
|
||||||
alert(\'input SecretId\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.SecretKey.value==\'\') {
|
|
||||||
alert(\'input SecretKey\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
return message($html, 'Change platform Auth token or key', 200);
|
|
||||||
}
|
|
|
@ -1,491 +0,0 @@
|
||||||
<?php
|
|
||||||
// https://vercel.com/docs/api#endpoints/deployments/create-a-new-deployment
|
|
||||||
|
|
||||||
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 ($_SERVER['REQUEST_SCHEME']!='http'&&$_SERVER['REQUEST_SCHEME']!='https') {
|
|
||||||
if ($_SERVER['HTTP_X_FORWARDED_PROTO']!='') {
|
|
||||||
$tmp = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0];
|
|
||||||
if ($tmp=='http'||$tmp=='https') $_SERVER['REQUEST_SCHEME'] = $tmp;
|
|
||||||
}
|
|
||||||
if ($_SERVER['HTTP_FLY_FORWARDED_PROTO']!='') $_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_FLY_FORWARDED_PROTO'];
|
|
||||||
}
|
|
||||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
|
||||||
$_SERVER['referhost'] = explode('/', $_SERVER['HTTP_REFERER'])[2];
|
|
||||||
$_SERVER['base_path'] = "/";
|
|
||||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
|
||||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getGET()
|
|
||||||
{
|
|
||||||
if (!$_POST) {
|
|
||||||
if (!!$HTTP_RAW_POST_DATA) {
|
|
||||||
$tmpdata = $HTTP_RAW_POST_DATA;
|
|
||||||
} else {
|
|
||||||
$tmpdata = file_get_contents('php://input');
|
|
||||||
}
|
|
||||||
if (!!$tmpdata) {
|
|
||||||
$postbody = explode("&", $tmpdata);
|
|
||||||
foreach ($postbody as $postvalues) {
|
|
||||||
$pos = strpos($postvalues,"=");
|
|
||||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
|
||||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
|
||||||
if ($p>0) {
|
|
||||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
|
||||||
$getstrarr = explode("&",$getstr);
|
|
||||||
foreach ($getstrarr as $getvalues) {
|
|
||||||
if ($getvalues != '') {
|
|
||||||
$pos = strpos($getvalues, "=");
|
|
||||||
//echo $pos;
|
|
||||||
if ($pos > 0) {
|
|
||||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
|
||||||
} else {
|
|
||||||
$getarry[urldecode($getvalues)] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($getarry)) {
|
|
||||||
return $getarry;
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfig($str, $disktag = '')
|
|
||||||
{
|
|
||||||
$projectPath = splitlast(__DIR__, '/')[0];
|
|
||||||
$configPath = $projectPath . '/.data/config.php';
|
|
||||||
$s = file_get_contents($configPath);
|
|
||||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
|
||||||
if ($configs!='') {
|
|
||||||
$envs = json_decode($configs, true);
|
|
||||||
if (isInnerEnv($str)) {
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
if (isset($envs[$disktag][$str])) {
|
|
||||||
if (isBase64Env($str)) return base64y_decode($envs[$disktag][$str]);
|
|
||||||
else return $envs[$disktag][$str];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isset($envs[$str])) {
|
|
||||||
if (isBase64Env($str)) return base64y_decode($envs[$str]);
|
|
||||||
else return $envs[$str];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfig($arr, $disktag = '')
|
|
||||||
{
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$projectPath = splitlast(__DIR__, '/')[0];
|
|
||||||
$configPath = $projectPath . '/.data/config.php';
|
|
||||||
$s = file_get_contents($configPath);
|
|
||||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
|
||||||
if ($configs!='') $envs = json_decode($configs, true);
|
|
||||||
$disktags = explode("|",getConfig('disktag'));
|
|
||||||
$indisk = 0;
|
|
||||||
$operatedisk = 0;
|
|
||||||
foreach ($arr as $k => $v) {
|
|
||||||
if (isCommonEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $envs[$k] = base64y_encode($v);
|
|
||||||
else $envs[$k] = $v;
|
|
||||||
} elseif (isInnerEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v);
|
|
||||||
else $envs[$disktag][$k] = $v;
|
|
||||||
$indisk = 1;
|
|
||||||
} elseif ($k=='disktag_add') {
|
|
||||||
array_push($disktags, $v);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_del') {
|
|
||||||
$disktags = array_diff($disktags, [ $v ]);
|
|
||||||
$envs[$v] = '';
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_copy') {
|
|
||||||
$newtag = $v . '_' . date("Ymd_His");
|
|
||||||
$envs[$newtag] = $envs[$v];
|
|
||||||
array_push($disktags, $newtag);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
|
||||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
|
||||||
} else {
|
|
||||||
$envs[$k] = $v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($indisk) {
|
|
||||||
$diskconfig = $envs[$disktag];
|
|
||||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
|
||||||
ksort($diskconfig);
|
|
||||||
$envs[$disktag] = $diskconfig;
|
|
||||||
}
|
|
||||||
if ($operatedisk) {
|
|
||||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
|
||||||
$tags = [];
|
|
||||||
foreach ($disktags as $tag) {
|
|
||||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
|
||||||
else array_push($tags, $tag);
|
|
||||||
}
|
|
||||||
$envs['disktag'] = implode('|', $tags);
|
|
||||||
$envs[$arr['disktag_newname']] = $envs[$arr['disktag_rename']];
|
|
||||||
$envs[$arr['disktag_rename']] = '';
|
|
||||||
} else {
|
|
||||||
$disktags = array_unique($disktags);
|
|
||||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
|
||||||
if ($disktag_s!='') $envs['disktag'] = substr($disktag_s, 0, -1);
|
|
||||||
else $envs['disktag'] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
|
||||||
//ksort($envs);
|
|
||||||
//sortConfig($envs);
|
|
||||||
//error_log1(json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($envs, JSON_PRETTY_PRINT));
|
|
||||||
//echo json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($envs, JSON_PRETTY_PRINT);
|
|
||||||
return setVercelConfig($envs, getConfig('HerokuappId'), getConfig('APIKey'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function install()
|
|
||||||
{
|
|
||||||
global $constStr;
|
|
||||||
if ($_GET['install1']) {
|
|
||||||
if ($_POST['admin']!='') {
|
|
||||||
$tmp['admin'] = $_POST['admin'];
|
|
||||||
//$tmp['language'] = $_POST['language'];
|
|
||||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
|
||||||
$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), true);
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 400);
|
|
||||||
} else {
|
|
||||||
$html = getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var status = "' . $response['DplStatus'] . '";
|
|
||||||
var i = 0;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+1000);
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($_GET['install0']) {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install1" method="post" onsubmit="return notnull(this);">
|
|
||||||
language:<br>';
|
|
||||||
foreach ($constStr['languages'] as $key1 => $value1) {
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
|
||||||
}
|
|
||||||
$html .= '<br>
|
|
||||||
<a href="https://vercel.com/account/tokens" target="_blank">' . getconstStr('Create') . ' token</a><br>
|
|
||||||
<label>Token:<input name="APIKey" type="password" placeholder="" value=""></label><br>';
|
|
||||||
$html .= '<br>
|
|
||||||
<label>Set admin password:<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>';
|
|
||||||
$html .= '
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<div id="showerror"></div>
|
|
||||||
<script>
|
|
||||||
var nowtime= new Date();
|
|
||||||
var timezone = 0-nowtime.getTimezoneOffset()/60;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie="timezone="+timezone+"; path=/; "+expires;
|
|
||||||
var errordiv = document.getElementById("showerror");
|
|
||||||
function changelanguage(str)
|
|
||||||
{
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=\'+str+\'; path=/; \'+expires;
|
|
||||||
location.href = location.href;
|
|
||||||
}
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.admin.value==\'\') {
|
|
||||||
alert(\'input admin\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.APIKey.value==\'\') {
|
|
||||||
alert(\'input Token\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SelectLanguage');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (substr($_SERVER["host"], -10)=="vercel.app") {
|
|
||||||
$html .= '<a href="?install0">' . getconstStr('ClickInstall') . '</a>, ' . getconstStr('LogintoBind');
|
|
||||||
$html .= "<br>Remember: you MUST wait 30-60s after each operate / do some change, that make sure Vercel has done the building<br>" ;
|
|
||||||
} else {
|
|
||||||
$html.= "Please visit form *.vercel.app";
|
|
||||||
}
|
|
||||||
$title = 'Install';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
function copyFolder($from, $to)
|
|
||||||
{
|
|
||||||
if (substr($from, -1)=='/') $from = substr($from, 0, -1);
|
|
||||||
if (substr($to, -1)=='/') $to = substr($to, 0, -1);
|
|
||||||
if (!file_exists($to)) mkdir($to, 0777, 1);
|
|
||||||
$handler=opendir($from);
|
|
||||||
while($filename=readdir($handler)) {
|
|
||||||
if($filename != '.' && $filename != '..'){
|
|
||||||
$fromfile = $from.'/'.$filename;
|
|
||||||
$tofile = $to.'/'.$filename;
|
|
||||||
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
|
||||||
copyFolder($fromfile, $tofile);
|
|
||||||
}else{
|
|
||||||
copy($fromfile, $tofile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir($handler);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setVercelConfig($envs, $appId, $token)
|
|
||||||
{
|
|
||||||
sortConfig($envs);
|
|
||||||
$outPath = '/tmp/code/';
|
|
||||||
$outPath_Api = $outPath . 'api/';
|
|
||||||
$coderoot = __DIR__;
|
|
||||||
$coderoot = splitlast($coderoot, '/')[0] . '/';
|
|
||||||
//echo $outPath_Api . '<br>' . $coderoot . '<br>';
|
|
||||||
copyFolder($coderoot, $outPath_Api);
|
|
||||||
$prestr = '<?php $configs = \'' . PHP_EOL;
|
|
||||||
$aftstr = PHP_EOL . '\';';
|
|
||||||
file_put_contents($outPath_Api . '.data/config.php', $prestr . json_encode($envs, JSON_PRETTY_PRINT) . $aftstr);
|
|
||||||
|
|
||||||
return VercelUpdate($appId, $token, $outPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
function VercelUpdate($appId, $token, $sourcePath = "")
|
|
||||||
{
|
|
||||||
if (checkBuilding($appId, $token)) return '{"error":{"message":"Another building is in progress."}}';
|
|
||||||
$url = "https://api.vercel.com/v13/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 . "<br>";
|
|
||||||
getEachFiles($file, $sourcePath);
|
|
||||||
$data["files"] = $file;
|
|
||||||
|
|
||||||
//echo json_encode($data, JSON_PRETTY_PRINT) . " ,data<br>";
|
|
||||||
$response = curl("POST", $url, json_encode($data), $header);
|
|
||||||
//echo json_encode($response, JSON_PRETTY_PRINT) . " ,res<br>";
|
|
||||||
$result = json_decode($response["body"], true);
|
|
||||||
$result['DplStatus'] = $result['id'];
|
|
||||||
return json_encode($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkBuilding($projectId, $token)
|
|
||||||
{
|
|
||||||
$r = 0;
|
|
||||||
$url = "https://api.vercel.com/v6/deployments/?projectId=" . $projectId;
|
|
||||||
$header["Authorization"] = "Bearer " . $token;
|
|
||||||
$header["Content-Type"] = "application/json";
|
|
||||||
$response = curl("GET", $url, '', $header);
|
|
||||||
//echo json_encode($response, JSON_PRETTY_PRINT) . " ,res<br>";
|
|
||||||
$result = json_decode($response["body"], true);
|
|
||||||
foreach ( $result['deployments'] as $deployment ) {
|
|
||||||
if ($deployment['state']!=="READY") $r++;
|
|
||||||
}
|
|
||||||
return $r;
|
|
||||||
//if ($r===0) return true;
|
|
||||||
//else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getEachFiles(&$file, $base, $path = "")
|
|
||||||
{
|
|
||||||
//if (substr($base, -1)=="/") $base = substr($base, 0, -1);
|
|
||||||
//if (substr($path, -1)=="/") $path = substr($path, 0, -1);
|
|
||||||
$handler=opendir(path_format($base . "/" . $path));
|
|
||||||
while($filename=readdir($handler)) {
|
|
||||||
if($filename != '.' && $filename != '..' && $filename != '.git'){
|
|
||||||
$fromfile = path_format($base . "/" . $path . "/" . $filename);
|
|
||||||
//echo $fromfile . "<br>";
|
|
||||||
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);
|
|
||||||
$file[] = $tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir($handler);
|
|
||||||
|
|
||||||
return json_encode( [ 'response' => 'success' ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error($response)
|
|
||||||
{
|
|
||||||
return isset($response['error']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error_msg($response)
|
|
||||||
{
|
|
||||||
return $response['error']['code'] . '<br>
|
|
||||||
' . $response['error']['message'] . '<br>
|
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfigResponse($response)
|
|
||||||
{
|
|
||||||
return json_decode($response, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
|
||||||
{
|
|
||||||
$tmppath = '/tmp';
|
|
||||||
|
|
||||||
if ($GitSource=='Github') {
|
|
||||||
// 从github下载对应tar.gz,并解压
|
|
||||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
|
||||||
} elseif ($GitSource=='HITGitlab') {
|
|
||||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
|
||||||
} else return json_encode(['error'=>['code'=>'Git Source input Error!']]);
|
|
||||||
|
|
||||||
$tarfile = $tmppath . '/github.tar.gz';
|
|
||||||
file_put_contents($tarfile, file_get_contents($url));
|
|
||||||
$phar = new PharData($tarfile);
|
|
||||||
$html = $phar->extractTo($tmppath, null, true);//路径 要解压的文件 是否覆盖
|
|
||||||
unlink($tarfile);
|
|
||||||
|
|
||||||
// 获取解压出的目录名
|
|
||||||
$outPath = findIndexPath($tmppath);
|
|
||||||
|
|
||||||
if ($outPath=='') return '{"error":{"message":"no outpath"}}';
|
|
||||||
$name = $project . 'CODE';
|
|
||||||
mkdir($tmppath . "/" . $name, 0777, 1);
|
|
||||||
rename($outPath, $tmppath . "/" . $name . '/api');
|
|
||||||
$outPath = $tmppath . "/" . $name;
|
|
||||||
//echo $outPath . "<br>";
|
|
||||||
//error_log1($outPath);
|
|
||||||
|
|
||||||
// put in config
|
|
||||||
$coderoot = __DIR__;
|
|
||||||
$coderoot = splitlast($coderoot, '/')[0] . '/';
|
|
||||||
copy($coderoot . '.data/config.php', $outPath . '/api/.data/config.php');
|
|
||||||
|
|
||||||
return VercelUpdate(getConfig('HerokuappId'), getConfig('APIKey'), $outPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
function WaitFunction($deployid = '') {
|
|
||||||
if ($buildId=='1') {
|
|
||||||
$tmp['stat'] = 400;
|
|
||||||
$tmp['body'] = 'id must provided.';
|
|
||||||
return $tmp;
|
|
||||||
}
|
|
||||||
$header["Authorization"] = "Bearer " . getConfig('APIKey');
|
|
||||||
$header["Content-Type"] = "application/json";
|
|
||||||
$url = "https://api.vercel.com/v11/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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeAuthKey() {
|
|
||||||
if ($_POST['APIKey']!='') {
|
|
||||||
$APIKey = $_POST['APIKey'];
|
|
||||||
$tmp['APIKey'] = $APIKey;
|
|
||||||
$response = setConfigResponse( setVercelConfig($tmp, getConfig('HerokuappId'), $APIKey) );
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 400);
|
|
||||||
} else {
|
|
||||||
$html = getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var status = "' . $response['DplStatus'] . '";
|
|
||||||
var i = 0;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$html = '
|
|
||||||
<form action="" method="post" onsubmit="return notnull(this);">
|
|
||||||
<a href="https://vercel.com/account/tokens" target="_blank">' . getconstStr('Create') . ' token</a><br>
|
|
||||||
<label>Token:<input name="APIKey" type="password" placeholder="" value=""></label><br>
|
|
||||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.APIKey.value==\'\') {
|
|
||||||
alert(\'Input Token\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
return message($html, 'Change platform Auth token or key', 200);
|
|
||||||
}
|
|
|
@ -1,473 +0,0 @@
|
||||||
<?php
|
|
||||||
// https://vercel.com/docs/api#endpoints/deployments/create-a-new-deployment
|
|
||||||
|
|
||||||
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 ($_SERVER['REQUEST_SCHEME']!='http'&&$_SERVER['REQUEST_SCHEME']!='https') {
|
|
||||||
if ($_SERVER['HTTP_X_FORWARDED_PROTO']!='') {
|
|
||||||
$tmp = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0];
|
|
||||||
if ($tmp=='http'||$tmp=='https') $_SERVER['REQUEST_SCHEME'] = $tmp;
|
|
||||||
}
|
|
||||||
if ($_SERVER['HTTP_FLY_FORWARDED_PROTO']!='') $_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_FLY_FORWARDED_PROTO'];
|
|
||||||
}
|
|
||||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
|
||||||
$_SERVER['referhost'] = explode('/', $_SERVER['HTTP_REFERER'])[2];
|
|
||||||
$_SERVER['base_path'] = "/";
|
|
||||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
|
||||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getGET()
|
|
||||||
{
|
|
||||||
if (!$_POST) {
|
|
||||||
if (!!$HTTP_RAW_POST_DATA) {
|
|
||||||
$tmpdata = $HTTP_RAW_POST_DATA;
|
|
||||||
} else {
|
|
||||||
$tmpdata = file_get_contents('php://input');
|
|
||||||
}
|
|
||||||
if (!!$tmpdata) {
|
|
||||||
$postbody = explode("&", $tmpdata);
|
|
||||||
foreach ($postbody as $postvalues) {
|
|
||||||
$pos = strpos($postvalues,"=");
|
|
||||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
|
||||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
|
||||||
if ($p>0) {
|
|
||||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
|
||||||
$getstrarr = explode("&",$getstr);
|
|
||||||
foreach ($getstrarr as $getvalues) {
|
|
||||||
if ($getvalues != '') {
|
|
||||||
$pos = strpos($getvalues, "=");
|
|
||||||
//echo $pos;
|
|
||||||
if ($pos > 0) {
|
|
||||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
|
||||||
} else {
|
|
||||||
$getarry[urldecode($getvalues)] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($getarry)) {
|
|
||||||
return $getarry;
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfig($str, $disktag = '')
|
|
||||||
{
|
|
||||||
if (isInnerEnv($str)) {
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$tmp = getenv($disktag);
|
|
||||||
if (is_array($tmp)) $env = $tmp;
|
|
||||||
else $env = json_decode($tmp, true);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfig($arr, $disktag = '')
|
|
||||||
{
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
|
||||||
$disktags = explode("|", getenv('disktag'));
|
|
||||||
if ($disktag!='') {
|
|
||||||
$tmp = getenv($disktag);
|
|
||||||
if (is_array($tmp)) $diskconfig = $tmp;
|
|
||||||
else $diskconfig = json_decode($tmp, true);
|
|
||||||
}
|
|
||||||
$tmp = [];
|
|
||||||
$indisk = 0;
|
|
||||||
$operatedisk = 0;
|
|
||||||
foreach ($arr as $k => $v) {
|
|
||||||
if (isCommonEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
|
||||||
else $tmp[$k] = $v;
|
|
||||||
} elseif (isInnerEnv($k)) {
|
|
||||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
|
||||||
else $diskconfig[$k] = $v;
|
|
||||||
$indisk = 1;
|
|
||||||
} elseif ($k=='disktag_add') {
|
|
||||||
array_push($disktags, $v);
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_del') {
|
|
||||||
$disktags = array_diff($disktags, [ $v ]);
|
|
||||||
$tmp[$v] = '';
|
|
||||||
$operatedisk = 1;
|
|
||||||
} elseif ($k=='disktag_copy') {
|
|
||||||
$newtag = $v . '_' . date("Ymd_His");
|
|
||||||
$tagvalue = getenv($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') {
|
|
||||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
|
||||||
} else {
|
|
||||||
$tmp[$k] = json_encode($v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($indisk) {
|
|
||||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
|
||||||
ksort($diskconfig);
|
|
||||||
$tmp[$disktag] = json_encode($diskconfig);
|
|
||||||
}
|
|
||||||
if ($operatedisk) {
|
|
||||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
|
||||||
$tags = [];
|
|
||||||
foreach ($disktags as $tag) {
|
|
||||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
|
||||||
else array_push($tags, $tag);
|
|
||||||
}
|
|
||||||
$tmp['disktag'] = implode('|', $tags);
|
|
||||||
$tagvalue = getenv($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);
|
|
||||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
|
||||||
if ($disktag_s!='') $tmp['disktag'] = substr($disktag_s, 0, -1);
|
|
||||||
else $tmp['disktag'] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($tmp as $key => $val) if ($val=='') $tmp[$key]=null;
|
|
||||||
|
|
||||||
//error_log1(json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($tmp, JSON_PRETTY_PRINT));
|
|
||||||
//echo json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($tmp, JSON_PRETTY_PRINT);
|
|
||||||
return setVercelConfig($tmp, getConfig('HerokuappId'), getConfig('APIKey'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function install()
|
|
||||||
{
|
|
||||||
global $constStr;
|
|
||||||
if ($_GET['install1']) {
|
|
||||||
if ($_POST['admin']!='') {
|
|
||||||
$tmp['admin'] = $_POST['admin'];
|
|
||||||
//$tmp['language'] = $_POST['language'];
|
|
||||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
|
||||||
$APIKey = $_POST['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), true);
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 400);
|
|
||||||
} else {
|
|
||||||
$html = getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var status = "' . $response['DplStatus'] . '";
|
|
||||||
var i = 0;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+1000);
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=; path=/; \'+expires;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($_GET['install0']) {
|
|
||||||
$html .= '
|
|
||||||
<form action="?install1" method="post" onsubmit="return notnull(this);">
|
|
||||||
language:<br>';
|
|
||||||
foreach ($constStr['languages'] as $key1 => $value1) {
|
|
||||||
$html .= '
|
|
||||||
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
|
||||||
}
|
|
||||||
$html .= '<br>
|
|
||||||
<a href="https://vercel.com/account/tokens" target="_blank">' . getconstStr('Create') . ' token</a><br>
|
|
||||||
<label>Token:<input name="APIKey" type="password" placeholder="" value=""></label><br>';
|
|
||||||
$html .= '<br>
|
|
||||||
<label>Set admin password:<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>';
|
|
||||||
$html .= '
|
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
|
||||||
</form>
|
|
||||||
<div id="showerror"></div>
|
|
||||||
<script>
|
|
||||||
var nowtime= new Date();
|
|
||||||
var timezone = 0-nowtime.getTimezoneOffset()/60;
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie="timezone="+timezone+"; path=/; "+expires;
|
|
||||||
var errordiv = document.getElementById("showerror");
|
|
||||||
function changelanguage(str)
|
|
||||||
{
|
|
||||||
var expd = new Date();
|
|
||||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
|
||||||
var expires = "expires="+expd.toGMTString();
|
|
||||||
document.cookie=\'language=\'+str+\'; path=/; \'+expires;
|
|
||||||
location.href = location.href;
|
|
||||||
}
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.admin.value==\'\') {
|
|
||||||
alert(\'input admin\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (t.APIKey.value==\'\') {
|
|
||||||
alert(\'input Token\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
$title = getconstStr('SelectLanguage');
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (substr($_SERVER["host"], -10)=="vercel.app") {
|
|
||||||
$html .= '<a href="?install0">' . getconstStr('ClickInstall') . '</a>, ' . getconstStr('LogintoBind');
|
|
||||||
$html .= "<br>Remember: you MUST wait 30-60s after each operate / do some change, that make sure Vercel has done the building<br>" ;
|
|
||||||
} else {
|
|
||||||
$html.= "Please visit form *.vercel.app";
|
|
||||||
}
|
|
||||||
$title = 'Install';
|
|
||||||
return message($html, $title, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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"];
|
|
||||||
}
|
|
||||||
foreach ($envs as $key => $value) {
|
|
||||||
$response = null;
|
|
||||||
$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 . ", <br>" . $response . json_encode($response, JSON_PRETTY_PRINT) . "<br>";
|
|
||||||
if (!!$response && $response['stat']!=200) return $response['body'];
|
|
||||||
}
|
|
||||||
return VercelUpdate($appId, $token);
|
|
||||||
}
|
|
||||||
|
|
||||||
function VercelUpdate($appId, $token, $sourcePath = "")
|
|
||||||
{
|
|
||||||
if (checkBuilding($appId, $token)) return '{"error":{"message":"Another building is in progress."}}';
|
|
||||||
$url = "https://api.vercel.com/v13/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 . "<br>";
|
|
||||||
getEachFiles($file, $sourcePath);
|
|
||||||
$data["files"] = $file;
|
|
||||||
|
|
||||||
//echo json_encode($data, JSON_PRETTY_PRINT) . " ,data<br>";
|
|
||||||
$response = curl("POST", $url, json_encode($data), $header);
|
|
||||||
//echo json_encode($response, JSON_PRETTY_PRINT) . " ,res<br>";
|
|
||||||
$result = json_decode($response["body"], true);
|
|
||||||
$result['DplStatus'] = $result['id'];
|
|
||||||
return json_encode($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkBuilding($projectId, $token)
|
|
||||||
{
|
|
||||||
$r = 0;
|
|
||||||
$url = "https://api.vercel.com/v6/deployments/?projectId=" . $projectId;
|
|
||||||
$header["Authorization"] = "Bearer " . $token;
|
|
||||||
$header["Content-Type"] = "application/json";
|
|
||||||
$response = curl("GET", $url, '', $header);
|
|
||||||
//echo json_encode($response, JSON_PRETTY_PRINT) . " ,res<br>";
|
|
||||||
$result = json_decode($response["body"], true);
|
|
||||||
foreach ( $result['deployments'] as $deployment ) {
|
|
||||||
if ($deployment['state']!=="READY") $r++;
|
|
||||||
}
|
|
||||||
return $r;
|
|
||||||
//if ($r===0) return true;
|
|
||||||
//else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getEachFiles(&$file, $base, $path = "")
|
|
||||||
{
|
|
||||||
//if (substr($base, -1)=="/") $base = substr($base, 0, -1);
|
|
||||||
//if (substr($path, -1)=="/") $path = substr($path, 0, -1);
|
|
||||||
$handler=opendir(path_format($base . "/" . $path));
|
|
||||||
while($filename=readdir($handler)) {
|
|
||||||
if($filename != '.' && $filename != '..' && $filename != '.git'){
|
|
||||||
$fromfile = path_format($base . "/" . $path . "/" . $filename);
|
|
||||||
//echo $fromfile . "<br>";
|
|
||||||
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);
|
|
||||||
$file[] = $tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir($handler);
|
|
||||||
|
|
||||||
return json_encode( [ 'response' => 'success' ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error($response)
|
|
||||||
{
|
|
||||||
return isset($response['error']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function api_error_msg($response)
|
|
||||||
{
|
|
||||||
return $response['error']['code'] . '<br>
|
|
||||||
' . $response['error']['message'] . '<br>
|
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setConfigResponse($response)
|
|
||||||
{
|
|
||||||
return json_decode($response, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
|
||||||
{
|
|
||||||
$tmppath = '/tmp';
|
|
||||||
|
|
||||||
if ($GitSource=='Github') {
|
|
||||||
// 从github下载对应tar.gz,并解压
|
|
||||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
|
||||||
} elseif ($GitSource=='HITGitlab') {
|
|
||||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
|
||||||
} else return json_encode(['error'=>['code'=>'Git Source input Error!']]);
|
|
||||||
|
|
||||||
$tarfile = $tmppath . '/github.tar.gz';
|
|
||||||
file_put_contents($tarfile, file_get_contents($url));
|
|
||||||
$phar = new PharData($tarfile);
|
|
||||||
$html = $phar->extractTo($tmppath, null, true);//路径 要解压的文件 是否覆盖
|
|
||||||
unlink($tarfile);
|
|
||||||
|
|
||||||
// 获取解压出的目录名
|
|
||||||
$outPath = findIndexPath($tmppath);
|
|
||||||
|
|
||||||
if ($outPath=='') return '{"error":{"message":"no outpath"}}';
|
|
||||||
$name = $project . 'CODE';
|
|
||||||
mkdir($tmppath . "/" . $name, 0777, 1);
|
|
||||||
rename($outPath, $tmppath . "/" . $name . '/api');
|
|
||||||
$outPath = $tmppath . "/" . $name;
|
|
||||||
//echo $outPath . "<br>";
|
|
||||||
//error_log1($outPath);
|
|
||||||
|
|
||||||
return VercelUpdate(getConfig('HerokuappId'), getConfig('APIKey'), $outPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
function WaitFunction($deployid) {
|
|
||||||
if ($buildId=='1') {
|
|
||||||
$tmp['stat'] = 400;
|
|
||||||
$tmp['body'] = 'id must provided.';
|
|
||||||
return $tmp;
|
|
||||||
}
|
|
||||||
$header["Authorization"] = "Bearer " . getConfig('APIKey');
|
|
||||||
$header["Content-Type"] = "application/json";
|
|
||||||
$url = "https://api.vercel.com/v11/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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeAuthKey() {
|
|
||||||
if ($_POST['APIKey']!='') {
|
|
||||||
$APIKey = $_POST['APIKey'];
|
|
||||||
$tmp['APIKey'] = $APIKey;
|
|
||||||
$response = json_decode(setVercelConfig($tmp, getConfig('HerokuappId'), $APIKey), true);
|
|
||||||
if (api_error($response)) {
|
|
||||||
$html = api_error_msg($response);
|
|
||||||
$title = 'Error';
|
|
||||||
return message($html, $title, 400);
|
|
||||||
} else {
|
|
||||||
$html = getconstStr('Success') . '
|
|
||||||
<script>
|
|
||||||
var status = "' . $response['DplStatus'] . '";
|
|
||||||
var i = 0;
|
|
||||||
var uploadList = setInterval(function(){
|
|
||||||
if (document.getElementById("dis").style.display=="none") {
|
|
||||||
console.log(i++);
|
|
||||||
} else {
|
|
||||||
clearInterval(uploadList);
|
|
||||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
</script>';
|
|
||||||
return message($html, $title, 201, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$html = '
|
|
||||||
<form action="" method="post" onsubmit="return notnull(this);">
|
|
||||||
<a href="https://vercel.com/account/tokens" target="_blank">' . getconstStr('Create') . ' token</a><br>
|
|
||||||
<label>Token:<input name="APIKey" type="password" placeholder="" value=""></label><br>
|
|
||||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
function notnull(t)
|
|
||||||
{
|
|
||||||
if (t.APIKey.value==\'\') {
|
|
||||||
alert(\'Input Token\');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>';
|
|
||||||
return message($html, 'Change platform Auth token or key', 200);
|
|
||||||
}
|
|
Loading…
Reference in New Issue