commit
5f79777f40
32
.htaccess
32
.htaccess
|
@ -1,15 +1,31 @@
|
|||
# apache
|
||||
# LoadModule rewrite_module modules/mod_rewrite.so
|
||||
# AllowOverride All
|
||||
# # Apache
|
||||
# # LoadModule rewrite_module modules/mod_rewrite.so
|
||||
# # AllowOverride All
|
||||
RewriteEngine On
|
||||
# RewriteCond $1 !^(.well-known)
|
||||
RewriteRule ^(.*) index.php?/$1 [L]
|
||||
|
||||
#-----------------------------------
|
||||
# nginx
|
||||
# rewrite ^(.*) /index.php?/$1 last;
|
||||
###-----------------------------------
|
||||
### nginx
|
||||
# rewrite ^/(?!.well-known)(.*)$ /index.php?/$1 last;
|
||||
#
|
||||
# caddy
|
||||
### nginx Subdirectory 在子目录中使用
|
||||
# location /OneManager2/ {
|
||||
# rewrite ^/(.*)$ /OneManager2/index.php?/$1 last;
|
||||
# }
|
||||
#
|
||||
### caddy
|
||||
# rewrite {
|
||||
# to index.php?/$1
|
||||
# }
|
||||
#-----------------------------------
|
||||
#
|
||||
### caddy2 Caddyfile
|
||||
# @try_files {
|
||||
# not path /.well-known/*
|
||||
# file {
|
||||
# try_files index.php
|
||||
# }
|
||||
# }
|
||||
# rewrite @try_files {http.matchers.file.relative}
|
||||
#
|
||||
###-----------------------------------
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
language = "php74"
|
||||
run = "php -S 0.0.0.0:8000 index.php"
|
||||
entrypoint = "index.php"
|
|
@ -0,0 +1,90 @@
|
|||
|
||||
// odd, 单日
|
||||
const SingleDay = 'https://aaa1.herokuapp.com'
|
||||
// even, 双日
|
||||
const DoubleDay = 'https://bbb2.herokuapp.com'
|
||||
|
||||
//const SingleDay = 'https://153xxxxx0.cn-hongkong.fc.aliyuncs.com/2016-08-15/proxy/onedrive/xxx/'
|
||||
//const DoubleDay = 'https://153xxxxx0.cn-hongkong.fc.aliyuncs.com/2016-08-15/proxy/onedrive/xxx/'
|
||||
|
||||
// CF proxy all, 一切给CF代理,true/false
|
||||
const CFproxy = true
|
||||
|
||||
// Used in cloudflare workers, odd or even days point to 2 heroku account.
|
||||
|
||||
// 由于heroku不绑卡不能自定义域名,就算绑卡后https也不方便
|
||||
// 另外免费套餐每月550小时,有些人不够用
|
||||
// 于是在CF Workers使用此代码,分单双日拉取不同heroku帐号下的相同网页
|
||||
// 只改上面,下面不用动
|
||||
|
||||
addEventListener('fetch', event => {
|
||||
let url=new URL(event.request.url);
|
||||
if (url.protocol == 'http:') {
|
||||
url.protocol = 'https:'
|
||||
event.respondWith( Response.redirect(url.href) )
|
||||
} else {
|
||||
let response = null;
|
||||
let nd = new Date();
|
||||
if (nd.getDate()%2) {
|
||||
host = SingleDay
|
||||
} else {
|
||||
host = DoubleDay
|
||||
}
|
||||
if (host.substr(0, 7)!='http://'&&host.substr(0, 8)!='https://') host = 'http://' + host;
|
||||
|
||||
response = fetchAndApply(host, event.request);
|
||||
|
||||
event.respondWith( response );
|
||||
}
|
||||
})
|
||||
|
||||
async function fetchAndApply(host, request) {
|
||||
let f_url = new URL(request.url);
|
||||
let a_url = new URL(host);
|
||||
let replace_path = a_url.pathname;
|
||||
if (replace_path.substr(replace_path.length-1)!='/') replace_path += '/';
|
||||
let replaced_path = '/';
|
||||
let query = f_url.search;
|
||||
let path = f_url.pathname;
|
||||
if (host.substr(host.length-1)=='/') path = path.substr(1);
|
||||
f_url.href = host + path + query;
|
||||
|
||||
let response = null;
|
||||
if (!CFproxy) {
|
||||
response = await fetch(f_url, request);
|
||||
} else {
|
||||
let method = request.method;
|
||||
let body = request.body;
|
||||
let request_headers = request.headers;
|
||||
let new_request_headers = new Headers(request_headers);
|
||||
new_request_headers.set('Host', f_url.host);
|
||||
new_request_headers.set('Referer', request.url);
|
||||
|
||||
response = await fetch(f_url.href, {
|
||||
method: method,
|
||||
body: body,
|
||||
headers: new_request_headers
|
||||
});
|
||||
}
|
||||
|
||||
let out_headers = new Headers(response.headers);
|
||||
if (out_headers.get('Content-Disposition')=='attachment') out_headers.delete('Content-Disposition');
|
||||
let out_body = null;
|
||||
let contentType = out_headers.get('Content-Type');
|
||||
if (contentType.includes("application/text")) {
|
||||
out_body = await response.text();
|
||||
while (out_body.includes(replace_path)) out_body = out_body.replace(replace_path, replaced_path);
|
||||
} else if (contentType.includes("text/html")) {
|
||||
out_body = await response.text();
|
||||
while (replace_path!='/'&&out_body.includes(replace_path)) out_body = out_body.replace(replace_path, replaced_path);
|
||||
} else {
|
||||
out_body = await response.body;
|
||||
}
|
||||
|
||||
let out_response = new Response(out_body, {
|
||||
status: response.status,
|
||||
headers: out_headers
|
||||
})
|
||||
|
||||
return out_response;
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
|
||||
// Hosts Array
|
||||
// 服务器数组
|
||||
const H = [
|
||||
'https://herooneindex.herokuapp.com/',
|
||||
'https://onemanager.glitch.me/',
|
||||
'https://onemanager-php.vercel.app/'
|
||||
]
|
||||
|
||||
// View Type
|
||||
// 1 , only first host,
|
||||
// 只第一条Host记录有用
|
||||
// 2 , view top 2 host as odd/even days,
|
||||
// 只有前两条记录有效,分别单双日运行
|
||||
// 3 , view random host
|
||||
// 所有记录随机访问
|
||||
const T = 1
|
||||
|
||||
// CF proxy all, true/false
|
||||
// 一切给CF代理,true或false
|
||||
const CFproxy = true
|
||||
|
||||
// Used in cloudflare workers
|
||||
// // // // // //
|
||||
|
||||
addEventListener('fetch', event => {
|
||||
let url=new URL(event.request.url);
|
||||
if (url.protocol == 'http:') {
|
||||
// force HTTPS
|
||||
url.protocol = 'https:'
|
||||
event.respondWith( Response.redirect(url.href) )
|
||||
} else {
|
||||
let host = null;
|
||||
if (T===1) {
|
||||
host = H[0];
|
||||
}
|
||||
if (T===2) {
|
||||
host = H[new Date().getDate()%2];
|
||||
}
|
||||
if (T===3) {
|
||||
let n = H.length;
|
||||
host = H[Math.round(Math.random()*n*10)%n];
|
||||
}
|
||||
//console.log(host)
|
||||
if (host.substr(0, 7)!='http://'&&host.substr(0, 8)!='https://') host = 'http://' + host;
|
||||
|
||||
let response = fetchAndApply(host, event.request);
|
||||
|
||||
event.respondWith( response );
|
||||
}
|
||||
})
|
||||
|
||||
async function fetchAndApply(host, request) {
|
||||
let f_url = new URL(request.url);
|
||||
let a_url = new URL(host);
|
||||
let replace_path = a_url.pathname;
|
||||
if (replace_path.substr(replace_path.length-1)!='/') replace_path += '/';
|
||||
let replaced_path = '/';
|
||||
let query = f_url.search;
|
||||
let path = f_url.pathname;
|
||||
if (host.substr(host.length-1)=='/') path = path.substr(1);
|
||||
f_url.href = host + path + query;
|
||||
|
||||
let response = null;
|
||||
if (!CFproxy) {
|
||||
response = await fetch(f_url, request);
|
||||
} else {
|
||||
let method = request.method;
|
||||
let body = request.body;
|
||||
let request_headers = request.headers;
|
||||
let new_request_headers = new Headers(request_headers);
|
||||
new_request_headers.set('Host', f_url.host);
|
||||
new_request_headers.set('Referer', request.url);
|
||||
response = await fetch(f_url.href, {
|
||||
/*cf: {
|
||||
cacheEverything: true,
|
||||
cacheTtl: 1000,
|
||||
mirage: true,
|
||||
polish: "on",
|
||||
minify: {
|
||||
javascript: true,
|
||||
css: true,
|
||||
html: true,
|
||||
}
|
||||
},*/
|
||||
method: method,
|
||||
body: body,
|
||||
headers: new_request_headers
|
||||
});
|
||||
}
|
||||
|
||||
let out_headers = new Headers(response.headers);
|
||||
if (out_headers.get('Content-Disposition')=='attachment') out_headers.delete('Content-Disposition');
|
||||
let out_body = null;
|
||||
let contentType = out_headers.get('Content-Type');
|
||||
if (contentType.includes("application/text")) {
|
||||
out_body = await response.text();
|
||||
while (replace_path!='/'&&out_body.includes(replace_path)) out_body = out_body.replace(replace_path, replaced_path);
|
||||
} else if (contentType.includes("text/html")) {
|
||||
//f_url.href +
|
||||
out_body = await response.text();
|
||||
while (replace_path!='/'&&out_body.includes(replace_path)) out_body = out_body.replace(replace_path, replaced_path);
|
||||
} else {
|
||||
out_body = await response.body;
|
||||
}
|
||||
|
||||
let out_response = new Response(out_body, {
|
||||
status: response.status,
|
||||
headers: out_headers
|
||||
})
|
||||
|
||||
return out_response;
|
||||
}
|
3861
common.php
3861
common.php
File diff suppressed because it is too large
Load Diff
624
conststr.php
624
conststr.php
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,980 @@
|
|||
<?php
|
||||
|
||||
class Aliyundrive {
|
||||
protected $access_token;
|
||||
protected $disktag;
|
||||
|
||||
function __construct($tag) {
|
||||
$this->disktag = $tag;
|
||||
//$this->auth_url = 'https://websv.aliyundrive.com/token/refresh';
|
||||
$this->auth_url = 'https://auth.aliyundrive.com/v2/account/token';
|
||||
$this->api_url = 'https://api.aliyundrive.com/v2';
|
||||
$this->driveId = getConfig('driveId', $tag);
|
||||
$res = $this->get_access_token(getConfig('refresh_token', $tag));
|
||||
}
|
||||
|
||||
public function isfine()
|
||||
{
|
||||
if (!$this->access_token) return false;
|
||||
else return true;
|
||||
}
|
||||
public function show_base_class()
|
||||
{
|
||||
return get_class();
|
||||
//$tmp[0] = get_class();
|
||||
//$tmp[1] = get_class($this);
|
||||
//return $tmp;
|
||||
}
|
||||
|
||||
public function ext_show_innerenv()
|
||||
{
|
||||
return ['driveId'];
|
||||
}
|
||||
|
||||
public function list_files($path = '/')
|
||||
{
|
||||
|
||||
$files = $this->list_path($path);
|
||||
|
||||
return $this->files_format($files);
|
||||
}
|
||||
|
||||
protected function files_format($files)
|
||||
{
|
||||
//return $files;
|
||||
if ($files['type']=='file') {
|
||||
$tmp['type'] = 'file';
|
||||
$tmp['id'] = $files['file_id'];
|
||||
if (isset($files['name'])) $tmp['name'] = $files['name'];
|
||||
elseif (isset($files['file_name'])) $tmp['name'] = $files['file_name'];
|
||||
$tmp['time'] = $files['updated_at'];
|
||||
$tmp['size'] = $files['size'];
|
||||
$tmp['mime'] = $files['file']['mimeType'];
|
||||
$tmp['url'] = $files['download_url'];
|
||||
$tmp['content'] = $files['content'];
|
||||
if (isset($files['exist'])) $tmp['exist'] = $files['exist'];
|
||||
if (isset($files['rapid_upload'])) $tmp['rapid_upload'] = $files['rapid_upload'];
|
||||
} elseif ($files['type']=='folder'||isset($files['items'])) {
|
||||
$tmp['type'] = 'folder';
|
||||
$tmp['id'] = $files['file_id'];
|
||||
if (isset($files['name'])) $tmp['name'] = $files['name'];
|
||||
elseif (isset($files['file_name'])) $tmp['name'] = $files['file_name'];
|
||||
$tmp['time'] = $files['updated_at'];
|
||||
$tmp['size'] = $files['size'];
|
||||
//$tmp['page'] = $files['folder']['page'];
|
||||
foreach ($files['items'] as $file) {
|
||||
$filename = strtolower($file['name']);
|
||||
if ($file['type']=='file') {
|
||||
$tmp['list'][$filename]['type'] = 'file';
|
||||
$tmp['list'][$filename]['url'] = $file['download_url'];
|
||||
$tmp['list'][$filename]['mime'] = $file['file']['content_type'];
|
||||
} elseif ($file['type']=='folder') {
|
||||
$tmp['list'][$filename]['type'] = 'folder';
|
||||
}
|
||||
//$tmp['id'] = $file['parent_file_id'];
|
||||
$tmp['list'][$filename]['id'] = $file['file_id'];
|
||||
$tmp['list'][$filename]['name'] = $file['name'];
|
||||
$tmp['list'][$filename]['time'] = $file['updated_at'];
|
||||
$tmp['list'][$filename]['size'] = $file['size'];
|
||||
//$tmp['childcount']++;
|
||||
}
|
||||
} elseif (isset($files['code'])||isset($files['error'])) {
|
||||
return $files;
|
||||
}
|
||||
//error_log1(json_encode($tmp));
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
protected function list_path($path = '/')
|
||||
{
|
||||
global $exts;
|
||||
while (substr($path, -1)=='/') $path = substr($path, 0, -1);
|
||||
if ($path == '') $path = '/';
|
||||
if (!($files = getcache('path_' . $path, $this->disktag))) {
|
||||
if ($path == '/' || $path == '') {
|
||||
$files = $this->fileList('root');
|
||||
//error_log1('root_id' . $files['file_id']);
|
||||
$files['file_id'] = 'root';
|
||||
$files['type'] = 'folder';
|
||||
//error_log1(json_encode($files, JSON_PRETTY_PRINT));
|
||||
} else {
|
||||
$tmp = splitlast($path, '/');
|
||||
$parent_path = $tmp[0];
|
||||
$filename = urldecode($tmp[1]);
|
||||
$parent_folder = $this->list_path($parent_path);
|
||||
foreach ($parent_folder['items'] as $item) {
|
||||
if ($item['name']==$filename) {
|
||||
if ($item['type']=='folder') {
|
||||
$files = $this->fileList($item['file_id']);
|
||||
$files['type'] = 'folder';
|
||||
$files['file_id'] = $item['file_id'];
|
||||
$files['name'] = $item['name'];
|
||||
$files['time'] = $item['updated_at'];
|
||||
$files['size'] = $item['size'];
|
||||
} else $files = $item;
|
||||
}
|
||||
}
|
||||
//echo $files['name'];
|
||||
}
|
||||
if ($files['type']=='file') {
|
||||
if (in_array(strtolower(splitlast($files['name'],'.')[1]), $exts['txt'])) {
|
||||
if ($files['size']<1024*1024) {
|
||||
if (!(isset($files['content'])&&$files['content']['stat']==200)) {
|
||||
$header['Referer'] = 'https://www.aliyundrive.com/';
|
||||
$header['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36';
|
||||
$content1 = curl('GET', $files['download_url'], '', $header);
|
||||
$tmp = null;
|
||||
$tmp = json_decode(json_encode($content1), true);
|
||||
if ($tmp['body']===null) {
|
||||
$tmp['body'] = iconv("GBK", 'UTF-8//TRANSLIT', $content1['body']);
|
||||
$tmp = json_decode(json_encode($tmp), true);
|
||||
if ($tmp['body']!==null) $content1['body'] = $tmp['body'];
|
||||
}
|
||||
//error_log1('body : ' . $content1['body'] . PHP_EOL);
|
||||
$files['content'] = $content1;
|
||||
savecache('path_' . $path, $files, $this->disktag);
|
||||
}
|
||||
} else {
|
||||
$files['content']['stat'] = 202;
|
||||
$files['content']['body'] = 'File too large.';
|
||||
}
|
||||
//error_log1($files['name'] . ' : ' . json_encode($files['content']) . PHP_EOL);
|
||||
}
|
||||
}
|
||||
if (!$files) {
|
||||
$files['error']['code'] = 'Not Found';
|
||||
$files['error']['message'] = $path . ' Not Found';
|
||||
$files['error']['stat'] = 404;
|
||||
} elseif (isset($files['stat'])) {
|
||||
$files['error']['stat'] = $files['stat'];
|
||||
$files['error']['code'] = 'Error';
|
||||
$files['error']['message'] = $files['body'];
|
||||
unset($files['file_id']);
|
||||
unset($files['type']);
|
||||
} elseif (isset($files['code'])) {
|
||||
$files['error']['stat'] = 500;
|
||||
$files['error']['code'] = $files['code'];
|
||||
$files['error']['message'] = $files['message'];
|
||||
unset($files['file_id']);
|
||||
unset($files['type']);
|
||||
} else {
|
||||
savecache('path_' . $path, $files, $this->disktag, 600);
|
||||
}
|
||||
}
|
||||
//error_log1('path:' . $path . ', files:' . substr(json_encode($files), 0, 150));
|
||||
//error_log1('path:' . $path . ', files:' . json_encode($files));
|
||||
return $files;
|
||||
}
|
||||
|
||||
protected function fileGet($file_id)
|
||||
{
|
||||
$url = $this->api_url . '/file/get';
|
||||
|
||||
$header["content-type"] = "application/json; charset=utf-8";
|
||||
$header['authorization'] = 'Bearer ' . $this->access_token;
|
||||
|
||||
$data['drive_id'] = $this->driveId;
|
||||
$data['file_id'] = $file_id;
|
||||
|
||||
$res = curl('POST', $url, json_encode($data), $header);
|
||||
if ($res['stat']==200) return json_decode($res['body'], true);
|
||||
else return $res;
|
||||
}
|
||||
protected function fileList($parent_file_id)
|
||||
{
|
||||
$url = $this->api_url . '/file/list';
|
||||
|
||||
$header["content-type"] = "application/json; charset=utf-8";
|
||||
$header['authorization'] = 'Bearer ' . $this->access_token;
|
||||
|
||||
$data['limit'] = 200;
|
||||
$data['marker'] = null;
|
||||
$data['drive_id'] = $this->driveId;
|
||||
$data['parent_file_id'] = $parent_file_id;
|
||||
$data['image_thumbnail_process'] = 'image/resize,w_160/format,jpeg';
|
||||
$data['image_url_process'] = 'image/resize,w_1920/format,jpeg';
|
||||
$data['video_thumbnail_process'] = 'video/snapshot,t_0,f_jpg,w_300';
|
||||
$data['fields'] = '*';
|
||||
$data['order_by'] = 'name'; //updated_at
|
||||
$data['order_direction'] = 'ASC'; //DESC
|
||||
|
||||
$res = curl('POST', $url, json_encode($data), $header);
|
||||
//error_log1($res['stat'] . $res['body']);
|
||||
if ($res['stat']==200) {
|
||||
$body = json_decode($res['body'], true);
|
||||
$body1 = $body;
|
||||
while ($body1['next_marker']!='') {
|
||||
$data['marker'] = $body1['next_marker'];
|
||||
$res1 = null;
|
||||
$res1 = curl('POST', $url, json_encode($data), $header);
|
||||
$body1 = json_decode($res1['body'], true);
|
||||
$body['items'] = array_merge($body['items'], $body1['items']);
|
||||
}
|
||||
return $body;
|
||||
//return json_decode($res['body'], true);
|
||||
}
|
||||
else return $res;
|
||||
}
|
||||
|
||||
public function Rename($file, $newname) {
|
||||
$url = $this->api_url . '/file/update';
|
||||
|
||||
$header["content-type"] = "application/json; charset=utf-8";
|
||||
$header['authorization'] = 'Bearer ' . $this->access_token;
|
||||
|
||||
$data['check_name_mode'] = 'refuse';
|
||||
$data['drive_id'] = $this->driveId;
|
||||
$data['file_id'] = $file['id'];
|
||||
$data['name'] = $newname;
|
||||
//$data['parent_file_id'] = 'root';
|
||||
|
||||
$result = curl('POST', $url, json_encode($data), $header);
|
||||
//savecache('path_' . $file['path'], json_decode('{}',true), $this->disktag, 1);
|
||||
//error_log1('decode:' . json_encode($result));
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
//return output($result['body'], $result['stat']);
|
||||
}
|
||||
public function Delete($file) {
|
||||
$url = $this->api_url . '/batch';
|
||||
|
||||
$header["content-type"] = "application/json; charset=utf-8";
|
||||
$header['authorization'] = 'Bearer ' . $this->access_token;
|
||||
|
||||
$data['resource'] = 'file';
|
||||
$data['requests'][0]['url'] = '/file/delete';
|
||||
$data['requests'][0]['method'] = 'DELETE';
|
||||
$data['requests'][0]['id'] = $file['id'];
|
||||
$data['requests'][0]['headers']['Content-Type'] = 'application/json';
|
||||
$data['requests'][0]['body']['drive_id'] = $this->driveId;
|
||||
$data['requests'][0]['body']['file_id'] = $file['id'];
|
||||
|
||||
$result = curl('POST', $url, json_encode($data), $header);
|
||||
//savecache('path_' . $file['path'], json_decode('{}',true), $this->disktag, 1);
|
||||
//error_log1('result:' . json_encode($result));
|
||||
//return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
$res = json_decode($result['body'], true)['responses'][0];
|
||||
if (isset($res['status'])) return output($res['id'], $res['status']);
|
||||
else return output($result['body'], $result['stat']);
|
||||
}
|
||||
public function Encrypt($folder, $passfilename, $pass) {
|
||||
$existfile = $this->list_path($folder['path'] . '/' . $passfilename);
|
||||
if (isset($existfile['type'])) { // 删掉原文件
|
||||
$this->Delete(['id'=>$existfile['file_id']]);
|
||||
}
|
||||
if ($pass==='') {
|
||||
// 如果为空,上面已经删除了
|
||||
return output('Success', 200);
|
||||
}
|
||||
if (!$folder['id']) {
|
||||
$res = $this->list_path($folder['path']);
|
||||
//error_log1('res:' . json_encode($res));
|
||||
$folder['id'] = $res['file_id'];
|
||||
}
|
||||
$tmp = '/tmp/' . $passfilename;
|
||||
file_put_contents($tmp, $pass);
|
||||
|
||||
$result = $this->tmpfileCreate($folder['id'], $tmp, $passfilename);
|
||||
|
||||
if ($result['stat']==201) {
|
||||
//error_log1('1,url:' . $url .' res:' . json_encode($result));
|
||||
$res = json_decode($result['body'], true);
|
||||
$url = $res['part_info_list'][0]['upload_url'];
|
||||
if (!$url) { // 无url,应该算秒传
|
||||
return output('no up url', 200);
|
||||
}
|
||||
$file_id = $res['file_id'];
|
||||
$upload_id = $res['upload_id'];
|
||||
$result = curl('PUT', $url, $pass, [], 1);
|
||||
if ($result['stat']==200) { // 块1传好
|
||||
$result = $this->fileComplete($file_id, $upload_id, [ $result['returnhead']['ETag'] ]);
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
}
|
||||
//error_log1('2,url:' . $url .' res:' . json_encode($result));
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
public function Move($file, $folder) {
|
||||
if (!$folder['id']) {
|
||||
$res = $this->list_path($folder['path']);
|
||||
//error_log1('res:' . json_encode($res));
|
||||
$folder['id'] = $res['file_id'];
|
||||
}
|
||||
|
||||
$url = $this->api_url . '/batch';
|
||||
|
||||
$header["content-type"] = "application/json; charset=utf-8";
|
||||
$header['authorization'] = 'Bearer ' . $this->access_token;
|
||||
|
||||
$data['resource'] = 'file';
|
||||
$data['requests'][0]['url'] = '/file/move';
|
||||
$data['requests'][0]['method'] = 'POST';
|
||||
$data['requests'][0]['id'] = $file['id'];
|
||||
$data['requests'][0]['headers']['Content-Type'] = 'application/json';
|
||||
$data['requests'][0]['body']['drive_id'] = $this->driveId;
|
||||
$data['requests'][0]['body']['file_id'] = $file['id'];
|
||||
$data['requests'][0]['body']['auto_rename'] = true;
|
||||
$data['requests'][0]['body']['to_parent_file_id'] = $folder['id'];
|
||||
|
||||
$result = curl('POST', $url, json_encode($data), $header);
|
||||
//savecache('path_' . $file['path'], json_decode('{}',true), $this->disktag, 1);
|
||||
//error_log1('result:' . json_encode($result));
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
public function Copy($file) {
|
||||
if (!$file['id']) {
|
||||
$oldfile = $this->list_path($file['path'] . '/' . $file['name']);
|
||||
//error_log1('res:' . json_encode($res));
|
||||
//$file['id'] = $res['file_id'];
|
||||
} else {
|
||||
$oldfile = $this->fileGet($file['id']);
|
||||
}
|
||||
if ($oldfile['type']=='folder') return output('Can not copy folder', 415);
|
||||
if (!function_exists('bcadd')) {
|
||||
// no php-bcmath
|
||||
if ($bcmathurl = getConfig('bcmathUrl', $this->disktag)) {
|
||||
if (strpos($bcmathurl, '?')) {
|
||||
$bcmathurl .= '÷nd=0x' . substr(md5($this->access_token), 0, 16) . '&divisor=' . $oldfile['size'];
|
||||
} else {
|
||||
$bcmathurl .= '?dividend=0x' . substr(md5($this->access_token), 0, 16) . '&divisor=' . $oldfile['size'];
|
||||
}
|
||||
$o = curl('GET', $bcmathurl)['body'];
|
||||
} else {
|
||||
return output('No bcmath module, can not copy', 415);
|
||||
}
|
||||
} else {
|
||||
$r = bchexdec( substr(md5($this->access_token), 0, 16) );
|
||||
$o = bcmod($r, $oldfile['size']);
|
||||
}
|
||||
$res = curl('GET', $oldfile['download_url'], '', [
|
||||
'Referer' => ''
|
||||
, 'Range' => 'bytes=' . $o . '-' . ($o+7)
|
||||
]);
|
||||
if ($res['stat']==206) {
|
||||
$proof_code = base64_encode($res['body']);
|
||||
$url = 'https://api.aliyundrive.com/adrive/v2/file/createWithFolders';
|
||||
$header["content-type"] = "application/json; charset=utf-8";
|
||||
$header['authorization'] = 'Bearer ' . $this->access_token;
|
||||
$data['check_name_mode'] = 'auto_rename'; // ignore, auto_rename, refuse.
|
||||
$data['content_hash'] = $oldfile['content_hash'];
|
||||
$data['content_hash_name'] = 'sha1';
|
||||
$data['drive_id'] = $this->driveId;
|
||||
$data['name'] = $oldfile['name'];
|
||||
$data['parent_file_id'] = $oldfile['parent_file_id'];
|
||||
$data['part_info_list'][0]['part_number'] = 1;
|
||||
$data['proof_code'] = $proof_code;
|
||||
$data['proof_version'] = 'v1';
|
||||
$data['size'] = $oldfile['size'];
|
||||
$data['type'] = 'file';
|
||||
$result = curl('POST', $url, json_encode($data), $header);
|
||||
/*if ($result['stat']==201) {
|
||||
$res = json_decode($result['body'], true);
|
||||
if ($res['rapid_upload']) return output('rapid upload', 200);
|
||||
$url = $res['part_info_list'][0]['upload_url'];
|
||||
if (!$url) { // 无url,应该算秒传
|
||||
return output('no up url', 200);
|
||||
} else {
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
}*/
|
||||
//error_log1('2,url:' . $url .' res:' . json_encode($result));
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
} else {
|
||||
return output("Get proof error\n" . json_encode($res), 415);
|
||||
}
|
||||
|
||||
}
|
||||
public function Edit($file, $content) {
|
||||
$tmp = splitlast($file['path'], '/');
|
||||
$folderpath = $tmp[0];
|
||||
$filename = $tmp[1];
|
||||
$existfile = $this->list_path($file['path']);
|
||||
if (isset($existfile['type'])) { // 删掉原文件
|
||||
$this->Delete(['id'=>$existfile['file_id']]);
|
||||
}
|
||||
$tmp1 = '/tmp/' . $filename;
|
||||
file_put_contents($tmp1, $content);
|
||||
|
||||
$result = $this->tmpfileCreate($this->list_path($folderpath)['file_id'], $tmp1, $filename);
|
||||
|
||||
if ($result['stat']==201) {
|
||||
//error_log1('1,url:' . $url .' res:' . json_encode($result));
|
||||
$res = json_decode($result['body'], true);
|
||||
$url = $res['part_info_list'][0]['upload_url'];
|
||||
if (!$url) { // 无url,应该算秒传
|
||||
return output('no up url', 0);
|
||||
}
|
||||
$file_id = $res['file_id'];
|
||||
$upload_id = $res['upload_id'];
|
||||
$result = curl('PUT', $url, $content, [], 1);
|
||||
if ($result['stat']==200) { // 块1传好
|
||||
$result = $this->fileComplete($file_id, $upload_id, [ $result['returnhead']['ETag'] ]);
|
||||
if ($result['stat']!=200) return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
else return output('success', 0);
|
||||
}
|
||||
}
|
||||
//error_log1('2,url:' . $url .' res:' . json_encode($result));
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
public function Create($folder, $type, $name, $content = '') {
|
||||
if (!$folder['id']) {
|
||||
$res = $this->list_path($folder['path']);
|
||||
//error_log1('res:' . json_encode($res));
|
||||
$folder['id'] = $res['file_id'];
|
||||
}
|
||||
if ($type=='folder') {
|
||||
$result = $this->folderCreate($folder['id'], $name);
|
||||
//error_log1('res:' . json_encode($result));
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
if ($type=='file') {
|
||||
$tmp = '/tmp/' . $name;
|
||||
file_put_contents($tmp, $content);
|
||||
|
||||
$result = $this->tmpfileCreate($folder['id'], $tmp, $name);
|
||||
|
||||
if ($result['stat']==201) {
|
||||
//error_log1('1,url:' . $url .' res:' . json_encode($result));
|
||||
$res = json_decode($result['body'], true);
|
||||
if (isset($res['exist'])&&$res['exist']!=false) {
|
||||
// 已经有
|
||||
//error_log1('exist:' . json_encode($res));
|
||||
return output('{"type":"file","name":"' . $name . '", "exist":true}', 200);
|
||||
}
|
||||
if (isset($res['rapid_upload'])&&$res['rapid_upload']!=false) {
|
||||
// 秒传
|
||||
//error_log1('rapid up:' . json_encode($res));
|
||||
return output('{"type":"file","name":"' . $name . '", "rapid_upload":true}', 200);
|
||||
}
|
||||
$url = $res['part_info_list'][0]['upload_url'];
|
||||
$file_id = $res['file_id'];
|
||||
$upload_id = $res['upload_id'];
|
||||
$result = curl('PUT', $url, $content, [], 1);
|
||||
//error_log1('2,url:' . $url .' res:' . json_encode($result));
|
||||
if ($result['stat']==200) { // 块1传好
|
||||
$result = $this->fileComplete($file_id, $upload_id, [ $result['returnhead']['ETag'] ]);
|
||||
//error_log1('3,url:' . $url .' res:' . json_encode($result));
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
}
|
||||
//error_log1('4,url:' . $url .' res:' . json_encode($result));
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
return output('Type not folder or file.', 500);
|
||||
}
|
||||
|
||||
protected function folderCreate($parentId, $folderName) {
|
||||
if (strrpos($folderName, '/')) {
|
||||
$tmp = splitlast($folderName, '/');
|
||||
$parentId = json_decode($this->folderCreate($parentId, $tmp[0])['body'], true)['file_id'];
|
||||
$folderName = $tmp[1];
|
||||
}
|
||||
$url = $this->api_url . '/file/create';
|
||||
|
||||
$header["content-type"] = "application/json; charset=utf-8";
|
||||
$header['authorization'] = 'Bearer ' . $this->access_token;
|
||||
|
||||
$data['check_name_mode'] = 'refuse'; // ignore, auto_rename, refuse.
|
||||
$data['drive_id'] = $this->driveId;
|
||||
$data['name'] = $folderName;
|
||||
$data['parent_file_id'] = $parentId;
|
||||
$data['type'] = 'folder';
|
||||
|
||||
return curl('POST', $url, json_encode($data), $header);
|
||||
}
|
||||
protected function fileCreate($parentId, $fileName, $sha1, $size, $part_number) {
|
||||
$url = $this->api_url . '/file/create';
|
||||
|
||||
$header["content-type"] = "application/json; charset=utf-8";
|
||||
$header['authorization'] = 'Bearer ' . $this->access_token;
|
||||
|
||||
$data['check_name_mode'] = 'refuse'; // ignore, auto_rename, refuse.
|
||||
$data['content_hash'] = $sha1;
|
||||
$data['content_hash_name'] = 'sha1';
|
||||
$data['content_type'] = '';
|
||||
$data['drive_id'] = $this->driveId;
|
||||
$data['ignoreError'] = false;
|
||||
$data['name'] = $fileName;
|
||||
$data['parent_file_id'] = $parentId;
|
||||
for ($i=0;$i<$part_number;$i++) {
|
||||
$data['part_info_list'][$i]['part_number'] = $i+1;
|
||||
}
|
||||
$data['size'] = (int)$size;
|
||||
$data['type'] = 'file';
|
||||
|
||||
return curl('POST', $url, json_encode($data), $header);
|
||||
}
|
||||
protected function fileCreate1($parentId, $fileName, $sha1, $proof_code, $size, $part_number) {
|
||||
//$url = $this->api_url . '/file/create';
|
||||
$url = 'https://api.aliyundrive.com/adrive/v2/file/createWithFolders';
|
||||
|
||||
$header["content-type"] = "application/json; charset=utf-8";
|
||||
$header['authorization'] = 'Bearer ' . $this->access_token;
|
||||
|
||||
$data['check_name_mode'] = 'refuse'; // ignore, auto_rename, refuse.
|
||||
$data['content_hash'] = $sha1;
|
||||
$data['content_hash_name'] = 'sha1';
|
||||
//$data['content_type'] = '';
|
||||
$data['drive_id'] = $this->driveId;
|
||||
//$data['ignoreError'] = false;
|
||||
$data['name'] = $fileName;
|
||||
$data['parent_file_id'] = $parentId;
|
||||
for ($i=0;$i<$part_number;$i++) {
|
||||
$data['part_info_list'][$i]['part_number'] = $i+1;
|
||||
}
|
||||
$data['proof_code'] = $proof_code;
|
||||
$data['proof_version'] = 'v1';
|
||||
$data['size'] = (int)$size;
|
||||
$data['type'] = 'file';
|
||||
|
||||
return curl('POST', $url, json_encode($data), $header);
|
||||
}
|
||||
protected function tmpfileCreate($parentId, $tmpFilePath, $tofileName = '') {
|
||||
$sha1 = sha1_file($tmpFilePath);
|
||||
if ($tofileName == '') $tofileName = splitlast($tmpFilePath, '/')[1];
|
||||
$url = $this->api_url . '/file/create';
|
||||
|
||||
$header["content-type"] = "application/json; charset=utf-8";
|
||||
$header['authorization'] = 'Bearer ' . $this->access_token;
|
||||
|
||||
$data['check_name_mode'] = 'refuse'; // ignore, auto_rename, refuse.
|
||||
$data['content_hash'] = $sha1;
|
||||
$data['content_hash_name'] = 'sha1';
|
||||
$data['content_type'] = 'text/plain'; // now only txt
|
||||
$data['drive_id'] = $this->driveId;
|
||||
$data['ignoreError'] = false;
|
||||
$data['name'] = $tofileName;
|
||||
$data['parent_file_id'] = $parentId;
|
||||
$data['part_info_list'][0]['part_number'] = 1; // now only txt
|
||||
$data['size'] = filesize($tmpFilePath);
|
||||
$data['type'] = 'file';
|
||||
|
||||
return curl('POST', $url, json_encode($data), $header);
|
||||
}
|
||||
protected function fileComplete($file_id, $upload_id, $etags) {
|
||||
$url = $this->api_url . '/file/complete';
|
||||
|
||||
$header["content-type"] = "application/json; charset=utf-8";
|
||||
$header['authorization'] = 'Bearer ' . $this->access_token;
|
||||
|
||||
$data['drive_id'] = $this->driveId;
|
||||
$data['file_id'] = $file_id;
|
||||
$data['ignoreError'] = false;
|
||||
$i = 0;
|
||||
foreach ($etags as $etag) {
|
||||
$data['part_info_list'][$i]['part_number'] = $i + 1;
|
||||
$data['part_info_list'][$i]['etag'] = $etag;
|
||||
$i++;
|
||||
}
|
||||
$data['upload_id'] = $upload_id;
|
||||
|
||||
return curl('POST', $url, json_encode($data), $header);
|
||||
}
|
||||
|
||||
public function get_thumbnails_url($path = '/')
|
||||
{
|
||||
$res = $this->list_path($path);
|
||||
$thumb_url = $res['thumbnail'];
|
||||
return $thumb_url;
|
||||
}
|
||||
public function smallfileupload($path, $tmpfile) {
|
||||
if (!$_SERVER['admin']) {
|
||||
$tmp1 = splitlast($tmpfile['name'], '.');
|
||||
if ($tmp1[0]==''||$tmp1[1]=='') $filename = sha1_file($tmpfile['tmp_name']);
|
||||
else $filename = sha1_file($tmpfile['tmp_name']) . '.' . $tmp1[1];
|
||||
} else {
|
||||
$filename = $tmpfile['name'];
|
||||
}
|
||||
//$content = file_get_contents($tmpfile['tmp_name']);
|
||||
$result = $this->tmpfileCreate($this->list_path($_SERVER['list_path'] . '/' . $path . '/')['file_id'], $tmpfile['tmp_name'], $filename);
|
||||
//error_log1('1,url:' . $url .' res:' . json_encode($result));
|
||||
if ($result['stat']==201) {
|
||||
$res = json_decode($result['body'], true);
|
||||
$url = $res['part_info_list'][0]['upload_url'];
|
||||
if (!$url) { // 无url,应该算秒传
|
||||
//return output('no up url', 0);
|
||||
$a = 1;
|
||||
} else {
|
||||
$file_id = $res['file_id'];
|
||||
$upload_id = $res['upload_id'];
|
||||
//$result = curl('PUT', $url, $content, [], 1);
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_PUT, 1);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
$fh_res = fopen($tmpfile['tmp_name'], 'r');
|
||||
curl_setopt($ch, CURLOPT_INFILE, $fh_res);
|
||||
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($tmpfile['tmp_name']));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$tmpres = splitlast(curl_exec($ch), "\r\n\r\n");
|
||||
$result['body'] = $tmpres[1];
|
||||
$returnhead = $tmpres[0];
|
||||
foreach (explode("\r\n", $returnhead) as $head) {
|
||||
$tmp = explode(': ', $head);
|
||||
$heads[$tmp[0]] = $tmp[1];
|
||||
}
|
||||
$result['returnhead'] = $heads;
|
||||
$result['stat'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
fclose($fh_res);
|
||||
curl_close($ch);
|
||||
//error_log1('2,url:' . $url .' res:' . json_encode($result));
|
||||
if ($result['stat']==200) { // 块1传好
|
||||
$result = $this->fileComplete($file_id, $upload_id, [ $result['returnhead']['ETag'] ]);
|
||||
//error_log1('3, res:' . json_encode($result));
|
||||
//if ($result['stat']!=200) return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
//else return output('success', 0);
|
||||
}
|
||||
}
|
||||
$res = json_decode($result['body'], true);
|
||||
//if (isset($res['url']))
|
||||
$res['download_url'] = $_SERVER['host'] . path_format($_SERVER['base_disk_path'] . '/' . $path . '/' . $filename);
|
||||
}
|
||||
return output(json_encode($this->files_format($res), JSON_UNESCAPED_SLASHES), $result['stat']);
|
||||
}
|
||||
public function bigfileupload($path)
|
||||
{
|
||||
if (isset($_POST['uploadid'])) {
|
||||
// Complete
|
||||
$result = $this->fileComplete($_POST['fileid'], $_POST['uploadid'], json_decode($_POST['etag'], true));
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
} else {
|
||||
if (isset($_POST['CalcProof'])) {
|
||||
return output(substr(md5($this->access_token), 0, 16), 200);
|
||||
// Calc proof code
|
||||
/*if (!function_exists('bcadd')) {
|
||||
// no php-bcmath
|
||||
return output(0, 200);
|
||||
} else {
|
||||
$r = bchexdec( substr(md5($this->access_token), 0, 16) );
|
||||
$i = $_POST['filesize'];
|
||||
//$o = $i ? bcmod($r, $i) : 0;
|
||||
$o = bcmod($r, $i);
|
||||
return output($o, 200);
|
||||
}*/
|
||||
}
|
||||
if ($_POST['upbigfilename']=='') return output('error: no file name', 400);
|
||||
if (!is_numeric($_POST['filesize'])) return output('error: no file size', 400);
|
||||
if (!isset($_POST['filesha1'])) return output('error: no file sha1', 400);
|
||||
|
||||
$tmp = splitlast($_POST['upbigfilename'], '/');
|
||||
if ($tmp[1]!='') {
|
||||
$fileinfo['name'] = $tmp[1];
|
||||
if ($_SERVER['admin']) $fileinfo['path'] = $tmp[0];
|
||||
} else {
|
||||
$fileinfo['name'] = $_POST['upbigfilename'];
|
||||
}
|
||||
$fileinfo['size'] = $_POST['filesize'];
|
||||
$fileinfo['filelastModified'] = $_POST['filelastModified'];
|
||||
if ($_SERVER['admin']) {
|
||||
$filename = $fileinfo['name'];
|
||||
} else {
|
||||
$tmp1 = splitlast($fileinfo['name'], '.');
|
||||
if ($tmp1[0]==''||$tmp1[1]=='') $filename = $_POST['filesha1'];
|
||||
else $filename = $_POST['filesha1'] . '.' . $tmp1[1];
|
||||
}
|
||||
|
||||
$parent = $this->list_path($path . '/' . $fileinfo['path']);
|
||||
if (isset($parent['file_id'])) {
|
||||
$parent_file_id = $parent['file_id'];
|
||||
} else {
|
||||
$res = $this->folderCreate($this->list_path($path)['file_id'], $fileinfo['path']);
|
||||
//error_log1($res['body']);
|
||||
$parent_file_id = json_decode($res['body'], true)['file_id'];
|
||||
}
|
||||
//if (!function_exists('bcadd')) {
|
||||
// $response = $this->fileCreate($parent_file_id, $filename, $_POST['filesha1'], $fileinfo['size'], ceil($fileinfo['size']/$_POST['chunksize']));
|
||||
//} else {
|
||||
$response = $this->fileCreate1($parent_file_id, $filename, $_POST['filesha1'], $_POST['proof_code'], $fileinfo['size'], ceil($fileinfo['size']/$_POST['chunksize']));
|
||||
//}
|
||||
$res = json_decode($response['body'], true);
|
||||
if (isset($res['exist'])) {
|
||||
// 已经有
|
||||
//error_log1('exist:' . json_encode($res));
|
||||
return output(json_encode($this->files_format(json_decode($response['body'], true))), $response['stat']);
|
||||
//return output('{"type":"file","name":"' . $_POST['upbigfilename'] . '", "exist":true}', 200);
|
||||
}
|
||||
if (isset($res['rapid_upload'])&&$res['rapid_upload']!=false) {
|
||||
// 秒传
|
||||
//error_log1('rapid up:' . json_encode($res));
|
||||
return output(json_encode($this->files_format(json_decode($response['body'], true))), $response['stat']);
|
||||
//return output('{"type":"file","name":"' . $_POST['upbigfilename'] . '", "rapid upload":true}', 200);
|
||||
}
|
||||
//if ($response['stat']<500) {
|
||||
// $responsearry = json_decode($response['body'], true);
|
||||
// if (isset($responsearry['error'])) return output($response['body'], $response['stat']);
|
||||
// $fileinfo['uploadUrl'] = $responsearry['uploadUrl'];
|
||||
// if ($fileinfo['size']>10*1024*1024) $this->MSAPI('PUT', path_format($path . '/' . $cachefilename), json_encode($fileinfo, JSON_PRETTY_PRINT), $this->access_token);
|
||||
//}
|
||||
return output($response['body'], $response['stat']);
|
||||
}
|
||||
}
|
||||
|
||||
public function AddDisk() {
|
||||
global $constStr;
|
||||
global $EnvConfigs;
|
||||
|
||||
$envs = '';
|
||||
foreach ($EnvConfigs as $env => $v) if (isCommonEnv($env)) $envs .= '\'' . $env . '\', ';
|
||||
$url = path_format($_SERVER['PHP_SELF'] . '/');
|
||||
|
||||
if (isset($_GET['Finish'])) {
|
||||
if ($this->access_token == '') {
|
||||
$refresh_token = getConfig('refresh_token', $this->disktag);
|
||||
if (!$refresh_token) {
|
||||
$html = 'No refresh_token config, please AddDisk again or wait minutes.<br>' . $this->disktag;
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
$response = $this->get_access_token($refresh_token);
|
||||
if (!$response) return message($this->error['body'], 'Error', $this->error['stat']);
|
||||
}
|
||||
$tmp = null;
|
||||
if ($_POST['driveId']!='') {
|
||||
$tmp['driveId'] = $_POST['driveId'];
|
||||
} else {
|
||||
return message('no driveId', 'Error', 201);
|
||||
}
|
||||
|
||||
$response = setConfigResponse( setConfig($tmp, $this->disktag) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
} else {
|
||||
$str .= '
|
||||
<script>
|
||||
var status = "' . $response['DplStatus'] . '";
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(min++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . $url . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>';
|
||||
return message($str, getconstStr('WaitJumpIndex'), 201, 1);
|
||||
}
|
||||
}
|
||||
if (isset($_GET['SelectDrive'])) {
|
||||
if ($this->access_token == '') {
|
||||
if (isset($_POST['refresh_token'])) {
|
||||
$res = curl('POST', $this->auth_url, json_encode([ 'refresh_token' => $_POST['refresh_token'], 'grant_type' => 'refresh_token' ]), ["content-type"=>"application/json; charset=utf-8"]);
|
||||
//return output($res['body']);
|
||||
if ($res['stat']!=200) {
|
||||
return message($res['body'], $res['stat'], $res['stat']);
|
||||
}
|
||||
//var_dump($res['body']);
|
||||
$result = json_decode($res['body'], true);
|
||||
|
||||
$tmp = null;
|
||||
$tmp['refresh_token'] = $result['refresh_token'];
|
||||
$tmp['token_expires'] = time()+3*24*60*60;
|
||||
$tmp['Driver'] = 'Aliyundrive';
|
||||
//error_log(json_encode($tmp));
|
||||
|
||||
$response = setConfigResponse( setConfig($tmp, $this->disktag) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
savecache('access_token', $result['access_token'], $this->disktag, $result['expires_in'] - 60);
|
||||
} else {
|
||||
$refresh_token = getConfig('refresh_token', $this->disktag);
|
||||
if (!$refresh_token) {
|
||||
$html = 'No refresh_token config, please AddDisk again or wait minutes.<br>' . $this->disktag;
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
$response = $this->get_access_token($refresh_token);
|
||||
if (!$response) return message($this->error['body'], 'Error', $this->error['stat']);
|
||||
}
|
||||
}
|
||||
if (!isset($result['default_drive_id'])) {
|
||||
$res = curl('POST', $this->auth_url, json_encode([ 'refresh_token' => getConfig('refresh_token', $this->disktag), 'grant_type' => 'refresh_token' ]), ["content-type"=>"application/json; charset=utf-8"]);
|
||||
//return output($res['body']);
|
||||
if ($res['stat']!=200) {
|
||||
return message($res['body'], $res['stat'], $res['stat']);
|
||||
}
|
||||
//var_dump($res['body']);
|
||||
$result = json_decode($res['body'], true);
|
||||
}
|
||||
|
||||
//$tmp = null;
|
||||
//$tmp['driveId'] = $result['default_drive_id'];
|
||||
//$tmp['default_sbox_drive_id'] = $result['default_sbox_drive_id'];
|
||||
$title = 'Select Driver';
|
||||
$html = '
|
||||
<div>
|
||||
<form action="?Finish&disktag=' . $_GET['disktag'] . '&AddDisk=' . get_class($this) . '" method="post" onsubmit="return notnull(this);">
|
||||
<label><input type="radio" name="driveId" value="' . $result['default_drive_id'] . '"' . ($result['default_drive_id']==$this->driveId?' checked':'') . '>' . '用普通空间 ' . getconstStr(' ') . '</label><br>
|
||||
<label><input type="radio" name="driveId" value="' . $result['default_sbox_drive_id'] . '"' . ($result['default_sbox_drive_id']==$this->driveId?' checked':'') . '>' . '用虎符文件保险箱 </label><br>
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
var status = "' . $response['DplStatus'] . '";
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.driveId.value==\'\') {
|
||||
alert(\'Select a Disk\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>
|
||||
';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
if (isset($_GET['install0']) && $_POST['disktag_add']!='') {
|
||||
$_POST['disktag_add'] = preg_replace('/[^0-9a-zA-Z|_]/i', '', $_POST['disktag_add']);
|
||||
$f = substr($_POST['disktag_add'], 0, 1);
|
||||
if (strlen($_POST['disktag_add'])==1) $_POST['disktag_add'] .= '_';
|
||||
if (isCommonEnv($_POST['disktag_add'])) {
|
||||
return message('Do not input ' . $envs . '<br><button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>
|
||||
<script>
|
||||
var expd = new Date();
|
||||
expd.setTime(expd.getTime()+1);
|
||||
var expires = "expires="+expd.toGMTString();
|
||||
document.cookie=\'disktag=; path=/; \'+expires;
|
||||
</script>', 'Error', 201);
|
||||
} elseif (!(('a'<=$f && $f<='z') || ('A'<=$f && $f<='Z'))) {
|
||||
return message('Please start with letters<br><button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>
|
||||
<script>
|
||||
var expd = new Date();
|
||||
expd.setTime(expd.getTime()+1);
|
||||
var expires = "expires="+expd.toGMTString();
|
||||
document.cookie=\'disktag=; path=/; \'+expires;
|
||||
</script>', 'Error', 201);
|
||||
}
|
||||
|
||||
$tmp = null;
|
||||
foreach ($EnvConfigs as $env => $v) if (isInnerEnv($env)) $tmp[$env] = '';
|
||||
|
||||
$tmp['Driver'] = 'Aliyundrive';
|
||||
$tmp['disktag_add'] = $_POST['disktag_add'];
|
||||
$tmp['diskname'] = $_POST['diskname'];
|
||||
//error_log(json_encode($tmp));
|
||||
|
||||
$response = setConfigResponse( setConfig($tmp, $this->disktag) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 400);
|
||||
} else {
|
||||
$title = 'Refresh token';
|
||||
$html = '
|
||||
<form action="?SelectDrive&disktag=' . $_GET['disktag'] . '&AddDisk=' . get_class($this) . '" method="post" onsubmit="return notnull(this);">
|
||||
<div>填入refresh_token:
|
||||
<input type="text" name="refresh_token" placeholder="自行百度如何获取' . getconstStr(' ') . '" style="width:100%"><br>
|
||||
</div><br>
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
<form>
|
||||
<script>
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.refresh_token.value==\'\') {
|
||||
alert(\'Input refresh_token\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
var status = "' . $response['DplStatus'] . '";
|
||||
</script>
|
||||
';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
}
|
||||
|
||||
$html = '
|
||||
<div>
|
||||
<form id="form1" action="" method="post" onsubmit="return notnull(this);">
|
||||
' . getconstStr('DiskTag') . ': (' . getConfig('disktag') . ')
|
||||
<input type="text" name="disktag_add" placeholder="' . getconstStr('EnvironmentsDescription')['disktag'] . '" style="width:100%"><br>
|
||||
' . getconstStr('DiskName') . ':
|
||||
<input type="text" name="diskname" placeholder="' . getconstStr('EnvironmentsDescription')['diskname'] . '" style="width:100%"><br>
|
||||
<br>
|
||||
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.disktag_add.value==\'\') {
|
||||
alert(\'' . getconstStr('DiskTag') . '\');
|
||||
return false;
|
||||
}
|
||||
envs = [' . $envs . '];
|
||||
if (envs.indexOf(t.disktag_add.value)>-1) {
|
||||
alert("Do not input ' . $envs . '");
|
||||
return false;
|
||||
}
|
||||
var reg = /^[a-zA-Z]([_a-zA-Z0-9]{1,})$/;
|
||||
if (!reg.test(t.disktag_add.value)) {
|
||||
alert(\'' . getconstStr('TagFormatAlert') . '\');
|
||||
return false;
|
||||
}
|
||||
|
||||
document.getElementById("form1").action="?install0&disktag=" + t.disktag_add.value + "&AddDisk=Aliyundrive";
|
||||
//var expd = new Date();
|
||||
//expd.setTime(expd.getTime()+(2*60*60*1000));
|
||||
//var expires = "expires="+expd.toGMTString();
|
||||
//document.cookie=\'disktag=\'+t.disktag_add.value+\'; path=/; \'+expires;
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
$title = 'Select Account Type';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
protected function get_access_token($refresh_token) {
|
||||
if (!$refresh_token) {
|
||||
$tmp['stat'] = 0;
|
||||
$tmp['body'] = 'No refresh_token';
|
||||
$this->error = $tmp;
|
||||
return false;
|
||||
}
|
||||
if (!($this->access_token = getcache('access_token', $this->disktag))) {
|
||||
$p=0;
|
||||
$tmp1['refresh_token'] = $refresh_token;
|
||||
$tmp1['grant_type'] = 'refresh_token';
|
||||
while ($response['stat']==0&&$p<3) {
|
||||
$response = curl('POST', $this->auth_url, json_encode($tmp1), ["content-type"=>"application/json; charset=utf-8"]);
|
||||
$p++;
|
||||
}
|
||||
//error_log1(json_encode($response));
|
||||
if ($response['stat']==200) $ret = json_decode($response['body'], true);
|
||||
if (!isset($ret['access_token'])) {
|
||||
error_log1('failed to get [' . $this->disktag . '] access_token. response: ' . $response['stat'] . $response['body']);
|
||||
//$response['body'] = json_encode(json_decode($response['body']), JSON_PRETTY_PRINT);
|
||||
$response['body'] .= 'failed to get [' . $this->disktag . '] access_token.';
|
||||
$this->error = $response;
|
||||
return false;
|
||||
}
|
||||
$tmp = $ret;
|
||||
$tmp['access_token'] = substr($tmp['access_token'], 0, 10) . '******';
|
||||
$tmp['refresh_token'] = substr($tmp['refresh_token'], 0, 10) . '******';
|
||||
error_log1('[' . $this->disktag . '] Get access token:' . json_encode($tmp, JSON_PRETTY_PRINT));
|
||||
$this->access_token = $ret['access_token'];
|
||||
savecache('access_token', $this->access_token, $this->disktag, $ret['expires_in'] - 300);
|
||||
if (time()>getConfig('token_expires', $this->disktag)) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+3*24*60*60 ], $this->disktag);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function getDiskSpace() {
|
||||
if (!($diskSpace = getcache('diskSpace', $this->disktag))) {
|
||||
$url = $this->api_url . '/databox/get_personal_info';
|
||||
$header["content-type"] = "application/json; charset=utf-8";
|
||||
$header['authorization'] = 'Bearer ' . $this->access_token;
|
||||
$response = curl('POST', $url, '', $header);
|
||||
//error_log1(json_encode($response));
|
||||
$res = json_decode($response['body'], true)['personal_space_info'];
|
||||
$used = size_format($res['used_size']);
|
||||
$total = size_format($res['total_size']);
|
||||
$diskSpace = $used . ' / ' . $total;
|
||||
savecache('diskSpace', $diskSpace, $this->disktag);
|
||||
}
|
||||
return $diskSpace;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,865 @@
|
|||
<?php
|
||||
|
||||
class Googledrive {
|
||||
protected $access_token;
|
||||
protected $disktag;
|
||||
|
||||
function __construct($tag) {
|
||||
$this->disktag = $tag;
|
||||
$this->redirect_uri = 'https://scfonedrive.github.io';
|
||||
if (getConfig('client_id', $tag) && getConfig('client_secret', $tag)) {
|
||||
$this->client_id = getConfig('client_id', $tag);
|
||||
$this->client_secret = getConfig('client_secret', $tag);
|
||||
} else {
|
||||
$this->client_id = '106151778902-ajieetaab5ondhbvia97n4tr5k0cg8eo.apps.googleusercontent.com';
|
||||
$this->client_secret = 'LlCV-rQClzYIKCEqiVddh68G';
|
||||
}
|
||||
//$this->oauth_url = 'https://www.googleapis.com/oauth2/v4/';
|
||||
$this->oauth_url = 'https://accounts.google.com/o/oauth2/';
|
||||
$this->api_url = 'https://www.googleapis.com/drive/v3';
|
||||
$this->scope = 'https://www.googleapis.com/auth/drive';
|
||||
|
||||
$this->client_secret = urlencode($this->client_secret);
|
||||
$this->scope = urlencode($this->scope);
|
||||
//$this->DownurlStrName = '@microsoft.graph.downloadUrl';
|
||||
//$this->ext_api_url = '/me/drive/root';
|
||||
$this->driveId = getConfig('driveId', $tag);
|
||||
$res = $this->get_access_token(getConfig('refresh_token', $tag));
|
||||
}
|
||||
|
||||
public function isfine()
|
||||
{
|
||||
if (!$this->access_token) return false;
|
||||
else return true;
|
||||
}
|
||||
public function show_base_class()
|
||||
{
|
||||
return get_class();
|
||||
//$tmp[0] = get_class();
|
||||
//$tmp[1] = get_class($this);
|
||||
//return $tmp;
|
||||
}
|
||||
|
||||
public function ext_show_innerenv()
|
||||
{
|
||||
return ['driveId'];
|
||||
}
|
||||
|
||||
public function list_files($path = '/')
|
||||
{
|
||||
$files = $this->list_path($path);
|
||||
|
||||
return $this->files_format($files);
|
||||
}
|
||||
|
||||
protected function files_format($files)
|
||||
{
|
||||
if (isset($files['files']) || (isset($files['mimeType'])&&$files['mimeType']=='application/vnd.google-apps.folder') ) {
|
||||
$tmp['type'] = 'folder';
|
||||
$tmp['id'] = $files['id'];
|
||||
$tmp['name'] = $files['name'];
|
||||
$tmp['time'] = $files['modifiedTime'];
|
||||
$tmp['size'] = $files['size'];
|
||||
$tmp['childcount'] = $files['folder']['childCount'];
|
||||
$tmp['page'] = $files['folder']['page'];
|
||||
foreach ($files['files'] as $file) {
|
||||
$filename = strtolower($file['name']);
|
||||
if ($file['mimeType']=='application/vnd.google-apps.folder') {
|
||||
$tmp['list'][$filename]['type'] = 'folder';
|
||||
} else {
|
||||
$tmp['list'][$filename]['type'] = 'file';
|
||||
//var_dump($file);
|
||||
//echo $file['name'] . ':' . $this->DownurlStrName . ':' . $file[$this->DownurlStrName] . PHP_EOL;
|
||||
$tmp['list'][$filename]['url'] = ($file['downUrl']?$file['downUrl']:$file['webContentLink']);
|
||||
$tmp['list'][$filename]['mime'] = $file['mimeType'];
|
||||
}
|
||||
$tmp['list'][$filename]['id'] = $file['id'];
|
||||
$tmp['list'][$filename]['name'] = $file['name'];
|
||||
$tmp['list'][$filename]['time'] = $file['modifiedTime'];
|
||||
$tmp['list'][$filename]['size'] = $file['size'];
|
||||
}
|
||||
} elseif (isset($files['mimeType'])) {
|
||||
$tmp['type'] = 'file';
|
||||
$tmp['id'] = $files['id'];
|
||||
$tmp['name'] = $files['name'];
|
||||
$tmp['time'] = $files['modifiedTime'];
|
||||
$tmp['size'] = $files['size'];
|
||||
$tmp['mime'] = $files['mimeType'];
|
||||
$tmp['url'] = ($files['downUrl']?$files['downUrl']:$files['webContentLink']);
|
||||
$tmp['content'] = $files['content'];
|
||||
} else/*if (isset($files['error']))*/ {
|
||||
return $files;
|
||||
}
|
||||
//error_log1(json_encode($tmp));
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
protected function list_path($path = '/')
|
||||
{
|
||||
global $exts;
|
||||
while (substr($path, -1)=='/') $path = substr($path, 0, -1);
|
||||
if ($path == '') $path = '/';
|
||||
|
||||
if (!($files = getcache('path_' . $path, $this->disktag))) {
|
||||
//$response = curl('GET', $this->api_url . '/drives', '', ['Authorization' => 'Bearer ' . $this->access_token]);
|
||||
//$response = curl('GET', $this->api_url . '/files?fields=*,files(id,name,mimeType,size,modifiedTime,parents,webContentLink,thumbnailLink),nextPageToken' . (($this->driveId!='')?'&driveId=' . $this->driveId . '&corpora=teamDrive&includeItemsFromAllDrives=true&supportsAllDrives=true':''), '', ['Authorization' => 'Bearer ' . $this->access_token]);
|
||||
if ($path == '/' || $path == '') {
|
||||
$files = $this->fileList();
|
||||
//error_log1('root_id' . $files['id']);
|
||||
//$files['id'] = 'root';
|
||||
//$files['type'] = 'folder';
|
||||
} else {
|
||||
$tmp = splitlast($path, '/');
|
||||
$parent_path = $tmp[0];
|
||||
$filename = urldecode($tmp[1]);
|
||||
$parent_folder = $this->list_path($parent_path);
|
||||
$i = 0;
|
||||
foreach ($parent_folder['files'] as $item) {
|
||||
if ($item['name']==$filename) {
|
||||
if ($item['mimeType']=='application/vnd.google-apps.folder') {
|
||||
$files = $this->fileList($item['id']);
|
||||
$files['type'] = 'folder';
|
||||
$files['id'] = $item['id'];
|
||||
$files['name'] = $item['name'];
|
||||
$files['time'] = $item['modifiedTime'];
|
||||
$files['size'] = $item['size'];
|
||||
} else {
|
||||
if (isset($item['id'])&&$item['shared']!==true) $this->permission('create', $item['id']);
|
||||
//$this->permission('delete', $files['id']);
|
||||
|
||||
//if (isset($item['mimeType']) && $item['mimeType']!='application/vnd.google-apps.folder') {
|
||||
if (in_array(strtolower(splitlast($item['name'],'.')[1]), $exts['txt'])) {
|
||||
if ($files['size']<1024*1024) {
|
||||
if (!(isset($item['content'])&&$item['content']['stat']==200)) {
|
||||
//if (!isset($item['downUrl'])) {
|
||||
$res = curl('GET', $item['webContentLink'], '', [], 1);
|
||||
$weblink = $res['returnhead']['Location'];
|
||||
//if ($weblink!==null) $item['downUrl'] = $weblink;
|
||||
//else error_log1('Cant get link:' . json_encode($res, JSON_PRETTY_PRINT));
|
||||
//}
|
||||
if ($res['stat']==302) {
|
||||
$content1 = curl('GET', $weblink, '', ["User-Agent"=>"qkqpttgf/OneManager 3.0.0", "Accept"=>"*/*"]);
|
||||
$tmp = null;
|
||||
$tmp = json_decode(json_encode($content1), true);
|
||||
if ($tmp['body']===null) {
|
||||
$tmp['body'] = iconv("GBK", 'UTF-8//TRANSLIT', $content1['body']);
|
||||
$tmp = json_decode(json_encode($tmp), true);
|
||||
if ($tmp['body']!==null) $content1['body'] = $tmp['body'];
|
||||
}
|
||||
$item['content'] = $content1;
|
||||
}// else $content1 = $res;
|
||||
//error_log1($item['name'] . '~' . json_encode($content1, JSON_PRETTY_PRINT) . PHP_EOL);
|
||||
$parent_folder['files'][$i] = $item;
|
||||
savecache('path_' . $path, $parent_folder, $this->disktag);
|
||||
}
|
||||
} else {
|
||||
$files['content']['stat'] = 202;
|
||||
$files['content']['body'] = 'File too large.';
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
//error_log1(json_encode($item, JSON_PRETTY_PRINT));
|
||||
$files = $item;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
//echo $files['name'];
|
||||
}
|
||||
|
||||
if (!$files) {
|
||||
$files['error']['code'] = 'Not Found';
|
||||
$files['error']['message'] = 'Not Found';
|
||||
$files['error']['stat'] = 404;
|
||||
} elseif (isset($files['stat'])) {
|
||||
$files['error']['stat'] = $files['stat'];
|
||||
$files['error']['code'] = 'Error';
|
||||
$files['error']['message'] = $files['body'];
|
||||
} else {
|
||||
savecache('path_' . $path, $files, $this->disktag, 600);
|
||||
}
|
||||
}
|
||||
//error_log1('path:' . $path . ', files:' . json_encode($files, JSON_PRETTY_PRINT));
|
||||
//error_log1('path:' . $path . ', files:' . substr(json_encode($files), 0, 150));
|
||||
return $files;
|
||||
}
|
||||
protected function fileList($parent_file_id = '')
|
||||
{
|
||||
$url = $this->api_url . '/files';
|
||||
|
||||
$url .= '?fields=files(id,name,mimeType,size,modifiedTime,parents,webContentLink,thumbnailLink,shared,permissions,permissionIds),nextPageToken';
|
||||
//$url .= '?fields=files(*),nextPageToken';
|
||||
//$url .= '?q=mimeType=\'application/vnd.google-apps.folder\'';
|
||||
if ($parent_file_id!='') {
|
||||
$q = $parent_file_id;
|
||||
} else {
|
||||
$q = $this->driveId;
|
||||
}
|
||||
$q = '\'' . $q . '\' in parents and trashed = false';
|
||||
$q = urlencode($q);
|
||||
$url .= '&q=' . $q;
|
||||
if ($this->driveId!='root') $url .= '&driveId=' . $this->driveId . '&corpora=teamDrive&includeItemsFromAllDrives=true&supportsAllDrives=true';
|
||||
|
||||
$header['Authorization'] = 'Bearer ' . $this->access_token;
|
||||
|
||||
$res = curl('GET', $url, '', $header);
|
||||
if ($res['stat']==200) return json_decode($res['body'], true);
|
||||
else return $res;
|
||||
}
|
||||
protected function permission($op, $fileId)
|
||||
{
|
||||
$url = $this->api_url . '/files/' . $fileId . '/permissions';
|
||||
if ($op=='create') {
|
||||
$method = 'POST';
|
||||
$header['Content-Type'] = 'application/json';
|
||||
$tmp['role'] = 'reader';
|
||||
$tmp['type'] = 'anyone';
|
||||
$data = json_encode($tmp);
|
||||
} elseif ($op=='delete') {
|
||||
$url .= '/anyoneWithLink';
|
||||
$method = 'DELETE';
|
||||
$data = '';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
$url .= '?supportsAllDrives=true';
|
||||
$header['Authorization'] = 'Bearer ' . $this->access_token;
|
||||
|
||||
$res = curl($method, $url, $data, $header);
|
||||
//error_log1('Set Share' . json_encode($res, JSON_PRETTY_PRINT));
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function Rename($file, $newname) {
|
||||
$url = $this->api_url . '/files/' . $file['id'] . '?supportsAllDrives=true';
|
||||
$tmp['name'] = $newname;
|
||||
$result = $this->GDAPI('PATCH', $url, json_encode($tmp));
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
public function Delete($file) {
|
||||
$url = $this->api_url . '/files/' . $file['id'] . '?supportsAllDrives=true';
|
||||
$result = $this->GDAPI('DELETE', $url);
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
public function Encrypt($folder, $passfilename, $pass) {
|
||||
$existfile = $this->list_path($folder['path'] . '/' . $passfilename);
|
||||
if (isset($existfile['name'])) {
|
||||
if ($pass==='') {
|
||||
// 如果为空,删除
|
||||
$this->Delete(['id'=>$existfile['id']]);
|
||||
return output('Success', 200);
|
||||
} else {
|
||||
$result = $this->editFile($existfile['id'], $pass);
|
||||
}
|
||||
} else {
|
||||
if (!$folder['id']) {
|
||||
$res = $this->list_path($folder['path']);
|
||||
//error_log1('res:' . json_encode($res));
|
||||
$folder['id'] = $res['id'];
|
||||
}
|
||||
if (!$folder['id']) {
|
||||
$folder['id'] = $this->driveId;
|
||||
}
|
||||
$result = $this->createFile_c($folder['id'], $passfilename, $pass);
|
||||
}
|
||||
|
||||
//error_log1('2,url:' . $url .' res:' . json_encode($result));
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
public function Move($file, $folder) {
|
||||
$nowParentId = $this->list_path($file['path'])['id'];
|
||||
if (!$nowParentId) {
|
||||
$nowParentId = $this->driveId;
|
||||
}
|
||||
if (!$folder['id']) {
|
||||
$res = $this->list_path($folder['path']);
|
||||
//error_log1('res:' . json_encode($res));
|
||||
$folder['id'] = $res['id'];
|
||||
}
|
||||
if (!$folder['id']) {
|
||||
$folder['id'] = $this->driveId;
|
||||
}
|
||||
$url = $this->api_url . '/files/' . $file['id'] . '?removeParents=' . $nowParentId . '&addParents=' . $folder['id'] . '&supportsAllDrives=true';
|
||||
//$tmp['name'] = $newname;
|
||||
$result = $this->GDAPI('PATCH', $url);
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
public function Copy($file) {
|
||||
$url = $this->api_url . '/files/' . $file['id'] . '/copy?supportsAllDrives=true';
|
||||
$namearr = splitlast($file['name'], '.');
|
||||
date_default_timezone_set('UTC');
|
||||
if ($namearr[0]!='') {
|
||||
$newname = $namearr[0] . '_' . date("Ymd\_His");
|
||||
if ($namearr[1]!='') $newname .= '.' . $namearr[1];
|
||||
} else {
|
||||
$newname = '.' . $namearr[1] . '_' . date("Ymd\_His");
|
||||
}
|
||||
$tmp['name'] = $newname;
|
||||
$result = $this->GDAPI('POST', $url, json_encode($tmp));
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
public function Edit($file, $content) {
|
||||
$tmp = splitlast($file['path'], '/');
|
||||
$folderpath = $tmp[0];
|
||||
$filename = $tmp[1];
|
||||
$existfile = $this->list_path($file['path']);
|
||||
if (isset($existfile['name'])) {
|
||||
$result = $this->editFile($existfile['id'], $content);
|
||||
} else {
|
||||
$result = $this->createFile_c($this->list_path($folderpath)['id'], $filename, $content);
|
||||
}
|
||||
//error_log1('edit: ' . json_encode($result, JSON_PRETTY_PRINT));
|
||||
if ($result['stat']==200) return output('success', 0);
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
public function Create($parent, $type, $name, $content = '') {
|
||||
$filename = spurlencode($name);
|
||||
$filename = path_format($parent['path'] . '/' . $filename);
|
||||
$res = $this->list_path($filename);
|
||||
//error_log1($filename . '查重:' . json_encode($res, JSON_PRETTY_PRINT) . PHP_EOL);
|
||||
if (isset($res['name'])) {
|
||||
$tmp['error']['code'] = 'File exist';
|
||||
$tmp['error']['message'] = $res;
|
||||
$tmp['error']['stat'] = 409;
|
||||
return output(json_encode($this->files_format($tmp), JSON_PRETTY_PRINT), $tmp['error']['stat']);
|
||||
}
|
||||
if (!$parent['id']) {
|
||||
$res = $this->list_path($parent['path']);
|
||||
//error_log1('找ID:' . json_encode($res));
|
||||
$parent['id'] = $res['id'];
|
||||
}
|
||||
if (!$parent['id']) {
|
||||
$parent['id'] = $this->driveId;
|
||||
}
|
||||
|
||||
if ($type=='file') {
|
||||
$result = $this->createFile_c($parent['id'], $name, $content);
|
||||
}
|
||||
if ($type=='folder') {
|
||||
$result = $this->createFolder($parent['id'], $name);
|
||||
}
|
||||
//error_log1('data:' . $data . ' res:' . json_encode($result, JSON_PRETTY_PRINT));
|
||||
//savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
|
||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||
}
|
||||
public function get_thumbnails_url($path = '/') {
|
||||
$res = $this->list_path($path);
|
||||
$thumb_url = $res['thumbnailLink'];
|
||||
return $thumb_url;
|
||||
}
|
||||
public function bigfileupload($path) {
|
||||
return output('Stop!\nCan not upload form explorer without token.', 403);
|
||||
|
||||
// https://developers.google.com/drive/api/v3/manage-uploads#http---multiple-requests
|
||||
|
||||
if ($_POST['upbigfilename']=='') return output('error: no file name', 400);
|
||||
if (!is_numeric($_POST['filesize'])) return output('error: no file size', 400);
|
||||
if (!$_SERVER['admin']) if (!isset($_POST['filemd5'])) return output('error: no file md5', 400);
|
||||
$filename = $_POST['upbigfilename'];
|
||||
$filename = path_format($path . '/' . $filename);
|
||||
$res = $this->list_path($filename);
|
||||
//error_log1($filename . '查重:' . json_encode($res, JSON_PRETTY_PRINT) . PHP_EOL);
|
||||
if (isset($res['name'])) {
|
||||
$tmp['error']['code'] = 'File exist';
|
||||
$tmp['error']['message'] = json_encode($res);
|
||||
$tmp['error']['stat'] = 409;
|
||||
return output(json_encode($this->files_format($tmp), JSON_PRETTY_PRINT), $tmp['error']['stat']);
|
||||
}
|
||||
$tmp = splitlast($_POST['upbigfilename'], '/');
|
||||
if ($tmp[1]!='') {
|
||||
$fileinfo['name'] = $tmp[1];
|
||||
if ($_SERVER['admin']) $fileinfo['path'] = $tmp[0];
|
||||
} else {
|
||||
$fileinfo['name'] = $_POST['upbigfilename'];
|
||||
}
|
||||
$fileinfo['size'] = $_POST['filesize'];
|
||||
$fileinfo['filelastModified'] = $_POST['filelastModified'];
|
||||
if ($_SERVER['admin']) {
|
||||
$filename = $fileinfo['name'];
|
||||
} else {
|
||||
$tmp1 = splitlast($fileinfo['name'], '.');
|
||||
if ($tmp1[0]==''||$tmp1[1]=='') $filename = $_POST['filemd5'];
|
||||
else $filename = $_POST['filemd5'] . '.' . $tmp1[1];
|
||||
}
|
||||
$parent = $this->list_path($path . '/' . $fileinfo['path']);
|
||||
if (isset($parent['id'])) {
|
||||
$parent_file_id = $parent['id'];
|
||||
} else {
|
||||
$res = $this->createFolder($this->list_path($path)['id'], $fileinfo['path']);
|
||||
//error_log1($res['body']);
|
||||
$parent_file_id = json_decode($res['body'], true)['id'];
|
||||
}
|
||||
$url = 'https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable';
|
||||
$res = $this->list_path($path);
|
||||
//error_log1('找ID:' . json_encode($res));
|
||||
$parentId = $res['id'];
|
||||
if (!$parentId) {
|
||||
$parentId = $this->driveId;
|
||||
}
|
||||
$tmp['name'] = $_POST['upbigfilename'];
|
||||
$tmp['parents'][0] = $parentId;
|
||||
|
||||
$header['Authorization'] = 'Bearer ' . $this->access_token;
|
||||
$header['Content-Type'] = 'application/json; charset=UTF-8';
|
||||
//$header['Content-Length'] = '';
|
||||
//$header['X-Upload-Content-Type'] = '';
|
||||
//$header['X-Upload-Content-Length'] = $_POST['filesize'];
|
||||
|
||||
$response = curl('POST', $url, json_encode($tmp), $header, 1);
|
||||
return output($response['returnhead']['Location'], $response['stat']);
|
||||
}
|
||||
|
||||
protected function editFile($id, $content) {
|
||||
$url = 'https://www.googleapis.com/upload/drive/v3/files/' . $id . '?uploadType=multipart&supportsAllDrives=true';
|
||||
|
||||
$boundary = md5($id . date());
|
||||
$header['Content-Type'] = 'multipart/related; boundary=' . $boundary;
|
||||
$header['Authorization'] = 'Bearer ' . $this->access_token;
|
||||
$data = '--' . $boundary . "\r\n";
|
||||
$data .= 'Content-Type: application/json; charset=UTF-8' . "\r\n";
|
||||
$data .= "\r\n";
|
||||
$data .= "\r\n";
|
||||
$data .= "\r\n";
|
||||
$data .= '--' . $boundary . "\r\n";
|
||||
$data .= 'Content-Type: text/plain' . "\r\n";
|
||||
$data .= "\r\n";
|
||||
$data .= $content . "\r\n";
|
||||
$data .= '--' . $boundary . "--";
|
||||
|
||||
$result = curl('PATCH', $url, $data, $header);
|
||||
//error_log1('url: ' . $url . ' data: ' . $data . ' result: ' . json_encode($result, JSON_PRETTY_PRINT));
|
||||
return $result;
|
||||
}
|
||||
protected function createFile_c($parentId, $name, $content) {
|
||||
while (substr($name, 0, 1)=='/') $name = substr($name, 1);
|
||||
while (substr($name, -1)=='/') $name = substr($name, 0, -1);
|
||||
if (strpos($name, '/')>0) {
|
||||
$p = splitlast($name, '/');
|
||||
$res = $this->createFolder($parentId, $p[0]);
|
||||
$parentId = json_decode($res['body'], true)['id'];
|
||||
$name = $p[1];
|
||||
}
|
||||
|
||||
$url = 'https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart&supportsAllDrives=true';
|
||||
$tmp['name'] = $name;
|
||||
$tmp['parents'][0] = $parentId;
|
||||
|
||||
$boundary = md5($name . date());
|
||||
$header['Content-Type'] = 'multipart/related; boundary=' . $boundary;
|
||||
$header['Authorization'] = 'Bearer ' . $this->access_token;
|
||||
$data = '--' . $boundary . "\r\n";
|
||||
$data .= 'Content-Type: application/json; charset=UTF-8' . "\r\n";
|
||||
$data .= "\r\n";
|
||||
$data .= json_encode($tmp, JSON_PRETTY_PRINT) . "\r\n";
|
||||
$data .= "\r\n";
|
||||
$data .= '--' . $boundary . "\r\n";
|
||||
$data .= 'Content-Type: text/plain' . "\r\n";
|
||||
$data .= "\r\n";
|
||||
$data .= $content . "\r\n";
|
||||
$data .= '--' . $boundary . "--";
|
||||
|
||||
$result = curl('POST', $url, $data, $header);
|
||||
return $result;
|
||||
}
|
||||
protected function createFolder($parentId, $name) {
|
||||
while (substr($name, 0, 1)=='/') $name = substr($name, 1);
|
||||
while (substr($name, -1)=='/') $name = substr($name, 0, -1);
|
||||
if (strpos($name, '/')>0) {
|
||||
$p = splitlast($name, '/');
|
||||
$res = $this->createFolder($parentId, $p[0]);
|
||||
$parentId = json_decode($res['body'], true)['id'];
|
||||
$name = $p[1];
|
||||
}
|
||||
|
||||
$url = $this->api_url . '/files?&supportsAllDrives=true';
|
||||
|
||||
$tmp['name'] = $name;
|
||||
$tmp['parents'][0] = $parentId;
|
||||
$tmp['mimeType'] = 'application/vnd.google-apps.folder';
|
||||
$data = json_encode($tmp);
|
||||
|
||||
$header['Content-Type'] = 'application/json; charset=UTF-8';
|
||||
$header['Authorization'] = 'Bearer ' . $this->access_token;
|
||||
|
||||
$result = curl('POST', $url, $data, $header);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function AddDisk() {
|
||||
global $constStr;
|
||||
global $EnvConfigs;
|
||||
|
||||
$envs = '';
|
||||
foreach ($EnvConfigs as $env => $v) if (isCommonEnv($env)) $envs .= '\'' . $env . '\', ';
|
||||
$url = path_format($_SERVER['PHP_SELF'] . '/');
|
||||
|
||||
if (isset($_GET['Finish'])) {
|
||||
if ($this->access_token == '') {
|
||||
$refresh_token = getConfig('refresh_token', $this->disktag);
|
||||
if (!$refresh_token) {
|
||||
$html = 'No refresh_token config, please AddDisk again or wait minutes.<br>' . $this->disktag;
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
$response = $this->get_access_token($refresh_token);
|
||||
if (!$response) return message($this->error['body'], 'Error', $this->error['stat']);
|
||||
}
|
||||
|
||||
$tmp = null;
|
||||
if ($_POST['DriveType']=='Googledrive') {
|
||||
$tmp['driveId'] = 'root';
|
||||
} else {
|
||||
// 直接是id
|
||||
$tmp['driveId'] = $_POST['DriveType'];
|
||||
}
|
||||
|
||||
$response = setConfigResponse( setConfig($tmp, $this->disktag) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
} else {
|
||||
$str .= '<meta http-equiv="refresh" content="5;URL=' . $url . '">';
|
||||
return message($str, getconstStr('WaitJumpIndex'), 201);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET['SelectDrive'])) {
|
||||
if ($this->access_token == '') {
|
||||
$refresh_token = getConfig('refresh_token', $this->disktag);
|
||||
if (!$refresh_token) {
|
||||
$html = 'No refresh_token config, please AddDisk again or wait minutes.<br>' . $this->disktag;
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
$response = $this->get_access_token($refresh_token);
|
||||
if (!$response) return message($this->error['body'], 'Error', $this->error['stat']);
|
||||
}
|
||||
|
||||
$api = $this->api_url . '/drives';
|
||||
$arr = curl('GET', $api, '', [ 'Authorization' => 'Bearer ' . $this->access_token ]);
|
||||
//if (!($arr['stat']==200||$arr['stat']==403||$arr['stat']==400||$arr['stat']==404))
|
||||
if ($arr['stat']!=200) return message($arr['stat'] . json_encode(json_decode($arr['body']), JSON_PRETTY_PRINT), 'Get followedSites', $arr['stat']);
|
||||
error_log1($arr['body']);
|
||||
$drives = json_decode($arr['body'], true)['drives'];
|
||||
|
||||
$title = 'Select Driver';
|
||||
$html = '
|
||||
<div>
|
||||
<form action="?Finish&disktag=' . $_GET['disktag'] . '&AddDisk=' . get_class($this) . '" method="post" onsubmit="return notnull(this);">
|
||||
<label><input type="radio" name="DriveType" value="Googledrive" checked>' . 'Use Googledrive ' . getconstStr(' ') . '</label><br>';
|
||||
if ($drives[0]!='') foreach ($drives as $k => $v) {
|
||||
$html .= '
|
||||
<label>
|
||||
<input type="radio" name="DriveType" value="' . $v['id'] . '" onclick="document.getElementById(\'sharepointSiteUrl\').value=\'' . $v['webUrl'] . '\';">' . 'Use Google share drive: <br><div style="width:100%;margin:0px 35px">: ' . $v['name'] . '<br>siteid: ' . $v['id'] . '</div>
|
||||
</label>';
|
||||
}
|
||||
$html .= '
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.DriveType.value==\'\') {
|
||||
alert(\'Select a Disk\');
|
||||
return false;
|
||||
}
|
||||
if (t.DriveType.value==\'Custom\') {
|
||||
if (t.sharepointSite.value==\'\') {
|
||||
alert(\'sharepoint Site Address\');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>
|
||||
';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
if (isset($_GET['install2']) && isset($_GET['code'])) {
|
||||
$data['client_id'] = $this->client_id;
|
||||
$data['client_secret'] = $this->client_secret;
|
||||
$data['grant_type'] = 'authorization_code';
|
||||
$data['redirect_uri'] = $this->redirect_uri;
|
||||
$data['code'] = $_GET['code'];
|
||||
$api = $this->oauth_url . 'token';
|
||||
//$api = 'https://www.googleapis.com/oauth2/v4/token';
|
||||
$tmp = curl('POST',
|
||||
$api,
|
||||
json_encode($data)
|
||||
);
|
||||
if ($tmp['stat']==200) $ret = json_decode($tmp['body'], true);
|
||||
if (isset($ret['refresh_token'])) {
|
||||
$refresh_token = $ret['refresh_token'];
|
||||
$str = '
|
||||
refresh_token :<br>';
|
||||
$str .= '
|
||||
<textarea readonly style="width: 95%">' . $refresh_token . '</textarea><br><br>
|
||||
' . getconstStr('SavingToken') . '
|
||||
<script>
|
||||
var texta=document.getElementsByTagName(\'textarea\');
|
||||
for(i=0;i<texta.length;i++) {
|
||||
texta[i].style.height = texta[i].scrollHeight + \'px\';
|
||||
}
|
||||
</script>';
|
||||
$tmptoken['refresh_token'] = $refresh_token;
|
||||
//$tmptoken['token_expires'] = time()+7*24*60*60;
|
||||
$response = setConfigResponse( setConfig($tmptoken, $this->disktag) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
} else {
|
||||
savecache('access_token', $ret['access_token'], $this->disktag, $ret['expires_in'] - 60);
|
||||
$str .= '
|
||||
<meta http-equiv="refresh" content="3;URL=' . $url . '?AddDisk=' . get_class($this) . '&disktag=' . $_GET['disktag'] . '&SelectDrive">';
|
||||
return message($str, getconstStr('Wait') . ' 3s', 201);
|
||||
}
|
||||
}
|
||||
return message('<pre>' . $tmp['body'] . '</pre>', $tmp['stat']);
|
||||
//return message('<pre>' . json_encode($ret, JSON_PRETTY_PRINT) . '</pre>', 500);
|
||||
}
|
||||
|
||||
if (isset($_GET['install1'])) {
|
||||
if (get_class($this)=='Googledrive') {
|
||||
return message('
|
||||
<a href="" id="a1">' . getconstStr('JumptoOffice') . '</a>
|
||||
<script>
|
||||
url=location.protocol + "//" + location.host + "' . $url . '?install2&disktag=' . $_GET['disktag'] . '&AddDisk=' . get_class($this) . '";
|
||||
url="' . $this->oauth_url . 'auth?scope=' . $this->scope . '&response_type=code&client_id=' . $this->client_id . '&redirect_uri=' . $this->redirect_uri . '&access_type=offline&state=' . '"+encodeURIComponent(url);
|
||||
document.getElementById(\'a1\').href=url;
|
||||
//window.open(url,"_blank");
|
||||
location.href = url;
|
||||
</script>
|
||||
', getconstStr('Wait') . ' 1s', 201);
|
||||
} else {
|
||||
return message('Something error, retry after a few seconds.', 'Retry', 201);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET['install0'])) {
|
||||
if ($_POST['disktag_add']!='') {
|
||||
$_POST['disktag_add'] = preg_replace('/[^0-9a-zA-Z|_]/i', '', $_POST['disktag_add']);
|
||||
$f = substr($_POST['disktag_add'], 0, 1);
|
||||
if (strlen($_POST['disktag_add'])==1) $_POST['disktag_add'] .= '_';
|
||||
if (isCommonEnv($_POST['disktag_add'])) {
|
||||
return message('Do not input ' . $envs . '<br><button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>', 'Error', 201);
|
||||
} elseif (!(('a'<=$f && $f<='z') || ('A'<=$f && $f<='Z'))) {
|
||||
return message('Please start with letters<br><button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>
|
||||
<script>
|
||||
var expd = new Date();
|
||||
expd.setTime(expd.getTime()+1);
|
||||
var expires = "expires="+expd.toGMTString();
|
||||
document.cookie=\'disktag=; path=/; \'+expires;
|
||||
</script>', 'Error', 201);
|
||||
}
|
||||
|
||||
$tmp = null;
|
||||
// clear envs
|
||||
foreach ($EnvConfigs as $env => $v) if (isInnerEnv($env)) $tmp[$env] = '';
|
||||
|
||||
//$this->disktag = $_POST['disktag_add'];
|
||||
$tmp['disktag_add'] = $_POST['disktag_add'];
|
||||
$tmp['diskname'] = $_POST['diskname'];
|
||||
$tmp['Driver'] = 'Googledrive';
|
||||
|
||||
if ($_POST['NT_Drive_custom']=='on') {
|
||||
$tmp['client_id'] = $_POST['NT_client_id'];
|
||||
$tmp['client_secret'] = $_POST['NT_client_secret'];
|
||||
}
|
||||
|
||||
$response = setConfigResponse( setConfig($tmp, $this->disktag) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
} else {
|
||||
$title = getconstStr('MayinEnv');
|
||||
$html = getconstStr('Wait') . ' 3s<meta http-equiv="refresh" content="3;URL=' . $url . '?install1&disktag=' . $_GET['disktag'] . '&AddDisk=Googledrive">';
|
||||
}
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
}
|
||||
|
||||
$html = '
|
||||
<div>
|
||||
<form id="form1" action="" method="post" onsubmit="return notnull(this);">
|
||||
' . getconstStr('DiskTag') . ': (' . getConfig('disktag') . ')
|
||||
<input type="text" name="disktag_add" placeholder="' . getconstStr('EnvironmentsDescription')['disktag'] . '" style="width:100%"><br>
|
||||
' . getconstStr('DiskName') . ':
|
||||
<input type="text" name="diskname" placeholder="' . getconstStr('EnvironmentsDescription')['diskname'] . '" style="width:100%"><br>
|
||||
<br>
|
||||
<div>
|
||||
<label><input type="checkbox" name="NT_Drive_custom" onclick="document.getElementById(\'NT_secret\').style.display=(this.checked?\'\':\'none\');">' . getconstStr('CustomIdSecret') . '</label><br>
|
||||
<div id="NT_secret" style="display:none;margin:10px 35px">
|
||||
<a href="https://console.cloud.google.com/apis" target="_blank">' . getconstStr('GetSecretIDandKEY') . '</a><br>
|
||||
return_uri(Reply URL):<br>https://scfonedrive.github.io<br>
|
||||
client_id:<input type="text" name="NT_client_id" style="width:100%" placeholder="123456789-abcdefghijklmno.apps.googleusercontent.com"><br>
|
||||
client_secret:<input type="text" name="NT_client_secret" style="width:100%"><br>
|
||||
</div>
|
||||
</div>
|
||||
<br>';
|
||||
if ($_SERVER['language']=='zh-cn') $html .= '你要理解 scfonedrive.github.io 是github上的静态网站,<br><font color="red">除非github真的挂掉</font>了,<br>不然,稍后你如果连不上,请检查你的运营商或其它“你懂的”问题!<br>';
|
||||
$html .='
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.disktag_add.value==\'\') {
|
||||
alert(\'' . getconstStr('DiskTag') . '\');
|
||||
return false;
|
||||
}
|
||||
envs = [' . $envs . '];
|
||||
if (envs.indexOf(t.disktag_add.value)>-1) {
|
||||
alert("Do not input ' . $envs . '");
|
||||
return false;
|
||||
}
|
||||
var reg = /^[a-zA-Z]([_a-zA-Z0-9]{1,})$/;
|
||||
if (!reg.test(t.disktag_add.value)) {
|
||||
alert(\'' . getconstStr('TagFormatAlert') . '\');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (t.NT_Drive_custom.checked==true) {
|
||||
if (t.NT_client_secret.value==\'\'||t.NT_client_id.value==\'\') {
|
||||
alert(\'client_id & client_secret\');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById("form1").action="?install0&disktag=" + t.disktag_add.value + "&AddDisk=Googledrive";
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
$title = 'Select Account Type';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
protected function get_access_token($refresh_token) {
|
||||
if (!$refresh_token) {
|
||||
$tmp['stat'] = 0;
|
||||
$tmp['body'] = 'No refresh_token';
|
||||
$this->error = $tmp;
|
||||
return false;
|
||||
}
|
||||
if (!($this->access_token = getcache('access_token', $this->disktag))) {
|
||||
$p=0;
|
||||
$data['client_id'] = $this->client_id;
|
||||
$data['client_secret'] = $this->client_secret;
|
||||
$data['grant_type'] = 'refresh_token';
|
||||
//$data['redirect_uri'] = $this->redirect_uri;
|
||||
$data['refresh_token'] = $refresh_token;
|
||||
while ($response['stat']==0&&$p<3) {
|
||||
//$response = curl('POST', 'https://www.googleapis.com/oauth2/v4/token', json_encode($data));
|
||||
$response = curl('POST', $this->oauth_url . 'token', json_encode($data));
|
||||
$p++;
|
||||
}
|
||||
if ($response['stat']==200) $ret = json_decode($response['body'], true);
|
||||
if (!isset($ret['access_token'])) {
|
||||
error_log1($this->oauth_url . 'token' . '?client_id=' . $this->client_id . '&client_secret=' . $this->client_secret . '&grant_type=refresh_token&refresh_token=' . substr($refresh_token, 0, 20) . '******' . substr($refresh_token, -20));
|
||||
error_log1('failed to get [' . $this->disktag . '] access_token. response: ' . $response['body']);
|
||||
$response['body'] = json_encode(json_decode($response['body']), JSON_PRETTY_PRINT);
|
||||
$response['body'] .= '\nfailed to get [' . $this->disktag . '] access_token.';
|
||||
$this->error = $response;
|
||||
return false;
|
||||
//throw new Exception($response['stat'].', failed to get ['.$this->disktag.'] access_token.'.$response['body']);
|
||||
}
|
||||
$tmp = $ret;
|
||||
$tmp['access_token'] = substr($tmp['access_token'], 0, 10) . '******';
|
||||
//$tmp['refresh_token'] = substr($tmp['refresh_token'], 0, 10) . '******';
|
||||
error_log1('[' . $this->disktag . '] Get access token:' . json_encode($tmp, JSON_PRETTY_PRINT));
|
||||
$this->access_token = $ret['access_token'];
|
||||
savecache('access_token', $this->access_token, $this->disktag, $ret['expires_in'] - 300);
|
||||
//if (time()>getConfig('token_expires', $this->disktag)) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+7*24*60*60 ], $this->disktag);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function getDiskSpace() {
|
||||
if ($this->driveId!='root') return '0 / 0';
|
||||
if (!($diskSpace = getcache('diskSpace', $this->disktag))) {
|
||||
$url = $this->api_url . '/about?fields=storageQuota';
|
||||
$response = $this->GDAPI('GET', $url);
|
||||
if ($response['stat']==200) {
|
||||
$res = json_decode($response['body'], true)['storageQuota'];
|
||||
$used = size_format($res['usage']);
|
||||
$total = size_format($res['limit']);
|
||||
$diskSpace = $used . ' / ' . $total;
|
||||
savecache('diskSpace', $diskSpace, $this->disktag);
|
||||
} else return json_encode($response);
|
||||
}
|
||||
return $diskSpace;
|
||||
}
|
||||
|
||||
protected function GDAPI($method, $url, $data = '')
|
||||
{
|
||||
/*if (substr($path,0,7) == 'http://' or substr($path,0,8) == 'https://') {
|
||||
$url = $path;
|
||||
} else {
|
||||
$url = $this->api_url;
|
||||
if ($path=='' or $path=='/') {
|
||||
$url .= '/';
|
||||
} else {
|
||||
$url .= ':' . $path;
|
||||
if (substr($url,-1)=='/') $url=substr($url,0,-1);
|
||||
}
|
||||
if ($method=='PUT') {
|
||||
if ($path=='' or $path=='/') {
|
||||
$url .= 'content';
|
||||
} else {
|
||||
$url .= ':/content';
|
||||
}
|
||||
$headers['Content-Type'] = 'text/plain';
|
||||
} elseif ($method=='PATCH') {
|
||||
$headers['Content-Type'] = 'application/json';
|
||||
} elseif ($method=='POST') {
|
||||
$headers['Content-Type'] = 'application/json';
|
||||
} elseif ($method=='DELETE') {
|
||||
$headers['Content-Type'] = 'application/json';
|
||||
} else {
|
||||
if ($path=='' or $path=='/') {
|
||||
$url .= $method;
|
||||
} else {
|
||||
$url .= ':/' . $method;
|
||||
}
|
||||
$method='POST';
|
||||
$headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
}*/
|
||||
$headers['Authorization'] = 'Bearer ' . $this->access_token;
|
||||
if (!isset($headers['Accept'])) $headers['Accept'] = '*/*';
|
||||
$headers['Content-Type'] = 'application/json';
|
||||
//if (!isset($headers['Referer'])) $headers['Referer'] = $url;*
|
||||
$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, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders);
|
||||
$response['body'] = curl_exec($ch);
|
||||
$response['stat'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
//$response['Location'] = curl_getinfo($ch);
|
||||
curl_close($ch);
|
||||
/*error_log1($response['stat'].'
|
||||
' . $response['body'].'
|
||||
' . $url.'
|
||||
' . $data);*/
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
if (!class_exists('Onedrive')) require 'Onedrive.php';
|
||||
|
||||
class OnedriveCN extends Onedrive {
|
||||
|
||||
function __construct($tag) {
|
||||
$this->disktag = $tag;
|
||||
$this->redirect_uri = 'https://scfonedrive.github.io';
|
||||
if (getConfig('client_id', $tag) && getConfig('client_secret', $tag)) {
|
||||
$this->client_id = getConfig('client_id', $tag);
|
||||
$this->client_secret = getConfig('client_secret', $tag);
|
||||
} else {
|
||||
$this->client_id = '31f3bed5-b9d9-4173-86a4-72c73d278617';
|
||||
$this->client_secret = 'P5-ZNtFK-tT90J.We_-DcsuB8uV7AfjL8Y';
|
||||
}
|
||||
$this->oauth_url = 'https://login.partner.microsoftonline.cn/common/oauth2/v2.0/';
|
||||
$this->api_url = 'https://microsoftgraph.chinacloudapi.cn/v1.0';
|
||||
$this->scope = 'https://microsoftgraph.chinacloudapi.cn/Files.ReadWrite.All https://microsoftgraph.chinacloudapi.cn/Sites.ReadWrite.All offline_access';
|
||||
$res = $this->get_access_token(getConfig('refresh_token', $tag));
|
||||
|
||||
$this->client_secret = urlencode($this->client_secret);
|
||||
$this->scope = urlencode($this->scope);
|
||||
$this->DownurlStrName = '@microsoft.graph.downloadUrl';
|
||||
$this->ext_api_url = '/me/drive/root';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
if (!class_exists('Onedrive')) require 'Onedrive.php';
|
||||
|
||||
class Sharelink extends Onedrive {
|
||||
|
||||
function __construct($tag) {
|
||||
$this->disktag = $tag;
|
||||
$this->redirect_uri = 'https://scfonedrive.github.io';
|
||||
$this->api_url = getConfig('shareapiurl', $tag);
|
||||
$res = $this->get_access_token(1);
|
||||
//$this->ext_api_url = '/me/drive/root';
|
||||
$this->DownurlStrName = '@content.downloadUrl';
|
||||
}
|
||||
|
||||
public function ext_show_innerenv()
|
||||
{
|
||||
return [ 'shareurl' ];
|
||||
}
|
||||
|
||||
protected function get_access_token($refresh_token) {
|
||||
if (!($this->access_token = getcache('access_token', $this->disktag))) {
|
||||
$shareurl = getConfig('shareurl', $this->disktag);
|
||||
if (!($this->sharecookie = getcache('sharecookie', $this->disktag))) {
|
||||
$res = curl('GET', $shareurl, '', [], 1);
|
||||
error_log1(json_encode($res, JSON_PRETTY_PRINT));
|
||||
if (isset($res['returnhead']['Set-Cookie'])) $this->sharecookie = $res['returnhead']['Set-Cookie'];
|
||||
if (isset($res['returnhead']['set-cookie'])) $this->sharecookie = $res['returnhead']['set-cookie'];
|
||||
if ($this->sharecookie=='') {
|
||||
$this->error = $res;
|
||||
return false;
|
||||
}
|
||||
savecache('sharecookie', $this->sharecookie, $this->disktag);
|
||||
}
|
||||
$tmp1 = splitlast($shareurl, '/')[0];
|
||||
$account = splitlast($tmp1, '/')[1];
|
||||
$domain = splitlast($shareurl, '/:')[0];
|
||||
$response = curl('POST',
|
||||
$domain . "/personal/" . $account . "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" . urlencode("/personal/" . $account . "/Documents") . "'&RootFolder=" . urlencode("/personal/" . $account . "/Documents/") . "&TryNewExperienceSingle=TRUE",
|
||||
'{"parameters":{"__metadata":{"type":"SP.RenderListDataParameters"},"RenderOptions":136967,"AllowMultipleValueFilterForTaxonomyFields":true,"AddRequiredFields":true}}',
|
||||
[ 'Accept' => 'application/json;odata=verbose', 'Content-Type' => 'application/json;odata=verbose', 'origin' => $domain, 'Cookie' => $this->sharecookie ]
|
||||
);
|
||||
if ($response['stat']==200) $ret = json_decode($response['body'], true);
|
||||
$this->access_token = splitlast($ret['ListSchema']['.driveAccessToken'],'=')[1];
|
||||
$this->api_url = $ret['ListSchema']['.driveUrl'].'/root';
|
||||
if (!$this->access_token) {
|
||||
error_log1($domain . "/personal/" . $account . "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" . urlencode("/personal/" . $account . "/Documents") . "'&RootFolder=" . urlencode("/personal/" . $account . "/Documents/") . "&TryNewExperienceSingle=TRUE");
|
||||
error_log1('failed to get share access_token. response' . json_encode($ret));
|
||||
//$response['body'] = json_encode(json_decode($response['body']), JSON_PRETTY_PRINT);
|
||||
$response['body'] .= '<br>' .json_decode($response['body'], true)['error']['message']['value'];
|
||||
$response['body'] .= '<br>failed to get shareurl access_token.';
|
||||
$this->error = $response;
|
||||
return false;
|
||||
//throw new Exception($response['stat'].', failed to get share access_token.'.$response['body']);
|
||||
}
|
||||
//$tmp = $ret;
|
||||
//$tmp['access_token'] = '******';
|
||||
//error_log1('['.$this->disktag.'] Get access token:'.json_encode($tmp, JSON_PRETTY_PRINT));
|
||||
savecache('access_token', $this->access_token, $this->disktag);
|
||||
$tmp1 = null;
|
||||
if (getConfig('shareapiurl', $this->disktag)!=$this->api_url) $tmp1['shareapiurl'] = $this->api_url;
|
||||
//if (getConfig('sharecookie', $this->disktag)!=$this->sharecookie) $tmp1['sharecookie'] = $this->sharecookie;
|
||||
if (!!$tmp1) setConfig($tmp1, $this->disktag);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
if (!class_exists('Onedrive')) require 'Onedrive.php';
|
||||
|
||||
class Sharepoint extends Onedrive {
|
||||
|
||||
function __construct($tag) {
|
||||
$this->disktag = $tag;
|
||||
$this->redirect_uri = 'https://scfonedrive.github.io';
|
||||
if (getConfig('client_id', $tag) && getConfig('client_secret', $tag)) {
|
||||
$this->client_id = getConfig('client_id', $tag);
|
||||
$this->client_secret = getConfig('client_secret', $tag);
|
||||
} else {
|
||||
$this->client_id = '734ef928-d74c-4555-8d1b-d942fa0a1a41';
|
||||
$this->client_secret = '_I5gOpmG5vTC2Ts_K._wCW4nN1km~4Pk52';
|
||||
}
|
||||
$this->oauth_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/';
|
||||
$this->api_url = 'https://graph.microsoft.com/v1.0';
|
||||
$this->scope = 'https://graph.microsoft.com/Files.ReadWrite.All https://graph.microsoft.com/Sites.ReadWrite.All offline_access';
|
||||
$res = $this->get_access_token(getConfig('refresh_token', $tag));
|
||||
|
||||
$this->client_secret = urlencode($this->client_secret);
|
||||
$this->scope = urlencode($this->scope);
|
||||
$this->DownurlStrName = '@microsoft.graph.downloadUrl';
|
||||
$this->ext_api_url = '/sites/' . getConfig('siteid', $tag) . '/drive/root';
|
||||
}
|
||||
|
||||
public function ext_show_innerenv()
|
||||
{
|
||||
return [ 'sharepointSite', 'siteid' ];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
if (!class_exists('Onedrive')) require 'Onedrive.php';
|
||||
|
||||
class SharepointCN extends Onedrive {
|
||||
|
||||
function __construct($tag) {
|
||||
$this->disktag = $tag;
|
||||
$this->redirect_uri = 'https://scfonedrive.github.io';
|
||||
if (getConfig('client_id', $tag) && getConfig('client_secret', $tag)) {
|
||||
$this->client_id = getConfig('client_id', $tag);
|
||||
$this->client_secret = getConfig('client_secret', $tag);
|
||||
} else {
|
||||
$this->client_id = '31f3bed5-b9d9-4173-86a4-72c73d278617';
|
||||
$this->client_secret = 'P5-ZNtFK-tT90J.We_-DcsuB8uV7AfjL8Y';
|
||||
}
|
||||
$this->oauth_url = 'https://login.partner.microsoftonline.cn/common/oauth2/v2.0/';
|
||||
$this->api_url = 'https://microsoftgraph.chinacloudapi.cn/v1.0';
|
||||
$this->scope = 'https://microsoftgraph.chinacloudapi.cn/Files.ReadWrite.All https://microsoftgraph.chinacloudapi.cn/Sites.ReadWrite.All offline_access';
|
||||
$res = $this->get_access_token(getConfig('refresh_token', $tag));
|
||||
|
||||
$this->client_secret = urlencode($this->client_secret);
|
||||
$this->scope = urlencode($this->scope);
|
||||
$this->DownurlStrName = '@microsoft.graph.downloadUrl';
|
||||
$this->ext_api_url = '/sites/' . getConfig('siteid', $tag) . '/drive/root';
|
||||
}
|
||||
|
||||
public function ext_show_innerenv()
|
||||
{
|
||||
return [ 'sharepointSite', 'siteid' ];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"start": "php -S 0.0.0.0:8080 index.php"
|
||||
}
|
137
index.php
137
index.php
|
@ -1,13 +1,26 @@
|
|||
<?php
|
||||
//error_reporting(E_ALL & ~E_NOTICE);
|
||||
error_reporting(0);
|
||||
include 'vendor/autoload.php';
|
||||
include 'conststr.php';
|
||||
include 'common.php';
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
//echo '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
|
||||
//echo '<pre>'. json_encode($_ENV, JSON_PRETTY_PRINT).'</pre>';
|
||||
if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
|
||||
include 'platform/scf.php';
|
||||
if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/TencentSCF_file.php';
|
||||
else include 'platform/TencentSCF_env.php';
|
||||
} elseif (isset($_SERVER['FC_FUNC_CODE_PATH'])) {
|
||||
include 'platform/AliyunFC.php';
|
||||
} elseif (isset($_SERVER['_APP_SHARE_DIR']) && $_SERVER['_APP_SHARE_DIR']=='/var/share/CFF/processrouter') {
|
||||
//if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/HuaweiFG_file.php';
|
||||
//else include 'platform/HuaweiFG_env.php';
|
||||
echo 'FG' . PHP_EOL;
|
||||
} elseif (isset($_SERVER['BCE_CFC_RUNTIME_NAME']) && $_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') {
|
||||
include 'platform/BaiduCFC.php';
|
||||
} elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') {
|
||||
include 'platform/heroku.php';
|
||||
include 'platform/Heroku.php';
|
||||
$path = getpath();
|
||||
//echo 'path:'. $path;
|
||||
$_GET = getGET();
|
||||
|
@ -18,9 +31,26 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
|
|||
header($headerName . ': ' . $headerVal, true);
|
||||
}
|
||||
http_response_code($re['statusCode']);
|
||||
echo $re['body'];
|
||||
} else {
|
||||
include 'platform/normal.php';
|
||||
if ($re['isBase64Encoded']) echo base64_decode($re['body']);
|
||||
else echo $re['body'];
|
||||
} elseif (isset($_SERVER['DOCUMENT_ROOT'])&&$_SERVER['DOCUMENT_ROOT']==='/var/task/user') {
|
||||
if (getenv('ONEMANAGER_CONFIG_SAVE')=='env') include 'platform/Vercel_env.php';
|
||||
else include 'platform/Vercel.php';
|
||||
$path = getpath();
|
||||
//echo 'path:'. $path;
|
||||
$_GET = getGET();
|
||||
//echo '<pre>'. json_encode($_GET, JSON_PRETTY_PRINT).'</pre>';
|
||||
$re = main($path);
|
||||
$sendHeaders = array();
|
||||
foreach ($re['headers'] as $headerName => $headerVal) {
|
||||
header($headerName . ': ' . $headerVal, true);
|
||||
}
|
||||
http_response_code($re['statusCode']);
|
||||
if ($re['isBase64Encoded']) echo base64_decode($re['body']);
|
||||
else echo $re['body'];
|
||||
} elseif (isset($_SERVER['DOCUMENT_ROOT'])&&substr($_SERVER['DOCUMENT_ROOT'], 0, 13)==='/home/runner/') {
|
||||
include 'platform/Replit.php';
|
||||
|
||||
$path = getpath();
|
||||
//echo 'path:'. $path;
|
||||
$_GET = getGET();
|
||||
|
@ -32,14 +62,36 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
|
|||
header($headerName . ': ' . $headerVal, true);
|
||||
}
|
||||
http_response_code($re['statusCode']);
|
||||
echo $re['body'];
|
||||
if ($re['isBase64Encoded']) echo base64_decode($re['body']);
|
||||
else echo $re['body'];
|
||||
} else {
|
||||
include 'platform/Normal.php';
|
||||
if (!function_exists('curl_init')) {
|
||||
return message('<font color="red">Need curl</font>, please install php-curl.', 'Error', 500);
|
||||
}
|
||||
$path = getpath();
|
||||
//echo 'path:'. $path;
|
||||
$_GET = getGET();
|
||||
//echo '<pre>'. json_encode($_GET, JSON_PRETTY_PRINT).'</pre>';
|
||||
$re = main($path);
|
||||
$sendHeaders = array();
|
||||
foreach ($re['headers'] as $headerName => $headerVal) {
|
||||
header($headerName . ': ' . $headerVal, true);
|
||||
}
|
||||
http_response_code($re['statusCode']);
|
||||
if ($re['isBase64Encoded']) echo base64_decode($re['body']);
|
||||
else echo $re['body'];
|
||||
}
|
||||
|
||||
// Tencent SCF
|
||||
function main_handler($event, $context)
|
||||
{
|
||||
$event = json_decode(json_encode($event), true);
|
||||
$context = json_decode(json_encode($context), true);
|
||||
printInput($event, $context);
|
||||
if ( $event['requestContext']['serviceId'] === substr($event['headers']['host'], 0, strlen($event['requestContext']['serviceId'])) ) {
|
||||
if ($event['path']==='/' . $context['function_name']) return output('add / at last.', 308, ['Location'=>'/'.$event['requestContext']['stage'].'/'.$context['function_name'].'/']);
|
||||
}
|
||||
unset($_POST);
|
||||
unset($_GET);
|
||||
unset($_COOKIE);
|
||||
|
@ -50,3 +102,76 @@ function main_handler($event, $context)
|
|||
|
||||
return main($path);
|
||||
}
|
||||
|
||||
// Aliyun FC & Huawei FG & Baidu CFC
|
||||
function handler($event, $context)
|
||||
{
|
||||
if (isset($_SERVER['FC_FUNC_CODE_PATH'])) {
|
||||
// Aliyun FC
|
||||
set_error_handler("myErrorHandler");
|
||||
$tmp = array(
|
||||
'method' => $event->getMethod(),
|
||||
'clientIP' => $event->getAttribute("clientIP"),
|
||||
'requestURI' => $event->getAttribute("requestURI"),
|
||||
'path' => spurlencode($event->getAttribute("path"), '/'),
|
||||
'queryString' => $event->getQueryParams(),
|
||||
'headers' => $event->getHeaders(),
|
||||
'body' => $event->getBody()->getContents(),
|
||||
);
|
||||
$event = $tmp;
|
||||
$context = json_decode(json_encode($context), true);
|
||||
printInput($event, $context);
|
||||
unset($_POST);
|
||||
unset($_GET);
|
||||
unset($_COOKIE);
|
||||
unset($_SERVER);
|
||||
GetGlobalVariable($event);
|
||||
$path = GetPathSetting($event, $context);
|
||||
|
||||
$re = main($path);
|
||||
|
||||
return new RingCentral\Psr7\Response($re['statusCode'], $re['headers'], ($re['isBase64Encoded']?base64_decode($re['body']):$re['body']));
|
||||
|
||||
} elseif ($_SERVER['_APP_SHARE_DIR']=='/var/share/CFF/processrouter') {
|
||||
// Huawei FG
|
||||
global $contextUserData;
|
||||
$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);
|
||||
if ($event['isBase64Encoded']) $event['body'] = base64_decode($event['body']);
|
||||
|
||||
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 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);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,552 @@
|
|||
<?php
|
||||
// https://help.aliyun.com/document_detail/53252.html
|
||||
// https://github.com/aliyun/fc-php-sdk/blob/master/src/AliyunFC/Client.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['queryString'];
|
||||
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'][0]);
|
||||
foreach ($cookiebody as $cookievalues) {
|
||||
$pos = strpos($cookievalues,"=");
|
||||
$_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1));
|
||||
}
|
||||
}
|
||||
|
||||
function GetPathSetting($event, $context)
|
||||
{
|
||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($event['headers']['Accept-Language'][0],';')[0],',')[0]);
|
||||
$_SERVER['accountId'] = $context['accountId'];
|
||||
$_SERVER['region'] = $context['region'];
|
||||
$_SERVER['service_name'] = $context['service']['name'];
|
||||
$_SERVER['function_name'] = $context['function']['name'];
|
||||
//$path = str_replace('%5D', ']', str_replace('%5B', '[', $event['path']));//%5B
|
||||
//$path = $event['path'];
|
||||
$path = $event['requestURI'];
|
||||
if (strpos($path, '?')) $path = substr($path, 0, strpos($path, '?'));
|
||||
$tmp = urldecode($event['requestURI']);
|
||||
if (strpos($tmp, '?')) $tmp = substr($tmp, 0, strpos($tmp, '?'));
|
||||
if ($path=='/'||$path=='') {
|
||||
$_SERVER['base_path'] = $tmp;
|
||||
} else {
|
||||
$tmp = str_replace('&', '&', $tmp);
|
||||
while ($tmp!=urldecode($tmp)) $tmp = urldecode($tmp);
|
||||
$tmp1 = urldecode($event['path']);
|
||||
while ($tmp1!=urldecode($tmp1)) $tmp1 = urldecode($tmp1);
|
||||
$_SERVER['base_path'] = substr($tmp, 0, strlen($tmp)-strlen($tmp1)+1);
|
||||
//$_SERVER['base_path'] = substr($tmp, 0, strlen(urldecode($event['path'])));
|
||||
}
|
||||
$_SERVER['base_path'] = spurlencode($_SERVER['base_path'], '/');
|
||||
//$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
|
||||
$_SERVER['REMOTE_ADDR'] = $event['clientIP'];
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = $event['headers']['X-Requested-With'][0];
|
||||
if (isset($event['headers']['Authorization'])) {
|
||||
$basicAuth = splitfirst(base64_decode(splitfirst($event['headers']['Authorization'][0], 'Basic ')[1]), ':');
|
||||
$_SERVER['PHP_AUTH_USER'] = $basicAuth[0];
|
||||
$_SERVER['PHP_AUTH_PW'] = $basicAuth[1];
|
||||
}
|
||||
$_SERVER['HTTP_HOST'] = $event['headers']['Host'][0];
|
||||
$_SERVER['REQUEST_SCHEME'] = $event['headers']['X-Forwarded-Proto'][0];
|
||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['referhost'] = explode('/', $event['headers']['Referer'][0])[2];
|
||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['If-Modified-Since'][0];
|
||||
$_SERVER['FC_FUNC_CODE_PATH'] = getenv('FC_FUNC_CODE_PATH');
|
||||
$_SERVER['REQUEST_METHOD'] = $event['method'];
|
||||
return $path;
|
||||
//return spurlencode($path, '/');
|
||||
}
|
||||
|
||||
function getConfig($str, $disktag = '')
|
||||
{
|
||||
if (isInnerEnv($str)) {
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$env = json_decode(getenv($disktag), true);
|
||||
if (isset($env[$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($env[$str]);
|
||||
else return $env[$str];
|
||||
}
|
||||
} else {
|
||||
if (isBase64Env($str)) return base64y_decode(getenv($str));
|
||||
else return getenv($str);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function setConfig($arr, $disktag = '')
|
||||
{
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$disktags = explode("|", getConfig('disktag'));
|
||||
$diskconfig = json_decode(getenv($disktag), true);
|
||||
$tmp = [];
|
||||
$indisk = 0;
|
||||
$operatedisk = 0;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (isCommonEnv($k)) {
|
||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
||||
else $tmp[$k] = $v;
|
||||
} elseif (isInnerEnv($k)) {
|
||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
||||
else $diskconfig[$k] = $v;
|
||||
$indisk = 1;
|
||||
} elseif ($k=='disktag_add') {
|
||||
array_push($disktags, $v);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_del') {
|
||||
$disktags = array_diff($disktags, [ $v ]);
|
||||
$tmp[$v] = '';
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_copy') {
|
||||
$newtag = $v . '_' . date("Ymd_His");
|
||||
$tmp[$newtag] = getConfig($v);
|
||||
array_push($disktags, $newtag);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
||||
} else {
|
||||
$tmp[$k] = json_encode($v);
|
||||
}
|
||||
}
|
||||
if ($indisk) {
|
||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||
ksort($diskconfig);
|
||||
$tmp[$disktag] = json_encode($diskconfig);
|
||||
}
|
||||
if ($operatedisk) {
|
||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
||||
$tags = [];
|
||||
foreach ($disktags as $tag) {
|
||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
||||
else array_push($tags, $tag);
|
||||
}
|
||||
$tmp['disktag'] = implode('|', $tags);
|
||||
$tmp[$arr['disktag_newname']] = getConfig($arr['disktag_rename']);
|
||||
$tmp[$arr['disktag_rename']] = '';
|
||||
} else {
|
||||
$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, $_SERVER['accountId'], $_SERVER['region'], $_SERVER['service_name'], $_SERVER['function_name'], getConfig('AccessKeyID'), getConfig('AccessKeySecret'));
|
||||
//WaitSCFStat();
|
||||
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']) {
|
||||
//if ($_POST['admin']!='') {
|
||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
||||
//$AccessKeyID = getConfig('AccessKeyID');
|
||||
//if ($AccessKeyID=='') {
|
||||
$AccessKeyID = $_POST['AccessKeyID'];
|
||||
$tmp['AccessKeyID'] = $AccessKeyID;
|
||||
//}
|
||||
//$AccessKeySecret = getConfig('AccessKeySecret');
|
||||
//if ($AccessKeySecret=='') {
|
||||
$AccessKeySecret = $_POST['AccessKeySecret'];
|
||||
$tmp['AccessKeySecret'] = $AccessKeySecret;
|
||||
//}
|
||||
$response = setConfigResponse( SetbaseConfig($tmp, $_SERVER['accountId'], $_SERVER['region'], $_SERVER['service_name'], $_SERVER['function_name'], $AccessKeyID, $AccessKeySecret) );
|
||||
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('AccessKeyID')==''||getConfig('AccessKeySecret')=='')
|
||||
$html .= '
|
||||
<a href="https://usercenter.console.aliyun.com/?#/manage/ak" target="_blank">' . getconstStr('Create') . ' AccessKeyID & AccessKeySecret</a><br>
|
||||
<label>AccessKeyID:<input name="AccessKeyID" type="text" placeholder="" size=""></label><br>
|
||||
<label>AccessKeySecret:<input name="AccessKeySecret" type="password" 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('AccessKeyID')==''||getConfig('AccessKeySecret')=='')
|
||||
$html .= '
|
||||
if (t.AccessKeyID.value==\'\') {
|
||||
alert(\'input AccessKeyID\');
|
||||
return false;
|
||||
}
|
||||
if (t.AccessKeySecret.value==\'\') {
|
||||
alert(\'input SecretKey\');
|
||||
return false;
|
||||
}';
|
||||
$html .= '
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
$title = getconstStr('SelectLanguage');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
$html .= '<a href="?install0">' . getconstStr('ClickInstall').'</a>, ' . getconstStr('LogintoBind');
|
||||
$title = 'Install';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
function FCAPI2016($config, $Method, $data = '')
|
||||
{
|
||||
$accountId = $config['accountId'];
|
||||
$region = $config['region'];
|
||||
$service_name = $config['service_name'];
|
||||
$function_name = $config['function_name'];
|
||||
$AccessKeyID = $config['AccessKeyID'];
|
||||
$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)
|
||||
{
|
||||
//print_r($Envs);
|
||||
$config['accountId'] = $accountId;
|
||||
$config['region'] = $region;
|
||||
$config['service_name'] = $service_name;
|
||||
$config['function_name'] = $function_name;
|
||||
$config['AccessKeyID'] = $AccessKeyID;
|
||||
$config['AccessKeySecret'] = $AccessKeySecret;
|
||||
|
||||
$tmp = json_decode(getfunctioninfo($config), true);
|
||||
foreach ($tmp['environmentVariables'] as $key => $value ) {
|
||||
$tmp_env[$key] = $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);
|
||||
sortConfig($tmp_env);
|
||||
|
||||
$tmpdata['environmentVariables'] = $tmp_env;
|
||||
return FCAPI2016($config, 'PUT', json_encode($tmpdata));
|
||||
}
|
||||
|
||||
function SetbaseConfig($Envs, $accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret)
|
||||
{
|
||||
$config['accountId'] = $accountId;
|
||||
$config['region'] = $region;
|
||||
$config['service_name'] = $service_name;
|
||||
$config['function_name'] = $function_name;
|
||||
$config['AccessKeyID'] = $AccessKeyID;
|
||||
$config['AccessKeySecret'] = $AccessKeySecret;
|
||||
|
||||
$tmp = json_decode(getfunctioninfo($config), true);
|
||||
foreach ($tmp['environmentVariables'] as $key => $value ) {
|
||||
$tmp_env[$key] = $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);
|
||||
|
||||
$tmpdata['description'] = 'Onedrive index and manager in Aliyun FC.';
|
||||
$tmpdata['memorySize'] = 128;
|
||||
$tmpdata['timeout'] = 30;
|
||||
$tmpdata['environmentVariables'] = $tmp_env;
|
||||
|
||||
return FCAPI2016($config, 'PUT', json_encode($tmpdata));
|
||||
}
|
||||
|
||||
function updateProgram($accountId, $region, $service_name, $function_name, $AccessKeyID, $AccessKeySecret, $source)
|
||||
{
|
||||
$config['accountId'] = $accountId;
|
||||
$config['region'] = $region;
|
||||
$config['service_name'] = $service_name;
|
||||
$config['function_name'] = $function_name;
|
||||
$config['AccessKeyID'] = $AccessKeyID;
|
||||
$config['AccessKeySecret'] = $AccessKeySecret;
|
||||
|
||||
$tmp = json_decode(getfunctioninfo($config), true);
|
||||
|
||||
$tmpdata['code']['zipFile'] = base64_encode( file_get_contents($source) );
|
||||
|
||||
return FCAPI2016($config, 'PUT', json_encode($tmpdata));
|
||||
}
|
||||
|
||||
function api_error($response)
|
||||
{
|
||||
return isset($response['ErrorMessage']);
|
||||
}
|
||||
|
||||
function api_error_msg($response)
|
||||
{
|
||||
return $response['ErrorCode'] . '<br>
|
||||
' . $response['ErrorMessage'] . '<br><br>
|
||||
|
||||
accountId:' . $_SERVER['accountId'] . '<br>
|
||||
region:' . $_SERVER['region'] . '<br>
|
||||
service_name:' . $_SERVER['service_name'] . '<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($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||
{
|
||||
$source = '/tmp/code.zip';
|
||||
$outPath = '/tmp/';
|
||||
|
||||
if ($GitSource=='Github') {
|
||||
// 从github下载对应tar.gz,并解压
|
||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||
} elseif ($GitSource=='HITGitlab') {
|
||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
||||
} else return json_encode(['ErrorMessage'=>'Git Source input Error!']);
|
||||
$tarfile = '/tmp/github.tar.gz';
|
||||
file_put_contents($tarfile, file_get_contents($url));
|
||||
$phar = new PharData($tarfile);
|
||||
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
||||
|
||||
// 获取解压出的目录名
|
||||
$outPath = findIndexPath($outPath);
|
||||
|
||||
// 将目录中文件打包成zip
|
||||
$zip = new ZipArchive();
|
||||
if($zip->open($source, ZipArchive::CREATE)){
|
||||
addFileToZip($zip, $outPath); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
|
||||
$zip->close(); //关闭处理的zip文件
|
||||
}
|
||||
|
||||
return updateProgram($_SERVER['accountId'], $_SERVER['region'], $_SERVER['service_name'], $_SERVER['function_name'], getConfig('AccessKeyID'), getConfig('AccessKeySecret'), $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)){// 如果读取的某个对象是文件夹,则递归
|
||||
addFileToZip($zip, $rootpath, $path."/".$filename);
|
||||
}else{ //将文件加入zip对象
|
||||
$zip->addFile($nowname);
|
||||
$newname = $path."/".$filename;
|
||||
if (substr($newname,0,1)=='/') $newname = substr($newname, 1);
|
||||
$zip->renameName($nowname, $newname);
|
||||
}
|
||||
}
|
||||
}
|
||||
@closedir($handler);
|
||||
}
|
||||
|
||||
function myErrorHandler($errno, $errstr, $errfile, $errline) {
|
||||
if (!(error_reporting() & $errno)) {
|
||||
return false;
|
||||
}
|
||||
switch ($errno) {
|
||||
case E_USER_ERROR:
|
||||
$errInfo = array(
|
||||
"errorMessage" => $errstr,
|
||||
"errorType" => \ServerlessFC\friendly_error_type($errno),
|
||||
"stackTrace" => array(
|
||||
"file" => $errfile,
|
||||
"line" => $errline,
|
||||
),
|
||||
);
|
||||
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
|
||||
break;
|
||||
default: // E_USER_WARNING | E_USER_NOTICE
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function WaitFunction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function changeAuthKey() {
|
||||
if ($_POST['AccessKeyID']!=''&&$_POST['AccessKeySecret']!='') {
|
||||
$tmp['AccessKeyID'] = $_POST['AccessKeyID'];
|
||||
$tmp['AccessKeySecret'] = $_POST['AccessKeySecret'];
|
||||
$response = setConfigResponse( SetbaseConfig($tmp, $_SERVER['accountId'], $_SERVER['region'], $_SERVER['service_name'], $_SERVER['function_name'], $tmp['AccessKeyID'], $tmp['AccessKeySecret']) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 400);
|
||||
} else {
|
||||
$html = getconstStr('Success') . '
|
||||
<script>
|
||||
var i = 0;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
}
|
||||
$html = '
|
||||
<form action="" method="post" onsubmit="return notnull(this);">
|
||||
<a href="https://usercenter.console.aliyun.com/?#/manage/ak" target="_blank">' . getconstStr('Create') . ' AccessKeyID & AccessKeySecret</a><br>
|
||||
<label>AccessKeyID:<input name="AccessKeyID" type="text" placeholder="" size=""></label><br>
|
||||
<label>AccessKeySecret:<input name="AccessKeySecret" type="password" placeholder="" size=""></label><br>
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
</form>
|
||||
<script>
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.AccessKeyID.value==\'\') {
|
||||
alert(\'input AccessKeyID\');
|
||||
return false;
|
||||
}
|
||||
if (t.AccessKeySecret.value==\'\') {
|
||||
alert(\'input SecretKey\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
return message($html, 'Change platform Auth token or key', 200);
|
||||
}
|
||||
|
||||
function smallfileupload($drive, $path) {
|
||||
return output('Can not upload through FC.', 400);
|
||||
}
|
|
@ -0,0 +1,491 @@
|
|||
<?php
|
||||
// https://cloud.baidu.com/doc/CFC/s/jjwvz45ex
|
||||
// https://cloud.baidu.com/doc/CFC/s/2jwvz44ns
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
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'];
|
||||
//$_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'];
|
||||
$_SERVER['HTTP_USER_AGENT'] = $event['headers']['User-Agent'];
|
||||
if (isset($event['headers']['authorization'])) {
|
||||
$basicAuth = splitfirst(base64_decode(splitfirst($event['headers']['authorization'], 'Basic ')[1]), ':');
|
||||
$_SERVER['PHP_AUTH_USER'] = $basicAuth[0];
|
||||
$_SERVER['PHP_AUTH_PW'] = $basicAuth[1];
|
||||
}
|
||||
$_SERVER['HTTP_HOST'] = $event['headers']['Host'];
|
||||
$_SERVER['REQUEST_SCHEME'] = $event['headers']['X-Forwarded-Proto'];
|
||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['referhost'] = explode('/', $event['headers']['Referer'])[2];
|
||||
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
|
||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['If-Modified-Since'];
|
||||
$_SERVER['REQUEST_METHOD'] = $event['httpMethod'];
|
||||
$_SERVER['BCE_CFC_RUNTIME_NAME'] = 'php7';
|
||||
return $path;
|
||||
}
|
||||
|
||||
function getConfig($str, $disktag = '')
|
||||
{
|
||||
if (isInnerEnv($str)) {
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$env = json_decode(getenv($disktag), true);
|
||||
if (isset($env[$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($env[$str]);
|
||||
else return $env[$str];
|
||||
}
|
||||
} else {
|
||||
if (isBase64Env($str)) return base64y_decode(getenv($str));
|
||||
else return getenv($str);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function setConfig($arr, $disktag = '')
|
||||
{
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$disktags = explode("|",getConfig('disktag'));
|
||||
$diskconfig = json_decode(getenv($disktag), true);
|
||||
$tmp = [];
|
||||
$indisk = 0;
|
||||
$operatedisk = 0;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (isCommonEnv($k)) {
|
||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
||||
else $tmp[$k] = $v;
|
||||
} elseif (isInnerEnv($k)) {
|
||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
||||
else $diskconfig[$k] = $v;
|
||||
$indisk = 1;
|
||||
} elseif ($k=='disktag_add') {
|
||||
array_push($disktags, $v);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_del') {
|
||||
$disktags = array_diff($disktags, [ $v ]);
|
||||
$tmp[$v] = '';
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_copy') {
|
||||
$newtag = $v . '_' . date("Ymd_His");
|
||||
$tmp[$newtag] = getConfig($v);
|
||||
array_push($disktags, $newtag);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
||||
} else {
|
||||
$tmp[$k] = json_encode($v);
|
||||
}
|
||||
}
|
||||
if ($indisk) {
|
||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||
ksort($diskconfig);
|
||||
$tmp[$disktag] = json_encode($diskconfig);
|
||||
}
|
||||
if ($operatedisk) {
|
||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
||||
$tags = [];
|
||||
foreach ($disktags as $tag) {
|
||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
||||
else array_push($tags, $tag);
|
||||
}
|
||||
$tmp['disktag'] = implode('|', $tags);
|
||||
$tmp[$arr['disktag_newname']] = getConfig($arr['disktag_rename']);
|
||||
$tmp[$arr['disktag_rename']] = '';
|
||||
} else {
|
||||
$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="password" 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 = 'Install';
|
||||
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);
|
||||
sortConfig($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 = json_encode($response, JSON_PRETTY_PRINT);
|
||||
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($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||
{
|
||||
$source = '/tmp/code.zip';
|
||||
$outPath = '/tmp/';
|
||||
|
||||
if ($GitSource=='Github') {
|
||||
// 从github下载对应tar.gz,并解压
|
||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||
} elseif ($GitSource=='HITGitlab') {
|
||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
||||
} else return json_encode(['FunctionBrn'=>$_SERVER['functionBrn'], 'code'=>'Git Source input Error!']);
|
||||
$tarfile = '/tmp/github.tar.gz';
|
||||
file_put_contents($tarfile, file_get_contents($url));
|
||||
$phar = new PharData($tarfile);
|
||||
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
||||
|
||||
// 获取解压出的目录名
|
||||
$outPath = findIndexPath($outPath);
|
||||
|
||||
// 将目录中文件打包成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($handler);
|
||||
}
|
||||
|
||||
function WaitFunction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function changeAuthKey() {
|
||||
if ($_POST['SecretId']!=''&&$_POST['SecretKey']!='') {
|
||||
$SecretId = $_POST['SecretId'];
|
||||
$tmp['SecretId'] = $SecretId;
|
||||
$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, 400);
|
||||
} else {
|
||||
$html = getconstStr('Success') . '
|
||||
<script>
|
||||
var i = 0;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
}
|
||||
$html = '
|
||||
<form action="" method="post" onsubmit="return notnull(this);">
|
||||
<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="password" placeholder="" size=""></label><br>
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
</form>
|
||||
<script>
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.SecretId.value==\'\') {
|
||||
alert(\'input Access Key\');
|
||||
return false;
|
||||
}
|
||||
if (t.SecretKey.value==\'\') {
|
||||
alert(\'input Secret Key\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
return message($html, 'Change platform Auth token or key', 200);
|
||||
}
|
||||
|
||||
function smallfileupload($drive, $path) {
|
||||
return output('Can not upload through CFC.', 400);
|
||||
}
|
|
@ -0,0 +1,423 @@
|
|||
<?php
|
||||
// https://devcenter.heroku.com/articles/platform-api-reference#build-create
|
||||
|
||||
function getpath()
|
||||
{
|
||||
if (getConfig('function_name') && getConfig('APIKey')) {
|
||||
$APIKey = getConfig('APIKey');
|
||||
$res = HerokuAPI('GET', 'https://api.heroku.com/apps/' . getConfig('function_name'), '', $APIKey);
|
||||
$response = json_decode($res['body'], true);
|
||||
if (isset($response['build_stack'])) {
|
||||
$tmp['HerokuappId'] = $response['id'];
|
||||
$tmp['function_name'] = null;
|
||||
} else {
|
||||
error_log1('Something error' . 'Get Heroku app id: ' . json_encode($res, JSON_PRETTY_PRINT));
|
||||
//return message('Get Heroku app id: ' . json_encode($res, JSON_PRETTY_PRINT), 'Something error', 500);
|
||||
}
|
||||
$response = json_decode(setHerokuConfig($tmp, $tmp['HerokuappId'], $APIKey)['body'], true);
|
||||
$title = 'Change function_name to HerokuappId';
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$stat = 500;
|
||||
error_log1('Change function_name to HerokuappId' . $html);
|
||||
} else {
|
||||
$html = getconstStr('Wait') . ' 5s, jump to index.
|
||||
<meta http-equiv="refresh" content="5;URL=/">';
|
||||
$stat = 201;
|
||||
}
|
||||
//return message($html, $title, $stat);
|
||||
}
|
||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($_SERVER['HTTP_ACCEPT_LANGUAGE'],';')[0],',')[0]);
|
||||
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
$_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_X_FORWARDED_PROTO'];
|
||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['referhost'] = explode('/', $_SERVER['HTTP_REFERER'])[2];
|
||||
$_SERVER['base_path'] = path_format(substr($_SERVER['SCRIPT_NAME'], 0, -10) . '/');
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
||||
else $path = $_SERVER['REQUEST_URI'];
|
||||
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
||||
return substr($path, 1);
|
||||
//return spurlencode($path, '/');
|
||||
}
|
||||
|
||||
function getGET()
|
||||
{
|
||||
//error_log1('POST:' . json_encode($_POST));
|
||||
if (!$_POST) {
|
||||
if (!!$HTTP_RAW_POST_DATA) {
|
||||
$tmpdata = $HTTP_RAW_POST_DATA;
|
||||
//error_log1('RAW:' . $tmpdata);
|
||||
} else {
|
||||
$tmpdata = file_get_contents('php://input');
|
||||
//error_log1('PHPINPUT:' . $tmpdata);
|
||||
}
|
||||
if (!!$tmpdata) {
|
||||
$postbody = explode("&", $tmpdata);
|
||||
foreach ($postbody as $postvalues) {
|
||||
$pos = strpos($postvalues,"=");
|
||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
||||
}
|
||||
//error_log1('POSTformPHPINPUT:' . json_encode($_POST));
|
||||
}
|
||||
}
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) {
|
||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
||||
$getstrarr = explode("&",$getstr);
|
||||
foreach ($getstrarr as $getvalues) {
|
||||
if ($getvalues != '') {
|
||||
$pos = strpos($getvalues, "=");
|
||||
//echo $pos;
|
||||
if ($pos > 0) {
|
||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
||||
} else {
|
||||
$getarry[urldecode($getvalues)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($getarry)) {
|
||||
return $getarry;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function getConfig($str, $disktag = '')
|
||||
{
|
||||
if (isInnerEnv($str)) {
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$env = json_decode(getenv($disktag), true);
|
||||
if (isset($env[$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($env[$str]);
|
||||
else return $env[$str];
|
||||
}
|
||||
} else {
|
||||
if (isBase64Env($str)) return base64y_decode(getenv($str));
|
||||
else return getenv($str);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function setConfig($arr, $disktag = '')
|
||||
{
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$disktags = explode("|",getConfig('disktag'));
|
||||
if ($disktag!='') $diskconfig = json_decode(getenv($disktag), true);
|
||||
$tmp = [];
|
||||
$indisk = 0;
|
||||
$operatedisk = 0;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (isCommonEnv($k)) {
|
||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
||||
else $tmp[$k] = $v;
|
||||
} elseif (isInnerEnv($k)) {
|
||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
||||
else $diskconfig[$k] = $v;
|
||||
$indisk = 1;
|
||||
} elseif ($k=='disktag_add') {
|
||||
array_push($disktags, $v);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_del') {
|
||||
$disktags = array_diff($disktags, [ $v ]);
|
||||
$tmp[$v] = '';
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_copy') {
|
||||
$newtag = $v . '_' . date("Ymd_His");
|
||||
$tmp[$newtag] = getConfig($v);
|
||||
array_push($disktags, $newtag);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
||||
} else {
|
||||
$tmp[$k] = json_encode($v);
|
||||
}
|
||||
}
|
||||
if ($indisk) {
|
||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||
ksort($diskconfig);
|
||||
$tmp[$disktag] = json_encode($diskconfig);
|
||||
}
|
||||
if ($operatedisk) {
|
||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
||||
$tags = [];
|
||||
foreach ($disktags as $tag) {
|
||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
||||
else array_push($tags, $tag);
|
||||
}
|
||||
$tmp['disktag'] = implode('|', $tags);
|
||||
$tmp[$arr['disktag_newname']] = getConfig($arr['disktag_rename']);
|
||||
$tmp[$arr['disktag_rename']] = null;
|
||||
} else {
|
||||
$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'] = null;
|
||||
}
|
||||
}
|
||||
foreach ($tmp as $key => $val) if ($val=='') $tmp[$key]=null;
|
||||
|
||||
return setHerokuConfig($tmp, getConfig('HerokuappId'), getConfig('APIKey'));
|
||||
error_log1(json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($tmp, JSON_PRETTY_PRINT));
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
global $constStr;
|
||||
if ($_GET['install1']) {
|
||||
if ($_POST['admin']!='') {
|
||||
$tmp['admin'] = $_POST['admin'];
|
||||
//$tmp['language'] = $_POST['language'];
|
||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
||||
$APIKey = $_POST['APIKey'];
|
||||
$tmp['APIKey'] = $APIKey;
|
||||
$HerokuappId = getConfig('HerokuappId');
|
||||
if ($HerokuappId=='') {
|
||||
$function_name = getConfig('function_name');
|
||||
if ($function_name=='') {
|
||||
$tmp1 = substr($_SERVER['HTTP_HOST'], 0, strrpos($_SERVER['HTTP_HOST'], '.'));
|
||||
$maindomain = substr($tmp1, strrpos($tmp1, '.')+1);
|
||||
if ($maindomain=='herokuapp') $function_name = substr($tmp1, 0, strrpos($tmp1, '.'));
|
||||
else return message('Please visit from xxxx.herokuapp.com', '', 500);
|
||||
$res = HerokuAPI('GET', 'https://api.heroku.com/apps/' . $function_name, '', $APIKey);
|
||||
$response = json_decode($res['body'], true);
|
||||
if (isset($response['build_stack'])) {
|
||||
$HerokuappId = $response['id'];
|
||||
} else {
|
||||
return message('Get Heroku app id: ' . json_encode($res, JSON_PRETTY_PRINT), 'Something error', 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
$tmp['HerokuappId'] = $HerokuappId;
|
||||
$response = json_decode(setHerokuConfig($tmp, $HerokuappId, $APIKey)['body'], true);
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 400);
|
||||
} else {
|
||||
$html = getconstStr('Success') . '
|
||||
<script>
|
||||
var expd = new Date();
|
||||
expd.setTime(expd.getTime()+1000);
|
||||
var expires = "expires="+expd.toGMTString();
|
||||
document.cookie=\'language=; path=/; \'+expires;
|
||||
var status = "' . $response['DplStatus'] . '";
|
||||
var i = 0;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
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>';
|
||||
}
|
||||
$html .= '
|
||||
<a href="https://dashboard.heroku.com/account" target="_blank">' . getconstStr('Create') . ' API Key</a><br>
|
||||
<label>API Key:<input name="APIKey" type="password" placeholder="" size=""></label><br>';
|
||||
$html .= '
|
||||
<label>Set admin password:<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></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 (t.admin.value==\'\') {
|
||||
alert(\'input admin\');
|
||||
return false;
|
||||
}';
|
||||
$html .= '
|
||||
if (t.APIKey.value==\'\') {
|
||||
alert(\'input API 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 = 'Install';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
function HerokuAPI($method, $url, $data = '', $apikey)
|
||||
{
|
||||
if ($method=='PATCH'||$method=='POST') {
|
||||
$headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
$headers['Authorization'] = 'Bearer ' . $apikey;
|
||||
$headers['Accept'] = 'application/vnd.heroku+json; version=3';
|
||||
//if (!isset($headers['Accept'])) $headers['Accept'] = '*/*';
|
||||
//if (!isset($headers['Referer'])) $headers['Referer'] = $url;
|
||||
$sendHeaders = array();
|
||||
foreach ($headers as $headerName => $headerVal) {
|
||||
$sendHeaders[] = $headerName . ': ' . $headerVal;
|
||||
}
|
||||
error_log1($method . $url . $data . $apikey);
|
||||
$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, 0);
|
||||
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);
|
||||
$response['stat'] = curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
error_log1($response['stat'].'
|
||||
'.$response['body'].'
|
||||
');
|
||||
return $response;
|
||||
}
|
||||
|
||||
function getHerokuConfig($HerokuappId, $apikey)
|
||||
{
|
||||
return HerokuAPI('GET', 'https://api.heroku.com/apps/' . $HerokuappId . '/config-vars', '', $apikey);
|
||||
}
|
||||
|
||||
function setHerokuConfig($env, $HerokuappId, $apikey)
|
||||
{
|
||||
$data = json_encode($env);
|
||||
if (substr($data, 0, 1)=='{') return HerokuAPI('PATCH', 'https://api.heroku.com/apps/' . $HerokuappId . '/config-vars', $data, $apikey);
|
||||
}
|
||||
|
||||
function updateHerokuapp($HerokuappId, $apikey, $source)
|
||||
{
|
||||
$tmp['source_blob']['url'] = $source;
|
||||
$data = json_encode($tmp);
|
||||
$response = HerokuAPI('POST', 'https://api.heroku.com/apps/' . $HerokuappId . '/builds', $data, $apikey);
|
||||
$result = json_decode( $response['body'], true );
|
||||
$result['DplStatus'] = $result['id'];
|
||||
$response['body'] = json_encode($result);
|
||||
return $response;
|
||||
}
|
||||
|
||||
function api_error($response)
|
||||
{
|
||||
return isset($response['id'])&&isset($response['message']);
|
||||
}
|
||||
|
||||
function api_error_msg($response)
|
||||
{
|
||||
return $response['id'] . '<br>
|
||||
' . $response['message'] . '<br><br>
|
||||
function_name:' . $_SERVER['function_name'] . '<br>
|
||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
||||
}
|
||||
|
||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||
{
|
||||
if ($GitSource=='Github') {
|
||||
//'https://github.com/qkqpttgf/OneManager-php/tarball/master/';
|
||||
$source = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||
} elseif ($GitSource=='HITGitlab') {
|
||||
$source = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
||||
} else return ['stat'=>403, 'body'=>json_encode(['id'=>'Error', 'message'=>'Git Source input Error!'])];
|
||||
|
||||
return updateHerokuapp(getConfig('HerokuappId'), getConfig('APIKey'), $source);
|
||||
}
|
||||
|
||||
function setConfigResponse($response)
|
||||
{
|
||||
return json_decode( $response['body'], true );
|
||||
}
|
||||
|
||||
function WaitFunction($buildId = '') {
|
||||
// GET /apps/{app_id_or_name}/builds/{build_id}
|
||||
if ($buildId=='1') return true;
|
||||
$response = HerokuAPI('GET', 'https://api.heroku.com/apps/' . getConfig('HerokuappId') . '/builds/' . $buildId, '', getConfig('APIKey'));
|
||||
if ($response['stat']==200) {
|
||||
$result = json_decode($response['body'], true);
|
||||
if ($result['status']=="succeeded") return true;
|
||||
else return false;
|
||||
} else {
|
||||
$response['body'] .= $url;
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
function changeAuthKey() {
|
||||
if ($_POST['APIKey']!='') {
|
||||
$APIKey = $_POST['APIKey'];
|
||||
$tmp['APIKey'] = $APIKey;
|
||||
$response = setConfigResponse( setHerokuConfig($tmp, getConfig('HerokuappId'), $APIKey) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 400);
|
||||
} else {
|
||||
$html = getconstStr('Success') . '
|
||||
<script>
|
||||
var status = "' . $response['DplStatus'] . '";
|
||||
var i = 0;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
}
|
||||
$html = '
|
||||
<form action="" method="post" onsubmit="return notnull(this);">
|
||||
<a href="https://dashboard.heroku.com/account" target="_blank">'.getconstStr('Create').' API Key</a><br>
|
||||
<label>API Key:<input name="APIKey" type="password" placeholder="" size=""></label><br>
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
</form>
|
||||
<script>
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.APIKey.value==\'\') {
|
||||
alert(\'input API Key\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
return message($html, 'Change platform Auth token or key', 200);
|
||||
}
|
||||
|
||||
function smallfileupload($drive, $path) {
|
||||
if ($_FILES['file1']['error']) return output($_FILES['file1']['error'], 400);
|
||||
if ($_FILES['file1']['size']>4*1024*1024) return output('File too large', 400);
|
||||
return $drive->smallfileupload($path, $_FILES['file1']);
|
||||
}
|
|
@ -0,0 +1,542 @@
|
|||
<?php
|
||||
// https://support.huaweicloud.com/api-functiongraph/functiongraph_06_0110.html
|
||||
// https://support.huaweicloud.com/api-functiongraph/functiongraph_06_0111.html
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
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'][''].'/');
|
||||
$path = str_replace('+', '%2B', $path);
|
||||
$_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'] = '/';
|
||||
}
|
||||
//$_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'];
|
||||
$_SERVER['HTTP_USER_AGENT'] = $event['headers']['user-agent'];
|
||||
if (isset($event['headers']['authorization'])) {
|
||||
$basicAuth = splitfirst(base64_decode(splitfirst($event['headers']['authorization'], 'Basic ')[1]), ':');
|
||||
$_SERVER['PHP_AUTH_USER'] = $basicAuth[0];
|
||||
$_SERVER['PHP_AUTH_PW'] = $basicAuth[1];
|
||||
}
|
||||
$_SERVER['REQUEST_SCHEME'] = $event['headers']['x-forwarded-proto'];
|
||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['referhost'] = explode('/', $event['headers']['referer'])[2];
|
||||
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
|
||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since'];
|
||||
$_SERVER['REQUEST_METHOD'] = $event['httpMethod'];
|
||||
$_SERVER['_APP_SHARE_DIR'] = '/var/share/CFF/processrouter';
|
||||
return $path;
|
||||
}
|
||||
|
||||
function getConfig($str, $disktag = '')
|
||||
{
|
||||
global $contextUserData;
|
||||
if (isInnerEnv($str)) {
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$env = json_decode($contextUserData->getUserData($disktag), true);
|
||||
if (isset($env[$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($env[$str]);
|
||||
else return $env[$str];
|
||||
}
|
||||
} else {
|
||||
if (isBase64Env($str)) return base64y_decode($contextUserData->getUserData($str));
|
||||
else return $contextUserData->getUserData($str);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function setConfig($arr, $disktag = '')
|
||||
{
|
||||
global $contextUserData;
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$disktags = explode("|",getConfig('disktag'));
|
||||
$diskconfig = json_decode($contextUserData->getUserData($disktag), true);
|
||||
$tmp = [];
|
||||
$indisk = 0;
|
||||
$operatedisk = 0;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (isCommonEnv($k)) {
|
||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
||||
else $tmp[$k] = $v;
|
||||
} elseif (isInnerEnv($k)) {
|
||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
||||
else $diskconfig[$k] = $v;
|
||||
$indisk = 1;
|
||||
} elseif ($k=='disktag_add') {
|
||||
array_push($disktags, $v);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_del') {
|
||||
$disktags = array_diff($disktags, [ $v ]);
|
||||
$tmp[$v] = '';
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_copy') {
|
||||
$newtag = $v . '_' . date("Ymd_His");
|
||||
$tmp[$newtag] = getConfig($v);
|
||||
array_push($disktags, $newtag);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
||||
} else {
|
||||
$tmp[$k] = json_encode($v);
|
||||
}
|
||||
}
|
||||
if ($indisk) {
|
||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||
ksort($diskconfig);
|
||||
$tmp[$disktag] = json_encode($diskconfig);
|
||||
}
|
||||
if ($operatedisk) {
|
||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
||||
$tags = [];
|
||||
foreach ($disktags as $tag) {
|
||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
||||
else array_push($tags, $tag);
|
||||
}
|
||||
$tmp['disktag'] = implode('|', $tags);
|
||||
$tmp[$arr['disktag_newname']] = getConfig($arr['disktag_rename']);
|
||||
$tmp[$arr['disktag_rename']] = '';
|
||||
} else {
|
||||
$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'] = $_POST['HW_urn'];
|
||||
$tmp['HW_key'] = $_POST['HW_key'];
|
||||
$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="password" 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 = 'Install';
|
||||
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);
|
||||
sortConfig($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($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||
{
|
||||
$source = '/tmp/code.zip';
|
||||
$outPath = '/tmp/';
|
||||
|
||||
if ($GitSource=='Github') {
|
||||
// 从github下载对应tar.gz,并解压
|
||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||
} elseif ($GitSource=='HITGitlab') {
|
||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
||||
} else return json_encode(['error_code'=>'Error', 'error_msg'=>'Git Source input Error!']);
|
||||
$tarfile = '/tmp/github.tar.gz';
|
||||
file_put_contents($tarfile, file_get_contents($url));
|
||||
$phar = new PharData($tarfile);
|
||||
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
||||
|
||||
// 获取解压出的目录名
|
||||
$outPath = findIndexPath($outPath);
|
||||
|
||||
// 将目录中文件打包成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($handler);
|
||||
}
|
||||
|
||||
function WaitFunction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function changeAuthKey() {
|
||||
if ($_POST['HW_key']!=''&&$_POST['HW_secret']!='') {
|
||||
$tmp['HW_key'] = $_POST['HW_key'];
|
||||
$tmp['HW_secret'] = $_POST['HW_secret'];
|
||||
$response = setConfigResponse( SetbaseConfig($tmp, getConfig('HW_urn'), $tmp['HW_key'], $tmp['HW_secret']) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 400);
|
||||
} else {
|
||||
$html = getconstStr('Success') . '
|
||||
<script>
|
||||
var status = "' . $response['DplStatus'] . '";
|
||||
var i = 0;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
}
|
||||
$html = '
|
||||
<form action="" method="post" onsubmit="return notnull(this);">
|
||||
<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="password" placeholder="" size=""></label><br>
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
</form>
|
||||
<script>
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.HW_key.value==\'\') {
|
||||
alert(\'input Access Key Id\');
|
||||
return false;
|
||||
}
|
||||
if (t.HW_secret.value==\'\') {
|
||||
alert(\'input Secret Access Key\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
return message($html, 'Change platform Auth token or key', 200);
|
||||
}
|
||||
|
||||
function smallfileupload($drive, $path) {
|
||||
return output('Can not upload through FG.', 400);
|
||||
}
|
|
@ -0,0 +1,908 @@
|
|||
<?php
|
||||
// https://support.huaweicloud.com/api-functiongraph/functiongraph_06_0110.html
|
||||
// https://support.huaweicloud.com/api-functiongraph/functiongraph_06_0111.html
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
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'][''].'/');
|
||||
$path = str_replace('+', '%2B', $path);
|
||||
$_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'] = '/';
|
||||
}
|
||||
//$_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'];
|
||||
$_SERVER['HTTP_USER_AGENT'] = $event['headers']['user-agent'];
|
||||
if (isset($event['headers']['authorization'])) {
|
||||
$basicAuth = splitfirst(base64_decode(splitfirst($event['headers']['authorization'], 'Basic ')[1]), ':');
|
||||
$_SERVER['PHP_AUTH_USER'] = $basicAuth[0];
|
||||
$_SERVER['PHP_AUTH_PW'] = $basicAuth[1];
|
||||
}
|
||||
$_SERVER['REQUEST_SCHEME'] = $event['headers']['x-forwarded-proto'];
|
||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['referhost'] = explode('/', $event['headers']['referer'])[2];
|
||||
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
|
||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since'];
|
||||
$_SERVER['REQUEST_METHOD'] = $event['httpMethod'];
|
||||
$_SERVER['_APP_SHARE_DIR'] = '/var/share/CFF/processrouter';
|
||||
return $path;
|
||||
}
|
||||
|
||||
function getConfig($str, $disktag = '')
|
||||
{
|
||||
$projectPath = splitlast(__DIR__, '/')[0];
|
||||
$configPath = $projectPath . '/.data/config.php';
|
||||
$s = file_get_contents($configPath);
|
||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||
if ($configs!='') {
|
||||
$envs = json_decode($configs, true);
|
||||
if (isInnerEnv($str)) {
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
if (isset($envs[$disktag][$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($envs[$disktag][$str]);
|
||||
else return $envs[$disktag][$str];
|
||||
}
|
||||
} else {
|
||||
if (isset($envs[$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($envs[$str]);
|
||||
else return $envs[$str];
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function setConfig($arr, $disktag = '')
|
||||
{
|
||||
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$projectPath = splitlast(__DIR__, '/')[0];
|
||||
$configPath = $projectPath . '/.data/config.php';
|
||||
$s = file_get_contents($configPath);
|
||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||
if ($configs!='') $envs = json_decode($configs, true);
|
||||
$disktags = explode("|",getConfig('disktag'));
|
||||
$indisk = 0;
|
||||
$operatedisk = 0;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (isCommonEnv($k)) {
|
||||
if (isBase64Env($k)) $envs[$k] = base64y_encode($v);
|
||||
else $envs[$k] = $v;
|
||||
} elseif (isInnerEnv($k)) {
|
||||
if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v);
|
||||
else $envs[$disktag][$k] = $v;
|
||||
$indisk = 1;
|
||||
} elseif ($k=='disktag_add') {
|
||||
array_push($disktags, $v);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_del') {
|
||||
$disktags = array_diff($disktags, [ $v ]);
|
||||
$envs[$v] = '';
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_copy') {
|
||||
$newtag = $v . '_' . date("Ymd_His");
|
||||
$envs[$newtag] = $envs[$v];
|
||||
array_push($disktags, $newtag);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
||||
} else {
|
||||
$envs[$k] = $v;
|
||||
}
|
||||
}
|
||||
if ($indisk) {
|
||||
$diskconfig = $envs[$disktag];
|
||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||
ksort($diskconfig);
|
||||
$envs[$disktag] = $diskconfig;
|
||||
}
|
||||
if ($operatedisk) {
|
||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
||||
$tags = [];
|
||||
foreach ($disktags as $tag) {
|
||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
||||
else array_push($tags, $tag);
|
||||
}
|
||||
$envs['disktag'] = implode('|', $tags);
|
||||
$envs[$arr['disktag_newname']] = $envs[$arr['disktag_rename']];
|
||||
$envs[$arr['disktag_rename']] = '';
|
||||
} else {
|
||||
$disktags = array_unique($disktags);
|
||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
||||
if ($disktag_s!='') $envs['disktag'] = substr($disktag_s, 0, -1);
|
||||
else $envs['disktag'] = '';
|
||||
}
|
||||
}
|
||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
||||
//ksort($envs);
|
||||
$response = updateEnvironment($envs, 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'] = $_POST['HW_urn'];
|
||||
$tmp['HW_key'] = $_POST['HW_key'];
|
||||
$tmp['HW_secret'] = $_POST['HW_secret'];
|
||||
$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']) );
|
||||
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_ENV') . '<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="urn:fss:ap-XXXXXXXX:XXXXXXXXXXXXXXXXXXXXc01a1e9caXXX:function:default:XXXXX:latest" 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="password" 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 Access Key Id\');
|
||||
return false;
|
||||
}
|
||||
if (t.HW_secret.value==\'\') {
|
||||
alert(\'input Secret Access 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 = 'Install';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
function getfunctioninfo($HW_urn, $HW_key, $HW_secret)
|
||||
{
|
||||
$URN = explode(':', $HW_urn);
|
||||
$Region = $URN[2];
|
||||
$project_id = $URN[3];
|
||||
$url = 'https://functiongraph.' . $Region . '.myhuaweicloud.com/v2/' . $project_id . '/fgs/functions/' . $HW_urn . '/config';
|
||||
$signer = new Signer();
|
||||
$signer->Key = $HW_key;
|
||||
$signer->Secret = $HW_secret;
|
||||
$req = new Request('GET', $url);
|
||||
$req->headers = array(
|
||||
'content-type' => 'application/json;charset=utf8',
|
||||
);
|
||||
$req->body = '';
|
||||
$curl = $signer->Sign($req);
|
||||
$response = curl_exec($curl);
|
||||
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
curl_close($curl);
|
||||
return $response;
|
||||
}
|
||||
|
||||
function getfunctioncode($HW_urn, $HW_key, $HW_secret)
|
||||
{
|
||||
$URN = explode(':', $HW_urn);
|
||||
$Region = $URN[2];
|
||||
$project_id = $URN[3];
|
||||
$url = 'https://functiongraph.' . $Region . '.myhuaweicloud.com/v2/' . $project_id . '/fgs/functions/' . $HW_urn . '/code';
|
||||
$signer = new Signer();
|
||||
$signer->Key = $HW_key;
|
||||
$signer->Secret = $HW_secret;
|
||||
$req = new Request('GET', $url);
|
||||
$req->headers = array(
|
||||
'content-type' => 'application/json;charset=utf8',
|
||||
);
|
||||
$req->body = '';
|
||||
$curl = $signer->Sign($req);
|
||||
$response = curl_exec($curl);
|
||||
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
curl_close($curl);
|
||||
//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('GET', $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)
|
||||
{
|
||||
sortConfig($Envs);
|
||||
//echo json_encode($Envs,JSON_PRETTY_PRINT);
|
||||
$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 . '.data/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)
|
||||
{
|
||||
//echo json_encode($Envs,JSON_PRETTY_PRINT);
|
||||
if ($Envs['ONEMANAGER_CONFIG_SAVE'] == 'file') $envs = Array( 'ONEMANAGER_CONFIG_SAVE' => 'file' );
|
||||
else {
|
||||
$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;
|
||||
}
|
||||
|
||||
// https://functiongraph.cn-north-4.myhuaweicloud.com/v2/{project_id}/fgs/functions/{function_urn}/config
|
||||
$URN = explode(':', $HW_urn);
|
||||
$Region = $URN[2];
|
||||
$project_id = $URN[3];
|
||||
$url = 'https://functiongraph.' . $Region . '.myhuaweicloud.com/v2/' . $project_id . '/fgs/functions/' . $HW_urn . '/config';
|
||||
$signer = new Signer();
|
||||
$signer->Key = $HW_key;
|
||||
$signer->Secret = $HW_secret;
|
||||
$req = new Request('PUT', $url);
|
||||
$req->headers = array(
|
||||
'content-type' => 'application/json;charset=utf8',
|
||||
);
|
||||
$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($envs);
|
||||
$req->body = json_encode($tmpdata);
|
||||
$curl = $signer->Sign($req);
|
||||
$response = curl_exec($curl);
|
||||
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
curl_close($curl);
|
||||
//return $response;
|
||||
if (api_error(setConfigResponse($response))) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$projectPath = splitlast(__DIR__, '/')[0];
|
||||
$configPath = $projectPath . '/.data/config.php';
|
||||
$s = file_get_contents($configPath);
|
||||
$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;
|
||||
}
|
||||
|
||||
function updateProgram($HW_urn, $HW_key, $HW_secret, $source)
|
||||
{
|
||||
$URN = explode(':', $HW_urn);
|
||||
$Region = $URN[2];
|
||||
$project_id = $URN[3];
|
||||
$url = 'https://functiongraph.' . $Region . '.myhuaweicloud.com/v2/' . $project_id . '/fgs/functions/' . $HW_urn . '/code';
|
||||
$signer = new Signer();
|
||||
$signer->Key = $HW_key;
|
||||
$signer->Secret = $HW_secret;
|
||||
$req = new Request('PUT', $url);
|
||||
$req->headers = array(
|
||||
'content-type' => 'application/json;charset=utf8',
|
||||
);
|
||||
$tmpdata['code_type'] = 'zip';
|
||||
$tmpdata['func_code']['file'] = base64_encode( file_get_contents($source) );
|
||||
$req->body = json_encode($tmpdata);
|
||||
$curl = $signer->Sign($req);
|
||||
$response = curl_exec($curl);
|
||||
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
curl_close($curl);
|
||||
return $response;
|
||||
}
|
||||
|
||||
function api_error($response)
|
||||
{
|
||||
return isset($response['error_code']);
|
||||
}
|
||||
|
||||
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($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||
{
|
||||
$source = '/tmp/code.zip';
|
||||
$outPath = '/tmp/';
|
||||
|
||||
if ($GitSource=='Github') {
|
||||
// 从github下载对应tar.gz,并解压
|
||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||
} elseif ($GitSource=='HITGitlab') {
|
||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
||||
} else return json_encode(['error_code'=>'Error', 'error_msg'=>'Git Source input Error!']);
|
||||
$tarfile = '/tmp/github.tar.gz';
|
||||
file_put_contents($tarfile, file_get_contents($url));
|
||||
$phar = new PharData($tarfile);
|
||||
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
||||
|
||||
// 获取解压出的目录名
|
||||
$outPath = findIndexPath($outPath);
|
||||
|
||||
// 放入配置文件
|
||||
file_put_contents($outPath . '/.data/config.php', file_get_contents(__DIR__ . '/../.data/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('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($handler);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
define("BasicDateFormat", "Ymd\THis\Z");
|
||||
define("Algorithm", "SDK-HMAC-SHA256");
|
||||
define("HeaderXDate", "X-Sdk-Date");
|
||||
define("HeaderHost", "host");
|
||||
define("HeaderAuthorization", "Authorization");
|
||||
define("HeaderContentSha256", "X-Sdk-Content-Sha256");
|
||||
|
||||
class Request
|
||||
{
|
||||
public $method = '';
|
||||
public $scheme = '';
|
||||
public $host = '';
|
||||
public $uri = '';
|
||||
public $query = array();
|
||||
public $headers = array();
|
||||
public $body = '';
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$i = count($args);
|
||||
if ($i == 0) {
|
||||
$this->construct(NULL, NULL, NULL, NULL);
|
||||
} elseif ($i == 1) {
|
||||
$this->construct($args[0], NULL, NULL, NULL);
|
||||
} elseif ($i == 2) {
|
||||
$this->construct($args[0], $args[1], NULL, NULL);
|
||||
} elseif ($i == 3) {
|
||||
$this->construct($args[0], $args[1], $args[2], NULL);
|
||||
} else {
|
||||
$this->construct($args[0], $args[1], $args[2], $args[3]);
|
||||
}
|
||||
}
|
||||
|
||||
function construct($method, $url, $headers, $body)
|
||||
{
|
||||
if ($method != NULL) {
|
||||
$this->method = $method;
|
||||
}
|
||||
if ($url != NULL) {
|
||||
$spl = explode("://", $url, 2);
|
||||
$scheme = 'http';
|
||||
if (count($spl) > 1) {
|
||||
$scheme = $spl[0];
|
||||
$url = $spl[1];
|
||||
}
|
||||
$spl = explode("?", $url, 2);
|
||||
$url = $spl[0];
|
||||
$query = array();
|
||||
if (count($spl) > 1) {
|
||||
foreach (explode("&", $spl[1]) as $kv) {
|
||||
$spl = explode("=", $kv, 2);
|
||||
$key = $spl[0];
|
||||
if (count($spl) == 1) {
|
||||
$value = "";
|
||||
} else {
|
||||
$value = $spl[1];
|
||||
}
|
||||
if ($key != "") {
|
||||
$key = urldecode($key);
|
||||
$value = urldecode($value);
|
||||
if (array_key_exists($key, $query)) {
|
||||
array_push($query[$key], $value);
|
||||
} else {
|
||||
$query[$key] = array($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$spl = explode("/", $url, 2);
|
||||
$host = $spl[0];
|
||||
if (count($spl) == 1) {
|
||||
$url = "/";
|
||||
} else {
|
||||
$url = "/" . $spl[1];
|
||||
}
|
||||
$this->scheme = $scheme;
|
||||
$this->host = $host;
|
||||
$this->uri = urldecode($url);
|
||||
$this->query = $query;
|
||||
}
|
||||
if ($headers != NULL) {
|
||||
$this->headers = $headers;
|
||||
}
|
||||
if ($body != NULL) {
|
||||
$this->body = $body;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Signer
|
||||
{
|
||||
public $Key = '';
|
||||
public $Secret = '';
|
||||
|
||||
function escape($string)
|
||||
{
|
||||
$entities = array('+', "%7E");
|
||||
$replacements = array('%20', "~");
|
||||
return str_replace($entities, $replacements, urlencode($string));
|
||||
}
|
||||
|
||||
function findHeader($r, $header)
|
||||
{
|
||||
foreach ($r->headers as $key => $value) {
|
||||
if (!strcasecmp($key, $header)) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Build a CanonicalRequest from a regular request string
|
||||
//
|
||||
// CanonicalRequest =
|
||||
// HTTPRequestMethod + '\n' +
|
||||
// CanonicalURI + '\n' +
|
||||
// CanonicalQueryString + '\n' +
|
||||
// CanonicalHeaders + '\n' +
|
||||
// SignedHeaders + '\n' +
|
||||
// HexEncode(Hash(RequestPayload))
|
||||
function CanonicalRequest($r, $signedHeaders)
|
||||
{
|
||||
$CanonicalURI = $this->CanonicalURI($r);
|
||||
$CanonicalQueryString = $this->CanonicalQueryString($r);
|
||||
$canonicalHeaders = $this->CanonicalHeaders($r, $signedHeaders);
|
||||
$signedHeadersString = join(";", $signedHeaders);
|
||||
$hash = $this->findHeader($r, HeaderContentSha256);
|
||||
if (!$hash) {
|
||||
$hash = hash("sha256", $r->body);
|
||||
}
|
||||
return "$r->method\n$CanonicalURI\n$CanonicalQueryString\n$canonicalHeaders\n$signedHeadersString\n$hash";
|
||||
}
|
||||
|
||||
// CanonicalURI returns request uri
|
||||
function CanonicalURI($r)
|
||||
{
|
||||
$pattens = explode("/", $r->uri);
|
||||
$uri = array();
|
||||
foreach ($pattens as $v) {
|
||||
array_push($uri, $this->escape($v));
|
||||
}
|
||||
$urlpath = join("/", $uri);
|
||||
if (substr($urlpath, -1) != "/") {
|
||||
$urlpath = $urlpath . "/";
|
||||
}
|
||||
return $urlpath;
|
||||
}
|
||||
|
||||
// CanonicalQueryString
|
||||
function CanonicalQueryString($r)
|
||||
{
|
||||
$keys = array();
|
||||
foreach ($r->query as $key => $value) {
|
||||
array_push($keys, $key);
|
||||
}
|
||||
sort($keys);
|
||||
$a = array();
|
||||
foreach ($keys as $key) {
|
||||
$k = $this->escape($key);
|
||||
$value = $r->query[$key];
|
||||
if (is_array($value)) {
|
||||
sort($value);
|
||||
foreach ($value as $v) {
|
||||
$kv = "$k=" . $this->escape($v);
|
||||
array_push($a, $kv);
|
||||
}
|
||||
} else {
|
||||
$kv = "$k=" . $this->escape($value);
|
||||
array_push($a, $kv);
|
||||
}
|
||||
}
|
||||
return join("&", $a);
|
||||
}
|
||||
|
||||
// CanonicalHeaders
|
||||
function CanonicalHeaders($r, $signedHeaders)
|
||||
{
|
||||
$headers = array();
|
||||
foreach ($r->headers as $key => $value) {
|
||||
$headers[strtolower($key)] = trim($value);
|
||||
}
|
||||
$a = array();
|
||||
foreach ($signedHeaders as $key) {
|
||||
array_push($a, $key . ':' . $headers[$key]);
|
||||
}
|
||||
return join("\n", $a) . "\n";
|
||||
}
|
||||
|
||||
function curlHeaders($r)
|
||||
{
|
||||
$header = array();
|
||||
foreach ($r->headers as $key => $value) {
|
||||
array_push($header, strtolower($key) . ':' . trim($value));
|
||||
}
|
||||
return $header;
|
||||
}
|
||||
|
||||
// SignedHeaders
|
||||
function SignedHeaders($r)
|
||||
{
|
||||
$a = array();
|
||||
foreach ($r->headers as $key => $value) {
|
||||
array_push($a, strtolower($key));
|
||||
}
|
||||
sort($a);
|
||||
return $a;
|
||||
}
|
||||
|
||||
// Create a "String to Sign".
|
||||
function StringToSign($canonicalRequest, $t)
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
$date = date(BasicDateFormat, $t);
|
||||
$hash = hash("sha256", $canonicalRequest);
|
||||
return "SDK-HMAC-SHA256\n$date\n$hash";
|
||||
}
|
||||
|
||||
// Create the HWS Signature.
|
||||
function SignStringToSign($stringToSign, $signingKey)
|
||||
{
|
||||
return hash_hmac("sha256", $stringToSign, $signingKey);
|
||||
}
|
||||
|
||||
// Get the finalized value for the "Authorization" header. The signature parameter is the output from SignStringToSign
|
||||
function AuthHeaderValue($signature, $accessKey, $signedHeaders)
|
||||
{
|
||||
$signedHeadersString = join(";", $signedHeaders);
|
||||
return "SDK-HMAC-SHA256 Access=$accessKey, SignedHeaders=$signedHeadersString, Signature=$signature";
|
||||
}
|
||||
|
||||
public function Sign($r)
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
$date = $this->findHeader($r, HeaderXDate);
|
||||
if ($date) {
|
||||
$t = date_timestamp_get(date_create_from_format(BasicDateFormat, $date));
|
||||
}
|
||||
if (!@$t) {
|
||||
$t = time();
|
||||
$r->headers[HeaderXDate] = date(BasicDateFormat, $t);
|
||||
}
|
||||
$queryString = $this->CanonicalQueryString($r);
|
||||
if ($queryString != "") {
|
||||
$queryString = "?" . $queryString;
|
||||
}
|
||||
$signedHeaders = $this->SignedHeaders($r);
|
||||
$canonicalRequest = $this->CanonicalRequest($r, $signedHeaders);
|
||||
$stringToSign = $this->StringToSign($canonicalRequest, $t);
|
||||
$signature = $this->SignStringToSign($stringToSign, $this->Secret);
|
||||
$authValue = $this->AuthHeaderValue($signature, $this->Key, $signedHeaders);
|
||||
$r->headers[HeaderAuthorization] = $authValue;
|
||||
|
||||
$curl = curl_init();
|
||||
$uri = str_replace(array("%2F"), array("/"), rawurlencode($r->uri));
|
||||
$url = $r->scheme . '://' . $r->host . $uri . $queryString;
|
||||
$headers = $this->curlHeaders($r);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $r->method);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $r->body);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
curl_setopt($curl, CURLOPT_NOBODY, FALSE);
|
||||
return $curl;
|
||||
}
|
||||
}
|
||||
|
||||
function WaitFunction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function changeAuthKey() {
|
||||
if ($_POST['HW_key']!=''&&$_POST['HW_secret']!='') {
|
||||
$tmp['HW_key'] = $_POST['HW_key'];
|
||||
$tmp['HW_secret'] = $_POST['HW_secret'];
|
||||
$response = setConfigResponse( SetbaseConfig($tmp, getConfig('HW_urn'), $tmp['HW_key'], $tmp['HW_secret']) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 400);
|
||||
} else {
|
||||
$html = getconstStr('Success') . '
|
||||
<script>
|
||||
var status = "' . $response['DplStatus'] . '";
|
||||
var i = 0;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
}
|
||||
$html = '
|
||||
<form action="" method="post" onsubmit="return notnull(this);">
|
||||
<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="password" placeholder="" size=""></label><br>
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
</form>
|
||||
<script>
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.HW_key.value==\'\') {
|
||||
alert(\'input Access Key Id\');
|
||||
return false;
|
||||
}
|
||||
if (t.HW_secret.value==\'\') {
|
||||
alert(\'input Secret Access Key\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
return message($html, 'Change platform Auth token or key', 200);
|
||||
}
|
||||
|
||||
function smallfileupload($drive, $path) {
|
||||
return output('Can not upload through FG.', 400);
|
||||
}
|
|
@ -0,0 +1,399 @@
|
|||
<?php
|
||||
|
||||
function getpath()
|
||||
{
|
||||
$_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_FLY_CLIENT_IP'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_FLY_CLIENT_IP'];
|
||||
if ($_SERVER['HTTP_FLY_FORWARDED_PROTO']!='') $_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_FLY_FORWARDED_PROTO'];
|
||||
if ($_SERVER['HTTP_X_FORWARDED_PROTO']!='') {
|
||||
$tmp = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0];
|
||||
if ($tmp=='http'||$tmp=='https') $_SERVER['REQUEST_SCHEME'] = $tmp;
|
||||
}
|
||||
if ($_SERVER['REQUEST_SCHEME']!='http'&&$_SERVER['REQUEST_SCHEME']!='https') {
|
||||
$_SERVER['REQUEST_SCHEME'] = 'http';
|
||||
}
|
||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['referhost'] = explode('/', $_SERVER['HTTP_REFERER'])[2];
|
||||
if (isset($_SERVER['DOCUMENT_ROOT'])&&$_SERVER['DOCUMENT_ROOT']==='/app') $_SERVER['base_path'] = '/';
|
||||
else $_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'],'?');
|
||||
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
||||
else $path = $_SERVER['REQUEST_URI'];
|
||||
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
||||
return $path;
|
||||
}
|
||||
|
||||
function getGET()
|
||||
{
|
||||
if (!$_POST) {
|
||||
if (!!$HTTP_RAW_POST_DATA) {
|
||||
$tmpdata = $HTTP_RAW_POST_DATA;
|
||||
} else {
|
||||
$tmpdata = file_get_contents('php://input');
|
||||
}
|
||||
if (!!$tmpdata) {
|
||||
$postbody = explode("&", $tmpdata);
|
||||
foreach ($postbody as $postvalues) {
|
||||
$pos = strpos($postvalues,"=");
|
||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) {
|
||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
||||
$getstrarr = explode("&",$getstr);
|
||||
foreach ($getstrarr as $getvalues) {
|
||||
if ($getvalues != '') {
|
||||
$pos = strpos($getvalues, "=");
|
||||
//echo $pos;
|
||||
if ($pos > 0) {
|
||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
||||
} else {
|
||||
$getarry[urldecode($getvalues)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($getarry)) {
|
||||
return $getarry;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function getConfig($str, $disktag = '')
|
||||
{
|
||||
global $slash;
|
||||
$projectPath = splitlast(__DIR__, $slash)[0];
|
||||
$configPath = $projectPath . $slash . '.data' . $slash . 'config.php';
|
||||
$s = file_get_contents($configPath);
|
||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||
if ($configs!='') {
|
||||
$envs = json_decode($configs, true);
|
||||
if (isInnerEnv($str)) {
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
if (isset($envs[$disktag][$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($envs[$disktag][$str]);
|
||||
else return $envs[$disktag][$str];
|
||||
}
|
||||
} else {
|
||||
if (isset($envs[$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($envs[$str]);
|
||||
else return $envs[$str];
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function setConfig($arr, $disktag = '')
|
||||
{
|
||||
global $slash;
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$projectPath = splitlast(__DIR__, $slash)[0];
|
||||
$configPath = $projectPath . $slash . '.data' . $slash . 'config.php';
|
||||
$s = file_get_contents($configPath);
|
||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||
if ($configs!='') $envs = json_decode($configs, true);
|
||||
$disktags = explode("|", getConfig('disktag'));
|
||||
$indisk = 0;
|
||||
$operatedisk = 0;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (isCommonEnv($k)) {
|
||||
if (isBase64Env($k)) $envs[$k] = base64y_encode($v);
|
||||
else $envs[$k] = $v;
|
||||
} elseif (isInnerEnv($k)) {
|
||||
if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v);
|
||||
else $envs[$disktag][$k] = $v;
|
||||
$indisk = 1;
|
||||
} elseif ($k=='disktag_add') {
|
||||
array_push($disktags, $v);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_del') {
|
||||
$disktags = array_diff($disktags, [ $v ]);
|
||||
$envs[$v] = '';
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_copy') {
|
||||
$newtag = $v . '_' . date("Ymd_His");
|
||||
$envs[$newtag] = $envs[$v];
|
||||
array_push($disktags, $newtag);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
||||
} else {
|
||||
//$tmpdisk = json_decode($v, true);
|
||||
//var_dump($tmpdisk);
|
||||
//error_log(json_encode($tmpdisk));
|
||||
//if ($tmpdisk===null)
|
||||
$envs[$k] = $v;
|
||||
//else $envs[$k] = $tmpdisk;
|
||||
}
|
||||
}
|
||||
if ($indisk) {
|
||||
$diskconfig = $envs[$disktag];
|
||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||
ksort($diskconfig);
|
||||
$envs[$disktag] = $diskconfig;
|
||||
}
|
||||
if ($operatedisk) {
|
||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
||||
$tags = [];
|
||||
foreach ($disktags as $tag) {
|
||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
||||
else array_push($tags, $tag);
|
||||
}
|
||||
$envs['disktag'] = implode('|', $tags);
|
||||
$envs[$arr['disktag_newname']] = $envs[$arr['disktag_rename']];
|
||||
unset($envs[$arr['disktag_rename']]);
|
||||
} else {
|
||||
$disktags = array_unique($disktags);
|
||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
||||
if ($disktag_s!='') $envs['disktag'] = substr($disktag_s, 0, -1);
|
||||
else $envs['disktag'] = '';
|
||||
}
|
||||
}
|
||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
||||
//ksort($envs);
|
||||
sortConfig($envs);
|
||||
|
||||
//echo '<pre>'. json_encode($envs, JSON_PRETTY_PRINT).'</pre>';
|
||||
$prestr = '<?php $configs = \'' . PHP_EOL;
|
||||
$aftstr = PHP_EOL . '\';';
|
||||
$response = file_put_contents($configPath, $prestr . json_encode($envs, JSON_PRETTY_PRINT) . $aftstr);
|
||||
if ($response>0) return json_encode( [ 'response' => 'success' ] );
|
||||
return json_encode( [ 'message' => 'Failed to write config.', 'code' => 'failed' ] );
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
global $constStr;
|
||||
if ($_GET['install2']) {
|
||||
if ($_POST['admin']!='') {
|
||||
$tmp['admin'] = $_POST['admin'];
|
||||
//$tmp['language'] = $_COOKIE['language'];
|
||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
||||
$response = setConfigResponse( setConfig($tmp) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
} else {
|
||||
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 (!ConfigWriteable()) {
|
||||
$html .= getconstStr('MakesuerWriteable');
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
/*if (!RewriteEngineOn()) {
|
||||
$html .= getconstStr('MakesuerRewriteOn');
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
}*/
|
||||
$html .= '<button id="checkrewritebtn" onclick="checkrewrite();">'.getconstStr('MakesuerRewriteOn').'</button>
|
||||
<div id="formdiv" style="display: none">
|
||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
||||
<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"><br>
|
||||
<input id="submitbtn" type="submit" value="'.getconstStr('Submit').'" disabled>
|
||||
</form>
|
||||
</div>
|
||||
<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 notnull(t)
|
||||
{
|
||||
if (t.admin.value==\'\') {
|
||||
alert(\''.getconstStr('SetAdminPassword').'\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function checkrewrite()
|
||||
{
|
||||
url=location.protocol + "//" + location.host;
|
||||
//if (location.port!="") url += ":" + location.port;
|
||||
url += location.pathname;
|
||||
if (url.substr(-1)!="/") url += "/";
|
||||
url += "app.json";
|
||||
url += "?" + Date.now();
|
||||
var xhr4 = new XMLHttpRequest();
|
||||
xhr4.open("GET", url);
|
||||
xhr4.setRequestHeader("x-requested-with","XMLHttpRequest");
|
||||
xhr4.send(null);
|
||||
xhr4.onload = function(e){
|
||||
console.log(xhr4.responseText+","+xhr4.status);
|
||||
if (xhr4.status==201) {
|
||||
document.getElementById("checkrewritebtn").style.display = "none";
|
||||
document.getElementById("submitbtn").disabled = false;
|
||||
document.getElementById("formdiv").style.display = "";
|
||||
} else {
|
||||
alert("' . getconstStr('MakesuerRewriteOn') . '?\nfalse\n\nUrl: " + url + "\nExpect http code 201, but received " + xhr4.status);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>';
|
||||
$title = getconstStr('SetAdminPassword');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
if ($_GET['install0']) {
|
||||
$html .= '
|
||||
<form action="?install1" method="post">
|
||||
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>';
|
||||
}
|
||||
$html .= '
|
||||
<input type="submit" value="'.getconstStr('Submit').'">
|
||||
</form>
|
||||
<script>
|
||||
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;
|
||||
}
|
||||
</script>';
|
||||
$title = getconstStr('SelectLanguage');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
$title = 'Install';
|
||||
$html = '<a href="?install0">' . getconstStr('ClickInstall') . '</a>, ' . getconstStr('LogintoBind');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
function ConfigWriteable()
|
||||
{
|
||||
$t = md5( md5(time()).rand(1000,9999) );
|
||||
$r = setConfig([ 'tmp' => $t ]);
|
||||
$tmp = getConfig('tmp');
|
||||
setConfig([ 'tmp' => '' ]);
|
||||
if ($tmp == $t) return true;
|
||||
if ($r) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function api_error($response)
|
||||
{
|
||||
return isset($response['message']);
|
||||
}
|
||||
|
||||
function api_error_msg($response)
|
||||
{
|
||||
return $response['code'] . '<br>
|
||||
' . $response['message'] . '<br>
|
||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
||||
}
|
||||
|
||||
function setConfigResponse($response)
|
||||
{
|
||||
return json_decode($response, true);
|
||||
}
|
||||
|
||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||
{
|
||||
global $slash;
|
||||
// __DIR__ is xxx/platform
|
||||
$projectPath = splitlast(__DIR__, $slash)[0];
|
||||
|
||||
if ($GitSource=='Github') {
|
||||
// 从github下载对应tar.gz,并解压
|
||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||
} elseif ($GitSource=='HITGitlab') {
|
||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
||||
} else return 0;
|
||||
$tarfile = $projectPath . $slash .'github.tar.gz';
|
||||
$githubfile = file_get_contents($url);
|
||||
if (!$githubfile) return 0;
|
||||
file_put_contents($tarfile, $githubfile);
|
||||
|
||||
if (splitfirst(PHP_VERSION, '.')[0] > '5') {
|
||||
$phar = new PharData($tarfile); // need php5.3, 7, 8
|
||||
$phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖
|
||||
} else {
|
||||
ob_start();
|
||||
passthru('tar -xzvf ' . $tarfile, $stat);
|
||||
ob_get_clean();
|
||||
}
|
||||
unlink($tarfile);
|
||||
|
||||
$outPath = '';
|
||||
$outPath = findIndexPath($projectPath);
|
||||
//error_log1($outPath);
|
||||
if ($outPath=='') return 0;
|
||||
|
||||
//unlink($outPath.'/config.php');
|
||||
$response = rename($projectPath . $slash . '.data' . $slash . 'config.php', $outPath . $slash . '.data' . $slash . 'config.php');
|
||||
if (!$response) {
|
||||
$tmp1['code'] = "Move Failed";
|
||||
$tmp1['message'] = "Can not move " . $projectPath . $slash . '.data' . $slash . 'config.php' . " to " . $outPath . $slash . '.data' . $slash . 'config.php';
|
||||
return json_encode($tmp1);
|
||||
}
|
||||
return moveFolder($outPath, $projectPath);
|
||||
}
|
||||
|
||||
function moveFolder($from, $to)
|
||||
{
|
||||
global $slash;
|
||||
if (substr($from, -1)==$slash) $from = substr($from, 0, -1);
|
||||
if (substr($to, -1)==$slash) $to = substr($to, 0, -1);
|
||||
if (!file_exists($to)) mkdir($to, 0777);
|
||||
$handler=opendir($from);
|
||||
while($filename=readdir($handler)) {
|
||||
if($filename != '.' && $filename != '..'){
|
||||
$fromfile = $from . $slash . $filename;
|
||||
$tofile = $to . $slash . $filename;
|
||||
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
||||
$response = moveFolder($fromfile, $tofile);
|
||||
if (api_error(setConfigResponse($response))) return $response;
|
||||
}else{
|
||||
//if (file_exists($tofile)) unlink($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);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handler);
|
||||
rmdir($from);
|
||||
return json_encode( [ 'response' => 'success' ] );
|
||||
}
|
||||
|
||||
function WaitFunction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function changeAuthKey() {
|
||||
return message("Not need.", 'Change platform Auth token or key', 404);
|
||||
}
|
||||
|
||||
function smallfileupload($drive, $path) {
|
||||
if ($_FILES['file1']['error']) return output($_FILES['file1']['error'], 400);
|
||||
if ($_FILES['file1']['size']>4*1024*1024) return output('File too large', 400);
|
||||
return $drive->smallfileupload($path, $_FILES['file1']);
|
||||
}
|
|
@ -0,0 +1,363 @@
|
|||
<?php
|
||||
|
||||
function getpath()
|
||||
{
|
||||
$_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 ($_SERVER['REQUEST_SCHEME']!='http'&&$_SERVER['REQUEST_SCHEME']!='https') {
|
||||
if ($_SERVER['HTTP_X_FORWARDED_PROTO']!='') {
|
||||
$tmp = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0];
|
||||
if ($tmp=='http'||$tmp=='https') $_SERVER['REQUEST_SCHEME'] = $tmp;
|
||||
}
|
||||
if ($_SERVER['HTTP_FLY_FORWARDED_PROTO']!='') $_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_FLY_FORWARDED_PROTO'];
|
||||
}
|
||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['referhost'] = explode('/', $_SERVER['HTTP_REFERER'])[2];
|
||||
$_SERVER['base_path'] = '/';
|
||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
||||
else $path = $_SERVER['REQUEST_URI'];
|
||||
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
||||
return $path;
|
||||
}
|
||||
|
||||
function getGET()
|
||||
{
|
||||
if (!$_POST) {
|
||||
if (!!$HTTP_RAW_POST_DATA) {
|
||||
$tmpdata = $HTTP_RAW_POST_DATA;
|
||||
} else {
|
||||
$tmpdata = file_get_contents('php://input');
|
||||
}
|
||||
if (!!$tmpdata) {
|
||||
$postbody = explode("&", $tmpdata);
|
||||
foreach ($postbody as $postvalues) {
|
||||
$pos = strpos($postvalues,"=");
|
||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) {
|
||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
||||
$getstrarr = explode("&",$getstr);
|
||||
foreach ($getstrarr as $getvalues) {
|
||||
if ($getvalues != '') {
|
||||
$pos = strpos($getvalues, "=");
|
||||
//echo $pos;
|
||||
if ($pos > 0) {
|
||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
||||
} else {
|
||||
$getarry[urldecode($getvalues)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($getarry)) {
|
||||
return $getarry;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function ReplitAPI($op, $key, $value = '') {
|
||||
//error_log1($op . '_' . $key . '_' . $value);
|
||||
$apiurl = getenv('REPLIT_DB_URL');
|
||||
//foreach (explode("\n", curl('GET', $apiurl . '?prefix')['body']) as $a) curl('DELETE', $apiurl . '/' . $a);
|
||||
if ($op === 'r') {
|
||||
if (!($config = getcache('REPLIT_CONFIG'))) {
|
||||
$config = json_decode(curl('GET', $apiurl . '/REPLIT_CONFIG')['body'], true);
|
||||
savecache('REPLIT_CONFIG', $config);
|
||||
}
|
||||
return ['stat'=>200, 'body'=>(is_array($config[$key])?json_encode($config[$key]):$config[$key])];
|
||||
} elseif ($op === 'w') {
|
||||
return curl('POST', $apiurl, 'REPLIT_CONFIG=' . $value, ["Content-Type"=>"application/x-www-form-urlencoded"]);
|
||||
} elseif ($op === 'd') {
|
||||
// not use
|
||||
return curl('DELETE', $apiurl . '/' . $key);
|
||||
} else {
|
||||
return ['stat'=>500, 'body'=>'error option input to function ReplitAPI().'];
|
||||
}
|
||||
}
|
||||
|
||||
function getConfig($str, $disktag = '')
|
||||
{
|
||||
if (isInnerEnv($str)) {
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$env = json_decode(ReplitAPI('r', $disktag)['body'], true);
|
||||
if (isset($env[$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($env[$str]);
|
||||
else return $env[$str];
|
||||
}
|
||||
} else {
|
||||
if (isBase64Env($str)) return base64y_decode(ReplitAPI('r', $str)['body']);
|
||||
else return ReplitAPI('r', $str)['body'];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function setConfig($arr, $disktag = '')
|
||||
{
|
||||
if (!($envs = getcache('REPLIT_CONFIG'))) {
|
||||
$envs = json_decode(curl('GET', getenv('REPLIT_DB_URL') . '/REPLIT_CONFIG')['body'], true);
|
||||
savecache('REPLIT_CONFIG', $envs);
|
||||
}
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$disktags = explode("|", getConfig('disktag'));
|
||||
$indisk = 0;
|
||||
$operatedisk = 0;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (isCommonEnv($k)) {
|
||||
if (isBase64Env($k)) $envs[$k] = base64y_encode($v);
|
||||
else $envs[$k] = $v;
|
||||
} elseif (isInnerEnv($k)) {
|
||||
if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v);
|
||||
else $envs[$disktag][$k] = $v;
|
||||
$indisk = 1;
|
||||
} elseif ($k=='disktag_add') {
|
||||
array_push($disktags, $v);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_del') {
|
||||
$disktags = array_diff($disktags, [ $v ]);
|
||||
$envs[$v] = '';
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_copy') {
|
||||
$newtag = $v . '_' . date("Ymd_His");
|
||||
$envs[$newtag] = $envs[$v];
|
||||
array_push($disktags, $newtag);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
||||
} else {
|
||||
$envs[$k] = $v;
|
||||
}
|
||||
}
|
||||
if ($indisk) {
|
||||
$diskconfig = $envs[$disktag];
|
||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||
ksort($diskconfig);
|
||||
$envs[$disktag] = $diskconfig;
|
||||
}
|
||||
if ($operatedisk) {
|
||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
||||
$tags = [];
|
||||
foreach ($disktags as $tag) {
|
||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
||||
else array_push($tags, $tag);
|
||||
}
|
||||
$envs['disktag'] = implode('|', $tags);
|
||||
$envs[$arr['disktag_newname']] = $envs[$arr['disktag_rename']];
|
||||
unset($envs[$arr['disktag_rename']]);
|
||||
} else {
|
||||
$disktags = array_unique($disktags);
|
||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
||||
if ($disktag_s!='') $envs['disktag'] = substr($disktag_s, 0, -1);
|
||||
else $envs['disktag'] = '';
|
||||
}
|
||||
}
|
||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
||||
sortConfig($envs);
|
||||
$response = ReplitAPI('w', 'REPLIT_CONFIG', json_encode($envs));
|
||||
//error_log1(json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($envs, JSON_PRETTY_PRINT));
|
||||
savecache('REPLIT_CONFIG', null, '', 0);
|
||||
if (api_error($response)) return ['stat'=>$response['stat'], 'body'=>$response['body'] . "<br>\nError in writting " . $key . "=" . $val];
|
||||
return $response;
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
global $constStr;
|
||||
if ($_GET['install2']) {
|
||||
if ($_POST['admin']!='') {
|
||||
$tmp['admin'] = $_POST['admin'];
|
||||
//$tmp['language'] = $_COOKIE['language'];
|
||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
||||
$response = setConfigResponse( setConfig($tmp) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
} else {
|
||||
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 (!ConfigWriteable()) {
|
||||
$html .= getconstStr('MakesuerWriteable');
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
if (!RewriteEngineOn()) {
|
||||
$html .= getconstStr('MakesuerRewriteOn');
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
}*/
|
||||
$html .= '
|
||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
||||
<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"><br>
|
||||
<input id="submitbtn" 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 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">
|
||||
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>';
|
||||
}
|
||||
$html .= '
|
||||
<input type="submit" value="'.getconstStr('Submit').'">
|
||||
</form>
|
||||
<script>
|
||||
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;
|
||||
}
|
||||
</script>';
|
||||
$title = getconstStr('SelectLanguage');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
$title = 'Install';
|
||||
$html = '<a href="?install0">' . getconstStr('ClickInstall') . '</a>, ' . getconstStr('LogintoBind');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
function ConfigWriteable()
|
||||
{
|
||||
$t = md5( md5(time()).rand(1000,9999) );
|
||||
$r = setConfig([ 'tmp' => $t ]);
|
||||
$tmp = getConfig('tmp');
|
||||
setConfig([ 'tmp' => '' ]);
|
||||
if ($tmp == $t) return true;
|
||||
if ($r) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function api_error($response)
|
||||
{
|
||||
return !($response['stat']==200||$response['stat']==204||$response['stat']==404);
|
||||
//return isset($response['message']);
|
||||
}
|
||||
|
||||
function api_error_msg($response)
|
||||
{
|
||||
return '<pre>'. json_encode($response, JSON_PRETTY_PRINT).'</pre>' . '<br>
|
||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
||||
}
|
||||
|
||||
function setConfigResponse($response)
|
||||
{
|
||||
return $response;
|
||||
//return json_decode($response, true);
|
||||
}
|
||||
|
||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||
{
|
||||
// __DIR__ is xxx/platform
|
||||
$projectPath = splitlast(__DIR__, '/')[0];
|
||||
|
||||
if ($GitSource=='Github') {
|
||||
// 从github下载对应tar.gz,并解压
|
||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||
} elseif ($GitSource=='HITGitlab') {
|
||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
||||
} else return ['stat'=>500, 'body'=>'Git Source input Error!'];
|
||||
$tarfile = $projectPath . '/github.tar.gz';
|
||||
$githubfile = file_get_contents($url);
|
||||
if (!$githubfile) return ['stat'=>500, 'body'=>'download error from github.'];
|
||||
file_put_contents($tarfile, $githubfile);
|
||||
if (splitfirst(PHP_VERSION, '.')[0] > '5') {
|
||||
$phar = new PharData($tarfile); // need php5.3, 7, 8
|
||||
$phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖
|
||||
} else {
|
||||
ob_start();
|
||||
passthru('tar -xzvf ' . $tarfile, $stat);
|
||||
ob_get_clean();
|
||||
}
|
||||
unlink($tarfile);
|
||||
|
||||
$outPath = '';
|
||||
$outPath = findIndexPath($projectPath);
|
||||
//error_log1($outPath);
|
||||
if ($outPath=='') return ['stat'=>500, 'body'=>'can\'t find folder after download from github.'];
|
||||
|
||||
return moveFolder($outPath, $projectPath);
|
||||
}
|
||||
|
||||
function moveFolder($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)){// 如果读取的某个对象是文件夹,则递归
|
||||
$response = moveFolder($fromfile, $tofile);
|
||||
if (api_error(setConfigResponse($response))) return $response;
|
||||
}else{
|
||||
if (file_exists($tofile)) unlink($tofile);
|
||||
$response = rename($fromfile, $tofile);
|
||||
if (!$response) {
|
||||
$tmp['code'] = "Move Failed";
|
||||
$tmp['message'] = "Can not move " . $fromfile . " to " . $tofile;
|
||||
return ['stat'=>500, 'body'=>json_encode($tmp)];
|
||||
}
|
||||
if (file_exists($fromfile)) unlink($fromfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handler);
|
||||
rmdir($from);
|
||||
return ['stat'=>200, 'body'=>'success.'];
|
||||
}
|
||||
|
||||
function WaitFunction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function changeAuthKey() {
|
||||
return message("Not need.", 'Change platform Auth token or key', 404);
|
||||
}
|
||||
|
||||
function smallfileupload($drive, $path) {
|
||||
if ($_FILES['file1']['error']) return output($_FILES['file1']['error'], 400);
|
||||
if ($_FILES['file1']['size']>4*1024*1024) return output('File too large', 400);
|
||||
return $drive->smallfileupload($path, $_FILES['file1']);
|
||||
}
|
|
@ -0,0 +1,379 @@
|
|||
<?php
|
||||
|
||||
function getpath()
|
||||
{
|
||||
$_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 ($_SERVER['REQUEST_SCHEME']!='http'&&$_SERVER['REQUEST_SCHEME']!='https') {
|
||||
if ($_SERVER['HTTP_X_FORWARDED_PROTO']!='') {
|
||||
$tmp = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0];
|
||||
if ($tmp=='http'||$tmp=='https') $_SERVER['REQUEST_SCHEME'] = $tmp;
|
||||
}
|
||||
if ($_SERVER['HTTP_FLY_FORWARDED_PROTO']!='') $_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_FLY_FORWARDED_PROTO'];
|
||||
}
|
||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['referhost'] = explode('/', $_SERVER['HTTP_REFERER'])[2];
|
||||
$_SERVER['base_path'] = '/';
|
||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
||||
else $path = $_SERVER['REQUEST_URI'];
|
||||
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
||||
return $path;
|
||||
}
|
||||
|
||||
function getGET()
|
||||
{
|
||||
if (!$_POST) {
|
||||
if (!!$HTTP_RAW_POST_DATA) {
|
||||
$tmpdata = $HTTP_RAW_POST_DATA;
|
||||
} else {
|
||||
$tmpdata = file_get_contents('php://input');
|
||||
}
|
||||
if (!!$tmpdata) {
|
||||
$postbody = explode("&", $tmpdata);
|
||||
foreach ($postbody as $postvalues) {
|
||||
$pos = strpos($postvalues,"=");
|
||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) {
|
||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
||||
$getstrarr = explode("&",$getstr);
|
||||
foreach ($getstrarr as $getvalues) {
|
||||
if ($getvalues != '') {
|
||||
$pos = strpos($getvalues, "=");
|
||||
//echo $pos;
|
||||
if ($pos > 0) {
|
||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
||||
} else {
|
||||
$getarry[urldecode($getvalues)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($getarry)) {
|
||||
return $getarry;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function ReplitAPI($op, $key, $value = '') {
|
||||
//error_log1($op . '_' . $key . '_' . $value);
|
||||
$apiurl = getenv('REPLIT_DB_URL');
|
||||
if ($op === 'r') {
|
||||
return curl('GET', $apiurl . '/' . $key);
|
||||
} elseif ($op === 'w') {
|
||||
return curl('POST', $apiurl, $key . '=' . $value, ["Content-Type"=>"application/x-www-form-urlencoded"]);
|
||||
} elseif ($op === 'd') {
|
||||
return curl('DELETE', $apiurl . '/' . $key);
|
||||
} else {
|
||||
return ['stat'=>500, 'body'=>'error option input to function ReplitAPI().'];
|
||||
}
|
||||
}
|
||||
|
||||
function getConfig($str, $disktag = '')
|
||||
{
|
||||
if (isInnerEnv($str)) {
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$env = json_decode(ReplitAPI('r', $disktag)['body'], true);
|
||||
if (isset($env[$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($env[$str]);
|
||||
else return $env[$str];
|
||||
}
|
||||
} else {
|
||||
if (isBase64Env($str)) return base64y_decode(ReplitAPI('r', $str)['body']);
|
||||
else return ReplitAPI('r', $str)['body'];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function setConfig($arr, $disktag = '')
|
||||
{
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$disktags = explode("|", getConfig('disktag'));
|
||||
if ($disktag!='') $diskconfig = json_decode(ReplitAPI('r', $disktag)['body'], true);
|
||||
$tmp = [];
|
||||
$indisk = 0;
|
||||
$operatedisk = 0;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (isCommonEnv($k)) {
|
||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
||||
else $tmp[$k] = $v;
|
||||
} elseif (isInnerEnv($k)) {
|
||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
||||
else $diskconfig[$k] = $v;
|
||||
$indisk = 1;
|
||||
} elseif ($k=='disktag_add') {
|
||||
array_push($disktags, $v);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_del') {
|
||||
$disktags = array_diff($disktags, [ $v ]);
|
||||
$tmp[$v] = '';
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_copy') {
|
||||
$newtag = $v . '_' . date("Ymd_His");
|
||||
$tmp[$newtag] = getConfig($v);
|
||||
array_push($disktags, $newtag);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
||||
} else {
|
||||
$tmp[$k] = json_encode($v);
|
||||
}
|
||||
}
|
||||
if ($indisk) {
|
||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||
ksort($diskconfig);
|
||||
$tmp[$disktag] = json_encode($diskconfig);
|
||||
}
|
||||
if ($operatedisk) {
|
||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
||||
$tags = [];
|
||||
foreach ($disktags as $tag) {
|
||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
||||
else array_push($tags, $tag);
|
||||
}
|
||||
$tmp['disktag'] = implode('|', $tags);
|
||||
$tmp[$arr['disktag_newname']] = getConfig($arr['disktag_rename']);
|
||||
$tmp[$arr['disktag_rename']] = null;
|
||||
} else {
|
||||
$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'] = null;
|
||||
}
|
||||
}
|
||||
$response = null;
|
||||
foreach ($tmp as $key => $val) {
|
||||
if (!!$val) $response = ReplitAPI('w', $key, $val);
|
||||
else $response = ReplitAPI('d', $key);
|
||||
if (api_error($response)) return ['stat'=>$response['stat'], 'body'=>$response['body'] . "<br>\nError in writting " . $key . "=" . $val];
|
||||
}
|
||||
//error_log1(json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($tmp, JSON_PRETTY_PRINT));
|
||||
return $response;
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
global $constStr;
|
||||
if ($_GET['install2']) {
|
||||
if ($_POST['admin']!='') {
|
||||
$tmp['admin'] = $_POST['admin'];
|
||||
//$tmp['language'] = $_COOKIE['language'];
|
||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
||||
$response = setConfigResponse( setConfig($tmp) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
} else {
|
||||
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 (!ConfigWriteable()) {
|
||||
$html .= getconstStr('MakesuerWriteable');
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
/*if (!RewriteEngineOn()) {
|
||||
$html .= getconstStr('MakesuerRewriteOn');
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
}*/
|
||||
$html .= '<button id="checkrewritebtn" onclick="checkrewrite();">'.getconstStr('MakesuerRewriteOn').'</button>
|
||||
<div id="formdiv" style="display: none">
|
||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
||||
<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"><br>
|
||||
<input id="submitbtn" type="submit" value="'.getconstStr('Submit').'" disabled>
|
||||
</form>
|
||||
</div>
|
||||
<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 notnull(t)
|
||||
{
|
||||
if (t.admin.value==\'\') {
|
||||
alert(\''.getconstStr('SetAdminPassword').'\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function checkrewrite()
|
||||
{
|
||||
url=location.protocol + "//" + location.host;
|
||||
//if (location.port!="") url += ":" + location.port;
|
||||
url += location.pathname;
|
||||
if (url.substr(-1)!="/") url += "/";
|
||||
url += "app.json";
|
||||
url += "?" + Date.now();
|
||||
var xhr4 = new XMLHttpRequest();
|
||||
xhr4.open("GET", url);
|
||||
xhr4.setRequestHeader("x-requested-with","XMLHttpRequest");
|
||||
xhr4.send(null);
|
||||
xhr4.onload = function(e){
|
||||
console.log(xhr4.responseText+","+xhr4.status);
|
||||
if (xhr4.status==201) {
|
||||
document.getElementById("checkrewritebtn").style.display = "none";
|
||||
document.getElementById("submitbtn").disabled = false;
|
||||
document.getElementById("formdiv").style.display = "";
|
||||
} else {
|
||||
alert("' . getconstStr('MakesuerRewriteOn') . '?\nfalse\n\nUrl: " + url + "\nExpect http code 201, but received " + xhr4.status);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>';
|
||||
$title = getconstStr('SetAdminPassword');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
if ($_GET['install0']) {
|
||||
$html .= '
|
||||
<form action="?install1" method="post">
|
||||
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>';
|
||||
}
|
||||
$html .= '
|
||||
<input type="submit" value="'.getconstStr('Submit').'">
|
||||
</form>
|
||||
<script>
|
||||
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;
|
||||
}
|
||||
</script>';
|
||||
$title = getconstStr('SelectLanguage');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
$title = 'Install';
|
||||
$html = '<a href="?install0">' . getconstStr('ClickInstall') . '</a>, ' . getconstStr('LogintoBind');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
function ConfigWriteable()
|
||||
{
|
||||
$t = md5( md5(time()).rand(1000,9999) );
|
||||
$r = setConfig([ 'tmp' => $t ]);
|
||||
$tmp = getConfig('tmp');
|
||||
setConfig([ 'tmp' => '' ]);
|
||||
if ($tmp == $t) return true;
|
||||
if ($r) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function api_error($response)
|
||||
{
|
||||
return !($response['stat']==200||$response['stat']==204||$response['stat']==404);
|
||||
//return isset($response['message']);
|
||||
}
|
||||
|
||||
function api_error_msg($response)
|
||||
{
|
||||
return '<pre>'. json_encode($response, JSON_PRETTY_PRINT).'</pre>' . '<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')
|
||||
{
|
||||
$slash = '/';
|
||||
if (strpos(__DIR__, ':')) $slash = '\\';
|
||||
// __DIR__ is xxx/platform
|
||||
$projectPath = splitlast(__DIR__, $slash)[0];
|
||||
|
||||
// 从github下载对应tar.gz,并解压
|
||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||
$tarfile = $projectPath . $slash .'github.tar.gz';
|
||||
$githubfile = file_get_contents($url);
|
||||
if (!$githubfile) return ['stat'=>500, 'body'=>'download error from github.'];
|
||||
file_put_contents($tarfile, $githubfile);
|
||||
if (splitfirst(PHP_VERSION, '.')[0] > '5') {
|
||||
$phar = new PharData($tarfile); // need php5.3, 7, 8
|
||||
$phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖
|
||||
} else {
|
||||
ob_start();
|
||||
passthru('tar -xzvf ' . $tarfile, $stat);
|
||||
ob_get_clean();
|
||||
}
|
||||
unlink($tarfile);
|
||||
|
||||
$outPath = '';
|
||||
$tmp = scandir($projectPath);
|
||||
$name = $auth . '-' . $project;
|
||||
foreach ($tmp as $f) {
|
||||
if ( substr($f, 0, strlen($name)) == $name) {
|
||||
$outPath = $projectPath . $slash . $f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//error_log1($outPath);
|
||||
if ($outPath=='') return ['stat'=>500, 'body'=>'can\'t find folder after download from github.'];
|
||||
|
||||
return moveFolder($outPath, $projectPath, $slash);
|
||||
}
|
||||
|
||||
function moveFolder($from, $to, $slash)
|
||||
{
|
||||
if (substr($from, -1)==$slash) $from = substr($from, 0, -1);
|
||||
if (substr($to, -1)==$slash) $to = substr($to, 0, -1);
|
||||
if (!file_exists($to)) mkdir($to, 0777);
|
||||
$handler=opendir($from);
|
||||
while($filename=readdir($handler)) {
|
||||
if($filename != '.' && $filename != '..'){
|
||||
$fromfile = $from . $slash . $filename;
|
||||
$tofile = $to . $slash . $filename;
|
||||
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
||||
$response = moveFolder($fromfile, $tofile, $slash);
|
||||
if (api_error(setConfigResponse($response))) return $response;
|
||||
}else{
|
||||
if (file_exists($tofile)) unlink($tofile);
|
||||
$response = rename($fromfile, $tofile);
|
||||
if (!$response) {
|
||||
$tmp['code'] = "Move Failed";
|
||||
$tmp['message'] = "Can not move " . $fromfile . " to " . $tofile;
|
||||
return ['stat'=>500, 'body'=>json_encode($tmp)];
|
||||
}
|
||||
if (file_exists($fromfile)) unlink($fromfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handler);
|
||||
rmdir($from);
|
||||
return ['stat'=>200, 'body'=>'success.'];
|
||||
}
|
||||
|
||||
function WaitFunction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function changeAuthKey() {
|
||||
return message("Not need.", 'Change platform Auth token or key', 404);
|
||||
}
|
|
@ -0,0 +1,668 @@
|
|||
<?php
|
||||
// https://cloud.tencent.com/document/product/583/33846
|
||||
// https://cloud.tencent.com/document/product/583/18581
|
||||
// https://cloud.tencent.com/document/product/583/18580
|
||||
|
||||
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['queryString'];
|
||||
$postbody = explode("&",$event['body']);
|
||||
foreach ($postbody as $postvalues) {
|
||||
$pos = strpos($postvalues,"=");
|
||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
||||
}
|
||||
$cookiebody = explode("; ",$event['headers']['cookie']);
|
||||
foreach ($cookiebody as $cookievalues) {
|
||||
$pos = strpos($cookievalues,"=");
|
||||
$_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1));
|
||||
}
|
||||
}
|
||||
|
||||
function GetPathSetting($event, $context)
|
||||
{
|
||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($event['headers']['accept-language'],';')[0],',')[0]);
|
||||
$_SERVER['function_name'] = $context['function_name'];
|
||||
$_SERVER['namespace'] = $context['namespace'];
|
||||
$_SERVER['Region'] = $context['tencentcloud_region'];
|
||||
$host_name = $event['headers']['host'];
|
||||
$_SERVER['HTTP_HOST'] = $host_name;
|
||||
$serviceId = $event['requestContext']['serviceId'];
|
||||
if ( $serviceId === substr($host_name,0,strlen($serviceId)) ) {
|
||||
$_SERVER['base_path'] = '/'.$event['requestContext']['stage'].'/'.$_SERVER['function_name'].'/';
|
||||
$path = substr($event['path'], strlen('/'.$_SERVER['function_name'].'/'));
|
||||
} else {
|
||||
$_SERVER['base_path'] = $event['requestContext']['path'];
|
||||
$path = substr($event['path'], strlen($event['requestContext']['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'];
|
||||
$_SERVER['HTTP_USER_AGENT'] = $event['headers']['user-agent'];
|
||||
if (isset($event['headers']['authorization'])) {
|
||||
$basicAuth = splitfirst(base64_decode(splitfirst($event['headers']['authorization'], 'Basic ')[1]), ':');
|
||||
$_SERVER['PHP_AUTH_USER'] = $basicAuth[0];
|
||||
$_SERVER['PHP_AUTH_PW'] = $basicAuth[1];
|
||||
}
|
||||
$_SERVER['REQUEST_SCHEME'] = $event['headers']['x-api-scheme'];
|
||||
//$_SERVER['REQUEST_SCHEME'] = $event['headers']['x-forwarded-proto'];
|
||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['referhost'] = explode('/', $event['headers']['referer'])[2];
|
||||
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
|
||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since'];
|
||||
$_SERVER['REQUEST_METHOD'] = $event['httpMethod'];
|
||||
$_SERVER['USER'] = 'qcloud';
|
||||
return $path;
|
||||
}
|
||||
|
||||
function getConfig($str, $disktag = '')
|
||||
{
|
||||
if (isInnerEnv($str)) {
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$env = json_decode(getenv($disktag), true);
|
||||
if (isset($env[$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($env[$str]);
|
||||
else return $env[$str];
|
||||
}
|
||||
} else {
|
||||
if (isBase64Env($str)) return base64y_decode(getenv($str));
|
||||
else return getenv($str);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function setConfig($arr, $disktag = '')
|
||||
{
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$disktags = explode("|",getConfig('disktag'));
|
||||
$diskconfig = json_decode(getenv($disktag), true);
|
||||
$tmp = [];
|
||||
$indisk = 0;
|
||||
$operatedisk = 0;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (isCommonEnv($k)) {
|
||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
||||
else $tmp[$k] = $v;
|
||||
} elseif (isInnerEnv($k)) {
|
||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
||||
else $diskconfig[$k] = $v;
|
||||
$indisk = 1;
|
||||
} elseif ($k=='disktag_add') {
|
||||
array_push($disktags, $v);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_del') {
|
||||
$disktags = array_diff($disktags, [ $v ]);
|
||||
$tmp[$v] = '';
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_copy') {
|
||||
$newtag = $v . '_' . date("Ymd_His");
|
||||
$tmp[$newtag] = getConfig($v);
|
||||
array_push($disktags, $newtag);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
||||
} else {
|
||||
$tmp[$k] = json_encode($v);
|
||||
}
|
||||
}
|
||||
if ($indisk) {
|
||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||
ksort($diskconfig);
|
||||
$tmp[$disktag] = json_encode($diskconfig);
|
||||
}
|
||||
if ($operatedisk) {
|
||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
||||
$tags = [];
|
||||
foreach ($disktags as $tag) {
|
||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
||||
else array_push($tags, $tag);
|
||||
}
|
||||
$tmp['disktag'] = implode('|', $tags);
|
||||
$tmp[$arr['disktag_newname']] = getConfig($arr['disktag_rename']);
|
||||
$tmp[$arr['disktag_rename']] = '';
|
||||
} else {
|
||||
$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, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'));
|
||||
WaitSCFStat();
|
||||
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()
|
||||
{
|
||||
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, 1);
|
||||
}
|
||||
return message(getconstStr('Success') . '
|
||||
<script>
|
||||
var expd = new Date();
|
||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
||||
var expires = "expires="+expd.toGMTString();
|
||||
document.cookie=\'language=; path=/; \'+expires;
|
||||
var i = 0;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>', 201, 1);
|
||||
}
|
||||
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;
|
||||
}
|
||||
$tmp['ONEMANAGER_CONFIG_SAVE'] = $_POST['ONEMANAGER_CONFIG_SAVE'];
|
||||
$response = json_decode(SetbaseConfig($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
} else {
|
||||
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, 1);
|
||||
}
|
||||
$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, 1);
|
||||
}
|
||||
}
|
||||
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.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>SecretKey:<input name="SecretKey" type="password" placeholder="" size=""></label><br>';
|
||||
$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').'">
|
||||
</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 SecretId\');
|
||||
return false;
|
||||
}
|
||||
if (t.SecretKey.value==\'\') {
|
||||
alert(\'input SecretKey\');
|
||||
return false;
|
||||
}';
|
||||
$html .= '
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
$title = getconstStr('SelectLanguage');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
$html .= '<a href="?install0">'.getconstStr('ClickInstall').'</a>, '.getconstStr('LogintoBind');
|
||||
$title = 'Install';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
function post2url($url, $data)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
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, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
//echo $response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
function ReorganizeDate($arr)
|
||||
{
|
||||
$str = '';
|
||||
ksort($arr);
|
||||
foreach ($arr as $k1 => $v1) {
|
||||
$str .= '&' . $k1 . '=' . $v1;
|
||||
}
|
||||
$str = substr($str, 1); // remove first '&'. 去掉第一个&
|
||||
return $str;
|
||||
}
|
||||
|
||||
function getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
||||
{
|
||||
//$meth = 'GET';
|
||||
$meth = 'POST';
|
||||
$host = 'scf.tencentcloudapi.com';
|
||||
$tmpdata['Action'] = 'GetFunction';
|
||||
$tmpdata['FunctionName'] = $function_name;
|
||||
$tmpdata['Namespace'] = $Namespace;
|
||||
$tmpdata['Nonce'] = time();
|
||||
$tmpdata['Region'] = $Region;
|
||||
$tmpdata['SecretId'] = $SecretId;
|
||||
$tmpdata['Timestamp'] = time();
|
||||
$tmpdata['Token'] = '';
|
||||
$tmpdata['Version'] = '2018-04-16';
|
||||
$data = ReorganizeDate($tmpdata);
|
||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
||||
//echo urlencode($signStr);
|
||||
//return file_get_contents('https://'.$url.'&Signature='.urlencode($signStr));
|
||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
||||
}
|
||||
|
||||
function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
||||
{
|
||||
//print_r($Envs);
|
||||
WaitSCFStat();
|
||||
//json_decode($a,true)['Response']['Environment']['Variables'][0]['Key']
|
||||
$tmp = json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Environment']['Variables'];
|
||||
foreach ($tmp as $tmp1) {
|
||||
$tmp_env[$tmp1['Key']] = $tmp1['Value'];
|
||||
}
|
||||
foreach ($Envs as $key1 => $value1) {
|
||||
$tmp_env[$key1] = $value1;
|
||||
}
|
||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
||||
//$tmp_env['Region'] = $Region;
|
||||
//ksort($tmp_env);
|
||||
sortConfig($tmp_env);
|
||||
|
||||
$i = 0;
|
||||
foreach ($tmp_env as $key1 => $value1) {
|
||||
$tmpdata['Environment.Variables.'.$i.'.Key'] = $key1;
|
||||
$tmpdata['Environment.Variables.'.$i.'.Value'] = $value1;
|
||||
$i++;
|
||||
}
|
||||
$meth = 'POST';
|
||||
$host = 'scf.tencentcloudapi.com';
|
||||
$tmpdata['Action'] = 'UpdateFunctionConfiguration';
|
||||
$tmpdata['FunctionName'] = $function_name;
|
||||
$tmpdata['Namespace'] = $Namespace;
|
||||
$tmpdata['Nonce'] = time();
|
||||
$tmpdata['Region'] = $Region;
|
||||
$tmpdata['SecretId'] = $SecretId;
|
||||
$tmpdata['Timestamp'] = time();
|
||||
$tmpdata['Token'] = '';
|
||||
$tmpdata['Version'] = '2018-04-16';
|
||||
$data = ReorganizeDate($tmpdata);
|
||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
||||
//echo urlencode($signStr);
|
||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
||||
}
|
||||
|
||||
function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
||||
{
|
||||
//echo json_encode($Envs,JSON_PRETTY_PRINT);
|
||||
if ($Envs['ONEMANAGER_CONFIG_SAVE'] == 'file') $Envs = Array( 'ONEMANAGER_CONFIG_SAVE' => 'file' );
|
||||
//json_decode($a,true)['Response']['Environment']['Variables'][0]['Key']
|
||||
$tmp = json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Environment']['Variables'];
|
||||
foreach ($tmp as $tmp1) {
|
||||
$tmp_env[$tmp1['Key']] = $tmp1['Value'];
|
||||
}
|
||||
foreach ($Envs as $key1 => $value1) {
|
||||
$tmp_env[$key1] = $value1;
|
||||
}
|
||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
||||
//$tmp_env['Region'] = $Region;
|
||||
ksort($tmp_env);
|
||||
|
||||
$i = 0;
|
||||
foreach ($tmp_env as $key1 => $value1) {
|
||||
$tmpdata['Environment.Variables.'.$i.'.Key'] = $key1;
|
||||
$tmpdata['Environment.Variables.'.$i.'.Value'] = $value1;
|
||||
$i++;
|
||||
}
|
||||
$meth = 'POST';
|
||||
$host = 'scf.tencentcloudapi.com';
|
||||
$tmpdata['Action'] = 'UpdateFunctionConfiguration';
|
||||
$tmpdata['FunctionName'] = $function_name;
|
||||
$tmpdata['Namespace'] = $Namespace;
|
||||
$tmpdata['Nonce'] = time();
|
||||
$tmpdata['Region'] = $Region;
|
||||
$tmpdata['SecretId'] = $SecretId;
|
||||
$tmpdata['Timestamp'] = time();
|
||||
$tmpdata['Token'] = '';
|
||||
$tmpdata['Version'] = '2018-04-16';
|
||||
$tmpdata['Description'] = 'Onedrive index and manager in Tencent SCF.';
|
||||
$tmpdata['MemorySize'] = 64;
|
||||
$tmpdata['Timeout'] = 30;
|
||||
$data = ReorganizeDate($tmpdata);
|
||||
echo $data;
|
||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
||||
//echo urlencode($signStr);
|
||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
||||
}
|
||||
|
||||
function updateProgram_OLD($function_name, $Region, $Namespace, $SecretId, $SecretKey, $source)
|
||||
{
|
||||
WaitSCFStat();
|
||||
$meth = 'POST';
|
||||
$host = 'scf.tencentcloudapi.com';
|
||||
$tmpdata['Action'] = 'UpdateFunctionCode';
|
||||
$tmpdata['Code.GitUrl'] = $source['url'];
|
||||
$tmpdata['Code.GitBranch'] = $source['branch'];
|
||||
$tmpdata['CodeSource'] = 'Git';
|
||||
$tmpdata['FunctionName'] = $function_name;
|
||||
$tmpdata['Handler'] = 'index.main_handler';
|
||||
$tmpdata['Namespace'] = $Namespace;
|
||||
$tmpdata['Nonce'] = time();
|
||||
$tmpdata['Region'] = $Region;
|
||||
$tmpdata['SecretId'] = $SecretId;
|
||||
$tmpdata['Timestamp'] = time();
|
||||
$tmpdata['Token'] = '';
|
||||
$tmpdata['Version'] = '2018-04-16';
|
||||
$data = ReorganizeDate($tmpdata);
|
||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
||||
//echo urlencode($signStr);
|
||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
||||
}
|
||||
|
||||
function api_error($response)
|
||||
{
|
||||
return isset($response['Error']);
|
||||
}
|
||||
|
||||
function api_error_msg($response)
|
||||
{
|
||||
return $response['Error']['Code'] . '<br>
|
||||
' . $response['Error']['Message'] . '<br><br>
|
||||
function_name:' . $_SERVER['function_name'] . '<br>
|
||||
Region:' . $_SERVER['Region'] . '<br>
|
||||
namespace:' . $_SERVER['namespace'] . '<br>
|
||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
||||
}
|
||||
|
||||
function setConfigResponse($response)
|
||||
{
|
||||
return json_decode( $response, true )['Response'];
|
||||
}
|
||||
|
||||
function WaitFunction() {
|
||||
//$trynum = 0;
|
||||
//while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']!='Active' ) echo '
|
||||
//'.++$trynum;
|
||||
if ( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']=='Active' ) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
function updateProgram($function_name, $Region, $Namespace, $SecretId, $SecretKey, $source)
|
||||
{
|
||||
$secretId = $SecretId;
|
||||
$secretKey = $SecretKey;
|
||||
$host = 'scf.tencentcloudapi.com';
|
||||
$service = "scf";
|
||||
$version = "2018-04-16";
|
||||
$action = "UpdateFunctionCode";
|
||||
$region = $Region;
|
||||
$timestamp = time();
|
||||
$algorithm = "TC3-HMAC-SHA256";
|
||||
|
||||
// step 1: build canonical request string
|
||||
$httpRequestMethod = "POST";
|
||||
$canonicalUri = "/";
|
||||
$canonicalQueryString = "";
|
||||
$canonicalHeaders = "content-type:application/json; charset=utf-8\n"."host:".$host."\n";
|
||||
$signedHeaders = "content-type;host";
|
||||
|
||||
//$tmpdata['Action'] = 'UpdateFunctionCode';
|
||||
$tmpdata['Code']['ZipFile'] = base64_encode( file_get_contents($source) );
|
||||
$tmpdata['CodeSource'] = 'ZipFile';
|
||||
$tmpdata['FunctionName'] = $function_name;
|
||||
$tmpdata['Handler'] = 'index.main_handler';
|
||||
//$tmpdata['Namespace'] = $Namespace;
|
||||
//$tmpdata['Nonce'] = time();
|
||||
//$tmpdata['Region'] = $Region;
|
||||
//$tmpdata['SecretId'] = $SecretId;
|
||||
//$tmpdata['Timestamp'] = time();
|
||||
//$tmpdata['Token'] = '';
|
||||
//$tmpdata['Version'] = '2018-04-16';
|
||||
$payload = json_encode($tmpdata);
|
||||
//$payload = '{"Limit": 1, "Filters": [{"Values": ["\u672a\u547d\u540d"], "Name": "instance-name"}]}';
|
||||
$hashedRequestPayload = hash("SHA256", $payload);
|
||||
$canonicalRequest = $httpRequestMethod."\n"
|
||||
.$canonicalUri."\n"
|
||||
.$canonicalQueryString."\n"
|
||||
.$canonicalHeaders."\n"
|
||||
.$signedHeaders."\n"
|
||||
.$hashedRequestPayload;
|
||||
//echo $canonicalRequest.PHP_EOL;
|
||||
|
||||
// step 2: build string to sign
|
||||
$date = gmdate("Y-m-d", $timestamp);
|
||||
$credentialScope = $date."/".$service."/tc3_request";
|
||||
$hashedCanonicalRequest = hash("SHA256", $canonicalRequest);
|
||||
$stringToSign = $algorithm."\n"
|
||||
.$timestamp."\n"
|
||||
.$credentialScope."\n"
|
||||
.$hashedCanonicalRequest;
|
||||
//echo $stringToSign.PHP_EOL;
|
||||
|
||||
// step 3: sign string
|
||||
$secretDate = hash_hmac("SHA256", $date, "TC3".$secretKey, true);
|
||||
$secretService = hash_hmac("SHA256", $service, $secretDate, true);
|
||||
$secretSigning = hash_hmac("SHA256", "tc3_request", $secretService, true);
|
||||
$signature = hash_hmac("SHA256", $stringToSign, $secretSigning);
|
||||
//echo $signature.PHP_EOL;
|
||||
|
||||
// step 4: build authorization
|
||||
$authorization = $algorithm
|
||||
." Credential=".$secretId."/".$credentialScope
|
||||
.", SignedHeaders=content-type;host, Signature=".$signature;
|
||||
//echo $authorization.PHP_EOL;
|
||||
|
||||
//$curl = "curl -X POST https://".$host
|
||||
// .' -H "Authorization: '.$authorization.'"'
|
||||
// .' -H "Content-Type: application/json; charset=utf-8"'
|
||||
// .' -H "Host: '.$host.'"'
|
||||
// .' -H "X-TC-Action: '.$action.'"'
|
||||
// .' -H "X-TC-Timestamp: '.$timestamp.'"'
|
||||
// .' -H "X-TC-Version: '.$version.'"'
|
||||
// .' -H "X-TC-Region: '.$region.'"'
|
||||
// ." -d '".$payload."'";
|
||||
//error_log1( $curl.PHP_EOL );
|
||||
//return '{"response": {"Error": {"Message":"' . $curl . '"}}}';
|
||||
$headers['Authorization'] = $authorization;
|
||||
$headers['Content-Type'] = 'application/json; charset=utf-8';
|
||||
$headers['Host'] = $host;
|
||||
$headers['X-TC-Action'] = $action;
|
||||
$headers['X-TC-Timestamp'] = $timestamp;
|
||||
$headers['X-TC-Version'] = $version;
|
||||
$headers['X-TC-Region'] = $region;
|
||||
return curl('POST', 'https://'.$host, $payload, $headers)['body'];
|
||||
}
|
||||
|
||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||
{
|
||||
$source = '/tmp/code.zip';
|
||||
$outPath = '/tmp/';
|
||||
|
||||
if ($GitSource=='Github') {
|
||||
// 从github下载对应tar.gz,并解压
|
||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||
} elseif ($GitSource=='HITGitlab') {
|
||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
||||
} else return json_encode(['Response'=>['Error'=>['code'=>'Git Source input Error!']]]);
|
||||
$tarfile = '/tmp/github.tar.gz';
|
||||
file_put_contents($tarfile, file_get_contents($url));
|
||||
$phar = new PharData($tarfile);
|
||||
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
||||
|
||||
// 获取解压出的目录名
|
||||
$outPath = findIndexPath($outPath);
|
||||
|
||||
// 将目录中文件打包成zip
|
||||
//$zip=new ZipArchive();
|
||||
$zip=new PharData($source);
|
||||
//if($zip->open($source, ZipArchive::CREATE)){
|
||||
addFileToZip($zip, $outPath); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
|
||||
// $zip->close(); //关闭处理的zip文件
|
||||
//}
|
||||
|
||||
return updateProgram($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], 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($handler);
|
||||
}
|
||||
|
||||
function changeAuthKey() {
|
||||
if ($_POST['SecretId']!=''&&$_POST['SecretId']!='') {
|
||||
$tmp['SecretId'] = $_POST['SecretId'];
|
||||
$tmp['SecretKey'] = $_POST['SecretKey'];
|
||||
$response = setConfigResponse( SetbaseConfig($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $tmp['SecretId'], $tmp['SecretKey']) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 400);
|
||||
} else {
|
||||
$html = getconstStr('Success') . '
|
||||
<script>
|
||||
var status = "' . $response['DplStatus'] . '";
|
||||
var i = 0;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
}
|
||||
$html = '
|
||||
<form action="" method="post" onsubmit="return notnull(this);">
|
||||
<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>SecretKey:<input name="SecretKey" type="password" placeholder="" size=""></label><br>
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
</form>
|
||||
<script>
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.SecretId.value==\'\') {
|
||||
alert(\'input SecretId\');
|
||||
return false;
|
||||
}
|
||||
if (t.SecretKey.value==\'\') {
|
||||
alert(\'input SecretKey\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
return message($html, 'Change platform Auth token or key', 200);
|
||||
}
|
||||
|
||||
function smallfileupload($drive, $path) {
|
||||
return output('Can not upload through SCF.', 400);
|
||||
}
|
|
@ -0,0 +1,711 @@
|
|||
<?php
|
||||
// https://cloud.tencent.com/document/product/583/33846
|
||||
// https://cloud.tencent.com/document/product/583/18581
|
||||
// https://cloud.tencent.com/document/product/583/18580
|
||||
|
||||
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['queryString'];
|
||||
$postbody = explode("&",$event['body']);
|
||||
foreach ($postbody as $postvalues) {
|
||||
$pos = strpos($postvalues,"=");
|
||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
||||
}
|
||||
$cookiebody = explode("; ",$event['headers']['cookie']);
|
||||
foreach ($cookiebody as $cookievalues) {
|
||||
$pos = strpos($cookievalues,"=");
|
||||
$_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1));
|
||||
}
|
||||
}
|
||||
|
||||
function GetPathSetting($event, $context)
|
||||
{
|
||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($event['headers']['accept-language'],';')[0],',')[0]);
|
||||
$_SERVER['function_name'] = $context['function_name'];
|
||||
$_SERVER['namespace'] = $context['namespace'];
|
||||
$_SERVER['Region'] = $context['tencentcloud_region'];
|
||||
$host_name = $event['headers']['host'];
|
||||
$_SERVER['HTTP_HOST'] = $host_name;
|
||||
$serviceId = $event['requestContext']['serviceId'];
|
||||
if ( $serviceId === substr($host_name,0,strlen($serviceId)) ) {
|
||||
$_SERVER['base_path'] = '/'.$event['requestContext']['stage'].'/'.$_SERVER['function_name'].'/';
|
||||
$path = substr($event['path'], strlen('/'.$_SERVER['function_name'].'/'));
|
||||
} else {
|
||||
$_SERVER['base_path'] = $event['requestContext']['path'];
|
||||
$path = substr($event['path'], strlen($event['requestContext']['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'];
|
||||
$_SERVER['HTTP_USER_AGENT'] = $event['headers']['user-agent'];
|
||||
if (isset($event['headers']['authorization'])) {
|
||||
$basicAuth = splitfirst(base64_decode(splitfirst($event['headers']['authorization'], 'Basic ')[1]), ':');
|
||||
$_SERVER['PHP_AUTH_USER'] = $basicAuth[0];
|
||||
$_SERVER['PHP_AUTH_PW'] = $basicAuth[1];
|
||||
}
|
||||
$_SERVER['REQUEST_SCHEME'] = $event['headers']['x-api-scheme'];
|
||||
//$_SERVER['REQUEST_SCHEME'] = $event['headers']['x-forwarded-proto'];
|
||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['referhost'] = explode('/', $event['headers']['referer'])[2];
|
||||
$_SERVER['HTTP_TRANSLATE'] = $event['headers']['translate'];//'f'
|
||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $event['headers']['if-modified-since'];
|
||||
$_SERVER['REQUEST_METHOD'] = $event['httpMethod'];
|
||||
$_SERVER['USER'] = 'qcloud';
|
||||
return $path;
|
||||
}
|
||||
|
||||
function getConfig($str, $disktag = '')
|
||||
{
|
||||
//include 'config.php';
|
||||
$s = file_get_contents('.data/config.php');
|
||||
//$configs = substr($s, 18, -2);
|
||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||
if ($configs!='') {
|
||||
$envs = json_decode($configs, true);
|
||||
if (isInnerEnv($str)) {
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
if (isset($envs[$disktag][$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($envs[$disktag][$str]);
|
||||
else return $envs[$disktag][$str];
|
||||
}
|
||||
} else {
|
||||
if (isset($envs[$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($envs[$str]);
|
||||
else return $envs[$str];
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function setConfig($arr, $disktag = '')
|
||||
{
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
//include 'config.php';
|
||||
$s = file_get_contents('.data/config.php');
|
||||
//$configs = substr($s, 18, -2);
|
||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||
if ($configs!='') $envs = json_decode($configs, true);
|
||||
$disktags = explode("|",getConfig('disktag'));
|
||||
$indisk = 0;
|
||||
$operatedisk = 0;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (isCommonEnv($k)) {
|
||||
if (isBase64Env($k)) $envs[$k] = base64y_encode($v);
|
||||
else $envs[$k] = $v;
|
||||
} elseif (isInnerEnv($k)) {
|
||||
if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v);
|
||||
else $envs[$disktag][$k] = $v;
|
||||
$indisk = 1;
|
||||
} elseif ($k=='disktag_add') {
|
||||
array_push($disktags, $v);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_del') {
|
||||
$disktags = array_diff($disktags, [ $v ]);
|
||||
$envs[$v] = '';
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_copy') {
|
||||
$newtag = $v . '_' . date("Ymd_His");
|
||||
$envs[$newtag] = $envs[$v];
|
||||
array_push($disktags, $newtag);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
||||
} else {
|
||||
$envs[$k] = $v;
|
||||
}
|
||||
}
|
||||
if ($indisk) {
|
||||
$diskconfig = $envs[$disktag];
|
||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||
ksort($diskconfig);
|
||||
$envs[$disktag] = $diskconfig;
|
||||
}
|
||||
if ($operatedisk) {
|
||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
||||
$tags = [];
|
||||
foreach ($disktags as $tag) {
|
||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
||||
else array_push($tags, $tag);
|
||||
}
|
||||
$envs['disktag'] = implode('|', $tags);
|
||||
$envs[$arr['disktag_newname']] = $envs[$arr['disktag_rename']];
|
||||
$envs[$arr['disktag_rename']] = '';
|
||||
} else {
|
||||
$disktags = array_unique($disktags);
|
||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
||||
if ($disktag_s!='') $envs['disktag'] = substr($disktag_s, 0, -1);
|
||||
else $envs['disktag'] = '';
|
||||
}
|
||||
}
|
||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
||||
//ksort($envs);
|
||||
$response = updateEnvironment($envs, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'));
|
||||
WaitSCFStat($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'));
|
||||
return $response;
|
||||
}
|
||||
|
||||
function WaitSCFStat($function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
||||
{
|
||||
$trynum = 0;
|
||||
while( json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Status']!='Active' ) echo '
|
||||
'.++$trynum;
|
||||
}
|
||||
|
||||
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, 1);
|
||||
}
|
||||
return message(getconstStr('Success') . '
|
||||
<script>
|
||||
var expd = new Date();
|
||||
expd.setTime(expd.getTime()+(2*60*60*1000));
|
||||
var expires = "expires="+expd.toGMTString();
|
||||
document.cookie=\'language=; path=/; \'+expires;
|
||||
var i = 0;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>', 201, 1);
|
||||
}
|
||||
if ($_GET['install1']) {
|
||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
||||
$SecretId = $_POST['SecretId'];
|
||||
$tmp['SecretId'] = $SecretId;
|
||||
$SecretKey = $_POST['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'];
|
||||
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_ENV') . '<br><a href="' . $_SERVER['base_path'] . '">' . getconstStr('Home') . '</a>';
|
||||
$title = 'Reinstall';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
$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, 1);
|
||||
}
|
||||
}
|
||||
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.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>SecretKey:<input name="SecretKey" type="password" placeholder="" size=""></label><br>';
|
||||
$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').'">
|
||||
</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 SecretId\');
|
||||
return false;
|
||||
}
|
||||
if (t.SecretKey.value==\'\') {
|
||||
alert(\'input SecretKey\');
|
||||
return false;
|
||||
}';
|
||||
$html .= '
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
$title = getconstStr('SelectLanguage');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
$html .= '<a href="?install0">'.getconstStr('ClickInstall').'</a>, '.getconstStr('LogintoBind');
|
||||
$title = 'Install';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
function post2url($url, $data)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
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, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
//echo $response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
function ReorganizeDate($arr)
|
||||
{
|
||||
$str = '';
|
||||
ksort($arr);
|
||||
foreach ($arr as $k1 => $v1) {
|
||||
$str .= '&' . $k1 . '=' . $v1;
|
||||
}
|
||||
$str = substr($str, 1); // remove first '&'. 去掉第一个&
|
||||
return $str;
|
||||
}
|
||||
|
||||
function getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
||||
{
|
||||
//$meth = 'GET';
|
||||
$meth = 'POST';
|
||||
$host = 'scf.tencentcloudapi.com';
|
||||
$tmpdata['Action'] = 'GetFunction';
|
||||
$tmpdata['FunctionName'] = $function_name;
|
||||
$tmpdata['Namespace'] = $Namespace;
|
||||
$tmpdata['Nonce'] = time();
|
||||
$tmpdata['Region'] = $Region;
|
||||
$tmpdata['SecretId'] = $SecretId;
|
||||
$tmpdata['Timestamp'] = time();
|
||||
$tmpdata['Token'] = '';
|
||||
$tmpdata['Version'] = '2018-04-16';
|
||||
$data = ReorganizeDate($tmpdata);
|
||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
||||
//echo urlencode($signStr);
|
||||
//return file_get_contents('https://'.$url.'&Signature='.urlencode($signStr));
|
||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
||||
}
|
||||
|
||||
function getfunctioncodeurl($function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
||||
{
|
||||
//$meth = 'GET';
|
||||
$meth = 'POST';
|
||||
$host = 'scf.tencentcloudapi.com';
|
||||
$tmpdata['Action'] = 'GetFunctionAddress';
|
||||
$tmpdata['FunctionName'] = $function_name;
|
||||
$tmpdata['Namespace'] = $Namespace;
|
||||
$tmpdata['Nonce'] = time();
|
||||
$tmpdata['Region'] = $Region;
|
||||
$tmpdata['SecretId'] = $SecretId;
|
||||
$tmpdata['Timestamp'] = time();
|
||||
$tmpdata['Token'] = '';
|
||||
$tmpdata['Version'] = '2018-04-16';
|
||||
$data = ReorganizeDate($tmpdata);
|
||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
||||
//echo urlencode($signStr);
|
||||
//return file_get_contents('https://'.$url.'&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)
|
||||
{
|
||||
sortConfig($Envs);
|
||||
// 获取当前代码并解压
|
||||
//$codeurl = json_decode(getfunctioncodeurl($function_name, $Region, $Namespace, $SecretId, $SecretKey), true)['Response']['Url'];
|
||||
//$codezip = '/tmp/oldcode.zip';
|
||||
$outPath = '/tmp/code/';
|
||||
|
||||
//file_put_contents($codezip, file_get_contents($codeurl));
|
||||
//$zip=new ZipArchive();
|
||||
//$zip->open($codezip);
|
||||
//$html = $zip->extractTo($outPath);
|
||||
|
||||
$coderoot = __DIR__ . '/../';
|
||||
copyFolder($coderoot, $outPath);
|
||||
|
||||
// 将配置写入
|
||||
$prestr = '<?php $configs = \'' . PHP_EOL;
|
||||
$aftstr = PHP_EOL . '\';';
|
||||
file_put_contents($outPath . '.data/config.php', $prestr . json_encode($Envs, JSON_PRETTY_PRINT) . $aftstr);
|
||||
|
||||
// 将目录中文件打包成zip
|
||||
$source = '/tmp/code.zip';
|
||||
//$zip=new ZipArchive();
|
||||
$zip=new PharData($source);
|
||||
//if($zip->open($source, ZipArchive::CREATE)){
|
||||
addFileToZip($zip, $outPath); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
|
||||
// $zip->close(); //关闭处理的zip文件
|
||||
//}
|
||||
|
||||
return updateProgram($function_name, $Region, $namespace, $SecretId, $SecretKey, $source);
|
||||
$tmp1['Response']['Error']['Message'] = $codeurl;
|
||||
error_log1($tmp1['Response']['Error']['Message']);
|
||||
return json_encode($tmp1);
|
||||
}
|
||||
|
||||
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';
|
||||
$host = 'scf.tencentcloudapi.com';
|
||||
$tmpdata['Action'] = 'UpdateFunctionConfiguration';
|
||||
$tmpdata['FunctionName'] = $function_name;
|
||||
$tmpdata['Namespace'] = $Namespace;
|
||||
$tmpdata['Nonce'] = time();
|
||||
$tmpdata['Region'] = $Region;
|
||||
$tmpdata['SecretId'] = $SecretId;
|
||||
$tmpdata['Timestamp'] = time();
|
||||
$tmpdata['Token'] = '';
|
||||
$tmpdata['Version'] = '2018-04-16';
|
||||
$tmpdata['Description'] = 'Onedrive index and manager in Tencent SCF.';
|
||||
$tmpdata['MemorySize'] = 64;
|
||||
$tmpdata['Timeout'] = 30;
|
||||
$data = ReorganizeDate($tmpdata);
|
||||
//echo $data;
|
||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
||||
//echo urlencode($signStr);
|
||||
$response = post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
||||
if (api_error(setConfigResponse($response))) {
|
||||
return $response;
|
||||
}
|
||||
if ( json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Timeout'] < 25 ) {
|
||||
$tmp['Response']['Error']['Message'] = 'Operating, please try again.';
|
||||
$tmp['Response']['Error']['Code'] = 'Retry';
|
||||
return json_encode($tmp);
|
||||
}
|
||||
WaitSCFStat($function_name, $Region, $Namespace, $SecretId, $SecretKey);
|
||||
|
||||
$s = file_get_contents('.data/config.php');
|
||||
//$configs = substr($s, 18, -2);
|
||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||
if ($configs!='') $envs = json_decode($configs, true);
|
||||
foreach ($Envs as $k => $v) {
|
||||
$envs[$k] = $v;
|
||||
}
|
||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
||||
//ksort($envs);
|
||||
$response = updateEnvironment($envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey);
|
||||
return $response;
|
||||
}
|
||||
|
||||
function updateProgram($function_name, $Region, $Namespace, $SecretId, $SecretKey, $source)
|
||||
{
|
||||
$secretId = $SecretId;
|
||||
$secretKey = $SecretKey;
|
||||
$host = 'scf.tencentcloudapi.com';
|
||||
$service = "scf";
|
||||
$version = "2018-04-16";
|
||||
$action = "UpdateFunctionCode";
|
||||
$region = $Region;
|
||||
$timestamp = time();
|
||||
$algorithm = "TC3-HMAC-SHA256";
|
||||
|
||||
// step 1: build canonical request string
|
||||
$httpRequestMethod = "POST";
|
||||
$canonicalUri = "/";
|
||||
$canonicalQueryString = "";
|
||||
$canonicalHeaders = "content-type:application/json; charset=utf-8\n"."host:".$host."\n";
|
||||
$signedHeaders = "content-type;host";
|
||||
|
||||
//$tmpdata['Action'] = 'UpdateFunctionCode';
|
||||
$tmpdata['Code']['ZipFile'] = base64_encode( file_get_contents($source) );
|
||||
$tmpdata['CodeSource'] = 'ZipFile';
|
||||
$tmpdata['FunctionName'] = $function_name;
|
||||
$tmpdata['Handler'] = 'index.main_handler';
|
||||
//$tmpdata['Namespace'] = $Namespace;
|
||||
//$tmpdata['Nonce'] = time();
|
||||
//$tmpdata['Region'] = $Region;
|
||||
//$tmpdata['SecretId'] = $SecretId;
|
||||
//$tmpdata['Timestamp'] = time();
|
||||
//$tmpdata['Token'] = '';
|
||||
//$tmpdata['Version'] = '2018-04-16';
|
||||
$payload = json_encode($tmpdata);
|
||||
//$payload = '{"Limit": 1, "Filters": [{"Values": ["\u672a\u547d\u540d"], "Name": "instance-name"}]}';
|
||||
$hashedRequestPayload = hash("SHA256", $payload);
|
||||
$canonicalRequest = $httpRequestMethod."\n"
|
||||
.$canonicalUri."\n"
|
||||
.$canonicalQueryString."\n"
|
||||
.$canonicalHeaders."\n"
|
||||
.$signedHeaders."\n"
|
||||
.$hashedRequestPayload;
|
||||
//echo $canonicalRequest.PHP_EOL;
|
||||
|
||||
// step 2: build string to sign
|
||||
$date = gmdate("Y-m-d", $timestamp);
|
||||
$credentialScope = $date."/".$service."/tc3_request";
|
||||
$hashedCanonicalRequest = hash("SHA256", $canonicalRequest);
|
||||
$stringToSign = $algorithm."\n"
|
||||
.$timestamp."\n"
|
||||
.$credentialScope."\n"
|
||||
.$hashedCanonicalRequest;
|
||||
//echo $stringToSign.PHP_EOL;
|
||||
|
||||
// step 3: sign string
|
||||
$secretDate = hash_hmac("SHA256", $date, "TC3".$secretKey, true);
|
||||
$secretService = hash_hmac("SHA256", $service, $secretDate, true);
|
||||
$secretSigning = hash_hmac("SHA256", "tc3_request", $secretService, true);
|
||||
$signature = hash_hmac("SHA256", $stringToSign, $secretSigning);
|
||||
//echo $signature.PHP_EOL;
|
||||
|
||||
// step 4: build authorization
|
||||
$authorization = $algorithm
|
||||
." Credential=".$secretId."/".$credentialScope
|
||||
.", SignedHeaders=content-type;host, Signature=".$signature;
|
||||
//echo $authorization.PHP_EOL;
|
||||
|
||||
//$curl = "curl -X POST https://".$host
|
||||
// .' -H "Authorization: '.$authorization.'"'
|
||||
// .' -H "Content-Type: application/json; charset=utf-8"'
|
||||
// .' -H "Host: '.$host.'"'
|
||||
// .' -H "X-TC-Action: '.$action.'"'
|
||||
// .' -H "X-TC-Timestamp: '.$timestamp.'"'
|
||||
// .' -H "X-TC-Version: '.$version.'"'
|
||||
// .' -H "X-TC-Region: '.$region.'"'
|
||||
// ." -d '".$payload."'";
|
||||
//error_log1( $curl.PHP_EOL );
|
||||
//return '{"response": {"Error": {"Message":"' . $curl . '"}}}';
|
||||
$headers['Authorization'] = $authorization;
|
||||
$headers['Content-Type'] = 'application/json; charset=utf-8';
|
||||
$headers['Host'] = $host;
|
||||
$headers['X-TC-Action'] = $action;
|
||||
$headers['X-TC-Timestamp'] = $timestamp;
|
||||
$headers['X-TC-Version'] = $version;
|
||||
$headers['X-TC-Region'] = $region;
|
||||
return curl('POST', 'https://'.$host, $payload, $headers)['body'];
|
||||
}
|
||||
|
||||
function api_error($response)
|
||||
{
|
||||
return isset($response['Error']);
|
||||
return ($response==null)||isset($response['Error']);
|
||||
}
|
||||
|
||||
function api_error_msg($response)
|
||||
{
|
||||
return $response['Error']['Code'] . '<br>
|
||||
' . $response['Error']['Message'] . '<br><br>
|
||||
function_name:' . $_SERVER['function_name'] . '<br>
|
||||
Region:' . $_SERVER['Region'] . '<br>
|
||||
namespace:' . $_SERVER['namespace'] . '<br>
|
||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
||||
}
|
||||
|
||||
function setConfigResponse($response)
|
||||
{
|
||||
return json_decode( $response, true )['Response'];
|
||||
}
|
||||
|
||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||
{
|
||||
$source = '/tmp/code.zip';
|
||||
$outPath = '/tmp/';
|
||||
|
||||
if ($GitSource=='Github') {
|
||||
// 从github下载对应tar.gz,并解压
|
||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||
} elseif ($GitSource=='HITGitlab') {
|
||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
||||
} else return json_encode(['Response'=>['Error'=>['code'=>'Git Source input Error!']]]);
|
||||
$tarfile = '/tmp/github.tar.gz';
|
||||
file_put_contents($tarfile, file_get_contents($url));
|
||||
$phar = new PharData($tarfile);
|
||||
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
|
||||
|
||||
// 获取解压出的目录名
|
||||
$outPath = findIndexPath($outPath);
|
||||
|
||||
// 放入配置文件
|
||||
file_put_contents($outPath . '/.data/config.php', file_get_contents(__DIR__ . '/../.data/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($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], 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($handler);
|
||||
}
|
||||
|
||||
function WaitFunction() {
|
||||
if ( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey')),true)['Response']['Status']=='Active' ) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
function changeAuthKey() {
|
||||
if ($_POST['SecretId']!=''&&$_POST['SecretId']!='') {
|
||||
$tmp['SecretId'] = $_POST['SecretId'];
|
||||
$tmp['SecretKey'] = $_POST['SecretKey'];
|
||||
$response = setConfigResponse( SetbaseConfig($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $tmp['SecretId'], $tmp['SecretKey']) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 400);
|
||||
} else {
|
||||
$html = getconstStr('Success') . '
|
||||
<script>
|
||||
var status = "' . $response['DplStatus'] . '";
|
||||
var i = 0;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
}
|
||||
$html = '
|
||||
<form action="" method="post" onsubmit="return notnull(this);">
|
||||
<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>SecretKey:<input name="SecretKey" type="password" placeholder="" size=""></label><br>
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
</form>
|
||||
<script>
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.SecretId.value==\'\') {
|
||||
alert(\'input SecretId\');
|
||||
return false;
|
||||
}
|
||||
if (t.SecretKey.value==\'\') {
|
||||
alert(\'input SecretKey\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
return message($html, 'Change platform Auth token or key', 200);
|
||||
}
|
||||
|
||||
function smallfileupload($drive, $path) {
|
||||
return output('Can not upload through SCF.', 400);
|
||||
}
|
|
@ -0,0 +1,497 @@
|
|||
<?php
|
||||
// https://vercel.com/docs/api#endpoints/deployments/create-a-new-deployment
|
||||
|
||||
function getpath()
|
||||
{
|
||||
$_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_FLY_CLIENT_IP'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_FLY_CLIENT_IP'];
|
||||
if ($_SERVER['REQUEST_SCHEME']!='http'&&$_SERVER['REQUEST_SCHEME']!='https') {
|
||||
if ($_SERVER['HTTP_X_FORWARDED_PROTO']!='') {
|
||||
$tmp = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0];
|
||||
if ($tmp=='http'||$tmp=='https') $_SERVER['REQUEST_SCHEME'] = $tmp;
|
||||
}
|
||||
if ($_SERVER['HTTP_FLY_FORWARDED_PROTO']!='') $_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_FLY_FORWARDED_PROTO'];
|
||||
}
|
||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['referhost'] = explode('/', $_SERVER['HTTP_REFERER'])[2];
|
||||
$_SERVER['base_path'] = "/";
|
||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
||||
else $path = $_SERVER['REQUEST_URI'];
|
||||
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
||||
$_SERVER['DOCUMENT_ROOT'] = '/var/task/user';
|
||||
return $path;
|
||||
}
|
||||
|
||||
function getGET()
|
||||
{
|
||||
if (!$_POST) {
|
||||
if (!!$HTTP_RAW_POST_DATA) {
|
||||
$tmpdata = $HTTP_RAW_POST_DATA;
|
||||
} else {
|
||||
$tmpdata = file_get_contents('php://input');
|
||||
}
|
||||
if (!!$tmpdata) {
|
||||
$postbody = explode("&", $tmpdata);
|
||||
foreach ($postbody as $postvalues) {
|
||||
$pos = strpos($postvalues,"=");
|
||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) {
|
||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
||||
$getstrarr = explode("&",$getstr);
|
||||
foreach ($getstrarr as $getvalues) {
|
||||
if ($getvalues != '') {
|
||||
$pos = strpos($getvalues, "=");
|
||||
//echo $pos;
|
||||
if ($pos > 0) {
|
||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
||||
} else {
|
||||
$getarry[urldecode($getvalues)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($getarry)) {
|
||||
return $getarry;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function getConfig($str, $disktag = '')
|
||||
{
|
||||
$projectPath = splitlast(__DIR__, '/')[0];
|
||||
$configPath = $projectPath . '/.data/config.php';
|
||||
$s = file_get_contents($configPath);
|
||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||
if ($configs!='') {
|
||||
$envs = json_decode($configs, true);
|
||||
if (isInnerEnv($str)) {
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
if (isset($envs[$disktag][$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($envs[$disktag][$str]);
|
||||
else return $envs[$disktag][$str];
|
||||
}
|
||||
} else {
|
||||
if (isset($envs[$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($envs[$str]);
|
||||
else return $envs[$str];
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function setConfig($arr, $disktag = '')
|
||||
{
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$projectPath = splitlast(__DIR__, '/')[0];
|
||||
$configPath = $projectPath . '/.data/config.php';
|
||||
$s = file_get_contents($configPath);
|
||||
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
|
||||
if ($configs!='') $envs = json_decode($configs, true);
|
||||
$disktags = explode("|",getConfig('disktag'));
|
||||
$indisk = 0;
|
||||
$operatedisk = 0;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (isCommonEnv($k)) {
|
||||
if (isBase64Env($k)) $envs[$k] = base64y_encode($v);
|
||||
else $envs[$k] = $v;
|
||||
} elseif (isInnerEnv($k)) {
|
||||
if (isBase64Env($k)) $envs[$disktag][$k] = base64y_encode($v);
|
||||
else $envs[$disktag][$k] = $v;
|
||||
$indisk = 1;
|
||||
} elseif ($k=='disktag_add') {
|
||||
array_push($disktags, $v);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_del') {
|
||||
$disktags = array_diff($disktags, [ $v ]);
|
||||
$envs[$v] = '';
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_copy') {
|
||||
$newtag = $v . '_' . date("Ymd_His");
|
||||
$envs[$newtag] = $envs[$v];
|
||||
array_push($disktags, $newtag);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
||||
} else {
|
||||
$envs[$k] = $v;
|
||||
}
|
||||
}
|
||||
if ($indisk) {
|
||||
$diskconfig = $envs[$disktag];
|
||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||
ksort($diskconfig);
|
||||
$envs[$disktag] = $diskconfig;
|
||||
}
|
||||
if ($operatedisk) {
|
||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
||||
$tags = [];
|
||||
foreach ($disktags as $tag) {
|
||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
||||
else array_push($tags, $tag);
|
||||
}
|
||||
$envs['disktag'] = implode('|', $tags);
|
||||
$envs[$arr['disktag_newname']] = $envs[$arr['disktag_rename']];
|
||||
$envs[$arr['disktag_rename']] = '';
|
||||
} else {
|
||||
$disktags = array_unique($disktags);
|
||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
||||
if ($disktag_s!='') $envs['disktag'] = substr($disktag_s, 0, -1);
|
||||
else $envs['disktag'] = '';
|
||||
}
|
||||
}
|
||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
||||
//ksort($envs);
|
||||
//sortConfig($envs);
|
||||
//error_log1(json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($envs, JSON_PRETTY_PRINT));
|
||||
//echo json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($envs, JSON_PRETTY_PRINT);
|
||||
return setVercelConfig($envs, getConfig('HerokuappId'), getConfig('APIKey'));
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
global $constStr;
|
||||
if ($_GET['install1']) {
|
||||
if ($_POST['admin']!='') {
|
||||
$tmp['admin'] = $_POST['admin'];
|
||||
//$tmp['language'] = $_POST['language'];
|
||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
||||
$APIKey = $_POST['APIKey'];
|
||||
//if ($APIKey=='') {
|
||||
// $APIKey = getConfig('APIKey');
|
||||
//}
|
||||
$tmp['APIKey'] = $APIKey;
|
||||
|
||||
$token = $APIKey;
|
||||
$header["Authorization"] = "Bearer " . $token;
|
||||
$header["Content-Type"] = "application/json";
|
||||
$aliases = json_decode(curl("GET", "https://api.vercel.com/v3/now/aliases", "", $header)['body'], true);
|
||||
$host = splitfirst($_SERVER["host"], "//")[1];
|
||||
foreach ($aliases["aliases"] as $key => $aliase) {
|
||||
if ($host==$aliase["alias"]) $projectId = $aliase["projectId"];
|
||||
}
|
||||
$tmp['HerokuappId'] = $projectId;
|
||||
|
||||
$response = json_decode(setVercelConfig($tmp, $projectId, $APIKey), true);
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 400);
|
||||
} else {
|
||||
$html = getconstStr('Success') . '
|
||||
<script>
|
||||
var status = "' . $response['DplStatus'] . '";
|
||||
var i = 0;
|
||||
var expd = new Date();
|
||||
expd.setTime(expd.getTime()+1000);
|
||||
var expires = "expires="+expd.toGMTString();
|
||||
document.cookie=\'language=; path=/; \'+expires;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
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>';
|
||||
}
|
||||
$html .= '<br>
|
||||
<a href="https://vercel.com/account/tokens" target="_blank">' . getconstStr('Create') . ' token</a><br>
|
||||
<label>Token:<input name="APIKey" type="password" placeholder="" value=""></label><br>';
|
||||
$html .= '<br>
|
||||
<label>Set admin password:<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>';
|
||||
$html .= '
|
||||
<input type="submit" value="'.getconstStr('Submit').'">
|
||||
</form>
|
||||
<div id="showerror"></div>
|
||||
<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;
|
||||
var errordiv = document.getElementById("showerror");
|
||||
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 (t.admin.value==\'\') {
|
||||
alert(\'input admin\');
|
||||
return false;
|
||||
}
|
||||
if (t.APIKey.value==\'\') {
|
||||
alert(\'input Token\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
$title = getconstStr('SelectLanguage');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
if (substr($_SERVER["host"], -10)=="vercel.app") {
|
||||
$html .= '<a href="?install0">' . getconstStr('ClickInstall') . '</a>, ' . getconstStr('LogintoBind');
|
||||
$html .= "<br>Remember: you MUST wait 30-60s after each operate / do some change, that make sure Vercel has done the building<br>" ;
|
||||
} else {
|
||||
$html.= "Please visit form *.vercel.app";
|
||||
}
|
||||
$title = 'Install';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
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, 1);
|
||||
$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 setVercelConfig($envs, $appId, $token)
|
||||
{
|
||||
sortConfig($envs);
|
||||
$outPath = '/tmp/code/';
|
||||
$outPath_Api = $outPath . 'api/';
|
||||
$coderoot = __DIR__;
|
||||
$coderoot = splitlast($coderoot, '/')[0] . '/';
|
||||
//echo $outPath_Api . '<br>' . $coderoot . '<br>';
|
||||
copyFolder($coderoot, $outPath_Api);
|
||||
$prestr = '<?php $configs = \'' . PHP_EOL;
|
||||
$aftstr = PHP_EOL . '\';';
|
||||
file_put_contents($outPath_Api . '.data/config.php', $prestr . json_encode($envs, JSON_PRETTY_PRINT) . $aftstr);
|
||||
|
||||
return VercelUpdate($appId, $token, $outPath);
|
||||
}
|
||||
|
||||
function VercelUpdate($appId, $token, $sourcePath = "")
|
||||
{
|
||||
if (checkBuilding($appId, $token)) return '{"error":{"message":"Another building is in progress."}}';
|
||||
$url = "https://api.vercel.com/v13/deployments";
|
||||
$header["Authorization"] = "Bearer " . $token;
|
||||
$header["Content-Type"] = "application/json";
|
||||
$data["name"] = "OneManager";
|
||||
$data["project"] = $appId;
|
||||
$data["target"] = "production";
|
||||
$data["routes"][0]["src"] = "/(.*)";
|
||||
$data["routes"][0]["dest"] = "/api/index.php";
|
||||
$data["functions"]["api/index.php"]["runtime"] = "vercel-php@0.4.0";
|
||||
if ($sourcePath=="") $sourcePath = splitlast(splitlast(__DIR__, "/")[0], "/")[0];
|
||||
//echo $sourcePath . "<br>";
|
||||
getEachFiles($file, $sourcePath);
|
||||
$data["files"] = $file;
|
||||
|
||||
//echo json_encode($data, JSON_PRETTY_PRINT) . " ,data<br>";
|
||||
$response = curl("POST", $url, json_encode($data), $header);
|
||||
//echo json_encode($response, JSON_PRETTY_PRINT) . " ,res<br>";
|
||||
$result = json_decode($response["body"], true);
|
||||
$result['DplStatus'] = $result['id'];
|
||||
return json_encode($result);
|
||||
}
|
||||
|
||||
function checkBuilding($projectId, $token)
|
||||
{
|
||||
$r = 0;
|
||||
$url = "https://api.vercel.com/v6/deployments/?projectId=" . $projectId;
|
||||
$header["Authorization"] = "Bearer " . $token;
|
||||
$header["Content-Type"] = "application/json";
|
||||
$response = curl("GET", $url, '', $header);
|
||||
//echo json_encode($response, JSON_PRETTY_PRINT) . " ,res<br>";
|
||||
$result = json_decode($response["body"], true);
|
||||
foreach ( $result['deployments'] as $deployment ) {
|
||||
if ($deployment['state']!=="READY") $r++;
|
||||
}
|
||||
return $r;
|
||||
//if ($r===0) return true;
|
||||
//else return false;
|
||||
}
|
||||
|
||||
function getEachFiles(&$file, $base, $path = "")
|
||||
{
|
||||
//if (substr($base, -1)=="/") $base = substr($base, 0, -1);
|
||||
//if (substr($path, -1)=="/") $path = substr($path, 0, -1);
|
||||
$handler=opendir(path_format($base . "/" . $path));
|
||||
while($filename=readdir($handler)) {
|
||||
if($filename != '.' && $filename != '..' && $filename != '.git'){
|
||||
$fromfile = path_format($base . "/" . $path . "/" . $filename);
|
||||
//echo $fromfile . "<br>";
|
||||
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
||||
$response = getEachFiles($file, $base, path_format($path . "/" . $filename));
|
||||
if (api_error(setConfigResponse($response))) return $response;
|
||||
}else{
|
||||
$tmp['file'] = path_format($path . "/" . $filename);
|
||||
$tmp['data'] = file_get_contents($fromfile);
|
||||
$file[] = $tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handler);
|
||||
|
||||
return json_encode( [ 'response' => 'success' ] );
|
||||
}
|
||||
|
||||
function api_error($response)
|
||||
{
|
||||
return isset($response['error']);
|
||||
}
|
||||
|
||||
function api_error_msg($response)
|
||||
{
|
||||
return $response['error']['code'] . '<br>
|
||||
' . $response['error']['message'] . '<br>
|
||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
||||
}
|
||||
|
||||
function setConfigResponse($response)
|
||||
{
|
||||
return json_decode($response, true);
|
||||
}
|
||||
|
||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||
{
|
||||
$tmppath = '/tmp';
|
||||
|
||||
if ($GitSource=='Github') {
|
||||
// 从github下载对应tar.gz,并解压
|
||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||
} elseif ($GitSource=='HITGitlab') {
|
||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
||||
} else return json_encode(['error'=>['code'=>'Git Source input Error!']]);
|
||||
|
||||
$tarfile = $tmppath . '/github.tar.gz';
|
||||
file_put_contents($tarfile, file_get_contents($url));
|
||||
$phar = new PharData($tarfile);
|
||||
$html = $phar->extractTo($tmppath, null, true);//路径 要解压的文件 是否覆盖
|
||||
unlink($tarfile);
|
||||
|
||||
// 获取解压出的目录名
|
||||
$outPath = findIndexPath($tmppath);
|
||||
|
||||
if ($outPath=='') return '{"error":{"message":"no outpath"}}';
|
||||
$name = $project . 'CODE';
|
||||
mkdir($tmppath . "/" . $name, 0777, 1);
|
||||
rename($outPath, $tmppath . "/" . $name . '/api');
|
||||
$outPath = $tmppath . "/" . $name;
|
||||
//echo $outPath . "<br>";
|
||||
//error_log1($outPath);
|
||||
|
||||
// put in config
|
||||
$coderoot = __DIR__;
|
||||
$coderoot = splitlast($coderoot, '/')[0] . '/';
|
||||
copy($coderoot . '.data/config.php', $outPath . '/api/.data/config.php');
|
||||
|
||||
return VercelUpdate(getConfig('HerokuappId'), getConfig('APIKey'), $outPath);
|
||||
}
|
||||
|
||||
function WaitFunction($deployid = '') {
|
||||
if ($buildId=='1') {
|
||||
$tmp['stat'] = 400;
|
||||
$tmp['body'] = 'id must provided.';
|
||||
return $tmp;
|
||||
}
|
||||
$header["Authorization"] = "Bearer " . getConfig('APIKey');
|
||||
$header["Content-Type"] = "application/json";
|
||||
$url = "https://api.vercel.com/v11/deployments/" . $deployid;
|
||||
$response = curl("GET", $url, "", $header);
|
||||
if ($response['stat']==200) {
|
||||
$result = json_decode($response['body'], true);
|
||||
if ($result['readyState']=="READY") return true;
|
||||
if ($result['readyState']=="ERROR") return $response;
|
||||
return false;
|
||||
} else {
|
||||
$response['body'] .= $url;
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
function changeAuthKey() {
|
||||
if ($_POST['APIKey']!='') {
|
||||
$APIKey = $_POST['APIKey'];
|
||||
$tmp['APIKey'] = $APIKey;
|
||||
$response = setConfigResponse( setVercelConfig($tmp, getConfig('HerokuappId'), $APIKey) );
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 400);
|
||||
} else {
|
||||
$html = getconstStr('Success') . '
|
||||
<script>
|
||||
var status = "' . $response['DplStatus'] . '";
|
||||
var i = 0;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
}
|
||||
$html = '
|
||||
<form action="" method="post" onsubmit="return notnull(this);">
|
||||
<a href="https://vercel.com/account/tokens" target="_blank">' . getconstStr('Create') . ' token</a><br>
|
||||
<label>Token:<input name="APIKey" type="password" placeholder="" value=""></label><br>
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
</form>
|
||||
<script>
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.APIKey.value==\'\') {
|
||||
alert(\'Input Token\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
return message($html, 'Change platform Auth token or key', 200);
|
||||
}
|
||||
|
||||
function smallfileupload($drive, $path) {
|
||||
if ($_FILES['file1']['error']) return output($_FILES['file1']['error'], 400);
|
||||
if ($_FILES['file1']['size']>4*1024*1024) return output('File too large', 400);
|
||||
return $drive->smallfileupload($path, $_FILES['file1']);
|
||||
}
|
|
@ -0,0 +1,473 @@
|
|||
<?php
|
||||
// https://vercel.com/docs/api#endpoints/deployments/create-a-new-deployment
|
||||
|
||||
function getpath()
|
||||
{
|
||||
$_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_FLY_CLIENT_IP'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_FLY_CLIENT_IP'];
|
||||
if ($_SERVER['REQUEST_SCHEME']!='http'&&$_SERVER['REQUEST_SCHEME']!='https') {
|
||||
if ($_SERVER['HTTP_X_FORWARDED_PROTO']!='') {
|
||||
$tmp = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0];
|
||||
if ($tmp=='http'||$tmp=='https') $_SERVER['REQUEST_SCHEME'] = $tmp;
|
||||
}
|
||||
if ($_SERVER['HTTP_FLY_FORWARDED_PROTO']!='') $_SERVER['REQUEST_SCHEME'] = $_SERVER['HTTP_FLY_FORWARDED_PROTO'];
|
||||
}
|
||||
$_SERVER['host'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['referhost'] = explode('/', $_SERVER['HTTP_REFERER'])[2];
|
||||
$_SERVER['base_path'] = "/";
|
||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
||||
else $path = $_SERVER['REQUEST_URI'];
|
||||
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
||||
$_SERVER['DOCUMENT_ROOT'] = '/var/task/user';
|
||||
return $path;
|
||||
}
|
||||
|
||||
function getGET()
|
||||
{
|
||||
if (!$_POST) {
|
||||
if (!!$HTTP_RAW_POST_DATA) {
|
||||
$tmpdata = $HTTP_RAW_POST_DATA;
|
||||
} else {
|
||||
$tmpdata = file_get_contents('php://input');
|
||||
}
|
||||
if (!!$tmpdata) {
|
||||
$postbody = explode("&", $tmpdata);
|
||||
foreach ($postbody as $postvalues) {
|
||||
$pos = strpos($postvalues,"=");
|
||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) {
|
||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
||||
$getstrarr = explode("&",$getstr);
|
||||
foreach ($getstrarr as $getvalues) {
|
||||
if ($getvalues != '') {
|
||||
$pos = strpos($getvalues, "=");
|
||||
//echo $pos;
|
||||
if ($pos > 0) {
|
||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
||||
} else {
|
||||
$getarry[urldecode($getvalues)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($getarry)) {
|
||||
return $getarry;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function getConfig($str, $disktag = '')
|
||||
{
|
||||
if (isInnerEnv($str)) {
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$tmp = getenv($disktag);
|
||||
if (is_array($tmp)) $env = $tmp;
|
||||
else $env = json_decode($tmp, true);
|
||||
if (isset($env[$str])) {
|
||||
if (isBase64Env($str)) return base64y_decode($env[$str]);
|
||||
else return $env[$str];
|
||||
}
|
||||
} else {
|
||||
if (isBase64Env($str)) return base64y_decode(getenv($str));
|
||||
else return getenv($str);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function setConfig($arr, $disktag = '')
|
||||
{
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
$disktags = explode("|", getenv('disktag'));
|
||||
if ($disktag!='') {
|
||||
$tmp = getenv($disktag);
|
||||
if (is_array($tmp)) $diskconfig = $tmp;
|
||||
else $diskconfig = json_decode($tmp, true);
|
||||
}
|
||||
$tmp = [];
|
||||
$indisk = 0;
|
||||
$operatedisk = 0;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (isCommonEnv($k)) {
|
||||
if (isBase64Env($k)) $tmp[$k] = base64y_encode($v);
|
||||
else $tmp[$k] = $v;
|
||||
} elseif (isInnerEnv($k)) {
|
||||
if (isBase64Env($k)) $diskconfig[$k] = base64y_encode($v);
|
||||
else $diskconfig[$k] = $v;
|
||||
$indisk = 1;
|
||||
} elseif ($k=='disktag_add') {
|
||||
array_push($disktags, $v);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_del') {
|
||||
$disktags = array_diff($disktags, [ $v ]);
|
||||
$tmp[$v] = '';
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_copy') {
|
||||
$newtag = $v . '_' . date("Ymd_His");
|
||||
$tagvalue = getenv($v);
|
||||
if (is_array($tagvalue)) $tmp[$newtag] = json_encode($tagvalue);
|
||||
else $tmp[$newtag] = $tagvalue;
|
||||
array_push($disktags, $newtag);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_rename' || $k=='disktag_newname') {
|
||||
if ($arr['disktag_rename']!=$arr['disktag_newname']) $operatedisk = 1;
|
||||
} else {
|
||||
$tmp[$k] = json_encode($v);
|
||||
}
|
||||
}
|
||||
if ($indisk) {
|
||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||
ksort($diskconfig);
|
||||
$tmp[$disktag] = json_encode($diskconfig);
|
||||
}
|
||||
if ($operatedisk) {
|
||||
if (isset($arr['disktag_newname']) && $arr['disktag_newname']!='') {
|
||||
$tags = [];
|
||||
foreach ($disktags as $tag) {
|
||||
if ($tag==$arr['disktag_rename']) array_push($tags, $arr['disktag_newname']);
|
||||
else array_push($tags, $tag);
|
||||
}
|
||||
$tmp['disktag'] = implode('|', $tags);
|
||||
$tagvalue = getenv($arr['disktag_rename']);
|
||||
if (is_array($tagvalue)) $tmp[$arr['disktag_newname']] = json_encode($tagvalue);
|
||||
else $tmp[$arr['disktag_newname']] = $tagvalue;
|
||||
$tmp[$arr['disktag_rename']] = null;
|
||||
} else {
|
||||
$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'] = null;
|
||||
}
|
||||
}
|
||||
foreach ($tmp as $key => $val) if ($val=='') $tmp[$key]=null;
|
||||
|
||||
//error_log1(json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($tmp, JSON_PRETTY_PRINT));
|
||||
//echo json_encode($arr, JSON_PRETTY_PRINT) . ' => tmp:' . json_encode($tmp, JSON_PRETTY_PRINT);
|
||||
return setVercelConfig($tmp, getConfig('HerokuappId'), getConfig('APIKey'));
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
global $constStr;
|
||||
if ($_GET['install1']) {
|
||||
if ($_POST['admin']!='') {
|
||||
$tmp['admin'] = $_POST['admin'];
|
||||
//$tmp['language'] = $_POST['language'];
|
||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
||||
$APIKey = $_POST['APIKey'];
|
||||
$tmp['APIKey'] = $APIKey;
|
||||
|
||||
$token = $APIKey;
|
||||
$header["Authorization"] = "Bearer " . $token;
|
||||
$header["Content-Type"] = "application/json";
|
||||
$aliases = json_decode(curl("GET", "https://api.vercel.com/v3/now/aliases", "", $header)['body'], true);
|
||||
$host = splitfirst($_SERVER["host"], "//")[1];
|
||||
foreach ($aliases["aliases"] as $key => $aliase) {
|
||||
if ($host==$aliase["alias"]) $projectId = $aliase["projectId"];
|
||||
}
|
||||
$tmp['HerokuappId'] = $projectId;
|
||||
|
||||
$response = json_decode(setVercelConfig($tmp, $projectId, $APIKey), true);
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 400);
|
||||
} else {
|
||||
$html = getconstStr('Success') . '
|
||||
<script>
|
||||
var status = "' . $response['DplStatus'] . '";
|
||||
var i = 0;
|
||||
var expd = new Date();
|
||||
expd.setTime(expd.getTime()+1000);
|
||||
var expires = "expires="+expd.toGMTString();
|
||||
document.cookie=\'language=; path=/; \'+expires;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
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>';
|
||||
}
|
||||
$html .= '<br>
|
||||
<a href="https://vercel.com/account/tokens" target="_blank">' . getconstStr('Create') . ' token</a><br>
|
||||
<label>Token:<input name="APIKey" type="password" placeholder="" value=""></label><br>';
|
||||
$html .= '<br>
|
||||
<label>Set admin password:<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>';
|
||||
$html .= '
|
||||
<input type="submit" value="'.getconstStr('Submit').'">
|
||||
</form>
|
||||
<div id="showerror"></div>
|
||||
<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;
|
||||
var errordiv = document.getElementById("showerror");
|
||||
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 (t.admin.value==\'\') {
|
||||
alert(\'input admin\');
|
||||
return false;
|
||||
}
|
||||
if (t.APIKey.value==\'\') {
|
||||
alert(\'input Token\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
$title = getconstStr('SelectLanguage');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
if (substr($_SERVER["host"], -10)=="vercel.app") {
|
||||
$html .= '<a href="?install0">' . getconstStr('ClickInstall') . '</a>, ' . getconstStr('LogintoBind');
|
||||
$html .= "<br>Remember: you MUST wait 30-60s after each operate / do some change, that make sure Vercel has done the building<br>" ;
|
||||
} else {
|
||||
$html.= "Please visit form *.vercel.app";
|
||||
}
|
||||
$title = 'Install';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
|
||||
// POST /v8/projects/:id/env
|
||||
function setVercelConfig($envs, $appId, $token)
|
||||
{
|
||||
$url = "https://api.vercel.com/v8/projects/" . $appId . "/env";
|
||||
$header["Authorization"] = "Bearer " . $token;
|
||||
$header["Content-Type"] = "application/json";
|
||||
$response = curl("GET", $url, "", $header);
|
||||
$result = json_decode($response['body'], true);
|
||||
foreach ($result["envs"] as $key => $value) {
|
||||
$existEnvs[$value["key"]] = $value["id"];
|
||||
}
|
||||
foreach ($envs as $key => $value) {
|
||||
$response = null;
|
||||
$tmp = null;
|
||||
$tmp["type"] = "encrypted";
|
||||
$tmp["key"] = $key;
|
||||
$tmp["value"] = $value;
|
||||
$tmp["target"] = [ "development", "production", "preview" ];
|
||||
if (isset($existEnvs[$key])) {
|
||||
if ($value) $response = curl("PATCH", $url . "/" . $existEnvs[$key], json_encode($tmp), $header);
|
||||
else $response = curl("DELETE", $url . "/" . $existEnvs[$key], "", $header);
|
||||
} else {
|
||||
if ($value) $response = curl("POST", $url, json_encode($tmp), $header);
|
||||
}
|
||||
//echo $key . " = " . $value . ", <br>" . $response . json_encode($response, JSON_PRETTY_PRINT) . "<br>";
|
||||
if (!!$response && $response['stat']!=200) return $response['body'];
|
||||
}
|
||||
return VercelUpdate($appId, $token);
|
||||
}
|
||||
|
||||
function VercelUpdate($appId, $token, $sourcePath = "")
|
||||
{
|
||||
if (checkBuilding($appId, $token)) return '{"error":{"message":"Another building is in progress."}}';
|
||||
$url = "https://api.vercel.com/v13/deployments";
|
||||
$header["Authorization"] = "Bearer " . $token;
|
||||
$header["Content-Type"] = "application/json";
|
||||
$data["name"] = "OneManager";
|
||||
$data["project"] = $appId;
|
||||
$data["target"] = "production";
|
||||
$data["routes"][0]["src"] = "/(.*)";
|
||||
$data["routes"][0]["dest"] = "/api/index.php";
|
||||
$data["functions"]["api/index.php"]["runtime"] = "vercel-php@0.4.0";
|
||||
if ($sourcePath=="") $sourcePath = splitlast(splitlast(__DIR__, "/")[0], "/")[0];
|
||||
//echo $sourcePath . "<br>";
|
||||
getEachFiles($file, $sourcePath);
|
||||
$data["files"] = $file;
|
||||
|
||||
//echo json_encode($data, JSON_PRETTY_PRINT) . " ,data<br>";
|
||||
$response = curl("POST", $url, json_encode($data), $header);
|
||||
//echo json_encode($response, JSON_PRETTY_PRINT) . " ,res<br>";
|
||||
$result = json_decode($response["body"], true);
|
||||
$result['DplStatus'] = $result['id'];
|
||||
return json_encode($result);
|
||||
}
|
||||
|
||||
function checkBuilding($projectId, $token)
|
||||
{
|
||||
$r = 0;
|
||||
$url = "https://api.vercel.com/v6/deployments/?projectId=" . $projectId;
|
||||
$header["Authorization"] = "Bearer " . $token;
|
||||
$header["Content-Type"] = "application/json";
|
||||
$response = curl("GET", $url, '', $header);
|
||||
//echo json_encode($response, JSON_PRETTY_PRINT) . " ,res<br>";
|
||||
$result = json_decode($response["body"], true);
|
||||
foreach ( $result['deployments'] as $deployment ) {
|
||||
if ($deployment['state']!=="READY") $r++;
|
||||
}
|
||||
return $r;
|
||||
//if ($r===0) return true;
|
||||
//else return false;
|
||||
}
|
||||
|
||||
function getEachFiles(&$file, $base, $path = "")
|
||||
{
|
||||
//if (substr($base, -1)=="/") $base = substr($base, 0, -1);
|
||||
//if (substr($path, -1)=="/") $path = substr($path, 0, -1);
|
||||
$handler=opendir(path_format($base . "/" . $path));
|
||||
while($filename=readdir($handler)) {
|
||||
if($filename != '.' && $filename != '..' && $filename != '.git'){
|
||||
$fromfile = path_format($base . "/" . $path . "/" . $filename);
|
||||
//echo $fromfile . "<br>";
|
||||
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
||||
$response = getEachFiles($file, $base, path_format($path . "/" . $filename));
|
||||
if (api_error(setConfigResponse($response))) return $response;
|
||||
}else{
|
||||
$tmp['file'] = path_format($path . "/" . $filename);
|
||||
$tmp['data'] = file_get_contents($fromfile);
|
||||
$file[] = $tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handler);
|
||||
|
||||
return json_encode( [ 'response' => 'success' ] );
|
||||
}
|
||||
|
||||
function api_error($response)
|
||||
{
|
||||
return isset($response['error']);
|
||||
}
|
||||
|
||||
function api_error_msg($response)
|
||||
{
|
||||
return $response['error']['code'] . '<br>
|
||||
' . $response['error']['message'] . '<br>
|
||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
||||
}
|
||||
|
||||
function setConfigResponse($response)
|
||||
{
|
||||
return json_decode($response, true);
|
||||
}
|
||||
|
||||
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||
{
|
||||
$tmppath = '/tmp';
|
||||
|
||||
if ($GitSource=='Github') {
|
||||
// 从github下载对应tar.gz,并解压
|
||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||
} elseif ($GitSource=='HITGitlab') {
|
||||
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
|
||||
} else return json_encode(['error'=>['code'=>'Git Source input Error!']]);
|
||||
|
||||
$tarfile = $tmppath . '/github.tar.gz';
|
||||
file_put_contents($tarfile, file_get_contents($url));
|
||||
$phar = new PharData($tarfile);
|
||||
$html = $phar->extractTo($tmppath, null, true);//路径 要解压的文件 是否覆盖
|
||||
unlink($tarfile);
|
||||
|
||||
// 获取解压出的目录名
|
||||
$outPath = findIndexPath($tmppath);
|
||||
|
||||
if ($outPath=='') return '{"error":{"message":"no outpath"}}';
|
||||
$name = $project . 'CODE';
|
||||
mkdir($tmppath . "/" . $name, 0777, 1);
|
||||
rename($outPath, $tmppath . "/" . $name . '/api');
|
||||
$outPath = $tmppath . "/" . $name;
|
||||
//echo $outPath . "<br>";
|
||||
//error_log1($outPath);
|
||||
|
||||
return VercelUpdate(getConfig('HerokuappId'), getConfig('APIKey'), $outPath);
|
||||
}
|
||||
|
||||
function WaitFunction($deployid) {
|
||||
if ($buildId=='1') {
|
||||
$tmp['stat'] = 400;
|
||||
$tmp['body'] = 'id must provided.';
|
||||
return $tmp;
|
||||
}
|
||||
$header["Authorization"] = "Bearer " . getConfig('APIKey');
|
||||
$header["Content-Type"] = "application/json";
|
||||
$url = "https://api.vercel.com/v11/deployments/" . $deployid;
|
||||
$response = curl("GET", $url, "", $header);
|
||||
if ($response['stat']==200) {
|
||||
$result = json_decode($response['body'], true);
|
||||
if ($result['readyState']=="READY") return true;
|
||||
if ($result['readyState']=="ERROR") return $response;
|
||||
return false;
|
||||
} else {
|
||||
$response['body'] .= $url;
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
function changeAuthKey() {
|
||||
if ($_POST['APIKey']!='') {
|
||||
$APIKey = $_POST['APIKey'];
|
||||
$tmp['APIKey'] = $APIKey;
|
||||
$response = json_decode(setVercelConfig($tmp, getConfig('HerokuappId'), $APIKey), true);
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 400);
|
||||
} else {
|
||||
$html = getconstStr('Success') . '
|
||||
<script>
|
||||
var status = "' . $response['DplStatus'] . '";
|
||||
var i = 0;
|
||||
var uploadList = setInterval(function(){
|
||||
if (document.getElementById("dis").style.display=="none") {
|
||||
console.log(i++);
|
||||
} else {
|
||||
clearInterval(uploadList);
|
||||
location.href = "' . path_format($_SERVER['base_path'] . '/') . '";
|
||||
}
|
||||
}, 1000);
|
||||
</script>';
|
||||
return message($html, $title, 201, 1);
|
||||
}
|
||||
}
|
||||
$html = '
|
||||
<form action="" method="post" onsubmit="return notnull(this);">
|
||||
<a href="https://vercel.com/account/tokens" target="_blank">' . getconstStr('Create') . ' token</a><br>
|
||||
<label>Token:<input name="APIKey" type="password" placeholder="" value=""></label><br>
|
||||
<input type="submit" value="' . getconstStr('Submit') . '">
|
||||
</form>
|
||||
<script>
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.APIKey.value==\'\') {
|
||||
alert(\'Input Token\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>';
|
||||
return message($html, 'Change platform Auth token or key', 200);
|
||||
}
|
|
@ -1,260 +0,0 @@
|
|||
<?php
|
||||
|
||||
function getpath()
|
||||
{
|
||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($_SERVER['HTTP_ACCEPT_LANGUAGE'],';')[0],',')[0]);
|
||||
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
$_SERVER['base_path'] = path_format(substr($_SERVER['SCRIPT_NAME'], 0, -10) . '/');
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
||||
else $path = $_SERVER['REQUEST_URI'];
|
||||
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
||||
return substr($path, 1);
|
||||
//return spurlencode($path, '/');
|
||||
}
|
||||
|
||||
function getGET()
|
||||
{
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) {
|
||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
||||
$getstrarr = explode("&",$getstr);
|
||||
foreach ($getstrarr as $getvalues) {
|
||||
if ($getvalues != '') {
|
||||
$pos = strpos($getvalues, "=");
|
||||
//echo $pos;
|
||||
if ($pos > 0) {
|
||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
||||
} else {
|
||||
$getarry[urldecode($getvalues)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($getarry)) {
|
||||
return $getarry;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
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 equal_replace($env[$str],1);
|
||||
else return $env[$str];
|
||||
}
|
||||
} else {
|
||||
if (in_array($str, $Base64Env)) return equal_replace(getenv($str),1);
|
||||
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] = equal_replace($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] = equal_replace($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'] = '';
|
||||
}
|
||||
foreach ($tmp as $key => $val) if ($val=='') $tmp[$key]=null;
|
||||
// echo '正式设置:'.json_encode($tmp,JSON_PRETTY_PRINT).'
|
||||
//';
|
||||
return setHerokuConfig($tmp, getConfig('function_name'), getConfig('APIKey'));
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
global $constStr;
|
||||
if ($_GET['install1']) {
|
||||
if ($_POST['admin']!='') {
|
||||
$tmp['admin'] = $_POST['admin'];
|
||||
$tmp['language'] = $_POST['language'];
|
||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
||||
$APIKey = getConfig('APIKey');
|
||||
if ($APIKey=='') {
|
||||
$APIKey = $_POST['APIKey'];
|
||||
$tmp['APIKey'] = $APIKey;
|
||||
}
|
||||
$function_name = getConfig('function_name');
|
||||
if ($function_name=='') {
|
||||
$tmp1 = substr($_SERVER['HTTP_HOST'], 0, strrpos($_SERVER['HTTP_HOST'], '.'));
|
||||
$maindomain = substr($tmp1, strrpos($tmp1, '.')+1);
|
||||
if ($maindomain=='herokuapp') $function_name = substr($tmp1, 0, strrpos($tmp1, '.'));
|
||||
else $function_name = 'visit from xxxx.herokuapp.com';
|
||||
$tmp['function_name'] = $function_name;
|
||||
}
|
||||
$response = json_decode(setHerokuConfig($tmp, $function_name, $APIKey)['body'], true);
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
} else {
|
||||
return output('Jump<meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
|
||||
}
|
||||
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('APIKey')=='') $html .= '
|
||||
<a href="https://dashboard.heroku.com/account" target="_blank">'.getconstStr('Create').' API Key</a><br>
|
||||
<label>API Key:<input name="APIKey" type="text" placeholder="" size=""></label><br>';
|
||||
$html .= '
|
||||
<label>Set admin password:<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></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)
|
||||
{
|
||||
document.cookie=\'language=\'+str+\'; path=/\';
|
||||
location.href = location.href;
|
||||
}
|
||||
function notnull(t)
|
||||
{
|
||||
if (t.admin.value==\'\') {
|
||||
alert(\'input admin\');
|
||||
return false;
|
||||
}';
|
||||
if (getConfig('APIKey')=='') $html .= '
|
||||
if (t.APIKey.value==\'\') {
|
||||
alert(\'input API 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 HerokuAPI($method, $url, $data = '', $apikey)
|
||||
{
|
||||
if ($method=='PATCH'||$method=='POST') {
|
||||
$headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
$headers['Authorization'] = 'Bearer ' . $apikey;
|
||||
$headers['Accept'] = 'application/vnd.heroku+json; version=3';
|
||||
//if (!isset($headers['Accept'])) $headers['Accept'] = '*/*';
|
||||
//if (!isset($headers['Referer'])) $headers['Referer'] = $url;
|
||||
$sendHeaders = array();
|
||||
foreach ($headers as $headerName => $headerVal) {
|
||||
$sendHeaders[] = $headerName . ': ' . $headerVal;
|
||||
}
|
||||
error_log($method . $url . $data . $apikey);
|
||||
$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, 0);
|
||||
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);
|
||||
$response['stat'] = curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
error_log($response['stat'].'
|
||||
'.$response['body'].'
|
||||
');
|
||||
return $response;
|
||||
}
|
||||
|
||||
function getHerokuConfig($function_name, $apikey)
|
||||
{
|
||||
return HerokuAPI('GET', 'https://api.heroku.com/apps/' . $function_name . '/config-vars', '', $apikey);
|
||||
}
|
||||
|
||||
function setHerokuConfig($env, $function_name, $apikey)
|
||||
{
|
||||
$data = json_encode($env);
|
||||
return HerokuAPI('PATCH', 'https://api.heroku.com/apps/' . $function_name . '/config-vars', $data, $apikey);
|
||||
}
|
||||
|
||||
function updateHerokuapp($function_name, $apikey, $source)
|
||||
{
|
||||
$tmp['source_blob']['url'] = $source;
|
||||
$data = json_encode($tmp);
|
||||
return HerokuAPI('POST', 'https://api.heroku.com/apps/' . $function_name . '/builds', $data, $apikey);
|
||||
}
|
||||
|
||||
function api_error($response)
|
||||
{
|
||||
return isset($response['id'])&&isset($response['message']);
|
||||
}
|
||||
|
||||
function api_error_msg($response)
|
||||
{
|
||||
return $response['id'] . '<br>
|
||||
' . $response['message'] . '<br><br>
|
||||
function_name:' . $_SERVER['function_name'] . '<br>
|
||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
||||
}
|
||||
|
||||
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||
{
|
||||
//'https://github.com/qkqpttgf/OneManager-php/tarball/master/';
|
||||
$source = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . $branch . '/';
|
||||
return json_decode(updateHerokuapp(getConfig('function_name'), getConfig('APIKey'), $source)['body'], true);
|
||||
}
|
||||
|
||||
function setConfigResponse($response)
|
||||
{
|
||||
return json_decode( $response['body'], true );
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
<?php
|
||||
|
||||
function getpath()
|
||||
{
|
||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($_SERVER['HTTP_ACCEPT_LANGUAGE'],';')[0],',')[0]);
|
||||
$_SERVER['base_path'] = path_format(substr($_SERVER['SCRIPT_NAME'], 0, -10) . '/');
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p);
|
||||
else $path = $_SERVER['REQUEST_URI'];
|
||||
$path = path_format( substr($path, strlen($_SERVER['base_path'])) );
|
||||
return substr($path, 1);
|
||||
//return spurlencode($path, '/');
|
||||
}
|
||||
|
||||
function getGET()
|
||||
{
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>0) {
|
||||
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
|
||||
$getstrarr = explode("&",$getstr);
|
||||
foreach ($getstrarr as $getvalues) {
|
||||
if ($getvalues != '') {
|
||||
$pos = strpos($getvalues, "=");
|
||||
//echo $pos;
|
||||
if ($pos > 0) {
|
||||
$getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1));
|
||||
} else {
|
||||
$getarry[urldecode($getvalues)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($getarry)) {
|
||||
return $getarry;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function getConfig($str, $disktag = '')
|
||||
{
|
||||
global $InnerEnv;
|
||||
global $Base64Env;
|
||||
//include 'config.php';
|
||||
$s = file_get_contents('config.php');
|
||||
$configs = substr($s, 18, -2);
|
||||
if ($configs!='') {
|
||||
$envs = json_decode($configs, true);
|
||||
if (in_array($str, $InnerEnv)) {
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
if (isset($envs[$disktag][$str])) {
|
||||
if (in_array($str, $Base64Env)) return equal_replace($envs[$disktag][$str],1);
|
||||
else return $envs[$disktag][$str];
|
||||
}
|
||||
} else {
|
||||
if (isset($envs[$str])) {
|
||||
if (in_array($str, $Base64Env)) return equal_replace($envs[$str],1);
|
||||
else return $envs[$str];
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function setConfig($arr, $disktag = '')
|
||||
{
|
||||
global $InnerEnv;
|
||||
global $Base64Env;
|
||||
if ($disktag=='') $disktag = $_SERVER['disktag'];
|
||||
//include 'config.php';
|
||||
$s = file_get_contents('config.php');
|
||||
$configs = substr($s, 18, -2);
|
||||
if ($configs!='') $envs = json_decode($configs, true);
|
||||
$disktags = explode("|",getConfig('disktag'));
|
||||
//$indisk = 0;
|
||||
$operatedisk = 0;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (in_array($k, $InnerEnv)) {
|
||||
if (in_array($k, $Base64Env)) $envs[$disktag][$k] = equal_replace($v);
|
||||
else $envs[$disktag][$k] = $v;
|
||||
/*$diskconfig[$k] = $v;
|
||||
$indisk = 1;*/
|
||||
} elseif ($k=='disktag_add') {
|
||||
array_push($disktags, $v);
|
||||
$operatedisk = 1;
|
||||
} elseif ($k=='disktag_del') {
|
||||
$disktags = array_diff($disktags, [ $v ]);
|
||||
$envs[$v] = '';
|
||||
$operatedisk = 1;
|
||||
} else {
|
||||
if (in_array($k, $Base64Env)) $envs[$k] = equal_replace($v);
|
||||
else $envs[$k] = $v;
|
||||
}
|
||||
}
|
||||
/*if ($indisk) {
|
||||
$diskconfig = array_filter($diskconfig, 'array_value_isnot_null');
|
||||
ksort($diskconfig);
|
||||
$tmp[$disktag] = json_encode($diskconfig);
|
||||
}*/
|
||||
if ($operatedisk) {
|
||||
$disktags = array_unique($disktags);
|
||||
foreach ($disktags as $disktag) if ($disktag!='') $disktag_s .= $disktag . '|';
|
||||
if ($disktag_s!='') $envs['disktag'] = substr($disktag_s, 0, -1);
|
||||
else $envs['disktag'] = '';
|
||||
}
|
||||
$envs = array_filter($envs, 'array_value_isnot_null');
|
||||
ksort($envs);
|
||||
//echo '<pre>'. json_encode($envs, JSON_PRETTY_PRINT).'</pre>';
|
||||
$prestr = '<?php $configs = \'
|
||||
';
|
||||
$aftstr = '
|
||||
\';';
|
||||
return file_put_contents('config.php', $prestr . json_encode($envs, JSON_PRETTY_PRINT) . $aftstr);
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
global $constStr;
|
||||
if ($_GET['install2']) {
|
||||
if ($_POST['admin']!='') {
|
||||
$tmp['admin'] = $_POST['admin'];
|
||||
$tmp['language'] = $_COOKIE['language'];
|
||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
||||
$response = setConfig($tmp);
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
} else {
|
||||
return output('Jump<script>document.cookie=\'language=; path=/\';</script><meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($_GET['install1']) {
|
||||
if (!ConfigWriteable()) {
|
||||
$html .= getconstStr('MakesuerWriteable');
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
/*if (!RewriteEngineOn()) {
|
||||
$html .= getconstStr('MakesuerRewriteOn');
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
}*/
|
||||
$html .= '<button id="checkrewritebtn" onclick="checkrewrite();">'.getconstStr('MakesuerRewriteOn').'</button>
|
||||
<div id="formdiv" style="display: none">
|
||||
<form action="?install2" method="post" onsubmit="return notnull(this);">
|
||||
<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"><br>
|
||||
<input id="submitbtn" type="submit" value="'.getconstStr('Submit').'" disabled>
|
||||
</form>
|
||||
</div>
|
||||
<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 notnull(t)
|
||||
{
|
||||
if (t.admin.value==\'\') {
|
||||
alert(\''.getconstStr('SetAdminPassword').'\');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function checkrewrite()
|
||||
{
|
||||
url=location.protocol + "//" + location.host;
|
||||
//if (location.port!="") url += ":" + location.port;
|
||||
url += location.pathname;
|
||||
if (url.substr(-1)!="/") url += "/";
|
||||
url += "config.php";
|
||||
//alert(url);
|
||||
var xhr4 = new XMLHttpRequest();
|
||||
xhr4.open("GET", url);
|
||||
xhr4.setRequestHeader("x-requested-with","XMLHttpRequest");
|
||||
xhr4.send(null);
|
||||
xhr4.onload = function(e){
|
||||
console.log(xhr4.responseText+","+xhr4.status);
|
||||
if (xhr4.status==201) {
|
||||
document.getElementById("checkrewritebtn").style.display = "none";
|
||||
document.getElementById("submitbtn").disabled = false;
|
||||
document.getElementById("formdiv").style.display = "";
|
||||
} else {
|
||||
alert(url+"\n"+xhr4.status);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>';
|
||||
$title = getconstStr('SetAdminPassword');
|
||||
return message($html, $title, 201);
|
||||
}
|
||||
if ($_GET['install0']) {
|
||||
$html .= '
|
||||
<form action="?install1" method="post">
|
||||
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>';
|
||||
}
|
||||
$html .= '
|
||||
<input type="submit" value="'.getconstStr('Submit').'">
|
||||
</form>
|
||||
<script>
|
||||
function changelanguage(str)
|
||||
{
|
||||
document.cookie=\'language=\'+str+\'; path=/\';
|
||||
location.href = location.href;
|
||||
}
|
||||
</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 ConfigWriteable()
|
||||
{
|
||||
$t = md5( md5(time()).rand(1000,9999) );
|
||||
$r = setConfig([ 'tmp' => $t ]);
|
||||
$tmp = getConfig('tmp');
|
||||
setConfig([ 'tmp' => '' ]);
|
||||
if ($tmp == $t) return true;
|
||||
if ($r) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function RewriteEngineOn()
|
||||
{
|
||||
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
|
||||
$tmpurl = $http_type . $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'];
|
||||
$tmpurl .= path_format($_SERVER['base_path'] . '/config.php');
|
||||
$tmp = curl_request($tmpurl);
|
||||
if ($tmp['stat']==200) return false;
|
||||
if ($tmp['stat']==201) return true; //when install return 201, after installed return 404 or 200;
|
||||
return false;
|
||||
}
|
||||
|
||||
function api_error($response)
|
||||
{
|
||||
return !$response;
|
||||
}
|
||||
|
||||
function api_error_msg($response)
|
||||
{
|
||||
return $response . '<br>
|
||||
Can not write config to file.<br>
|
||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
||||
}
|
||||
|
||||
function OnekeyUpate()
|
||||
{
|
||||
return json_decode(updateHerokuapp(getConfig('function_name'), getConfig('APIKey'))['body'], true);
|
||||
}
|
||||
|
||||
function setConfigResponse($response)
|
||||
{
|
||||
return $response;
|
||||
}
|
429
platform/scf.php
429
platform/scf.php
|
@ -1,429 +0,0 @@
|
|||
<?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['queryString'];
|
||||
$postbody = explode("&",$event['body']);
|
||||
foreach ($postbody as $postvalues) {
|
||||
$pos = strpos($postvalues,"=");
|
||||
$_POST[urldecode(substr($postvalues,0,$pos))]=urldecode(substr($postvalues,$pos+1));
|
||||
}
|
||||
$cookiebody = explode("; ",$event['headers']['cookie']);
|
||||
foreach ($cookiebody as $cookievalues) {
|
||||
$pos = strpos($cookievalues,"=");
|
||||
$_COOKIE[urldecode(substr($cookievalues,0,$pos))]=urldecode(substr($cookievalues,$pos+1));
|
||||
}
|
||||
$_SERVER['USER'] = 'qcloud';
|
||||
}
|
||||
|
||||
function GetPathSetting($event, $context)
|
||||
{
|
||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($event['headers']['accept-language'],';')[0],',')[0]);
|
||||
$_SERVER['function_name'] = $context['function_name'];
|
||||
$_SERVER['namespace'] = $context['namespace'];
|
||||
$host_name = $event['headers']['host'];
|
||||
$_SERVER['HTTP_HOST'] = $host_name;
|
||||
$serviceId = $event['requestContext']['serviceId'];
|
||||
if ( $serviceId === substr($host_name,0,strlen($serviceId)) ) {
|
||||
$_SERVER['base_path'] = '/'.$event['requestContext']['stage'].'/'.$_SERVER['function_name'].'/';
|
||||
$_SERVER['Region'] = getenv('Region');
|
||||
if ($_SERVER['Region'] == '') {
|
||||
$_SERVER['Region'] = substr($host_name, strpos($host_name, '.')+1);
|
||||
$_SERVER['Region'] = substr($_SERVER['Region'], 0, strpos($_SERVER['Region'], '.'));
|
||||
}
|
||||
$path = substr($event['path'], strlen('/'.$_SERVER['function_name'].'/'));
|
||||
} else {
|
||||
$_SERVER['base_path'] = $event['requestContext']['path'];
|
||||
$_SERVER['Region'] = getenv('Region');
|
||||
$path = substr($event['path'], strlen($event['requestContext']['path']));
|
||||
}
|
||||
if (substr($path,-1)=='/') $path=substr($path,0,-1);
|
||||
$_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 equal_replace($env[$str],1);
|
||||
else return $env[$str];
|
||||
}
|
||||
} else {
|
||||
if (in_array($str, $Base64Env)) return equal_replace(getenv($str),1);
|
||||
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] = equal_replace($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] = equal_replace($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, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'));
|
||||
WaitSCFStat();
|
||||
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()
|
||||
{
|
||||
global $constStr;
|
||||
if ($_GET['install2']) {
|
||||
$tmp['admin'] = $_POST['admin'];
|
||||
setConfig($tmp);
|
||||
if (needUpdate()) {
|
||||
OnekeyUpate();
|
||||
return message('update to github version, reinstall.<script>document.cookie=\'language=; path=/\';</script><meta http-equiv="refresh" content="3;URL=' . $url . '">', 'Program updating', 201);
|
||||
}
|
||||
return output('Jump<script>document.cookie=\'language=; path=/\';</script><meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
|
||||
}
|
||||
if ($_GET['install1']) {
|
||||
//if ($_POST['admin']!='') {
|
||||
$tmp['language'] = $_POST['language'];
|
||||
$tmp['Region'] = $_POST['Region'];
|
||||
$tmp['timezone'] = $_COOKIE['timezone'];
|
||||
$SecretId = getConfig('SecretId');
|
||||
if ($SecretId=='') {
|
||||
$SecretId = $_POST['SecretId'];
|
||||
$tmp['SecretId'] = $SecretId;
|
||||
}
|
||||
$SecretKey = getConfig('SecretKey');
|
||||
if ($SecretKey=='') {
|
||||
$SecretKey = $_POST['SecretKey'];
|
||||
$tmp['SecretKey'] = $SecretKey;
|
||||
}
|
||||
$response = json_decode(SetbaseConfig($tmp, $_SERVER['function_name'], $_POST['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
|
||||
if (api_error($response)) {
|
||||
$html = api_error_msg($response);
|
||||
$title = 'Error';
|
||||
return message($html, $title, 201);
|
||||
} else {
|
||||
$html .= '
|
||||
<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.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>SecretKey:<input name="SecretKey" type="text" placeholder="" size=""></label><br>';
|
||||
$html .= '
|
||||
<select class="changelanguage" name="Region">
|
||||
<option value="">选择区域</option>
|
||||
<option value="ap-beijing">华北地区(北京)</option>
|
||||
<option value="ap-chengdu">西南地区(成都)</option>
|
||||
<option value="ap-guangzhou">华南地区(广州)</option>
|
||||
<option value="ap-guangzhou-open">华南地区(广州Open)</option>
|
||||
<option value="ap-hongkong">港澳台地区(中国香港)</option>
|
||||
<option value="ap-mumbai">亚太南部(孟买)</option>
|
||||
<option value="ap-shanghai">华东地区(上海)</option>
|
||||
<option value="ap-shanghai-fsi">华东地区(上海金融)</option>
|
||||
<option value="ap-singapore">亚太东南(新加坡)</option>
|
||||
<option value="ap-tokyo">亚太东北(东京)</option>
|
||||
<option value="na-siliconvalley">美国西部(硅谷)</option>
|
||||
<option value="na-toronto">北美地区(多伦多)</option>
|
||||
</select>(腾讯几个月了还不做出来,只能先弄选择了)<br>
|
||||
<input type="submit" value="'.getconstStr('Submit').'">
|
||||
</form>
|
||||
<script>
|
||||
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)
|
||||
{
|
||||
document.cookie=\'language=\'+str+\'; path=/\';
|
||||
location.href = location.href;
|
||||
}
|
||||
function notnull(t)
|
||||
{';
|
||||
if (getConfig('SecretId')==''||getConfig('SecretKey')=='') $html .= '
|
||||
if (t.SecretId.value==\'\') {
|
||||
alert(\'input SecretId\');
|
||||
return false;
|
||||
}
|
||||
if (t.SecretKey.value==\'\') {
|
||||
alert(\'input SecretKey\');
|
||||
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 post2url($url, $data)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
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, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
//echo $response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
function ReorganizeDate($arr)
|
||||
{
|
||||
$str = '';
|
||||
ksort($arr);
|
||||
foreach ($arr as $k1 => $v1) {
|
||||
$str .= '&' . $k1 . '=' . $v1;
|
||||
}
|
||||
$str = substr($str, 1); // remove first '&'. 去掉第一个&
|
||||
return $str;
|
||||
}
|
||||
|
||||
function getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
||||
{
|
||||
//$meth = 'GET';
|
||||
$meth = 'POST';
|
||||
$host = 'scf.tencentcloudapi.com';
|
||||
$tmpdata['Action'] = 'GetFunction';
|
||||
$tmpdata['FunctionName'] = $function_name;
|
||||
$tmpdata['Namespace'] = $Namespace;
|
||||
$tmpdata['Nonce'] = time();
|
||||
$tmpdata['Region'] = $Region;
|
||||
$tmpdata['SecretId'] = $SecretId;
|
||||
$tmpdata['Timestamp'] = time();
|
||||
$tmpdata['Token'] = '';
|
||||
$tmpdata['Version'] = '2018-04-16';
|
||||
$data = ReorganizeDate($tmpdata);
|
||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
||||
//echo urlencode($signStr);
|
||||
//return file_get_contents('https://'.$url.'&Signature='.urlencode($signStr));
|
||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
||||
}
|
||||
|
||||
function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
||||
{
|
||||
//print_r($Envs);
|
||||
WaitSCFStat();
|
||||
//json_decode($a,true)['Response']['Environment']['Variables'][0]['Key']
|
||||
$tmp = json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Environment']['Variables'];
|
||||
foreach ($tmp as $tmp1) {
|
||||
$tmp_env[$tmp1['Key']] = $tmp1['Value'];
|
||||
}
|
||||
foreach ($Envs as $key1 => $value1) {
|
||||
$tmp_env[$key1] = $value1;
|
||||
}
|
||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
||||
$tmp_env['Region'] = $Region;
|
||||
ksort($tmp_env);
|
||||
|
||||
$i = 0;
|
||||
foreach ($tmp_env as $key1 => $value1) {
|
||||
$tmpdata['Environment.Variables.'.$i.'.Key'] = $key1;
|
||||
$tmpdata['Environment.Variables.'.$i.'.Value'] = $value1;
|
||||
$i++;
|
||||
}
|
||||
$meth = 'POST';
|
||||
$host = 'scf.tencentcloudapi.com';
|
||||
$tmpdata['Action'] = 'UpdateFunctionConfiguration';
|
||||
$tmpdata['FunctionName'] = $function_name;
|
||||
$tmpdata['Namespace'] = $Namespace;
|
||||
$tmpdata['Nonce'] = time();
|
||||
$tmpdata['Region'] = $Region;
|
||||
$tmpdata['SecretId'] = $SecretId;
|
||||
$tmpdata['Timestamp'] = time();
|
||||
$tmpdata['Token'] = '';
|
||||
$tmpdata['Version'] = '2018-04-16';
|
||||
$data = ReorganizeDate($tmpdata);
|
||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
||||
//echo urlencode($signStr);
|
||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
||||
}
|
||||
|
||||
function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $SecretKey)
|
||||
{
|
||||
echo json_encode($Envs,JSON_PRETTY_PRINT);
|
||||
/*$trynum = 0;
|
||||
while( json_decode(getfunctioninfo($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey),true)['Response']['Status']!='Active' ) echo '
|
||||
'.++$trynum;*/
|
||||
//json_decode($a,true)['Response']['Environment']['Variables'][0]['Key']
|
||||
$tmp = json_decode(getfunctioninfo($function_name, $Region, $Namespace, $SecretId, $SecretKey),true)['Response']['Environment']['Variables'];
|
||||
foreach ($tmp as $tmp1) {
|
||||
$tmp_env[$tmp1['Key']] = $tmp1['Value'];
|
||||
}
|
||||
foreach ($Envs as $key1 => $value1) {
|
||||
$tmp_env[$key1] = $value1;
|
||||
}
|
||||
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
|
||||
$tmp_env['Region'] = $Region;
|
||||
ksort($tmp_env);
|
||||
|
||||
$i = 0;
|
||||
foreach ($tmp_env as $key1 => $value1) {
|
||||
$tmpdata['Environment.Variables.'.$i.'.Key'] = $key1;
|
||||
$tmpdata['Environment.Variables.'.$i.'.Value'] = $value1;
|
||||
$i++;
|
||||
}
|
||||
$meth = 'POST';
|
||||
$host = 'scf.tencentcloudapi.com';
|
||||
$tmpdata['Action'] = 'UpdateFunctionConfiguration';
|
||||
$tmpdata['FunctionName'] = $function_name;
|
||||
$tmpdata['Namespace'] = $Namespace;
|
||||
$tmpdata['Nonce'] = time();
|
||||
$tmpdata['Region'] = $Region;
|
||||
$tmpdata['SecretId'] = $SecretId;
|
||||
$tmpdata['Timestamp'] = time();
|
||||
$tmpdata['Token'] = '';
|
||||
$tmpdata['Version'] = '2018-04-16';
|
||||
$tmpdata['Description'] = 'Onedrive index and manager in SCF.';
|
||||
$tmpdata['MemorySize'] = 64;
|
||||
$tmpdata['Timeout'] = 30;
|
||||
$data = ReorganizeDate($tmpdata);
|
||||
echo $data;
|
||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
||||
//echo urlencode($signStr);
|
||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
||||
}
|
||||
|
||||
function updateProgram($function_name, $Region, $Namespace, $SecretId, $SecretKey, $source)
|
||||
{
|
||||
WaitSCFStat();
|
||||
$meth = 'POST';
|
||||
$host = 'scf.tencentcloudapi.com';
|
||||
$tmpdata['Action'] = 'UpdateFunctionCode';
|
||||
$tmpdata['Code.GitUrl'] = $source['url'];
|
||||
$tmpdata['Code.GitBranch'] = $source['branch'];
|
||||
$tmpdata['CodeSource'] = 'Git';
|
||||
$tmpdata['FunctionName'] = $function_name;
|
||||
$tmpdata['Handler'] = 'index.main_handler';
|
||||
$tmpdata['Namespace'] = $Namespace;
|
||||
$tmpdata['Nonce'] = time();
|
||||
$tmpdata['Region'] = $Region;
|
||||
$tmpdata['SecretId'] = $SecretId;
|
||||
$tmpdata['Timestamp'] = time();
|
||||
$tmpdata['Token'] = '';
|
||||
$tmpdata['Version'] = '2018-04-16';
|
||||
$data = ReorganizeDate($tmpdata);
|
||||
$signStr = base64_encode(hash_hmac('sha1', $meth.$host.'/?'.$data, $SecretKey, true));
|
||||
//echo urlencode($signStr);
|
||||
return post2url('https://'.$host, $data.'&Signature='.urlencode($signStr));
|
||||
}
|
||||
|
||||
function api_error($response)
|
||||
{
|
||||
return isset($response['Error']);
|
||||
}
|
||||
|
||||
function api_error_msg($response)
|
||||
{
|
||||
return $response['Error']['Code'] . '<br>
|
||||
' . $response['Error']['Message'] . '<br><br>
|
||||
function_name:' . $_SERVER['function_name'] . '<br>
|
||||
Region:' . $_SERVER['Region'] . '<br>
|
||||
namespace:' . $_SERVER['namespace'] . '<br>
|
||||
<button onclick="location.href = location.href;">'.getconstStr('Refresh').'</button>';
|
||||
}
|
||||
|
||||
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||
{
|
||||
$source['url'] = 'https://github.com/' . $auth . '/' . $project;
|
||||
$source['branch'] = $branch;
|
||||
return json_decode(updateProgram($_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], getConfig('SecretId'), getConfig('SecretKey'), $source), true)['Response'];
|
||||
}
|
||||
|
||||
function setConfigResponse($response)
|
||||
{
|
||||
return json_decode( $response, true )['Response'];
|
||||
}
|
262
readme.md
262
readme.md
|
@ -1,53 +1,229 @@
|
|||
Install program first, then add onedrive in setup after login.
|
||||
先安装程序,登录后在设置中添加onedrive。
|
||||
[中文readme](readme_cn.md)
|
||||
|
||||
# Deploy to heroku
|
||||
Official: https://heroku.com
|
||||
# NOTICE:
|
||||
|
||||
How to Install: Click the button [](https://heroku.com/deploy) to Deploy a new app, or create an app then deploy via connect to your github fork.
|
||||
The Releases is used as archive, not newest code.
|
||||
|
||||
DEMO: https://herooneindex.herokuapp.com/
|
||||
Please read the descriptions of settings before raising an issue.
|
||||
|
||||
# Deploy to VPS(Virtual Private Server) 部署到VPS或空间
|
||||
How to Install:
|
||||
1.Start web service on your server (httpd or other), make sure you can visit it.
|
||||
启动web服务器,确保你能访问到。
|
||||
2.Make the rewrite works, the rule is in .htaccess file, make sure any query redirect to index.php.
|
||||
开启伪静态(重写)功能,规则在.htaccess文件中,ngnix从里面复制,我们的目的是不管访问什么都让index.php来处理。
|
||||
3.Upload code.
|
||||
上传好代码。
|
||||
4.Change the file config.php can be read&write (666 is suggested).
|
||||
让代码中的config.php文件程序可读写,推荐chmod 666 config.php。
|
||||
5.View the website in chrome or other.
|
||||
在浏览器中访问。
|
||||
---
|
||||
|
||||
# Deploy to SCF
|
||||
Official: https://cloud.tencent.com/product/scf
|
||||
# Deploy to Vercel
|
||||
|
||||
~~How to Install: https://service-pgxgvop2-1258064400.ap-hongkong.apigateway.myqcloud.com/test/abcdef/%E6%97%A0%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%87%BD%E6%95%B0SCF%E6%90%AD%E5%BB%BAOneDrive.mp4?preview~~
|
||||
### Official
|
||||
|
||||
先手动在环境变量添加Region,ap-hongkong或ap-guangzhou之类,具体看 https://cloud.tencent.com/document/api/583/17238 最底下,然后再安装。
|
||||
添加网盘时,SCF反应不过来,会添加失败,请不要删除,再添加一次相同的就可以了。
|
||||
https://vercel.com/
|
||||
|
||||
DEMO: https://service-pgxgvop2-1258064400.ap-hongkong.apigateway.myqcloud.com/test/abcdef/
|
||||
### Demo
|
||||
|
||||
# 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.
|
||||
下载时,由程序解析出直链,浏览器直接从微软Onedrive服务器下载文件,服务器只消耗与微软通信的少量流量。
|
||||
When uploading files, the program produce a direct url, visitor upload files to MS OFFICE via the direct url, the server expend a few bandwidth in produce.
|
||||
上传时,由程序生成上传url,浏览器直接向微软Onedrive的这个url上传文件,服务器只消耗与微软通信的少量流量。
|
||||
The XXX_path in setting is the path in Onedrive, not in url, program will find the path in Onedrive.
|
||||
设置中的 XXX_path 是Onedrive里面的路径,并不是你url里面的,程序会去你Onedrive里面找这个路径。
|
||||
LOGO ICON: put your 'favicon.ico' in the path you showed, make sure xxxxx.com/favicon.ico can be visited.
|
||||
网站图标:将favicon.ico文件放在你要展示的目录中,确保 xxxxx.com/favicon.ico 可以访问到。
|
||||
Program will show content of 'readme.md' & 'head.md'.
|
||||
可以在文件列表显示head.md跟readme.md文件的内容。
|
||||
guest up path, is a folder that the guest can upload files, but can not be list (exclude admin).
|
||||
游客上传目录(也叫图床目录),是指定一个目录,让游客可以上传文件,不限格式,不限大小。这个目录里面的内容不列清单(除非管理登录)。
|
||||
If there is 'index.html' file, program will only show the content of 'index.html', not list the files.
|
||||
如果目录中有index.html文件,只会输出显示html文件,不显示程序框架。
|
||||
Click 'EditTime' or 'Size', the list will sort by time or size, Click 'File' can resume sort.
|
||||
点击“时间”、“大小”,可以排序显示,点“文件”恢复原样。
|
||||
https://onemanager-php.vercel.app/
|
||||
|
||||
QQ Group: 943919989 (请看完上面的中英双语再加群,谢谢!)
|
||||
Telegram Group: https://t.me/joinchat/I_RVc0bqxuxlT-d0cO7ozw
|
||||
### Notice
|
||||
|
||||
> 1. you must wait 30-50s to make sure deploy READY after change config;
|
||||
>
|
||||
> 2. Vercel limit 100 deploy every day.
|
||||
|
||||
### How to Install
|
||||
|
||||
> https://scfonedrive.github.io/Vercel/Deploy.html .
|
||||
|
||||
---
|
||||
|
||||
# Deploy to Replit
|
||||
|
||||
### Official
|
||||
|
||||
https://repl.it/
|
||||
https://replit.com/
|
||||
|
||||
### Demo
|
||||
|
||||
https://onemanager.qkqpttgf.repl.co/
|
||||
|
||||
### Notice
|
||||
|
||||
> `Import from Github` useing the `.replit` file in code files will cause an empty web page, may someone help me?
|
||||
|
||||
### How to Install
|
||||
|
||||
> 1. Click the "+" or "Create Repl", find template "PHP Web Server" (via input "php"), input a name for your project in "Title" or left it default, Click the "+ Create Repl".
|
||||
> 2. After done, input `git clone https://github.com/qkqpttgf/OneManager-php && mv -b OneManager-php/* ./ && mv -b OneManager-php/.[^.]* ./ && rm -rf *~ && rm -rf OneManager-php` to Console or Shell on the right, press "Enter" to run it.
|
||||
> 3. Click the green button "Run", it will show the web page on the right, you can open it in a new tab or window.
|
||||
|
||||
---
|
||||
|
||||
# Deploy to Heroku
|
||||
|
||||
### Official
|
||||
|
||||
https://heroku.com
|
||||
|
||||
### Demo
|
||||
|
||||
https://herooneindex.herokuapp.com/
|
||||
|
||||
### How to Install
|
||||
|
||||
> ~~Click the button [](https://heroku.com/deploy) to Deploy a new app~~(`"We couldn't deploy your app because the source code violates the Salesforce Acceptable Use and External-Facing Services Policy."`)
|
||||
>
|
||||
> Star this project, then Fork, create an app in Heroku, then turn to the Deploy tab, "Deployment method" via "Connect GitHub", select your github fork.
|
||||
|
||||
---
|
||||
|
||||
# Deploy to Glitch
|
||||
|
||||
### Official
|
||||
|
||||
https://glitch.com/
|
||||
|
||||
### Demo
|
||||
|
||||
https://onemanager.glitch.me/
|
||||
|
||||
### How to Install
|
||||
|
||||
[New Project] -> [Import form Github] -> paste "https://github.com/qkqpttgf/OneManager-php" , after done, [Show] -> [In a New Window].
|
||||
|
||||
---
|
||||
|
||||
# Deploy to Tencent Serverless Cloud Function (SCF)
|
||||
|
||||
### Official
|
||||
|
||||
https://cloud.tencent.com/product/scf
|
||||
|
||||
### DEMO
|
||||
|
||||
null
|
||||
|
||||
### How to Install
|
||||
|
||||
see CN readme.
|
||||
|
||||
----
|
||||
|
||||
|
||||
# Deploy to Huawei cloud Function Graph (FG)
|
||||
|
||||
### Official
|
||||
|
||||
https://console.huaweicloud.com/functiongraph/
|
||||
|
||||
### DEMO
|
||||
|
||||
null
|
||||
|
||||
### How to Install
|
||||
|
||||
see CN readme.
|
||||
|
||||
----
|
||||
|
||||
# Deploy to Aliyun Function Compute (FC)
|
||||
|
||||
### Official:
|
||||
|
||||
https://fc.console.aliyun.com/
|
||||
|
||||
### DEMO
|
||||
|
||||
null
|
||||
|
||||
### How to Install
|
||||
|
||||
see CN readme.
|
||||
|
||||
---
|
||||
|
||||
# Deploy to Baidu Cloud Function Compute (CFC)
|
||||
|
||||
### Official
|
||||
|
||||
https://console.bce.baidu.com/cfc/#/cfc/functions
|
||||
|
||||
### DEMO
|
||||
|
||||
null
|
||||
|
||||
### How to Install
|
||||
|
||||
see CN readme.
|
||||
|
||||
---
|
||||
|
||||
# Deploy to Virtual Private Server (VPS) or php host
|
||||
|
||||
### DEMO
|
||||
|
||||
null
|
||||
|
||||
### How to Install
|
||||
|
||||
1. Start web service on your server (httpd or other), make sure you can visit it.
|
||||
|
||||
2. Make the rewrite works, the rule is in .htaccess file, make sure any query redirect to index.php.
|
||||
|
||||
3. Upload code.
|
||||
|
||||
4. Change the file .data/config.php can be read&write (666 is suggested).
|
||||
|
||||
5. View the website in chrome or other.
|
||||
|
||||
----
|
||||
|
||||
# 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 uploading files, the program produce a direct url, visitor upload files to MS OFFICE via the direct url, the server expend a few bandwidth in produce.
|
||||
|
||||
The XXX_path in setting is the path in Onedrive, not in url, program will find the path in Onedrive.
|
||||
|
||||
LOGO ICON: put your 'favicon.ico' in the path you showed, make sure xxxxx.com/favicon.ico can be visited.
|
||||
|
||||
Program will show content of 'readme.md' & 'head.md'.
|
||||
|
||||
guest upload path, is a folder that the guest can upload files, but can not be list (exclude admin).
|
||||
|
||||
If there is 'index.html' file, program will only show the content of 'index.html', not list the files.
|
||||
|
||||
Click 'EditTime' or 'Size', the list will sort by time or size, Click 'File' can resume sort.
|
||||
|
||||
----
|
||||
|
||||
# Functional files
|
||||
|
||||
### favicon.ico
|
||||
|
||||
put it in the showing home folder of FIRST disk (maybe not root of onedrive).
|
||||
|
||||
### index.html
|
||||
|
||||
show content of index.html as html.
|
||||
|
||||
### head.md
|
||||
|
||||
### readme.md
|
||||
|
||||
it will showed at top or bottom as markdown.
|
||||
|
||||
### head.omf
|
||||
|
||||
### foot.omf
|
||||
|
||||
it will showed at top or bottom as html (javascript works!).
|
||||
|
||||
----
|
||||
|
||||
# A cup of coffee
|
||||
|
||||
https://paypal.me/qkqpttgf
|
||||
|
||||
-----
|
||||
|
||||
# Chat
|
||||
|
||||
### Telegram Group
|
||||
|
||||
https://t.me/joinchat/I_RVc0bqxuxlT-d0cO7ozw
|
||||
|
|
|
@ -0,0 +1,271 @@
|
|||
[Readme EN](readme.md)
|
||||
|
||||
# 注意:
|
||||
|
||||
请关掉浏览器的翻译。
|
||||
|
||||
Releases只是当存档在用的,并不是最新代码。
|
||||
|
||||
请将设置中所有的设置项的说明都读一遍,有些问题就不用问了。
|
||||
|
||||
---
|
||||
|
||||
# 部署到 Vercel
|
||||
|
||||
### 官网
|
||||
|
||||
https://vercel.com/
|
||||
|
||||
### Demo
|
||||
|
||||
https://onemanager-php.vercel.app/
|
||||
|
||||
### 注意
|
||||
|
||||
> 1. 每次更改配置后都要等 30-50s 来确保部署成功;
|
||||
>
|
||||
> 2. Vercel 每天限制 100 次部署。
|
||||
|
||||
### 安装(英文)
|
||||
|
||||
https://scfonedrive.github.io/Vercel/Deploy.html
|
||||
|
||||
---
|
||||
|
||||
# 部署到 Replit
|
||||
|
||||
### 官网
|
||||
|
||||
https://repl.it/
|
||||
https://replit.com/
|
||||
|
||||
### Demo
|
||||
|
||||
https://onemanager.qkqpttgf.repl.co/
|
||||
|
||||
### 注意
|
||||
|
||||
> 直接`Import from Github`通过`.replit`文件指定php时,网页会空白,有人帮忙解决吗?
|
||||
|
||||
### 安装
|
||||
|
||||
> 1. 点右上的 "+" 或左上的 "+ Create Repl",template中输入php,点选"PHP Web Server",在"Title"里输入你想要的名称或者让它默认, 点下面的"+ Create Repl"。
|
||||
> 2. 结束后,在右边的Console或Shell里输入 `git clone https://github.com/qkqpttgf/OneManager-php && mv -b OneManager-php/* ./ && mv -b OneManager-php/.[^.]* ./ && rm -rf *~ && rm -rf OneManager-php` 敲回车运行。
|
||||
> 3. 点上方的绿色 "Run" 按钮,右边会显示一个网页,你要在新窗口打开它来安装,不然不能登录。
|
||||
|
||||
---
|
||||
|
||||
# 部署到 Heroku
|
||||
|
||||
### 官网
|
||||
|
||||
https://heroku.com
|
||||
|
||||
### Demo
|
||||
|
||||
https://herooneindex.herokuapp.com/
|
||||
|
||||
### 安装
|
||||
|
||||
> 给这个项目点star,然后fork,在Heroku创建一个app,然后点进Deploy页,在"Deployment method"处点"Connect GitHub",选择你的fork。
|
||||
|
||||
---
|
||||
|
||||
# 部署到 Glitch
|
||||
|
||||
### 官网
|
||||
|
||||
https://glitch.com/
|
||||
|
||||
### Demo
|
||||
|
||||
https://onemanager.glitch.me/
|
||||
|
||||
### 安装
|
||||
|
||||
点 [New Project] -> 点 [Import form Github] -> 粘贴 "https://github.com/qkqpttgf/OneManager-php" ,结束后,左上角点 [Show] -> [In a New Window]。
|
||||
|
||||
---
|
||||
|
||||
# 部署到腾讯无服务器云函数 Serverless Cloud Function (SCF)
|
||||
|
||||
### 官网
|
||||
|
||||
https://cloud.tencent.com/product/scf
|
||||
|
||||
### DEMO
|
||||
|
||||
暂无
|
||||
|
||||
### 注意事项
|
||||
|
||||
SCF新增限制,环境变量整体最大4KB,所以最多添加4个盘(可以在安装时选择将配置保存在文件来避开限制)。
|
||||
|
||||
### 安装
|
||||
|
||||
1. 进入函数服务,上方选择地区,然后点击新建。
|
||||
|
||||
2. 输入函数名称,选择模板函数,在模糊搜索中输入onedrive,大小写随意,选择那个【获取onedrive信息.....】,点下一步,在代码界面不用动,直接点完成。
|
||||
|
||||
3. 点击触发管理,创建触发器,触发方式改成API网关触发,底下勾选启用集成响应,提交。
|
||||
|
||||
4. 在触发管理中可以看到一个 访问路径,访问它,开始安装。
|
||||
|
||||
(重点:**勾选集成响应**)
|
||||
|
||||
> **添加网盘时,SCF可能会反应不过来,不跳转到微软,导致添加失败,请不要删除这个盘,再添加一次相同标签的盘就可以了。**
|
||||
|
||||
----
|
||||
|
||||
|
||||
# 部署到华为云函数工作流 Function Graph (FG)
|
||||
|
||||
### 官网
|
||||
|
||||
https://console.huaweicloud.com/functiongraph/
|
||||
|
||||
### DEMO
|
||||
|
||||
暂无
|
||||
|
||||
### 注意事项
|
||||
|
||||
FG中,环境变量整体大小为2KB,所以最多添加2个盘(一个onedrive一个aliyundrive)(可以在安装时选择将配置保存在文件来避开限制)。
|
||||
|
||||
### 安装
|
||||
|
||||
1. 在函数列表,点右边创建函数
|
||||
2. 输入名称,选择运行时语言为PHP7.3,点上传ZIP文件,选择文件,然后点右边的创建函数(这里的ZIP文件不能直接用从Github上下载的ZIP文件,要将它解压后,去掉外层文件夹后,再压缩为ZIP。)
|
||||
3. 创建触发器:选API网关,安全认证选None,后端超时(毫秒)将5000改成30000,上面创建分组一下,其它的点点点
|
||||
4. 访问触发器给的url,开始安装
|
||||
5. 在【触发器界面】点【触发器名称】,跳到API网关管理,右边【更多URL】,可以添加自定义域名,自定义域名后发现还是要 xxxx.com/函数名 来访问,点上方的【编辑】,第1页不用改,点【下一步】,**请求Path改成/**,注意匹配模式是前缀匹配,Method为ANY,然后不用点下一步了,点【立即完成】,然后去【发布】生效
|
||||
|
||||
----
|
||||
|
||||
# 部署到阿里云函数计算 Function Compute (FC)
|
||||
|
||||
### 官网
|
||||
|
||||
https://fc.console.aliyun.com/
|
||||
|
||||
### DEMO
|
||||
|
||||
无
|
||||
|
||||
### 安装
|
||||
|
||||
1. 新建函数 -- HTTP函数
|
||||
2. 运行环境选择php7.2
|
||||
3. 触发器认证方式选择anonymous,请求方式里面,点一下GET,再点一下POST,最终框框里面有这2个
|
||||
4. 上传代码(这里的ZIP文件不能直接用从Github上下载的ZIP文件,要将它解压后,去掉外层文件夹后,再压缩为ZIP。)
|
||||
5. 触发器中点进去,找到配置自定义域名,点击前往,创建,路径中填 /* ,其它下拉选择。
|
||||
6. 访问你的域名,开始安装
|
||||
|
||||
---
|
||||
|
||||
# 部署到百度云函数计算 Cloud Function Compute (CFC)
|
||||
|
||||
### 官网
|
||||
|
||||
https://console.bce.baidu.com/cfc/#/cfc/functions
|
||||
|
||||
### DEMO
|
||||
|
||||
暂无
|
||||
|
||||
### 注意事项
|
||||
|
||||
**自定义域名需要另外使用API网关,并备案。**
|
||||
|
||||
### 安装
|
||||
|
||||
1. 在函数列表,点创建函数
|
||||
2. 创建方式改为空白函数,点下一步
|
||||
3. 输入名称,选择运行时为PHP7.2,点下一步
|
||||
4. 触发器:下拉选择HTTP触发器,URL路径填 /{filepath+} ,HTTP方法全选,身份验证:不验证,点提交
|
||||
5. 进入代码编辑页,编辑类型改上传函数ZIP包,选择文件(这里的ZIP文件不能直接用从Github上下载的ZIP文件,要将它解压后,去掉外层文件夹后,再压缩为ZIP。),开始上传
|
||||
6. 点击右边触发器,复制并访问提供的url,开始安装
|
||||
|
||||
---
|
||||
|
||||
# 部署到VPS (Virtual Private Server) 或 空间
|
||||
|
||||
### DEMO
|
||||
|
||||
暂无
|
||||
|
||||
### 安装
|
||||
|
||||
1. 启动web服务器,确保你能访问到。
|
||||
|
||||
2. 开启伪静态(重写)功能,规则在.htaccess文件中,ngnix从里面复制,我们的目的是不管访问什么都让index.php来处理。
|
||||
|
||||
3. 上传好代码。
|
||||
|
||||
4. 使web身份可读写代码中的.data/config.php文件,推荐chmod 666 .data/config.php。
|
||||
|
||||
5. 在浏览器中访问。
|
||||
|
||||
----
|
||||
|
||||
# 特性
|
||||
|
||||
下载时,由程序解析出直链,浏览器直接从微软Onedrive服务器下载文件,服务器只消耗与微软通信的少量流量。
|
||||
|
||||
上传时,由程序生成上传url,浏览器直接向微软Onedrive的这个url上传文件,服务器只消耗与微软通信的少量流量。
|
||||
|
||||
设置中的 XXX_path 是Onedrive里面的路径,并不是你url里面的,程序会去你Onedrive里面找这个路径。
|
||||
|
||||
网站图标:将favicon.ico文件放在你要展示的目录中,确保 xxxxx.com/favicon.ico 可以访问到。
|
||||
|
||||
可以在文件列表显示head.md跟readme.md文件的内容。
|
||||
|
||||
游客上传目录(也叫图床目录),是指定一个目录,让游客可以上传文件,不限格式,不限大小。这个目录里面的内容不列清单(除非管理登录)。
|
||||
|
||||
如果目录中有index.html文件,只会输出显示html文件,不显示程序框架。
|
||||
|
||||
点击“时间”、“大小”,可以排序显示,点“文件”恢复原样。
|
||||
|
||||
----
|
||||
|
||||
# 功能性文件
|
||||
|
||||
### favicon.ico
|
||||
|
||||
放在第一个盘的显示目录(不一定是onedrive根目录)。
|
||||
|
||||
### index.html
|
||||
|
||||
将index.html以静态网页显示出来。
|
||||
|
||||
### head.md
|
||||
|
||||
### readme.md
|
||||
|
||||
以MD语法显示在顶部或底部。
|
||||
|
||||
### head.omf
|
||||
|
||||
### foot.omf
|
||||
|
||||
以html显示在顶部或底部(可以跑js)。
|
||||
|
||||
----
|
||||
|
||||
# 捐赠
|
||||
|
||||
https://paypal.me/qkqpttgf
|
||||
|
||||
-----
|
||||
|
||||
# 群聊
|
||||
|
||||
**请看完上面的中英双语再加群,谢谢!**
|
||||
|
||||
### QQ 群:
|
||||
|
||||
212088653
|
||||
|
||||
### Telegram Group
|
||||
|
||||
https://t.me/joinchat/I_RVc0bqxuxlT-d0cO7ozw
|
|
@ -0,0 +1,577 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="<!--constStr@language-->">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><!--Title--></title>
|
||||
<link rel="shortcut icon" href="<!--base_path-->favicon.ico" type="image/x-icon">
|
||||
<!--https://p.sfx.ms/images/favicon.ico-->
|
||||
<style>
|
||||
/* 通用样式 */
|
||||
/* 用于消除默认自带样式 */
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color: #333;
|
||||
font-family: "Segoe UI", Tahoma, Arial, sans-serif;
|
||||
overflow: hidden;
|
||||
}
|
||||
a {
|
||||
text-decoration: none;
|
||||
}
|
||||
ul {
|
||||
list-style: none;
|
||||
}
|
||||
input[type="radio"] {
|
||||
margin: 0;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* 兼容样式 */
|
||||
body {
|
||||
-webkit-user-select:none;
|
||||
-moz-user-select:none;
|
||||
-ms-user-select:none;
|
||||
user-select:none;
|
||||
}
|
||||
select:-moz-focusring {
|
||||
color: transparent;
|
||||
text-shadow: 0 0 0 #000;
|
||||
}
|
||||
|
||||
/* 自定义样式 */
|
||||
.container {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: 1100px;
|
||||
}
|
||||
.pull-left {
|
||||
float: left;
|
||||
}
|
||||
.pull-right {
|
||||
float: right;
|
||||
}
|
||||
|
||||
/* 字体外部引用 */
|
||||
@font-face {
|
||||
font-family: 'iconfont'; /* project id 1634400 */
|
||||
src: url('//at.alicdn.com/t/font_1634400_9yg8f5s278.eot');
|
||||
src: url('//at.alicdn.com/t/font_1634400_9yg8f5s278.eot?#iefix') format('embedded-opentype'),
|
||||
url('//at.alicdn.com/t/font_1634400_9yg8f5s278.woff2') format('woff2'),
|
||||
url('//at.alicdn.com/t/font_1634400_9yg8f5s278.woff') format('woff'),
|
||||
url('//at.alicdn.com/t/font_1634400_9yg8f5s278.ttf') format('truetype'),
|
||||
url('//at.alicdn.com/t/font_1634400_9yg8f5s278.svg#iconfont') format('svg');
|
||||
}
|
||||
.iconfont {
|
||||
font-family:"iconfont" !important;
|
||||
font-size:16px;font-style:normal;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-webkit-text-stroke-width: 0.2px;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
/* header */
|
||||
header {
|
||||
width: 100%;
|
||||
/*height: 88px;*/
|
||||
line-height: 48px;
|
||||
font-size: 16px;
|
||||
background-color: #0078D4;
|
||||
}
|
||||
header nav {
|
||||
margin: 0 auto;
|
||||
padding: 0 10px;
|
||||
height: 48px;
|
||||
color: #FFF;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
header nav a {
|
||||
color: #FFF;
|
||||
font-weight: 600;
|
||||
}
|
||||
header nav .lang .language { outline: none; }
|
||||
header .control {
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
background-color: #f4f4f4;
|
||||
}
|
||||
header .control .control-item {
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
/* main */
|
||||
main {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
}
|
||||
main .scroll {
|
||||
overflow-y: scroll;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
}
|
||||
main .main-item-list {
|
||||
padding-left: 32px;
|
||||
padding-right: 32px;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
font-size: 12px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
main .main-title h1 {
|
||||
margin: 0;
|
||||
padding: 32px;
|
||||
font-size: 20px;
|
||||
font-weight: 100;
|
||||
}
|
||||
main .main-items:hover {
|
||||
background-color: #F4F4F4;
|
||||
}
|
||||
main .main-items:hover .main-items-radio {
|
||||
display: inline-block!important;
|
||||
}
|
||||
main .main-item-list .inner-container {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
width: 100%;
|
||||
height: 32px;
|
||||
border-bottom: 1px solid #FFF;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
main .main-item-list .inner-container > div {
|
||||
padding-left: 12px;
|
||||
padding-right: 8px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
main .main-item-list .main-item-title {
|
||||
border-bottom: 1px solid #EAEAEA;
|
||||
}
|
||||
main .main-item-list .main-items-radio-box {
|
||||
width: 48px;
|
||||
height: 32px;
|
||||
line-height: 40px;
|
||||
text-align: center;
|
||||
}
|
||||
main .main-item-list .main-items-radio-box .main-items-radio {
|
||||
display: none;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
||||
main .main-item-list .main-items-radio-box .main-items-radio[currstatus=true] {
|
||||
display: block;
|
||||
}
|
||||
main .main-item-list .main-items-icon {
|
||||
min-width: 38px;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
text-align: center;
|
||||
}
|
||||
main .main-item-title .main-items-icon {
|
||||
height: 32px!important;
|
||||
line-height: 9px!important;
|
||||
}
|
||||
main .main-item-title .main-items-icon:hover,
|
||||
main .main-item-list .main-items-displayName:hover,
|
||||
main .main-item-list .main-items-dateModified:hover,
|
||||
main .main-item-list .main-items-size:hover {
|
||||
background-color: #EAEAEA;
|
||||
}
|
||||
main .main-item-list .main-items-icon .iconfont {
|
||||
font-size: 20px;
|
||||
}
|
||||
main .main-item-list .main-items-icon img {
|
||||
display: inline-block;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
main .main-items {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
border-bottom: 1px solid #F4F4F4;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
main .main-item-list .main-items-displayName,
|
||||
main .main-item-list .main-items-fileName {
|
||||
width: 520px;
|
||||
}
|
||||
main .main-item-list .main-items-dateModified,
|
||||
main .main-item-list .main-items-dateTime {
|
||||
width: 250px;
|
||||
}
|
||||
main .main-item-list .main-items-size,
|
||||
main .main-item-list .main-items-fileSize {
|
||||
width: 180px;
|
||||
}
|
||||
main .main-item-list .main-items-radio-box,
|
||||
main .main-item-list .main-items-icon,
|
||||
main .main-item-list .main-items-fileName,
|
||||
main .main-item-list .main-items-dateTime,
|
||||
main .main-item-list .main-items-fileSize {
|
||||
padding: 11px 8px 11px 12px;
|
||||
height: 42px;
|
||||
line-height: 22px;
|
||||
font-family: "Microsoft Yahei UI", Verdana, Simsun, "Segoe UI", -apple-system, BlinkMacSystemFont, "Roboto", "Helvetica Neue", sans-serif;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
box-sizing: border-box;
|
||||
/*overflow: hidden;*/
|
||||
}
|
||||
main .main-item-list .main-items-fileName a {
|
||||
color: inherit;
|
||||
}
|
||||
main .main-item-list .main-items-fileName a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.more-disk{
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow:ellipsis;
|
||||
white-space: nowrap;
|
||||
display: inline-block;
|
||||
max-width: 100px;
|
||||
}
|
||||
.more-disk div{
|
||||
list-style:none;
|
||||
position:absolute;
|
||||
display:none;background:#ffffff;border-radius:5px;margin:0 0 0 -10px;/*padding:0 7px;*/color:#205D67;z-index:1;
|
||||
box-shadow: 0 0.5em 3em rgba(161,177,204,.4);
|
||||
}
|
||||
.more-disk:hover div{display:block}
|
||||
.more-disk div li{line-height:normal;padding: 3px 10px;}
|
||||
.more-disk div li a{text-decoration: none; color:rgba(0,0,0,.3);}
|
||||
.more-disk div li a:hover{color:rgba(0,0,0,.87);}
|
||||
.more-disk div li a[now]{color:rgba(0,0,0,1);}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="container">
|
||||
<div class="title pull-left">
|
||||
<a href="<!--base_path-->"><!--Sitename--></a>
|
||||
</div>
|
||||
<div class="pull-right"><!--
|
||||
<!--LoginStart-->
|
||||
<a class="pull-left" onclick="/*login();*/"><!--constStr@Login--></a>
|
||||
<!--LoginEnd-->
|
||||
<!--AdminStart-->
|
||||
<a class="pull-left" onclick="logout();"><!--constStr@Logout--></a>
|
||||
<!--AdminEnd-->
|
||||
| -->
|
||||
<div class="pull-right lang">
|
||||
<select name="language" id="language" class="language" onchange="changelanguage(this.options[this.options.selectedIndex].value)">
|
||||
<option value="">Language</option>
|
||||
<!--SelectLanguageStart-->
|
||||
<option value="<!--SelectLanguageKey-->" <!--SelectLanguageSelected-->><!--SelectLanguageValue--></option>
|
||||
<!--SelectLanguageEnd-->
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<!--AdminStart-->
|
||||
<div class="control">
|
||||
<div class="container">
|
||||
<div class="control-item">
|
||||
<button class="control-items">
|
||||
<i class="iconfont control-items-icon"></i>
|
||||
<span class="control-items-content"><!--constStr@Create--></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--AdminEnd-->
|
||||
</header>
|
||||
<main>
|
||||
<!--ListStart-->
|
||||
<div class="scroll">
|
||||
<div class="container">
|
||||
<div class="main-title">
|
||||
<h1 class="main-title-path">
|
||||
<a href="<!--base_path-->"><!--constStr@Home--></a>
|
||||
<!--DiskPathArrayStart-->
|
||||
>
|
||||
<a href="<!--PathArrayLink-->"><!--PathArrayName--></a>
|
||||
<!--DiskPathArrayEnd-->
|
||||
</h1>
|
||||
</div>
|
||||
<!--IsFileStart-->
|
||||
<div class="main-item-list">
|
||||
<div class="main-items main-item-title">
|
||||
<div class="inner-container">
|
||||
<div>
|
||||
<div style="margin: 24px">
|
||||
<textarea id="url" title="url" rows="1" style="width: 100%; margin-top: 2px;" readonly><!--FileEncodeUrl--></textarea>
|
||||
<a href="<!--FileEncodeUrl-->"><ion-icon name="download" style="line-height: 16px;vertical-align: middle;"></ion-icon> <!--constStr@Download--></a>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<!--IsimgFileStart-->
|
||||
<img src="<!--FileDownUrl-->" alt="<!--FileName-->" onload="if (this.offsetWidth>document.getElementById('url').offsetWidth) this.style.width='100%';" />
|
||||
<!--IsimgFileEnd-->
|
||||
<!--IsvideoFileStart-->
|
||||
<div id="video-a0"></div>
|
||||
<!--IsvideoFileEnd-->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--IsFileEnd-->
|
||||
<!--IsFolderStart-->
|
||||
<div class="main-item-list">
|
||||
<div class="main-items main-item-title">
|
||||
<div class="inner-container">
|
||||
<!--AdminStart-->
|
||||
<div class="main-items-radio-box">
|
||||
<!-- <input class="main-items-radio main-items-check-all" type="radio" name="" id=""> -->
|
||||
</div>
|
||||
<!--AdminEnd-->
|
||||
<div class="main-items-icon">
|
||||
<i class="iconfont"></i>
|
||||
</div>
|
||||
<div class="main-items-displayName"><!--constStr@File--></div>
|
||||
<div class="main-items-dateModified"><!--constStr@EditTime--></div>
|
||||
<div class="main-items-size"><!--constStr@Size--></div>
|
||||
</div>
|
||||
</div>
|
||||
<!--FolderListStart-->
|
||||
<div class="main-items">
|
||||
<!--AdminStart-->
|
||||
<div class="main-items-radio-box">
|
||||
<input class="main-items-radio" type="radio" checked name="file" id="">
|
||||
</div>
|
||||
<!--AdminEnd-->
|
||||
<div class="main-items-icon">
|
||||
<img src="https://spoprod-a.akamaihd.net/files/fabric/assets/item-types-fluent/20/folder.svg" alt="folder icon">
|
||||
</div>
|
||||
<div class="main-items-fileName">
|
||||
<a href="<!--FileEncodeReplaceUrl-->/"><!--FileEncodeReplaceName--></a>
|
||||
</div>
|
||||
<div class="main-items-dateTime" ><!--lastModifiedDateTime--></div>
|
||||
<div class="main-items-fileSize" ><!--size--></div>
|
||||
</div>
|
||||
<!--FolderListEnd-->
|
||||
<!--FileListStart-->
|
||||
<div class="main-items">
|
||||
<!--AdminStart-->
|
||||
<div class="main-items-radio-box">
|
||||
<input class="main-items-radio" type="radio" checked name="file" id="">
|
||||
</div>
|
||||
<!--AdminEnd-->
|
||||
<div class="main-items-icon">
|
||||
<i class="iconfont"></i>
|
||||
</div>
|
||||
<div class="main-items-fileName">
|
||||
<a href="<!--FileEncodeReplaceUrl-->?preview" target="_blank"><!--FileEncodeReplaceName--></a>
|
||||
</div>
|
||||
<div class="main-items-dateTime" ><!--lastModifiedDateTime--></div>
|
||||
<div class="main-items-fileSize" ><!--size--></div>
|
||||
</div>
|
||||
<!--FileListEnd-->
|
||||
</div>
|
||||
<!--IsFolderEnd-->
|
||||
</div>
|
||||
</div>
|
||||
<!--ListEnd-->
|
||||
</main>
|
||||
<footer>
|
||||
<!-- OneDrive程序 -->
|
||||
</footer>
|
||||
<div id="mask" class="mask" style="display:none;"></div>
|
||||
<!--LoginStart-->
|
||||
<div id="login_div" class="operatediv" style="display:none">
|
||||
<div style="margin:50px">
|
||||
<a onclick="operatediv_close('login')" class="operatediv_close"><!--constStr@Close--></a>
|
||||
<center>
|
||||
<form action="<!--IsPreview?-->login=admin" method="post">
|
||||
<input id="login_input" name="password1" type="password" placeholder="<!--constStr@InputPassword-->">
|
||||
<input type="submit" value="<!--constStr@Login-->">
|
||||
</form>
|
||||
</center>
|
||||
</div>
|
||||
</div>
|
||||
<!--LoginEnd-->
|
||||
<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
|
||||
<script>
|
||||
<!--AdminStart-->
|
||||
window.onload = function ()
|
||||
{
|
||||
// 获取所有radios元素
|
||||
var allRadios = document.getElementsByClassName("main-items-radio");
|
||||
RegisterRadioClick(allRadios);
|
||||
}
|
||||
|
||||
// 为所有radio注册点击事件
|
||||
function RegisterRadioClick(radios)
|
||||
{
|
||||
if (radios != null)
|
||||
{
|
||||
var radio;
|
||||
for (var i = 0; i < radios.length ; i++)
|
||||
{
|
||||
// 获取单个radio元素
|
||||
radio = radios[i];
|
||||
// 为每个radio元素设置当前状态为:False
|
||||
//radio.setAttribute("currStatus", "false");
|
||||
// 页面刚加载后,取消因缓存的checked属性
|
||||
radio.checked = false;
|
||||
// 为页面中每个radio元素注册点击事件
|
||||
radio.onclick = function()
|
||||
{
|
||||
// 获取当前点击对象的自定义属性
|
||||
var currStatus = this.getAttribute("currStatus");
|
||||
AllRadioCurrentStatus2False(radios);
|
||||
if (currStatus === "true")
|
||||
{
|
||||
AllRadioCurrentStatus2False(radios);
|
||||
this.setAttribute("currStatus", false);
|
||||
this.checked = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setAttribute("currStatus", true);
|
||||
this.checked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 把页面里所有radio元素自定义属性变成为false
|
||||
// 不然会出现需要点击两次才会被选中
|
||||
function AllRadioCurrentStatus2False(radios)
|
||||
{
|
||||
for (var i = 0; i < radios.length; i++)
|
||||
{
|
||||
radios[i].setAttribute("currStatus", false);
|
||||
}
|
||||
}
|
||||
<!--AdminEnd-->
|
||||
function changelanguage(str)
|
||||
{
|
||||
if (str=='Language') str = '';
|
||||
document.cookie='language='+str+'; path=/';
|
||||
location.href = location.href;
|
||||
}
|
||||
<!--ListStart-->
|
||||
/*var root = '<!--base_disk_path-->';
|
||||
function path_format(path) {
|
||||
path = '/' + path + '/';
|
||||
while (path.indexOf('//') !== -1) {
|
||||
path = path.replace('//', '/')
|
||||
}
|
||||
return path
|
||||
}
|
||||
document.querySelectorAll('.main-title-path').forEach(function (e) {
|
||||
var path = e.innerText;
|
||||
if (path.substr(path.length-1)=='/') path = path.substr(0, path.length-1);
|
||||
var paths = path.split('/');
|
||||
e.innerHTML = '<a href="' + root + '"><!--constStr@Home--></a> > ';
|
||||
if (paths <= 2) return;
|
||||
for (var i = 1; i < paths.length - 1; i++) {
|
||||
var to = path_format(root + paths.slice(0, i + 1).join('/'));
|
||||
e.innerHTML += '<a href="' + to + '">' + paths[i] + '</a> > '
|
||||
}
|
||||
e.innerHTML += paths[paths.length - 1];
|
||||
e.innerHTML = e.innerHTML.replace(/\s\/\s$/, '')
|
||||
});*/
|
||||
<!--IsFileStart-->
|
||||
var $url = document.getElementById('url');
|
||||
if ($url) {
|
||||
//$url.innerHTML = location.protocol + '//' + location.host + $url.innerHTML;
|
||||
let url = location.href;
|
||||
url = url.substr(0, url.length-8);
|
||||
$url.innerHTML = url.replace(/&/g, '&amp;');
|
||||
$url.style.height = $url.scrollHeight + 'px';
|
||||
}
|
||||
<!--IsvideoFileStart-->
|
||||
function loadResources(type, src, callback) {
|
||||
let script = document.createElement(type);
|
||||
let loaded = false;
|
||||
if (typeof callback === 'function') {
|
||||
script.onload = script.onreadystatechange = () => {
|
||||
if (!loaded && (!script.readyState || /loaded|complete/.test(script.readyState))) {
|
||||
script.onload = script.onreadystatechange = null;
|
||||
loaded = true;
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type === 'link') {
|
||||
script.href = src;
|
||||
script.rel = 'stylesheet';
|
||||
} else {
|
||||
script.src = src;
|
||||
}
|
||||
document.getElementsByTagName('head')[0].appendChild(script);
|
||||
}
|
||||
function addVideos(videos) {
|
||||
let host = 'https://s0.pstatp.com/cdn/expire-1-M';
|
||||
let unloadedResourceCount = 4;
|
||||
let callback = (() => {
|
||||
return () => {
|
||||
if (!--unloadedResourceCount) {
|
||||
createDplayers(videos);
|
||||
}
|
||||
};
|
||||
})(unloadedResourceCount, videos);
|
||||
loadResources(
|
||||
'link',
|
||||
host + '/dplayer/1.25.0/DPlayer.min.css',
|
||||
callback
|
||||
);
|
||||
loadResources(
|
||||
'script',
|
||||
host + '/dplayer/1.25.0/DPlayer.min.js',
|
||||
callback
|
||||
);
|
||||
loadResources(
|
||||
'script',
|
||||
host + '/hls.js/0.12.4/hls.light.min.js',
|
||||
callback
|
||||
);
|
||||
loadResources(
|
||||
'script',
|
||||
host + '/flv.js/1.5.0/flv.min.js',
|
||||
callback
|
||||
);
|
||||
}
|
||||
function createDplayers(videos) {
|
||||
for (i = 0; i < videos.length; i++) {
|
||||
console.log(videos[i]);
|
||||
new DPlayer({
|
||||
container: document.getElementById('video-a' + i),
|
||||
screenshot: true,
|
||||
video: {
|
||||
url: videos[i]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
addVideos(['<!--FileDownUrl-->']);
|
||||
<!--IsvideoFileEnd-->
|
||||
<!--IsFileEnd-->
|
||||
<!--ListEnd-->
|
||||
<!--AdminStart-->
|
||||
function logout() {
|
||||
document.cookie = "admin=; path=/";
|
||||
location.href = location.href;
|
||||
}
|
||||
<!--AdminEnd-->
|
||||
<!--LoginStart-->
|
||||
function login() {
|
||||
document.getElementById('mask').style.display='';
|
||||
//document.getElementById('mask').style.width=document.documentElement.scrollWidth+'px';
|
||||
document.getElementById('mask').style.height=document.documentElement.scrollHeight<window.innerHeight?window.innerHeight:document.documentElement.scrollHeight+'px';
|
||||
document.getElementById('login_div').style.display='';
|
||||
document.getElementById('login_div').style.left=(document.body.clientWidth-document.getElementById('login_div').offsetWidth)/2 +'px';
|
||||
document.getElementById('login_div').style.top=(window.innerHeight-document.getElementById('login_div').offsetHeight)/2+document.body.scrollTop +'px';
|
||||
document.getElementById('login_input').focus();
|
||||
}
|
||||
<!--LoginEnd-->
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,27 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title><!--Sitename--> /<!--PathArrayStart--><!--PathArrayName-->/<!--PathArrayEnd--></title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><!--Sitename--> /<!--DiskPathArrayStart--><!--PathArrayName-->/<!--DiskPathArrayEnd--></h1>
|
||||
<table>
|
||||
<tr><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr>
|
||||
<tr><th colspan="4"><hr></th></tr>
|
||||
<!--BackArrowStart-->
|
||||
<tr><td><a href="<!--BackArrowUrl-->">Parent Directory</a> </td><td> </td><td align="right"> - </td><td> </td></tr>
|
||||
<!--BackArrowEnd-->
|
||||
<!--ListStart-->
|
||||
<!--IsFolderStart-->
|
||||
<!--FolderListStart-->
|
||||
<tr><td><a href="<!--FileEncodeReplaceUrl-->/"><!--FileEncodeReplaceName-->/</a></td><td align="right"><!--lastModifiedDateTime--></td><td align="right"> - </td><td> </td></tr>
|
||||
<!--FolderListEnd-->
|
||||
<!--FileListStart-->
|
||||
<tr><td><a href="<!--FileEncodeReplaceUrl-->"><!--FileEncodeReplaceName--></a></td><td align="right"><!--lastModifiedDateTime--></td><td align="right"><!--size--></td><td> </td></tr>
|
||||
<!--FileListEnd-->
|
||||
<!--IsFolderEnd-->
|
||||
<!--ListEnd-->
|
||||
<tr><th colspan="4"><hr></th></tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,24 @@
|
|||
<html>
|
||||
<head>
|
||||
<title><!--Sitename--> - /<!--PathArrayStart--><!--PathArrayName-->/<!--PathArrayEnd--></title>
|
||||
</head>
|
||||
<body>
|
||||
<H1><!--Sitename--> - /<!--DiskPathArrayStart--><!--PathArrayName-->/<!--DiskPathArrayEnd--></H1><hr>
|
||||
<table>
|
||||
<!--BackArrowStart-->
|
||||
<tr><td colspan="3"><A HREF="<!--BackArrowUrl-->">[To Parent Directory]</A></td></tr>
|
||||
<!--BackArrowEnd-->
|
||||
<!--ListStart-->
|
||||
<!--IsFolderStart-->
|
||||
<!--FolderListStart-->
|
||||
<tr><td><!--lastModifiedDateTime--></td><td align="right" width="20%"><dir></td><td><A HREF="<!--FileEncodeReplaceUrl-->/"><!--FileEncodeReplaceName--></A></td></tr>
|
||||
<!--FolderListEnd-->
|
||||
<!--FileListStart-->
|
||||
<tr><td><!--lastModifiedDateTime--></td><td align="right" width="20%"><!--size--></td><td><A HREF="<!--FileEncodeReplaceUrl-->"><!--FileEncodeReplaceName--></A></td></tr>
|
||||
<!--FileListEnd-->
|
||||
<!--IsFolderEnd-->
|
||||
<!--ListEnd-->
|
||||
</table>
|
||||
<hr>
|
||||
</body>
|
||||
</html>
|
1289
theme/ly_white.php
1289
theme/ly_white.php
File diff suppressed because it is too large
Load Diff
1283
theme/lybwb.php
1283
theme/lybwb.php
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,377 @@
|
|||
<!--IconValuesStart-->
|
||||
{
|
||||
"music":"audiotrack",
|
||||
"video":"ondemand_video",
|
||||
"img":"image",
|
||||
"default":"insert_drive_file"
|
||||
}
|
||||
<!--IconValuesEnd-->
|
||||
<!DOCTYPE html>
|
||||
<html lang="<!--constStr@language-->">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
|
||||
<title><!--Title--></title>
|
||||
<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="stylesheet" href="//cdnjs.loli.net/ajax/libs/mdui/0.4.1/css/mdui.css">
|
||||
<style>
|
||||
body{background-color:#f2f5fa;padding-bottom:60px;<!--BackgroundStart-->background-position:center bottom;background-repeat:no-repeat;background-size:cover;background-attachment:fixed;background-image:url("<!--BackgroundUrl-->");<!--BackgroundEnd-->}
|
||||
.nexmoe-item{margin:20px -8px 0!important;padding:15px!important;border-radius:5px;background-color:#fff;-webkit-box-shadow:0 .5em 3em rgba(161,177,204,.4);box-shadow:0 .5em 3em rgba(161,177,204,.4);background-color:#fff}
|
||||
.mdui-img-fluid,.mdui-video-fluid{border-radius:5px;border:1px solid #eee}
|
||||
.mdui-list{padding:0}
|
||||
.mdui-list-item{margin:0!important;border-radius:5px;padding:0 10px 0 5px!important;border:1px solid #eee;margin-bottom:10px!important}
|
||||
.mdui-list-item:last-child{margin-bottom:0!important}
|
||||
.mdui-list-item:first-child{border:none}
|
||||
.mdui-toolbar{width:auto;margin-top:60px!important}
|
||||
.mdui-appbar .mdui-toolbar{height:56px;font-size:16px}
|
||||
.mdui-toolbar>*{padding:0 6px;margin:0 2px;}
|
||||
.mdui-toolbar>.mdui-typo-headline{padding:0 16px 0 0}
|
||||
.mdui-toolbar>i{padding:0}
|
||||
.mdui-toolbar>a{padding:0 16px;line-height:30px;border-radius:30px;border:1px solid #eee;opacity:.87}
|
||||
.mdui-toolbar>a:hover,a.mdui-typo-headline,a.active{opacity:1}
|
||||
.mdui-container{max-width:980px}
|
||||
.mdui-list>.th{background-color:initial}
|
||||
.mdui-list-item>a{width:100%;line-height:48px}
|
||||
.mdui-toolbar>a:last-child{opacity:1;background-color:#1e89f2;color:#ffff}
|
||||
.more-disk{display: inline-block;max-width: 100px;}
|
||||
.more-disk div{
|
||||
list-style:none;
|
||||
position:absolute;display:none;background:#ffffff;border-radius:5px;margin:0 0 0 -10px;/*padding:0 7px;*/color:#205D67;z-index:1;
|
||||
box-shadow: 0 0.5em 3em rgba(161,177,204,.4);
|
||||
}
|
||||
.more-disk:hover div{display:block}
|
||||
.more-disk div li{line-height:normal;padding: 3px 10px;}
|
||||
.more-disk div li a{text-decoration: none; color:rgba(0,0,0,.3);}
|
||||
.more-disk div li a:hover{color:rgba(0,0,0,.87);}
|
||||
.more-disk div li a[now]{color:rgba(0,0,0,1);}
|
||||
@media screen and (max-width:980px){
|
||||
.mdui-list-item .mdui-text-right{display:none}
|
||||
.mdui-container{width:100%!important;margin:0}
|
||||
/*.mdui-toolbar>*{display:none}*/
|
||||
.mdui-toolbar>a:last-child,.mdui-toolbar>.mdui-typo-headline,.mdui-toolbar>i:first-child{display:block}
|
||||
}
|
||||
</style>
|
||||
<!--customCss-->
|
||||
<script src="//cdnjs.loli.net/ajax/libs/mdui/0.4.1/js/mdui.min.js"></script>
|
||||
</head>
|
||||
<body class="mdui-theme-primary-blue-grey mdui-theme-accent-blue">
|
||||
<div class="mdui-container">
|
||||
<div class="mdui-container-fluid">
|
||||
<div class="mdui-toolbar nexmoe-item" id="toolbar">
|
||||
<a href="<!--base_path-->"><!--Sitename--></a>
|
||||
<!--MultiDiskAreaStart-->
|
||||
<i class="mdui-icon material-icons mdui-icon-dark" style="margin:0;">chevron_right</i>
|
||||
<div class="more-disk">
|
||||
<span><!--DiskNameNow--></span>
|
||||
<div>
|
||||
<!--MultiDisksStart-->
|
||||
<li><a href="<!--MultiDisksUrl-->" <!--MultiDisksNow-->><!--MultiDisksName--></a></li>
|
||||
<!--MultiDisksEnd-->
|
||||
</div>
|
||||
</div>
|
||||
<!--MultiDiskAreaEnd-->
|
||||
<!--PathArrayStart-->
|
||||
<i class="mdui-icon material-icons mdui-icon-dark" style="margin:0;">chevron_right</i>
|
||||
<a href="<!--PathArrayLink-->"><!--PathArrayName--></a>
|
||||
<!--PathArrayEnd-->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--ListStart-->
|
||||
<div class="mdui-container-fluid">
|
||||
<!--EncryptedStart-->
|
||||
<div class="mdui-col-md-6 mdui-col-offset-md-3">
|
||||
<!--<center><h1 class="mdui-typo-display-2-opacity">这是一个受保护的文件夹,您需要提供访问密码才能查看。</h1></center>-->
|
||||
<form action="" method="post">
|
||||
<div class="mdui-textfield mdui-textfield-floating-label">
|
||||
<i class="mdui-icon material-icons">https</i>
|
||||
<label class="mdui-textfield-label"><!--constStr@InputPassword--></label>
|
||||
<input name="password1" class="mdui-textfield-input" type="password"/>
|
||||
</div>
|
||||
<br>
|
||||
<button type="submit" class="mdui-center mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme">
|
||||
<i class="mdui-icon material-icons">fingerprint</i>
|
||||
<!--constStr@Submit-->
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<!--EncryptedEnd-->
|
||||
<!--GuestUploadStart-->
|
||||
<!--
|
||||
<div class="nexmoe-item" style="padding: 100px!important;">
|
||||
<div class="mdui-typo-display-3-opacity" style="text-align:center;">OneImages</div>
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
<input class="mdui-center" type="file" style="margin: 50px 0;" name="file" />
|
||||
<div class="mdui-row-xs-3">
|
||||
<div class="mdui-col"></div>
|
||||
<div class="mdui-col">
|
||||
<button class="mdui-btn mdui-btn-block mdui-color-theme-accent mdui-ripple"><!--constStr@Upload--></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
-->
|
||||
<!--GuestUploadEnd-->
|
||||
<!--HeadomfStart-->
|
||||
<div class="mdui-typo mdui-shadow-3" style="padding: 20px;margin: 20px 0">
|
||||
<!--HeadomfContent-->
|
||||
</div>
|
||||
<!--HeadomfEnd-->
|
||||
<!--HeadmdStart-->
|
||||
<div class="mdui-typo mdui-shadow-3 markdown" style="padding: 20px;margin: 20px 0">
|
||||
<!--HeadmdContent-->
|
||||
</div>
|
||||
<!--HeadmdEnd-->
|
||||
<!--IsFileStart-->
|
||||
<!--IsimgFileStart-->
|
||||
<div class="nexmoe-item">
|
||||
<img class="mdui-img-fluid mdui-center" src="<!--FileDownUrl-->"/>
|
||||
</div>
|
||||
<!--IsimgFileEnd-->
|
||||
<!--IstxtFileStart-->
|
||||
<div class="nexmoe-item">
|
||||
<pre id="editor" style="white-space: pre-wrap;"><!--TxtContent--></pre>
|
||||
</div>
|
||||
<!--IstxtFileEnd-->
|
||||
<!--IsmusicFileStart-->
|
||||
<div class="nexmoe-item">
|
||||
<audio class="mdui-center" src="<!--FileDownUrl-->" controls autoplay style="width: 100%;" ></audio>
|
||||
</div>
|
||||
<!--IsmusicFileEnd-->
|
||||
<!--IsofficeFileStart-->
|
||||
<div class="nexmoe-item">
|
||||
<iframe id="office-a" src="https://view.officeapps.live.com/op/view.aspx?src=<!--FileEncodeDownUrl-->" style="width: 100%;height: 800px" frameborder="0"></iframe>
|
||||
</div>
|
||||
<!--IsofficeFileEnd-->
|
||||
<!--IsvideoFileStart-->
|
||||
<link class="dplayer-css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dplayer/dist/DPlayer.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/dplayer/dist/DPlayer.min.js"></script>
|
||||
<div class="nexmoe-item">
|
||||
<div class="mdui-center" id="dplayer"></div>
|
||||
</div>
|
||||
<script>
|
||||
const dp = new DPlayer({
|
||||
container: document.getElementById('dplayer'),
|
||||
lang:'zh-cn',
|
||||
video: {
|
||||
url: '<!--FileDownUrl-->',
|
||||
type: 'auto'
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<!--IsvideoFileEnd-->
|
||||
<!--IsOtherFileStart-->
|
||||
<div class="nexmoe-item"><!--constStr@FileNotSupport--></div>
|
||||
<!--IsOtherFileEnd-->
|
||||
<a href="<!--FileEncodeReplaceUrl-->" class="mdui-fab mdui-fab-fixed mdui-ripple mdui-color-theme-accent"><i class="mdui-icon material-icons">file_download</i></a>
|
||||
<!--IsFileEnd-->
|
||||
<!--IsFolderStart-->
|
||||
<style>
|
||||
.thumb .th{
|
||||
display: none;
|
||||
}
|
||||
.thumb .mdui-text-right{
|
||||
display: none;
|
||||
}
|
||||
.thumb .mdui-list-item a ,.thumb .mdui-list-item {
|
||||
width:217px;
|
||||
height: 230px;
|
||||
float: left;
|
||||
margin: 10px 10px !important;
|
||||
}
|
||||
.thumb .mdui-col-xs-12,.thumb .mdui-col-sm-7{
|
||||
width:100% !important;
|
||||
height:230px;
|
||||
}
|
||||
.thumb .mdui-list-item .mdui-icon{
|
||||
font-size:100px;
|
||||
display: block;
|
||||
margin-top: 40px;
|
||||
color: #7ab5ef;
|
||||
}
|
||||
.thumb .mdui-list-item span{
|
||||
float: left;
|
||||
display: block;
|
||||
text-align: center;
|
||||
width:100%;
|
||||
position: absolute;
|
||||
top: 180px;
|
||||
}
|
||||
</style>
|
||||
<div class="nexmoe-item">
|
||||
|
||||
<div class="mdui-row">
|
||||
<ul class="mdui-list">
|
||||
<li class="mdui-list-item th">
|
||||
<div class="mdui-col-xs-12 mdui-col-sm-7"><!--constStr@File--> <i class="mdui-icon material-icons icon-sort" data-sort="name" data-order="downward">expand_more</i></div>
|
||||
<div class="mdui-col-sm-3 mdui-text-right"><!--constStr@EditTime--> <i class="mdui-icon material-icons icon-sort" data-sort="date" data-order="downward">expand_more</i></div>
|
||||
<div class="mdui-col-sm-2 mdui-text-right"><!--constStr@Size--> <i class="mdui-icon material-icons icon-sort" data-sort="size" data-order="downward">expand_more</i></div>
|
||||
</li>
|
||||
<!--BackArrowStart-->
|
||||
<li class="mdui-list-item mdui-ripple">
|
||||
<a href="<!--BackArrowUrl-->">
|
||||
<div class="mdui-col-xs-12 mdui-col-sm-7">
|
||||
<i class="mdui-icon material-icons">arrow_upward</i>
|
||||
..
|
||||
</div>
|
||||
<div class="mdui-col-sm-3 mdui-text-right"></div>
|
||||
<div class="mdui-col-sm-2 mdui-text-right"></div>
|
||||
</a>
|
||||
</li>
|
||||
<!--BackArrowEnd-->
|
||||
|
||||
<!--FolderListStart-->
|
||||
<li class="mdui-list-item mdui-ripple">
|
||||
<a href="<!--FileEncodeReplaceUrl-->/">
|
||||
<div class="mdui-col-xs-12 mdui-col-sm-7 mdui-text-truncate">
|
||||
<i class="mdui-icon material-icons">folder_open</i>
|
||||
<span><!--FileEncodeReplaceName--></span>
|
||||
</div>
|
||||
<div class="mdui-col-sm-3 mdui-text-right"><!--lastModifiedDateTime--></div>
|
||||
<div class="mdui-col-sm-2 mdui-text-right"><!--size--></div>
|
||||
</a>
|
||||
</li>
|
||||
<!--FolderListEnd-->
|
||||
<!--FileListStart-->
|
||||
<li class="mdui-list-item file mdui-ripple">
|
||||
<a href="<!--FileEncodeReplaceUrl-->?preview" target="_blank">
|
||||
<div class="mdui-col-xs-12 mdui-col-sm-7 mdui-text-truncate">
|
||||
<i class="mdui-icon material-icons"><!--IconValue--></i>
|
||||
<span><!--FileEncodeReplaceName--></span>
|
||||
</div>
|
||||
<div class="mdui-col-sm-3 mdui-text-right"><!--lastModifiedDateTime--></div>
|
||||
<div class="mdui-col-sm-2 mdui-text-right"><!--size--></div>
|
||||
</a>
|
||||
</li>
|
||||
<!--FileListEnd-->
|
||||
|
||||
<!--MorePageStart-->
|
||||
<form action="" method="POST" id="nextpageform">
|
||||
<input type="hidden" id="pagenum" name="pagenum" value="">
|
||||
<li class="mdui-list-item th">
|
||||
<div class="mdui-col-sm-6 mdui-left mdui-text-left">
|
||||
<!--PrePageStart-->
|
||||
<a onclick="nextpage(<!--PrePageNum-->);" class="mdui-btn mdui-btn-raised"><!--constStr@PrePage--></a>
|
||||
<!--PrePageEnd-->
|
||||
<!--NextPageStart-->
|
||||
<a onclick="nextpage(<!--NextPageNum-->);" class="mdui-btn mdui-btn-raised"><!--constStr@NextPage--></a>
|
||||
<!--NextPageEnd-->
|
||||
</div>
|
||||
<div class="mdui-col-sm-6 mdui-right mdui-text-right">
|
||||
<div class="mdui-right mdui-text-right"><span class="mdui-chip-title">Page: <!--MorePageListStart--><!--MorePageListEnd--><!--MorePageListNowStart--><!--PageNum--><!--MorePageListNowEnd-->/<!--MaxPageNum--></span></div>
|
||||
</div>
|
||||
</li>
|
||||
</form>
|
||||
<!--MorePageEnd-->
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<!--ReadmemdStart-->
|
||||
<div class="mdui-typo mdui-shadow-3 markdown" style="padding: 20px;margin: 20px 0">
|
||||
<!--ReadmemdContent-->
|
||||
</div>
|
||||
<!--ReadmemdEnd-->
|
||||
<!--FootomfStart-->
|
||||
<div class="mdui-typo mdui-shadow-3" style="padding: 20px;margin: 20px 0">
|
||||
<!--FootomfContent-->
|
||||
</div>
|
||||
<!--FootomfEnd-->
|
||||
</div>
|
||||
<!--ShowThumbnailsStart-->
|
||||
<a href="javascript:thumb();" class="mdui-fab mdui-fab-fixed mdui-ripple mdui-color-theme-accent"><i class="mdui-icon material-icons">format_list_bulleted</i></a>
|
||||
<!--ShowThumbnailsEnd-->
|
||||
<!--IsFolderEnd-->
|
||||
<!--ListEnd-->
|
||||
<!--MdRequireStart--><link rel="stylesheet" href="//unpkg.zhimg.com/github-markdown-css@3.0.1/github-markdown.css">
|
||||
<script type="text/javascript" src="//unpkg.zhimg.com/marked@0.6.2/marked.min.js"></script><!--MdRequireEnd-->
|
||||
<script>
|
||||
<!--MorePageStart-->
|
||||
function nextpage(num) {
|
||||
document.getElementById('pagenum').value=num;
|
||||
document.getElementById('nextpageform').submit();
|
||||
}
|
||||
<!--MorePageEnd-->
|
||||
$ = mdui.JQ;
|
||||
$.fn.extend({
|
||||
sortElements: function (comparator, getSortable) {
|
||||
getSortable = getSortable || function () { return this; };
|
||||
var placements = this.map(function () {
|
||||
var sortElement = getSortable.call(this),
|
||||
parentNode = sortElement.parentNode,
|
||||
nextSibling = parentNode.insertBefore(
|
||||
document.createTextNode(''),
|
||||
sortElement.nextSibling
|
||||
);
|
||||
return function () {
|
||||
parentNode.insertBefore(this, nextSibling);
|
||||
parentNode.removeChild(nextSibling);
|
||||
};
|
||||
});
|
||||
return [].sort.call(this, comparator).each(function (i) {
|
||||
placements[i].call(getSortable.call(this));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function downall() {
|
||||
let dl_link_list = Array.from(document.querySelectorAll("li a"))
|
||||
.map(x => x.href) // 所有list中的链接
|
||||
.filter(x => x.slice(-1) != "/"); // 筛选出非文件夹的文件下载链接
|
||||
let blob = new Blob([dl_link_list.join("\r\n")], {
|
||||
type: 'text/plain'
|
||||
}); // 构造Blog对象
|
||||
let a = document.createElement('a'); // 伪造一个a对象
|
||||
a.href = window.URL.createObjectURL(blob); // 构造href属性为Blob对象生成的链接
|
||||
a.download = "folder_download_link.txt"; // 文件名称,你可以根据你的需要构造
|
||||
a.click() // 模拟点击
|
||||
a.remove();
|
||||
}
|
||||
<!--ShowThumbnailsStart-->
|
||||
function thumb(){
|
||||
if($('.mdui-fab i').text() == "apps"){
|
||||
$('.mdui-fab i').text("format_list_bulleted");
|
||||
$('.nexmoe-item').removeClass('thumb');
|
||||
$('.nexmoe-item .mdui-icon').show();
|
||||
$('.nexmoe-item .mdui-list-item').css("background","");
|
||||
}else{
|
||||
$('.mdui-fab i').text("apps");
|
||||
$('.nexmoe-item').addClass('thumb');
|
||||
$('.mdui-col-xs-12 i.mdui-icon').each(function(){
|
||||
if($(this).text() == "image"){
|
||||
var thumbnails = $(this).parent().parent().attr('href');
|
||||
thumbnails = thumbnails.substr(0, thumbnails.length-8)+'?thumbnails&location';
|
||||
$(this).hide();
|
||||
$(this).parent().parent().parent().css("background","url("+thumbnails+") no-repeat center top");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
<!--ShowThumbnailsEnd-->
|
||||
$(function(){
|
||||
$('.file a').each(function(){
|
||||
$(this).on('click', function () {
|
||||
var form = $('<form target=_blank method=post></form>').attr('action', $(this).attr('href')).get(0);
|
||||
$(document.body).append(form);
|
||||
form.submit();
|
||||
$(form).remove();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
$('.icon-sort').on('click', function () {
|
||||
let sort_type = $(this).attr("data-sort"), sort_order = $(this).attr("data-order");
|
||||
let sort_order_to = (sort_order === "less") ? "more" : "less";
|
||||
$('li[data-sort]').sortElements(function (a, b) {
|
||||
let data_a = $(a).attr("data-sort-" + sort_type), data_b = $(b).attr("data-sort-" + sort_type);
|
||||
let rt = data_a.localeCompare(data_b, undefined, {numeric: true});
|
||||
return (sort_order === "more") ? 0-rt : rt;
|
||||
});
|
||||
$(this).attr("data-order", sort_order_to).text("expand_" + sort_order_to);
|
||||
});
|
||||
});
|
||||
document.querySelectorAll('.markdown').forEach(function (e) {
|
||||
e.innerHTML = marked(e.innerHTML);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,580 @@
|
|||
<!--IconValuesStart-->
|
||||
{
|
||||
"music":"audiotrack",
|
||||
"video":"ondemand_video",
|
||||
"img":"image",
|
||||
"default":"insert_drive_file"
|
||||
}
|
||||
<!--IconValuesEnd-->
|
||||
<!DOCTYPE html>
|
||||
<html lang="<!--constStr@language-->">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
|
||||
<title><!--Title--></title>
|
||||
<link rel="stylesheet" href="//cdnjs.loli.net/ajax/libs/mdui/0.4.1/css/mdui.css">
|
||||
<script src="//cdnjs.loli.net/ajax/libs/mdui/0.4.1/js/mdui.min.js"></script>
|
||||
<script src="//cdn.bootcss.com/jquery/1.12.3/jquery.min.js"></script>
|
||||
<script src="//cdn.staticfile.org/layer/2.3/layer.js"></script>
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/glightbox/dist/css/glightbox.min.css">
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css">
|
||||
<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">
|
||||
|
||||
<style>
|
||||
body{<!--BackgroundStart-->background-repeat:no-repeat;background-size:cover;background-attachment:fixed;background-image:url("<!--BackgroundUrl-->");<!--BackgroundEnd-->}
|
||||
.mdui-appbar .mdui-toolbar{
|
||||
height:64px;
|
||||
font-size: 15px;
|
||||
}
|
||||
.mdui-toolbar>*{
|
||||
padding: 0 6px;
|
||||
margin: 0 2px;
|
||||
opacity:0.5;
|
||||
}
|
||||
.mdui-toolbar>.mdui-typo-headline{
|
||||
padding: 0 1px 0 0;
|
||||
}
|
||||
.mdui-toolbar>i{
|
||||
padding: 0;
|
||||
}
|
||||
.mdui-toolbar>a:hover,a.mdui-typo-headline,a.active{
|
||||
opacity:1;
|
||||
}
|
||||
.mdui-container{
|
||||
max-width:950px;
|
||||
}
|
||||
.mdui-list-item{
|
||||
-webkit-transition:none;
|
||||
transition:none;
|
||||
}
|
||||
.mdui-list>.th{
|
||||
background-color:initial;
|
||||
}
|
||||
.mdui-list-item>a{
|
||||
width:100%;
|
||||
line-height: 48px
|
||||
}
|
||||
.mdui-list-item{
|
||||
margin: 2px 0px;
|
||||
padding:0;
|
||||
}
|
||||
.mdui-toolbar>a:last-child{
|
||||
opacity:1;
|
||||
}
|
||||
#instantclick-bar {
|
||||
background: white;
|
||||
}
|
||||
.mdui-video-fluid {
|
||||
height: -webkit-fill-available;
|
||||
}
|
||||
.dplayer-video-wrap .dplayer-video {
|
||||
height: -webkit-fill-available !important;
|
||||
}
|
||||
.gslide iframe, .gslide video {
|
||||
height: -webkit-fill-available;
|
||||
}
|
||||
@media screen and (max-width:950px) {
|
||||
.mdui-list-item .mdui-text-right{
|
||||
display: none;
|
||||
}
|
||||
.mdui-container{
|
||||
width:100% !important;
|
||||
margin:0px;
|
||||
}
|
||||
.mdui-toolbar>*{
|
||||
display: none;
|
||||
}
|
||||
.mdui-toolbar>a:last-child,.mdui-toolbar>a:nth-last-of-type(2),.mdui-toolbar>.mdui-typo-headline,.mdui-toolbar>i:first-child,.mdui-toolbar-spacer{
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
.spec-col{padding:.9em;display:flex;align-items:center;white-space:nowrap;flex:1 50%;min-width:225px}
|
||||
.spec-type{font-size:1.35em}
|
||||
.spec-value{font-size:1.25em}
|
||||
.spec-text{float:left}
|
||||
.device-section{padding-top:30px}
|
||||
.spec-device-img{height:auto;height:340px;padding-bottom:30px}
|
||||
#dl-header{margin:0}
|
||||
#dl-section{padding-top:10px}
|
||||
#dl-latest{position:relative;top:50%;transform:translateY(-50%)}
|
||||
</style>
|
||||
</head>
|
||||
<body class=" mdui-appbar-with-toolbar mdui-theme-primary-indigo mdui-theme-accent-pink">
|
||||
<header class="mdui-appbar mdui-appbar-fixed mdui-color-theme mdui-appbar-inset">
|
||||
<div class="mdui-toolbar mdui-color-theme">
|
||||
<span class="mdui-btn mdui-typo-headline mdui-btn-icon mdui-ripple mdui-ripple-white" mdui-drawer="{target: '#main-drawer', swipe: true}" mdui-tooltip="{content: '菜单'}"><i class="mdui-icon material-icons">menu</i></span>
|
||||
<a href="<!--base_path-->" class="mdui-typo-headline"><!--Sitename--></a>
|
||||
<!--PathArrayStart-->
|
||||
<i class="mdui-icon material-icons mdui-icon-dark" style="margin:0;">chevron_right</i>
|
||||
<a href="<!--PathArrayLink-->"><!--PathArrayName--></a>
|
||||
<!--PathArrayEnd-->
|
||||
<div class="mdui-toolbar-spacer"></div>
|
||||
<!--ShowThumbnailsStart-->
|
||||
<a href="javascript:thumb();" id="thumb" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: '切换显示'}"><i class="mdui-icon material-icons">format_list_bulleted</i></a>
|
||||
<!--ShowThumbnailsEnd-->
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="mdui-drawer mdui-drawer-close mdui-color-indigo-50" id="main-drawer">
|
||||
<div class="mdui-grid-tile">
|
||||
<!--<a><img src="//image.suning.cn/uimg/ZR/share_order/158562104413864293.jpg"/></a>-->
|
||||
<div class="mdui-grid-tile-actions mdui-grid-tile-actions-gradient">
|
||||
<div class="mdui-grid-tile-text">
|
||||
<div class="mdui-grid-tile-title"><!--Title--></div>
|
||||
<div class="mdui-grid-tile-subtitle">OneManager</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mdui-list" mdui-collapse="{accordion: true}">
|
||||
<a href="<!--base_path-->" class="mdui-list-item mdui-ripple">
|
||||
<i class="mdui-list-item-icon mdui-icon material-icons">home</i>
|
||||
<div class="mdui-list-item-content"><!--constStr@Home--></div>
|
||||
</a>
|
||||
<!--MultiDiskAreaStart-->
|
||||
<!--MultiDisksStart-->
|
||||
<a href="<!--MultiDisksUrl-->" class="mdui-list-item mdui-ripple" <!--MultiDisksNow-->>
|
||||
<i class="mdui-list-item-icon mdui-icon material-icons">cloud</i>
|
||||
<div class="mdui-list-item-content"><!--MultiDisksName--></div>
|
||||
</a>
|
||||
<!--MultiDisksEnd-->
|
||||
<!--MultiDiskAreaEnd-->
|
||||
<a href="https://github.com/qkqpttgf/OneManager-php" class="mdui-list-item mdui-ripple">
|
||||
<i class="mdui-list-item-icon mdui-icon material-icons">code</i>
|
||||
<div class="mdui-list-item-content">Github</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--ListStart-->
|
||||
|
||||
<!--EncryptedStart-->
|
||||
<div class="mdui-col-md-6 mdui-col-offset-md-3">
|
||||
<!--<center><h1 class="mdui-typo-display-2-opacity">这是一个受保护的文件夹,您需要提供访问密码才能查看。</h1></center>-->
|
||||
<form action="" method="post">
|
||||
<div class="mdui-textfield mdui-textfield-floating-label">
|
||||
<i class="mdui-icon material-icons">https</i>
|
||||
<label class="mdui-textfield-label"><!--constStr@InputPassword--></label>
|
||||
<input name="password1" class="mdui-textfield-input" type="password"/>
|
||||
</div>
|
||||
<br>
|
||||
<button type="submit" class="mdui-center mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme">
|
||||
<i class="mdui-icon material-icons">fingerprint</i>
|
||||
<!--constStr@Submit-->
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<!--EncryptedEnd-->
|
||||
<!--GuestUploadStart-->
|
||||
<!--
|
||||
<div class="nexmoe-item" style="padding: 100px!important;">
|
||||
<div class="mdui-typo-display-3-opacity" style="text-align:center;">OneImages</div>
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
<input class="mdui-center" type="file" style="margin: 50px 0;" name="file" />
|
||||
<div class="mdui-row-xs-3">
|
||||
<div class="mdui-col"></div>
|
||||
<div class="mdui-col">
|
||||
<button class="mdui-btn mdui-btn-block mdui-color-theme-accent mdui-ripple"><!--constStr@Upload--></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
-->
|
||||
<!--GuestUploadEnd-->
|
||||
|
||||
<!--IsFileStart-->
|
||||
<div class="mdui-container-fluid">
|
||||
<!--IsimgFileStart-->
|
||||
<div class="nexmoe-item">
|
||||
<img class="mdui-img-fluid mdui-center" src="<!--FileDownUrl-->"/>
|
||||
</div>
|
||||
<!--IsimgFileEnd-->
|
||||
<!--IstxtFileStart-->
|
||||
<div class="nexmoe-item">
|
||||
<pre id="editor" style="white-space: pre-wrap;"><!--TxtContent--></pre>
|
||||
</div>
|
||||
<!--IstxtFileEnd-->
|
||||
<!--IsmusicFileStart-->
|
||||
<div class="nexmoe-item">
|
||||
<audio class="mdui-center" src="<!--FileDownUrl-->" controls autoplay style="width: 100%;" ></audio>
|
||||
</div>
|
||||
<!--IsmusicFileEnd-->
|
||||
<!--IsofficeFileStart-->
|
||||
<div class="nexmoe-item">
|
||||
<iframe id="office-a" src="https://view.officeapps.live.com/op/view.aspx?src=<!--FileEncodeDownUrl-->" style="width: 100%;height: 800px" frameborder="0"></iframe>
|
||||
</div>
|
||||
<!--IsofficeFileEnd-->
|
||||
<!--IsvideoFileStart-->
|
||||
<link class="dplayer-css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dplayer/dist/DPlayer.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/dplayer/dist/DPlayer.min.js"></script>
|
||||
<div class="nexmoe-item">
|
||||
<div class="mdui-center" id="dplayer"></div>
|
||||
</div>
|
||||
<script>
|
||||
const dp = new DPlayer({
|
||||
container: document.getElementById('dplayer'),
|
||||
lang:'zh-cn',
|
||||
video: {
|
||||
url: '<!--FileDownUrl-->',
|
||||
type: 'auto'
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<!--IsvideoFileEnd-->
|
||||
<!--IsOtherFileStart-->
|
||||
<div class="nexmoe-item"><!--constStr@FileNotSupport--></div>
|
||||
<!--IsOtherFileEnd-->
|
||||
</div>
|
||||
<a href="<!--FileEncodeReplaceUrl-->" class="mdui-fab mdui-fab-fixed mdui-ripple mdui-color-theme-accent"><i class="mdui-icon material-icons">file_download</i></a>
|
||||
|
||||
<!--IsFileEnd-->
|
||||
|
||||
<!--IsFolderStart-->
|
||||
<div class="mdui-container">
|
||||
<div class="mdui-container-fluid"></div>
|
||||
<div class="mdui-container-fluid">
|
||||
<!--HeadomfStart-->
|
||||
<div class="mdui-typo mdui-shadow-3" style="padding: 20px;margin: 20px 0">
|
||||
<!--HeadomfContent-->
|
||||
</div>
|
||||
<!--HeadomfEnd-->
|
||||
<!--HeadmdStart-->
|
||||
<div class="mdui-typo mdui-shadow-3 markdown" style="padding: 20px;margin: 20px 0">
|
||||
<!--HeadmdContent-->
|
||||
</div>
|
||||
<!--HeadmdEnd-->
|
||||
<style>
|
||||
.thumb .th{
|
||||
display: none;
|
||||
}
|
||||
.thumb .mdui-text-right{
|
||||
display: none;
|
||||
}
|
||||
.thumb .mdui-list-item a ,.thumb .mdui-list-item {
|
||||
width:213px;
|
||||
height: 230px;
|
||||
float: left;
|
||||
margin: 10px 10px !important;
|
||||
}
|
||||
|
||||
.thumb .mdui-col-xs-12,.thumb .mdui-col-sm-7{
|
||||
width:100% !important;
|
||||
height:230px;
|
||||
}
|
||||
|
||||
.thumb .mdui-list-item .mdui-icon{
|
||||
font-size:100px;
|
||||
display: block;
|
||||
margin-top: 40px;
|
||||
color: #7ab5ef;
|
||||
}
|
||||
.thumb .mdui-list-item span{
|
||||
float: left;
|
||||
display: block;
|
||||
text-align: center;
|
||||
width:100%;
|
||||
position: absolute;
|
||||
top: 180px;
|
||||
}
|
||||
.thumb .forcedownload {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="nexmoe-item">
|
||||
<div class="mdui-row">
|
||||
<ul class="mdui-list">
|
||||
<li class="mdui-list-item th" style="padding-right:36px;">
|
||||
<div class="mdui-col-xs-12 mdui-col-sm-7"><!--constStr@File--> <i class="mdui-icon material-icons icon-sort" data-sort="name" data-order="downward">expand_more</i></div>
|
||||
<div class="mdui-col-sm-3 mdui-text-right"><!--constStr@EditTime--> <i class="mdui-icon material-icons icon-sort" data-sort="date" data-order="downward">expand_more</i></div>
|
||||
<div class="mdui-col-sm-2 mdui-text-right"><!--constStr@Size--> <i class="mdui-icon material-icons icon-sort" data-sort="size" data-order="downward">expand_more</i></div>
|
||||
</li>
|
||||
<!--BackArrowStart-->
|
||||
<li class="mdui-list-item mdui-ripple">
|
||||
<a href="<!--BackArrowUrl-->">
|
||||
<div class="mdui-col-xs-12 mdui-col-sm-7">
|
||||
<i class="mdui-icon material-icons">arrow_upward</i>
|
||||
..
|
||||
</div>
|
||||
<div class="mdui-col-sm-3 mdui-text-right"></div>
|
||||
<div class="mdui-col-sm-2 mdui-text-right"></div>
|
||||
</a>
|
||||
</li>
|
||||
<!--BackArrowEnd-->
|
||||
|
||||
<!--FolderListStart-->
|
||||
<li class="mdui-list-item mdui-ripple" data-sort data-sort-name="<!--FileEncodeReplaceName-->" data-sort-date="<!--lastModifiedDateTime-->" data-sort-size="<!--size-->" style="padding-right:36px;">
|
||||
<a href="<!--FileEncodeReplaceUrl-->/">
|
||||
<div class="mdui-col-xs-12 mdui-col-sm-7 mdui-text-truncate">
|
||||
<i class="mdui-icon material-icons">folder_open</i>
|
||||
<span><!--FileEncodeReplaceName--></span>
|
||||
</div>
|
||||
<div class="mdui-col-sm-3 mdui-text-right"><!--lastModifiedDateTime--></div>
|
||||
<div class="mdui-col-sm-2 mdui-text-right"><!--size--></div>
|
||||
</a>
|
||||
</li>
|
||||
<!--FolderListEnd-->
|
||||
<!--FileListStart-->
|
||||
<li class="mdui-list-item file mdui-ripple" data-sort data-sort-name="<!--FileEncodeReplaceName-->" data-sort-date="<!--lastModifiedDateTime-->" data-sort-size="<!--size-->" data-readypreview="<!--FileExt-->">
|
||||
<a class="<!--FileExtType-->" data-name="<!--FileEncodeReplaceName-->" href="<!--FileEncodeReplaceUrl-->?preview" target="_blank">
|
||||
<!--<?php if(isImage($item['name']) and $_COOKIE["image_mode"] == "1"):?>
|
||||
<img class="mdui-img-fluid" src="<?php echo get_absolute_path($root.$path).rawurlencode($item['name']); ?>">
|
||||
<?php else:?>-->
|
||||
<div class="mdui-col-xs-12 mdui-col-sm-7 mdui-text-truncate">
|
||||
<i class="mdui-icon material-icons"><!--IconValue--></i>
|
||||
<span><!--FileEncodeReplaceName--></span>
|
||||
</div>
|
||||
<div class="mdui-col-sm-3 mdui-text-right"><!--lastModifiedDateTime--></div>
|
||||
<div class="mdui-col-sm-2 mdui-text-right"><!--size--></div>
|
||||
</a>
|
||||
|
||||
<div class="forcedownload " >
|
||||
<a title="<!--constStr@Download-->" href="<!--FileEncodeReplaceUrl-->">
|
||||
<button class="mdui-btn mdui-ripple mdui-btn-icon"><i class="mdui-icon material-icons">file_download</i></button>
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<!--FileListEnd-->
|
||||
|
||||
<!--MorePageStart-->
|
||||
<form action="" method="POST" id="nextpageform">
|
||||
<input type="hidden" id="pagenum" name="pagenum" value="">
|
||||
<li class="mdui-list-item th">
|
||||
<div class="mdui-col-sm-6 mdui-left mdui-text-left">
|
||||
<!--PrePageStart-->
|
||||
<a onclick="nextpage(<!--PrePageNum-->);" class="mdui-btn mdui-btn-raised"><!--constStr@PrePage--></a>
|
||||
<!--PrePageEnd-->
|
||||
<!--NextPageStart-->
|
||||
<a onclick="nextpage(<!--NextPageNum-->);" class="mdui-btn mdui-btn-raised"><!--constStr@NextPage--></a>
|
||||
<!--NextPageEnd-->
|
||||
</div>
|
||||
<div class="mdui-col-sm-6 mdui-right mdui-text-right">
|
||||
<div class="mdui-right mdui-text-right"><span class="mdui-chip-title">Page: <!--MorePageListStart--><!--MorePageListEnd--><!--MorePageListNowStart--><!--PageNum--><!--MorePageListNowEnd-->/<!--MaxPageNum--></span></div>
|
||||
</div>
|
||||
</li>
|
||||
</form>
|
||||
<!--MorePageEnd-->
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<!--ReadmemdStart-->
|
||||
<div class="mdui-typo mdui-shadow-3 markdown" style="padding: 20px;margin: 20px 0">
|
||||
<!--ReadmemdContent-->
|
||||
</div>
|
||||
<!--ReadmemdEnd-->
|
||||
<!--FootomfStart-->
|
||||
<div class="mdui-typo mdui-shadow-3" style="padding: 20px;margin: 20px 0">
|
||||
<!--FootomfContent-->
|
||||
</div>
|
||||
<!--FootomfEnd-->
|
||||
</div>
|
||||
</div>
|
||||
<!--IsFolderEnd-->
|
||||
<!--ListEnd-->
|
||||
<script src="//cdn.jsdelivr.net/gh/mcstudios/glightbox/dist/js/glightbox.min.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script>
|
||||
<!--MdRequireStart--><link rel="stylesheet" href="//unpkg.zhimg.com/github-markdown-css@3.0.1/github-markdown.css">
|
||||
<script type="text/javascript" src="//unpkg.zhimg.com/marked@0.6.2/marked.min.js"></script><!--MdRequireEnd-->
|
||||
<script>
|
||||
<!--MorePageStart-->
|
||||
function nextpage(num) {
|
||||
document.getElementById('pagenum').value=num;
|
||||
document.getElementById('nextpageform').submit();
|
||||
}
|
||||
<!--MorePageEnd-->
|
||||
var $$ = mdui.JQ;
|
||||
$$(function() {
|
||||
$$('.file .iframe').each(function() {
|
||||
$$(this).on('click', function() {
|
||||
url=$$(this).attr('href');
|
||||
//url=url.substr(0,url.length-8);
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '<a target="_blank" href="'+url+'">'+ $$(this).find('span').text()+'(点击新窗口打开)</a>', //jia,
|
||||
//shadeClose: true,
|
||||
move: false,
|
||||
shade: false,
|
||||
maxmin: true,
|
||||
area: ['100%', '100%'],
|
||||
content: url //le
|
||||
,min: function(layero){
|
||||
//zi;
|
||||
layero.css({top: '90%'})
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
$('.file .dl').each(function () {
|
||||
$(this).on('click', function () {
|
||||
var form = $('<form target=_blank method=post></form>').attr('action', $(this).attr('href')).get(0);
|
||||
$(document.body).append(form);
|
||||
form.submit();
|
||||
$(form).remove();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
});
|
||||
window.TC=window.TC||{};
|
||||
jQuery(".file .audio").click(function(e){
|
||||
e.preventDefault();
|
||||
TC.preview_audio(this);
|
||||
});
|
||||
TC.preview_audio = function(aud){
|
||||
if(!TC.aplayer){
|
||||
TC.aplayerList=[];
|
||||
jQuery(".file .audio").each(function(){
|
||||
var ext = jQuery(this).data("readypreview");
|
||||
var n = jQuery(this).find("span").text();
|
||||
var l = n.replace("."+ext,".lrc");
|
||||
var la = jQuery('a[data-name="'+l+'"]');
|
||||
var lrc = undefined;
|
||||
if(la.length>0){
|
||||
lrc = la[0].href+"?s";
|
||||
}
|
||||
TC.aplayerList.push({
|
||||
name:n,
|
||||
url:this.href.substr(0,this.href.length-8),
|
||||
artist:" ",
|
||||
lrc:lrc
|
||||
});
|
||||
})
|
||||
jQuery('<div id="aplayer">').appendTo("body");
|
||||
TC.aplayer = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
fixed: true,
|
||||
audio: TC.aplayerList,
|
||||
lrcType: 3
|
||||
});
|
||||
}
|
||||
var k=-1;
|
||||
for(var i in TC.aplayerList){
|
||||
if(TC.aplayerList[i].name==jQuery(aud).data("name")){
|
||||
k=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(k>=0){
|
||||
TC.aplayer.list.switch(k);
|
||||
TC.aplayer.play();
|
||||
TC.aplayer.setMode("normal");
|
||||
}
|
||||
}
|
||||
|
||||
$ = mdui.JQ;
|
||||
$.fn.extend({
|
||||
sortElements: function (comparator, getSortable) {
|
||||
getSortable = getSortable || function () { return this; };
|
||||
|
||||
var placements = this.map(function () {
|
||||
var sortElement = getSortable.call(this),
|
||||
parentNode = sortElement.parentNode,
|
||||
nextSibling = parentNode.insertBefore(
|
||||
document.createTextNode(''),
|
||||
sortElement.nextSibling
|
||||
);
|
||||
|
||||
return function () {
|
||||
parentNode.insertBefore(this, nextSibling);
|
||||
parentNode.removeChild(nextSibling);
|
||||
};
|
||||
});
|
||||
|
||||
return [].sort.call(this, comparator).each(function (i) {
|
||||
placements[i].call(getSortable.call(this));
|
||||
});
|
||||
}
|
||||
});
|
||||
var lightbox = GLightbox();
|
||||
function downall() {
|
||||
let dl_link_list = Array.from(document.querySelectorAll("li a"))
|
||||
.map(x => x.href) // 所有list中的链接
|
||||
.filter(x => x.slice(-1) != "/"); // 筛选出非文件夹的文件下载链接
|
||||
|
||||
let blob = new Blob([dl_link_list.join("\r\n")], {
|
||||
type: 'text/plain'
|
||||
}); // 构造Blog对象
|
||||
let a = document.createElement('a'); // 伪造一个a对象
|
||||
a.href = window.URL.createObjectURL(blob); // 构造href属性为Blob对象生成的链接
|
||||
a.download = "folder_download_link.txt"; // 文件名称,你可以根据你的需要构造
|
||||
a.click() // 模拟点击
|
||||
a.remove();
|
||||
}
|
||||
<!--ShowThumbnailsStart-->
|
||||
function thumb(){
|
||||
if($('#thumb i').text() == "apps"){
|
||||
$('#thumb i').text("format_list_bulleted");
|
||||
$('.nexmoe-item').removeClass('thumb');
|
||||
$('.nexmoe-item .mdui-icon').show();
|
||||
$('.nexmoe-item .mdui-list-item').css("background","");
|
||||
}else{
|
||||
$('#thumb i').text("apps");
|
||||
$('.nexmoe-item').addClass('thumb');
|
||||
$('.mdui-col-xs-12 i.mdui-icon').each(function(){
|
||||
//if($(this).text() == "image" || $(this).text() == "ondemand_video"){
|
||||
if($(this).text() == "image"){
|
||||
var thumbnails = $(this).parent().parent().attr('href');
|
||||
//var thumb =(href.indexOf('?') == -1)?'?t=220':'&t=220';
|
||||
thumbnails = thumbnails.substr(0, thumbnails.length-8)+'?thumbnails&location';
|
||||
$(this).hide();
|
||||
//$(this).parent().parent().parent().css("background","url("+href+thumb+") no-repeat center top");
|
||||
$(this).parent().parent().parent().css("background","url("+thumbnails+") no-repeat center top");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
<!--ShowThumbnailsEnd-->
|
||||
$(function(){
|
||||
$('.icon-sort').on('click', function () {
|
||||
let sort_type = $(this).attr("data-sort"), sort_order = $(this).attr("data-order");
|
||||
let sort_order_to = (sort_order === "less") ? "more" : "less";
|
||||
|
||||
$('li[data-sort]').sortElements(function (a, b) {
|
||||
let data_a = $(a).attr("data-sort-" + sort_type), data_b = $(b).attr("data-sort-" + sort_type);
|
||||
let rt = data_a.localeCompare(data_b, undefined, {numeric: true});
|
||||
return (sort_order === "more") ? 0-rt : rt;
|
||||
});
|
||||
|
||||
$(this).attr("data-order", sort_order_to).text("expand_" + sort_order_to);
|
||||
});
|
||||
});
|
||||
|
||||
var ckname='image_mode';
|
||||
function getCookie(name)
|
||||
{
|
||||
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
|
||||
if(arr=document.cookie.match(reg))
|
||||
return unescape(arr[2]);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
function setCookie(key,value,day){
|
||||
var exp = new Date();
|
||||
exp.setTime(exp.getTime() - 1);
|
||||
var cval=getCookie(key);
|
||||
if(cval!=null)
|
||||
document.cookie= key + "="+cval+";expires="+exp.toGMTString();
|
||||
var date = new Date();
|
||||
var nowDate = date.getDate();
|
||||
date.setDate(nowDate + day);
|
||||
var cookie = key+"="+value+"; expires="+date;
|
||||
document.cookie = cookie;
|
||||
return cookie;
|
||||
}
|
||||
$('#image_view').on('click', function () {
|
||||
if($(this).prop('checked') == true){
|
||||
setCookie(ckname,1,1);
|
||||
window.location.href=window.location.href;
|
||||
}else{
|
||||
setCookie(ckname,0,1);
|
||||
window.location.href=window.location.href;
|
||||
}
|
||||
});
|
||||
document.querySelectorAll('.markdown').forEach(function (e) {
|
||||
e.innerHTML = marked(e.innerHTML);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,24 @@
|
|||
<html>
|
||||
<head>
|
||||
<title><!--Sitename--> - /<!--PathArrayStart--><!--PathArrayName-->/<!--PathArrayEnd--></title>
|
||||
</head>
|
||||
<body>
|
||||
<H1><!--Sitename--> - /<!--DiskPathArrayStart--><!--PathArrayName-->/<!--DiskPathArrayEnd--></H1><hr>
|
||||
<table>
|
||||
<!--BackArrowStart-->
|
||||
<tr><td colspan="3"><A HREF="<!--BackArrowUrl-->">../</A></td></tr>
|
||||
<!--BackArrowEnd-->
|
||||
<!--ListStart-->
|
||||
<!--IsFolderStart-->
|
||||
<!--FolderListStart-->
|
||||
<tr><td><A HREF="<!--FileEncodeReplaceUrl-->/"><!--FileEncodeReplaceName-->/</A></td><td align="right"><!--lastModifiedDateTime--></td><td align="right">-</td></tr>
|
||||
<!--FolderListEnd-->
|
||||
<!--FileListStart-->
|
||||
<tr><td><A HREF="<!--FileEncodeReplaceUrl-->"><!--FileEncodeReplaceName--></A></td><td align="right"><!--lastModifiedDateTime--></td><td align="right"><!--size--></td></tr>
|
||||
<!--FileListEnd-->
|
||||
<!--IsFolderEnd-->
|
||||
<!--ListEnd-->
|
||||
</table>
|
||||
<hr>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because it is too large
Load Diff
1198
theme/onemoe.php
1198
theme/onemoe.php
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
1263
theme/purenice.php
1263
theme/purenice.php
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,515 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<link rel="preconnect" href="https://cdn.jsdelivr.net" />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" />
|
||||
<meta charset="utf-8" />
|
||||
<link
|
||||
rel="shortcut icon"
|
||||
href="<!--base_path-->favicon.ico"
|
||||
type="image/x-icon"
|
||||
/>
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"
|
||||
/>
|
||||
<title><!--Title--></title>
|
||||
<meta name="description" content="A Onemanager-PHP site with Theme-renexmoe" />
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/186526/renexmoe-cdn@v1.3/css/app.css"><meta name="theme-color" content="#fff" />
|
||||
<!--BackgroundStart-->
|
||||
<style>
|
||||
body {
|
||||
--bg: url("<!--BackgroundUrl-->");
|
||||
background-repeat: no-repeat;
|
||||
background-size: cover;
|
||||
background-attachment: fixed;
|
||||
background-image: var(--bg);
|
||||
}
|
||||
|
||||
.mdui-shadow-3 {
|
||||
background: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.disableddarkmode = true;
|
||||
</script>
|
||||
<!--BackgroundEnd-->
|
||||
<!--BackgroundMStart-->
|
||||
<style>
|
||||
body {
|
||||
--bg: url("<!--BackgroundMUrl-->");
|
||||
background-repeat: no-repeat;
|
||||
background-size: cover;
|
||||
background-attachment: fixed;
|
||||
background-image: var(--bg);
|
||||
}
|
||||
|
||||
.mdui-shadow-3 {
|
||||
background: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.disableddarkmode = true;
|
||||
</script>
|
||||
<!--BackgroundMEnd-->
|
||||
|
||||
</head>
|
||||
<body
|
||||
class="mdui-appbar-with-toolbar mdui-theme-layout-auto mdui-loaded mdui-theme-accent-pink"
|
||||
>
|
||||
<header
|
||||
class="mdui-appbar mdui-appbar-fixed mdui-shadow-0 mdui-appbar-scroll-toolbar-hide"
|
||||
>
|
||||
<div class="mdui-toolbar">
|
||||
<span
|
||||
class="mdui-btn mdui-btn-icon mdui-ripple mdui-ripple-white"
|
||||
onclick='mdui.$("body").toggleClass("mdui-drawer-body-left");'
|
||||
id="toggle-drawer"
|
||||
><i class="mdui-icon material-icons">menu</i></span
|
||||
>
|
||||
<a
|
||||
class="mdui-btn mdui-btn-icon mdui-ripple mdui-ripple-white mdui-hidden-sm-up"
|
||||
onclick="window.history.back()"
|
||||
>
|
||||
<i class="mdui-icon material-icons">arrow_back</i>
|
||||
</a>
|
||||
<a href="<!--base_path-->" class="mdui-typo-headline">
|
||||
<!--Sitename-->
|
||||
</a>
|
||||
<!--PathArrayStart-->
|
||||
<i class="mdui-icon material-icons mdui-hidden-xs" style="margin: 0"
|
||||
>chevron_right</i
|
||||
><a href="<!--PathArrayLink-->" class="mdui-typo-subheading mdui-hidden-xs">
|
||||
<!--PathArrayName--></a
|
||||
>
|
||||
<!--PathArrayEnd-->
|
||||
<div class="mdui-toolbar-spacer"></div>
|
||||
<!--AdminStart--><a
|
||||
href="javascript:;"
|
||||
class="mdui-btn mdui-btn-icon mdui-ripple mdui-hidden-sm-up refresh"
|
||||
><i class="mdui-icon material-icons">refresh</i></a
|
||||
>
|
||||
<!--AdminEnd-->
|
||||
</div>
|
||||
|
||||
</header>
|
||||
|
||||
<div class="mdui-drawer mdui-drawer-close" id="main-drawer">
|
||||
<div class="mdui-list" mdui-collapse="{accordion: true}">
|
||||
<!--LoginStart-->
|
||||
<li class="mdui-list-item mdui-ripple" href="?login=admin" >
|
||||
<a class="mdui-list-item-icon mdui-icon material-icons">account_circle</a>
|
||||
<a class="mdui-list-item-content" href="?login=admin">登录</a>
|
||||
</li>
|
||||
<!--LoginEnd-->
|
||||
<!--AdminStart-->
|
||||
<li class="mdui-list-item mdui-ripple" href="?setup">
|
||||
<a class="mdui-list-item-icon mdui-icon material-icons" href="?setup"
|
||||
>account_circle</a
|
||||
><a class="mdui-list-item-content" href="?setup">管理</a>
|
||||
</li>
|
||||
<li
|
||||
class="mdui-list-item mdui-ripple"
|
||||
onclick="document.cookie=``;window.location.reload();"
|
||||
id="logout"
|
||||
>
|
||||
<i class="mdui-icon material-icons mdui-list-item-icon">exit_to_app</i>
|
||||
<div class="mdui-list-item-content">退出登陆</div>
|
||||
</li>
|
||||
<li class="mdui-list-item mdui-ripple" id="checkupdate">
|
||||
<i class="mdui-icon material-icons mdui-list-item-icon">update</i>
|
||||
<div class="mdui-list-item-content">检查主题更新</div>
|
||||
</li>
|
||||
<div class="mdui-divider"></div>
|
||||
<!--AdminEnd-->
|
||||
|
||||
<li
|
||||
class="mdui-list-item mdui-ripple"
|
||||
href="javascript:void(0);"
|
||||
onclick="renexmoe.toggle_theme();"
|
||||
>
|
||||
<a class="mdui-list-item-icon mdui-icon material-icons">brightness_4</a
|
||||
><a class="mdui-list-item-content">深色模式</a>
|
||||
</li>
|
||||
<li class="mdui-list-item mdui-ripple">
|
||||
<a
|
||||
href="<!--base_path-->"
|
||||
class="mdui-list-item-icon mdui-icon material-icons"
|
||||
>home</a
|
||||
><a href="<!--base_path-->" class="mdui-list-item-content" id="home">
|
||||
<!--constStr@Home--></a
|
||||
>
|
||||
</li>
|
||||
<!--MultiDiskAreaStart-->
|
||||
<div class="mdui-divider"></div>
|
||||
<!--MultiDisksStart-->
|
||||
<li class="mdui-list-item mdui-ripple">
|
||||
<a
|
||||
href="<!--MultiDisksUrl-->"
|
||||
class="mdui-list-item-icon mdui-icon material-icons"
|
||||
>cloud</a
|
||||
>
|
||||
<a
|
||||
href="<!--MultiDisksUrl-->"
|
||||
class="mdui-list-item-content mdui-text-truncate disk_name"
|
||||
>
|
||||
<!--MultiDisksName-->
|
||||
</a>
|
||||
</li>
|
||||
<!--MultiDisksEnd-->
|
||||
<div class="mdui-divider"></div>
|
||||
<!--MultiDiskAreaEnd-->
|
||||
|
||||
<a
|
||||
href="https://github.com/qkqpttgf/OneManager-php"
|
||||
class="mdui-list-item mdui-ripple"
|
||||
><i class="mdui-list-item-icon mdui-icon material-icons">code</i>
|
||||
<div class="mdui-list-item-content">Github</div>
|
||||
</a>
|
||||
<li
|
||||
class="mdui-list-item mdui-ripple"
|
||||
href="javascript:void(0);"
|
||||
id="about_theme"
|
||||
>
|
||||
<i class="mdui-list-item-icon mdui-icon material-icons">info</i>
|
||||
<div class="mdui-list-item-content">关于该主题</div>
|
||||
</li>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mdui-container">
|
||||
<ul class="mdui-menu" id="admin-menu">
|
||||
<li class="mdui-menu-item">
|
||||
<a href="javascript:;" class="mdui-ripple back"
|
||||
><i class="mdui-menu-item-icon mdui-icon material-icons">arrow_back</i
|
||||
>返回上一页</a
|
||||
>
|
||||
</li>
|
||||
<!--AdminStart-->
|
||||
<li class="mdui-menu-item">
|
||||
<a href="javascript:;" class="mdui-ripple refresh"
|
||||
><i class="mdui-menu-item-icon mdui-icon material-icons">refresh</i
|
||||
>刷新缓存</a
|
||||
>
|
||||
</li>
|
||||
<!--AdminEnd-->
|
||||
</ul>
|
||||
<i id="mouseplace" style="position: absolute"></i>
|
||||
|
||||
<div class="mdui-dialog" id="login_input">
|
||||
<div class="mdui-dialog-title">登录</div>
|
||||
<div class="mdui-dialog-content" style="height: 108px">
|
||||
<div class="mdui-textfield mdui-textfield-floating-label">
|
||||
<i class="mdui-icon material-icons">lock</i
|
||||
><label class="mdui-textfield-label">密码</label
|
||||
><input
|
||||
class="mdui-textfield-input"
|
||||
name="password1"
|
||||
type="password"
|
||||
onkeydown="if(event.keyCode==13) document.querySelector('#login_btn').click();"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mdui-dialog-actions">
|
||||
<button class="mdui-btn mdui-ripple" mdui-dialog-close="" id="login_close">取消</button
|
||||
><button
|
||||
id="login_btn"
|
||||
class="mdui-btn mdui-ripple"
|
||||
type="submit"
|
||||
value="登录"
|
||||
>
|
||||
登录
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<!--EncryptedStart-->
|
||||
<div class="mdui-col-md-6 mdui-col-offset-md-3">
|
||||
<br />
|
||||
<center>
|
||||
<div class="mdui-typo-title">
|
||||
这是一个受保护的文件夹,您需要提供访问密码才能查看。
|
||||
</div>
|
||||
</center>
|
||||
<form action="" method="post">
|
||||
<div class="mdui-textfield mdui-textfield-floating-label">
|
||||
<i class="mdui-icon material-icons">https</i
|
||||
><label class="mdui-textfield-label"> <!--constStr@InputPassword--></label
|
||||
><input name="password1" class="mdui-textfield-input" type="password" />
|
||||
</div>
|
||||
<br /><button
|
||||
type="submit"
|
||||
class="mdui-center mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme"
|
||||
>
|
||||
<i class="mdui-icon material-icons">fingerprint</i>
|
||||
<!--constStr@Submit-->
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<!--EncryptedEnd-->
|
||||
|
||||
<!--IsFolderStart-->
|
||||
<!--HeadomfStart-->
|
||||
<div class="mdui-typo mdui-shadow-3" style="padding: 20px; margin: 20px 0">
|
||||
<!--HeadomfContent-->
|
||||
</div>
|
||||
<!--HeadomfEnd-->
|
||||
<!--HeadmdStart-->
|
||||
<div class="mdui-chip mdui-ripple mdui-hidden-xs">
|
||||
<span class="mdui-chip-icon"
|
||||
><i class="mdui-icon material-icons">face</i></span
|
||||
><span class="mdui-chip-title">HEAD.md</span>
|
||||
</div>
|
||||
<div
|
||||
class="mdui-typo mdui-shadow-3 markdown"
|
||||
style="padding: 20px; margin: 20px 0; overflow-x: scroll"
|
||||
id="head"
|
||||
>
|
||||
<pre><code id="head-md"><!--HeadmdContent--></code></pre>
|
||||
</div>
|
||||
<!--HeadmdEnd-->
|
||||
|
||||
<div class="mdui-row mdui-shadow-3" style="margin: 20px 0; border-radius: 8px">
|
||||
<ul class="mdui-list" id="file-list">
|
||||
<li class="mdui-list-item mdui-ripple">
|
||||
<div class="mdui-row mdui-col-xs-12">
|
||||
<div class="mdui-col-xs-12 mdui-col-sm-7">
|
||||
<!--constStr@File--><i
|
||||
class="mdui-icon material-icons icon-sort"
|
||||
data-sort="name"
|
||||
data-order="downward"
|
||||
>expand_more</i
|
||||
>
|
||||
</div>
|
||||
<div class="mdui-col-sm-3 mdui-text-right">
|
||||
<!--constStr@EditTime--><i
|
||||
class="mdui-icon material-icons icon-sort"
|
||||
data-sort="date"
|
||||
data-order="downward"
|
||||
>expand_more</i
|
||||
>
|
||||
</div>
|
||||
<div class="mdui-col-sm-2 mdui-text-right">
|
||||
<!--constStr@Size--><i
|
||||
class="mdui-icon material-icons icon-sort"
|
||||
data-sort="size"
|
||||
data-order="downward"
|
||||
>expand_more</i
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<!--BackArrowStart-->
|
||||
<li class="mdui-list-item mdui-ripple back-page">
|
||||
<div class="mdui-row mdui-col-sm-12">
|
||||
<a href="<!--BackArrowUrl-->">
|
||||
<div class="mdui-col-xs-7">
|
||||
<i class="mdui-icon material-icons">arrow_upward</i>
|
||||
</div>
|
||||
<div class="mdui-col-xs-3 mdui-text-right"></div>
|
||||
<div class="mdui-col-xs-2 mdui-text-right"></div>
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<!--BackArrowEnd-->
|
||||
<!--FolderListStart-->
|
||||
<li
|
||||
class="mdui-list-item mdui-ripple"
|
||||
data-sort
|
||||
data-sort-name="<!--FileEncodeReplaceName-->"
|
||||
data-sort-date="<!--lastModifiedDateTime-->"
|
||||
data-sort-size="<!--size-->"
|
||||
style="padding-right: 36px"
|
||||
>
|
||||
<div class="mdui-row mdui-col-sm-12">
|
||||
<a href="<!--FileEncodeReplaceUrl-->/">
|
||||
<div class="mdui-col-xs-12 mdui-col-sm-7 mdui-text-truncate">
|
||||
<i class="mdui-icon material-icons">folder_open</i
|
||||
><span> <!--FileEncodeReplaceName--></span>
|
||||
</div>
|
||||
<div class="mdui-col-sm-3 mdui-text-right">
|
||||
<!--lastModifiedDateTime-->
|
||||
</div>
|
||||
<div class="mdui-col-sm-2 mdui-text-right">
|
||||
<!--size-->
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<!--FolderListEnd-->
|
||||
<!--FileListStart-->
|
||||
<li
|
||||
class="mdui-list-item file mdui-ripple"
|
||||
data-sort
|
||||
data-sort-name="<!--FileEncodeReplaceName-->"
|
||||
data-sort-date="<!--lastModifiedDateTime-->"
|
||||
data-sort-size="<!--size-->"
|
||||
data-readypreview="<!--FileExt-->"
|
||||
>
|
||||
<div class="mdui-row mdui-col-sm-12">
|
||||
<div class="mdui-col-xs-12 mdui-col-sm-7 mdui-text-truncate">
|
||||
<a
|
||||
class="<!--FileExtType-->"
|
||||
data-name="<!--FileEncodeReplaceName-->"
|
||||
href="<!--FileEncodeReplaceUrl-->?preview"
|
||||
aria-label="File"
|
||||
>
|
||||
<i class="mdui-icon material-icons"> <!--IconValue--></i>
|
||||
<span> <!--FileEncodeReplaceName--></span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="mdui-col-sm-3 mdui-text-right">
|
||||
<!--lastModifiedDateTime-->
|
||||
</div>
|
||||
<div class="mdui-col-sm-2 mdui-text-right">
|
||||
<!--size-->
|
||||
</div>
|
||||
</div>
|
||||
<div class="forcedownload mdui-text-right">
|
||||
<a
|
||||
title="<!--constStr@Download-->"
|
||||
aria-label="Download"
|
||||
href="<!--FileEncodeReplaceUrl-->"
|
||||
target="_blank"
|
||||
><button class="mdui-btn mdui-ripple mdui-btn-icon">
|
||||
<i class="mdui-icon material-icons">file_download</i>
|
||||
</button></a
|
||||
>
|
||||
</div>
|
||||
</li>
|
||||
<!--FileListEnd-->
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<!--ReadmemdStart-->
|
||||
<div class="mdui-chip mdui-ripple mdui-hidden-xs">
|
||||
<span class="mdui-chip-icon"
|
||||
><i class="mdui-icon material-icons">face</i></span
|
||||
><span class="mdui-chip-title">README.md</span>
|
||||
</div>
|
||||
<div
|
||||
class="mdui-typo mdui-shadow-3 markdown"
|
||||
style="padding: 20px; margin: 20px 0; overflow-x: scroll"
|
||||
id="readme"
|
||||
>
|
||||
<pre><code id="readme-md"><!--ReadmemdContent--></code></pre>
|
||||
</div>
|
||||
<!--ReadmemdEnd-->
|
||||
<!--FootomfStart-->
|
||||
<div class="mdui-typo mdui-shadow-3" style="padding: 20px; margin: 20px 0">
|
||||
<!--FootomfContent-->
|
||||
</div>
|
||||
<!--FootomfEnd-->
|
||||
|
||||
<script>
|
||||
document.querySelector("#admin-menu").innerHTML +=
|
||||
'<li class="mdui-menu-item"><a href="javascript:void(0);"class="mdui-ripple getalllink"><i class="mdui-menu-item-icon mdui-icon material-icons">link</i>批量链接</a></li>';
|
||||
</script>
|
||||
<script>
|
||||
window.MorePage = undefined;
|
||||
</script>
|
||||
<!--MorePageStart-->
|
||||
<script>
|
||||
window.MorePage = [
|
||||
<!--MorePageListNowStart-->
|
||||
<!--PageNum-->,
|
||||
<!--MorePageListNowEnd-->
|
||||
<!--MorePageListStart-->
|
||||
<!--PageNum-->,
|
||||
<!--MorePageListEnd-->
|
||||
];
|
||||
</script>
|
||||
<!--MorePageEnd-->
|
||||
|
||||
<!--IsFolderEnd-->
|
||||
<!--IsFileStart-->
|
||||
<div
|
||||
id="file"
|
||||
class="mdui-shadow-3"
|
||||
style="padding: 5px; margin: 20px 0px; padding: 20px; border-radius: 8px"
|
||||
>
|
||||
<!--IsimgFileStart-->
|
||||
<img class="mdui-img-fluid mdui-center mdui-m-t-5" src="<!--FileDownUrl-->" />
|
||||
<!--IsimgFileEnd-->
|
||||
<!--IsmusicFileStart-->
|
||||
<audio
|
||||
class="mdui-center"
|
||||
src="<!--FileDownUrl-->"
|
||||
controls
|
||||
autoplay
|
||||
style="width: 100%; margin-top: 10%; margin-bottom: 10%"
|
||||
></audio>
|
||||
<!--IsmusicFileEnd-->
|
||||
|
||||
<!--IsvideoFileStart-->
|
||||
<video
|
||||
class="mdui-video-fluid"
|
||||
controls
|
||||
style="margin-top: 20px; margin-bottom: 20px"
|
||||
>
|
||||
<source src="<!--FileDownUrl-->" />
|
||||
<p>
|
||||
Your browser doesn't support HTML5 video. Here is a
|
||||
<a href="<!--FileDownUrl-->">link to the video</a> instead.
|
||||
</p>
|
||||
</video>
|
||||
<!--IsvideoFileEnd-->
|
||||
<!--IsofficeFileStart-->
|
||||
<iframe
|
||||
id="office-a"
|
||||
src="https://view.officeapps.live.com/op/view.aspx?src=<!--FileEncodeDownUrl-->"
|
||||
style="width: 100%; height: 800px"
|
||||
frameborder="0"
|
||||
></iframe>
|
||||
<!--IsofficeFileEnd-->
|
||||
|
||||
<!--IspdfFileStart-->
|
||||
<embed src="<!--FileEncodeReplaceUrl-->" type="application/pdf" />
|
||||
<!--IspdfFileEnd-->
|
||||
<!--IstxtFileStart-->
|
||||
<pre
|
||||
id="editor"
|
||||
style="
|
||||
white-space: pre-wrap;
|
||||
font-family: JetBrains Mono, Fira Code, Sarasa Mono SC, Cascadia Code, Menlo,
|
||||
Consolas, monaco, Noto Sans SC;
|
||||
"
|
||||
><code id="code"><!--TxtContent--></code></pre>
|
||||
<script>
|
||||
document.querySelector("#admin-menu").innerHTML +=
|
||||
'<li class="mdui-menu-item"><a href="javascript:void(0);"class="mdui-ripple highlight"><i class="mdui-menu-item-icon mdui-icon material-icons">style</i>markdown解析</a></li>';
|
||||
document.querySelector(
|
||||
".mdui-toolbar"
|
||||
).innerHTML += `<a href="javascript:;" class="mdui-btn mdui-btn-icon mdui-ripple mdui-hidden-sm-up highlight"><i class="mdui-icon material-icons">style</i></a>`;
|
||||
</script>
|
||||
|
||||
<!--IstxtFileEnd-->
|
||||
|
||||
<!--IsOtherFileStart-->
|
||||
<!--constStr@FileNotSupport-->
|
||||
<!--IsOtherFileEnd-->
|
||||
</div>
|
||||
<a
|
||||
href="<!--FileEncodeReplaceUrl-->"
|
||||
target="_blank"
|
||||
class="mdui-fab mdui-fab-fixed mdui-ripple mdui-color-theme-accent"
|
||||
><i class="mdui-icon material-icons">file_download</i></a
|
||||
>
|
||||
<script>
|
||||
document.querySelector("#admin-menu").innerHTML +=
|
||||
'<li class="mdui-menu-item"><a href="javascript:void(0);"class="mdui-ripple downloadurl"><i class="mdui-menu-item-icon mdui-icon material-icons">cloud_download</i>下载链接</a></li>';
|
||||
document.querySelector(
|
||||
".mdui-toolbar"
|
||||
).innerHTML += `<a href="javascript:;" class="mdui-btn mdui-btn-icon mdui-ripple mdui-hidden-sm-up downloadurl"><i class="mdui-icon material-icons">cloud_download</i></a>`;
|
||||
</script>
|
||||
<!--IsFileEnd-->
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
<!--IconValuesStart-->
|
||||
{ "music":"audiotrack", "video":"ondemand_video", "img":"image",
|
||||
"pdf":"picture_as_pdf", "default":"insert_drive_file"}
|
||||
<!--IconValuesEnd-->
|
||||
<script src="https://cdn.jsdelivr.net/gh/186526/renexmoe-cdn@v1.3/js/app@1b381f3c.a4f2dc4618121eac37e2.js"></script><script src="https://cdn.jsdelivr.net/gh/186526/renexmoe-cdn@v1.3/js/app@28a13772.98a11cc0c1cf2495c3d8.js"></script><script src="https://cdn.jsdelivr.net/gh/186526/renexmoe-cdn@v1.3/js/app@34e3d95a.2f8dbf552095a86a7f1b.js"></script><script src="https://cdn.jsdelivr.net/gh/186526/renexmoe-cdn@v1.3/js/app@798ab416.9ed46bb752b71a3c13a4.js"></script><script src="https://cdn.jsdelivr.net/gh/186526/renexmoe-cdn@v1.3/js/app@9c50beac.30955a99f08c9574cd14.js"></script><script src="https://cdn.jsdelivr.net/gh/186526/renexmoe-cdn@v1.3/js/app@f0256996.956ea71aa357ba3fdc28.js"></script><script src="https://cdn.jsdelivr.net/gh/186526/renexmoe-cdn@v1.3/js/webpack-runtime.93708ab3e9cb84dcc01a.js"></script>
|
||||
</html>
|
1240
theme/ruoli_blue.php
1240
theme/ruoli_blue.php
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -11,7 +11,7 @@ example:
|
|||
"$0" -i
|
||||
"$0" -u
|
||||
"$0" -b master
|
||||
"$0" -r -b master
|
||||
"$0" -u -b master
|
||||
"$0" -ib test
|
||||
"
|
||||
# exit
|
||||
|
@ -62,11 +62,10 @@ OneManagerPath=`cd $(dirname $0);pwd -P`
|
|||
cd ${OneManagerPath}
|
||||
|
||||
git clone ${branch} ${gitsource}
|
||||
[ g"$install" == g"1" ] || \mv -b config.php OneManager-php/
|
||||
[ g"$install" == g"1" ] || \mv -b .data/config.php OneManager-php/.data/
|
||||
\mv -b OneManager-php/* ./
|
||||
\mv -b OneManager-php/.[^.]* ./
|
||||
rm -rf *~
|
||||
rm -rf .[^.]*~
|
||||
#rm -rf .[^.]*~
|
||||
rm -rf OneManager-php
|
||||
chmod 666 config.php
|
||||
|
||||
chmod 666 .data/config.php
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
101
version
101
version
|
@ -1,7 +1,106 @@
|
|||
20220127-1234.43
|
||||
<font color="red">change login page, default not '?admin' but '?login=admin' now! and if set adminloginpage, it will be '?login=[value]'.</font> rm JumpFirstDisk, 403 in operating root, change sorting disk, remake disktags tab, add global md config. Allow Preview when enable downloadencrypt. some change in adding Onedrive disk. show upload progress in table background. fix some bugs.
|
||||
<font color="red">更改登录地址,默认不再是'?admin'而是'?login=admin',如果设置了adminloginpage,那登录地址会是'?login=值'。</font>移除 JumpFirstDisk,在root操作时返回403,更改盘排序,重做盘符排列,添加全局md配置。在开启downloadencrypt后可以网页预览了。添加onedrive盘时稍做修改。上传时以背景做进度条。修复其它bug。
|
||||
|
||||
20211220-1100.42
|
||||
Add new platform Replit. Add a git source for update. sha1.js use jsdelivr cdn. fix some bugs.
|
||||
新增Replit平台。新增国内git源,以后国内可以选择从HIT源更新。sha1.js换成jsdelivr CDN。修复bug。
|
||||
20211201-1602.41
|
||||
add a latent function, you can edit platform token(or API key) via '?setup=auth' when the token invalid, not need edit it in Environment(or Config Var) manually, (even in Vercel, config saved in file, and can't modiy it manually).
|
||||
新增隐藏功能,在平台操作代码的token或API key失效时,可以在 '?setup=auth' 修改它,不用去环境变量修改了(特别地,Vercel保存在代码中时都改不到)。
|
||||
20211129
|
||||
check if there is another deployment building when start deploy.
|
||||
Vercel部署时检测是否有另一个部署。
|
||||
20211104
|
||||
check if exist php-curl or not in php host and VPS.
|
||||
在VPS中检测是否有php-curl。
|
||||
20211021
|
||||
specialchars, fix: list folder, encrypt folder, preview files, rename, show in title, error on back link after login at specialchars folder, etc.
|
||||
针对特殊字符,解决目录的列表,目录的加密,文件的预览,目录与文件重命名,在网页标题的显示,在特殊字符处登录后跳转出错等问题。
|
||||
20211006
|
||||
oprate files by fileID, write a localStorage when login to anti CSRF.
|
||||
管理时对文件id操作,管理登录时写入一个localStorage预防CSRF。
|
||||
20210908
|
||||
add fileConduitSize&fileConduitCacheTime, little files can stream from program, better to show html/js as local file.
|
||||
增加fileConduitSize,fileConduitCacheTime,小文件可以从服务器中转,以对html/js本地化更好的支持。
|
||||
20210903
|
||||
add a latent function, you can run some command by '?setup=cmd', be care, please dont try "top", and set times by "ping -c 4".
|
||||
新增隐藏功能,你可以通过'?setup=cmd'来跑一些命令,注意不要试图跑top,另外ping请-c设置次数。
|
||||
20210820-1810.40
|
||||
because Vercel must redeploy after change Environment Variables, and it must <4k, so decide that, save config in code file. <font color=red>in Vercel, after update, please install again. if you want continue use Environment, please add a ( name: "ONEMANAGER_CONFIG_SAVE", value: "env" ) in Environment Variables in Project Settings before update.</font>
|
||||
因为Vercel修改环境变量也必须重新部署才生效,而且环境变量只能小于4k,所以决定将配置保存在代码文件中。<font color=red>升级更新后,用Vercel的请重新安装。如果还想继续使用环境变量,请在更新前,在Project Settings的Environment Variables中,新增一个( name: "ONEMANAGER_CONFIG_SAVE", value: "env" )的环境变量。</font>
|
||||
20210817-2030.39
|
||||
fix bugs in Vercel. add wait function in operating. change update method in SCF. add payme in readme.
|
||||
修复一些Vercel上的bug。在操作完后添加等待功能,确认平台已经准备好。SCF的更新方式改变。在readme中添加讨饭链接。
|
||||
20210804-1535.38
|
||||
try fix "&"/"&" in filename. try show an img too height. change upload chunk size when upload speed>10M/s. fix forceHttps when custom domain in Glitch. fix ionicons svg lost.try use file id when rename. background (or other) based on width/height not only width. fix some bugs. Pre-Add platform Vercel, just wait bugs fixed.
|
||||
尝试修复文件名含 "&"/"&"。尝试在一屏内显示过长的图片。上传时分割的块大小随着上传速度改变。修复Glitch中使用自定义域名时forceHttps问题。修复ionicons图标失踪。尝试在重命名时使用file id来操作。背景(或其它)基于长宽来看是竖屏还是横屏,不再只看宽度。修复其它bug。预加入Vercel平台,等修复bugs。
|
||||
20210512-1648.37
|
||||
add setting "forceHttps", can force 302 jump to https. fix preview office files. fix manage in safari.fix disktag can be "home". fix some bugs.
|
||||
新增一个设置,可以强制跳转https。修复office文档预览。修复safari上点不了管理。盘的标签可以是home了,随便命名了。修复一些其它问题。
|
||||
20210331-1530.36
|
||||
admin can only use classic theme after admin login, and guest can not change theme now. fix: Sharelink can not work in php8. show disk space. limit 5 files in uploading. do with activityLimitReached. fix some bugs.
|
||||
暂时解决昨天阿里云盘最新防盗链。管理登录后只能用classic主题,游客不能再切换主题了。修复Sharelink在php8下不能正常工作。显示盘空间。同时上传文件数限制5个。对activityLimitReached稍微处理。修复一些bug。
|
||||
20210313-1352.35
|
||||
use driveId, after update, <font color="red">Aliyundrive and Googledrive please click the Change link after Driver type</font>. try fix: php8 will run error 500. change layout in settup. fix: uploading non-englist file name. try fix: sha1 a big file.
|
||||
换用driveId,更新后<font color="red">Aliyundrive与Googledrive请点一下那个切换链接</font>。尝试修复php8的500 ERROR。改变设置页面的布局。修复上传中文名文件时最终文件以url代码命名。阿里云盘上传时可以sha1大文件了。
|
||||
20210311-2004.34
|
||||
try fix: can not login, sha1.js not loaded(changed a cdn), show error log.
|
||||
尝试修复登录不了的情况:可能sha1.js没有载入(换了源),在登录页显示出错信息。
|
||||
20210309-1718.33
|
||||
Googledrive can operate now, but the uploading can not done on explorer without token. Onedrive try deal with activeLimit. Can change admin password now. Admin password will sha1 when submitting. Fix some bugs.
|
||||
Googledrive可以管理操作了,但因为没法在浏览器端不带token上传,所以上传操作作罢。Onedrive尝试处理activeLimit。可以修改admin密码了。登录等提交admin密码时,会sha1加密再提交。修复一些bug。
|
||||
20210301-1745.32
|
||||
Onedrive client secret extend. export&import config. adding Googledrive. add reffer: only listing domains can refer. add diskDescription: tips of disk. Heroku change function_name to HerokuappId. try fix domainforproxy. fix create in Aliyundrive. fix other bugs.
|
||||
Onedrive 的client延期。可以导入导出配置了。初步添加Googledrive。添加reffer:只有指定域名能引用。添加diskDescription:可以对盘备注了。Heroku中将function_name改为使用HerokuappId。尝试修复domainforproxy在个人帐号时的问题。修复阿里云盘不能新建与加密。修复其它bug。
|
||||
20210118-1600.31
|
||||
can change Ondrive to Sharepoint, can copy a disk. fix a bug that 500 error in setup.
|
||||
Onedrive跟Sharepoint可以切换了,可以复制一个盘。修复bug。
|
||||
20210115-1111.30
|
||||
<font color=red>v3, after update, please AddDisk again, please set passfile again.</font> themes of php deleted, or you can use branch v2_last.
|
||||
<font color=red>v3,一键升级后请重新添加盘,passfile失效,重新设置。</font>php主题删掉了,要么就用v2_last分支。
|
||||
20201229.29
|
||||
Modify tags, change sequence of disk.
|
||||
可以修改标签,移动标签顺序。
|
||||
20201215-1400.28
|
||||
fix: hackers can upload files to ANY folder (or create a new folder) in your Onedrive. add language zh-tw. now, on heroku, xhr can post. fix: 2 or more space in file name cause bugs.
|
||||
修复:构造代码后可以上传文件到你Onedrive的任意目录(甚至创建新目录)。新增zh-tw语言。xhr的post在heroku会接收了,改回post。修复:文件名有多个空格相连时造成bug。
|
||||
20201106-1730.27
|
||||
Add theme. A code used in CloudFlare Workers. Admin not need password in folder. Add caddy2 rewrite rule. Add new platform Glitch. <font color=red>web hosting and VPS user should backup your config.php, after update, copy it to .data foloder.</font>
|
||||
添加主题。添加一段用于CF workers的代码。加密目录管理员不需要密码了。添加caddy2伪静态。新增Glitch平台。<font color=red>虚拟主机与VPS用户请备份config.php,升级后,手动将它覆盖到.data目录。</font>
|
||||
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
|
||||
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>。
|
||||
20200723-1430.21
|
||||
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。
|
||||
20200713-1800.20
|
||||
add platform: Huawei cloud Function Graph. now you can use "?json" to get a json of folder or file. fix some bug.
|
||||
新增白嫖平台:华为云函数工作流FG。可以用"?json"来获得目录或文件的json。修复bug。
|
||||
20200607-1856.19
|
||||
add platform: Aliyun Function Compute. add setting: replace sharepoint.com to a proxy server name. add setting: disableShowThumb,customTheme. add function: php hosting website can update by a click
|
||||
现在可以安装到阿里函数计算FC了。php空间可以一键更新了。可以设置某个盘替换sharpoint.com域名为你的反代域名。新增disableShowThumb,customTheme。
|
||||
20200503-1848.18
|
||||
Rebuild theme. Add custom Css & custom Script, add FunctionalityFile: head.omf & foot.omf.
|
||||
重建主题文件结构。增加自定义css与自定义script。增加2个功能文件:head.omf、foot.omf。
|
||||
20200402-1830.17
|
||||
Oneclick update can select which branch to update. Now use the accept language instead of the language config.
|
||||
一键更新可以选择哪个分支了。现在开始使用浏览器语言,抛弃language设置。
|
||||
|
||||
20200326-0001.16
|
||||
You can add sharepoint site drive as a disk, <font color=red>you must reinstall after update</font>.
|
||||
可以将sharepoint网站添加成一个盘,<font color=red>由于结构改变,升级后只能重装</font>。
|
||||
|
|
|
@ -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>
|
|
@ -1,3 +1,3 @@
|
|||
OneManagerPath=`cd $(dirname $0);pwd -P`
|
||||
cd ${OneManagerPath}
|
||||
chmod 666 config.php
|
||||
chmod 666 .data/config.php
|
||||
|
|
Loading…
Reference in New Issue