Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hexbee
Cloudreve
提交
c28f08c2
C
Cloudreve
项目概览
hexbee
/
Cloudreve
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Cloudreve
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c28f08c2
编写于
2月 10, 2018
作者:
H
HFO4
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
自定远程服务端(未完成)
上级
0e0f7d52
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
1916 addition
and
1700 deletion
+1916
-1700
application/index/controller/Callback.php
application/index/controller/Callback.php
+7
-0
application/index/model/CallbackHandler.php
application/index/model/CallbackHandler.php
+27
-0
application/index/model/FileManage.php
application/index/model/FileManage.php
+36
-0
application/index/model/Remote.php
application/index/model/Remote.php
+59
-0
application/index/model/UploadHandler.php
application/index/model/UploadHandler.php
+32
-0
public/thumb/.gitignore
public/thumb/.gitignore
+2
-1
static/js/qiniu.js
static/js/qiniu.js
+1753
-1699
未找到文件。
application/index/controller/Callback.php
浏览文件 @
c28f08c2
...
...
@@ -81,4 +81,11 @@ class Callback extends Controller{
$handllerObj
->
s3Handler
(
$callbackKey
);
}
public
function
Remote
(){
ob_end_clean
();
header
(
'Content-Type: application/json'
);
$handllerObj
=
new
CallbackHandler
(
file_get_contents
(
"php://input"
));
$handllerObj
->
remoteHandler
(
Request
::
instance
()
->
header
(
'Authorization'
));
}
}
application/index/model/CallbackHandler.php
浏览文件 @
c28f08c2
...
...
@@ -20,6 +20,28 @@ class CallbackHandler extends Model{
$this
->
CallbackData
=
$data
;
}
public
function
remoteHandler
(
$header
){
$jsonData
=
json_decode
(
base64_decode
(
$this
->
CallbackData
),
true
);
$CallbackSqlData
=
Db
::
name
(
'callback'
)
->
where
(
'callback_key'
,
$jsonData
[
'callbackkey'
])
->
find
();
$this
->
policyData
=
Db
::
name
(
'policy'
)
->
where
(
'id'
,
$CallbackSqlData
[
'pid'
])
->
find
();
if
(
!
$this
->
IsRemoteCallback
(
$header
)){
$this
->
setError
(
"Undelegated Request"
);
}
if
(
$this
->
policyData
==
null
){
$this
->
setError
(
"CallbackKey Not Exist."
);
}
if
(
!
FileManage
::
sotrageCheck
(
$CallbackSqlData
[
"uid"
],
$jsonData
[
"fsize"
])){
$this
->
setError
(
"空间容量不足"
,
true
);
}
$picInfo
=
$jsonData
[
"picinfo"
];
$addAction
=
FileManage
::
addFile
(
$jsonData
,
$this
->
policyData
,
$CallbackSqlData
[
"uid"
],
$picInfo
);
if
(
!
$addAction
[
0
]){
$this
->
setError
(
$addAction
[
1
],
true
);
}
FileManage
::
storageCheckOut
(
$CallbackSqlData
[
"uid"
],
$jsonData
[
"fsize"
]);
$this
->
setSuccess
(
$jsonData
[
'fname'
]);
}
public
function
qiniuHandler
(
$header
){
$jsonData
=
json_decode
(
$this
->
CallbackData
,
true
);
$CallbackSqlData
=
Db
::
name
(
'callback'
)
->
where
(
'callback_key'
,
$jsonData
[
'callbackkey'
])
->
find
();
...
...
@@ -172,6 +194,11 @@ class CallbackHandler extends Model{
}
}
private
function
IsRemoteCallback
(
$header
){
$signKey
=
hash_hmac
(
"sha256"
,
$this
->
CallbackData
,
$this
->
policyData
[
"sk"
]);
return
(
$signKey
==
$header
);
}
public
function
IsOssCallback
(
$auth
,
$pubKey
){
if
(
empty
(
$auth
)
||
empty
(
$pubKey
)){
header
(
"http/1.1 403 Forbidden"
);
...
...
application/index/model/FileManage.php
浏览文件 @
c28f08c2
...
...
@@ -338,6 +338,10 @@ class FileManage extends Model{
$Redirect
=
$this
->
s3Preview
();
return
$Redirect
;
break
;
case
'remote'
:
$Redirect
=
$this
->
remotePreview
();
return
$Redirect
;
break
;
default
:
# code...
break
;
...
...
@@ -384,6 +388,9 @@ class FileManage extends Model{
case
's3'
:
return
$DownloadHandler
=
$this
->
s3Download
();
break
;
case
'remote'
:
return
$DownloadHandler
=
$this
->
remoteDownload
();
break
;
default
:
# code...
break
;
...
...
@@ -473,6 +480,8 @@ class FileManage extends Model{
self
::
upyunDelete
(
$value
,
$uniquePolicy
[
"upyunPolicyData"
][
$key
][
0
]);
}
else
if
(
in_array
(
$key
,
$uniquePolicy
[
"s3List"
])){
self
::
s3Delete
(
$value
,
$uniquePolicy
[
"s3PolicyData"
][
$key
][
0
]);
}
else
if
(
in_array
(
$key
,
$uniquePolicy
[
"remoteList"
])){
self
::
remoteDelete
(
$value
,
$uniquePolicy
[
"remotePolicyData"
][
$key
][
0
]);
}
}
return
[
"result"
=>
[
"success"
=>
true
,
"error"
=>
null
]];
...
...
@@ -580,6 +589,12 @@ class FileManage extends Model{
self
::
deleteFileRecord
(
array_column
(
$fileList
,
'id'
),
array_sum
(
array_column
(
$fileList
,
'size'
)),
$fileList
[
0
][
"upload_user"
]);
}
static
function
remoteDelete
(
$fileList
,
$policyData
){
$remoteObj
=
new
Remote
(
$policyData
);
$remoteObj
->
remove
(
array_column
(
$fileList
,
'pre_name'
));
self
::
deleteFileRecord
(
array_column
(
$fileList
,
'id'
),
array_sum
(
array_column
(
$fileList
,
'size'
)),
$fileList
[
0
][
"upload_user"
]);
}
static
function
deleteFileRecord
(
$id
,
$size
,
$uid
){
Db
::
name
(
'files'
)
->
where
([
'id'
=>
[
"in"
,
$id
],
...
...
@@ -673,6 +688,11 @@ class FileManage extends Model{
return
[
1
,
\
S3\S3
::
aws_s3_link
(
$this
->
policyData
[
"ak"
],
$this
->
policyData
[
"sk"
],
$this
->
policyData
[
"bucketname"
],
"/"
.
$this
->
fileData
[
"pre_name"
],
3600
,
$this
->
policyData
[
"op_name"
])];
}
public
function
remotePreview
(){
$remote
=
new
Remote
(
$this
->
policyData
);
return
[
1
,
$remote
->
preview
(
$this
->
fileData
[
"pre_name"
])];
}
public
function
upyunPreview
(
$base
=
null
,
$name
=
null
){
if
(
!
$this
->
policyData
[
'bucket_private'
]){
$fileUrl
=
$this
->
policyData
[
"url"
]
.
$this
->
fileData
[
"pre_name"
]
.
"?auth=0"
;
...
...
@@ -753,6 +773,11 @@ class FileManage extends Model{
return
[
1
,
\
S3\S3
::
aws_s3_link
(
$this
->
policyData
[
"ak"
],
$this
->
policyData
[
"sk"
],
$this
->
policyData
[
"bucketname"
],
"/"
.
$this
->
fileData
[
"pre_name"
],
3600
,
$this
->
policyData
[
"op_name"
],
array
(),
false
)];
}
private
function
remoteDownload
(){
$remote
=
new
Remote
(
$this
->
policyData
);
return
[
1
,
$remote
->
download
(
$this
->
fileData
[
"pre_name"
],
$this
->
fileData
[
"orign_name"
])];
}
public
function
ossDownload
(){
if
(
!
$this
->
policyData
[
'bucket_private'
]){
$fileUrl
=
$this
->
policyData
[
"url"
]
.
$this
->
fileData
[
"pre_name"
]
.
"?response-content-disposition="
.
urlencode
(
'attachment; filename='
.
$this
->
fileData
[
"orign_name"
]);
...
...
@@ -1145,6 +1170,8 @@ class FileManage extends Model{
$upyunPolicyData
=
[];
$s3List
=
[];
$s3PolicyData
=
[];
$remoteList
=
[];
$remotePolicyData
=
[];
foreach
(
$data
as
$key
=>
$value
)
{
if
(
!
in_array
(
$value
[
'policy_id'
],
$tempList
)){
array_push
(
$tempList
,
$value
[
'policy_id'
]);
...
...
@@ -1185,6 +1212,13 @@ class FileManage extends Model{
}
array_push
(
$s3PolicyData
[
$value
[
'policy_id'
]],
$policyTempData
);
break
;
case
'remote'
:
array_push
(
$remoteList
,
$value
[
'policy_id'
]);
if
(
empty
(
$remotePolicyData
[
$value
[
'policy_id'
]])){
$remotePolicyData
[
$value
[
'policy_id'
]]
=
[];
}
array_push
(
$remotePolicyData
[
$value
[
'policy_id'
]],
$policyTempData
);
break
;
default
:
# code...
break
;
...
...
@@ -1203,6 +1237,8 @@ class FileManage extends Model{
'upyunPolicyData'
=>
$upyunPolicyData
,
's3List'
=>
$s3List
,
's3PolicyData'
=>
$s3PolicyData
,
'remoteList'
=>
$remoteList
,
'remotePolicyData'
=>
$remotePolicyData
,
);
return
$returenValue
;
}
...
...
application/index/model/Remote.php
0 → 100644
浏览文件 @
c28f08c2
<?php
namespace
app\index\model
;
use
think\Model
;
use
think\Db
;
use
\
app\index\model\Option
;
class
Remote
extends
Model
{
public
$sk
;
private
$policy
;
private
$serverOutput
;
private
$httpCode
;
public
function
__construct
(
$policy
){
$this
->
policy
=
$policy
;
}
public
function
remove
(
$fileList
){
$signKey
=
$this
->
sign
(
$fileList
,
"DELETE"
);
$this
->
send
(
"manager.php"
,
$signKey
,
"DELETE"
,
base64_encode
(
json_encode
(
$fileList
)));
}
public
function
preview
(
$fname
){
return
$this
->
signUrl
(
$this
->
policy
[
"url"
]
.
"object.php?action=preview&name="
.
urlencode
(
$fname
)
.
"&expires="
.
(
time
()
+
(
int
)
Option
::
getValue
(
"timeout"
)));
}
public
function
download
(
$fname
,
$attnanme
){
return
$this
->
signUrl
(
$this
->
policy
[
"url"
]
.
"object.php?action=download&name="
.
urlencode
(
$fname
)
.
"&attaname="
.
urlencode
(
$attnanme
)
.
"&expires="
.
(
time
()
+
(
int
)
Option
::
getValue
(
"timeout"
)));
}
public
function
signUrl
(
$url
){
$signKey
=
hash_hmac
(
"sha256"
,
$url
,
"GET"
.
$this
->
policy
[
"sk"
]);
return
$url
.
"&auth="
.
$signKey
;
}
public
function
send
(
$target
,
$auth
,
$action
,
$object
){
$session
=
curl_init
(
$this
->
policy
[
"server"
]
.
$target
);
$postData
=
array
(
"action"
=>
$action
,
"auth"
=>
$auth
,
"object"
=>
$object
,
);
curl_setopt
(
$session
,
CURLOPT_POST
,
1
);
curl_setopt
(
$session
,
CURLOPT_POSTFIELDS
,
$postData
);
curl_setopt
(
$session
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$session
,
CURLOPT_SSL_VERIFYPEER
,
false
);
curl_setopt
(
$session
,
CURLOPT_SSL_VERIFYHOST
,
false
);
$this
->
serverOutput
=
curl_exec
(
$session
);
$this
->
httpCode
=
curl_getinfo
(
$session
,
CURLINFO_HTTP_CODE
);
echo
$this
->
serverOutput
;
}
public
function
sign
(
$content
,
$method
=
null
){
return
hash_hmac
(
"sha256"
,
base64_encode
(
json_encode
(
$content
)),
$method
.
$this
->
policy
[
"sk"
]);
}
}
?>
\ No newline at end of file
application/index/model/UploadHandler.php
浏览文件 @
c28f08c2
...
...
@@ -228,6 +228,9 @@ class UploadHandler extends Model{
case
's3'
:
return
$this
->
getS3Token
();
break
;
case
'remote'
:
return
$this
->
getRemoteToken
();
break
;
default
:
# code...
break
;
...
...
@@ -295,6 +298,35 @@ class UploadHandler extends Model{
return
$token
;
}
private
function
getRemoteToken
(){
$callbackKey
=
$this
->
getRandomKey
();
$sqlData
=
[
'callback_key'
=>
$callbackKey
,
'pid'
=>
$this
->
policyId
,
'uid'
=>
$this
->
userId
];
Db
::
name
(
'callback'
)
->
insert
(
$sqlData
);
$policy
=
array
(
'callbackUrl'
=>
Option
::
getValue
(
"siteURL"
)
.
'Callback/Remote'
,
'callbackKey'
=>
$callbackKey
,
'callbackBodyType'
=>
'application/json'
,
'fsizeLimit'
=>
(
int
)
$this
->
policyContent
[
'max_size'
],
'uid'
=>
$this
->
userId
,
);
$dirName
=
$this
->
getObjName
(
$this
->
policyContent
[
'dirrule'
]);
if
(
$this
->
policyContent
[
"autoname"
]){
$policy
=
array_merge
(
$policy
,
array
(
"saveKey"
=>
$dirName
.
(
empty
(
$dirName
)
?
""
:
"/"
)
.
$this
->
getObjName
(
$this
->
policyContent
[
'namerule'
])));
}
else
{
$policy
=
array_merge
(
$policy
,
array
(
"saveKey"
=>
$dirName
.
(
empty
(
$dirName
)
?
""
:
"/"
)
.
"$(fname)"
));
}
if
(
!
empty
(
$this
->
policyContent
[
'mimetype'
])){
$policy
=
array_merge
(
$policy
,
array
(
"mimeLimit"
=>
$this
->
policyContent
[
'mimetype'
]));
}
$signingKey
=
hash_hmac
(
"sha256"
,
json_encode
(
$policy
),
"UPLOAD"
.
$this
->
policyContent
[
'sk'
]);
$token
=
$signingKey
.
":"
.
base64_encode
(
json_encode
(
$policy
));
return
$token
;
}
static
function
upyunSign
(
$key
,
$secret
,
$method
,
$uri
,
$date
,
$policy
=
null
,
$md5
=
null
){
$elems
=
array
();
foreach
(
array
(
$method
,
$uri
,
$date
,
$policy
,
$md5
)
as
$v
){
...
...
public/thumb/.gitignore
浏览文件 @
c28f08c2
database.php
\ No newline at end of file
*
!.gitignore
\ No newline at end of file
static/js/qiniu.js
浏览文件 @
c28f08c2
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录