From 0f78b5eddcb82167e62c074b8a7d981a493e0f46 Mon Sep 17 00:00:00 2001 From: cdujeu Date: Thu, 31 Jul 2014 14:22:14 +0200 Subject: [PATCH] Fix PlUploader for access.ftp and similar ones --- .../class.PluploadProcessor.php | 39 ++++++++++++++++--- .../uploader.plupload/pluploader_tpl.html | 2 +- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/core/src/plugins/uploader.plupload/class.PluploadProcessor.php b/core/src/plugins/uploader.plupload/class.PluploadProcessor.php index 00a69020d6..691bd41e13 100644 --- a/core/src/plugins/uploader.plupload/class.PluploadProcessor.php +++ b/core/src/plugins/uploader.plupload/class.PluploadProcessor.php @@ -45,7 +45,9 @@ class PluploadProcessor extends AJXP_Plugin public function unifyChunks($action, &$httpVars, &$fileVars) { - $filename = SystemTextEncoding::fromUTF8($httpVars["name"]); + + $filename = AJXP_Utils::decodeSecureMagic($httpVars["name"]); + $tmpName = $fileVars["file"]["tmp_name"]; $chunk = $httpVars["chunk"]; $chunks = $httpVars["chunks"]; @@ -58,9 +60,26 @@ public function unifyChunks($action, &$httpVars, &$fileVars) } $plugin = AJXP_PluginsService::findPlugin("access", $repository->getAccessType()); $streamData = $plugin->detectStreamWrapper(true); - $dir = $httpVars["dir"]; + $dir = AJXP_Utils::securePath($httpVars["dir"]); $destStreamURL = $streamData["protocol"]."://".$repository->getId().$dir."/"; + $driver = ConfService::loadDriverForRepository($repository); + $remote = false; + if (method_exists($driver, "storeFileToCopy")) { + $remote = true; + $destCopy = AJXP_XMLWriter::replaceAjxpXmlKeywords($repository->getOption("TMP_UPLOAD")); + // Make tmp folder a bit more unique using secure_token + $tmpFolder = $destCopy."/".$httpVars["secure_token"]; + if(!is_dir($tmpFolder)){ + @mkdir($destCopy."/".$httpVars["secure_token"], 0700, true); + } + $target = $tmpFolder.'/'.$filename; + $fileVars["file"]["destination"] = base64_encode($dir); + }else{ + $target = $destStreamURL.$filename; + } + + //error_log("Directory: ".$dir); // Clean the fileName for security reasons @@ -79,7 +98,7 @@ public function unifyChunks($action, &$httpVars, &$fileVars) //error_log("tmpName: ".$tmpName); // Open temp file - $out = fopen($destStreamURL.$filename, $chunk == 0 ? "wb" : "ab"); + $out = fopen($target, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file $in = fopen($tmpName, "rb"); @@ -98,7 +117,7 @@ public function unifyChunks($action, &$httpVars, &$fileVars) die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}'); } else { // Open temp file - $out = fopen($destStreamURL.$filename, $chunk == 0 ? "wb" : "ab"); + $out = fopen($target, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file $in = fopen("php://input", "rb"); @@ -115,8 +134,16 @@ public function unifyChunks($action, &$httpVars, &$fileVars) die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } /* we apply the hook if we are uploading the last chunk */ - if($chunk == $chunks-1) - AJXP_Controller::applyHook("node.change", array(null, new AJXP_Node($destStreamURL.$filename), false)); + if($chunk == $chunks-1){ + if(!$remote){ + AJXP_Controller::applyHook("node.change", array(null, new AJXP_Node($destStreamURL.$filename), false)); + }else{ + $fileVars["file"]["tmp_name"] = $target; + $fileVars["file"]["name"] = $filename; + $driver->storeFileToCopy($fileVars["file"]); + AJXP_Controller::findActionAndApply("next_to_remote", array(), array()); + } + } // Return JSON-RPC response die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}'); } diff --git a/core/src/plugins/uploader.plupload/pluploader_tpl.html b/core/src/plugins/uploader.plupload/pluploader_tpl.html index 89090669aa..14bbd3e01b 100644 --- a/core/src/plugins/uploader.plupload/pluploader_tpl.html +++ b/core/src/plugins/uploader.plupload/pluploader_tpl.html @@ -97,7 +97,7 @@ }); Uploader.bind('FileUploaded', function(up, file, res) { if(this.total.queued <= 1) { - parent.ajaxplorer.fireContextRefresh(); + //parent.ajaxplorer.fireContextRefresh(); parent.document.fire("ajaxplorer:longtask_finished"); } $.get(upurl);