From 622b80a68076b880c13a31e0fd93f873d1176825 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Thu, 29 Mar 2018 21:39:04 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=BC=80=E5=90=AFDebug=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config.php b/application/config.php index a7d2ce8a..30b42d7b 100644 --- a/application/config.php +++ b/application/config.php @@ -18,7 +18,7 @@ return [ // 应用命名空间 'app_namespace' => 'app', // 应用调试模式 - 'app_debug' => false, + 'app_debug' => true, // 应用Trace 'app_trace' => false, // 应用模式状态 From 7536c8695b89c93e980c3353917c6e69e9a628f5 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Thu, 29 Mar 2018 21:41:40 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0remote=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/js/qiniu.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/static/js/qiniu.js b/static/js/qiniu.js index c6d01ae7..1672240b 100644 --- a/static/js/qiniu.js +++ b/static/js/qiniu.js @@ -1148,7 +1148,7 @@ function QiniuJsSDK() { // http://developer.qiniu.com/docs/v6/api/reference/up/bput.html if(uploadConfig.saveType == "remote"){ up.setOption({ - 'url': qiniuUploadUrl + 'chunk.php', + 'url': qiniuUploadUrl + 'chunk', 'multipart': false, 'chunk_size': chunk_size, 'required_features': "chunks", @@ -1213,7 +1213,7 @@ function QiniuJsSDK() { }); if(uploadConfig.saveType == "remote"){ up.setOption({ - 'url': qiniuUploadUrl + 'chunk.php' + 'url': qiniuUploadUrl + 'chunk' }); } logger.debug("up.setOption url: ", qiniuUploadUrl + '/mkblk/' + leftSize); @@ -1501,7 +1501,7 @@ function QiniuJsSDK() { local_path = '/path/'+that.URLSafeBase64Encode(pathTmp); } if(uploadConfig.saveType == "remote"){ - var url = qiniuUploadUrl + 'mkfile.php?size=' + file.size +"&key="+ key+"&fname="+ fname +"&path="+local_path; + var url = qiniuUploadUrl + 'mkfile?size=' + file.size +"&key="+ key+"&fname="+ fname +"&path="+local_path; }else{ var url = qiniuUploadUrl + '/mkfile/' + file.size + key + fname + x_vars_url+local_path; } From 32ca1132f2790eab07e118162412e2500c98d055 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Thu, 5 Apr 2018 13:24:52 +0800 Subject: [PATCH 3/6] =?UTF-8?q?aria2=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index/controller/RemoteDownload.php | 40 +++++++++++++++++++ application/index/model/Aria2.php | 15 +++++++ static/js/qiniu.js | 6 +-- 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 application/index/controller/RemoteDownload.php create mode 100644 application/index/model/Aria2.php diff --git a/application/index/controller/RemoteDownload.php b/application/index/controller/RemoteDownload.php new file mode 100644 index 00000000..2b3ef331 --- /dev/null +++ b/application/index/controller/RemoteDownload.php @@ -0,0 +1,40 @@ +userObj = new User(cookie('user_id'),cookie('login_key')); + if(!$this->userObj->loginStatus){ + echo "Bad request"; + exit(); + } + } + + private function checkPerimission($permissionId){ + $permissionData = $this->userObj->groupData["aria2"]; + if(explode(",",$permissionData)[$permissionId] != "1"){ + return false; + } + return true; + } + + public function addUrl(){ + if(!$this->checkPerimission(0)){ + return json(['error'=>1,'message'=>'您当前的无用户无法执行此操作']); + } + $aria2Options = Option::getValues(["aria2"]); + $aria2 = new Aria2($aria2Options); + } + +} \ No newline at end of file diff --git a/application/index/model/Aria2.php b/application/index/model/Aria2.php new file mode 100644 index 00000000..68d037e8 --- /dev/null +++ b/application/index/model/Aria2.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/static/js/qiniu.js b/static/js/qiniu.js index 1672240b..c6d01ae7 100644 --- a/static/js/qiniu.js +++ b/static/js/qiniu.js @@ -1148,7 +1148,7 @@ function QiniuJsSDK() { // http://developer.qiniu.com/docs/v6/api/reference/up/bput.html if(uploadConfig.saveType == "remote"){ up.setOption({ - 'url': qiniuUploadUrl + 'chunk', + 'url': qiniuUploadUrl + 'chunk.php', 'multipart': false, 'chunk_size': chunk_size, 'required_features': "chunks", @@ -1213,7 +1213,7 @@ function QiniuJsSDK() { }); if(uploadConfig.saveType == "remote"){ up.setOption({ - 'url': qiniuUploadUrl + 'chunk' + 'url': qiniuUploadUrl + 'chunk.php' }); } logger.debug("up.setOption url: ", qiniuUploadUrl + '/mkblk/' + leftSize); @@ -1501,7 +1501,7 @@ function QiniuJsSDK() { local_path = '/path/'+that.URLSafeBase64Encode(pathTmp); } if(uploadConfig.saveType == "remote"){ - var url = qiniuUploadUrl + 'mkfile?size=' + file.size +"&key="+ key+"&fname="+ fname +"&path="+local_path; + var url = qiniuUploadUrl + 'mkfile.php?size=' + file.size +"&key="+ key+"&fname="+ fname +"&path="+local_path; }else{ var url = qiniuUploadUrl + '/mkfile/' + file.size + key + fname + x_vars_url+local_path; } From 2ade8861c96be89c7dbda38b22ef8e972f594a6a Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Thu, 5 Apr 2018 17:07:36 +0800 Subject: [PATCH 4/6] =?UTF-8?q?aria2=E4=B8=8B=E8=BD=BD=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=AE=8C=E6=88=90=EF=BC=8C=E5=B9=B6=E4=B8=94=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E8=BF=9C=E7=A8=8B=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?path=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index/controller/RemoteDownload.php | 1 + application/index/model/Aria2.php | 42 ++++++++++++++++++- public/downloads/.gitignore | 2 + static/js/qiniu.js | 2 + 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 public/downloads/.gitignore diff --git a/application/index/controller/RemoteDownload.php b/application/index/controller/RemoteDownload.php index 2b3ef331..af749e74 100644 --- a/application/index/controller/RemoteDownload.php +++ b/application/index/controller/RemoteDownload.php @@ -35,6 +35,7 @@ class RemoteDownload extends Controller{ } $aria2Options = Option::getValues(["aria2"]); $aria2 = new Aria2($aria2Options); + $downloadStart = $aria2->addUrl(input("post.url")); } } \ No newline at end of file diff --git a/application/index/model/Aria2.php b/application/index/model/Aria2.php index 68d037e8..d01446e7 100644 --- a/application/index/model/Aria2.php +++ b/application/index/model/Aria2.php @@ -6,9 +6,49 @@ use think\Db; class Aria2 extends Model{ - + private $authToken; + private $apiUrl; + private $savePath; + private $saveOptions; + public $reqStatus; + public $reqMsg; + public function __construct($options){ + $this->authToken = $options["aria2_token"]; + $this->apiUrl = rtrim($options["aria2_rpcurl"],"/")."/"; + $this->saveOptions = json_decode($options["aria2_options"],true); + $this->savePath = $options["aria2_tmppath"]; + } + + public function addUrl($url){ + //{"params": ["token:123123132",["https://www.baidu.com/img/baidu_jgylogo3.gif"],{"dir":"../"}], "jsonrpc": "2.0", "id": "qer", "method": "aria2.addUri"} + $reqFileds = [ + "params" => ["token:".$this->authToken,[ + $url,["dir" => $this->savePath], + ]], + "jsonrpc" => "2.0", + "id" => uniqid(), + "method" => "aria2.addUri" + ]; + $reqFileds["params"][1][1] = array_merge($reqFileds["params"][1][1],$this->saveOptions); + $reqFileds = json_encode($reqFileds,JSON_OBJECT_AS_ARRAY); + $respondData = $this->sendReq($reqFileds); + } + private function sendReq($data){ + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $this->apiUrl."jsonrpc"); + curl_setopt($curl, CURLOPT_POST, 1); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); + curl_setopt($curl, CURLOPT_TIMEOUT, 15); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + $tmpInfo = curl_exec($curl); // 执行操作 + if (curl_errno($curl)) { + $this->reqStatus = 0; + $this->reqMsg = "请求失败,".curl_error($curl); + } + curl_close($curl); // 关闭CURL会话 + return json_decode($tmpInfo); // 返回数据,json格式 } } diff --git a/public/downloads/.gitignore b/public/downloads/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/public/downloads/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/static/js/qiniu.js b/static/js/qiniu.js index c6d01ae7..2800307f 100644 --- a/static/js/qiniu.js +++ b/static/js/qiniu.js @@ -1501,6 +1501,8 @@ function QiniuJsSDK() { local_path = '/path/'+that.URLSafeBase64Encode(pathTmp); } if(uploadConfig.saveType == "remote"){ + pathTmp = file.path; + local_path = that.URLSafeBase64Encode(pathTmp); var url = qiniuUploadUrl + 'mkfile.php?size=' + file.size +"&key="+ key+"&fname="+ fname +"&path="+local_path; }else{ var url = qiniuUploadUrl + '/mkfile/' + file.size + key + fname + x_vars_url+local_path; From 126aacca63936668c2257303f07d5d46352d314c Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Fri, 6 Apr 2018 10:26:10 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E7=A6=BB=E7=BA=BF=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=8F=8A=E6=95=B0=E6=8D=AE=E5=BA=93=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index/controller/RemoteDownload.php | 18 ++++++++++++ application/index/model/Aria2.php | 29 ++++++++++++------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/application/index/controller/RemoteDownload.php b/application/index/controller/RemoteDownload.php index af749e74..72d9eae5 100644 --- a/application/index/controller/RemoteDownload.php +++ b/application/index/controller/RemoteDownload.php @@ -29,6 +29,19 @@ class RemoteDownload extends Controller{ return true; } + private function insertRecord($aria2,$url){ + Db::name("download")->insert([ + "pid" => $aria2->pid, + "path_id" => $aria2->pathId, + "owner" => $this->userObj->uid, + "save_dir" => 1, + "status" => "ready", + "msg" => "", + "info"=>"", + "source" =>$url, + ]); + } + public function addUrl(){ if(!$this->checkPerimission(0)){ return json(['error'=>1,'message'=>'您当前的无用户无法执行此操作']); @@ -36,6 +49,11 @@ class RemoteDownload extends Controller{ $aria2Options = Option::getValues(["aria2"]); $aria2 = new Aria2($aria2Options); $downloadStart = $aria2->addUrl(input("post.url")); + if($aria2->reqStatus){ + $this->insertRecord($aria2,input("post.url")); + }else{ + return json(['error'=>1,'message'=>$aria2->reqMsg]); + } } } \ No newline at end of file diff --git a/application/index/model/Aria2.php b/application/index/model/Aria2.php index d01446e7..c3e5d435 100644 --- a/application/index/model/Aria2.php +++ b/application/index/model/Aria2.php @@ -12,27 +12,36 @@ class Aria2 extends Model{ private $saveOptions; public $reqStatus; public $reqMsg; + public $pathId; + public $pid; public function __construct($options){ $this->authToken = $options["aria2_token"]; $this->apiUrl = rtrim($options["aria2_rpcurl"],"/")."/"; $this->saveOptions = json_decode($options["aria2_options"],true); - $this->savePath = $options["aria2_tmppath"]; + $this->savePath = rtrim(rtrim($options["aria2_tmppath"],"/"),"\\").DS; } public function addUrl($url){ - //{"params": ["token:123123132",["https://www.baidu.com/img/baidu_jgylogo3.gif"],{"dir":"../"}], "jsonrpc": "2.0", "id": "qer", "method": "aria2.addUri"} + $this->pathId = uniqid(); $reqFileds = [ - "params" => ["token:".$this->authToken,[ - $url,["dir" => $this->savePath], - ]], + "params" => ["token:".$this->authToken, + [$url],["dir" => $this->savePath.$this->pathId], + ], "jsonrpc" => "2.0", - "id" => uniqid(), + "id" => $this->pathId, "method" => "aria2.addUri" ]; - $reqFileds["params"][1][1] = array_merge($reqFileds["params"][1][1],$this->saveOptions); + $reqFileds["params"][2] = array_merge($reqFileds["params"][2],$this->saveOptions); $reqFileds = json_encode($reqFileds,JSON_OBJECT_AS_ARRAY); $respondData = $this->sendReq($reqFileds); + if(isset($respondData["result"])){ + $this->reqStatus = 1; + $this->pid = $respondData["result"]; + }else{ + $this->reqStatus = 0; + $this->reqMsg = $respondData["error"]["message"]; + } } private function sendReq($data){ @@ -42,13 +51,13 @@ class Aria2 extends Model{ curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_TIMEOUT, 15); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - $tmpInfo = curl_exec($curl); // 执行操作 + $tmpInfo = curl_exec($curl); if (curl_errno($curl)) { $this->reqStatus = 0; $this->reqMsg = "请求失败,".curl_error($curl); } - curl_close($curl); // 关闭CURL会话 - return json_decode($tmpInfo); // 返回数据,json格式 + curl_close($curl); + return json_decode($tmpInfo,true); } } From aabc32efb53d8c8b2214e18c38ad5674d672f8a1 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Fri, 6 Apr 2018 16:21:40 +0800 Subject: [PATCH 6/6] =?UTF-8?q?aria2=E7=8A=B6=E6=80=81=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index/controller/RemoteDownload.php | 15 +++- application/index/model/Aria2.php | 89 +++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) diff --git a/application/index/controller/RemoteDownload.php b/application/index/controller/RemoteDownload.php index 72d9eae5..04201747 100644 --- a/application/index/controller/RemoteDownload.php +++ b/application/index/controller/RemoteDownload.php @@ -43,7 +43,8 @@ class RemoteDownload extends Controller{ } public function addUrl(){ - if(!$this->checkPerimission(0)){ + $policyData = Db::name("policy")->where("id",$this->userObj->groupData["policy_name"])->find(); + if(!$this->checkPerimission(0) || $policyData["policy_type"] != "local"){ return json(['error'=>1,'message'=>'您当前的无用户无法执行此操作']); } $aria2Options = Option::getValues(["aria2"]); @@ -56,4 +57,16 @@ class RemoteDownload extends Controller{ } } + public function FlushStatus(){ + $aria2Options = Option::getValues(["aria2"]); + $aria2 = new Aria2($aria2Options); + if(!input("?post.id")){ + return json(['error'=>1,'message'=>"信息不完整"]); + } + $policyData = Db::name("policy")->where("id",$this->userObj->groupData["policy_name"])->find(); + if(!$aria2->flushStatus(input("post.id"),$this->userObj->uid,$policyData)){ + return json(['error'=>1,'message'=>$aria2->reqMsg]); + } + } + } \ No newline at end of file diff --git a/application/index/model/Aria2.php b/application/index/model/Aria2.php index c3e5d435..ebaf3429 100644 --- a/application/index/model/Aria2.php +++ b/application/index/model/Aria2.php @@ -14,6 +14,8 @@ class Aria2 extends Model{ public $reqMsg; public $pathId; public $pid; + private $uid; + private $policy; public function __construct($options){ $this->authToken = $options["aria2_token"]; @@ -44,6 +46,93 @@ class Aria2 extends Model{ } } + public function flushStatus($id,$uid,$policy){ + $this->uid = $uid; + $this->policy = $policy; + $downloadInfo = Db::name("download")->where("id",$id)->find(); + if(empty($downloadInfo)){ + $this->reqStatus = 0; + $this->reqMsg = "未找到下载记录"; + return false; + } + if(in_array($downloadInfo["status"], ["error","complete"])){ + $this->reqStatus = 1; + return true; + } + if($uid != $downloadInfo["owner"]){ + $this->reqStatus = 0; + $this->reqMsg = "无权操作"; + return false; + } + $reqFileds = [ + "params" => ["token:".$this->authToken,$downloadInfo["pid"]], + "jsonrpc" => "2.0", + "id" => uniqid(), + "method" => "aria2.tellStatus" + ]; + $reqFileds = json_encode($reqFileds,JSON_OBJECT_AS_ARRAY); + $respondData = $this->sendReq($reqFileds); + if(isset($respondData["result"])){ + if($this->storageCheck($respondData["result"],$downloadInfo)){ + Db::name("download")->where("id",$id) + ->update([ + "status" => $respondData["result"]["status"], + "last_update" => date("Y-m-d h:i:s"), + "info" => json_encode([ + "completedLength" => $respondData["result"]["completedLength"], + "totalLength" => $respondData["result"]["totalLength"], + "dir" => $respondData["result"]["dir"], + "downloadSpeed" => $respondData["result"]["downloadSpeed"], + "errorMessage" => $respondData["result"]["errorMessage"], + ]), + ]); + switch ($respondData["result"]["status"]) { + case 'complete': + $this->setComplete($respondData["result"],$downloadInfo); + break; + + default: + # code... + break; + } + }else{ + $this->reqStatus = 0; + $this->reqMsg = "空间容量不足"; + //取消离线下载 + return false; + } + }else{ + $this->reqStatus = 0; + $this->reqMsg = $respondData["error"]["message"]; + } + return true; + } + + private function setComplete($quenInfo,$sqlData){ + FileManage::storageCheckOut($this->uid,(int)$quenInfo["totalLength"]); + if($this->policy["policy_type"] != "local"){ + return false; + } + $suffixTmp = explode('.', $quenInfo["dir"]); + $fileSuffix = array_pop($suffixTmp); + $allowedSuffix = explode(',', UploadHandler::getAllowedExt(json_decode($this->policy["filetype"],true))); + $sufficCheck = !in_array($fileSuffix,$allowedSuffix); + if(empty(UploadHandler::getAllowedExt(json_decode($this->policy["filetype"],true)))){ + $sufficCheck = false; + } + var_dump($sufficCheck); + } + + private function storageCheck($quenInfo,$sqlData){ + if(!FileManage::sotrageCheck($this->uid,(int)$quenInfo["totalLength"])){ + return false; + } + if(!FileManage::sotrageCheck($this->uid,(int)$quenInfo["completedLength"])){ + return false; + } + return true; + } + private function sendReq($data){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $this->apiUrl."jsonrpc");