From 2dc44a92d32345bbd906fb30539352c948fe47f5 Mon Sep 17 00:00:00 2001
From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com>
Date: Thu, 2 Apr 2020 11:17:45 +0800
Subject: [PATCH 01/12] fix scf update
---
platform/scf.php | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/platform/scf.php b/platform/scf.php
index f01e57a..8d71b54 100644
--- a/platform/scf.php
+++ b/platform/scf.php
@@ -370,13 +370,14 @@ function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $S
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
}
-function updateProgram($function_name, $Region, $Namespace, $SecretId, $SecretKey, $source = '')
+function updateProgram($function_name, $Region, $Namespace, $SecretId, $SecretKey, $source)
{
WaitSCFStat();
$meth = 'POST';
$host = 'scf.tencentcloudapi.com';
$tmpdata['Action'] = 'UpdateFunctionCode';
- $tmpdata['Code.GitUrl'] = $source;
+ $tmpdata['Code.GitUrl'] = $source['url'];
+ $tmpdata['Code.GitBranch'] = $source['branch'];
$tmpdata['CodeSource'] = 'Git';
$tmpdata['FunctionName'] = $function_name;
$tmpdata['Handler'] = 'index.main_handler';
@@ -410,8 +411,8 @@ namespace:' . $_SERVER['namespace'] . '
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
{
- //'https://github.com/qkqpttgf/OneManager-php/tree/v2-MultiDisk';
- $source = 'https://github.com/' . $auth . '/' . $project . '/tree/' . $branch;
+ $source['url'] = 'https://github.com/' . $auth . '/' . $project;
+ $source['branch'] = $branch;
return json_decode(updateProgram($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'), $source), true)['Response'];
}
From a6211d338232254c34328618a335a06cbd3bc1e7 Mon Sep 17 00:00:00 2001
From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com>
Date: Thu, 2 Apr 2020 16:27:45 +0800
Subject: [PATCH 02/12] Update update.sh
---
update.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 56 insertions(+), 2 deletions(-)
diff --git a/update.sh b/update.sh
index cb2c7ff..cc34856 100644
--- a/update.sh
+++ b/update.sh
@@ -1,12 +1,66 @@
#!bash
+if [ $# -eq 0 ]; then
+ echo "
+"$0" -i|u [-b branch]
+ i a new install with empty config.
+ u update use exist config.
+ b install the branch after parameter b, default master
+
+example:
+ "$0" -i
+ "$0" -u
+ "$0" -b master
+ "$0" -r -b master
+ "$0" -ib test
+"
+# exit
+ echo "###############
+0, new install
+1, update"
+ read -p "Input:" c
+ [ g"$c" == g"0" ] && install=1
+ [ g"$c" == g"1" ] && update=1
+fi
+
+i=0
+para[$i]=$0
+for av in "$@"
+do
+#echo $av
+ ((i++))
+ para[$i]=$av
+ if [ g"${av:0:1}" == g"-" ]; then
+ while [ g"$av" != g"" ]
+ do
+ ag=${av:0:1}
+ av=${av:1}
+ [ g"$ag" == g"b" ] && isbranch=1
+ [ g"$ag" == g"i" ] && install=1
+ [ g"$ag" == g"u" ] && update=1
+ done
+ else
+ if [ g"$isbranch" == g"1" ]; then
+ branch="-b $av"
+ isbranch=0
+ fi
+ fi
+done
+
+if [ g"$install" != g"1" -a g"$update" != g"1" ]; then
+ echo "Not install & Not update, exit"
+ exit
+fi
+#echo $branch
+#echo $install
+
gitsource='https://github.com/qkqpttgf/OneManager-php'
OneManagerPath=`cd $(dirname $0);pwd -P`
cd ${OneManagerPath}
-git clone ${gitsource}
-\mv -b config.php OneManager-php/
+git clone ${branch} ${gitsource}
+[ g"$install" == g"1" ] || \mv -b config.php OneManager-php/
\mv -b OneManager-php/* ./
\mv -b OneManager-php/.[^.]* ./
rm -rf *~
From 0a78999463db0fcfa5d501935b982bce7557a571 Mon Sep 17 00:00:00 2001
From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com>
Date: Thu, 2 Apr 2020 16:33:55 +0800
Subject: [PATCH 03/12] Update update.sh
---
update.sh | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/update.sh b/update.sh
index cc34856..23cc7c2 100644
--- a/update.sh
+++ b/update.sh
@@ -47,12 +47,14 @@ do
fi
done
+if [ g"$install" == g"1" -a g"$update" == g"1" ]; then
+ echo "Both install & update, exit"
+ exit
+fi
if [ g"$install" != g"1" -a g"$update" != g"1" ]; then
echo "Not install & Not update, exit"
exit
fi
-#echo $branch
-#echo $install
gitsource='https://github.com/qkqpttgf/OneManager-php'
From a868d5df44ba609aae5b410a43e75d501b95be15 Mon Sep 17 00:00:00 2001
From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com>
Date: Thu, 2 Apr 2020 18:16:13 +0800
Subject: [PATCH 04/12] Update conststr.php
---
conststr.php | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/conststr.php b/conststr.php
index c4f5df8..4403934 100644
--- a/conststr.php
+++ b/conststr.php
@@ -726,4 +726,12 @@ $constStr = [
'ko-kr' => '캐시 플러시',
'fa' => 'رفرش cache',
],
+ 'VPSnotupdate' => [
+ 'en-us' => 'In VPS can not update by a click! run update.sh',
+ 'zh-cn' => '在VPS中不能一键更新,可以运行update.sh',
+ ],
+ 'QueryBranchs' => [
+ 'en-us' => 'Query Branchs',
+ 'zh-cn' => '查询分支',
+ ],
];
From 286046b82aaf701638cb4687d674c549ece802b4 Mon Sep 17 00:00:00 2001
From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com>
Date: Thu, 2 Apr 2020 18:18:08 +0800
Subject: [PATCH 05/12] use accept_language
---
common.php | 72 ++++++++++++++++++++++++++----------------------------
1 file changed, 35 insertions(+), 37 deletions(-)
diff --git a/common.php b/common.php
index 7f3bb59..2967e4b 100644
--- a/common.php
+++ b/common.php
@@ -45,7 +45,7 @@ $CommonEnv = [
'disktag',
'function_name', // used in heroku.
'hideFunctionalityFile',
- 'language',
+ //'language',
'passfile',
'sitename',
'theme',
@@ -62,7 +62,7 @@ $ShowedCommonEnv = [
//'disktag',
//'function_name', // used in heroku.
'hideFunctionalityFile',
- 'language',
+ //'language',
'passfile',
'sitename',
'theme',
@@ -113,8 +113,11 @@ function main($path)
global $exts;
global $constStr;
- if (isset($_COOKIE['language'])) $constStr['language'] = $_COOKIE['language'];
- if (!$constStr['language']) $constStr['language'] = getConfig('language');
+ if (in_array($_SERVER['firstacceptlanguage'], array_keys($constStr['languages']))) $constStr['language'] = $_SERVER['firstacceptlanguage'];
+ if (isset($_COOKIE['language'])&&$_COOKIE['language']!='') $constStr['language'] = $_COOKIE['language'];
+ //if (!$constStr['language']) $constStr['language'] = getConfig('language');
+ /*echo 'firstacceptlanguage:'.$_SERVER['firstacceptlanguage'].'
+ '.'lan:'.$constStr['language'];*/
if ($constStr['language']=='') $constStr['language'] = 'en-us';
$_SERVER['language'] = $constStr['language'];
$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
@@ -274,28 +277,7 @@ function main($path)
function get_access_token($refresh_token)
{
if (getConfig('Drive_ver')=='shareurl') {
-
-//if (!$files) $files['body'] = $arr['body'];
- //$files['returnhead'] = $arr['returnhead'];
- //$files['cookie'] = $arr['returnhead']['Set-Cookie'];
-//return $files;
-
- /*$files['get'] = curl_request(
- "https://mfedu-my.sharepoint.com/personal/ysun_ac_stu_office_gy/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='%2Fpersonal%2Fysun_ac_stu_office_gy%2FDocuments'&RootFolder=%2Fpersonal%2Fysun_ac_stu_office_gy%2FDocuments%2F&TryNewExperienceSingle=TRUE",
- '{"parameters":{"__metadata":{"type":"SP.RenderListDataParameters"},"RenderOptions":136967,"AllowMultipleValueFilterForTaxonomyFields":true,"AddRequiredFields":true}}',
- ['Accept' => 'application/json;odata=verbose', 'Content-Type' => 'application/json;odata=verbose', 'origin' => 'https://mfedu-my.sharepoint.com', 'Cookie' => $arr['returnhead']['Set-Cookie']],
- 1);
- $files['get']['body'] = json_decode($files['get']['body'], true);
- $_SERVER['access_token'] = splitlast($files['get']['body']['ListSchema']['.driveAccessToken'],'=')[1];
- $_SERVER['api_url'] = $files['get']['body']['ListSchema']['.driveUrl'].'/root';
-
- $files = json_decode( curl_request( $_SERVER['api_url'].'?expand=children(select=name,size,file,folder,parentReference,lastModifiedDateTime,@microsoft.graph.downloadUrl,@content.downloadUrl)', false, ['Authorization' => 'Bearer ' . $_SERVER['access_token'], 'Accept' => 'application/json'] )['body'], true);
- $files['children']['a']['file'] = $_SERVER['api_url'];
- $files['children']['a']['name'] = $_SERVER['api_url'];
-*/
$shareurl = getConfig('shareurl');
- //$url = 'https://mfedu-my.sharepoint.com/:f:/g/personal/ysun_ac_stu_office_gy/EpDIBOaYyExHjfu-PJA46icB40X0FKVwmn_9UDJsRvu3Ug?e=XyRZxP';
- //$url = 'https://2d2-my.sharepoint.com/:f:/g/personal/ysun_host_ac_cn/Ehy8pjSQSoZOtLDs4ZKPiGUBYFt26CjEwG6bw7W5vleNNQ?e=DLZcWF';
$tmp1 = splitlast($shareurl, '/')[0];
$account = splitlast($tmp1, '/')[1];
$tmp1 = splitlast($shareurl, ':')[0];
@@ -311,8 +293,8 @@ function get_access_token($refresh_token)
$_SERVER['api_url'] = $ret['ListSchema']['.driveUrl'].'/root';
if (!$_SERVER['access_token']) {
error_log($domain . "/personal/" . $account . "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" . urlencode("/personal/" . $account . "/Documents") . "'&RootFolder=" . urlencode("/personal/" . $account . "/Documents/") . "&TryNewExperienceSingle=TRUE");
- 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('failed to get share access_token. response' . json_encode($ret));
+ throw new Exception($response['stat'].', failed to get share access_token.'.$response['body']);
}
error_log('Get access token:'.json_encode($ret, JSON_PRETTY_PRINT));
savecache('access_token', $_SERVER['access_token']);
@@ -362,14 +344,12 @@ function isHideFile($name)
function getcache($str)
{
- //$cache = null;
$cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'/Onedrive/'.$_SERVER['disktag']);
return $cache->fetch($str);
}
function savecache($key, $value, $exp = 1800)
{
- //$cache = null;
$cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'/Onedrive/'.$_SERVER['disktag']);
$cache->save($key, $value, $exp);
}
@@ -434,8 +414,6 @@ function get_siteid($access_token)
while ($url!=''&&$response['stat']!=200&&$i<4) {
$response = curl_request($url, false, ['Authorization' => 'Bearer ' . $access_token]);
$i++;
- //echo 'https://graph.microsoft.com/v1.0/sites/root:/sites/'.getConfig('sharepointname').$response['stat'].$response['body'].'
- //';
}
if ($response['stat']!=200) {
error_log('failed to get siteid. response' . json_encode($response));
@@ -505,7 +483,9 @@ function equal_replace($str, $add = false)
function is_guestup_path($path)
{
- if (path_format('/'.path_format(urldecode($_SERVER['list_path'].path_format($path))).'/')==path_format('/'.path_format(getConfig('guestup_path')).'/')&&getConfig('guestup_path')!='') return 1;
+ $a1 = path_format(path_format(urldecode($_SERVER['list_path'].path_format($path))).'/')
+ $a2 = path_format(path_format(getConfig('guestup_path')).'/')
+ if (getConfig('guestup_path')!=''&&strtolower($a1)==strtolower($a2)) return 1;
return 0;
}
@@ -957,18 +937,36 @@ function adminoperate($path)
return $tmparr;
}
+function splitfirst($str, $split)
+{
+ $len = strlen($split);
+ $pos = strpos($str, $split);
+ if ($pos===false) {
+ $tmp[0] = $str;
+ $tmp[1] = '';
+ } elseif ($pos>0) {
+ $tmp[0] = substr($str, 0, $pos);
+ $tmp[1] = substr($str, $pos+$len);
+ } else {
+ $tmp[0] = '';
+ $tmp[1] = substr($str, $len);
+ }
+ return $tmp;
+}
+
function splitlast($str, $split)
{
+ $len = strlen($split);
$pos = strrpos($str, $split);
if ($pos===false) {
$tmp[0] = $str;
$tmp[1] = '';
} elseif ($pos>0) {
$tmp[0] = substr($str, 0, $pos);
- $tmp[1] = substr($str, $pos+1);
+ $tmp[1] = substr($str, $pos+$len);
} else {
$tmp[0] = '';
- $tmp[1] = substr($str, 1);
+ $tmp[1] = substr($str, $len);
}
return $tmp;
}
@@ -1612,14 +1610,14 @@ function EnvOpt($needUpdate = 0)
'.getconstStr('AddDisk').'
';
if (!((isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud')||(isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app'))) {
$html .= '
-In VPS can not update by a click!
';
+'.getconstStr('VPSnotupdate').'
';
} else {
$html .= '