Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d48854791f | ||
|
|
6bf9e7e843 | ||
|
|
86a083e196 | ||
|
|
f4d7c354ea | ||
|
|
00d61d6118 | ||
|
|
f4a11d5312 | ||
|
|
56fe3f3c5f | ||
|
|
53c122937d | ||
|
|
1b2c468d7e | ||
|
|
187a43e073 | ||
|
|
2f01d6c3f7 | ||
|
|
6b0e5bf8d5 | ||
|
|
f86f713679 | ||
|
|
473769c693 | ||
|
|
179fa24c4a | ||
|
|
d479ac6662 | ||
|
|
1b04aafd95 | ||
|
|
3939317b1b | ||
|
|
739f42e24f | ||
|
|
6abedbafd5 | ||
|
|
05bbb1b861 | ||
|
|
3842fb7952 | ||
|
|
4ef20bdf50 | ||
|
|
7a86da6764 | ||
|
|
378a59eda6 | ||
|
|
3571c47671 | ||
|
|
1bee94cf43 | ||
|
|
f57ddf02db | ||
|
|
bc12e82c74 | ||
|
|
e67ff8736b | ||
|
|
fe765192e1 | ||
|
|
36df71a77c | ||
|
|
a1381e7fcc | ||
|
|
93b713b508 | ||
|
|
3a95027a06 | ||
|
|
cfda210fdc | ||
|
|
0a7887409c | ||
|
|
ce4fc41443 | ||
|
|
8cc9efa43c | ||
|
|
267b17102c | ||
|
|
127febb75d | ||
|
|
b0bee473ff | ||
|
|
91c6583d70 | ||
|
|
02745e7742 | ||
|
|
92d17d389d | ||
|
|
85741cae27 | ||
|
|
f926b37ae5 | ||
|
|
96cad800b7 | ||
|
|
55f267092d | ||
|
|
52a47fbd05 | ||
|
|
f6a8243a83 | ||
|
|
43ce495d76 | ||
|
|
eb12b784d3 | ||
|
|
1f4552bb73 | ||
|
|
d83bdcbf94 | ||
|
|
4e806bb8bd | ||
|
|
f10a5d3c1a | ||
|
|
6c4d20083f | ||
|
|
4cdc02ec7f | ||
|
|
0f9cc9451e | ||
|
|
2e94fb6502 | ||
|
|
e9ceedbd50 | ||
|
|
268c6e8be7 | ||
|
|
3619a611a7 | ||
|
|
2887a7026e | ||
|
|
08c790690d | ||
|
|
c653abf457 | ||
|
|
87654f35ce | ||
|
|
fe4f4e50d7 | ||
|
|
0dac337037 | ||
|
|
a18eb9f9f6 | ||
|
|
4962a90795 |
@@ -2,13 +2,14 @@
|
|||||||
# # LoadModule rewrite_module modules/mod_rewrite.so
|
# # LoadModule rewrite_module modules/mod_rewrite.so
|
||||||
# # AllowOverride All
|
# # AllowOverride All
|
||||||
RewriteEngine On
|
RewriteEngine On
|
||||||
|
# RewriteCond $1 !^(.well-known)
|
||||||
RewriteRule ^(.*) index.php?/$1 [L]
|
RewriteRule ^(.*) index.php?/$1 [L]
|
||||||
|
|
||||||
###-----------------------------------
|
###-----------------------------------
|
||||||
# # nginx
|
### nginx
|
||||||
# rewrite ^(.*) /index.php?/$1 last;
|
# rewrite ^/(?!.well-known)(.*)$ /index.php?/$1 last;
|
||||||
#
|
#
|
||||||
# # caddy
|
### caddy
|
||||||
# rewrite {
|
# rewrite {
|
||||||
# to index.php?/$1
|
# to index.php?/$1
|
||||||
# }
|
# }
|
||||||
|
|||||||
+266
-104
@@ -6,6 +6,7 @@ global $ShowedCommonEnv;
|
|||||||
global $InnerEnv;
|
global $InnerEnv;
|
||||||
global $ShowedInnerEnv;
|
global $ShowedInnerEnv;
|
||||||
global $Base64Env;
|
global $Base64Env;
|
||||||
|
global $timezones;
|
||||||
|
|
||||||
$Base64Env = [
|
$Base64Env = [
|
||||||
//'APIKey', // used in heroku.
|
//'APIKey', // used in heroku.
|
||||||
@@ -18,7 +19,9 @@ $Base64Env = [
|
|||||||
//'HW_secret', // used in FG.
|
//'HW_secret', // used in FG.
|
||||||
//'admin',
|
//'admin',
|
||||||
//'adminloginpage',
|
//'adminloginpage',
|
||||||
|
//'autoJumpFirstDisk',
|
||||||
'background',
|
'background',
|
||||||
|
'backgroundm',
|
||||||
'diskname',
|
'diskname',
|
||||||
//'disableShowThumb',
|
//'disableShowThumb',
|
||||||
//'disableChangeTheme',
|
//'disableChangeTheme',
|
||||||
@@ -62,7 +65,9 @@ $CommonEnv = [
|
|||||||
'HW_secret', // used in FG.
|
'HW_secret', // used in FG.
|
||||||
'admin',
|
'admin',
|
||||||
'adminloginpage',
|
'adminloginpage',
|
||||||
|
'autoJumpFirstDisk',
|
||||||
'background',
|
'background',
|
||||||
|
'backgroundm',
|
||||||
'disktag',
|
'disktag',
|
||||||
'disableShowThumb',
|
'disableShowThumb',
|
||||||
'disableChangeTheme',
|
'disableChangeTheme',
|
||||||
@@ -88,7 +93,9 @@ $ShowedCommonEnv = [
|
|||||||
//'HW_secret', // used in FG.
|
//'HW_secret', // used in FG.
|
||||||
//'admin',
|
//'admin',
|
||||||
'adminloginpage',
|
'adminloginpage',
|
||||||
|
'autoJumpFirstDisk',
|
||||||
'background',
|
'background',
|
||||||
|
'backgroundm',
|
||||||
//'disktag',
|
//'disktag',
|
||||||
'disableShowThumb',
|
'disableShowThumb',
|
||||||
'disableChangeTheme',
|
'disableChangeTheme',
|
||||||
@@ -198,9 +205,6 @@ function main($path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($_COOKIE['language'])&&$_COOKIE['language']!='') $constStr['language'] = $_COOKIE['language'];
|
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';
|
if ($constStr['language']=='') $constStr['language'] = 'en-us';
|
||||||
$_SERVER['language'] = $constStr['language'];
|
$_SERVER['language'] = $constStr['language'];
|
||||||
$_SERVER['timezone'] = getConfig('timezone');
|
$_SERVER['timezone'] = getConfig('timezone');
|
||||||
@@ -222,19 +226,18 @@ function main($path)
|
|||||||
}
|
}
|
||||||
if (getConfig('admin')!='') {
|
if (getConfig('admin')!='') {
|
||||||
if ($_POST['password1']==getConfig('admin')) {
|
if ($_POST['password1']==getConfig('admin')) {
|
||||||
return adminform('admin',md5($_POST['password1']),$url);
|
return adminform('admin', pass2cookie('admin', $_POST['password1']), $url);
|
||||||
} else return adminform();
|
} else return adminform();
|
||||||
} else {
|
} else {
|
||||||
return output('', 302, [ 'Location' => $url ]);
|
return output('', 302, [ 'Location' => $url ]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getConfig('admin')!='')
|
if ( isset($_COOKIE['admin'])&&$_COOKIE['admin']==pass2cookie('admin', getConfig('admin')) ) {
|
||||||
if ( isset($_COOKIE['admin'])&&$_COOKIE['admin']==md5(getConfig('admin')) ) {
|
$_SERVER['admin']=1;
|
||||||
$_SERVER['admin']=1;
|
$_SERVER['needUpdate'] = needUpdate();
|
||||||
$_SERVER['needUpdate'] = needUpdate();
|
} else {
|
||||||
} else {
|
$_SERVER['admin']=0;
|
||||||
$_SERVER['admin']=0;
|
}
|
||||||
}
|
|
||||||
if (isset($_GET['setup']))
|
if (isset($_GET['setup']))
|
||||||
if ($_SERVER['admin']) {
|
if ($_SERVER['admin']) {
|
||||||
// setup Environments. 设置,对环境变量操作
|
// setup Environments. 设置,对环境变量操作
|
||||||
@@ -247,31 +250,42 @@ function main($path)
|
|||||||
$_SERVER['sitename'] = getConfig('sitename');
|
$_SERVER['sitename'] = getConfig('sitename');
|
||||||
if (empty($_SERVER['sitename'])) $_SERVER['sitename'] = getconstStr('defaultSitename');
|
if (empty($_SERVER['sitename'])) $_SERVER['sitename'] = getconstStr('defaultSitename');
|
||||||
$_SERVER['base_disk_path'] = $_SERVER['base_path'];
|
$_SERVER['base_disk_path'] = $_SERVER['base_path'];
|
||||||
$disktags = explode("|",getConfig('disktag'));
|
$disktags = explode("|", getConfig('disktag'));
|
||||||
// echo 'count$disk:'.count($disktags);
|
// echo 'count$disk:'.count($disktags);
|
||||||
if (count($disktags)>1) {
|
if (count($disktags)>1) {
|
||||||
if ($path=='/'||$path=='') {
|
if ($path=='/'||$path=='') {
|
||||||
|
if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]);
|
||||||
|
$files['showname'] = 'root';
|
||||||
|
$files['folder']['childCount'] = count($disktags);
|
||||||
|
foreach ($disktags as $disktag) {
|
||||||
|
$files['children'][$disktag]['folder'] = 1;
|
||||||
|
$files['children'][$disktag]['name'] = $disktag;
|
||||||
|
$files['children'][$disktag]['showname'] = getConfig('diskname', $disktag);
|
||||||
|
}
|
||||||
if ($_GET['json']) {
|
if ($_GET['json']) {
|
||||||
// return a json
|
// return a json
|
||||||
$files['folder']['childCount'] = count($disktags);
|
|
||||||
foreach ($disktags as $disktag) {
|
|
||||||
$files['children'][$disktag]['folder'] = 1;
|
|
||||||
$files['children'][$disktag]['name'] = $disktag;
|
|
||||||
}
|
|
||||||
return files_json($files);
|
return files_json($files);
|
||||||
} // else return render_list($path, $files);
|
}
|
||||||
return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]);
|
} else {
|
||||||
|
$_SERVER['disktag'] = splitfirst( substr(path_format($path), 1), '/' )[0];
|
||||||
|
//$pos = strpos($path, '/');
|
||||||
|
//if ($pos>1) $_SERVER['disktag'] = substr($path, 0, $pos);
|
||||||
|
if (!in_array($_SERVER['disktag'], $disktags)) {
|
||||||
|
$tmp = path_format($_SERVER['base_path'] . '/' . $disktags[0] . '/' . $path);
|
||||||
|
if (!!$_GET) {
|
||||||
|
$tmp .= '?';
|
||||||
|
foreach ($_GET as $k => $v) {
|
||||||
|
if ($v === true) $tmp .= $k . '&';
|
||||||
|
else $tmp .= $k . '=' . $v . '&';
|
||||||
|
}
|
||||||
|
$tmp = substr($tmp, 0, -1);
|
||||||
|
}
|
||||||
|
return output('Please visit <a href="' . $tmp . '">' . $tmp . '</a>.', 302, [ 'Location' => $tmp ]);
|
||||||
|
//return message('<meta http-equiv="refresh" content="2;URL='.$_SERVER['base_path'].'">Please visit from <a href="'.$_SERVER['base_path'].'">Home Page</a>.', 'Error', 404);
|
||||||
|
}
|
||||||
|
$path = substr($path, strlen('/' . $_SERVER['disktag']));
|
||||||
|
if ($_SERVER['disktag']!='') $_SERVER['base_disk_path'] = path_format($_SERVER['base_disk_path'] . '/' . $_SERVER['disktag'] . '/');
|
||||||
}
|
}
|
||||||
$_SERVER['disktag'] = splitfirst( substr(path_format($path), 1), '/' )[0];
|
|
||||||
//$pos = strpos($path, '/');
|
|
||||||
//if ($pos>1) $_SERVER['disktag'] = substr($path, 0, $pos);
|
|
||||||
if (!in_array($_SERVER['disktag'], $disktags)) {
|
|
||||||
$tmp = path_format($_SERVER['base_path'].'/'.$disktags[0].'/'.$path);
|
|
||||||
return output('Please visit <a href="'.$tmp.'">'.$tmp.'</a>.', 302, [ 'Location' => $tmp ]);
|
|
||||||
//return message('<meta http-equiv="refresh" content="2;URL='.$_SERVER['base_path'].'">Please visit from <a href="'.$_SERVER['base_path'].'">Home Page</a>.', 'Error', 404);
|
|
||||||
}
|
|
||||||
$path = substr($path, strlen('/'.$_SERVER['disktag']));
|
|
||||||
if ($_SERVER['disktag']!='') $_SERVER['base_disk_path'] = path_format($_SERVER['base_disk_path']. '/' . $_SERVER['disktag'] . '/');
|
|
||||||
} else $_SERVER['disktag'] = $disktags[0];
|
} else $_SERVER['disktag'] = $disktags[0];
|
||||||
// echo 'main.disktag:'.$_SERVER['disktag'].',path:'.$path.'
|
// echo 'main.disktag:'.$_SERVER['disktag'].',path:'.$path.'
|
||||||
//';
|
//';
|
||||||
@@ -281,15 +295,17 @@ function main($path)
|
|||||||
$_SERVER['ajax']=0;
|
$_SERVER['ajax']=0;
|
||||||
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) if ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') $_SERVER['ajax']=1;
|
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) if ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') $_SERVER['ajax']=1;
|
||||||
|
|
||||||
|
if ($_SERVER['admin']) if (isset($_GET['AddDisk'])) return get_refresh_token();
|
||||||
|
|
||||||
|
if ($files['showname'] == 'root') return render_list($path, $files);
|
||||||
config_oauth();
|
config_oauth();
|
||||||
if ($_SERVER['admin']) if (isset($_GET['AddDisk'])||isset($_GET['authorization_code'])) return get_refresh_token();
|
|
||||||
$refresh_token = getConfig('refresh_token');
|
$refresh_token = getConfig('refresh_token');
|
||||||
//if (!$refresh_token) return get_refresh_token();
|
|
||||||
if (!$refresh_token) {
|
if (!$refresh_token) {
|
||||||
return render_list();
|
return render_list();
|
||||||
} else {
|
} else {
|
||||||
if (!($_SERVER['access_token'] = getcache('access_token'))) {
|
if (!($_SERVER['access_token'] = getcache('access_token'))) {
|
||||||
get_access_token($refresh_token);
|
$response = get_access_token($refresh_token);
|
||||||
|
if (isset($response['stat'])) return message($response['body'], 'Error', $response['stat']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_SERVER['ajax']) {
|
if ($_SERVER['ajax']) {
|
||||||
@@ -388,7 +404,11 @@ function main($path)
|
|||||||
$url = proxy_replace_domain($url, $domainforproxy);
|
$url = proxy_replace_domain($url, $domainforproxy);
|
||||||
}
|
}
|
||||||
if ( strtolower(splitlast($files['name'],'.')[1])=='html' ) return output($files['content']['body'], $files['content']['stat']);
|
if ( strtolower(splitlast($files['name'],'.')[1])=='html' ) return output($files['content']['body'], $files['content']['stat']);
|
||||||
else return output('', 302, [ 'Location' => $url ]);
|
else {
|
||||||
|
if ($_SERVER['HTTP_RANGE']!='') $header['Range'] = $_SERVER['HTTP_RANGE'];
|
||||||
|
$header['Location'] = $url;
|
||||||
|
return output('', 302, $header);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( isset($files['folder']) || isset($files['file']) ) {
|
if ( isset($files['folder']) || isset($files['file']) ) {
|
||||||
@@ -404,6 +424,11 @@ function main($path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pass2cookie($name, $pass)
|
||||||
|
{
|
||||||
|
return md5($name . ':' . md5($pass));
|
||||||
|
}
|
||||||
|
|
||||||
function proxy_replace_domain($url, $domainforproxy)
|
function proxy_replace_domain($url, $domainforproxy)
|
||||||
{
|
{
|
||||||
$tmp = splitfirst($url, '//');
|
$tmp = splitfirst($url, '//');
|
||||||
@@ -448,7 +473,7 @@ function files_json($files)
|
|||||||
$tmp1['mime'] = $file['file']['mimeType'];
|
$tmp1['mime'] = $file['file']['mimeType'];
|
||||||
array_push($tmp['list'], $tmp1);
|
array_push($tmp['list'], $tmp1);
|
||||||
}
|
}
|
||||||
} else return output('', 404);
|
} else return output(var_dump($files), 404);
|
||||||
return output(json_encode($tmp), 200, ['Content-Type' => 'application/json']);
|
return output(json_encode($tmp), 200, ['Content-Type' => 'application/json']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,7 +497,9 @@ function get_access_token($refresh_token)
|
|||||||
if (!$_SERVER['access_token']) {
|
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($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 share access_token. response' . json_encode($ret));
|
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']);
|
$response['body'] .= '\nfailed to get shareurl access_token.';
|
||||||
|
return $response;
|
||||||
|
//throw new Exception($response['stat'].', failed to get share access_token.'.$response['body']);
|
||||||
}
|
}
|
||||||
$tmp = $ret;
|
$tmp = $ret;
|
||||||
$tmp['access_token'] = '******';
|
$tmp['access_token'] = '******';
|
||||||
@@ -491,7 +518,9 @@ function get_access_token($refresh_token)
|
|||||||
if (!isset($ret['access_token'])) {
|
if (!isset($ret['access_token'])) {
|
||||||
error_log($_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=' . substr($refresh_token, 0, 20) . '******' . substr($refresh_token, -20));
|
error_log($_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=' . substr($refresh_token, 0, 20) . '******' . substr($refresh_token, -20));
|
||||||
error_log('failed to get ['.$_SERVER['disktag'].'] access_token. response' . json_encode($ret));
|
error_log('failed to get ['.$_SERVER['disktag'].'] access_token. response' . json_encode($ret));
|
||||||
throw new Exception($response['stat'].', failed to get ['.$_SERVER['disktag'].'] access_token.'.$response['body']);
|
$response['body'] .= '\nfailed to get ['.$_SERVER['disktag'].'] access_token.';
|
||||||
|
return $response;
|
||||||
|
//throw new Exception($response['stat'].', failed to get ['.$_SERVER['disktag'].'] access_token.'.$response['body']);
|
||||||
}
|
}
|
||||||
$tmp = $ret;
|
$tmp = $ret;
|
||||||
$tmp['access_token'] = '******';
|
$tmp['access_token'] = '******';
|
||||||
@@ -501,6 +530,7 @@ function get_access_token($refresh_token)
|
|||||||
savecache('access_token', $_SERVER['access_token'], $ret['expires_in'] - 300);
|
savecache('access_token', $_SERVER['access_token'], $ret['expires_in'] - 300);
|
||||||
if (time()>getConfig('token_expires')) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+7*24*60*60 ]);
|
if (time()>getConfig('token_expires')) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+7*24*60*60 ]);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function list_files($path)
|
function list_files($path)
|
||||||
@@ -536,14 +566,34 @@ function isHideFile($name)
|
|||||||
|
|
||||||
function getcache($str)
|
function getcache($str)
|
||||||
{
|
{
|
||||||
$cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'/Onedrive/'.$_SERVER['disktag']);
|
$cache = filecache();
|
||||||
return $cache->fetch($str);
|
return $cache->fetch($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
function savecache($key, $value, $exp = 1800)
|
function savecache($key, $value, $exp = 1800)
|
||||||
{
|
{
|
||||||
$cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'/Onedrive/'.$_SERVER['disktag']);
|
$cache = filecache();
|
||||||
$cache->save($key, $value, $exp);
|
return $cache->save($key, $value, $exp);
|
||||||
|
}
|
||||||
|
|
||||||
|
function filecache()
|
||||||
|
{
|
||||||
|
$dir = sys_get_temp_dir();
|
||||||
|
if (!is_writable($dir)) {
|
||||||
|
$tmp = __DIR__ . '/tmp/';
|
||||||
|
if (file_exists($tmp)) {
|
||||||
|
if ( is_writable($tmp) ) $dir = $tmp;
|
||||||
|
} elseif ( mkdir($tmp) ) $dir = $tmp;
|
||||||
|
}
|
||||||
|
$tag = __DIR__ . '/OneManager/' . $_SERVER['disktag'];
|
||||||
|
while (strpos($tag, '/')>-1) $tag = str_replace('/', '_', $tag);
|
||||||
|
if (strpos($tag, ':')>-1) {
|
||||||
|
while (strpos($tag, ':')>-1) $tag = str_replace(':', '_', $tag);
|
||||||
|
while (strpos($tag, '\\')>-1) $tag = str_replace('\\', '_', $tag);
|
||||||
|
}
|
||||||
|
// error_log('DIR:' . $dir . ' TAG: ' . $tag);
|
||||||
|
$cache = new \Doctrine\Common\Cache\FilesystemCache($dir, $tag);
|
||||||
|
return $cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getconstStr($str)
|
function getconstStr($str)
|
||||||
@@ -575,10 +625,12 @@ function config_oauth()
|
|||||||
if (getConfig('usesharepoint')=='on') $_SERVER['api_url'] = 'https://graph.microsoft.com/v1.0/sites/' . getConfig('siteid') . '/drive/root';
|
if (getConfig('usesharepoint')=='on') $_SERVER['api_url'] = 'https://graph.microsoft.com/v1.0/sites/' . getConfig('siteid') . '/drive/root';
|
||||||
}
|
}
|
||||||
if (getConfig('Drive_ver')=='CN') {
|
if (getConfig('Drive_ver')=='CN') {
|
||||||
// CN
|
// CN 21Vianet
|
||||||
// https://portal.azure.cn
|
// https://portal.azure.cn
|
||||||
$_SERVER['client_id'] = '04c3ca0b-8d07-4773-85ad-98b037d25631';
|
//$_SERVER['client_id'] = '04c3ca0b-8d07-4773-85ad-98b037d25631';
|
||||||
$_SERVER['client_secret'] = 'h8@B7kFVOmj0+8HKBWeNTgl@pU/z4yLB';
|
//$_SERVER['client_secret'] = 'h8@B7kFVOmj0+8HKBWeNTgl@pU/z4yLB'; // expire 20200902
|
||||||
|
$_SERVER['client_id'] = 'b15f63f5-8b72-48b5-af69-8cab7579bff7';
|
||||||
|
$_SERVER['client_secret'] = '0IIuZ1Kcq_YI3NrkZFwsniEo~BoP~8_M22';
|
||||||
$_SERVER['oauth_url'] = 'https://login.partner.microsoftonline.cn/common/oauth2/v2.0/';
|
$_SERVER['oauth_url'] = 'https://login.partner.microsoftonline.cn/common/oauth2/v2.0/';
|
||||||
$_SERVER['api_url'] = 'https://microsoftgraph.chinacloudapi.cn/v1.0/me/drive/root';
|
$_SERVER['api_url'] = 'https://microsoftgraph.chinacloudapi.cn/v1.0/me/drive/root';
|
||||||
$_SERVER['scope'] = 'https://microsoftgraph.chinacloudapi.cn/Files.ReadWrite.All offline_access';
|
$_SERVER['scope'] = 'https://microsoftgraph.chinacloudapi.cn/Files.ReadWrite.All offline_access';
|
||||||
@@ -614,7 +666,9 @@ function get_siteid($access_token)
|
|||||||
}
|
}
|
||||||
if ($response['stat']!=200) {
|
if ($response['stat']!=200) {
|
||||||
error_log('failed to get siteid. response' . json_encode($response));
|
error_log('failed to get siteid. response' . json_encode($response));
|
||||||
throw new Exception($response['stat'].', failed to get siteid.'.$response['body']);
|
$response['body'] .= '\nfailed to get siteid.';
|
||||||
|
return $response;
|
||||||
|
//throw new Exception($response['stat'].', failed to get siteid.'.$response['body']);
|
||||||
}
|
}
|
||||||
return json_decode($response['body'],true)['id'];
|
return json_decode($response['body'],true)['id'];
|
||||||
}
|
}
|
||||||
@@ -650,15 +704,16 @@ function path_format($path)
|
|||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
function spurlencode($str,$split='')
|
function spurlencode($str, $split='')
|
||||||
{
|
{
|
||||||
$str = str_replace(' ', '%20',$str);
|
$str = str_replace(' ', '%20',$str);
|
||||||
$tmp='';
|
$tmp='';
|
||||||
if ($split!='') {
|
if ($split!='') {
|
||||||
$tmparr=explode($split,$str);
|
$tmparr=explode($split, $str);
|
||||||
for($x=0;$x<count($tmparr);$x++) {
|
foreach ($tmparr as $str1) {
|
||||||
if ($tmparr[$x]!='') $tmp .= $split . urlencode($tmparr[$x]);
|
$tmp .= urlencode($str1) . $split;
|
||||||
}
|
}
|
||||||
|
$tmp = substr($tmp, 0, -strlen($split));
|
||||||
} else {
|
} else {
|
||||||
$tmp = urlencode($str);
|
$tmp = urlencode($str);
|
||||||
}
|
}
|
||||||
@@ -666,6 +721,25 @@ function spurlencode($str,$split='')
|
|||||||
return $tmp;
|
return $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function base64y_encode($str)
|
||||||
|
{
|
||||||
|
$str = base64_encode($str);
|
||||||
|
while (substr($str,-1)=='=') $str=substr($str,0,-1);
|
||||||
|
while (strpos($str, '+')!==false) $str = str_replace('+', '-', $str);
|
||||||
|
while (strpos($str, '/')!==false) $str = str_replace('/', '_', $str);
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
function base64y_decode($str)
|
||||||
|
{
|
||||||
|
while (strpos($str, '_')!==false) $str = str_replace('_', '/', $str);
|
||||||
|
while (strpos($str, '-')!==false) $str = str_replace('-', '+', $str);
|
||||||
|
while (strlen($str)%4) $str .= '=';
|
||||||
|
$str = base64_decode($str);
|
||||||
|
if (strpos($str, '%')!==false) $str = urldecode($str);
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
function equal_replace($str, $add = false)
|
function equal_replace($str, $add = false)
|
||||||
{
|
{
|
||||||
if ($add) {
|
if ($add) {
|
||||||
@@ -691,6 +765,42 @@ function array_value_isnot_null($arr)
|
|||||||
return $arr!=='';
|
return $arr!=='';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function curl($method, $url, $data = '', $headers = [], $returnheader = 0)
|
||||||
|
{
|
||||||
|
//if (!isset($headers['Accept'])) $headers['Accept'] = '*/*';
|
||||||
|
//if (!isset($headers['Referer'])) $headers['Referer'] = $url;
|
||||||
|
//if (!isset($headers['Content-Type'])) $headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||||
|
$sendHeaders = array();
|
||||||
|
foreach ($headers as $headerName => $headerVal) {
|
||||||
|
$sendHeaders[] = $headerName . ': ' . $headerVal;
|
||||||
|
}
|
||||||
|
$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, $returnheader);
|
||||||
|
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);
|
||||||
|
if ($returnheader) {
|
||||||
|
list($returnhead, $response['body']) = explode("\r\n\r\n", curl_exec($ch));
|
||||||
|
foreach (explode("\r\n", $returnhead) as $head) {
|
||||||
|
$tmp = explode(': ', $head);
|
||||||
|
$heads[$tmp[0]] = $tmp[1];
|
||||||
|
}
|
||||||
|
$response['returnhead'] = $heads;
|
||||||
|
} else {
|
||||||
|
$response['body'] = curl_exec($ch);
|
||||||
|
}
|
||||||
|
$response['stat'] = curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
function curl_request($url, $data = false, $headers = [], $returnheader = 0)
|
function curl_request($url, $data = false, $headers = [], $returnheader = 0)
|
||||||
{
|
{
|
||||||
if (!isset($headers['Accept'])) $headers['Accept'] = '*/*';
|
if (!isset($headers['Accept'])) $headers['Accept'] = '*/*';
|
||||||
@@ -815,9 +925,7 @@ function message($message, $title = 'Message', $statusCode = 200)
|
|||||||
<body>
|
<body>
|
||||||
<h1>' . $title . '</h1>
|
<h1>' . $title . '</h1>
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
' . $message . '
|
' . $message . '
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -826,10 +934,11 @@ function message($message, $title = 'Message', $statusCode = 200)
|
|||||||
|
|
||||||
function needUpdate()
|
function needUpdate()
|
||||||
{
|
{
|
||||||
$current_ver = file_get_contents(__DIR__ . '/version');
|
$current_version = file_get_contents(__DIR__ . '/version');
|
||||||
$current_ver = substr($current_ver, strpos($current_ver, '.')+1);
|
$current_ver = substr($current_version, strpos($current_version, '.')+1);
|
||||||
$current_ver = explode(urldecode('%0A'),$current_ver)[0];
|
$current_ver = explode(urldecode('%0A'),$current_ver)[0];
|
||||||
$current_ver = explode(urldecode('%0D'),$current_ver)[0];
|
$current_ver = explode(urldecode('%0D'),$current_ver)[0];
|
||||||
|
$split = splitfirst($current_version, '.' . $current_ver)[0] . '.' . $current_ver;
|
||||||
//$github_version = file_get_contents('https://raw.githubusercontent.com/qkqpttgf/OneManager-php/master/version');
|
//$github_version = file_get_contents('https://raw.githubusercontent.com/qkqpttgf/OneManager-php/master/version');
|
||||||
$tmp = curl_request('https://raw.githubusercontent.com/qkqpttgf/OneManager-php/master/version');
|
$tmp = curl_request('https://raw.githubusercontent.com/qkqpttgf/OneManager-php/master/version');
|
||||||
if ($tmp['stat']==0) return 0;
|
if ($tmp['stat']==0) return 0;
|
||||||
@@ -838,7 +947,9 @@ function needUpdate()
|
|||||||
$github_ver = explode(urldecode('%0A'),$github_ver)[0];
|
$github_ver = explode(urldecode('%0A'),$github_ver)[0];
|
||||||
$github_ver = explode(urldecode('%0D'),$github_ver)[0];
|
$github_ver = explode(urldecode('%0D'),$github_ver)[0];
|
||||||
if ($current_ver != $github_ver) {
|
if ($current_ver != $github_ver) {
|
||||||
$_SERVER['github_version'] = $github_version;
|
//$_SERVER['github_version'] = $github_version;
|
||||||
|
$_SERVER['github_ver_new'] = splitfirst($github_version, $split)[0];
|
||||||
|
$_SERVER['github_ver_old'] = splitfirst($github_version, $_SERVER['github_ver_new'])[1];
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -888,9 +999,9 @@ function size_format($byte)
|
|||||||
|
|
||||||
function time_format($ISO)
|
function time_format($ISO)
|
||||||
{
|
{
|
||||||
|
if ($ISO=='') return date('Y-m-d H:i:s');
|
||||||
$ISO = str_replace('T', ' ', $ISO);
|
$ISO = str_replace('T', ' ', $ISO);
|
||||||
$ISO = str_replace('Z', ' ', $ISO);
|
$ISO = str_replace('Z', ' ', $ISO);
|
||||||
//return $ISO;
|
|
||||||
return date('Y-m-d H:i:s',strtotime($ISO . " UTC"));
|
return date('Y-m-d H:i:s',strtotime($ISO . " UTC"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -942,20 +1053,24 @@ function bigfileupload($path)
|
|||||||
$fileinfo['size'] = $_GET['filesize'];
|
$fileinfo['size'] = $_GET['filesize'];
|
||||||
$fileinfo['lastModified'] = $_GET['lastModified'];
|
$fileinfo['lastModified'] = $_GET['lastModified'];
|
||||||
$filename = spurlencode($_GET['upbigfilename'],'/');
|
$filename = spurlencode($_GET['upbigfilename'],'/');
|
||||||
$cachefilename = spurlencode( $fileinfo['path'] . '/.' . $fileinfo['lastModified'] . '_' . $fileinfo['size'] . '_' . $fileinfo['name'] . '.tmp', '/');
|
if ($fileinfo['size']>10*1024*1024) {
|
||||||
$getoldupinfo=fetch_files(path_format($path . '/' . $cachefilename));
|
$cachefilename = spurlencode( $fileinfo['path'] . '/.' . $fileinfo['lastModified'] . '_' . $fileinfo['size'] . '_' . $fileinfo['name'] . '.tmp', '/');
|
||||||
//echo json_encode($getoldupinfo, JSON_PRETTY_PRINT);
|
$getoldupinfo=fetch_files(path_format($path . '/' . $cachefilename));
|
||||||
if (isset($getoldupinfo['file'])&&$getoldupinfo['size']<5120) {
|
//echo json_encode($getoldupinfo, JSON_PRETTY_PRINT);
|
||||||
$getoldupinfo_j = curl_request($getoldupinfo[$_SERVER['DownurlStrName']]);
|
if (isset($getoldupinfo['file'])&&$getoldupinfo['size']<5120) {
|
||||||
$getoldupinfo = json_decode($getoldupinfo_j['body'], true);
|
$getoldupinfo_j = curl_request($getoldupinfo[$_SERVER['DownurlStrName']]);
|
||||||
if ( json_decode( curl_request($getoldupinfo['uploadUrl'])['body'], true)['@odata.context']!='' ) return output($getoldupinfo_j['body'], $getoldupinfo_j['stat']);
|
$getoldupinfo = json_decode($getoldupinfo_j['body'], true);
|
||||||
|
if ( json_decode( curl_request($getoldupinfo['uploadUrl'])['body'], true)['@odata.context']!='' ) return output($getoldupinfo_j['body'], $getoldupinfo_j['stat']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//if (!$_SERVER['admin']) $filename = spurlencode( $fileinfo['name'] ) . '.scfupload';
|
//if (!$_SERVER['admin']) $filename = spurlencode( $fileinfo['name'] ) . '.scfupload';
|
||||||
$response=MSAPI('createUploadSession',path_format($path1 . '/' . $filename),'{"item": { "@microsoft.graph.conflictBehavior": "fail" }}',$_SERVER['access_token']);
|
$response = MSAPI('createUploadSession', path_format($path1 . '/' . $filename), '{"item": { "@microsoft.graph.conflictBehavior": "fail" }}', $_SERVER['access_token']);
|
||||||
$responsearry = json_decode($response['body'],true);
|
if ($response['stat']<500) {
|
||||||
if (isset($responsearry['error'])) return output($response['body'], $response['stat']);
|
$responsearry = json_decode($response['body'],true);
|
||||||
$fileinfo['uploadUrl'] = $responsearry['uploadUrl'];
|
if (isset($responsearry['error'])) return output($response['body'], $response['stat']);
|
||||||
MSAPI('PUT', path_format($path1 . '/' . $cachefilename), json_encode($fileinfo, JSON_PRETTY_PRINT), $_SERVER['access_token'])['body'];
|
$fileinfo['uploadUrl'] = $responsearry['uploadUrl'];
|
||||||
|
if ($fileinfo['size']>10*1024*1024) MSAPI('PUT', path_format($path1 . '/' . $cachefilename), json_encode($fileinfo, JSON_PRETTY_PRINT), $_SERVER['access_token']);
|
||||||
|
}
|
||||||
return output($response['body'], $response['stat']);
|
return output($response['body'], $response['stat']);
|
||||||
}
|
}
|
||||||
return output('error', 400);
|
return output('error', 400);
|
||||||
@@ -963,34 +1078,34 @@ function bigfileupload($path)
|
|||||||
|
|
||||||
function adminform($name = '', $pass = '', $path = '')
|
function adminform($name = '', $pass = '', $path = '')
|
||||||
{
|
{
|
||||||
$statusCode = 401;
|
$html = '<html><head><title>' . getconstStr('AdminLogin') . '</title><meta charset=utf-8></head>';
|
||||||
$html = '<html><head><title>'.getconstStr('AdminLogin').'</title><meta charset=utf-8></head>';
|
|
||||||
if ($name!=''&&$pass!='') {
|
if ($name!=''&&$pass!='') {
|
||||||
$html .= '<body>'.getconstStr('LoginSuccess').'</body></html>';
|
$html .= '<meta http-equiv="refresh" content="3;URL=' . $path . '"><body>' . getconstStr('LoginSuccess') . '</body></html>';
|
||||||
$statusCode = 302;
|
$statusCode = 201;
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
$header = [
|
$header = [
|
||||||
'Set-Cookie' => $name.'='.$pass.'; path=/; expires='.date(DATE_COOKIE,strtotime('+1hour')),
|
'Set-Cookie' => $name . '=' . $pass . '; path=/; expires=' . date(DATE_COOKIE, strtotime('+1hour')),
|
||||||
'Location' => $path,
|
//'Location' => $path,
|
||||||
'Content-Type' => 'text/html'
|
'Content-Type' => 'text/html'
|
||||||
];
|
];
|
||||||
return output($html,$statusCode,$header);
|
return output($html, $statusCode, $header);
|
||||||
}
|
}
|
||||||
|
$statusCode = 401;
|
||||||
$html .= '
|
$html .= '
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<center><h4>'.getconstStr('InputPassword').'</h4>
|
<center><h4>' . getconstStr('InputPassword') . '</h4>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<div>
|
<div>
|
||||||
<input name="password1" type="password"/>
|
<input name="password1" type="password"/>
|
||||||
<input type="submit" value="'.getconstStr('Login').'">
|
<input type="submit" value="' . getconstStr('Login') . '">
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</center>
|
</center>
|
||||||
</div>
|
</div>
|
||||||
';
|
';
|
||||||
$html .= '</body></html>';
|
$html .= '</body></html>';
|
||||||
return output($html,$statusCode);
|
return output($html, $statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminoperate($path)
|
function adminoperate($path)
|
||||||
@@ -1439,10 +1554,11 @@ function get_refresh_token()
|
|||||||
{
|
{
|
||||||
global $constStr;
|
global $constStr;
|
||||||
global $CommonEnv;
|
global $CommonEnv;
|
||||||
|
config_oauth();
|
||||||
$envs = '';
|
$envs = '';
|
||||||
foreach ($CommonEnv as $env) $envs .= '\'' . $env . '\', ';
|
foreach ($CommonEnv as $env) $envs .= '\'' . $env . '\', ';
|
||||||
$url = path_format($_SERVER['PHP_SELF'] . '/');
|
$url = path_format($_SERVER['PHP_SELF'] . '/');
|
||||||
if (isset($_GET['authorization_code']) && isset($_GET['code'])) {
|
if (isset($_GET['install2']) && isset($_GET['code'])) {
|
||||||
$_SERVER['disktag'] = $_COOKIE['disktag'];
|
$_SERVER['disktag'] = $_COOKIE['disktag'];
|
||||||
config_oauth();
|
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']);
|
$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']);
|
||||||
@@ -1464,13 +1580,22 @@ function get_refresh_token()
|
|||||||
</script>';
|
</script>';
|
||||||
$tmptoken['refresh_token'] = $refresh_token;
|
$tmptoken['refresh_token'] = $refresh_token;
|
||||||
$tmptoken['token_expires'] = time()+7*24*60*60;
|
$tmptoken['token_expires'] = time()+7*24*60*60;
|
||||||
if (getConfig('usesharepoint')=='on') $tmptoken['siteid'] = get_siteid($ret['access_token']);
|
if (getConfig('usesharepoint')=='on') {
|
||||||
setConfig($tmptoken, $_COOKIE['disktag']);
|
$tmp1 = get_siteid($ret['access_token']);
|
||||||
savecache('access_token', $ret['access_token'], $ret['expires_in'] - 60);
|
if (isset($tmp1['stat'])) return message($tmp1['body'], 'Error', $tmp1['stat']);
|
||||||
//WaitSCFStat();
|
$tmptoken['siteid'] = $tmp1;
|
||||||
$str .= '
|
}
|
||||||
<meta http-equiv="refresh" content="5;URL=' . $url . '">';
|
$response = setConfigResponse( setConfig($tmptoken, $_COOKIE['disktag']) );
|
||||||
return message($str, getconstStr('WaitJumpIndex'));
|
if (api_error($response)) {
|
||||||
|
$html = api_error_msg($response);
|
||||||
|
$title = 'Error';
|
||||||
|
return message($html, $title, 201);
|
||||||
|
} else {
|
||||||
|
savecache('access_token', $ret['access_token'], $ret['expires_in'] - 60);
|
||||||
|
$str .= '
|
||||||
|
<meta http-equiv="refresh" content="5;URL=' . $url . '">';
|
||||||
|
return message($str, getconstStr('WaitJumpIndex'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return message('<pre>' . json_encode(json_decode($tmp['body']), JSON_PRETTY_PRINT) . '</pre>', $tmp['stat']);
|
return message('<pre>' . json_encode(json_decode($tmp['body']), JSON_PRETTY_PRINT) . '</pre>', $tmp['stat']);
|
||||||
//return message('<pre>' . json_encode($ret, JSON_PRETTY_PRINT) . '</pre>', 500);
|
//return message('<pre>' . json_encode($ret, JSON_PRETTY_PRINT) . '</pre>', 500);
|
||||||
@@ -1789,6 +1914,8 @@ function EnvOpt($needUpdate = 0)
|
|||||||
$canOneKeyUpate = 1;
|
$canOneKeyUpate = 1;
|
||||||
} elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
|
} elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
|
||||||
$canOneKeyUpate = 1;
|
$canOneKeyUpate = 1;
|
||||||
|
} elseif ($_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') {
|
||||||
|
$canOneKeyUpate = 1;
|
||||||
} elseif ($_SERVER['_APP_SHARE_DIR']==='/var/share/CFF/processrouter') {
|
} elseif ($_SERVER['_APP_SHARE_DIR']==='/var/share/CFF/processrouter') {
|
||||||
$canOneKeyUpate = 1;
|
$canOneKeyUpate = 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -1840,8 +1967,12 @@ function EnvOpt($needUpdate = 0)
|
|||||||
';
|
';
|
||||||
}
|
}
|
||||||
if ($needUpdate) {
|
if ($needUpdate) {
|
||||||
$html .= '<div style="position:relative;word-wrap: break-word;">
|
$html .= '<div style="position: relative; word-wrap: break-word;">
|
||||||
' . str_replace("\r", '<br>',$_SERVER['github_version']) . '
|
' . str_replace("\r", '<br>', $_SERVER['github_ver_new']) . '
|
||||||
|
</div>
|
||||||
|
<button onclick="document.getElementById(\'github_ver_old\').style.display=(document.getElementById(\'github_ver_old\').style.display==\'none\'?\'\':\'none\');">More...</button>
|
||||||
|
<div id="github_ver_old" style="position: relative; word-wrap: break-word; display: none">
|
||||||
|
' . str_replace("\r", '<br>', $_SERVER['github_ver_old']) . '
|
||||||
</div>';
|
</div>';
|
||||||
}/* else {
|
}/* else {
|
||||||
$html .= getconstStr('NotNeedUpdate');
|
$html .= getconstStr('NotNeedUpdate');
|
||||||
@@ -2253,7 +2384,7 @@ function render_list($path = '', $files = '')
|
|||||||
if ($_SERVER['admin'] or !isHideFile($file['name'])) {
|
if ($_SERVER['admin'] or !isHideFile($file['name'])) {
|
||||||
$filenum++;
|
$filenum++;
|
||||||
$FolderListStr = str_replace('<!--FileEncodeReplaceUrl-->', path_format($_SERVER['base_disk_path'] . '/' . $path . '/' . encode_str_replace($file['name'])), $FolderList);
|
$FolderListStr = str_replace('<!--FileEncodeReplaceUrl-->', path_format($_SERVER['base_disk_path'] . '/' . $path . '/' . encode_str_replace($file['name'])), $FolderList);
|
||||||
$FolderListStr = str_replace('<!--FileEncodeReplaceName-->', str_replace('&','&', $file['name']), $FolderListStr);
|
$FolderListStr = str_replace('<!--FileEncodeReplaceName-->', str_replace('&','&', $file['showname']?$file['showname']:$file['name']), $FolderListStr);
|
||||||
$FolderListStr = str_replace('<!--lastModifiedDateTime-->', time_format($file['lastModifiedDateTime']), $FolderListStr);
|
$FolderListStr = str_replace('<!--lastModifiedDateTime-->', time_format($file['lastModifiedDateTime']), $FolderListStr);
|
||||||
$FolderListStr = str_replace('<!--size-->', size_format($file['size']), $FolderListStr);
|
$FolderListStr = str_replace('<!--size-->', size_format($file['size']), $FolderListStr);
|
||||||
while (strpos($FolderListStr, '<!--filenum-->')) $FolderListStr = str_replace('<!--filenum-->', $filenum, $FolderListStr);
|
while (strpos($FolderListStr, '<!--filenum-->')) $FolderListStr = str_replace('<!--filenum-->', $filenum, $FolderListStr);
|
||||||
@@ -2433,28 +2564,59 @@ function render_list($path = '', $files = '')
|
|||||||
$html = $tmp[0];
|
$html = $tmp[0];
|
||||||
$tmp = splitfirst($tmp[1], '<!--BackgroundEnd-->');
|
$tmp = splitfirst($tmp[1], '<!--BackgroundEnd-->');
|
||||||
if (getConfig('background')) {
|
if (getConfig('background')) {
|
||||||
$background = str_replace('<!--BackgroundUrl-->', getConfig('background'), $tmp[0]);
|
$html .= str_replace('<!--BackgroundUrl-->', getConfig('background'), $tmp[0]);
|
||||||
}
|
}
|
||||||
$html .= $background . $tmp[1];
|
$html .= $tmp[1];
|
||||||
|
|
||||||
|
$tmp = splitfirst($html, '<!--BackgroundMStart-->');
|
||||||
|
$html = $tmp[0];
|
||||||
|
$tmp = splitfirst($tmp[1], '<!--BackgroundMEnd-->');
|
||||||
|
if (getConfig('backgroundm')) {
|
||||||
|
$html .= str_replace('<!--BackgroundMUrl-->', getConfig('backgroundm'), $tmp[0]);
|
||||||
|
}
|
||||||
|
$html .= $tmp[1];
|
||||||
|
|
||||||
$tmp = splitfirst($html, '<!--PathArrayStart-->');
|
$tmp = splitfirst($html, '<!--PathArrayStart-->');
|
||||||
$html = $tmp[0];
|
$html = $tmp[0];
|
||||||
$tmp = splitfirst($tmp[1], '<!--PathArrayEnd-->');
|
if ($tmp[1]!='') {
|
||||||
$PathArrayStr = $tmp[0];
|
$tmp = splitfirst($tmp[1], '<!--PathArrayEnd-->');
|
||||||
$tmp_path = str_replace('%23', '#', str_replace('&','&', $path));
|
$PathArrayStr = $tmp[0];
|
||||||
$tmp_url = $_SERVER['base_disk_path'];
|
$tmp_url = $_SERVER['base_disk_path'];
|
||||||
while ($tmp_path!='') {
|
$tmp_path = str_replace('&','&', substr(urldecode($_SERVER['PHP_SELF']), strlen($tmp_url)));
|
||||||
$tmp1 = splitfirst($tmp_path, '/');
|
while ($tmp_path!='') {
|
||||||
$folder1 = $tmp1[0];
|
$tmp1 = splitfirst($tmp_path, '/');
|
||||||
if ($folder1!='') {
|
$folder1 = $tmp1[0];
|
||||||
$tmp_url .= $folder1 . '/';
|
if ($folder1!='') {
|
||||||
$PathArrayStr1 = str_replace('<!--PathArrayLink-->', ($folder1==$files['name']?'':$tmp_url), $PathArrayStr);
|
$tmp_url .= $folder1 . '/';
|
||||||
$PathArrayStr1 = str_replace('<!--PathArrayName-->', $folder1, $PathArrayStr1);
|
$PathArrayStr1 = str_replace('<!--PathArrayLink-->', ($folder1==$files['name']?'':$tmp_url), $PathArrayStr);
|
||||||
$html .= $PathArrayStr1;
|
$PathArrayStr1 = str_replace('<!--PathArrayName-->', $folder1, $PathArrayStr1);
|
||||||
|
$html .= $PathArrayStr1;
|
||||||
|
}
|
||||||
|
$tmp_path = $tmp1[1];
|
||||||
}
|
}
|
||||||
$tmp_path = $tmp1[1];
|
$html .= $tmp[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmp = splitfirst($html, '<!--DiskPathArrayStart-->');
|
||||||
|
$html = $tmp[0];
|
||||||
|
if ($tmp[1]!='') {
|
||||||
|
$tmp = splitfirst($tmp[1], '<!--DiskPathArrayEnd-->');
|
||||||
|
$PathArrayStr = $tmp[0];
|
||||||
|
$tmp_url = $_SERVER['base_path'];
|
||||||
|
$tmp_path = str_replace('&','&', substr(urldecode($_SERVER['PHP_SELF']), strlen($tmp_url)));
|
||||||
|
while ($tmp_path!='') {
|
||||||
|
$tmp1 = splitfirst($tmp_path, '/');
|
||||||
|
$folder1 = $tmp1[0];
|
||||||
|
if ($folder1!='') {
|
||||||
|
$tmp_url .= $folder1 . '/';
|
||||||
|
$PathArrayStr1 = str_replace('<!--PathArrayLink-->', ($folder1==$files['name']?'':$tmp_url), $PathArrayStr);
|
||||||
|
$PathArrayStr1 = str_replace('<!--PathArrayName-->', ($folder1==$_SERVER['disktag']?(getConfig('diskname')==''?$_SERVER['disktag']:getConfig('diskname')):$folder1), $PathArrayStr1);
|
||||||
|
$html .= $PathArrayStr1;
|
||||||
|
}
|
||||||
|
$tmp_path = $tmp1[1];
|
||||||
|
}
|
||||||
|
$html .= $tmp[1];
|
||||||
}
|
}
|
||||||
$html .= $tmp[1];
|
|
||||||
|
|
||||||
$tmp = splitfirst($html, '<!--SelectLanguageStart-->');
|
$tmp = splitfirst($html, '<!--SelectLanguageStart-->');
|
||||||
$html = $tmp[0];
|
$html = $tmp[0];
|
||||||
@@ -2479,8 +2641,8 @@ function render_list($path = '', $files = '')
|
|||||||
$tmp = splitfirst($html, '<!--BackArrowStart-->');
|
$tmp = splitfirst($html, '<!--BackArrowStart-->');
|
||||||
$html = $tmp[0];
|
$html = $tmp[0];
|
||||||
$tmp = splitfirst($tmp[1], '<!--BackArrowEnd-->');
|
$tmp = splitfirst($tmp[1], '<!--BackArrowEnd-->');
|
||||||
if ($path !== '/') {
|
$current_url = path_format($_SERVER['PHP_SELF'] . '/');
|
||||||
$current_url = $_SERVER['PHP_SELF'];
|
if ($current_url !== $_SERVER['base_path']) {
|
||||||
while (substr($current_url, -1) === '/') {
|
while (substr($current_url, -1) === '/') {
|
||||||
$current_url = substr($current_url, 0, -1);
|
$current_url = substr($current_url, 0, -1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ $constStr = [
|
|||||||
'en-us' => [
|
'en-us' => [
|
||||||
'admin' => 'The admin password, Login button will not show when empty',
|
'admin' => 'The admin password, Login button will not show when empty',
|
||||||
'adminloginpage' => 'if set, the Login button will not display, and the login page no longer \'?admin\', it is \'?{this value}\'.',
|
'adminloginpage' => 'if set, the Login button will not display, and the login page no longer \'?admin\', it is \'?{this value}\'.',
|
||||||
|
'autoJumpFirstDisk' => 'used in multy disks, if 1, auto jump to first disk',
|
||||||
'customScript' => '<script> in all pages, e.g. http turn to https',
|
'customScript' => '<script> in all pages, e.g. http turn to https',
|
||||||
'customCss' => '<style> in <head>',
|
'customCss' => '<style> in <head>',
|
||||||
'customTheme' => 'an url of html',
|
'customTheme' => 'an url of html',
|
||||||
@@ -79,6 +80,7 @@ $constStr = [
|
|||||||
'disableChangeTheme' => 'if 1, the Theme selection button will not display',
|
'disableChangeTheme' => 'if 1, the Theme selection button will not display',
|
||||||
'downloadencrypt' => '0 or 1. if 1, the files in encrypt folder can be downloaded without password',
|
'downloadencrypt' => '0 or 1. if 1, the files in encrypt folder can be downloaded without password',
|
||||||
'background' => 'Set an url as background photo.',
|
'background' => 'Set an url as background photo.',
|
||||||
|
'backgroundm' => 'Set an url as background in mobile phone.',
|
||||||
'theme' => 'Select theme.',
|
'theme' => 'Select theme.',
|
||||||
'timezone' => 'Set default timezone.',
|
'timezone' => 'Set default timezone.',
|
||||||
'guestup_path' => 'Set guest upload dir, before set this, the files in this dir will show as normal.',
|
'guestup_path' => 'Set guest upload dir, before set this, the files in this dir will show as normal.',
|
||||||
@@ -92,6 +94,7 @@ $constStr = [
|
|||||||
'zh-cn' => [
|
'zh-cn' => [
|
||||||
'admin' => '管理密码,不添加时不显示登录页面且无法登录。',
|
'admin' => '管理密码,不添加时不显示登录页面且无法登录。',
|
||||||
'adminloginpage' => '如果设置,登录按钮及页面隐藏。管理登录的页面不再是\'?admin\',而是\'?此设置的值\'。',
|
'adminloginpage' => '如果设置,登录按钮及页面隐藏。管理登录的页面不再是\'?admin\',而是\'?此设置的值\'。',
|
||||||
|
'autoJumpFirstDisk' => '用于多盘,如果设1,将会自动跳到第一个盘。',
|
||||||
'customScript' => '<script>,在所有页都会存在,例如放一个http跳转https',
|
'customScript' => '<script>,在所有页都会存在,例如放一个http跳转https',
|
||||||
'customCss' => '<style>,在<head>最后面',
|
'customCss' => '<style>,在<head>最后面',
|
||||||
'customTheme' => 'html格式的主题的url',
|
'customTheme' => 'html格式的主题的url',
|
||||||
@@ -102,6 +105,7 @@ $constStr = [
|
|||||||
'disableChangeTheme' => '如果填 1, 主题选择切换将被隐藏',
|
'disableChangeTheme' => '如果填 1, 主题选择切换将被隐藏',
|
||||||
'downloadencrypt' => '0 或 1。如果 1, 那加密目录内的文件可以不需要密码就能下载。',
|
'downloadencrypt' => '0 或 1。如果 1, 那加密目录内的文件可以不需要密码就能下载。',
|
||||||
'background' => '设置一个url作为背景。',
|
'background' => '设置一个url作为背景。',
|
||||||
|
'backgroundm' => '设置一个url作为手机用的背景。',
|
||||||
'theme' => '选择一个主题。',
|
'theme' => '选择一个主题。',
|
||||||
'timezone' => '设置默认时区。',
|
'timezone' => '设置默认时区。',
|
||||||
'guestup_path' => '设置游客上传路径(图床路径),不设置这个值时该目录内容会正常列文件出来,设置后只有上传界面,不显示其中文件(登录后显示)。',
|
'guestup_path' => '设置游客上传路径(图床路径),不设置这个值时该目录内容会正常列文件出来,设置后只有上传界面,不显示其中文件(登录后显示)。',
|
||||||
@@ -792,4 +796,12 @@ $constStr = [
|
|||||||
'en-us' => 'Query Branchs',
|
'en-us' => 'Query Branchs',
|
||||||
'zh-cn' => '查询分支',
|
'zh-cn' => '查询分支',
|
||||||
],
|
],
|
||||||
|
'ONEMANAGER_CONFIG_SAVE_ENV' => [
|
||||||
|
'en-us' => 'Config save in Environments',
|
||||||
|
'zh-cn' => '配置保存在环境变量',
|
||||||
|
],
|
||||||
|
'ONEMANAGER_CONFIG_SAVE_FILE' => [
|
||||||
|
'en-us' => 'Config save in code file, may cause fee',
|
||||||
|
'zh-cn' => '配置保存在代码文件中,可能产生费用',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -6,11 +6,18 @@ include 'common.php';
|
|||||||
|
|
||||||
//echo '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
|
//echo '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
|
||||||
if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
|
if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
|
||||||
include 'platform/TencentSCF.php';
|
if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/TencentSCF_file.php';
|
||||||
|
else include 'platform/TencentSCF_env.php';
|
||||||
} elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
|
} elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
|
||||||
include 'platform/AliyunFC.php';
|
include 'platform/AliyunFC.php';
|
||||||
} elseif ($_SERVER['_APP_SHARE_DIR']=='/var/share/CFF/processrouter') {
|
} elseif ($_SERVER['_APP_SHARE_DIR']=='/var/share/CFF/processrouter') {
|
||||||
include 'platform/HuaweiFG.php';
|
//if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/HuaweiFG_file.php';
|
||||||
|
//else include 'platform/HuaweiFG_env.php';
|
||||||
|
echo 'FG' . PHP_EOL;
|
||||||
|
} elseif ($_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') {
|
||||||
|
//set_include_path(get_include_path() . PATH_SEPARATOR . '/opt/php');
|
||||||
|
//include 'BaiduBce.phar';
|
||||||
|
include 'platform/BaiduCFC.php';
|
||||||
} elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') {
|
} elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') {
|
||||||
include 'platform/Heroku.php';
|
include 'platform/Heroku.php';
|
||||||
$path = getpath();
|
$path = getpath();
|
||||||
@@ -57,7 +64,7 @@ function main_handler($event, $context)
|
|||||||
return main($path);
|
return main($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aliyun FC & Huawei FG
|
// Aliyun FC & Huawei FG & Baidu CFC
|
||||||
function handler($event, $context)
|
function handler($event, $context)
|
||||||
{
|
{
|
||||||
if (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
|
if (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
|
||||||
@@ -90,6 +97,9 @@ function handler($event, $context)
|
|||||||
// Huawei FG
|
// Huawei FG
|
||||||
global $contextUserData;
|
global $contextUserData;
|
||||||
$contextUserData = $context;
|
$contextUserData = $context;
|
||||||
|
if ($context->getUserData('ONEMANAGER_CONFIG_SAVE')=='file') include_once 'platform/HuaweiFG_file.php';
|
||||||
|
else include_once 'platform/HuaweiFG_env.php';
|
||||||
|
|
||||||
$event = json_decode(json_encode($event), true);
|
$event = json_decode(json_encode($event), true);
|
||||||
if ($event['isBase64Encoded']) $event['body'] = base64_decode($event['body']);
|
if ($event['isBase64Encoded']) $event['body'] = base64_decode($event['body']);
|
||||||
|
|
||||||
@@ -103,6 +113,27 @@ function handler($event, $context)
|
|||||||
$path = GetPathSetting($event, $context);
|
$path = GetPathSetting($event, $context);
|
||||||
|
|
||||||
return main($path);
|
return main($path);
|
||||||
|
|
||||||
|
} elseif ($_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') {
|
||||||
|
// Baidu CFC
|
||||||
|
//$html = '<pre>'. json_encode($event, JSON_PRETTY_PRINT).'</pre>';
|
||||||
|
//$html .= '<pre>'. json_encode($context, JSON_PRETTY_PRINT).'</pre>';
|
||||||
|
//$html .= '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
|
||||||
|
//$html .= $event['path'];
|
||||||
|
//$html .= $context['functionBrn'];
|
||||||
|
//return json_encode(output($html), JSON_FORCE_OBJECT);
|
||||||
|
|
||||||
|
printInput($event, $context);
|
||||||
|
unset($_POST);
|
||||||
|
unset($_GET);
|
||||||
|
unset($_COOKIE);
|
||||||
|
unset($_SERVER);
|
||||||
|
GetGlobalVariable($event);
|
||||||
|
//echo '<pre>'. json_encode($_COOKIE, JSON_PRETTY_PRINT).'</pre>';
|
||||||
|
$path = GetPathSetting($event, $context);
|
||||||
|
|
||||||
|
return json_encode(main($path), JSON_FORCE_OBJECT);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+100
-67
@@ -2,8 +2,6 @@
|
|||||||
// https://help.aliyun.com/document_detail/53252.html
|
// https://help.aliyun.com/document_detail/53252.html
|
||||||
// https://github.com/aliyun/fc-php-sdk/blob/master/src/AliyunFC/Client.php
|
// https://github.com/aliyun/fc-php-sdk/blob/master/src/AliyunFC/Client.php
|
||||||
|
|
||||||
use AliyunFC\Client;
|
|
||||||
|
|
||||||
function printInput($event, $context)
|
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);
|
if (strlen(json_encode($event['body']))>500) $event['body']=substr($event['body'],0,strpos($event['body'],'base64')+30) . '...Too Long!...' . substr($event['body'],-50);
|
||||||
@@ -61,11 +59,11 @@ function getConfig($str, $disktag = '')
|
|||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||||
$env = json_decode(getenv($disktag), true);
|
$env = json_decode(getenv($disktag), true);
|
||||||
if (isset($env[$str])) {
|
if (isset($env[$str])) {
|
||||||
if (in_array($str, $Base64Env)) return equal_replace($env[$str],1);
|
if (in_array($str, $Base64Env)) return base64y_decode($env[$str]);
|
||||||
else return $env[$str];
|
else return $env[$str];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (in_array($str, $Base64Env)) return equal_replace(getenv($str),1);
|
if (in_array($str, $Base64Env)) return base64y_decode(getenv($str));
|
||||||
else return getenv($str);
|
else return getenv($str);
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
@@ -83,7 +81,7 @@ function setConfig($arr, $disktag = '')
|
|||||||
$oparetdisk = 0;
|
$oparetdisk = 0;
|
||||||
foreach ($arr as $k => $v) {
|
foreach ($arr as $k => $v) {
|
||||||
if (in_array($k, $InnerEnv)) {
|
if (in_array($k, $InnerEnv)) {
|
||||||
if (in_array($k, $Base64Env)) $diskconfig[$k] = equal_replace($v);
|
if (in_array($k, $Base64Env)) $diskconfig[$k] = base64y_encode($v);
|
||||||
else $diskconfig[$k] = $v;
|
else $diskconfig[$k] = $v;
|
||||||
$indisk = 1;
|
$indisk = 1;
|
||||||
} elseif ($k=='disktag_add') {
|
} elseif ($k=='disktag_add') {
|
||||||
@@ -94,7 +92,7 @@ function setConfig($arr, $disktag = '')
|
|||||||
$tmp[$v] = '';
|
$tmp[$v] = '';
|
||||||
$oparetdisk = 1;
|
$oparetdisk = 1;
|
||||||
} else {
|
} else {
|
||||||
if (in_array($k, $Base64Env)) $tmp[$k] = equal_replace($v);
|
if (in_array($k, $Base64Env)) $tmp[$k] = base64y_encode($v);
|
||||||
else $tmp[$k] = $v;
|
else $tmp[$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,7 +119,12 @@ function install()
|
|||||||
global $constStr;
|
global $constStr;
|
||||||
if ($_GET['install2']) {
|
if ($_GET['install2']) {
|
||||||
$tmp['admin'] = $_POST['admin'];
|
$tmp['admin'] = $_POST['admin'];
|
||||||
setConfig($tmp);
|
$response = setConfigResponse( setConfig($tmp) );
|
||||||
|
if (api_error($response)) {
|
||||||
|
$html = api_error_msg($response);
|
||||||
|
$title = 'Error';
|
||||||
|
return message($html, $title, 201);
|
||||||
|
}
|
||||||
if (needUpdate()) {
|
if (needUpdate()) {
|
||||||
OnekeyUpate();
|
OnekeyUpate();
|
||||||
return message('update to github version, reinstall.
|
return message('update to github version, reinstall.
|
||||||
@@ -155,7 +158,7 @@ function install()
|
|||||||
$AccessKeySecret = $_POST['AccessKeySecret'];
|
$AccessKeySecret = $_POST['AccessKeySecret'];
|
||||||
$tmp['AccessKeySecret'] = $AccessKeySecret;
|
$tmp['AccessKeySecret'] = $AccessKeySecret;
|
||||||
}
|
}
|
||||||
$response = SetbaseConfig($tmp, $_SERVER['accountId'], $_SERVER['region'], $_SERVER['service_name'], $_SERVER['function_name'], $AccessKeyID, $AccessKeySecret);
|
$response = setConfigResponse( SetbaseConfig($tmp, $_SERVER['accountId'], $_SERVER['region'], $_SERVER['service_name'], $_SERVER['function_name'], $AccessKeyID, $AccessKeySecret) );
|
||||||
if (api_error($response)) {
|
if (api_error($response)) {
|
||||||
$html = api_error_msg($response);
|
$html = api_error_msg($response);
|
||||||
$title = 'Error';
|
$title = 'Error';
|
||||||
@@ -234,26 +237,71 @@ language:<br>';
|
|||||||
return message($html, $title, 201);
|
return message($html, $title, 201);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getfunctioninfo($accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)
|
function FCAPI2016($config, $Method, $data = '')
|
||||||
{
|
{
|
||||||
$fcClient = new Client([
|
$accountId = $config['accountId'];
|
||||||
"endpoint" => 'https://'.$accountId.'.'.$region.'.fc.aliyuncs.com',
|
$region = $config['region'];
|
||||||
"accessKeyID" => $AccessKeyID,
|
$service_name = $config['service_name'];
|
||||||
"accessKeySecret" => $AccessKeySecret
|
$function_name = $config['function_name'];
|
||||||
]);
|
$AccessKeyID = $config['AccessKeyID'];
|
||||||
return $fcClient->getFunction($service_name, $function_name);
|
$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)
|
function updateEnvironment($Envs, $accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)
|
||||||
{
|
{
|
||||||
//print_r($Envs);
|
//print_r($Envs);
|
||||||
$fcClient = new Client([
|
$config['accountId'] = $accountId;
|
||||||
"endpoint" => 'https://'.$accountId.'.'.$region.'.fc.aliyuncs.com',
|
$config['region'] = $region;
|
||||||
"accessKeyID" => $AccessKeyID,
|
$config['service_name'] = $service_name;
|
||||||
"accessKeySecret" => $AccessKeySecret
|
$config['function_name'] = $function_name;
|
||||||
]);
|
$config['AccessKeyID'] = $AccessKeyID;
|
||||||
$tmp = $fcClient->getFunction($service_name, $function_name)['data'];
|
$config['AccessKeySecret'] = $AccessKeySecret;
|
||||||
//$tmp = getfunctioninfo($accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)['data'];
|
|
||||||
|
$tmp = json_decode(getfunctioninfo($config), true);
|
||||||
foreach ($tmp['environmentVariables'] as $key => $value ) {
|
foreach ($tmp['environmentVariables'] as $key => $value ) {
|
||||||
$tmp_env[$key] = $value;
|
$tmp_env[$key] = $value;
|
||||||
}
|
}
|
||||||
@@ -263,27 +311,20 @@ function updateEnvironment($Envs, $accountId, $region, $service_name, $function_
|
|||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
||||||
ksort($tmp_env);
|
ksort($tmp_env);
|
||||||
|
|
||||||
$tmpdata['functionName'] = $tmp['functionName'];
|
|
||||||
$tmpdata['description'] = $tmp['description'];
|
|
||||||
$tmpdata['memorySize'] = $tmp['memorySize'];
|
|
||||||
$tmpdata['timeout'] = $tmp['timeout'];
|
|
||||||
$tmpdata['runtime'] = $tmp['runtime'];
|
|
||||||
$tmpdata['handler'] = $tmp['handler'];
|
|
||||||
$tmpdata['environmentVariables'] = $tmp_env;
|
$tmpdata['environmentVariables'] = $tmp_env;
|
||||||
$tmpdata['code']['zipFile'] = base64_encode( file_get_contents($fcClient->getFunctionCode($service_name, $function_name)['data']['url']) );
|
return FCAPI2016($config, 'PUT', json_encode($tmpdata));
|
||||||
return $fcClient->updateFunction($service_name, $function_name, $tmpdata);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function SetbaseConfig($Envs, $accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)
|
function SetbaseConfig($Envs, $accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)
|
||||||
{
|
{
|
||||||
//echo json_encode($Envs,JSON_PRETTY_PRINT);
|
$config['accountId'] = $accountId;
|
||||||
$fcClient = new Client([
|
$config['region'] = $region;
|
||||||
"endpoint" => 'https://'.$accountId.'.'.$region.'.fc.aliyuncs.com',
|
$config['service_name'] = $service_name;
|
||||||
"accessKeyID" => $AccessKeyID,
|
$config['function_name'] = $function_name;
|
||||||
"accessKeySecret" => $AccessKeySecret
|
$config['AccessKeyID'] = $AccessKeyID;
|
||||||
]);
|
$config['AccessKeySecret'] = $AccessKeySecret;
|
||||||
$tmp = $fcClient->getFunction($service_name, $function_name)['data'];
|
|
||||||
// $tmp = getfunctioninfo($accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)['data'];
|
$tmp = json_decode(getfunctioninfo($config), true);
|
||||||
foreach ($tmp['environmentVariables'] as $key => $value ) {
|
foreach ($tmp['environmentVariables'] as $key => $value ) {
|
||||||
$tmp_env[$key] = $value;
|
$tmp_env[$key] = $value;
|
||||||
}
|
}
|
||||||
@@ -293,59 +334,51 @@ function SetbaseConfig($Envs, $accountId, $region, $service_name, $function_name
|
|||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
||||||
ksort($tmp_env);
|
ksort($tmp_env);
|
||||||
|
|
||||||
$tmpdata['functionName'] = $function_name;
|
$tmpdata['description'] = 'Onedrive index and manager in Aliyun FC.';
|
||||||
$tmpdata['description'] = 'Onedrive index and manager in Ali FC.';
|
|
||||||
$tmpdata['memorySize'] = 128;
|
$tmpdata['memorySize'] = 128;
|
||||||
$tmpdata['timeout'] = 30;
|
$tmpdata['timeout'] = 30;
|
||||||
$tmpdata['runtime'] = 'php7.2';
|
|
||||||
$tmpdata['handler'] = 'index.handler';
|
|
||||||
$tmpdata['environmentVariables'] = $tmp_env;
|
$tmpdata['environmentVariables'] = $tmp_env;
|
||||||
$tmpdata['code']['zipFile'] = base64_encode( file_get_contents($fcClient->getFunctionCode($service_name, $function_name)['data']['url']) );
|
|
||||||
return $fcClient->updateFunction($service_name, $function_name, $tmpdata);
|
return FCAPI2016($config, 'PUT', json_encode($tmpdata));
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateProgram($accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret, $source)
|
function updateProgram($accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret, $source)
|
||||||
{
|
{
|
||||||
//WaitSCFStat();
|
$config['accountId'] = $accountId;
|
||||||
$fcClient = new Client([
|
$config['region'] = $region;
|
||||||
"endpoint" => 'https://'.$accountId.'.'.$region.'.fc.aliyuncs.com',
|
$config['service_name'] = $service_name;
|
||||||
"accessKeyID" => $AccessKeyID,
|
$config['function_name'] = $function_name;
|
||||||
"accessKeySecret" => $AccessKeySecret
|
$config['AccessKeyID'] = $AccessKeyID;
|
||||||
]);
|
$config['AccessKeySecret'] = $AccessKeySecret;
|
||||||
$tmp = $fcClient->getFunction($service_name, $function_name)['data'];
|
|
||||||
//$tmp = getfunctioninfo($accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)['data'];
|
$tmp = json_decode(getfunctioninfo($config), true);
|
||||||
|
|
||||||
$tmpdata['functionName'] = $tmp['functionName'];
|
|
||||||
$tmpdata['description'] = $tmp['description'];
|
|
||||||
$tmpdata['memorySize'] = $tmp['memorySize'];
|
|
||||||
$tmpdata['timeout'] = $tmp['timeout'];
|
|
||||||
$tmpdata['runtime'] = $tmp['runtime'];
|
|
||||||
$tmpdata['handler'] = $tmp['handler'];
|
|
||||||
$tmpdata['environmentVariables'] = $tmp['environmentVariables'];
|
|
||||||
$tmpdata['code']['zipFile'] = base64_encode( file_get_contents($source) );
|
$tmpdata['code']['zipFile'] = base64_encode( file_get_contents($source) );
|
||||||
|
|
||||||
return $fcClient->updateFunction($service_name, $function_name, $tmpdata);
|
return FCAPI2016($config, 'PUT', json_encode($tmpdata));
|
||||||
}
|
}
|
||||||
|
|
||||||
function api_error($response)
|
function api_error($response)
|
||||||
{
|
{
|
||||||
return !isset($response['data']);
|
return isset($response['ErrorMessage']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function api_error_msg($response)
|
function api_error_msg($response)
|
||||||
{
|
{
|
||||||
return $response;
|
return $response['ErrorCode'] . '<br>
|
||||||
return $response['Error']['Code'] . '<br>
|
' . $response['ErrorMessage'] . '<br><br>
|
||||||
' . $response['Error']['Message'] . '<br><br>
|
|
||||||
|
accountId:' . $_SERVER['accountId'] . '<br>
|
||||||
|
region:' . $_SERVER['region'] . '<br>
|
||||||
|
service_name:' . $_SERVER['service_name'] . '<br>
|
||||||
function_name:' . $_SERVER['function_name'] . '<br>
|
function_name:' . $_SERVER['function_name'] . '<br>
|
||||||
Region:' . $_SERVER['Region'] . '<br>
|
|
||||||
namespace:' . $_SERVER['namespace'] . '<br>
|
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function setConfigResponse($response)
|
function setConfigResponse($response)
|
||||||
{
|
{
|
||||||
return $response;
|
return json_decode($response, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||||
|
|||||||
@@ -0,0 +1,407 @@
|
|||||||
|
<?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['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));
|
||||||
|
}
|
||||||
|
$_SERVER['HTTP_USER_AGENT'] = $event['headers']['User-Agent'];
|
||||||
|
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
|
||||||
|
$_SERVER['BCE_CFC_RUNTIME_NAME'] = 'php7';
|
||||||
|
}
|
||||||
|
|
||||||
|
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'];
|
||||||
|
if (substr($path,-1)=='/') $path=substr($path,0,-1);
|
||||||
|
$_SERVER['is_guestup_path'] = is_guestup_path($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'];
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getConfig($str, $disktag = '')
|
||||||
|
{
|
||||||
|
global $InnerEnv;
|
||||||
|
global $Base64Env;
|
||||||
|
if (in_array($str, $InnerEnv)) {
|
||||||
|
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||||
|
$env = json_decode(getenv($disktag), true);
|
||||||
|
if (isset($env[$str])) {
|
||||||
|
if (in_array($str, $Base64Env)) return base64y_decode($env[$str]);
|
||||||
|
else return $env[$str];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (in_array($str, $Base64Env)) return base64y_decode(getenv($str));
|
||||||
|
else return getenv($str);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function setConfig($arr, $disktag = '')
|
||||||
|
{
|
||||||
|
global $InnerEnv;
|
||||||
|
global $Base64Env;
|
||||||
|
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||||
|
$disktags = explode("|",getConfig('disktag'));
|
||||||
|
$diskconfig = json_decode(getenv($disktag), true);
|
||||||
|
$tmp = [];
|
||||||
|
$indisk = 0;
|
||||||
|
$oparetdisk = 0;
|
||||||
|
foreach ($arr as $k => $v) {
|
||||||
|
if (in_array($k, $InnerEnv)) {
|
||||||
|
if (in_array($k, $Base64Env)) $diskconfig[$k] = base64y_encode($v);
|
||||||
|
else $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 {
|
||||||
|
if (in_array($k, $Base64Env)) $tmp[$k] = base64y_encode($v);
|
||||||
|
else $tmp[$k] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($indisk) {
|
||||||
|
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||||
|
ksort($diskconfig);
|
||||||
|
$tmp[$disktag] = json_encode($diskconfig);
|
||||||
|
}
|
||||||
|
if ($oparetdisk) {
|
||||||
|
$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="text" 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 = 'Error';
|
||||||
|
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);
|
||||||
|
|
||||||
|
$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 = var_dump($response);
|
||||||
|
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($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||||
|
{
|
||||||
|
$source = '/tmp/code.zip';
|
||||||
|
$outPath = '/tmp/';
|
||||||
|
|
||||||
|
// 从github下载对应tar.gz,并解压
|
||||||
|
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||||
|
$tarfile = '/tmp/github.tar.gz';
|
||||||
|
file_put_contents($tarfile, file_get_contents($url));
|
||||||
|
$phar = new PharData($tarfile);
|
||||||
|
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
||||||
|
|
||||||
|
// 获取包中目录名
|
||||||
|
$tmp = scandir('phar://'.$tarfile);
|
||||||
|
$name = $auth.'-'.$project;
|
||||||
|
foreach ($tmp as $f) {
|
||||||
|
if ( substr($f, 0, strlen($name)) == $name) {
|
||||||
|
$outPath .= $f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 放入配置文件
|
||||||
|
//file_put_contents($outPath . '/config.php', file_get_contents(__DIR__.'/../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('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($path);
|
||||||
|
}
|
||||||
+4
-4
@@ -46,11 +46,11 @@ function getConfig($str, $disktag = '')
|
|||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||||
$env = json_decode(getenv($disktag), true);
|
$env = json_decode(getenv($disktag), true);
|
||||||
if (isset($env[$str])) {
|
if (isset($env[$str])) {
|
||||||
if (in_array($str, $Base64Env)) return equal_replace($env[$str],1);
|
if (in_array($str, $Base64Env)) return base64y_decode($env[$str]);
|
||||||
else return $env[$str];
|
else return $env[$str];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (in_array($str, $Base64Env)) return equal_replace(getenv($str),1);
|
if (in_array($str, $Base64Env)) return base64y_decode(getenv($str));
|
||||||
else return getenv($str);
|
else return getenv($str);
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
@@ -68,7 +68,7 @@ function setConfig($arr, $disktag = '')
|
|||||||
$oparetdisk = 0;
|
$oparetdisk = 0;
|
||||||
foreach ($arr as $k => $v) {
|
foreach ($arr as $k => $v) {
|
||||||
if (in_array($k, $InnerEnv)) {
|
if (in_array($k, $InnerEnv)) {
|
||||||
if (in_array($k, $Base64Env)) $diskconfig[$k] = equal_replace($v);
|
if (in_array($k, $Base64Env)) $diskconfig[$k] = base64y_encode($v);
|
||||||
else $diskconfig[$k] = $v;
|
else $diskconfig[$k] = $v;
|
||||||
$indisk = 1;
|
$indisk = 1;
|
||||||
} elseif ($k=='disktag_add') {
|
} elseif ($k=='disktag_add') {
|
||||||
@@ -79,7 +79,7 @@ function setConfig($arr, $disktag = '')
|
|||||||
$tmp[$v] = '';
|
$tmp[$v] = '';
|
||||||
$oparetdisk = 1;
|
$oparetdisk = 1;
|
||||||
} else {
|
} else {
|
||||||
if (in_array($k, $Base64Env)) $tmp[$k] = equal_replace($v);
|
if (in_array($k, $Base64Env)) $tmp[$k] = base64y_encode($v);
|
||||||
else $tmp[$k] = $v;
|
else $tmp[$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,464 @@
|
|||||||
|
<?php
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
$_SERVER['HTTP_USER_AGENT'] = $event['headers']['user-agent'];
|
||||||
|
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
|
||||||
|
$_SERVER['_APP_SHARE_DIR'] = '/var/share/CFF/processrouter';
|
||||||
|
}
|
||||||
|
|
||||||
|
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'][''].'/');
|
||||||
|
$_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'] = '/';
|
||||||
|
}
|
||||||
|
if (substr($path,-1)=='/') $path=substr($path,0,-1);
|
||||||
|
$_SERVER['is_guestup_path'] = is_guestup_path($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'];
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getConfig($str, $disktag = '')
|
||||||
|
{
|
||||||
|
global $InnerEnv;
|
||||||
|
global $Base64Env;
|
||||||
|
global $contextUserData;
|
||||||
|
if (in_array($str, $InnerEnv)) {
|
||||||
|
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||||
|
$env = json_decode($contextUserData->getUserData($disktag), true);
|
||||||
|
if (isset($env[$str])) {
|
||||||
|
if (in_array($str, $Base64Env)) return base64y_decode($env[$str]);
|
||||||
|
else return $env[$str];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (in_array($str, $Base64Env)) return base64y_decode($contextUserData->getUserData($str));
|
||||||
|
else return $contextUserData->getUserData($str);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function setConfig($arr, $disktag = '')
|
||||||
|
{
|
||||||
|
global $InnerEnv;
|
||||||
|
global $Base64Env;
|
||||||
|
global $contextUserData;
|
||||||
|
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||||
|
$disktags = explode("|",getConfig('disktag'));
|
||||||
|
$diskconfig = json_decode($contextUserData->getUserData($disktag), true);
|
||||||
|
$tmp = [];
|
||||||
|
$indisk = 0;
|
||||||
|
$oparetdisk = 0;
|
||||||
|
foreach ($arr as $k => $v) {
|
||||||
|
if (in_array($k, $InnerEnv)) {
|
||||||
|
if (in_array($k, $Base64Env)) $diskconfig[$k] = base64y_encode($v);
|
||||||
|
else $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 {
|
||||||
|
if (in_array($k, $Base64Env)) $tmp[$k] = base64y_encode($v);
|
||||||
|
else $tmp[$k] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($indisk) {
|
||||||
|
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||||
|
ksort($diskconfig);
|
||||||
|
$tmp[$disktag] = json_encode($diskconfig);
|
||||||
|
}
|
||||||
|
if ($oparetdisk) {
|
||||||
|
$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'] = getConfig('HW_urn');
|
||||||
|
if ($tmp['HW_urn']=='') {
|
||||||
|
$tmp['HW_urn'] = $_POST['HW_urn'];
|
||||||
|
}
|
||||||
|
$tmp['HW_key'] = getConfig('HW_key');
|
||||||
|
if ($tmp['HW_key']=='') {
|
||||||
|
$tmp['HW_key'] = $_POST['HW_key'];
|
||||||
|
}
|
||||||
|
$tmp['HW_secret'] = getConfig('HW_secret');
|
||||||
|
if ($tmp['HW_secret']=='') {
|
||||||
|
$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="text" 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 = 'Error';
|
||||||
|
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);
|
||||||
|
|
||||||
|
$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($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||||
|
{
|
||||||
|
$source = '/tmp/code.zip';
|
||||||
|
$outPath = '/tmp/';
|
||||||
|
|
||||||
|
// 从github下载对应tar.gz,并解压
|
||||||
|
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||||
|
$tarfile = '/tmp/github.tar.gz';
|
||||||
|
file_put_contents($tarfile, file_get_contents($url));
|
||||||
|
$phar = new PharData($tarfile);
|
||||||
|
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
||||||
|
|
||||||
|
// 获取解压出的目录名
|
||||||
|
$tmp = scandir($outPath);
|
||||||
|
$name = $auth.'-'.$project;
|
||||||
|
foreach ($tmp as $f) {
|
||||||
|
if ( substr($f, 0, strlen($name)) == $name) {
|
||||||
|
$outPath .= $f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将目录中文件打包成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($path);
|
||||||
|
}
|
||||||
@@ -71,17 +71,24 @@ function getConfig($str, $disktag = '')
|
|||||||
{
|
{
|
||||||
global $InnerEnv;
|
global $InnerEnv;
|
||||||
global $Base64Env;
|
global $Base64Env;
|
||||||
global $contextUserData;
|
//include 'config.php';
|
||||||
if (in_array($str, $InnerEnv)) {
|
$s = file_get_contents(__DIR__ . '/../config.php');
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
//$configs = substr($s, 18, -2);
|
||||||
$env = json_decode($contextUserData->getUserData($disktag), true);
|
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||||
if (isset($env[$str])) {
|
if ($configs!='') {
|
||||||
if (in_array($str, $Base64Env)) return equal_replace($env[$str],1);
|
$envs = json_decode($configs, true);
|
||||||
else return $env[$str];
|
if (in_array($str, $InnerEnv)) {
|
||||||
|
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||||
|
if (isset($envs[$disktag][$str])) {
|
||||||
|
if (in_array($str, $Base64Env)) return base64y_decode($envs[$disktag][$str]);
|
||||||
|
else return $envs[$disktag][$str];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isset($envs[$str])) {
|
||||||
|
if (in_array($str, $Base64Env)) return base64y_decode($envs[$str]);
|
||||||
|
else return $envs[$str];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (in_array($str, $Base64Env)) return equal_replace($contextUserData->getUserData($str),1);
|
|
||||||
else return $contextUserData->getUserData($str);
|
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@@ -90,61 +97,62 @@ function setConfig($arr, $disktag = '')
|
|||||||
{
|
{
|
||||||
global $InnerEnv;
|
global $InnerEnv;
|
||||||
global $Base64Env;
|
global $Base64Env;
|
||||||
global $contextUserData;
|
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||||
|
//include 'config.php';
|
||||||
|
$s = file_get_contents(__DIR__ . '/../config.php');
|
||||||
|
//$configs = substr($s, 18, -2);
|
||||||
|
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||||
|
if ($configs!='') $envs = json_decode($configs, true);
|
||||||
$disktags = explode("|",getConfig('disktag'));
|
$disktags = explode("|",getConfig('disktag'));
|
||||||
$diskconfig = json_decode($contextUserData->getUserData($disktag), true);
|
|
||||||
$tmp = [];
|
|
||||||
$indisk = 0;
|
$indisk = 0;
|
||||||
$oparetdisk = 0;
|
$operatedisk = 0;
|
||||||
foreach ($arr as $k => $v) {
|
foreach ($arr as $k => $v) {
|
||||||
if (in_array($k, $InnerEnv)) {
|
if (in_array($k, $InnerEnv)) {
|
||||||
if (in_array($k, $Base64Env)) $diskconfig[$k] = equal_replace($v);
|
if (in_array($k, $Base64Env)) $envs[$disktag][$k] = base64y_encode($v);
|
||||||
else $diskconfig[$k] = $v;
|
else $envs[$disktag][$k] = $v;
|
||||||
$indisk = 1;
|
$indisk = 1;
|
||||||
} elseif ($k=='disktag_add') {
|
} elseif ($k=='disktag_add') {
|
||||||
array_push($disktags, $v);
|
array_push($disktags, $v);
|
||||||
$oparetdisk = 1;
|
$operatedisk = 1;
|
||||||
} elseif ($k=='disktag_del') {
|
} elseif ($k=='disktag_del') {
|
||||||
$disktags = array_diff($disktags, [ $v ]);
|
$disktags = array_diff($disktags, [ $v ]);
|
||||||
$tmp[$v] = '';
|
$envs[$v] = '';
|
||||||
$oparetdisk = 1;
|
$operatedisk = 1;
|
||||||
} else {
|
} else {
|
||||||
if (in_array($k, $Base64Env)) $tmp[$k] = equal_replace($v);
|
if (in_array($k, $Base64Env)) $envs[$k] = base64y_encode($v);
|
||||||
else $tmp[$k] = $v;
|
else $envs[$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($indisk) {
|
if ($indisk) {
|
||||||
|
$diskconfig = $envs[$disktag];
|
||||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||||
ksort($diskconfig);
|
ksort($diskconfig);
|
||||||
$tmp[$disktag] = json_encode($diskconfig);
|
$envs[$disktag] = $diskconfig;
|
||||||
}
|
}
|
||||||
if ($oparetdisk) {
|
if ($operatedisk) {
|
||||||
$disktags = array_unique($disktags);
|
$disktags = array_unique($disktags);
|
||||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
||||||
if ($disktag_s!='') $tmp['disktag'] = substr($disktag_s, 0, -1);
|
if ($disktag_s!='') $envs['disktag'] = substr($disktag_s, 0, -1);
|
||||||
else $tmp['disktag'] = '';
|
else $envs['disktag'] = '';
|
||||||
}
|
}
|
||||||
// echo '正式设置:'.json_encode($tmp,JSON_PRETTY_PRINT).'
|
$envs = array_filter($envs, 'array_value_isnot_null');
|
||||||
//';
|
ksort($envs);
|
||||||
$response = updateEnvironment($tmp, getConfig('HW_urn'), getConfig('HW_key'), getConfig('HW_secret'));
|
$response = updateEnvironment($envs, getConfig('HW_urn'), getConfig('HW_key'), getConfig('HW_secret'));
|
||||||
// WaitSCFStat();
|
|
||||||
return $response;
|
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()
|
function install()
|
||||||
{
|
{
|
||||||
global $constStr;
|
global $constStr;
|
||||||
|
global $contextUserData;
|
||||||
if ($_GET['install2']) {
|
if ($_GET['install2']) {
|
||||||
$tmp['admin'] = $_POST['admin'];
|
$tmp['admin'] = $_POST['admin'];
|
||||||
setConfig($tmp);
|
$response = setConfigResponse( setConfig($tmp) );
|
||||||
|
if (api_error($response)) {
|
||||||
|
$html = api_error_msg($response);
|
||||||
|
$title = 'Error';
|
||||||
|
return message($html, $title, 201);
|
||||||
|
}
|
||||||
if (needUpdate()) {
|
if (needUpdate()) {
|
||||||
OnekeyUpate();
|
OnekeyUpate();
|
||||||
return message('update to github version, reinstall.
|
return message('update to github version, reinstall.
|
||||||
@@ -180,13 +188,19 @@ function install()
|
|||||||
if ($tmp['HW_secret']=='') {
|
if ($tmp['HW_secret']=='') {
|
||||||
$tmp['HW_secret'] = $_POST['HW_secret'];
|
$tmp['HW_secret'] = $_POST['HW_secret'];
|
||||||
}
|
}
|
||||||
//$response = json_decode(SetbaseConfig($tmp, $HW_urn, $HW_name, $HW_pwd), true)['Response'];
|
$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']) );
|
$response = setConfigResponse( SetbaseConfig($tmp, $tmp['HW_urn'], $tmp['HW_key'], $tmp['HW_secret']) );
|
||||||
if (api_error($response)) {
|
if (api_error($response)) {
|
||||||
$html = api_error_msg($response);
|
$html = api_error_msg($response);
|
||||||
$title = 'Error';
|
$title = 'Error';
|
||||||
return message($html, $title, 201);
|
return message($html, $title, 201);
|
||||||
} else {
|
} 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 .= '
|
$html .= '
|
||||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
<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>
|
<label>'.getconstStr('SetAdminPassword').':<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>
|
||||||
@@ -217,11 +231,14 @@ language:<br>';
|
|||||||
}
|
}
|
||||||
if (getConfig('HW_urn')==''||getConfig('HW_key')==''||getConfig('HW_secret')=='') $html .= '
|
if (getConfig('HW_urn')==''||getConfig('HW_key')==''||getConfig('HW_secret')=='') $html .= '
|
||||||
在函数代码操作页上方找到URN,鼠标放上去后显示URN,复制填入:<br>
|
在函数代码操作页上方找到URN,鼠标放上去后显示URN,复制填入:<br>
|
||||||
<label>URN:<input name="HW_urn" type="text" placeholder="" size=""></label><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>,新增访问密钥,
|
<a href="https://console.huaweicloud.com/iam/#/mine/accessKey" target="_blank">点击链接</a>,新增访问密钥,
|
||||||
在下载的credentials.csv文件中找到对应信息,填入:<br>
|
在下载的credentials.csv文件中找到对应信息,填入:<br>
|
||||||
<label>Access Key Id:<input name="HW_key" type="text" placeholder="" size=""></label><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>';
|
<label>Secret Access Key:<input name="HW_secret" type="text" 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 .= '
|
$html .= '
|
||||||
<input type="submit" value="'.getconstStr('Submit').'">
|
<input type="submit" value="'.getconstStr('Submit').'">
|
||||||
</form>
|
</form>
|
||||||
@@ -288,51 +305,113 @@ function getfunctioninfo($HW_urn, $HW_key, $HW_secret)
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getfunctioncode($HW_urn, $HW_key, $HW_secret)
|
||||||
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);
|
|
||||||
|
|
||||||
$URN = explode(':', $HW_urn);
|
$URN = explode(':', $HW_urn);
|
||||||
$Region = $URN[2];
|
$Region = $URN[2];
|
||||||
$project_id = $URN[3];
|
$project_id = $URN[3];
|
||||||
$url = 'https://functiongraph.' . $Region . '.myhuaweicloud.com/v2/' . $project_id . '/fgs/functions/' . $HW_urn . '/config';
|
$url = 'https://functiongraph.' . $Region . '.myhuaweicloud.com/v2/' . $project_id . '/fgs/functions/' . $HW_urn . '/code';
|
||||||
$signer = new Signer();
|
$signer = new Signer();
|
||||||
$signer->Key = $HW_key;
|
$signer->Key = $HW_key;
|
||||||
$signer->Secret = $HW_secret;
|
$signer->Secret = $HW_secret;
|
||||||
$req = new Request('PUT', $url);
|
$req = new Request('GET', $url);
|
||||||
$req->headers = array(
|
$req->headers = array(
|
||||||
'content-type' => 'application/json;charset=utf8',
|
'content-type' => 'application/json;charset=utf8',
|
||||||
);
|
);
|
||||||
$tmpdata['handler'] = 'index.handler';
|
$req->body = '';
|
||||||
$tmpdata['memory_size'] = $contextUserData->getMemorySize()+1-1;
|
|
||||||
$tmpdata['runtime'] = 'PHP7.3';
|
|
||||||
$tmpdata['timeout'] = $contextUserData->getRunningTimeInSeconds()+1-1;
|
|
||||||
$tmpdata['user_data'] = json_encode($tmp_env);
|
|
||||||
$req->body = json_encode($tmpdata);
|
|
||||||
$curl = $signer->Sign($req);
|
$curl = $signer->Sign($req);
|
||||||
$response = curl_exec($curl);
|
$response = curl_exec($curl);
|
||||||
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
return $response;
|
//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_request($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)
|
||||||
|
{
|
||||||
|
|
||||||
|
//echo json_encode($Envs,JSON_PRETTY_PRINT);
|
||||||
|
global $contextUserData;
|
||||||
|
$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 . '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)
|
function SetbaseConfig($Envs, $HW_urn, $HW_key, $HW_secret)
|
||||||
{
|
{
|
||||||
//echo json_encode($Envs,JSON_PRETTY_PRINT);
|
//echo json_encode($Envs,JSON_PRETTY_PRINT);
|
||||||
$tmp_env = json_decode(json_decode(getfunctioninfo($HW_urn, $HW_key, $HW_secret),true)['user_data'],true);
|
if ($Envs['ONEMANAGER_CONFIG_SAVE'] == 'file') $envs = Array( 'ONEMANAGER_CONFIG_SAVE' => 'file' );
|
||||||
foreach ($Envs as $key1 => $value1) {
|
else {
|
||||||
$tmp_env[$key1] = $value1;
|
$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;
|
||||||
}
|
}
|
||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
|
||||||
ksort($tmp_env);
|
|
||||||
|
|
||||||
// https://functiongraph.cn-north-4.myhuaweicloud.com/v2/{project_id}/fgs/functions/{function_urn}/config
|
// https://functiongraph.cn-north-4.myhuaweicloud.com/v2/{project_id}/fgs/functions/{function_urn}/config
|
||||||
$URN = explode(':', $HW_urn);
|
$URN = explode(':', $HW_urn);
|
||||||
@@ -350,12 +429,27 @@ function SetbaseConfig($Envs, $HW_urn, $HW_key, $HW_secret)
|
|||||||
$tmpdata['memory_size'] = 128;
|
$tmpdata['memory_size'] = 128;
|
||||||
$tmpdata['runtime'] = 'PHP7.3';
|
$tmpdata['runtime'] = 'PHP7.3';
|
||||||
$tmpdata['timeout'] = 30;
|
$tmpdata['timeout'] = 30;
|
||||||
$tmpdata['user_data'] = json_encode($tmp_env);
|
$tmpdata['description'] = 'Onedrive index and manager in Huawei FG.';
|
||||||
|
$tmpdata['user_data'] = json_encode($envs);
|
||||||
$req->body = json_encode($tmpdata);
|
$req->body = json_encode($tmpdata);
|
||||||
$curl = $signer->Sign($req);
|
$curl = $signer->Sign($req);
|
||||||
$response = curl_exec($curl);
|
$response = curl_exec($curl);
|
||||||
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
|
//return $response;
|
||||||
|
if (api_error(setConfigResponse($response))) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
$s = file_get_contents(__DIR__ . '/../config.php');
|
||||||
|
//$configs = substr($s, 18, -2);
|
||||||
|
$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;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,6 +529,9 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 放入配置文件
|
||||||
|
file_put_contents($outPath . '/config.php', file_get_contents(__DIR__.'/../config.php'));
|
||||||
|
|
||||||
// 将目录中文件打包成zip
|
// 将目录中文件打包成zip
|
||||||
//$zip=new ZipArchive();
|
//$zip=new ZipArchive();
|
||||||
$zip=new PharData($source);
|
$zip=new PharData($source);
|
||||||
+51
-34
@@ -5,16 +5,19 @@ function getpath()
|
|||||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($_SERVER['HTTP_ACCEPT_LANGUAGE'],';')[0],',')[0]);
|
$_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_X_FORWARDED_FOR'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||||
$_SERVER['base_path'] = path_format(substr($_SERVER['SCRIPT_NAME'], 0, -10) . '/');
|
$_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'],'?');
|
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||||
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
||||||
else $path = $_SERVER['REQUEST_URI'];
|
else $path = $_SERVER['REQUEST_URI'];
|
||||||
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
||||||
return substr($path, 1);
|
return $path;
|
||||||
|
//return substr($path, 1);
|
||||||
//return spurlencode($path, '/');
|
//return spurlencode($path, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGET()
|
function getGET()
|
||||||
{
|
{
|
||||||
|
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
||||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||||
if ($p>0) {
|
if ($p>0) {
|
||||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
||||||
@@ -44,18 +47,19 @@ function getConfig($str, $disktag = '')
|
|||||||
global $Base64Env;
|
global $Base64Env;
|
||||||
//include 'config.php';
|
//include 'config.php';
|
||||||
$s = file_get_contents('config.php');
|
$s = file_get_contents('config.php');
|
||||||
$configs = substr($s, 18, -2);
|
//$configs = substr($s, 18, -2);
|
||||||
|
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||||
if ($configs!='') {
|
if ($configs!='') {
|
||||||
$envs = json_decode($configs, true);
|
$envs = json_decode($configs, true);
|
||||||
if (in_array($str, $InnerEnv)) {
|
if (in_array($str, $InnerEnv)) {
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||||
if (isset($envs[$disktag][$str])) {
|
if (isset($envs[$disktag][$str])) {
|
||||||
if (in_array($str, $Base64Env)) return equal_replace($envs[$disktag][$str],1);
|
if (in_array($str, $Base64Env)) return base64y_decode($envs[$disktag][$str]);
|
||||||
else return $envs[$disktag][$str];
|
else return $envs[$disktag][$str];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isset($envs[$str])) {
|
if (isset($envs[$str])) {
|
||||||
if (in_array($str, $Base64Env)) return equal_replace($envs[$str],1);
|
if (in_array($str, $Base64Env)) return base64y_decode($envs[$str]);
|
||||||
else return $envs[$str];
|
else return $envs[$str];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,14 +74,15 @@ function setConfig($arr, $disktag = '')
|
|||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||||
//include 'config.php';
|
//include 'config.php';
|
||||||
$s = file_get_contents('config.php');
|
$s = file_get_contents('config.php');
|
||||||
$configs = substr($s, 18, -2);
|
//$configs = substr($s, 18, -2);
|
||||||
|
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||||
if ($configs!='') $envs = json_decode($configs, true);
|
if ($configs!='') $envs = json_decode($configs, true);
|
||||||
$disktags = explode("|",getConfig('disktag'));
|
$disktags = explode("|",getConfig('disktag'));
|
||||||
$indisk = 0;
|
$indisk = 0;
|
||||||
$operatedisk = 0;
|
$operatedisk = 0;
|
||||||
foreach ($arr as $k => $v) {
|
foreach ($arr as $k => $v) {
|
||||||
if (in_array($k, $InnerEnv)) {
|
if (in_array($k, $InnerEnv)) {
|
||||||
if (in_array($k, $Base64Env)) $envs[$disktag][$k] = equal_replace($v);
|
if (in_array($k, $Base64Env)) $envs[$disktag][$k] = base64y_encode($v);
|
||||||
else $envs[$disktag][$k] = $v;
|
else $envs[$disktag][$k] = $v;
|
||||||
$indisk = 1;
|
$indisk = 1;
|
||||||
} elseif ($k=='disktag_add') {
|
} elseif ($k=='disktag_add') {
|
||||||
@@ -88,7 +93,7 @@ function setConfig($arr, $disktag = '')
|
|||||||
$envs[$v] = '';
|
$envs[$v] = '';
|
||||||
$operatedisk = 1;
|
$operatedisk = 1;
|
||||||
} else {
|
} else {
|
||||||
if (in_array($k, $Base64Env)) $envs[$k] = equal_replace($v);
|
if (in_array($k, $Base64Env)) $envs[$k] = base64y_encode($v);
|
||||||
else $envs[$k] = $v;
|
else $envs[$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,11 +112,11 @@ function setConfig($arr, $disktag = '')
|
|||||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
$envs = array_filter($envs, 'array_value_isnot_null');
|
||||||
ksort($envs);
|
ksort($envs);
|
||||||
//echo '<pre>'. json_encode($envs, JSON_PRETTY_PRINT).'</pre>';
|
//echo '<pre>'. json_encode($envs, JSON_PRETTY_PRINT).'</pre>';
|
||||||
$prestr = '<?php $configs = \'
|
$prestr = '<?php $configs = \'' . PHP_EOL;
|
||||||
';
|
$aftstr = PHP_EOL . '\';';
|
||||||
$aftstr = '
|
$response = file_put_contents('config.php', $prestr . json_encode($envs, JSON_PRETTY_PRINT) . $aftstr);
|
||||||
\';';
|
if ($response>0) return json_encode( [ 'response' => 'success' ] );
|
||||||
return file_put_contents('config.php', $prestr . json_encode($envs, JSON_PRETTY_PRINT) . $aftstr);
|
return json_encode( [ 'message' => 'Failed to write config.', 'code' => 'failed' ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
function install()
|
function install()
|
||||||
@@ -122,7 +127,7 @@ function install()
|
|||||||
$tmp['admin'] = $_POST['admin'];
|
$tmp['admin'] = $_POST['admin'];
|
||||||
//$tmp['language'] = $_COOKIE['language'];
|
//$tmp['language'] = $_COOKIE['language'];
|
||||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
$tmp['timezone'] = $_COOKIE['timezone'];
|
||||||
$response = setConfig($tmp);
|
$response = setConfigResponse( setConfig($tmp) );
|
||||||
if (api_error($response)) {
|
if (api_error($response)) {
|
||||||
$html = api_error_msg($response);
|
$html = api_error_msg($response);
|
||||||
$title = 'Error';
|
$title = 'Error';
|
||||||
@@ -191,7 +196,7 @@ function install()
|
|||||||
document.getElementById("submitbtn").disabled = false;
|
document.getElementById("submitbtn").disabled = false;
|
||||||
document.getElementById("formdiv").style.display = "";
|
document.getElementById("formdiv").style.display = "";
|
||||||
} else {
|
} else {
|
||||||
alert(url+"\n"+xhr4.status);
|
alert("Url: " + url + "\nExpect http code 201, but received " + xhr4.status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,29 +257,31 @@ function RewriteEngineOn()
|
|||||||
|
|
||||||
function api_error($response)
|
function api_error($response)
|
||||||
{
|
{
|
||||||
return !$response;
|
return isset($response['message']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function api_error_msg($response)
|
function api_error_msg($response)
|
||||||
{
|
{
|
||||||
return $response . '<br>
|
return $response['code'] . '<br>
|
||||||
Can not write config to file.<br>
|
' . $response['message'] . '<br>
|
||||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function setConfigResponse($response)
|
function setConfigResponse($response)
|
||||||
{
|
{
|
||||||
return $response;
|
return json_decode($response, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||||
{
|
{
|
||||||
|
$slash = '/';
|
||||||
|
if (strpos(__DIR__, ':')) $slash = '\\';
|
||||||
// __DIR__ is xxx/platform
|
// __DIR__ is xxx/platform
|
||||||
$projectPath = splitlast(__DIR__, '/')[0];
|
$projectPath = splitlast(__DIR__, $slash)[0];
|
||||||
|
|
||||||
// 从github下载对应tar.gz,并解压
|
// 从github下载对应tar.gz,并解压
|
||||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||||
$tarfile = $projectPath.'/github.tar.gz';
|
$tarfile = $projectPath . $slash .'github.tar.gz';
|
||||||
$githubfile = file_get_contents($url);
|
$githubfile = file_get_contents($url);
|
||||||
if (!$githubfile) return 0;
|
if (!$githubfile) return 0;
|
||||||
file_put_contents($tarfile, $githubfile);
|
file_put_contents($tarfile, $githubfile);
|
||||||
@@ -283,17 +290,17 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch =
|
|||||||
$phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖
|
$phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖
|
||||||
} else {
|
} else {
|
||||||
ob_start();
|
ob_start();
|
||||||
passthru('tar -xzvf '.$tarfile,$stat);
|
passthru('tar -xzvf ' . $tarfile, $stat);
|
||||||
ob_get_clean();
|
ob_get_clean();
|
||||||
}
|
}
|
||||||
unlink($tarfile);
|
unlink($tarfile);
|
||||||
|
|
||||||
$outPath = '';
|
$outPath = '';
|
||||||
$tmp = scandir($projectPath);
|
$tmp = scandir($projectPath);
|
||||||
$name = $auth.'-'.$project;
|
$name = $auth . '-' . $project;
|
||||||
foreach ($tmp as $f) {
|
foreach ($tmp as $f) {
|
||||||
if ( substr($f, 0, strlen($name)) == $name) {
|
if ( substr($f, 0, strlen($name)) == $name) {
|
||||||
$outPath = $projectPath . '/' . $f;
|
$outPath = $projectPath . $slash . $f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -301,31 +308,41 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch =
|
|||||||
if ($outPath=='') return 0;
|
if ($outPath=='') return 0;
|
||||||
|
|
||||||
//unlink($outPath.'/config.php');
|
//unlink($outPath.'/config.php');
|
||||||
rename($projectPath.'/config.php', $outPath.'/config.php');
|
$response = rename($projectPath . $slash . 'config.php', $outPath . $slash . 'config.php');
|
||||||
|
if (!$response) {
|
||||||
return moveFolder($outPath, $projectPath);
|
$tmp1['code'] = "Move Failed";
|
||||||
|
$tmp1['message'] = "Can not move " . $projectPath . $slash . 'config.php' . " to " . $outPath . $slash . 'config.php';
|
||||||
|
return json_encode($tmp1);
|
||||||
|
}
|
||||||
|
return moveFolder($outPath, $projectPath, $slash);
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveFolder($from, $to)
|
function moveFolder($from, $to, $slash)
|
||||||
{
|
{
|
||||||
if (substr($from, -1)=='/') $from = substr($from, 0, -1);
|
if (substr($from, -1)==$slash) $from = substr($from, 0, -1);
|
||||||
if (substr($to, -1)=='/') $to = substr($to, 0, -1);
|
if (substr($to, -1)==$slash) $to = substr($to, 0, -1);
|
||||||
if (!file_exists($to)) mkdir($to, 0777);
|
if (!file_exists($to)) mkdir($to, 0777);
|
||||||
$handler=opendir($from);
|
$handler=opendir($from);
|
||||||
while($filename=readdir($handler)) {
|
while($filename=readdir($handler)) {
|
||||||
if($filename != '.' && $filename != '..'){
|
if($filename != '.' && $filename != '..'){
|
||||||
$fromfile = $from.'/'.$filename;
|
$fromfile = $from . $slash . $filename;
|
||||||
$tofile = $to.'/'.$filename;
|
$tofile = $to . $slash . $filename;
|
||||||
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
||||||
moveFolder($fromfile, $tofile);
|
$response = moveFolder($fromfile, $tofile, $slash);
|
||||||
|
if (api_error(setConfigResponse($response))) return $response;
|
||||||
}else{
|
}else{
|
||||||
//if (file_exists($tofile)) unlink($tofile);
|
//if (file_exists($tofile)) unlink($tofile);
|
||||||
rename($fromfile, $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);
|
if (file_exists($fromfile)) unlink($fromfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir($handler);
|
closedir($handler);
|
||||||
rmdir($from);
|
rmdir($from);
|
||||||
return 1;
|
return json_encode( [ 'response' => 'success' ] );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ function getConfig($str, $disktag = '')
|
|||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||||
$env = json_decode(getenv($disktag), true);
|
$env = json_decode(getenv($disktag), true);
|
||||||
if (isset($env[$str])) {
|
if (isset($env[$str])) {
|
||||||
if (in_array($str, $Base64Env)) return equal_replace($env[$str],1);
|
if (in_array($str, $Base64Env)) return base64y_decode($env[$str]);
|
||||||
else return $env[$str];
|
else return $env[$str];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (in_array($str, $Base64Env)) return equal_replace(getenv($str),1);
|
if (in_array($str, $Base64Env)) return base64y_decode(getenv($str));
|
||||||
else return getenv($str);
|
else return getenv($str);
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
@@ -82,7 +82,7 @@ function setConfig($arr, $disktag = '')
|
|||||||
$oparetdisk = 0;
|
$oparetdisk = 0;
|
||||||
foreach ($arr as $k => $v) {
|
foreach ($arr as $k => $v) {
|
||||||
if (in_array($k, $InnerEnv)) {
|
if (in_array($k, $InnerEnv)) {
|
||||||
if (in_array($k, $Base64Env)) $diskconfig[$k] = equal_replace($v);
|
if (in_array($k, $Base64Env)) $diskconfig[$k] = base64y_encode($v);
|
||||||
else $diskconfig[$k] = $v;
|
else $diskconfig[$k] = $v;
|
||||||
$indisk = 1;
|
$indisk = 1;
|
||||||
} elseif ($k=='disktag_add') {
|
} elseif ($k=='disktag_add') {
|
||||||
@@ -93,7 +93,7 @@ function setConfig($arr, $disktag = '')
|
|||||||
$tmp[$v] = '';
|
$tmp[$v] = '';
|
||||||
$oparetdisk = 1;
|
$oparetdisk = 1;
|
||||||
} else {
|
} else {
|
||||||
if (in_array($k, $Base64Env)) $tmp[$k] = equal_replace($v);
|
if (in_array($k, $Base64Env)) $tmp[$k] = base64y_encode($v);
|
||||||
else $tmp[$k] = $v;
|
else $tmp[$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,7 +127,12 @@ function install()
|
|||||||
global $constStr;
|
global $constStr;
|
||||||
if ($_GET['install2']) {
|
if ($_GET['install2']) {
|
||||||
$tmp['admin'] = $_POST['admin'];
|
$tmp['admin'] = $_POST['admin'];
|
||||||
setConfig($tmp);
|
$response = setConfigResponse( setConfig($tmp) );
|
||||||
|
if (api_error($response)) {
|
||||||
|
$html = api_error_msg($response);
|
||||||
|
$title = 'Error';
|
||||||
|
return message($html, $title, 201);
|
||||||
|
}
|
||||||
if (needUpdate()) {
|
if (needUpdate()) {
|
||||||
OnekeyUpate();
|
OnekeyUpate();
|
||||||
return message('update to github version, reinstall.
|
return message('update to github version, reinstall.
|
||||||
@@ -160,12 +165,18 @@ function install()
|
|||||||
$SecretKey = $_POST['SecretKey'];
|
$SecretKey = $_POST['SecretKey'];
|
||||||
$tmp['SecretKey'] = $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'];
|
$response = json_decode(SetbaseConfig($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
|
||||||
if (api_error($response)) {
|
if (api_error($response)) {
|
||||||
$html = api_error_msg($response);
|
$html = api_error_msg($response);
|
||||||
$title = 'Error';
|
$title = 'Error';
|
||||||
return message($html, $title, 201);
|
return message($html, $title, 201);
|
||||||
} else {
|
} 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 .= '
|
$html .= '
|
||||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
<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>
|
<label>'.getconstStr('SetAdminPassword').':<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>
|
||||||
@@ -194,10 +205,13 @@ language:<br>';
|
|||||||
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
<label><input type="radio" name="language" value="'.$key1.'" '.($key1==$constStr['language']?'checked':'').' onclick="changelanguage(\''.$key1.'\')">'.$value1.'</label><br>';
|
||||||
}
|
}
|
||||||
if (getConfig('SecretId')==''||getConfig('SecretKey')=='') $html .= '
|
if (getConfig('SecretId')==''||getConfig('SecretKey')=='') $html .= '
|
||||||
<a href="https://console.cloud.tencent.com/cam/capi" target="_blank">'.getconstStr('Create').' SecretId & SecretKey</a><br>
|
<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>SecretId:<input name="SecretId" type="text" placeholder="" size=""></label><br>
|
||||||
<label>SecretKey:<input name="SecretKey" type="text" placeholder="" size=""></label><br>';
|
<label>SecretKey:<input name="SecretKey" type="text" placeholder="" size=""></label><br>';
|
||||||
$html .= '
|
$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').'">
|
<input type="submit" value="'.getconstStr('Submit').'">
|
||||||
</form>
|
</form>
|
||||||
<script>
|
<script>
|
||||||
@@ -329,7 +343,8 @@ function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId
|
|||||||
|
|
||||||
function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
||||||
{
|
{
|
||||||
echo json_encode($Envs,JSON_PRETTY_PRINT);
|
//echo json_encode($Envs,JSON_PRETTY_PRINT);
|
||||||
|
if ($Envs['ONEMANAGER_CONFIG_SAVE'] == 'file') $Envs = Array( 'ONEMANAGER_CONFIG_SAVE' => 'file' );
|
||||||
/*$trynum = 0;
|
/*$trynum = 0;
|
||||||
while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey),true)['Response']['Status']!='Active' ) echo '
|
while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey),true)['Response']['Status']!='Active' ) echo '
|
||||||
'.++$trynum;*/
|
'.++$trynum;*/
|
||||||
@@ -362,7 +377,7 @@ function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $S
|
|||||||
$tmpdata['Timestamp'] = time();
|
$tmpdata['Timestamp'] = time();
|
||||||
$tmpdata['Token'] = '';
|
$tmpdata['Token'] = '';
|
||||||
$tmpdata['Version'] = '2018-04-16';
|
$tmpdata['Version'] = '2018-04-16';
|
||||||
$tmpdata['Description'] = 'Onedrive index and manager in SCF.';
|
$tmpdata['Description'] = 'Onedrive index and manager in Tencent SCF.';
|
||||||
$tmpdata['MemorySize'] = 64;
|
$tmpdata['MemorySize'] = 64;
|
||||||
$tmpdata['Timeout'] = 30;
|
$tmpdata['Timeout'] = 30;
|
||||||
$data = ReorganizeDate($tmpdata);
|
$data = ReorganizeDate($tmpdata);
|
||||||
@@ -415,7 +430,7 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch =
|
|||||||
{
|
{
|
||||||
$source['url'] = 'https://github.com/' . $auth . '/' . $project;
|
$source['url'] = 'https://github.com/' . $auth . '/' . $project;
|
||||||
$source['branch'] = $branch;
|
$source['branch'] = $branch;
|
||||||
return json_decode(updateProgram($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'), $source), true)['Response'];
|
return updateProgram($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'), $source);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setConfigResponse($response)
|
function setConfigResponse($response)
|
||||||
|
|||||||
@@ -58,18 +58,19 @@ function getConfig($str, $disktag = '')
|
|||||||
global $Base64Env;
|
global $Base64Env;
|
||||||
//include 'config.php';
|
//include 'config.php';
|
||||||
$s = file_get_contents('config.php');
|
$s = file_get_contents('config.php');
|
||||||
$configs = substr($s, 18, -2);
|
//$configs = substr($s, 18, -2);
|
||||||
|
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||||
if ($configs!='') {
|
if ($configs!='') {
|
||||||
$envs = json_decode($configs, true);
|
$envs = json_decode($configs, true);
|
||||||
if (in_array($str, $InnerEnv)) {
|
if (in_array($str, $InnerEnv)) {
|
||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||||
if (isset($envs[$disktag][$str])) {
|
if (isset($envs[$disktag][$str])) {
|
||||||
if (in_array($str, $Base64Env)) return equal_replace($envs[$disktag][$str],1);
|
if (in_array($str, $Base64Env)) return base64y_decode($envs[$disktag][$str]);
|
||||||
else return $envs[$disktag][$str];
|
else return $envs[$disktag][$str];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isset($envs[$str])) {
|
if (isset($envs[$str])) {
|
||||||
if (in_array($str, $Base64Env)) return equal_replace($envs[$str],1);
|
if (in_array($str, $Base64Env)) return base64y_decode($envs[$str]);
|
||||||
else return $envs[$str];
|
else return $envs[$str];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,14 +85,15 @@ function setConfig($arr, $disktag = '')
|
|||||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||||
//include 'config.php';
|
//include 'config.php';
|
||||||
$s = file_get_contents('config.php');
|
$s = file_get_contents('config.php');
|
||||||
$configs = substr($s, 18, -2);
|
//$configs = substr($s, 18, -2);
|
||||||
|
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||||
if ($configs!='') $envs = json_decode($configs, true);
|
if ($configs!='') $envs = json_decode($configs, true);
|
||||||
$disktags = explode("|",getConfig('disktag'));
|
$disktags = explode("|",getConfig('disktag'));
|
||||||
$indisk = 0;
|
$indisk = 0;
|
||||||
$operatedisk = 0;
|
$operatedisk = 0;
|
||||||
foreach ($arr as $k => $v) {
|
foreach ($arr as $k => $v) {
|
||||||
if (in_array($k, $InnerEnv)) {
|
if (in_array($k, $InnerEnv)) {
|
||||||
if (in_array($k, $Base64Env)) $envs[$disktag][$k] = equal_replace($v);
|
if (in_array($k, $Base64Env)) $envs[$disktag][$k] = base64y_encode($v);
|
||||||
else $envs[$disktag][$k] = $v;
|
else $envs[$disktag][$k] = $v;
|
||||||
$indisk = 1;
|
$indisk = 1;
|
||||||
} elseif ($k=='disktag_add') {
|
} elseif ($k=='disktag_add') {
|
||||||
@@ -102,7 +104,7 @@ function setConfig($arr, $disktag = '')
|
|||||||
$envs[$v] = '';
|
$envs[$v] = '';
|
||||||
$operatedisk = 1;
|
$operatedisk = 1;
|
||||||
} else {
|
} else {
|
||||||
if (in_array($k, $Base64Env)) $envs[$k] = equal_replace($v);
|
if (in_array($k, $Base64Env)) $envs[$k] = base64y_encode($v);
|
||||||
else $envs[$k] = $v;
|
else $envs[$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,7 +139,12 @@ function install()
|
|||||||
global $constStr;
|
global $constStr;
|
||||||
if ($_GET['install2']) {
|
if ($_GET['install2']) {
|
||||||
$tmp['admin'] = $_POST['admin'];
|
$tmp['admin'] = $_POST['admin'];
|
||||||
setConfig($tmp);
|
$response = setConfigResponse( setConfig($tmp) );
|
||||||
|
if (api_error($response)) {
|
||||||
|
$html = api_error_msg($response);
|
||||||
|
$title = 'Error';
|
||||||
|
return message($html, $title, 201);
|
||||||
|
}
|
||||||
if (needUpdate()) {
|
if (needUpdate()) {
|
||||||
OnekeyUpate();
|
OnekeyUpate();
|
||||||
return message('update to github version, reinstall.
|
return message('update to github version, reinstall.
|
||||||
@@ -170,12 +177,18 @@ function install()
|
|||||||
$SecretKey = $_POST['SecretKey'];
|
$SecretKey = $_POST['SecretKey'];
|
||||||
$tmp['SecretKey'] = $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'];
|
$response = json_decode(SetbaseConfig($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
|
||||||
if (api_error($response)) {
|
if (api_error($response)) {
|
||||||
$html = api_error_msg($response);
|
$html = api_error_msg($response);
|
||||||
$title = 'Error';
|
$title = 'Error';
|
||||||
return message($html, $title, 201);
|
return message($html, $title, 201);
|
||||||
} else {
|
} 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 .= '
|
$html .= '
|
||||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
<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>
|
<label>'.getconstStr('SetAdminPassword').':<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>
|
||||||
@@ -208,6 +221,9 @@ language:<br>';
|
|||||||
<label>SecretId:<input name="SecretId" type="text" placeholder="" size=""></label><br>
|
<label>SecretId:<input name="SecretId" type="text" placeholder="" size=""></label><br>
|
||||||
<label>SecretKey:<input name="SecretKey" type="text" placeholder="" size=""></label><br>';
|
<label>SecretKey:<input name="SecretKey" type="text" placeholder="" size=""></label><br>';
|
||||||
$html .= '
|
$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').'">
|
<input type="submit" value="'.getconstStr('Submit').'">
|
||||||
</form>
|
</form>
|
||||||
<script>
|
<script>
|
||||||
@@ -319,36 +335,46 @@ function getfunctioncodeurl($function_name, $Region, $Namespace, $SecretId, $Sec
|
|||||||
return post2url('https://'.$host, $data.'&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)
|
function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
||||||
{
|
{
|
||||||
// 获取当前代码并解压
|
// 获取当前代码并解压
|
||||||
$codeurl = json_decode(getfunctioncodeurl($function_name, $Region, $Namespace, $SecretId, $SecretKey), true)['Response']['Url'];
|
//$codeurl = json_decode(getfunctioncodeurl($function_name, $Region, $Namespace, $SecretId, $SecretKey), true)['Response']['Url'];
|
||||||
$codezip = '/tmp/oldcode.zip';
|
//$codezip = '/tmp/oldcode.zip';
|
||||||
$outPath = '/tmp/code/';
|
$outPath = '/tmp/code/';
|
||||||
file_put_contents($codezip, file_get_contents($codeurl));
|
|
||||||
//$phar = new PharData($codezip);
|
|
||||||
//$phar = new Phar($codezip);
|
|
||||||
$zip=new ZipArchive();
|
|
||||||
$zip->open($codezip);
|
|
||||||
$html = $zip->extractTo($outPath);
|
|
||||||
|
|
||||||
// 获取当前配置并加入新配置
|
//file_put_contents($codezip, file_get_contents($codeurl));
|
||||||
$tmp = json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Environment']['Variables'];
|
//$zip=new ZipArchive();
|
||||||
foreach ($tmp as $tmp1) {
|
//$zip->open($codezip);
|
||||||
$tmp_env[$tmp1['Key']] = $tmp1['Value'];
|
//$html = $zip->extractTo($outPath);
|
||||||
}
|
|
||||||
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);
|
|
||||||
|
|
||||||
$prestr = '<?php $configs = \'
|
$coderoot = __DIR__ . '/../';
|
||||||
';
|
copyFolder($coderoot, $outPath);
|
||||||
$aftstr = '
|
|
||||||
\';';
|
// 将配置写入
|
||||||
file_put_contents($outPath . 'config.php', $prestr . json_encode($tmp_env, JSON_PRETTY_PRINT) . $aftstr);
|
$prestr = '<?php $configs = \'' . PHP_EOL;
|
||||||
|
$aftstr = PHP_EOL . '\';';
|
||||||
|
file_put_contents($outPath . 'config.php', $prestr . json_encode($Envs, JSON_PRETTY_PRINT) . $aftstr);
|
||||||
|
|
||||||
// 将目录中文件打包成zip
|
// 将目录中文件打包成zip
|
||||||
$source = '/tmp/code.zip';
|
$source = '/tmp/code.zip';
|
||||||
@@ -359,7 +385,7 @@ function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId
|
|||||||
// $zip->close(); //关闭处理的zip文件
|
// $zip->close(); //关闭处理的zip文件
|
||||||
//}
|
//}
|
||||||
|
|
||||||
return updateProgram($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey, $source);
|
return updateProgram($function_name, $Region, $namespace, $SecretId, $SecretKey, $source);
|
||||||
$tmp1['Response']['Error']['Message'] = $codeurl;
|
$tmp1['Response']['Error']['Message'] = $codeurl;
|
||||||
error_log($tmp1['Response']['Error']['Message']);
|
error_log($tmp1['Response']['Error']['Message']);
|
||||||
return json_encode($tmp1);
|
return json_encode($tmp1);
|
||||||
@@ -367,6 +393,27 @@ function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId
|
|||||||
|
|
||||||
function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
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';
|
$meth = 'POST';
|
||||||
$host = 'scf.tencentcloudapi.com';
|
$host = 'scf.tencentcloudapi.com';
|
||||||
$tmpdata['Action'] = 'UpdateFunctionConfiguration';
|
$tmpdata['Action'] = 'UpdateFunctionConfiguration';
|
||||||
@@ -378,7 +425,7 @@ function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $S
|
|||||||
$tmpdata['Timestamp'] = time();
|
$tmpdata['Timestamp'] = time();
|
||||||
$tmpdata['Token'] = '';
|
$tmpdata['Token'] = '';
|
||||||
$tmpdata['Version'] = '2018-04-16';
|
$tmpdata['Version'] = '2018-04-16';
|
||||||
$tmpdata['Description'] = 'Onedrive index and manager in SCF.';
|
$tmpdata['Description'] = 'Onedrive index and manager in Tencent SCF.';
|
||||||
$tmpdata['MemorySize'] = 64;
|
$tmpdata['MemorySize'] = 64;
|
||||||
$tmpdata['Timeout'] = 30;
|
$tmpdata['Timeout'] = 30;
|
||||||
$data = ReorganizeDate($tmpdata);
|
$data = ReorganizeDate($tmpdata);
|
||||||
@@ -396,17 +443,16 @@ function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $S
|
|||||||
}
|
}
|
||||||
WaitSCFStat($function_name, $Region, $Namespace, $SecretId, $SecretKey);
|
WaitSCFStat($function_name, $Region, $Namespace, $SecretId, $SecretKey);
|
||||||
|
|
||||||
$tmp = json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Environment']['Variables'];
|
$s = file_get_contents('config.php');
|
||||||
foreach ($tmp as $tmp1) {
|
//$configs = substr($s, 18, -2);
|
||||||
$tmp_env[$tmp1['Key']] = $tmp1['Value'];
|
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||||
|
if ($configs!='') $envs = json_decode($configs, true);
|
||||||
|
foreach ($Envs as $k => $v) {
|
||||||
|
$envs[$k] = $v;
|
||||||
}
|
}
|
||||||
foreach ($Envs as $key1 => $value1) {
|
$envs = array_filter($envs, 'array_value_isnot_null');
|
||||||
$tmp_env[$key1] = $value1;
|
ksort($envs);
|
||||||
}
|
$response = updateEnvironment($envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey);
|
||||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
|
||||||
ksort($tmp_env);
|
|
||||||
$response = updateEnvironment($tmp_env, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey);
|
|
||||||
//WaitSCFStat();
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,9 +13,9 @@ Official: https://cloud.tencent.com/product/scf
|
|||||||
DEMO: 无
|
DEMO: 无
|
||||||
注意:SCF新增限制,环境变量整体最大4KB,所以最多添加4个盘。
|
注意:SCF新增限制,环境变量整体最大4KB,所以最多添加4个盘。
|
||||||
|
|
||||||
How to Install: 无
|
How to Install: 无,(重点:勾选集成响应)
|
||||||
|
|
||||||
添加网盘时,SCF反应不过来,会添加失败,请不要删除,再添加一次相同的就可以了。
|
添加网盘时,SCF可能会反应不过来,不跳转到微软,导致添加失败,请不要删除这个盘,再添加一次相同标签的盘就可以了。
|
||||||
|
|
||||||
|
|
||||||
# Deploy to Virtual Private Server (VPS 或空间)
|
# Deploy to Virtual Private Server (VPS 或空间)
|
||||||
@@ -59,6 +59,20 @@ How to Install:
|
|||||||
6,访问你的域名,开始安装
|
6,访问你的域名,开始安装
|
||||||
|
|
||||||
|
|
||||||
|
# Deploy to Baidu Cloud Function Compute (CFC 百度云函数计算)
|
||||||
|
Official: https://console.bce.baidu.com/cfc/#/cfc/functions
|
||||||
|
DEMO: 无
|
||||||
|
自定义域名需要另外使用API网关,并备案。
|
||||||
|
|
||||||
|
How to Install:
|
||||||
|
1,在函数列表,点创建函数
|
||||||
|
2,创建方式改为空白函数,点下一步
|
||||||
|
3,输入名称,选择运行时为PHP7.2,点下一步
|
||||||
|
4,触发器:下拉选择HTTP触发器,URL路径填 /{filepath+} ,HTTP方法全选,身份验证:不验证,点提交
|
||||||
|
5,进入代码编辑页,编辑类型改上传函数ZIP包,选择文件(这里的ZIP文件不能直接用从Github上下载的ZIP文件,要将它解压后,去掉外层文件夹后,再压缩为ZIP。),开始上传
|
||||||
|
6,点击右边触发器,复制并访问提供的url,开始安装
|
||||||
|
|
||||||
|
|
||||||
# Features 特性
|
# Features 特性
|
||||||
When downloading files, the program produce a direct url, visitor download files from MS OFFICE via the direct url, the server expend a few bandwidth in produce.
|
When downloading files, the program produce a direct url, visitor download files from MS OFFICE via the direct url, the server expend a few bandwidth in produce.
|
||||||
下载时,由程序解析出直链,浏览器直接从微软Onedrive服务器下载文件,服务器只消耗与微软通信的少量流量。
|
下载时,由程序解析出直链,浏览器直接从微软Onedrive服务器下载文件,服务器只消耗与微软通信的少量流量。
|
||||||
|
|||||||
+3
-15
@@ -227,7 +227,6 @@
|
|||||||
main .main-item-list .main-items-fileName a:hover {
|
main .main-item-list .main-items-fileName a:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
.main-title-path a{vertical-align: middle;}
|
|
||||||
.more-disk{
|
.more-disk{
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@@ -292,22 +291,11 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="main-title">
|
<div class="main-title">
|
||||||
<h1 class="main-title-path">
|
<h1 class="main-title-path">
|
||||||
<!--MultiDiskAreaStart-->
|
<a href="<!--base_path-->"><!--constStr@Home--></a>
|
||||||
<div class="more-disk">
|
<!--DiskPathArrayStart-->
|
||||||
<span><!--DiskNameNow--></span>
|
|
||||||
<div>
|
|
||||||
<!--MultiDisksStart-->
|
|
||||||
<li><a href="<!--MultiDisksUrl-->" <!--MultiDisksNow-->><!--MultiDisksName--></a></li>
|
|
||||||
<!--MultiDisksEnd-->
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
>
|
|
||||||
<!--MultiDiskAreaEnd-->
|
|
||||||
<a href="<!--base_disk_path-->/"><!--constStr@Home--></a>
|
|
||||||
<!--PathArrayStart-->
|
|
||||||
>
|
>
|
||||||
<a href="<!--PathArrayLink-->"><!--PathArrayName--></a>
|
<a href="<!--PathArrayLink-->"><!--PathArrayName--></a>
|
||||||
<!--PathArrayEnd-->
|
<!--DiskPathArrayEnd-->
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<!--IsFileStart-->
|
<!--IsFileStart-->
|
||||||
|
|||||||
+18
-19
@@ -35,7 +35,7 @@
|
|||||||
.list-header-container{position:relative}
|
.list-header-container{position:relative}
|
||||||
.list-header-container a.back-link{color:#000;display:inline-block;position:absolute;font-size:16px;margin:20px 10px;padding:10px 10px;vertical-align:middle;text-decoration:none}
|
.list-header-container a.back-link{color:#000;display:inline-block;position:absolute;font-size:16px;margin:20px 10px;padding:10px 10px;vertical-align:middle;text-decoration:none}
|
||||||
.list-container,.list-header-container,.list-wrapper,a.back-link:hover,body{color:#24292e}
|
.list-container,.list-header-container,.list-wrapper,a.back-link:hover,body{color:#24292e}
|
||||||
.table-header{margin:0;border:0 none;padding:30px 60px;text-align:left;font-weight:400;color:#000;background-color:rgba(245,245,245,0.5);word-break: break-all;word-wrap: break-word;}
|
.table-header{margin:0;border:0 none;padding:30px 30px;text-align:left;font-weight:400;color:#000;background-color:rgba(245,245,245,0.5);word-break: break-all;word-wrap: break-word;}
|
||||||
.list-body-container{position:relative;left:0;overflow-x:hidden;overflow-y:auto;box-sizing:border-box;background:rgba(245,245,245,0.5)}
|
.list-body-container{position:relative;left:0;overflow-x:hidden;overflow-y:auto;box-sizing:border-box;background:rgba(245,245,245,0.5)}
|
||||||
.more-disk{margin:0;border:0 none;padding:30px 30px;text-align:left;font-weight:400;color:#000;background-color:rgba(245,245,245,0.5);white-space:nowrap;overflow:auto;}
|
.more-disk{margin:0;border:0 none;padding:30px 30px;text-align:left;font-weight:400;color:#000;background-color:rgba(245,245,245,0.5);white-space:nowrap;overflow:auto;}
|
||||||
.more-disk a{margin:0 10px;padding:5px;transition-duration: 0.4s;border-radius: 12px; background-color: white; color: black; border: 2px solid rgba(85,85,85,0.7); }
|
.more-disk a{margin:0 10px;padding:5px;transition-duration: 0.4s;border-radius: 12px; background-color: white; color: black; border: 2px solid rgba(85,85,85,0.7); }
|
||||||
@@ -63,6 +63,9 @@
|
|||||||
.readme{padding:8px;background-color:rgba(245,245,245,0.5);}
|
.readme{padding:8px;background-color:rgba(245,245,245,0.5);}
|
||||||
.markdown-body, .customfile{padding:20px;text-align:left}
|
.markdown-body, .customfile{padding:20px;text-align:left}
|
||||||
@media only screen and (max-width:480px){
|
@media only screen and (max-width:480px){
|
||||||
|
<!--BackgroundMStart-->
|
||||||
|
body{background-repeat:no-repeat;background-size:cover;background-attachment:fixed;background-image:url("<!--BackgroundMUrl-->");}
|
||||||
|
<!--BackgroundMEnd-->
|
||||||
.title{margin-bottom:24px}
|
.title{margin-bottom:24px}
|
||||||
.list-wrapper{width:95%; margin-bottom:24px;}
|
.list-wrapper{width:95%; margin-bottom:24px;}
|
||||||
.list-table {padding:8px}
|
.list-table {padding:8px}
|
||||||
@@ -146,12 +149,7 @@
|
|||||||
<div class="list-wrapper" id="list-div">
|
<div class="list-wrapper" id="list-div">
|
||||||
<div class="list-container">
|
<div class="list-container">
|
||||||
<div class="list-header-container">
|
<div class="list-header-container">
|
||||||
<!--BackArrowStart-->
|
<h3 class="table-header"><a href="<!--base_path-->"><!--constStr@Home--></a><!--DiskPathArrayStart--> / <a href="<!--PathArrayLink-->"><!--PathArrayName--></a><!--DiskPathArrayEnd--></h3>
|
||||||
<a href="<!--BackArrowUrl-->" class="back-link">
|
|
||||||
<ion-icon name="arrow-back"></ion-icon>
|
|
||||||
</a>
|
|
||||||
<!--BackArrowEnd-->
|
|
||||||
<h3 class="table-header"><!--PathArrayStart--> / <a href="<!--PathArrayLink-->"><!--PathArrayName--></a><!--PathArrayEnd--></h3>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="list-body-container">
|
<div class="list-body-container">
|
||||||
<!--EncryptedStart-->
|
<!--EncryptedStart-->
|
||||||
@@ -315,10 +313,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<!--AdminEnd-->
|
<!--AdminEnd-->
|
||||||
<!--IsFolderEnd-->
|
<!--IsFolderEnd-->
|
||||||
<!--ListEnd-->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!--ListEnd-->
|
||||||
<!--ReadmemdStart-->
|
<!--ReadmemdStart-->
|
||||||
<div class="list-wrapper" id="readme-div">
|
<div class="list-wrapper" id="readme-div">
|
||||||
<div class="list-container">
|
<div class="list-container">
|
||||||
@@ -651,15 +649,13 @@
|
|||||||
strarry=str.split('.');
|
strarry=str.split('.');
|
||||||
ext=strarry[strarry.length-1].toLowerCase();
|
ext=strarry[strarry.length-1].toLowerCase();
|
||||||
if (images.indexOf(ext)>-1) {
|
if (images.indexOf(ext)>-1) {
|
||||||
|
var url=files[$i].href;
|
||||||
|
url=url.substr(0,url.length-8);
|
||||||
if (document.getElementById('originalpic').checked==true) {
|
if (document.getElementById('originalpic').checked==true) {
|
||||||
var url=files[$i].href;
|
|
||||||
url=url.substr(0,url.length-8);
|
|
||||||
files[$i].parentNode.parentNode.innerHTML='<td colspan="3"><img src="'+url+'" alt="'+str+'" onload="if (this.offsetWidth>document.getElementById(\'list-div\').offsetWidth) this.style.width=\'100%\';"></td>';
|
files[$i].parentNode.parentNode.innerHTML='<td colspan="3"><img src="'+url+'" alt="'+str+'" onload="if (this.offsetWidth>document.getElementById(\'list-div\').offsetWidth) this.style.width=\'100%\';"></td>';
|
||||||
$i--;
|
$i--;
|
||||||
} else {
|
} else {
|
||||||
var nurl=window.location.href;
|
url+='?thumbnails';
|
||||||
if (nurl.substr(-1)!="/") nurl+="/";
|
|
||||||
var url=nurl+str+'?thumbnails';
|
|
||||||
get_thumbnails_url(url, str, files[$i]);
|
get_thumbnails_url(url, str, files[$i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1003,12 +999,14 @@
|
|||||||
var response=JSON.parse(xhr.responseText);
|
var response=JSON.parse(xhr.responseText);
|
||||||
if (response['size']>0) {
|
if (response['size']>0) {
|
||||||
// contain size, upload finish. 有size说明是最终返回,上传结束
|
// contain size, upload finish. 有size说明是最终返回,上传结束
|
||||||
var xhr3 = new XMLHttpRequest();
|
if (totalsize>10*1024*1024) {
|
||||||
xhr3.open("GET", '?action=del_upload_cache&filelastModified='+file.lastModified+'&filesize='+file.size+'&filename='+filename);
|
var xhr3 = new XMLHttpRequest();
|
||||||
xhr3.setRequestHeader('x-requested-with','XMLHttpRequest');
|
xhr3.open("GET", '?action=del_upload_cache&filelastModified='+file.lastModified+'&filesize='+file.size+'&filename='+filename);
|
||||||
xhr3.send(null);
|
xhr3.setRequestHeader('x-requested-with','XMLHttpRequest');
|
||||||
xhr3.onload = function(e){
|
xhr3.send(null);
|
||||||
console.log(xhr3.responseText+','+xhr3.status);
|
xhr3.onload = function(e){
|
||||||
|
console.log(xhr3.responseText+','+xhr3.status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
EndTime=new Date();
|
EndTime=new Date();
|
||||||
MiddleStr = '<!--constStr@EndAt-->:'+EndTime.toLocaleString()+'<br>';
|
MiddleStr = '<!--constStr@EndAt-->:'+EndTime.toLocaleString()+'<br>';
|
||||||
@@ -1019,6 +1017,7 @@
|
|||||||
}
|
}
|
||||||
document.getElementById('upfile_td1_'+tdnum).innerHTML='<div style="color:green"><a href="<!--base_disk_path--><!--Path-->'+(file.webkitRelativePath||response.name)+'?preview" id="upfile_a_'+tdnum+'" target="_blank">'+document.getElementById('upfile_td1_'+tdnum).innerHTML+'</a><br><a href="<!--base_disk_path--><!--Path-->'+(file.webkitRelativePath||response.name)+'" id="upfile_a1_'+tdnum+'"></a><!--constStr@UploadComplete--><button onclick="CopyAllDownloadUrl(\'#upfile_a1_'+tdnum+'\');" id="upfile_cpbt_'+tdnum+'" <!--AdminStart--> style="display:none"<!--AdminEnd--> ><!--constStr@CopyUrl--></button></div>';
|
document.getElementById('upfile_td1_'+tdnum).innerHTML='<div style="color:green"><a href="<!--base_disk_path--><!--Path-->'+(file.webkitRelativePath||response.name)+'?preview" id="upfile_a_'+tdnum+'" target="_blank">'+document.getElementById('upfile_td1_'+tdnum).innerHTML+'</a><br><a href="<!--base_disk_path--><!--Path-->'+(file.webkitRelativePath||response.name)+'" id="upfile_a1_'+tdnum+'"></a><!--constStr@UploadComplete--><button onclick="CopyAllDownloadUrl(\'#upfile_a1_'+tdnum+'\');" id="upfile_cpbt_'+tdnum+'" <!--AdminStart--> style="display:none"<!--AdminEnd--> ><!--constStr@CopyUrl--></button></div>';
|
||||||
label.innerHTML=StartStr+MiddleStr;
|
label.innerHTML=StartStr+MiddleStr;
|
||||||
|
label.style.color='green';
|
||||||
// uploadbuttonshow();
|
// uploadbuttonshow();
|
||||||
<!--AdminStart-->
|
<!--AdminStart-->
|
||||||
response.name=file.webkitRelativePath||response.name;
|
response.name=file.webkitRelativePath||response.name;
|
||||||
|
|||||||
+50
-26
@@ -24,9 +24,9 @@
|
|||||||
<link rel="icon" href="<!--base_path-->favicon.ico" type="image/x-icon">
|
<link rel="icon" href="<!--base_path-->favicon.ico" type="image/x-icon">
|
||||||
<link rel="shortcut icon" href="<!--base_path-->favicon.ico" type="image/x-icon">
|
<link rel="shortcut icon" href="<!--base_path-->favicon.ico" type="image/x-icon">
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kizx/onemoe-theme/onemoe.min.css" type="text/css" />
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kizx/onemoe-theme/onemoe.min.css" type="text/css" />
|
||||||
<!--BackgroundStart-->
|
<!--BackgroundStart-->
|
||||||
<style>body{background-repeat:no-repeat;background-size:cover;background-attachment:fixed;background-position-x:center;background-image:url("<!--BackgroundUrl-->")}</style>
|
<style>body{background-repeat:no-repeat;background-size:cover;background-attachment:fixed;background-position-x:center;background-image:url("<!--BackgroundUrl-->")}</style>
|
||||||
<!--BackgroundEnd-->
|
<!--BackgroundEnd-->
|
||||||
<script type="text/javascript">if(window.console&&window.console.log){console.log("%c Onemoe Theme %c https://github.com/kizx/onemoe-theme ","color: #fff; margin: 1em 0; padding: 5px 0; background: #673ab7;","margin: 1em 0; padding: 5px 0; background: #efefef;")}</script>
|
<script type="text/javascript">if(window.console&&window.console.log){console.log("%c Onemoe Theme %c https://github.com/kizx/onemoe-theme ","color: #fff; margin: 1em 0; padding: 5px 0; background: #673ab7;","margin: 1em 0; padding: 5px 0; background: #efefef;")}</script>
|
||||||
<!--customCss-->
|
<!--customCss-->
|
||||||
</head>
|
</head>
|
||||||
@@ -148,7 +148,7 @@
|
|||||||
<audio src="<!--FileDownUrl-->" controls="controls" style="width: 100%"></audio>
|
<audio src="<!--FileDownUrl-->" controls="controls" style="width: 100%"></audio>
|
||||||
<!--IsmusicFileEnd-->
|
<!--IsmusicFileEnd-->
|
||||||
<!--IspdfFileStart-->
|
<!--IspdfFileStart-->
|
||||||
<div id="pdf-d"></div>
|
<div id="pdf-d">Loading PDF</div>
|
||||||
<!--IspdfFileEnd-->
|
<!--IspdfFileEnd-->
|
||||||
<!--IsofficeFileStart-->
|
<!--IsofficeFileStart-->
|
||||||
<iframe id="office-a" src="https://view.officeapps.live.com/op/view.aspx?src=<!--FileEncodeDownUrl-->" style="width: 100%;height: 800px" frameborder="0"></iframe>
|
<iframe id="office-a" src="https://view.officeapps.live.com/op/view.aspx?src=<!--FileEncodeDownUrl-->" style="width: 100%;height: 800px" frameborder="0"></iframe>
|
||||||
@@ -548,10 +548,16 @@
|
|||||||
<!--IsvideoFileEnd-->
|
<!--IsvideoFileEnd-->
|
||||||
<!--IspdfFileStart-->
|
<!--IspdfFileStart-->
|
||||||
pdfjsLib.GlobalWorkerOptions.workerSrc = '//cdn.bootcss.com/pdf.js/2.3.200/pdf.worker.min.js';
|
pdfjsLib.GlobalWorkerOptions.workerSrc = '//cdn.bootcss.com/pdf.js/2.3.200/pdf.worker.min.js';
|
||||||
var loadingTask = pdfjsLib.getDocument({ url: '<!--FileDownUrl-->', });
|
var loadingTask = pdfjsLib.getDocument({
|
||||||
|
url: '<!--FileDownUrl-->',
|
||||||
|
cMapUrl: "//cdn.jsdelivr.net/npm/pdfjs-dist@2.2.228/cmaps/",
|
||||||
|
cMapPacked: true,
|
||||||
|
rangeChunkSize: 65535
|
||||||
|
});
|
||||||
loadingTask.promise.then(function(pdf) {
|
loadingTask.promise.then(function(pdf) {
|
||||||
var pagenum = pdf.numPages;
|
var pagenum = pdf.numPages;
|
||||||
var pdfContainer = document.getElementById('pdf-d');
|
var pdfContainer = document.getElementById('pdf-d');
|
||||||
|
pdfContainer.innerHTML = '';
|
||||||
for (var i=1;i<=pagenum;i++) {
|
for (var i=1;i<=pagenum;i++) {
|
||||||
var canvasNew = document.createElement('canvas');
|
var canvasNew = document.createElement('canvas');
|
||||||
canvasNew.id = 'pdf-c'+i;
|
canvasNew.id = 'pdf-c'+i;
|
||||||
@@ -775,19 +781,26 @@
|
|||||||
var timea=new Date().getTime();
|
var timea=new Date().getTime();
|
||||||
var i=0;
|
var i=0;
|
||||||
getuplink(i);
|
getuplink(i);
|
||||||
function getuplink(i) {
|
function getuplink(i, r=0) {
|
||||||
var file=files[i];
|
var file=files[i];
|
||||||
var tr1=document.createElement('tr');
|
var td1;
|
||||||
table1.appendChild(tr1);
|
var td2;
|
||||||
tr1.setAttribute('data-to',1);
|
if (r==0) {
|
||||||
var td1=document.createElement('td');
|
var tr1=document.createElement('tr');
|
||||||
tr1.appendChild(td1);
|
table1.appendChild(tr1);
|
||||||
td1.setAttribute('style','width:30%;word-break:break-word;');
|
tr1.setAttribute('data-to',1);
|
||||||
td1.setAttribute('id','upfile_td1_'+timea+'_'+i);
|
td1=document.createElement('td');
|
||||||
td1.innerHTML=(file.webkitRelativePath||file.name)+'<br>'+size_format(file.size);
|
tr1.appendChild(td1);
|
||||||
var td2=document.createElement('td');
|
td1.setAttribute('style','width:30%;word-break:break-word;');
|
||||||
tr1.appendChild(td2);
|
td1.setAttribute('id','upfile_td1_'+timea+'_'+i);
|
||||||
td2.setAttribute('id','upfile_td2_'+timea+'_'+i);
|
td1.innerHTML=(file.webkitRelativePath||file.name)+'<br>'+size_format(file.size);
|
||||||
|
td2=document.createElement('td');
|
||||||
|
tr1.appendChild(td2);
|
||||||
|
td2.setAttribute('id','upfile_td2_'+timea+'_'+i);
|
||||||
|
}
|
||||||
|
var tdnum = timea+'_'+i;
|
||||||
|
td1=document.getElementById('upfile_td1_'+tdnum);
|
||||||
|
td2=document.getElementById('upfile_td2_'+tdnum);
|
||||||
if (file.size>100*1024*1024*1024) {
|
if (file.size>100*1024*1024*1024) {
|
||||||
td2.innerHTML='<font color="red"><!--constStr@UpFileTooLarge--></font>';
|
td2.innerHTML='<font color="red"><!--constStr@UpFileTooLarge--></font>';
|
||||||
uploadbuttonshow();
|
uploadbuttonshow();
|
||||||
@@ -832,35 +845,46 @@
|
|||||||
var xhr1 = new XMLHttpRequest();
|
var xhr1 = new XMLHttpRequest();
|
||||||
xhr1.open("GET", '?action=upbigfile&upbigfilename='+ upbigfilename +'&filesize='+ file.size +'&lastModified='+ file.lastModified);
|
xhr1.open("GET", '?action=upbigfile&upbigfilename='+ upbigfilename +'&filesize='+ file.size +'&lastModified='+ file.lastModified);
|
||||||
xhr1.setRequestHeader('x-requested-with','XMLHttpRequest');
|
xhr1.setRequestHeader('x-requested-with','XMLHttpRequest');
|
||||||
xhr1.send(null);
|
xhr1.onprogress = function(e){
|
||||||
|
td2.innerHTML+='.';
|
||||||
|
}
|
||||||
xhr1.onload = function(e){
|
xhr1.onload = function(e){
|
||||||
|
console.log(xhr1.status+xhr1.responseText);
|
||||||
td2.innerHTML='<font color="red">'+xhr1.responseText+'</font>';
|
td2.innerHTML='<font color="red">'+xhr1.responseText+'</font>';
|
||||||
|
if (xhr1.status==409) {
|
||||||
|
// td2.innerHTML='nameAlreadyExists';
|
||||||
|
var html=JSON.parse(xhr1.responseText);
|
||||||
|
td2.innerHTML=html['error']['code']+': '+html['error']['message'];
|
||||||
|
<!--GuestStart-->
|
||||||
|
td2.innerHTML='md5: '+filemd5;
|
||||||
|
<!--GuestEnd-->
|
||||||
|
td1.innerHTML='<div style="color:green"><a href="<!--base_disk_path--><!--Path-->'+(file.webkitRelativePath||file.name)+'?preview" id="upfile_a_'+tdnum+'" target="_blank">'+td1.innerHTML+'</a><br><a href="<!--base_disk_path--><!--Path-->'+(file.webkitRelativePath||file.name)+'" id="upfile_a1_'+tdnum+'"></a><!--constStr@UploadComplete--><button onclick="CopyAllDownloadUrl(\'#upfile_a1_'+tdnum+'\');" id="upfile_cpbt_'+tdnum+'" <!--AdminStart--> style="display:none"<!--AdminEnd--> ><!--constStr@CopyUrl--></button></div>';
|
||||||
|
}
|
||||||
if (xhr1.status==200) {
|
if (xhr1.status==200) {
|
||||||
console.log(xhr1.responseText);
|
if (xhr1.responseText=='') {
|
||||||
|
getuplink(i,1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
var html=JSON.parse(xhr1.responseText);
|
var html=JSON.parse(xhr1.responseText);
|
||||||
if (!html['uploadUrl']) {
|
if (!html['uploadUrl']) {
|
||||||
td2.innerHTML='<font color="red">'+xhr1.responseText+'</font><br>';
|
td2.innerHTML='<font color="red">'+xhr1.responseText+'</font><br>';
|
||||||
uploadbuttonshow();
|
|
||||||
} else {
|
} else {
|
||||||
td2.innerHTML='<!--constStr@UploadStart--> ...';
|
td2.innerHTML='<!--constStr@UploadStart--> ...';
|
||||||
binupfile(file,html['uploadUrl'],timea+'_'+i, upbigfilename);
|
binupfile(file,html['uploadUrl'],timea+'_'+i, upbigfilename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (xhr1.status==409) {
|
|
||||||
td2.innerHTML='md5: '+filemd5;
|
|
||||||
tdnum = timea+'_'+i;
|
|
||||||
document.getElementById('upfile_td1_'+tdnum).innerHTML='<div style="color:green"><a href="<!--base_disk_path--><!--Path-->'+upbigfilename+'?preview" id="upfile_a_'+tdnum+'" target="_blank">'+document.getElementById('upfile_td1_'+tdnum).innerHTML+'</a><br><a href="<!--base_disk_path--><!--Path-->'+upbigfilename+'" id="upfile_a1_'+tdnum+'"></a><!--constStr@UploadComplete--><button onclick="CopyAllDownloadUrl(\'#upfile_a1_'+tdnum+'\');" id="upfile_cpbt_'+tdnum+'" <!--AdminStart--> style="display:none"<!--AdminEnd--> ><!--constStr@CopyUrl--></button></div>';
|
|
||||||
}
|
|
||||||
if (i<files.length-1) {
|
if (i<files.length-1) {
|
||||||
i++;
|
i++;
|
||||||
getuplink(i);
|
getuplink(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
xhr1.send(null);
|
||||||
<!--GuestStart-->
|
<!--GuestStart-->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
<!--GuestEnd-->
|
<!--GuestEnd-->
|
||||||
}
|
}
|
||||||
|
uploadbuttonshow();
|
||||||
}
|
}
|
||||||
function size_format(num) {
|
function size_format(num) {
|
||||||
if (num>1024) {
|
if (num>1024) {
|
||||||
@@ -953,7 +977,7 @@
|
|||||||
}
|
}
|
||||||
document.getElementById('upfile_td1_'+tdnum).innerHTML='<div style="color:green"><a href="<!--base_disk_path--><!--Path-->'+(file.webkitRelativePath||response.name)+'?preview" id="upfile_a_'+tdnum+'" target="_blank">'+document.getElementById('upfile_td1_'+tdnum).innerHTML+'</a><br><a href="<!--base_disk_path--><!--Path-->'+(file.webkitRelativePath||response.name)+'" id="upfile_a1_'+tdnum+'"></a><!--constStr@UploadComplete--><button onclick="CopyAllDownloadUrl(\'#upfile_a1_'+tdnum+'\');" id="upfile_cpbt_'+tdnum+'" <!--AdminStart--> style="display:none"<!--AdminEnd--> ><!--constStr@CopyUrl--></button></div>';
|
document.getElementById('upfile_td1_'+tdnum).innerHTML='<div style="color:green"><a href="<!--base_disk_path--><!--Path-->'+(file.webkitRelativePath||response.name)+'?preview" id="upfile_a_'+tdnum+'" target="_blank">'+document.getElementById('upfile_td1_'+tdnum).innerHTML+'</a><br><a href="<!--base_disk_path--><!--Path-->'+(file.webkitRelativePath||response.name)+'" id="upfile_a1_'+tdnum+'"></a><!--constStr@UploadComplete--><button onclick="CopyAllDownloadUrl(\'#upfile_a1_'+tdnum+'\');" id="upfile_cpbt_'+tdnum+'" <!--AdminStart--> style="display:none"<!--AdminEnd--> ><!--constStr@CopyUrl--></button></div>';
|
||||||
label.innerHTML=StartStr+MiddleStr;
|
label.innerHTML=StartStr+MiddleStr;
|
||||||
uploadbuttonshow();
|
// uploadbuttonshow();
|
||||||
<!--AdminStart-->
|
<!--AdminStart-->
|
||||||
response.name=file.webkitRelativePath||response.name;
|
response.name=file.webkitRelativePath||response.name;
|
||||||
addelement(response);
|
addelement(response);
|
||||||
@@ -976,7 +1000,7 @@
|
|||||||
} else {
|
} else {
|
||||||
label.innerHTML='<font color="red">'+xhr2.responseText+'</font>';
|
label.innerHTML='<font color="red">'+xhr2.responseText+'</font>';
|
||||||
}
|
}
|
||||||
uploadbuttonshow();
|
// uploadbuttonshow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* APC cache provider.
|
|
||||||
*
|
|
||||||
* @link www.doctrine-project.org
|
|
||||||
* @deprecated since version 1.6, use ApcuCache instead
|
|
||||||
* @since 2.0
|
|
||||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
|
||||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
||||||
* @author Jonathan Wage <jonwage@gmail.com>
|
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
|
||||||
* @author David Abdemoulaie <dave@hobodave.com>
|
|
||||||
*/
|
|
||||||
class ApcCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
return apc_fetch($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
return apc_exists($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
return apc_store($id, $data, $lifeTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
// apc_delete returns false if the id does not exist
|
|
||||||
return apc_delete($id) || ! apc_exists($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
return apc_clear_cache() && apc_clear_cache('user');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetchMultiple(array $keys)
|
|
||||||
{
|
|
||||||
return apc_fetch($keys) ?: [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
|
|
||||||
{
|
|
||||||
$result = apc_store($keysAndValues, null, $lifetime);
|
|
||||||
|
|
||||||
return empty($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
$info = apc_cache_info('', true);
|
|
||||||
$sma = apc_sma_info();
|
|
||||||
|
|
||||||
// @TODO - Temporary fix @see https://github.com/krakjoe/apcu/pull/42
|
|
||||||
if (PHP_VERSION_ID >= 50500) {
|
|
||||||
$info['num_hits'] = isset($info['num_hits']) ? $info['num_hits'] : $info['nhits'];
|
|
||||||
$info['num_misses'] = isset($info['num_misses']) ? $info['num_misses'] : $info['nmisses'];
|
|
||||||
$info['start_time'] = isset($info['start_time']) ? $info['start_time'] : $info['stime'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return array(
|
|
||||||
Cache::STATS_HITS => $info['num_hits'],
|
|
||||||
Cache::STATS_MISSES => $info['num_misses'],
|
|
||||||
Cache::STATS_UPTIME => $info['start_time'],
|
|
||||||
Cache::STATS_MEMORY_USAGE => $info['mem_size'],
|
|
||||||
Cache::STATS_MEMORY_AVAILABLE => $sma['avail_mem'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* APCu cache provider.
|
|
||||||
*
|
|
||||||
* @link www.doctrine-project.org
|
|
||||||
* @since 1.6
|
|
||||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
|
||||||
*/
|
|
||||||
class ApcuCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
return apcu_fetch($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
return apcu_exists($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
return apcu_store($id, $data, $lifeTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
// apcu_delete returns false if the id does not exist
|
|
||||||
return apcu_delete($id) || ! apcu_exists($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
return apcu_clear_cache();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetchMultiple(array $keys)
|
|
||||||
{
|
|
||||||
return apcu_fetch($keys) ?: [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
|
|
||||||
{
|
|
||||||
$result = apcu_store($keysAndValues, null, $lifetime);
|
|
||||||
|
|
||||||
return empty($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
$info = apcu_cache_info(true);
|
|
||||||
$sma = apcu_sma_info();
|
|
||||||
|
|
||||||
return array(
|
|
||||||
Cache::STATS_HITS => $info['num_hits'],
|
|
||||||
Cache::STATS_MISSES => $info['num_misses'],
|
|
||||||
Cache::STATS_UPTIME => $info['start_time'],
|
|
||||||
Cache::STATS_MEMORY_USAGE => $info['mem_size'],
|
|
||||||
Cache::STATS_MEMORY_AVAILABLE => $sma['avail_mem'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Array cache driver.
|
|
||||||
*
|
|
||||||
* @link www.doctrine-project.org
|
|
||||||
* @since 2.0
|
|
||||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
|
||||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
||||||
* @author Jonathan Wage <jonwage@gmail.com>
|
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
|
||||||
* @author David Abdemoulaie <dave@hobodave.com>
|
|
||||||
*/
|
|
||||||
class ArrayCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array[] $data each element being a tuple of [$data, $expiration], where the expiration is int|bool
|
|
||||||
*/
|
|
||||||
private $data = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $hitsCount = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $missesCount = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $upTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->upTime = time();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
if (! $this->doContains($id)) {
|
|
||||||
$this->missesCount += 1;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->hitsCount += 1;
|
|
||||||
|
|
||||||
return $this->data[$id][0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
if (! isset($this->data[$id])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$expiration = $this->data[$id][1];
|
|
||||||
|
|
||||||
if ($expiration && $expiration < time()) {
|
|
||||||
$this->doDelete($id);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
$this->data[$id] = [$data, $lifeTime ? time() + $lifeTime : false];
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
unset($this->data[$id]);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
$this->data = [];
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
Cache::STATS_HITS => $this->hitsCount,
|
|
||||||
Cache::STATS_MISSES => $this->missesCount,
|
|
||||||
Cache::STATS_UPTIME => $this->upTime,
|
|
||||||
Cache::STATS_MEMORY_USAGE => null,
|
|
||||||
Cache::STATS_MEMORY_AVAILABLE => null,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cache provider that allows to easily chain multiple cache providers
|
|
||||||
*
|
|
||||||
* @author Michaël Gallego <mic.gallego@gmail.com>
|
|
||||||
*/
|
|
||||||
class ChainCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var CacheProvider[]
|
|
||||||
*/
|
|
||||||
private $cacheProviders = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param CacheProvider[] $cacheProviders
|
|
||||||
*/
|
|
||||||
public function __construct($cacheProviders = array())
|
|
||||||
{
|
|
||||||
$this->cacheProviders = $cacheProviders;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function setNamespace($namespace)
|
|
||||||
{
|
|
||||||
parent::setNamespace($namespace);
|
|
||||||
|
|
||||||
foreach ($this->cacheProviders as $cacheProvider) {
|
|
||||||
$cacheProvider->setNamespace($namespace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
foreach ($this->cacheProviders as $key => $cacheProvider) {
|
|
||||||
if ($cacheProvider->doContains($id)) {
|
|
||||||
$value = $cacheProvider->doFetch($id);
|
|
||||||
|
|
||||||
// We populate all the previous cache layers (that are assumed to be faster)
|
|
||||||
for ($subKey = $key - 1 ; $subKey >= 0 ; $subKey--) {
|
|
||||||
$this->cacheProviders[$subKey]->doSave($id, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
foreach ($this->cacheProviders as $cacheProvider) {
|
|
||||||
if ($cacheProvider->doContains($id)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
$stored = true;
|
|
||||||
|
|
||||||
foreach ($this->cacheProviders as $cacheProvider) {
|
|
||||||
$stored = $cacheProvider->doSave($id, $data, $lifeTime) && $stored;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $stored;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
$deleted = true;
|
|
||||||
|
|
||||||
foreach ($this->cacheProviders as $cacheProvider) {
|
|
||||||
$deleted = $cacheProvider->doDelete($id) && $deleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $deleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
$flushed = true;
|
|
||||||
|
|
||||||
foreach ($this->cacheProviders as $cacheProvider) {
|
|
||||||
$flushed = $cacheProvider->doFlush() && $flushed;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $flushed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
// We return all the stats from all adapters
|
|
||||||
$stats = array();
|
|
||||||
|
|
||||||
foreach ($this->cacheProviders as $cacheProvider) {
|
|
||||||
$stats[] = $cacheProvider->doGetStats();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $stats;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
use \Couchbase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Couchbase cache provider.
|
|
||||||
*
|
|
||||||
* @link www.doctrine-project.org
|
|
||||||
* @since 2.4
|
|
||||||
* @author Michael Nitschinger <michael@nitschinger.at>
|
|
||||||
*/
|
|
||||||
class CouchbaseCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Couchbase|null
|
|
||||||
*/
|
|
||||||
private $couchbase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the Couchbase instance to use.
|
|
||||||
*
|
|
||||||
* @param Couchbase $couchbase
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setCouchbase(Couchbase $couchbase)
|
|
||||||
{
|
|
||||||
$this->couchbase = $couchbase;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Couchbase instance used by the cache.
|
|
||||||
*
|
|
||||||
* @return Couchbase|null
|
|
||||||
*/
|
|
||||||
public function getCouchbase()
|
|
||||||
{
|
|
||||||
return $this->couchbase;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
return $this->couchbase->get($id) ?: false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
return (null !== $this->couchbase->get($id));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
if ($lifeTime > 30 * 24 * 3600) {
|
|
||||||
$lifeTime = time() + $lifeTime;
|
|
||||||
}
|
|
||||||
return $this->couchbase->set($id, $data, (int) $lifeTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
return $this->couchbase->delete($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
return $this->couchbase->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
$stats = $this->couchbase->getStats();
|
|
||||||
$servers = $this->couchbase->getServers();
|
|
||||||
$server = explode(":", $servers[0]);
|
|
||||||
$key = $server[0] . ":" . "11210";
|
|
||||||
$stats = $stats[$key];
|
|
||||||
return array(
|
|
||||||
Cache::STATS_HITS => $stats['get_hits'],
|
|
||||||
Cache::STATS_MISSES => $stats['get_misses'],
|
|
||||||
Cache::STATS_UPTIME => $stats['uptime'],
|
|
||||||
Cache::STATS_MEMORY_USAGE => $stats['bytes'],
|
|
||||||
Cache::STATS_MEMORY_AVAILABLE => $stats['limit_maxbytes'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
use \Memcache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Memcache cache provider.
|
|
||||||
*
|
|
||||||
* @link www.doctrine-project.org
|
|
||||||
* @since 2.0
|
|
||||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
|
||||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
||||||
* @author Jonathan Wage <jonwage@gmail.com>
|
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
|
||||||
* @author David Abdemoulaie <dave@hobodave.com>
|
|
||||||
*/
|
|
||||||
class MemcacheCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Memcache|null
|
|
||||||
*/
|
|
||||||
private $memcache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the memcache instance to use.
|
|
||||||
*
|
|
||||||
* @param Memcache $memcache
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setMemcache(Memcache $memcache)
|
|
||||||
{
|
|
||||||
$this->memcache = $memcache;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the memcache instance used by the cache.
|
|
||||||
*
|
|
||||||
* @return Memcache|null
|
|
||||||
*/
|
|
||||||
public function getMemcache()
|
|
||||||
{
|
|
||||||
return $this->memcache;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
return $this->memcache->get($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
$flags = null;
|
|
||||||
$this->memcache->get($id, $flags);
|
|
||||||
|
|
||||||
//if memcache has changed the value of "flags", it means the value exists
|
|
||||||
return ($flags !== null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
if ($lifeTime > 30 * 24 * 3600) {
|
|
||||||
$lifeTime = time() + $lifeTime;
|
|
||||||
}
|
|
||||||
return $this->memcache->set($id, $data, 0, (int) $lifeTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
// Memcache::delete() returns false if entry does not exist
|
|
||||||
return $this->memcache->delete($id) || ! $this->doContains($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
return $this->memcache->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
$stats = $this->memcache->getStats();
|
|
||||||
return array(
|
|
||||||
Cache::STATS_HITS => $stats['get_hits'],
|
|
||||||
Cache::STATS_MISSES => $stats['get_misses'],
|
|
||||||
Cache::STATS_UPTIME => $stats['uptime'],
|
|
||||||
Cache::STATS_MEMORY_USAGE => $stats['bytes'],
|
|
||||||
Cache::STATS_MEMORY_AVAILABLE => $stats['limit_maxbytes'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
use \Memcached;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Memcached cache provider.
|
|
||||||
*
|
|
||||||
* @link www.doctrine-project.org
|
|
||||||
* @since 2.2
|
|
||||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
|
||||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
||||||
* @author Jonathan Wage <jonwage@gmail.com>
|
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
|
||||||
* @author David Abdemoulaie <dave@hobodave.com>
|
|
||||||
*/
|
|
||||||
class MemcachedCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Memcached|null
|
|
||||||
*/
|
|
||||||
private $memcached;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the memcache instance to use.
|
|
||||||
*
|
|
||||||
* @param Memcached $memcached
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setMemcached(Memcached $memcached)
|
|
||||||
{
|
|
||||||
$this->memcached = $memcached;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the memcached instance used by the cache.
|
|
||||||
*
|
|
||||||
* @return Memcached|null
|
|
||||||
*/
|
|
||||||
public function getMemcached()
|
|
||||||
{
|
|
||||||
return $this->memcached;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
return $this->memcached->get($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetchMultiple(array $keys)
|
|
||||||
{
|
|
||||||
return $this->memcached->getMulti($keys) ?: [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
|
|
||||||
{
|
|
||||||
if ($lifetime > 30 * 24 * 3600) {
|
|
||||||
$lifetime = time() + $lifetime;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->memcached->setMulti($keysAndValues, $lifetime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
$this->memcached->get($id);
|
|
||||||
|
|
||||||
return $this->memcached->getResultCode() === Memcached::RES_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
if ($lifeTime > 30 * 24 * 3600) {
|
|
||||||
$lifeTime = time() + $lifeTime;
|
|
||||||
}
|
|
||||||
return $this->memcached->set($id, $data, (int) $lifeTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
return $this->memcached->delete($id)
|
|
||||||
|| $this->memcached->getResultCode() === Memcached::RES_NOTFOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
return $this->memcached->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
$stats = $this->memcached->getStats();
|
|
||||||
$servers = $this->memcached->getServerList();
|
|
||||||
$key = $servers[0]['host'] . ':' . $servers[0]['port'];
|
|
||||||
$stats = $stats[$key];
|
|
||||||
return array(
|
|
||||||
Cache::STATS_HITS => $stats['get_hits'],
|
|
||||||
Cache::STATS_MISSES => $stats['get_misses'],
|
|
||||||
Cache::STATS_UPTIME => $stats['uptime'],
|
|
||||||
Cache::STATS_MEMORY_USAGE => $stats['bytes'],
|
|
||||||
Cache::STATS_MEMORY_AVAILABLE => $stats['limit_maxbytes'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,197 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
use MongoBinData;
|
|
||||||
use MongoCollection;
|
|
||||||
use MongoCursorException;
|
|
||||||
use MongoDate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MongoDB cache provider.
|
|
||||||
*
|
|
||||||
* @since 1.1
|
|
||||||
* @author Jeremy Mikola <jmikola@gmail.com>
|
|
||||||
*/
|
|
||||||
class MongoDBCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The data field will store the serialized PHP value.
|
|
||||||
*/
|
|
||||||
const DATA_FIELD = 'd';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The expiration field will store a MongoDate value indicating when the
|
|
||||||
* cache entry should expire.
|
|
||||||
*
|
|
||||||
* With MongoDB 2.2+, entries can be automatically deleted by MongoDB by
|
|
||||||
* indexing this field with the "expireAfterSeconds" option equal to zero.
|
|
||||||
* This will direct MongoDB to regularly query for and delete any entries
|
|
||||||
* whose date is older than the current time. Entries without a date value
|
|
||||||
* in this field will be ignored.
|
|
||||||
*
|
|
||||||
* The cache provider will also check dates on its own, in case expired
|
|
||||||
* entries are fetched before MongoDB's TTLMonitor pass can expire them.
|
|
||||||
*
|
|
||||||
* @see http://docs.mongodb.org/manual/tutorial/expire-data/
|
|
||||||
*/
|
|
||||||
const EXPIRATION_FIELD = 'e';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var MongoCollection
|
|
||||||
*/
|
|
||||||
private $collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* This provider will default to the write concern and read preference
|
|
||||||
* options set on the MongoCollection instance (or inherited from MongoDB or
|
|
||||||
* MongoClient). Using an unacknowledged write concern (< 1) may make the
|
|
||||||
* return values of delete() and save() unreliable. Reading from secondaries
|
|
||||||
* may make contain() and fetch() unreliable.
|
|
||||||
*
|
|
||||||
* @see http://www.php.net/manual/en/mongo.readpreferences.php
|
|
||||||
* @see http://www.php.net/manual/en/mongo.writeconcerns.php
|
|
||||||
* @param MongoCollection $collection
|
|
||||||
*/
|
|
||||||
public function __construct(MongoCollection $collection)
|
|
||||||
{
|
|
||||||
$this->collection = $collection;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
$document = $this->collection->findOne(array('_id' => $id), array(self::DATA_FIELD, self::EXPIRATION_FIELD));
|
|
||||||
|
|
||||||
if ($document === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->isExpired($document)) {
|
|
||||||
$this->doDelete($id);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return unserialize($document[self::DATA_FIELD]->bin);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
$document = $this->collection->findOne(array('_id' => $id), array(self::EXPIRATION_FIELD));
|
|
||||||
|
|
||||||
if ($document === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->isExpired($document)) {
|
|
||||||
$this->doDelete($id);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$result = $this->collection->update(
|
|
||||||
array('_id' => $id),
|
|
||||||
array('$set' => array(
|
|
||||||
self::EXPIRATION_FIELD => ($lifeTime > 0 ? new MongoDate(time() + $lifeTime) : null),
|
|
||||||
self::DATA_FIELD => new MongoBinData(serialize($data), MongoBinData::BYTE_ARRAY),
|
|
||||||
)),
|
|
||||||
array('upsert' => true, 'multiple' => false)
|
|
||||||
);
|
|
||||||
} catch (MongoCursorException $e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return isset($result['ok']) ? $result['ok'] == 1 : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
$result = $this->collection->remove(array('_id' => $id));
|
|
||||||
|
|
||||||
return isset($result['ok']) ? $result['ok'] == 1 : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
// Use remove() in lieu of drop() to maintain any collection indexes
|
|
||||||
$result = $this->collection->remove();
|
|
||||||
|
|
||||||
return isset($result['ok']) ? $result['ok'] == 1 : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
$serverStatus = $this->collection->db->command(array(
|
|
||||||
'serverStatus' => 1,
|
|
||||||
'locks' => 0,
|
|
||||||
'metrics' => 0,
|
|
||||||
'recordStats' => 0,
|
|
||||||
'repl' => 0,
|
|
||||||
));
|
|
||||||
|
|
||||||
$collStats = $this->collection->db->command(array('collStats' => 1));
|
|
||||||
|
|
||||||
return array(
|
|
||||||
Cache::STATS_HITS => null,
|
|
||||||
Cache::STATS_MISSES => null,
|
|
||||||
Cache::STATS_UPTIME => (isset($serverStatus['uptime']) ? (int) $serverStatus['uptime'] : null),
|
|
||||||
Cache::STATS_MEMORY_USAGE => (isset($collStats['size']) ? (int) $collStats['size'] : null),
|
|
||||||
Cache::STATS_MEMORY_AVAILABLE => null,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the document is expired.
|
|
||||||
*
|
|
||||||
* @param array $document
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function isExpired(array $document)
|
|
||||||
{
|
|
||||||
return isset($document[self::EXPIRATION_FIELD]) &&
|
|
||||||
$document[self::EXPIRATION_FIELD] instanceof MongoDate &&
|
|
||||||
$document[self::EXPIRATION_FIELD]->sec < time();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Php file cache driver.
|
|
||||||
*
|
|
||||||
* @since 2.3
|
|
||||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
|
||||||
*/
|
|
||||||
class PhpFileCache extends FileCache
|
|
||||||
{
|
|
||||||
const EXTENSION = '.doctrinecache.php';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function __construct($directory, $extension = self::EXTENSION, $umask = 0002)
|
|
||||||
{
|
|
||||||
parent::__construct($directory, $extension, $umask);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
$value = $this->includeFileForId($id);
|
|
||||||
|
|
||||||
if (! $value) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($value['lifetime'] !== 0 && $value['lifetime'] < time()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value['data'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
$value = $this->includeFileForId($id);
|
|
||||||
|
|
||||||
if (! $value) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value['lifetime'] === 0 || $value['lifetime'] > time();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
if ($lifeTime > 0) {
|
|
||||||
$lifeTime = time() + $lifeTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_object($data) && ! method_exists($data, '__set_state')) {
|
|
||||||
throw new \InvalidArgumentException(
|
|
||||||
"Invalid argument given, PhpFileCache only allows objects that implement __set_state() " .
|
|
||||||
"and fully support var_export(). You can use the FilesystemCache to save arbitrary object " .
|
|
||||||
"graphs using serialize()/deserialize()."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$filename = $this->getFilename($id);
|
|
||||||
|
|
||||||
$value = array(
|
|
||||||
'lifetime' => $lifeTime,
|
|
||||||
'data' => $data
|
|
||||||
);
|
|
||||||
|
|
||||||
$value = var_export($value, true);
|
|
||||||
$code = sprintf('<?php return %s;', $value);
|
|
||||||
|
|
||||||
return $this->writeFile($filename, $code);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $id
|
|
||||||
*
|
|
||||||
* @return array|false
|
|
||||||
*/
|
|
||||||
private function includeFileForId($id)
|
|
||||||
{
|
|
||||||
$fileName = $this->getFilename($id);
|
|
||||||
|
|
||||||
// note: error suppression is still faster than `file_exists`, `is_file` and `is_readable`
|
|
||||||
$value = @include $fileName;
|
|
||||||
|
|
||||||
if (! isset($value['lifetime'])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
use Predis\ClientInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Predis cache provider.
|
|
||||||
*
|
|
||||||
* @author othillo <othillo@othillo.nl>
|
|
||||||
*/
|
|
||||||
class PredisCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var ClientInterface
|
|
||||||
*/
|
|
||||||
private $client;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ClientInterface $client
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(ClientInterface $client)
|
|
||||||
{
|
|
||||||
$this->client = $client;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
$result = $this->client->get($id);
|
|
||||||
if (null === $result) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return unserialize($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetchMultiple(array $keys)
|
|
||||||
{
|
|
||||||
$fetchedItems = call_user_func_array(array($this->client, 'mget'), $keys);
|
|
||||||
|
|
||||||
return array_map('unserialize', array_filter(array_combine($keys, $fetchedItems)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
|
|
||||||
{
|
|
||||||
if ($lifetime) {
|
|
||||||
$success = true;
|
|
||||||
|
|
||||||
// Keys have lifetime, use SETEX for each of them
|
|
||||||
foreach ($keysAndValues as $key => $value) {
|
|
||||||
$response = $this->client->setex($key, $lifetime, serialize($value));
|
|
||||||
|
|
||||||
if ((string) $response != 'OK') {
|
|
||||||
$success = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $success;
|
|
||||||
}
|
|
||||||
|
|
||||||
// No lifetime, use MSET
|
|
||||||
$response = $this->client->mset(array_map(function ($value) {
|
|
||||||
return serialize($value);
|
|
||||||
}, $keysAndValues));
|
|
||||||
|
|
||||||
return (string) $response == 'OK';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
return (bool) $this->client->exists($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
$data = serialize($data);
|
|
||||||
if ($lifeTime > 0) {
|
|
||||||
$response = $this->client->setex($id, $lifeTime, $data);
|
|
||||||
} else {
|
|
||||||
$response = $this->client->set($id, $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response === true || $response == 'OK';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
return $this->client->del($id) >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
$response = $this->client->flushdb();
|
|
||||||
|
|
||||||
return $response === true || $response == 'OK';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
$info = $this->client->info();
|
|
||||||
|
|
||||||
return array(
|
|
||||||
Cache::STATS_HITS => $info['Stats']['keyspace_hits'],
|
|
||||||
Cache::STATS_MISSES => $info['Stats']['keyspace_misses'],
|
|
||||||
Cache::STATS_UPTIME => $info['Server']['uptime_in_seconds'],
|
|
||||||
Cache::STATS_MEMORY_USAGE => $info['Memory']['used_memory'],
|
|
||||||
Cache::STATS_MEMORY_AVAILABLE => false
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
use Redis;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Redis cache provider.
|
|
||||||
*
|
|
||||||
* @link www.doctrine-project.org
|
|
||||||
* @since 2.2
|
|
||||||
* @author Osman Ungur <osmanungur@gmail.com>
|
|
||||||
*/
|
|
||||||
class RedisCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Redis|null
|
|
||||||
*/
|
|
||||||
private $redis;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the redis instance to use.
|
|
||||||
*
|
|
||||||
* @param Redis $redis
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setRedis(Redis $redis)
|
|
||||||
{
|
|
||||||
$redis->setOption(Redis::OPT_SERIALIZER, $this->getSerializerValue());
|
|
||||||
$this->redis = $redis;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the redis instance used by the cache.
|
|
||||||
*
|
|
||||||
* @return Redis|null
|
|
||||||
*/
|
|
||||||
public function getRedis()
|
|
||||||
{
|
|
||||||
return $this->redis;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
return $this->redis->get($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetchMultiple(array $keys)
|
|
||||||
{
|
|
||||||
$fetchedItems = array_combine($keys, $this->redis->mget($keys));
|
|
||||||
|
|
||||||
// Redis mget returns false for keys that do not exist. So we need to filter those out unless it's the real data.
|
|
||||||
$foundItems = array();
|
|
||||||
|
|
||||||
foreach ($fetchedItems as $key => $value) {
|
|
||||||
if (false !== $value || $this->redis->exists($key)) {
|
|
||||||
$foundItems[$key] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $foundItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
|
|
||||||
{
|
|
||||||
if ($lifetime) {
|
|
||||||
$success = true;
|
|
||||||
|
|
||||||
// Keys have lifetime, use SETEX for each of them
|
|
||||||
foreach ($keysAndValues as $key => $value) {
|
|
||||||
if (!$this->redis->setex($key, $lifetime, $value)) {
|
|
||||||
$success = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $success;
|
|
||||||
}
|
|
||||||
|
|
||||||
// No lifetime, use MSET
|
|
||||||
return (bool) $this->redis->mset($keysAndValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
return $this->redis->exists($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
if ($lifeTime > 0) {
|
|
||||||
return $this->redis->setex($id, $lifeTime, $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->redis->set($id, $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
return $this->redis->delete($id) >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
return $this->redis->flushDB();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
$info = $this->redis->info();
|
|
||||||
return array(
|
|
||||||
Cache::STATS_HITS => $info['keyspace_hits'],
|
|
||||||
Cache::STATS_MISSES => $info['keyspace_misses'],
|
|
||||||
Cache::STATS_UPTIME => $info['uptime_in_seconds'],
|
|
||||||
Cache::STATS_MEMORY_USAGE => $info['used_memory'],
|
|
||||||
Cache::STATS_MEMORY_AVAILABLE => false
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the serializer constant to use. If Redis is compiled with
|
|
||||||
* igbinary support, that is used. Otherwise the default PHP serializer is
|
|
||||||
* used.
|
|
||||||
*
|
|
||||||
* @return integer One of the Redis::SERIALIZER_* constants
|
|
||||||
*/
|
|
||||||
protected function getSerializerValue()
|
|
||||||
{
|
|
||||||
if (defined('HHVM_VERSION')) {
|
|
||||||
return Redis::SERIALIZER_PHP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (defined('Redis::SERIALIZER_IGBINARY') && extension_loaded('igbinary')) {
|
|
||||||
return Redis::SERIALIZER_IGBINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Redis::SERIALIZER_PHP;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,250 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
use Riak\Bucket;
|
|
||||||
use Riak\Connection;
|
|
||||||
use Riak\Input;
|
|
||||||
use Riak\Exception;
|
|
||||||
use Riak\Object;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Riak cache provider.
|
|
||||||
*
|
|
||||||
* @link www.doctrine-project.org
|
|
||||||
* @since 1.1
|
|
||||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
||||||
*/
|
|
||||||
class RiakCache extends CacheProvider
|
|
||||||
{
|
|
||||||
const EXPIRES_HEADER = 'X-Riak-Meta-Expires';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Riak\Bucket
|
|
||||||
*/
|
|
||||||
private $bucket;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the riak bucket instance to use.
|
|
||||||
*
|
|
||||||
* @param \Riak\Bucket $bucket
|
|
||||||
*/
|
|
||||||
public function __construct(Bucket $bucket)
|
|
||||||
{
|
|
||||||
$this->bucket = $bucket;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$response = $this->bucket->get($id);
|
|
||||||
|
|
||||||
// No objects found
|
|
||||||
if ( ! $response->hasObject()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for attempted siblings
|
|
||||||
$object = ($response->hasSiblings())
|
|
||||||
? $this->resolveConflict($id, $response->getVClock(), $response->getObjectList())
|
|
||||||
: $response->getFirstObject();
|
|
||||||
|
|
||||||
// Check for expired object
|
|
||||||
if ($this->isExpired($object)) {
|
|
||||||
$this->bucket->delete($object);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return unserialize($object->getContent());
|
|
||||||
} catch (Exception\RiakException $e) {
|
|
||||||
// Covers:
|
|
||||||
// - Riak\ConnectionException
|
|
||||||
// - Riak\CommunicationException
|
|
||||||
// - Riak\UnexpectedResponseException
|
|
||||||
// - Riak\NotFoundException
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
// We only need the HEAD, not the entire object
|
|
||||||
$input = new Input\GetInput();
|
|
||||||
|
|
||||||
$input->setReturnHead(true);
|
|
||||||
|
|
||||||
$response = $this->bucket->get($id, $input);
|
|
||||||
|
|
||||||
// No objects found
|
|
||||||
if ( ! $response->hasObject()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$object = $response->getFirstObject();
|
|
||||||
|
|
||||||
// Check for expired object
|
|
||||||
if ($this->isExpired($object)) {
|
|
||||||
$this->bucket->delete($object);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (Exception\RiakException $e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$object = new Object($id);
|
|
||||||
|
|
||||||
$object->setContent(serialize($data));
|
|
||||||
|
|
||||||
if ($lifeTime > 0) {
|
|
||||||
$object->addMetadata(self::EXPIRES_HEADER, (string) (time() + $lifeTime));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->bucket->put($object);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (Exception\RiakException $e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$this->bucket->delete($id);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (Exception\BadArgumentsException $e) {
|
|
||||||
// Key did not exist on cluster already
|
|
||||||
} catch (Exception\RiakException $e) {
|
|
||||||
// Covers:
|
|
||||||
// - Riak\Exception\ConnectionException
|
|
||||||
// - Riak\Exception\CommunicationException
|
|
||||||
// - Riak\Exception\UnexpectedResponseException
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$keyList = $this->bucket->getKeyList();
|
|
||||||
|
|
||||||
foreach ($keyList as $key) {
|
|
||||||
$this->bucket->delete($key);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (Exception\RiakException $e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
// Only exposed through HTTP stats API, not Protocol Buffers API
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a given Riak Object have expired.
|
|
||||||
*
|
|
||||||
* @param \Riak\Object $object
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function isExpired(Object $object)
|
|
||||||
{
|
|
||||||
$metadataMap = $object->getMetadataMap();
|
|
||||||
|
|
||||||
return isset($metadataMap[self::EXPIRES_HEADER])
|
|
||||||
&& $metadataMap[self::EXPIRES_HEADER] < time();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On-read conflict resolution. Applied approach here is last write wins.
|
|
||||||
* Specific needs may override this method to apply alternate conflict resolutions.
|
|
||||||
*
|
|
||||||
* {@internal Riak does not attempt to resolve a write conflict, and store
|
|
||||||
* it as sibling of conflicted one. By following this approach, it is up to
|
|
||||||
* the next read to resolve the conflict. When this happens, your fetched
|
|
||||||
* object will have a list of siblings (read as a list of objects).
|
|
||||||
* In our specific case, we do not care about the intermediate ones since
|
|
||||||
* they are all the same read from storage, and we do apply a last sibling
|
|
||||||
* (last write) wins logic.
|
|
||||||
* If by any means our resolution generates another conflict, it'll up to
|
|
||||||
* next read to properly solve it.}
|
|
||||||
*
|
|
||||||
* @param string $id
|
|
||||||
* @param string $vClock
|
|
||||||
* @param array $objectList
|
|
||||||
*
|
|
||||||
* @return \Riak\Object
|
|
||||||
*/
|
|
||||||
protected function resolveConflict($id, $vClock, array $objectList)
|
|
||||||
{
|
|
||||||
// Our approach here is last-write wins
|
|
||||||
$winner = $objectList[count($objectList)];
|
|
||||||
|
|
||||||
$putInput = new Input\PutInput();
|
|
||||||
$putInput->setVClock($vClock);
|
|
||||||
|
|
||||||
$mergedObject = new Object($id);
|
|
||||||
$mergedObject->setContent($winner->getContent());
|
|
||||||
|
|
||||||
$this->bucket->put($mergedObject, $putInput);
|
|
||||||
|
|
||||||
return $mergedObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,220 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
use SQLite3;
|
|
||||||
use SQLite3Result;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SQLite3 cache provider.
|
|
||||||
*
|
|
||||||
* @since 1.4
|
|
||||||
* @author Jake Bell <jake@theunraveler.com>
|
|
||||||
*/
|
|
||||||
class SQLite3Cache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The ID field will store the cache key.
|
|
||||||
*/
|
|
||||||
const ID_FIELD = 'k';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The data field will store the serialized PHP value.
|
|
||||||
*/
|
|
||||||
const DATA_FIELD = 'd';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The expiration field will store a date value indicating when the
|
|
||||||
* cache entry should expire.
|
|
||||||
*/
|
|
||||||
const EXPIRATION_FIELD = 'e';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var SQLite3
|
|
||||||
*/
|
|
||||||
private $sqlite;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $table;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* Calling the constructor will ensure that the database file and table
|
|
||||||
* exist and will create both if they don't.
|
|
||||||
*
|
|
||||||
* @param SQLite3 $sqlite
|
|
||||||
* @param string $table
|
|
||||||
*/
|
|
||||||
public function __construct(SQLite3 $sqlite, $table)
|
|
||||||
{
|
|
||||||
$this->sqlite = $sqlite;
|
|
||||||
$this->table = (string) $table;
|
|
||||||
|
|
||||||
list($id, $data, $exp) = $this->getFields();
|
|
||||||
|
|
||||||
return $this->sqlite->exec(sprintf(
|
|
||||||
'CREATE TABLE IF NOT EXISTS %s(%s TEXT PRIMARY KEY NOT NULL, %s BLOB, %s INTEGER)',
|
|
||||||
$table,
|
|
||||||
$id,
|
|
||||||
$data,
|
|
||||||
$exp
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
if ($item = $this->findById($id)) {
|
|
||||||
return unserialize($item[self::DATA_FIELD]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
return null !== $this->findById($id, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
$statement = $this->sqlite->prepare(sprintf(
|
|
||||||
'INSERT OR REPLACE INTO %s (%s) VALUES (:id, :data, :expire)',
|
|
||||||
$this->table,
|
|
||||||
implode(',', $this->getFields())
|
|
||||||
));
|
|
||||||
|
|
||||||
$statement->bindValue(':id', $id);
|
|
||||||
$statement->bindValue(':data', serialize($data), SQLITE3_BLOB);
|
|
||||||
$statement->bindValue(':expire', $lifeTime > 0 ? time() + $lifeTime : null);
|
|
||||||
|
|
||||||
return $statement->execute() instanceof SQLite3Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
list($idField) = $this->getFields();
|
|
||||||
|
|
||||||
$statement = $this->sqlite->prepare(sprintf(
|
|
||||||
'DELETE FROM %s WHERE %s = :id',
|
|
||||||
$this->table,
|
|
||||||
$idField
|
|
||||||
));
|
|
||||||
|
|
||||||
$statement->bindValue(':id', $id);
|
|
||||||
|
|
||||||
return $statement->execute() instanceof SQLite3Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
return $this->sqlite->exec(sprintf('DELETE FROM %s', $this->table));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
// no-op.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find a single row by ID.
|
|
||||||
*
|
|
||||||
* @param mixed $id
|
|
||||||
* @param bool $includeData
|
|
||||||
*
|
|
||||||
* @return array|null
|
|
||||||
*/
|
|
||||||
private function findById($id, $includeData = true)
|
|
||||||
{
|
|
||||||
list($idField) = $fields = $this->getFields();
|
|
||||||
|
|
||||||
if (!$includeData) {
|
|
||||||
$key = array_search(static::DATA_FIELD, $fields);
|
|
||||||
unset($fields[$key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$statement = $this->sqlite->prepare(sprintf(
|
|
||||||
'SELECT %s FROM %s WHERE %s = :id LIMIT 1',
|
|
||||||
implode(',', $fields),
|
|
||||||
$this->table,
|
|
||||||
$idField
|
|
||||||
));
|
|
||||||
|
|
||||||
$statement->bindValue(':id', $id, SQLITE3_TEXT);
|
|
||||||
|
|
||||||
$item = $statement->execute()->fetchArray(SQLITE3_ASSOC);
|
|
||||||
|
|
||||||
if ($item === false) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->isExpired($item)) {
|
|
||||||
$this->doDelete($id);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $item;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets an array of the fields in our table.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getFields()
|
|
||||||
{
|
|
||||||
return array(static::ID_FIELD, static::DATA_FIELD, static::EXPIRATION_FIELD);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the item is expired.
|
|
||||||
*
|
|
||||||
* @param array $item
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function isExpired(array $item)
|
|
||||||
{
|
|
||||||
return isset($item[static::EXPIRATION_FIELD]) &&
|
|
||||||
$item[self::EXPIRATION_FIELD] !== null &&
|
|
||||||
$item[self::EXPIRATION_FIELD] < time();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
class Version
|
|
||||||
{
|
|
||||||
const VERSION = '1.6.1-DEV';
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Void cache driver. The cache could be of use in tests where you don`t need to cache anything.
|
|
||||||
*
|
|
||||||
* @link www.doctrine-project.org
|
|
||||||
* @since 1.5
|
|
||||||
* @author Kotlyar Maksim <kotlyar.maksim@gmail.com>
|
|
||||||
*/
|
|
||||||
class VoidCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* WinCache cache provider.
|
|
||||||
*
|
|
||||||
* @link www.doctrine-project.org
|
|
||||||
* @since 2.2
|
|
||||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
|
||||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
||||||
* @author Jonathan Wage <jonwage@gmail.com>
|
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
|
||||||
* @author David Abdemoulaie <dave@hobodave.com>
|
|
||||||
*/
|
|
||||||
class WinCacheCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
return wincache_ucache_get($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
return wincache_ucache_exists($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
return wincache_ucache_set($id, $data, $lifeTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
return wincache_ucache_delete($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
return wincache_ucache_clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetchMultiple(array $keys)
|
|
||||||
{
|
|
||||||
return wincache_ucache_get($keys);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
|
|
||||||
{
|
|
||||||
$result = wincache_ucache_set($keysAndValues, null, $lifetime);
|
|
||||||
|
|
||||||
return empty($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
$info = wincache_ucache_info();
|
|
||||||
$meminfo = wincache_ucache_meminfo();
|
|
||||||
|
|
||||||
return array(
|
|
||||||
Cache::STATS_HITS => $info['total_hit_count'],
|
|
||||||
Cache::STATS_MISSES => $info['total_miss_count'],
|
|
||||||
Cache::STATS_UPTIME => $info['total_cache_uptime'],
|
|
||||||
Cache::STATS_MEMORY_USAGE => $meminfo['memory_total'],
|
|
||||||
Cache::STATS_MEMORY_AVAILABLE => $meminfo['memory_free'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Xcache cache driver.
|
|
||||||
*
|
|
||||||
* @link www.doctrine-project.org
|
|
||||||
* @since 2.0
|
|
||||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
|
||||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
||||||
* @author Jonathan Wage <jonwage@gmail.com>
|
|
||||||
* @author Roman Borschel <roman@code-factory.org>
|
|
||||||
* @author David Abdemoulaie <dave@hobodave.com>
|
|
||||||
*/
|
|
||||||
class XcacheCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
return $this->doContains($id) ? unserialize(xcache_get($id)) : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
return xcache_isset($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
return xcache_set($id, serialize($data), (int) $lifeTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
return xcache_unset($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
$this->checkAuthorization();
|
|
||||||
|
|
||||||
xcache_clear_cache(XC_TYPE_VAR);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks that xcache.admin.enable_auth is Off.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @throws \BadMethodCallException When xcache.admin.enable_auth is On.
|
|
||||||
*/
|
|
||||||
protected function checkAuthorization()
|
|
||||||
{
|
|
||||||
if (ini_get('xcache.admin.enable_auth')) {
|
|
||||||
throw new \BadMethodCallException(
|
|
||||||
'To use all features of \Doctrine\Common\Cache\XcacheCache, '
|
|
||||||
. 'you must set "xcache.admin.enable_auth" to "Off" in your php.ini.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
$this->checkAuthorization();
|
|
||||||
|
|
||||||
$info = xcache_info(XC_TYPE_VAR, 0);
|
|
||||||
return array(
|
|
||||||
Cache::STATS_HITS => $info['hits'],
|
|
||||||
Cache::STATS_MISSES => $info['misses'],
|
|
||||||
Cache::STATS_UPTIME => null,
|
|
||||||
Cache::STATS_MEMORY_USAGE => $info['size'],
|
|
||||||
Cache::STATS_MEMORY_AVAILABLE => $info['avail'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\Common\Cache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Zend Data Cache cache driver.
|
|
||||||
*
|
|
||||||
* @link www.doctrine-project.org
|
|
||||||
* @since 2.0
|
|
||||||
* @author Ralph Schindler <ralph.schindler@zend.com>
|
|
||||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
||||||
*/
|
|
||||||
class ZendDataCache extends CacheProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFetch($id)
|
|
||||||
{
|
|
||||||
return zend_shm_cache_fetch($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doContains($id)
|
|
||||||
{
|
|
||||||
return (false !== zend_shm_cache_fetch($id));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doSave($id, $data, $lifeTime = 0)
|
|
||||||
{
|
|
||||||
return zend_shm_cache_store($id, $data, $lifeTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doDelete($id)
|
|
||||||
{
|
|
||||||
return zend_shm_cache_delete($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doFlush()
|
|
||||||
{
|
|
||||||
$namespace = $this->getNamespace();
|
|
||||||
if (empty($namespace)) {
|
|
||||||
return zend_shm_cache_clear();
|
|
||||||
}
|
|
||||||
return zend_shm_cache_clear($namespace);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function doGetStats()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,22 @@
|
|||||||
|
20200828-1420.26
|
||||||
|
nginx rewrite rule exclude .well-known folder, as auto SSL. add web.config to rewrite in IIS. now in windwos can do with \ in path. in aliyun FC & huawei FG API, use my code. CN 21Vianet client_id&secret expire. update description now only show new.
|
||||||
|
nginx的伪静态中排除.well-known目录,方便自动SSL。添加IIS的伪静态。与linux不同,处理windows下目录用\分隔。FC、FG中使用自己代码对接平台。<font color=red>世纪互联旧API即将过期失效,升级后世纪互联的盘需要删除重新添加。</font>更新说明只显示部分。
|
||||||
|
|
||||||
|
20200817-1740.25
|
||||||
|
when multy disks, now will default show disks as folders in root, if set autoJumpFirstDisk 1, it will auto jump to first disk.
|
||||||
|
多盘时,在网站根目录,默认会将各盘当成文件夹显示,可以去设置中设置autoJumpFirstDisk为1,这样可以跟以前一样自动跳到第一个盘。
|
||||||
|
20200816-1145.24
|
||||||
|
add platform: Baidu CFC. add setting: mobile background.
|
||||||
|
新增百度CFC平台。可以分别设置PC与手机的背景。
|
||||||
|
20200808-1130.23
|
||||||
|
FG: select save in env or file.
|
||||||
|
在FG中安装时,选择配置保存在环境变量还是文件中。
|
||||||
|
20200806-1130.23
|
||||||
|
SCF: select save in env or file.
|
||||||
|
在SCF中安装时,选择配置保存在环境变量还是文件中。
|
||||||
20200804-1453.22
|
20200804-1453.22
|
||||||
fix: once error will stop the after files in uploading multy files. SCF can get region now, change install. SCF config save in code file now not in env, <font color=red>if use SCF, you must reinstall after update</font>.
|
fix: once error will stop the after files in uploading multy files. SCF can get region now, change install. SCF config save in code file now not in env, <font color=red>if use SCF, you must reinstall after update</font>.
|
||||||
修复,当上传多个文件时,一个文件出错将导致后续文件不再上传。SCF可以获取到region了,安装过程修改。在SCF中,现在将配置保存到代码文件中,不受环境变量4K大小限制,<font color=red>升级后,用SCF的要重装</font>。
|
修复,当上传多个文件时,一个文件出错将导致后续文件不再上传。SCF可以获取到region了,安装过程修改。在SCF中,现在将配置保存到代码文件中,不受环境变量4K大小限制,<font color=red>升级后,用SCF的要重装</font>。
|
||||||
|
|
||||||
20200723-1430.21
|
20200723-1430.21
|
||||||
fix content-type in "?json". can not custom microsoft API id & secret by a link now, so show the return uri.
|
fix content-type in "?json". can not custom microsoft API id & secret by a link now, so show the return uri.
|
||||||
当使用"?json"时,现在content-type是json了。现在微软不能一键创建API应用了,提供回调URI。
|
当使用"?json"时,现在content-type是json了。现在微软不能一键创建API应用了,提供回调URI。
|
||||||
|
|||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<system.webServer>
|
||||||
|
<rewrite>
|
||||||
|
<rules>
|
||||||
|
<rule name="OneManagerIISRewrite" patternSyntax="Wildcard" stopProcessing="true">
|
||||||
|
<match url="*" />
|
||||||
|
<action type="Rewrite" url="index.php" appendQueryString="false" logRewrittenUrl="false" />
|
||||||
|
</rule>
|
||||||
|
</rules>
|
||||||
|
</rewrite>
|
||||||
|
</system.webServer>
|
||||||
|
</configuration>
|
||||||
Reference in New Issue
Block a user