Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwsswl
OneManager-php
提交
89546eb7
O
OneManager-php
项目概览
lwsswl
/
OneManager-php
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
OneManager-php
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
89546eb7
编写于
3月 18, 2020
作者:
Q
qkqpttgf
提交者:
GitHub
3月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
try fix retry 3 time when net err
上级
634be287
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
101 addition
and
88 deletion
+101
-88
function/common.php
function/common.php
+101
-88
未找到文件。
function/common.php
浏览文件 @
89546eb7
...
...
@@ -255,7 +255,7 @@ function curl_request($url, $data = false, $headers = [])
$response
[
'body'
]
=
curl_exec
(
$ch
);
$response
[
'stat'
]
=
curl_getinfo
(
$ch
,
CURLINFO_HTTP_CODE
);
curl_close
(
$ch
);
if
(
$response
[
'stat'
]
==
0
)
return
curl_request
(
$url
,
$data
,
$headers
);
//
if ($response['stat']==0) return curl_request($url, $data, $headers);
return
$response
;
}
...
...
@@ -515,11 +515,11 @@ function main($path)
$disktags
=
explode
(
"|"
,
getConfig
(
'disktag'
));
// echo 'count$disk:'.count($disktags);
if
(
count
(
$disktags
)
>
1
)
{
if
(
$path
==
'/'
||
$path
==
''
)
return
output
(
''
,
302
,
[
'Location'
=>
path_format
(
$_SERVER
[
'
PHP_SELF
'
]
.
'/'
.
$disktags
[
0
])
]);
if
(
$path
==
'/'
||
$path
==
''
)
return
output
(
''
,
302
,
[
'Location'
=>
path_format
(
$_SERVER
[
'
base_path
'
]
.
'/'
.
$disktags
[
0
])
]);
$_SERVER
[
'disktag'
]
=
$path
;
$pos
=
strpos
(
$path
,
'/'
);
if
(
$pos
>
1
)
$_SERVER
[
'disktag'
]
=
substr
(
$path
,
0
,
$pos
);
if
(
!
in_array
(
$_SERVER
[
'disktag'
],
$disktags
))
return
message
(
'Please visit from <a href="'
.
$_SERVER
[
'base_path'
]
.
'">Home Page</a>.'
,
'Error'
,
404
);
if
(
!
in_array
(
$_SERVER
[
'disktag'
],
$disktags
))
return
message
(
'
<meta http-equiv="refresh" content="2;URL='
.
$_SERVER
[
'base_path'
]
.
'">
Please visit from <a href="'
.
$_SERVER
[
'base_path'
]
.
'">Home Page</a>.'
,
'Error'
,
404
);
$path
=
substr
(
$path
,
strlen
(
'/'
.
$_SERVER
[
'disktag'
]));
if
(
$_SERVER
[
'disktag'
]
!=
''
)
$_SERVER
[
'base_disk_path'
]
=
path_format
(
$_SERVER
[
'base_disk_path'
]
.
'/'
.
$_SERVER
[
'disktag'
]
.
'/'
);
}
else
$_SERVER
[
'disktag'
]
=
$disktags
[
0
];
...
...
@@ -574,90 +574,90 @@ function main($path)
if
(
!
$refresh_token
)
{
return
render_list
();
}
else
{
if
(
!
(
$_SERVER
[
'access_token'
]
=
getcache
(
'access_token'
)))
{
$response
=
curl_request
(
$_SERVER
[
'oauth_url'
]
.
'token'
,
'client_id='
.
$_SERVER
[
'client_id'
]
.
'&client_secret='
.
$_SERVER
[
'client_secret'
]
.
'&grant_type=refresh_token&requested_token_use=on_behalf_of&refresh_token='
.
$refresh_token
);
if
(
$response
[
'stat'
]
==
200
)
$ret
=
json_decode
(
$response
[
'body'
],
true
);
if
(
!
isset
(
$ret
[
'access_token'
]))
{
error_log
(
$_SERVER
[
'oauth_url'
]
.
'token'
.
'?client_id='
.
$_SERVER
[
'client_id'
]
.
'&client_secret='
.
$_SERVER
[
'client_secret'
]
.
'&grant_type=refresh_token&requested_token_use=on_behalf_of&refresh_token='
.
$refresh_token
);
error_log
(
'failed to get access_token. response'
.
json_encode
(
$ret
));
throw
new
Exception
(
$response
[
'stat'
]
.
', failed to get access_token.'
.
$response
[
'body'
]);
if
(
!
(
$_SERVER
[
'access_token'
]
=
getcache
(
'access_token'
)))
{
$response
=
curl_request
(
$_SERVER
[
'oauth_url'
]
.
'token'
,
'client_id='
.
$_SERVER
[
'client_id'
]
.
'&client_secret='
.
$_SERVER
[
'client_secret'
]
.
'&grant_type=refresh_token&requested_token_use=on_behalf_of&refresh_token='
.
$refresh_token
);
if
(
$response
[
'stat'
]
==
200
)
$ret
=
json_decode
(
$response
[
'body'
],
true
);
if
(
!
isset
(
$ret
[
'access_token'
]))
{
error_log
(
$_SERVER
[
'oauth_url'
]
.
'token'
.
'?client_id='
.
$_SERVER
[
'client_id'
]
.
'&client_secret='
.
$_SERVER
[
'client_secret'
]
.
'&grant_type=refresh_token&requested_token_use=on_behalf_of&refresh_token='
.
$refresh_token
);
error_log
(
'failed to get access_token. response'
.
json_encode
(
$ret
));
throw
new
Exception
(
$response
[
'stat'
]
.
', failed to get access_token.'
.
$response
[
'body'
]);
}
error_log
(
'Get access token:'
.
json_encode
(
$ret
,
JSON_PRETTY_PRINT
));
$_SERVER
[
'access_token'
]
=
$ret
[
'access_token'
];
savecache
(
'access_token'
,
$_SERVER
[
'access_token'
],
$ret
[
'expires_in'
]
-
300
);
if
(
time
()
>
getConfig
(
'token_expires'
))
setConfig
([
'refresh_token'
=>
$ret
[
'refresh_token'
],
'token_expires'
=>
time
()
+
7
*
24
*
60
*
60
]);
}
error_log
(
'Get access token:'
.
json_encode
(
$ret
,
JSON_PRETTY_PRINT
));
$_SERVER
[
'access_token'
]
=
$ret
[
'access_token'
];
savecache
(
'access_token'
,
$_SERVER
[
'access_token'
],
$ret
[
'expires_in'
]
-
300
);
if
(
time
()
>
getConfig
(
'token_expires'
))
setConfig
([
'refresh_token'
=>
$ret
[
'refresh_token'
],
'token_expires'
=>
time
()
+
7
*
24
*
60
*
60
]);
}
$_SERVER
[
'retry'
]
=
0
;
if
(
$_SERVER
[
'ajax'
])
{
if
(
$_GET
[
'action'
]
==
'del_upload_cache'
&&
substr
(
$_GET
[
'filename'
],
-
4
)
==
'.tmp'
)
{
// del '.tmp' without login. 无需登录即可删除.tmp后缀文件
error_log
(
'del.tmp:GET,'
.
json_encode
(
$_GET
,
JSON_PRETTY_PRINT
));
$tmp
=
MSAPI
(
'DELETE'
,
path_format
(
path_format
(
$_SERVER
[
'list_path'
]
.
path_format
(
$path
))
.
'/'
.
spurlencode
(
$_GET
[
'filename'
])
),
''
,
$_SERVER
[
'access_token'
]);
$path1
=
path_format
(
$_SERVER
[
'list_path'
]
.
path_format
(
$path
));
savecache
(
'path_'
.
$path1
,
json_decode
(
'{}'
,
true
),
1
);
return
output
(
$tmp
[
'body'
],
$tmp
[
'stat'
]);
$_SERVER
[
'retry'
]
=
0
;
if
(
$_SERVER
[
'ajax'
])
{
if
(
$_GET
[
'action'
]
==
'del_upload_cache'
&&
substr
(
$_GET
[
'filename'
],
-
4
)
==
'.tmp'
)
{
// del '.tmp' without login. 无需登录即可删除.tmp后缀文件
error_log
(
'del.tmp:GET,'
.
json_encode
(
$_GET
,
JSON_PRETTY_PRINT
));
$tmp
=
MSAPI
(
'DELETE'
,
path_format
(
path_format
(
$_SERVER
[
'list_path'
]
.
path_format
(
$path
))
.
'/'
.
spurlencode
(
$_GET
[
'filename'
])
),
''
,
$_SERVER
[
'access_token'
]);
$path1
=
path_format
(
$_SERVER
[
'list_path'
]
.
path_format
(
$path
));
savecache
(
'path_'
.
$path1
,
json_decode
(
'{}'
,
true
),
1
);
return
output
(
$tmp
[
'body'
],
$tmp
[
'stat'
]);
}
if
(
$_GET
[
'action'
]
==
'uploaded_rename'
)
{
// rename .scfupload file without login.
// 无需登录即可重命名.scfupload后缀文件,filemd5为用户提交,可被构造,问题不大,以后处理
$oldname
=
spurlencode
(
$_GET
[
'filename'
]);
$pos
=
strrpos
(
$oldname
,
'.'
);
if
(
$pos
>
0
)
$ext
=
strtolower
(
substr
(
$oldname
,
$pos
));
$oldname
=
path_format
(
path_format
(
$_SERVER
[
'list_path'
]
.
path_format
(
$path
))
.
'/'
.
$oldname
.
'.scfupload'
);
$data
=
'{"name":"'
.
$_GET
[
'filemd5'
]
.
$ext
.
'"}'
;
//echo $oldname .'<br>'. $data;
$tmp
=
MSAPI
(
'PATCH'
,
$oldname
,
$data
,
$_SERVER
[
'access_token'
]);
if
(
$tmp
[
'stat'
]
==
409
)
MSAPI
(
'DELETE'
,
$oldname
,
''
,
$_SERVER
[
'access_token'
])[
'body'
];
$path1
=
path_format
(
$_SERVER
[
'list_path'
]
.
path_format
(
$path
));
savecache
(
'path_'
.
$path1
,
json_decode
(
'{}'
,
true
),
1
);
return
output
(
$tmp
[
'body'
],
$tmp
[
'stat'
]);
}
if
(
$_GET
[
'action'
]
==
'upbigfile'
)
return
bigfileupload
(
$path
);
}
if
(
$_GET
[
'action'
]
==
'uploaded_rename'
)
{
// rename .scfupload file without login.
// 无需登录即可重命名.scfupload后缀文件,filemd5为用户提交,可被构造,问题不大,以后处理
$oldname
=
spurlencode
(
$_GET
[
'filename'
]);
$pos
=
strrpos
(
$oldname
,
'.'
);
if
(
$pos
>
0
)
$ext
=
strtolower
(
substr
(
$oldname
,
$pos
));
$oldname
=
path_format
(
path_format
(
$_SERVER
[
'list_path'
]
.
path_format
(
$path
))
.
'/'
.
$oldname
.
'.scfupload'
);
$data
=
'{"name":"'
.
$_GET
[
'filemd5'
]
.
$ext
.
'"}'
;
//echo $oldname .'<br>'. $data;
$tmp
=
MSAPI
(
'PATCH'
,
$oldname
,
$data
,
$_SERVER
[
'access_token'
]);
if
(
$tmp
[
'stat'
]
==
409
)
MSAPI
(
'DELETE'
,
$oldname
,
''
,
$_SERVER
[
'access_token'
])[
'body'
];
$path1
=
path_format
(
$_SERVER
[
'list_path'
]
.
path_format
(
$path
));
savecache
(
'path_'
.
$path1
,
json_decode
(
'{}'
,
true
),
1
);
return
output
(
$tmp
[
'body'
],
$tmp
[
'stat'
]);
if
(
$_SERVER
[
'admin'
])
{
$tmp
=
adminoperate
(
$path
);
if
(
$tmp
[
'statusCode'
]
>
0
)
{
$path1
=
path_format
(
$_SERVER
[
'list_path'
]
.
path_format
(
$path
));
savecache
(
'path_'
.
$path1
,
json_decode
(
'{}'
,
true
),
1
);
return
$tmp
;
}
}
else
{
if
(
$_SERVER
[
'ajax'
])
return
output
(
getconstStr
(
'RefreshtoLogin'
),
401
);
}
if
(
$_GET
[
'action'
]
==
'upbigfile'
)
return
bigfileupload
(
$path
);
}
if
(
$_SERVER
[
'admin'
])
{
$tmp
=
adminoperate
(
$path
);
if
(
$tmp
[
'statusCode'
]
>
0
)
{
$path1
=
path_format
(
$_SERVER
[
'list_path'
]
.
path_format
(
$path
));
savecache
(
'path_'
.
$path1
,
json_decode
(
'{}'
,
true
),
1
);
return
$tmp
;
$_SERVER
[
'ishidden'
]
=
passhidden
(
$path
);
if
(
isset
(
$_GET
[
'thumbnails'
]))
{
if
(
$_SERVER
[
'ishidden'
]
<
4
)
{
if
(
in_array
(
strtolower
(
substr
(
$path
,
strrpos
(
$path
,
'.'
)
+
1
)),
$exts
[
'img'
]))
{
return
get_thumbnails_url
(
$path
);
}
else
return
output
(
json_encode
(
$exts
[
'img'
]),
400
);
}
else
return
output
(
''
,
401
);
}
}
else
{
if
(
$_SERVER
[
'ajax'
])
return
output
(
getconstStr
(
'RefreshtoLogin'
),
401
);
}
$_SERVER
[
'ishidden'
]
=
passhidden
(
$path
);
if
(
isset
(
$_GET
[
'thumbnails'
]))
{
if
(
$_SERVER
[
'ishidden'
]
<
4
)
{
if
(
in_array
(
strtolower
(
substr
(
$path
,
strrpos
(
$path
,
'.'
)
+
1
)),
$exts
[
'img'
]))
{
return
get_thumbnails_url
(
$path
);
}
else
return
output
(
json_encode
(
$exts
[
'img'
]),
400
);
}
else
return
output
(
''
,
401
);
}
$files
=
list_files
(
$path
);
//echo json_encode(array_keys($files['children']), JSON_PRETTY_PRINT);
if
(
isset
(
$_GET
[
'random'
])
&&
$_GET
[
'random'
]
!==
''
)
{
if
(
$_SERVER
[
'ishidden'
]
<
4
)
{
$tmp
=
[];
foreach
(
array_keys
(
$files
[
'children'
])
as
$filename
)
{
if
(
strtolower
(
splitlast
(
$filename
,
'.'
)[
1
])
==
strtolower
(
$_GET
[
'random'
]))
$tmp
[
$filename
]
=
$files
[
'children'
][
$filename
][
'@microsoft.graph.downloadUrl'
];
}
$tmp
=
array_values
(
$tmp
);
if
(
count
(
$tmp
)
>
0
)
{
if
(
isset
(
$_GET
[
'url'
]))
return
output
(
$tmp
[
rand
(
0
,
count
(
$tmp
)
-
1
)],
200
);
return
output
(
''
,
302
,
[
'Location'
=>
$tmp
[
rand
(
0
,
count
(
$tmp
)
-
1
)]
]);
}
else
return
output
(
''
,
404
);
}
else
return
output
(
''
,
401
);
}
if
(
isset
(
$files
[
'file'
])
&&
!
isset
(
$_GET
[
'preview'
]))
{
// is file && not preview mode
if
(
$_SERVER
[
'ishidden'
]
<
4
||
(
!!
getConfig
(
'downloadencrypt'
)
&&
$files
[
'name'
]
!=
getConfig
(
'passfile'
))
)
return
output
(
''
,
302
,
[
'Location'
=>
$files
[
'@microsoft.graph.downloadUrl'
]
]);
}
if
(
isset
(
$files
[
'folder'
])
||
isset
(
$files
[
'file'
])
)
{
return
render_list
(
$path
,
$files
);
}
else
{
return
message
(
'<a href="'
.
$_SERVER
[
'base_path'
]
.
'">'
.
getconstStr
(
'Back'
)
.
getconstStr
(
'Home'
)
.
'</a><div style="margin:8px;">'
.
$files
[
'error'
][
'message'
]
.
'</div><a href="javascript:history.back(-1)">'
.
getconstStr
(
'Back'
)
.
'</a>'
,
$files
[
'error'
][
'code'
],
$files
[
'error'
][
'stat'
]);
}
$files
=
list_files
(
$path
);
//echo json_encode(array_keys($files['children']), JSON_PRETTY_PRINT);
if
(
isset
(
$_GET
[
'random'
])
&&
$_GET
[
'random'
]
!==
''
)
{
if
(
$_SERVER
[
'ishidden'
]
<
4
)
{
$tmp
=
[];
foreach
(
array_keys
(
$files
[
'children'
])
as
$filename
)
{
if
(
strtolower
(
splitlast
(
$filename
,
'.'
)[
1
])
==
strtolower
(
$_GET
[
'random'
]))
$tmp
[
$filename
]
=
$files
[
'children'
][
$filename
][
'@microsoft.graph.downloadUrl'
];
}
$tmp
=
array_values
(
$tmp
);
if
(
count
(
$tmp
)
>
0
)
{
if
(
isset
(
$_GET
[
'url'
]))
return
output
(
$tmp
[
rand
(
0
,
count
(
$tmp
)
-
1
)],
200
);
return
output
(
''
,
302
,
[
'Location'
=>
$tmp
[
rand
(
0
,
count
(
$tmp
)
-
1
)]
]);
}
else
return
output
(
''
,
404
);
}
else
return
output
(
''
,
401
);
}
if
(
isset
(
$files
[
'file'
])
&&
!
isset
(
$_GET
[
'preview'
]))
{
// is file && not preview mode
if
(
$_SERVER
[
'ishidden'
]
<
4
||
(
!!
getConfig
(
'downloadencrypt'
)
&&
$files
[
'name'
]
!=
getConfig
(
'passfile'
))
)
return
output
(
''
,
302
,
[
'Location'
=>
$files
[
'@microsoft.graph.downloadUrl'
]
]);
}
if
(
isset
(
$files
[
'folder'
])
||
isset
(
$files
[
'file'
])
)
{
return
render_list
(
$path
,
$files
);
}
else
{
return
message
(
'<a href="'
.
$_SERVER
[
'base_path'
]
.
'">'
.
getconstStr
(
'Back'
)
.
getconstStr
(
'Home'
)
.
'</a><div style="margin:8px;">'
.
$files
[
'error'
][
'message'
]
.
'</div><a href="javascript:history.back(-1)">'
.
getconstStr
(
'Back'
)
.
'</a>'
,
$files
[
'error'
][
'code'
],
$files
[
'error'
][
'stat'
]);
}
}
}
...
...
@@ -672,7 +672,8 @@ function list_files($path)
}
else
{
$files
=
fetch_files
(
$path
);
}
if
(
isset
(
$files
[
'folder'
])
||
isset
(
$files
[
'file'
])
||
isset
(
$files
[
'error'
])
)
{
return
$files
;
/*if ( isset($files['folder']) || isset($files['file']) || isset($files['error']) ) {
return $files;
} else {
error_log( json_encode($files) . ' Network Error<br>' );
...
...
@@ -680,7 +681,7 @@ function list_files($path)
if ($_SERVER['retry'] < 3) {
return list_files($path);
} else return $files;
}
}
*/
}
function
adminform
(
$name
=
''
,
$pass
=
''
,
$path
=
''
)
...
...
@@ -950,7 +951,10 @@ function fetch_files($path = '/')
if
(
substr
(
$url
,
-
1
)
==
'/'
)
$url
=
substr
(
$url
,
0
,
-
1
);
}
$url
.
=
'?expand=children(select=name,size,file,folder,parentReference,lastModifiedDateTime,@microsoft.graph.downloadUrl)'
;
$arr
=
curl_request
(
$url
,
false
,
[
'Authorization'
=>
'Bearer '
.
$_SERVER
[
'access_token'
]]);
while
(
$retry
<
3
&&!
$arr
[
'stat'
])
{
$arr
=
curl_request
(
$url
,
false
,
[
'Authorization'
=>
'Bearer '
.
$_SERVER
[
'access_token'
]]);
$retry
++
;
}
if
(
$arr
[
'stat'
]
<
500
)
{
$files
=
json_decode
(
$arr
[
'body'
],
true
);
// echo $path . '<br><pre>' . json_encode($files, JSON_PRETTY_PRINT) . '</pre>';
...
...
@@ -972,8 +976,17 @@ function fetch_files($path = '/')
$files
[
'error'
][
'stat'
]
=
$arr
[
'stat'
];
}
}
else
{
error_log
(
$arr
[
'body'
]);
$files
=
json_decode
(
'{"unknownError":{ "stat":'
.
$arr
[
'stat'
]
.
',"message":"'
.
$arr
[
'body'
]
.
'"}}'
,
true
);
//error_log($arr['body']);
$files
=
json_decode
(
$arr
[
'body'
],
true
);
if
(
isset
(
$files
[
'error'
]))
{
$files
[
'error'
][
'stat'
]
=
$arr
[
'stat'
];
}
else
{
$files
[
'error'
][
'stat'
]
=
503
;
$files
[
'error'
][
'code'
]
=
'unknownError'
;
$files
[
'error'
][
'message'
]
=
'unknownError'
;
}
//$files = json_decode( '{"unknownError":{ "stat":'.$arr['stat'].',"message":"'.$arr['body'].'"}}', true);
//error_log(json_encode($files, JSON_PRETTY_PRINT));
}
}
...
...
@@ -1016,9 +1029,9 @@ function fetch_files_children($files, $path, $page)
if
(
$path
!==
'/'
)
{
$url
.
=
':'
.
$path
;
if
(
substr
(
$url
,
-
1
)
==
'/'
)
$url
=
substr
(
$url
,
0
,
-
1
);
$url
.
=
':/children?$select=name,size,file,folder,parentReference,lastModifiedDateTime'
;
$url
.
=
':/children?$select=name,size,file,folder,parentReference,lastModifiedDateTime
,@microsoft.graph.downloadUrl
'
;
}
else
{
$url
.
=
'/children?$select=name,size,file,folder,parentReference,lastModifiedDateTime'
;
$url
.
=
'/children?$select=name,size,file,folder,parentReference,lastModifiedDateTime
,@microsoft.graph.downloadUrl
'
;
}
$children
=
json_decode
(
curl_request
(
$url
,
false
,
[
'Authorization'
=>
'Bearer '
.
$_SERVER
[
'access_token'
]])[
'body'
],
true
);
// echo $url . '<br><pre>' . json_encode($children, JSON_PRETTY_PRINT) . '</pre>';
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录