scf get region

This commit is contained in:
qkqpttgf 2020-07-29 13:40:14 +08:00 committed by GitHub
parent 097254f084
commit a3b1430041
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 48 deletions

View File

@ -33,20 +33,15 @@ 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'] = getenv('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'].'/';
$_SERVER['Region'] = getenv('Region');
if ($_SERVER['Region'] == '') {
$_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['Region'] = getenv('Region');
$path = substr($event['path'], strlen($event['requestContext']['path']));
}
if (substr($path,-1)=='/') $path=substr($path,0,-1);
@ -154,27 +149,24 @@ function install()
<meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
}
if ($_GET['install1']) {
//if ($_POST['admin']!='') {
//$tmp['language'] = $_POST['language'];
$tmp['Region'] = $_POST['Region'];
$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 = json_decode(SetbaseConfig($tmp, $_SERVER['function_name'], $_POST['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
if (api_error($response)) {
$html = api_error_msg($response);
$title = 'Error';
return message($html, $title, 201);
} else {
$html .= '
$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 = 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 {
$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').'">
@ -189,10 +181,9 @@ function install()
return true;
}
</script>';
$title = getconstStr('SetAdminPassword');
return message($html, $title, 201);
}
//}
$title = getconstStr('SetAdminPassword');
return message($html, $title, 201);
}
}
if ($_GET['install0']) {
$html .= '
@ -207,21 +198,6 @@ language:<br>';
<label>SecretId:<input name="SecretId" type="text" placeholder="" size=""></label><br>
<label>SecretKey:<input name="SecretKey" type="text" placeholder="" size=""></label><br>';
$html .= '
<select class="changelanguage" name="Region">
<option value="">选择区域</option>
<option value="ap-beijing">华北地区(北京)</option>
<option value="ap-chengdu">西南地区(成都)</option>
<option value="ap-guangzhou">华南地区(广州)</option>
<option value="ap-guangzhou-open">华南地区(广州Open)</option>
<option value="ap-hongkong">港澳台地区(中国香港)</option>
<option value="ap-mumbai">亚太南部(孟买)</option>
<option value="ap-shanghai">华东地区(上海)</option>
<option value="ap-shanghai-fsi">华东地区(上海金融)</option>
<option value="ap-singapore">亚太东南(新加坡)</option>
<option value="ap-tokyo">亚太东北(东京)</option>
<option value="na-siliconvalley">美国西部(硅谷)</option>
<option value="na-toronto">北美地区(多伦多)</option>
</select>(腾讯几个月了还不做出来,只能先弄选择了)<br>
<input type="submit" value="'.getconstStr('Submit').'">
</form>
<script>
@ -325,7 +301,7 @@ function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId
$tmp_env[$key1] = $value1;
}
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
$tmp_env['Region'] = $Region;
//$tmp_env['Region'] = $Region;
ksort($tmp_env);
$i = 0;
@ -366,7 +342,7 @@ function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $S
$tmp_env[$key1] = $value1;
}
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
$tmp_env['Region'] = $Region;
//$tmp_env['Region'] = $Region;
ksort($tmp_env);
$i = 0;