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['function_name'] = $context['function_name'];
$host_name = $event['headers']['host'];
$serviceId = $event['requestContext']['serviceId'];
$public_path = path_format(getenv('public_path'));
$private_path = path_format(getenv('private_path'));
$domain_path = getenv('domain_path');
$tmp_path='';
if ($domain_path!='') {
$tmp = explode("|",$domain_path);
foreach ($tmp as $multidomain_paths){
$pos = strpos($multidomain_paths,":");
$tmp_path = path_format(substr($multidomain_paths,$pos+1));
if (substr($multidomain_paths,0,$pos)==$host_name) $private_path=$tmp_path;
}
}
// public_path is not Parent Dir of private_path. public_path 不能是 private_path 的上级目录。
if ($tmp_path!='') if ($public_path == substr($tmp_path,0,strlen($public_path))) $public_path=$tmp_path;
if ($public_path == substr($private_path,0,strlen($public_path))) $public_path=$private_path;
if ( $serviceId === substr($host_name,0,strlen($serviceId)) ) {
$_SERVER['base_path'] = '/'.$event['requestContext']['stage'].'/'.$_SERVER['function_name'].'/';
$_SERVER['list_path'] = $public_path;
$_SERVER['Region'] = substr($host_name, strpos($host_name, '.')+1);
$_SERVER['Region'] = substr($_SERVER['Region'], 0, strpos($_SERVER['Region'], '.'));
$path = substr($event['path'], strlen('/'.$_SERVER['function_name'].'/'));
} else {
$_SERVER['base_path'] = $event['requestContext']['path'];
$_SERVER['list_path'] = $private_path;
$_SERVER['Region'] = getenv('Region');
$path = substr($event['path'], strlen($event['requestContext']['path']));
}
if (substr($path,-1)=='/') $path=substr($path,0,-1);
if (empty($_SERVER['list_path'])) {
$_SERVER['list_path'] = '/';
} else {
$_SERVER['list_path'] = spurlencode($_SERVER['list_path'],'/') ;
}
$_SERVER['is_imgup_path'] = is_imgup_path($path);
$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
$_SERVER['REMOTE_ADDR'] = $event['requestContext']['sourceIp'];
$_SERVER['ajax']=0;
if ($event['headers']['x-requested-with']=='XMLHttpRequest') {
$_SERVER['ajax']=1;
}
/*
$referer = $event['headers']['referer'];
$tmpurl = substr($referer,strpos($referer,'//')+2);
$refererhost = substr($tmpurl,0,strpos($tmpurl,'/'));
if ($refererhost==$host_name) {
// Guest only upload from this site. 仅游客上传用,referer不对就空值,无法上传
$_SERVER['current_url'] = substr($referer,0,strpos($referer,'//')) . '//' . $host_name.$_SERVER['PHP_SELF'];
} else {
$_SERVER['current_url'] = '';
}
*/
return $path;
}
function get_refresh_token($function_name, $Region, $Namespace)
{
global $constStr;
$url = path_format($_SERVER['PHP_SELF'] . '/');
if ($_GET['authorization_code'] && isset($_GET['code'])) {
$ret = json_decode(curl_request($_SERVER['oauth_url'] . 'token', 'client_id=' . $_SERVER['client_id'] .'&client_secret=' . $_SERVER['client_secret'] . '&grant_type=authorization_code&requested_token_use=on_behalf_of&redirect_uri=' . $_SERVER['redirect_uri'] .'&code=' . $_GET['code']), true);
if (isset($ret['refresh_token'])) {
$tmptoken=$ret['refresh_token'];
$str = '
refresh_token :
';
for ($i=1;strlen($tmptoken)>0;$i++) {
$t['t' . $i] = substr($tmptoken,0,128);
$str .= '
t' . $i . ':
';
$tmptoken=substr($tmptoken,128);
}
$str .= '
Add t1-t'.--$i.' to environments.
';
if (getenv('SecretId')!='' && getenv('SecretKey')!='') {
echo updataEnvironment($t, $function_name, $Region, $Namespace);
$str .= '
';
}
return message($str, $constStr['WaitJumpIndex'][$constStr['language']]);
}
return message('
' . json_encode($ret, JSON_PRETTY_PRINT) . '', 500); } if ($_GET['install2']) { if (getenv('Onedrive_ver')=='MS' || getenv('Onedrive_ver')=='CN' || getenv('Onedrive_ver')=='MSC') { return message(' '.$constStr['JumptoOffice'][$constStr['language']].' ', $constStr['Wait'][$constStr['language']].' 1s', 201); } } if ($_GET['install1']) { // echo $_POST['Onedrive_ver']; if ($_POST['Onedrive_ver']=='MS' || $_POST['Onedrive_ver']=='CN' || $_POST['Onedrive_ver']=='MSC') { $tmp['Onedrive_ver'] = $_POST['Onedrive_ver']; $tmp['language'] = $_COOKIE['language']; $tmp['client_id'] = $_POST['client_id']; $tmp['client_secret'] = equal_replace(base64_encode($_POST['client_secret'])); $response = json_decode(updataEnvironment($tmp, $_SERVER['function_name'], $_SERVER['Region'], $Namespace), true)['Response']; sleep(2); $title = $constStr['MayinEnv'][$constStr['language']]; $html = $constStr['Wait'][$constStr['language']] . ' 3s'; if (isset($response['Error'])) { $html = $response['Error']['Code'] . '