6 Commits
Author SHA1 Message Date
qkqpttgfandGitHub 432fdc5f46 fix: upload file to any folder 2020-12-15 14:45:19 +08:00
root 7c09b0f33c fix: glitch xhr can post 2020-12-15 13:06:15 +08:00
root b0f10e1434 now, heroku xhr can post 2020-12-15 12:52:03 +08:00
qkqpttgfandGitHub 7a4398a55b Merge pull request #171 from 186526/patch-11
renexmoe update
2020-12-15 12:41:56 +08:00
186526andGitHub 9ed1b58c8d renexmoe update 2020-12-13 16:58:18 +08:00
qkqpttgfandGitHub 4add1167db try fix: suddenly can not save config in glitch 2020-12-08 14:53:25 +08:00
6 changed files with 469 additions and 52 deletions
+45 -31
View File
@@ -1120,57 +1120,67 @@ function adminoperate($path)
{
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if (substr($path1,-1)=='/') $path1=substr($path1,0,-1);
$tmpget = $_GET;
$tmppost = $_POST;
$tmparr['statusCode'] = 0;
if (isset($_GET['rename_newname'])&&$_GET['rename_newname']!=$_GET['rename_oldname'] && $_GET['rename_newname']!='') {
if ( (isset($tmpget['rename_newname'])&&$tmpget['rename_newname']!=$tmpget['rename_oldname'] && $tmpget['rename_newname']!='') || (isset($tmppost['rename_newname'])&&$tmppost['rename_newname']!=$tmppost['rename_oldname'] && $tmppost['rename_newname']!='') ) {
if (isset($tmppost['rename_newname'])) $VAR = 'tmppost';
else $VAR = 'tmpget';
// rename 重命名
$oldname = spurlencode($_GET['rename_oldname']);
$oldname = spurlencode(${$VAR}['rename_oldname']);
$oldname = path_format($path1 . '/' . $oldname);
$data = '{"name":"' . $_GET['rename_newname'] . '"}';
$data = '{"name":"' . ${$VAR}['rename_newname'] . '"}';
//echo $oldname;
$result = MSAPI('PATCH',$oldname,$data,$_SERVER['access_token']);
//savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
return output($result['body'], $result['stat']);
}
if (isset($_GET['delete_name'])) {
if (isset($tmpget['delete_name']) || isset($tmppost['delete_name'])) {
if (isset($tmppost['delete_name'])) $VAR = 'tmppost';
else $VAR = 'tmpget';
// delete 删除
$filename = spurlencode($_GET['delete_name']);
$filename = spurlencode(${$VAR}['delete_name']);
$filename = path_format($path1 . '/' . $filename);
//echo $filename;
$result = MSAPI('DELETE', $filename, '', $_SERVER['access_token']);
//savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
return output($result['body'], $result['stat']);
}
if (isset($_GET['operate_action'])&&$_GET['operate_action']==getconstStr('Encrypt')) {
if ( (isset($tmpget['operate_action'])&&$tmpget['operate_action']==getconstStr('Encrypt')) || (isset($tmppost['operate_action'])&&$tmppost['operate_action']==getconstStr('Encrypt')) ) {
if (isset($tmppost['operate_action'])) $VAR = 'tmppost';
else $VAR = 'tmpget';
// encrypt 加密
if (getConfig('passfile')=='') return message(getconstStr('SetpassfileBfEncrypt'),'',403);
if ($_GET['encrypt_folder']=='/') $_GET['encrypt_folder']=='';
$foldername = spurlencode($_GET['encrypt_folder']);
if (${$VAR}['encrypt_folder']=='/') ${$VAR}['encrypt_folder']=='';
$foldername = spurlencode(${$VAR}['encrypt_folder']);
$filename = path_format($path1 . '/' . $foldername . '/' . urlencode(getConfig('passfile')));
//echo $foldername;
$result = MSAPI('PUT', $filename, $_GET['encrypt_newpass'], $_SERVER['access_token']);
$result = MSAPI('PUT', $filename, ${$VAR}['encrypt_newpass'], $_SERVER['access_token']);
$path1 = path_format($path1 . '/' . $foldername );
if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1);
savecache('path_' . $path1 . '/?password', '', $_SERVER['disktag'], 1);
return output($result['body'], $result['stat']);
}
if (isset($_GET['move_folder'])) {
if (isset($tmpget['move_folder']) || isset($tmppost['move_folder'])) {
if (isset($tmppost['move_folder'])) $VAR = 'tmppost';
else $VAR = 'tmpget';
// move 移动
$moveable = 1;
if ($path == '/' && $_GET['move_folder'] == '/../') $moveable=0;
if ($_GET['move_folder'] == $_GET['move_name']) $moveable=0;
if ($path == '/' && ${$VAR}['move_folder'] == '/../') $moveable=0;
if (${$VAR}['move_folder'] == ${$VAR}['move_name']) $moveable=0;
if ($moveable) {
$filename = spurlencode($_GET['move_name']);
$filename = spurlencode(${$VAR}['move_name']);
$filename = path_format($path1 . '/' . $filename);
if ($_GET['move_folder'] == '/../') {
if (${$VAR}['move_folder'] == '/../') {
$foldername = path_format('/' . urldecode($path1) . '/');
$foldername = substr($foldername, 0, -1);
$foldername = splitlast($foldername, '/')[0];
} else $foldername = path_format('/' . urldecode($path1) . '/' . $_GET['move_folder']);
} else $foldername = path_format('/' . urldecode($path1) . '/' . ${$VAR}['move_folder']);
$data = '{"parentReference":{"path": "/drive/root:'.$foldername.'"}}';
$result = MSAPI('PATCH', $filename, $data, $_SERVER['access_token']);
//savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
if ($_GET['move_folder'] == '/../') $path2 = path_format( substr($path1, 0, strrpos($path1, '/')) . '/' );
else $path2 = path_format( $path1 . '/' . $_GET['move_folder'] . '/' );
if (${$VAR}['move_folder'] == '/../') $path2 = path_format( substr($path1, 0, strrpos($path1, '/')) . '/' );
else $path2 = path_format( $path1 . '/' . ${$VAR}['move_folder'] . '/' );
if ($path2!='/'&&substr($path2,-1)=='/') $path2=substr($path2,0,-1);
savecache('path_' . $path2, json_decode('{}',true), $_SERVER['disktag'], 1);
return output($result['body'], $result['stat']);
@@ -1178,11 +1188,13 @@ function adminoperate($path)
return output('{"error":"'.getconstStr('CannotMove').'"}', 403);
}
}
if (isset($_GET['copy_name'])) {
if (isset($tmpget['copy_name']) || isset($tmppost['copy_name'])) {
if (isset($tmppost['copy_name'])) $VAR = 'tmppost';
else $VAR = 'tmpget';
// copy 复制
$filename = spurlencode($_GET['copy_name']);
$filename = spurlencode(${$VAR}['copy_name']);
$filename = path_format($path1 . '/' . $filename);
$namearr = splitlast($_GET['copy_name'], '.');
$namearr = splitlast(${$VAR}['copy_name'], '.');
if ($namearr[0]!='') {
$newname = $namearr[0] . ' (' . getconstStr('Copy') . ')';
if ($namearr[1]!='') $newname .= '.' . $namearr[1];
@@ -1209,14 +1221,14 @@ function adminoperate($path)
}
//echo $result['stat'].$result['body'];
//savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
//if ($_GET['move_folder'] == '/../') $path2 = path_format( substr($path1, 0, strrpos($path1, '/')) . '/' );
//else $path2 = path_format( $path1 . '/' . $_GET['move_folder'] . '/' );
//if ($tmpget['move_folder'] == '/../') $path2 = path_format( substr($path1, 0, strrpos($path1, '/')) . '/' );
//else $path2 = path_format( $path1 . '/' . $tmpget['move_folder'] . '/' );
//savecache('path_' . $path2, json_decode('{}',true), $_SERVER['disktag'], 1);
return output($result['body'], $result['stat']);
}
if (isset($_POST['editfile'])) {
if (isset($tmppost['editfile'])) {
// edit 编辑
$data = $_POST['editfile'];
$data = $tmppost['editfile'];
/*TXT一般不会超过4M,不用二段上传
$filename = $path1 . ':/createUploadSession';
$response=MSAPI('POST',$filename,'{"item": { "@microsoft.graph.conflictBehavior": "replace" }}',$_SERVER['access_token']);
@@ -1227,21 +1239,23 @@ function adminoperate($path)
$resultarry = json_decode($result,true);
if (isset($resultarry['error'])) return message($resultarry['error']['message']. '<hr><a href="javascript:history.back(-1)">'.getconstStr('Back').'</a>','Error',403);
}
if (isset($_GET['create_name'])) {
if (isset($tmpget['create_name']) || isset($tmppost['create_name'])) {
if (isset($tmppost['create_name'])) $VAR = 'tmppost';
else $VAR = 'tmpget';
// create 新建
if ($_GET['create_type']=='file') {
$filename = spurlencode($_GET['create_name']);
if (${$VAR}['create_type']=='file') {
$filename = spurlencode(${$VAR}['create_name']);
$filename = path_format($path1 . '/' . $filename);
$result = MSAPI('PUT', $filename, $_GET['create_text'], $_SERVER['access_token']);
$result = MSAPI('PUT', $filename, ${$VAR}['create_text'], $_SERVER['access_token']);
}
if ($_GET['create_type']=='folder') {
$data = '{ "name": "' . $_GET['create_name'] . '", "folder": { }, "@microsoft.graph.conflictBehavior": "rename" }';
if (${$VAR}['create_type']=='folder') {
$data = '{ "name": "' . ${$VAR}['create_name'] . '", "folder": { }, "@microsoft.graph.conflictBehavior": "rename" }';
$result = MSAPI('children', $path1, $data, $_SERVER['access_token']);
}
//savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
return output($result['body'], $result['stat']);
}
if (isset($_GET['RefreshCache'])) {
if (isset($tmpget['RefreshCache'])) {
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1);
savecache('path_' . $path1 . '/?password', '', $_SERVER['disktag'], 1);
+18
View File
@@ -15,6 +15,24 @@ function getpath()
function getGET()
{
//error_log('POST' . json_encode($_POST));
if (!$_POST) {
if (!!$HTTP_RAW_POST_DATA) {
$tmpdata = $HTTP_RAW_POST_DATA;
//error_log('RAW' . $tmpdata);
} else {
$tmpdata = file_get_contents('php://input');
//error_log('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_log('POSTformPHPINPUT' . json_encode($_POST));
}
}
$p = strpos($_SERVER['REQUEST_URI'],'?');
if ($p>0) {
$getstr = substr($_SERVER['REQUEST_URI'], $p+1);
+26 -16
View File
@@ -18,6 +18,20 @@ function getpath()
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) {
@@ -46,8 +60,12 @@ function getConfig($str, $disktag = '')
{
global $InnerEnv;
global $Base64Env;
//include 'config.php';
$s = file_get_contents('.data/config.php');
$slash = '/';
if (strpos(__DIR__, ':')) $slash = '\\';
$projectPath = splitlast(__DIR__, $slash)[0];
$configPath = $projectPath . $slash . '.data' . $slash . 'config.php';
$s = file_get_contents($configPath);
//$configs = substr($s, 18, -2);
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
if ($configs!='') {
@@ -73,8 +91,11 @@ function setConfig($arr, $disktag = '')
global $InnerEnv;
global $Base64Env;
if ($disktag=='') $disktag = $_SERVER['disktag'];
//include 'config.php';
$s = file_get_contents('.data/config.php');
$slash = '/';
if (strpos(__DIR__, ':')) $slash = '\\';
$projectPath = splitlast(__DIR__, $slash)[0];
$configPath = $projectPath . $slash . '.data' . $slash . 'config.php';
$s = file_get_contents($configPath);
//$configs = substr($s, 18, -2);
$configs = '{' . splitlast(splitfirst($s, '{')[1], '}')[0] . '}';
if ($configs!='') $envs = json_decode($configs, true);
@@ -115,7 +136,7 @@ function setConfig($arr, $disktag = '')
//echo '<pre>'. json_encode($envs, JSON_PRETTY_PRINT).'</pre>';
$prestr = '<?php $configs = \'' . PHP_EOL;
$aftstr = PHP_EOL . '\';';
$response = file_put_contents('.data/config.php', $prestr . json_encode($envs, JSON_PRETTY_PRINT) . $aftstr);
$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' ] );
}
@@ -245,17 +266,6 @@ function ConfigWriteable()
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'] . '/.data/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 isset($response['message']);
+2 -2
View File
@@ -1112,9 +1112,8 @@
function submit_operate(str) {
var num=document.getElementById(str+'_sid').value;
var xhr = new XMLHttpRequest();
xhr.open("GET", '?'+serializeForm(str+'_form'));
xhr.open("POST", '');
xhr.setRequestHeader('x-requested-with', 'XMLHttpRequest');
xhr.send(null);
xhr.onload = function(e){
var html;
if (xhr.status<300) {
@@ -1134,6 +1133,7 @@
document.getElementById(str+'_div').style.display='none';
document.getElementById('mask').style.display='none';
}
xhr.send(serializeForm(str+'_form'));
return false;
}
function addelement(html) {
+373 -1
View File
File diff suppressed because one or more lines are too long
+4 -1
View File
@@ -1,7 +1,10 @@
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>更新说明只显示部分。