diff --git a/function/common.php b/function/common.php
index 6470224..12b62d1 100644
--- a/function/common.php
+++ b/function/common.php
@@ -3,14 +3,14 @@
function getcache($str)
{
$cache = null;
- $cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'Onedrive');
+ $cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'/Onedrive/'.$_SERVER['disktag']);
return $cache->fetch($str);
}
function savecache($key, $value, $exp = 3300)
{
$cache = null;
- $cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'Onedrive');
+ $cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'/Onedrive/'.$_SERVER['disktag']);
$cache->save($key, $value, $exp);
}
@@ -375,33 +375,31 @@ function main($path)
{
global $exts;
global $constStr;
- config_oauth();
+echo 'main.enterpath:'.$path.'
+';
$constStr['language'] = $_COOKIE['language'];
if ($constStr['language']=='') $constStr['language'] = getConfig('language');
if ($constStr['language']=='') $constStr['language'] = 'en-us';
+ $_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
+ $disktags = explode("|",getConfig('disktag'));
+ echo 'count$disk:'.count($disktags);
+ if (count($disktags)>1) {
+ if ($path=='/') return output('', 302, [ 'Location' => path_format($_SERVER['PHP_SELF'].'/'.$disktags[0]) ]);
+ $_SERVER['disktag'] = $path;
+ $pos = strpos($path, '/');
+ if ($pos>1) $_SERVER['disktag'] = substr($path, 0, $pos);
+ $path = substr($path, strlen('/'.$_SERVER['disktag']));
+ } else $_SERVER['disktag'] = $disktags[0];
+ echo 'main.disktag:'.$_SERVER['disktag'].',path:'.$path.'
+';
+ $_SERVER['base_disk_path'] = $_SERVER['base_path'];
+ if ($_SERVER['disktag']!='') $_SERVER['base_disk_path'] .= '/' . $_SERVER['disktag'];
$_SERVER['list_path'] = getListpath($_SERVER['HTTP_HOST']);
if ($_SERVER['list_path']=='') $_SERVER['list_path'] = '/';
$_SERVER['is_guestup_path'] = is_guestup_path($path);
- $_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
$_SERVER['ajax']=0;
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) if ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') $_SERVER['ajax']=1;
- $refresh_token = getConfig('refresh_token');
- if (!$refresh_token) return get_refresh_token();
-
- if (!($_SERVER['access_token'] = getcache('access_token'))) {
- $response = curl_request( $_SERVER['oauth_url'] . 'token', 'client_id='. $_SERVER['client_id'] .'&client_secret='. $_SERVER['client_secret'] .'&grant_type=refresh_token&requested_token_use=on_behalf_of&refresh_token=' . $refresh_token );
- if ($response['stat']==200) $ret = json_decode($response['body'], true);
- if (!isset($ret['access_token'])) {
- error_log('failed to get access_token. response' . json_encode($ret));
- throw new Exception($response['stat'].'failed to get access_token.'.$response['body']);
- }
- error_log('Get access token:'.json_encode($ret, JSON_PRETTY_PRINT));
- $_SERVER['access_token'] = $ret['access_token'];
- savecache('access_token', $_SERVER['access_token'], $ret['expires_in'] - 300);
- if (time()>getConfig('token_expires')) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+30*24*60*60 ]);
- }
-
if (getConfig('adminloginpage')=='') {
$adminloginpage = 'admin';
} else {
@@ -436,6 +434,28 @@ function main($path)
$url = path_format($_SERVER['PHP_SELF'] . '/');
return output('', 302, [ 'Location' => $url ]);
}
+
+ if (getConfig('admin')=='') return install();
+ config_oauth();
+ if ($_SERVER['admin']) if ($_GET['AddDisk']||$_GET['authorization_code']) return get_refresh_token();
+ $refresh_token = getConfig('refresh_token');
+ //if (!$refresh_token) return get_refresh_token();
+ if (!$refresh_token) {
+ return render_list();
+ } else {
+ if (!($_SERVER['access_token'] = getcache('access_token'))) {
+ $response = curl_request( $_SERVER['oauth_url'] . 'token', 'client_id='. $_SERVER['client_id'] .'&client_secret='. $_SERVER['client_secret'] .'&grant_type=refresh_token&requested_token_use=on_behalf_of&refresh_token=' . $refresh_token );
+ if ($response['stat']==200) $ret = json_decode($response['body'], true);
+ if (!isset($ret['access_token'])) {
+ error_log('failed to get access_token. response' . json_encode($ret));
+ throw new Exception($response['stat'].'failed to get access_token.'.$response['body']);
+ }
+ error_log('Get access token:'.json_encode($ret, JSON_PRETTY_PRINT));
+ $_SERVER['access_token'] = $ret['access_token'];
+ savecache('access_token', $_SERVER['access_token'], $ret['expires_in'] - 300);
+ if (time()>getConfig('token_expires')) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+30*24*60*60 ]);
+ }
+
$_SERVER['retry'] = 0;
if ($_SERVER['ajax']) {
@@ -489,7 +509,8 @@ function main($path)
if ( isset($files['folder']) || isset($files['file']) ) {
return render_list($path, $files);
} else {
- return message('
' . $files['error']['message'] . '
'.getconstStr('Back').'', $files['error']['code'], $files['error']['stat']);
+ return message(''.getconstStr('Back').getconstStr('Home').'' . $files['error']['message'] . '
'.getconstStr('Back').'', $files['error']['code'], $files['error']['stat']);
+ }
}
}
@@ -842,7 +863,7 @@ function fetch_files_children($files, $path, $page)
return $files;
}
-function render_list($path, $files)
+function render_list($path = '', $files = '')
{
global $exts;
global $constStr;
diff --git a/function/normal.php b/function/normal.php
index cad76ed..9c9bd42 100644
--- a/function/normal.php
+++ b/function/normal.php
@@ -36,11 +36,75 @@ function getGET()
}
}
+function getConfig($str, $disktag = '')
+{
+ global $innerEnv;
+ //include 'config.php';
+ if ($disktag=='') $disktag = $_SERVER['disktag'];
+ $s = file_get_contents('config.php');
+ $configs = substr($s, 18, -2);
+ if ($configs!='') {
+ $envs = json_decode($configs, true);
+ if (in_array($str, $innerEnv)) {
+ if (isset($envs[$disktag][$str])) return $envs[$disktag][$str];
+ } else if (isset($envs[$str])) return $envs[$str];
+ }
+ return '';
+}
+
+function setConfig($arr, $disktag = '')
+{
+ global $innerEnv;
+ if ($disktag=='') $disktag = $_SERVER['disktag'];
+ //include 'config.php';
+ $s = file_get_contents('config.php');
+ $configs = substr($s, 18, -2);
+ if ($configs!='') $envs = json_decode($configs, true);
+ $disktags = explode("|",getConfig('disktag'));
+ //$indisk = 0;
+ $oparetdisk = 0;
+ foreach ($arr as $k => $v) {
+ if (in_array($k, $innerEnv)) {
+ $envs[$disktag][$k] = $v;
+ /*$diskconfig[$k] = $v;
+ $indisk = 1;*/
+ } elseif ($k=='disktag_add') {
+ array_push($disktags, $v);
+ $oparetdisk = 1;
+ } elseif ($k=='disktag_del') {
+ $disktags = array_diff($disktags, [ $v ]);
+ $envs[$v] = '';
+ $oparetdisk = 1;
+ } else {
+ $envs[$k] = $v;
+ }
+ }
+ /*if ($indisk) {
+ $diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
+ ksort($diskconfig);
+ $tmp[$disktag] = json_encode($diskconfig);
+ }*/
+ if ($oparetdisk) {
+ foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
+ $envs['disktag'] = substr($disktag_s, 0, -1);
+ }
+ $envs = array_filter($envs, 'array_value_isnot_null');
+ ksort($envs);
+ //echo ''. json_encode($envs, JSON_PRETTY_PRINT).'
';
+ $prestr = '';
- setConfig([ 'refresh_token' => $tmptoken, 'token_expires' => time()+30*24*60*60 ]);
+ setConfig([ 'refresh_token' => $tmptoken, 'token_expires' => time()+30*24*60*60 ], $_COOKIE['disktag']);
savecache('access_token', $ret['access_token'], $ret['expires_in'] - 60);
$str .= '
- ';
+ ';
return message($str, getconstStr('WaitJumpIndex'));
}
return message('' . $tmp['body'] . '
', $tmp['stat']);
//return message('' . json_encode($ret, JSON_PRETTY_PRINT) . '
', 500);
}
- if ($_GET['install3']) {
+ if ($_GET['install1']) {
+ $_SERVER['disk_oprating'] = $_COOKIE['disktag'];
+ $_SERVER['disktag'] = $_COOKIE['disktag'];
+ config_oauth();
if (getConfig('Onedrive_ver')=='MS' || getConfig('Onedrive_ver')=='CN' || getConfig('Onedrive_ver')=='MSC') {
return message('
'.getconstStr('JumptoOffice').'
@@ -88,17 +156,19 @@ function get_refresh_token()
', getconstStr('Wait').' 1s', 201);
}
}
- if ($_GET['install2']) {
- // echo $_POST['Onedrive_ver'];
- if ($_POST['Onedrive_ver']=='MS' || $_POST['Onedrive_ver']=='CN' || $_POST['Onedrive_ver']=='MSC') {
+ if ($_GET['install0']) {
+ if ($_POST['disktag_add']!='' && ($_POST['Onedrive_ver']=='MS' || $_POST['Onedrive_ver']=='CN' || $_POST['Onedrive_ver']=='MSC')) {
+ $_SERVER['disktag'] = $_COOKIE['disktag'];
+ $tmp['disktag_add'] = $_POST['disktag_add'];
+ $tmp['diskname'] = $_POST['diskname'];
$tmp['Onedrive_ver'] = $_POST['Onedrive_ver'];
if ($_POST['Onedrive_ver']=='MSC') {
$tmp['client_id'] = $_POST['client_id'];
$tmp['client_secret'] = $_POST['client_secret'];
}
- $response = setConfig($tmp);
+ $response = setConfig($tmp, $_COOKIE['disktag']);
$title = getconstStr('MayinEnv');
- $html = getconstStr('Wait') . ' 3s';
+ $html = getconstStr('Wait') . ' 3s';
if (!$response) {
$html = $response . '
Can not write config to file.
@@ -108,20 +178,17 @@ Can not write config to file.
return message($html, $title, 201);
}
}
- if ($_GET['install1']) {
- if ($_POST['admin']!='') {
- $tmp['admin'] = $_POST['admin'];
- $tmp['language'] = $_POST['language'];
- $response = setConfig($tmp);
- if ($response) {
- if ($constStr['language']!='zh-cn') {
- $linklang='en-us';
- } else $linklang='zh-cn';
- $ru = "https://developer.microsoft.com/".$linklang."/graph/quick-start?appID=_appId_&appName=_appName_&redirectUrl=".$_SERVER['redirect_uri']."&platform=option-php";
- $deepLink = "/quickstart/graphIO?publicClientSupport=false&appName=OneManager&redirectUrl=".$_SERVER['redirect_uri']."&allowImplicitFlow=false&ru=".urlencode($ru);
- $app_url = "https://apps.dev.microsoft.com/?deepLink=".urlencode($deepLink);
- $html = '
- ';
- $title = 'Install';
- } else {
- $html = $response . '
+
+ ';
+ $title = 'Bind Onedrive';
+ return message($html, $title, 201);
+}
+
+function install()
+{
+ global $constStr;
+ if ($_GET['install1']) {
+ if ($_POST['admin']!='') {
+ $tmp['admin'] = $_POST['admin'];
+ $tmp['language'] = $_POST['language'];
+ $response = setConfig($tmp);
+ if (!$response) {
+ $html = $response . '
Can not write config to file.
';
- $title = 'Error';
- }
- return message($html, $title, 201);
+ $title = 'Error';
+ return message($html, $title, 201);
+ } else {
+ return output('Jump', 302);
+ }
}
}
if ($_GET['install0']) {
@@ -157,14 +254,19 @@ run Writeable.sh.';
return message($html, $title, 201);
}
$html .= '
-
';
$title = getconstStr('SelectLanguage');
return message($html, $title, 201);
}
- $html .= 'refresh_token not exist, click to install.';
+ $html .= 'Click to install the project, then login and bind your onedrive.';
$title = 'Error';
return message($html, $title, 201);
}
@@ -203,8 +315,7 @@ function ConfigWriteable()
function RewriteEngineOn()
{
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
- $tmpurl = $http_type . $_SERVER['SERVER_NAME'];
- //if $_SERVER['SERVER_PORT']
+ $tmpurl = $http_type . $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'];
$tmpurl .= path_format($_SERVER['base_path'] . '/config.php');
$tmp = curl_request($tmpurl);
if ($tmp['stat']==200) return false;
@@ -212,65 +323,6 @@ function RewriteEngineOn()
return false;
}
-function getConfig($str)
-{
- //include 'config.php';
- $s = file_get_contents('config.php');
- $configs = substr($s, 18, -2);
- if ($configs!='') {
- $envs = json_decode($configs, true);
- if (isset($envs[$str])) return $envs[$str];
- }
- return '';
- /*
- if (!class_exists('mydbreader')) {
- class mydbreader extends SQLite3
- {
- function __construct()
- {
- $this->open( __DIR__ .'/.ht.db');
- }
- }
- }
- $db = new mydbreader();
- if(!$db){
- echo $db->lastErrorMsg();
- } else {
- //echo "Opened database successfully
\n";
- $id=rand(1,309);
- $sql="select * from config where id=".$str.";";
- $ret = $db->query($sql);
- if(!$ret){
- echo $db->lastErrorMsg();
- } else {
- $row = $ret->fetchArray(SQLITE3_ASSOC);
- $value1 = $row['value'];
- }
- $db->close();
- }
- return $value1;
- */
-}
-
-function setConfig($arr)
-{
- //include 'config.php';
- $s = file_get_contents('config.php');
- $configs = substr($s, 18, -2);
- if ($configs!='') $envs = json_decode($configs, true);
- foreach ($arr as $k1 => $v1) {
- $envs[$k1] = $v1;
- }
- $envs = array_filter($envs, 'array_value_isnot_null');
- ksort($envs);
- //echo ''. json_encode($envs, JSON_PRETTY_PRINT).'
';
- $prestr = ' $v) {
+ if (in_array($k, $innerEnv)) {
+ $diskconfig[$k] = $v;
+ $indisk = 1;
+ } elseif ($k=='disktag_add') {
+ array_push($disktags, $v);
+ $oparetdisk = 1;
+ } elseif ($k=='disktag_del') {
+ $disktags = array_diff($disktags, [ $v ]);
+ $tmp[$v] = '';
+ $oparetdisk = 1;
+ } else {
+ $tmp[$k] = $v;
+ }
+ }
+ if ($indisk) {
+ $diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
+ ksort($diskconfig);
+ $tmp[$disktag] = json_encode($diskconfig);
+ }
+ if ($oparetdisk) {
+ foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
+ $tmp['disktag'] = substr($disktag_s, 0, -1);
+ }
+ echo '正式设置:'.json_encode($tmp,JSON_PRETTY_PRINT).'
+';
+ return updateEnvironment($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'));
+}
+
+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 get_refresh_token()
@@ -72,6 +145,8 @@ function get_refresh_token()
global $constStr;
$url = path_format($_SERVER['PHP_SELF'] . '/');
if ($_GET['authorization_code'] && isset($_GET['code'])) {
+ $_SERVER['disktag'] = $_COOKIE['disktag'];
+ config_oauth();
$tmp = 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']);
if ($tmp['stat']==200) $ret = json_decode($tmp['body'], true);
if (isset($ret['refresh_token'])) {
@@ -95,8 +170,9 @@ function get_refresh_token()
texta[i].style.height = texta[i].scrollHeight + \'px\';
}
document.cookie=\'language=; path=/\';
+ document.cookie=\'disktag=; path=/\';
';
- setConfig([ 'refresh_token' => $tmptoken, 'token_expires' => time()+30*24*60*60 ]);
+ setConfig([ 'refresh_token' => $tmptoken, 'token_expires' => time()+30*24*60*60 ], $_COOKIE['disktag']);
savecache('access_token', $ret['access_token'], $ret['expires_in'] - 60);
$trynum = 0;
while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']!='Active' ) echo '
@@ -108,7 +184,10 @@ function get_refresh_token()
return message('' . $tmp['body'] . '
', $tmp['stat']);
//return message('' . json_encode($ret, JSON_PRETTY_PRINT) . '
', 500);
}
- if ($_GET['install3']) {
+ if ($_GET['install1']) {
+ $_SERVER['disk_oprating'] = $_COOKIE['disktag'];
+ $_SERVER['disktag'] = $_COOKIE['disktag'];
+ config_oauth();
if (getConfig('Onedrive_ver')=='MS' || getConfig('Onedrive_ver')=='CN' || getConfig('Onedrive_ver')=='MSC') {
return message('
'.getconstStr('JumptoOffice').'
@@ -122,17 +201,19 @@ function get_refresh_token()
', getconstStr('Wait').' 1s', 201);
}
}
- if ($_GET['install2']) {
- // echo $_POST['Onedrive_ver'];
- if ($_POST['Onedrive_ver']=='MS' || $_POST['Onedrive_ver']=='CN' || $_POST['Onedrive_ver']=='MSC') {
+ if ($_GET['install0']) {
+ if ($_POST['disktag_add']!='' && ($_POST['Onedrive_ver']=='MS' || $_POST['Onedrive_ver']=='CN' || $_POST['Onedrive_ver']=='MSC')) {
+ $_SERVER['disktag'] = $_COOKIE['disktag'];
+ $tmp['disktag_add'] = $_POST['disktag_add'];
+ $tmp['diskname'] = $_POST['diskname'];
$tmp['Onedrive_ver'] = $_POST['Onedrive_ver'];
if ($_POST['Onedrive_ver']=='MSC') {
$tmp['client_id'] = $_POST['client_id'];
$tmp['client_secret'] = $_POST['client_secret'];
}
- $response = json_decode( setConfig($tmp), true )['Response'];
+ $response = json_decode( setConfig($tmp, $_COOKIE['disktag']), true )['Response'];
$title = getconstStr('MayinEnv');
- $html = getconstStr('Wait') . ' 3s';
+ $html = getconstStr('Wait') . ' 3s';
if (isset($response['Error'])) {
$html = $response['Error']['Code'] . '
' . $response['Error']['Message'] . '
@@ -145,6 +226,53 @@ namespace:' . $_SERVER['namespace'] . '
return message($html, $title, 201);
}
}
+
+ if ($constStr['language']!='zh-cn') {
+ $linklang='en-us';
+ } else $linklang='zh-cn';
+ $ru = "https://developer.microsoft.com/".$linklang."/graph/quick-start?appID=_appId_&appName=_appName_&redirectUrl=".$_SERVER['redirect_uri']."&platform=option-php";
+ $deepLink = "/quickstart/graphIO?publicClientSupport=false&appName=OneManager&redirectUrl=".$_SERVER['redirect_uri']."&allowImplicitFlow=false&ru=".urlencode($ru);
+ $app_url = "https://apps.dev.microsoft.com/?deepLink=".urlencode($deepLink);
+ $html = '
+
+ ';
+ $title = 'Bind Onedrive';
+ return message($html, $title, 201);
+}
+
+function install()
+{
+ global $constStr;
if ($_GET['install1']) {
if ($_POST['admin']!='') {
$tmp['admin'] = $_POST['admin'];
@@ -159,8 +287,7 @@ namespace:' . $_SERVER['namespace'] . '
$SecretKey = $_POST['SecretKey'];
$tmp['SecretKey'] = $SecretKey;
}
- echo SetbaseConfig($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey);
- $response = json_decode( updateEnvironment($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
+ $response = json_decode(SetbaseConfig($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
if (isset($response['Error'])) {
$html = $response['Error']['Code'] . '
' . $response['Error']['Message'] . '
@@ -170,34 +297,15 @@ namespace:' . $_SERVER['namespace'] . '
';
$title = 'Error';
} else {
- if (needUpdate()) {
- $trynum = 0;
- while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey),true)['Response']['Status']!='Active' ) echo '
+ $trynum = 0;
+ while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey),true)['Response']['Status']!='Active' ) echo '
'.++$trynum;
+ //$response = json_decode( updateEnvironment($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
+ if (needUpdate()) {
updateProgram($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey);
return message('update to github version, reinstall.', 'Program updating', 201);
}
- if ($constStr['language']!='zh-cn') {
- $linklang='en-us';
- } else $linklang='zh-cn';
- $ru = "https://developer.microsoft.com/".$linklang."/graph/quick-start?appID=_appId_&appName=_appName_&redirectUrl=".$_SERVER['redirect_uri']."&platform=option-php";
- $deepLink = "/quickstart/graphIO?publicClientSupport=false&appName=OneManager&redirectUrl=".$_SERVER['redirect_uri']."&allowImplicitFlow=false&ru=".urlencode($ru);
- $app_url = "https://apps.dev.microsoft.com/?deepLink=".urlencode($deepLink);
- $html = '
- ';
- $title = 'Install';
+ return output('Jump', 302);
}
return message($html, $title, 201);
}
@@ -215,7 +323,7 @@ language:
';
';
$html .= '
-
';
+
';
$html .= '
@@ -247,7 +355,7 @@ language:
';
$title = getconstStr('SelectLanguage');
return message($html, $title, 201);
}
- $html .= 'refresh_token not exist, click to install.';
+ $html .= 'Click to install the project, then login and bind your onedrive.';
$title = 'Error';
return message($html, $title, 201);
}
@@ -305,9 +413,7 @@ function getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $Secret
function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
{
//print_r($Envs);
- $trynum = 0;
- while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey),true)['Response']['Status']!='Active' ) echo '
-'.++$trynum;
+ 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) {
@@ -343,15 +449,34 @@ function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
}
-function SetbaseConfig($function_name, $Region, $Namespace, $SecretId, $SecretKey)
+function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
{
+ echo json_encode($Envs,JSON_PRETTY_PRINT);
+ $trynum = 0;
+ while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey),true)['Response']['Status']!='Active' ) echo '
+'.++$trynum;
+ //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['Description'] = 'Onedrive index & manager in SCF.';
- $tmpdata['MemorySize'] = 64;
- $tmpdata['Timeout'] = 30;
$tmpdata['Namespace'] = $Namespace;
$tmpdata['Nonce'] = time();
$tmpdata['Region'] = $Region;
@@ -359,7 +484,11 @@ function SetbaseConfig($function_name, $Region, $Namespace, $SecretId, $SecretKe
$tmpdata['Timestamp'] = time();
$tmpdata['Token'] = '';
$tmpdata['Version'] = '2018-04-16';
+ $tmpdata['Description'] = 'Onedrive index and manager in 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));
@@ -367,6 +496,7 @@ function SetbaseConfig($function_name, $Region, $Namespace, $SecretId, $SecretKe
function updateProgram($function_name, $Region, $Namespace, $SecretId, $SecretKey)
{
+ WaitSCFStat();
$meth = 'POST';
$host = 'scf.tencentcloudapi.com';
$tmpdata['Action'] = 'UpdateFunctionCode';
@@ -391,13 +521,10 @@ function updateProgram($function_name, $Region, $Namespace, $SecretId, $SecretKe
function EnvOpt($function_name, $needUpdate = 0)
{
global $constStr;
- $constEnv = [
- //'admin',
- 'adminloginpage', 'domain_path', 'guestup_path', 'passfile',
- //'private_path',
- 'public_path', 'sitename', 'language', 'theme'
- ];
- asort($constEnv);
+ global $commonEnv;
+ global $innerEnv;
+ asort($commonEnv);
+ asort($innerEnv);
$html = 'OneManager '.getconstStr('Setup').'';
if ($_POST['updateProgram']==getconstStr('updateProgram')) {
$response = json_decode(updateProgram($function_name, $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')), true)['Response'];
@@ -410,9 +537,7 @@ namespace:' . $namespace . '
';
$title = 'Error';
} else {
- $trynum = 0;
- while( json_decode(getfunctioninfo($function_name, $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']!='Active' ) echo '
-'.++$trynum;
+ WaitSCFStat();
$html .= getconstStr('UpdateSuccess') . '
';
$title = getconstStr('Setup');
@@ -420,11 +545,12 @@ namespace:' . $namespace . '
return message($html, $title);
}
if ($_POST['submit1']) {
+ $_SERVER['disk_oprating'] = '';
foreach ($_POST as $k => $v) {
- if (in_array($k, $constEnv)) {
- //if (!(getConfig($k)==''&&$v==''))
+ if (in_array($k, $commonEnv)||in_array($k, $innerEnv)||$k=='disktag_del' || $k=='disktag_add') {
$tmp[$k] = $v;
}
+ if ($k == 'disk') $_SERVER['disk_oprating'] = $v;
}
/*if ($tmp['domain_path']!='') {
$tmp1 = explode("|",$tmp['domain_path']);
@@ -435,7 +561,7 @@ namespace:' . $namespace . '
}
$tmp['domain_path'] = $tmparr;
}*/
- $response = json_decode( setConfig($tmp), true )['Response'];
+ $response = json_decode( setConfig($tmp, $_SERVER['disk_oprating']), true )['Response'];
if (isset($response['Error'])) {
$html = $response['Error']['Code'] . '
' . $response['Error']['Message'] . '
@@ -445,11 +571,9 @@ namespace:' . $_SERVER['namespace'] . '
';
$title = 'Error';
} else {
- $trynum = 0;
- while( json_decode(getfunctioninfo($function_name, $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']!='Active' ) echo '
-'.++$trynum;
+ WaitSCFStat();
//sleep(3);
- $html .= '';
+ $html .= json_encode($response,JSON_PRETTY_PRINT).'';
$title = getconstStr('Setup');
}
return message($html, $title);
@@ -471,9 +595,12 @@ namespace:' . $_SERVER['namespace'] . '
$html .= getconstStr('NotNeedUpdate');
}
$html .= '
- ';
+ foreach (explode("|",getConfig('disktag')) as $disktag) {
+ if ($disktag!='') {
+ $html .= '
+ ';
+ }
+ }
+ $html .= '
+ Add Disk';
return message($html, getconstStr('Setup'));
}
diff --git a/index.php b/index.php
index cfe97a9..c53a035 100644
--- a/index.php
+++ b/index.php
@@ -46,7 +46,7 @@ function main_handler($event, $context)
unset($_SERVER);
GetGlobalVariable($event);
//echo ''. json_encode($_COOKIE, JSON_PRETTY_PRINT).'
';
- config_oauth();
$path = GetPathSetting($event, $context);
+
return main($path);
}
diff --git a/theme/classic.php b/theme/classic.php
index c2faf9d..41f191f 100644
--- a/theme/classic.php
+++ b/theme/classic.php
@@ -7,8 +7,8 @@
-
-
+
+
-
+'.json_encode($files, JSON_PRETTY_PRINT).''; ?>