Permalink
Browse files

Fixes and migration of the handler requests signatures.

  • Loading branch information...
1 parent 6f59792 commit c912858339ffb63be937ccd1587144b9daf4c89e @cdujeu cdujeu committed May 12, 2016
Showing with 438 additions and 1,365 deletions.
  1. +9 −10 core/src/plugins/access.fs/class.fsAccessDriver.php
  2. +107 −84 core/src/plugins/access.ftp/class.ftpAccessDriver.php
  3. +1 −1 core/src/plugins/access.ftp/class.ftpAccessWrapper.php
  4. +2 −2 core/src/plugins/access.imap/class.imapAccessDriver.php
  5. +42 −40 core/src/plugins/access.jsapi/class.jsapiAccessDriver.php
  6. +0 −1 core/src/plugins/access.mysql/class.mysqlAccessDriver.php
  7. +0 −15 core/src/plugins/access.remote_fs/additionalActions.xml
  8. +0 −406 core/src/plugins/access.remote_fs/class.remote_fsAccessDriver.php
  9. +0 −310 core/src/plugins/access.remote_fs/class.remote_fsAccessWrapper.php
  10. +0 −40 core/src/plugins/access.remote_fs/i18n/conf/de.php
  11. +0 −40 core/src/plugins/access.remote_fs/i18n/conf/en.php
  12. +0 −40 core/src/plugins/access.remote_fs/i18n/conf/fr.php
  13. +0 −40 core/src/plugins/access.remote_fs/i18n/conf/it.php
  14. +0 −40 core/src/plugins/access.remote_fs/i18n/conf/pt.php
  15. +0 −51 core/src/plugins/access.remote_fs/manifest.xml
  16. +0 −3 core/src/plugins/access.remote_fs/plugin_doc.html
  17. BIN core/src/plugins/access.remote_fs/remote_fs_icon.png
  18. +4 −4 core/src/plugins/action.avatar/class.AvatarProvider.php
  19. +18 −17 core/src/plugins/action.cart/class.CartManager.php
  20. +195 −171 core/src/plugins/action.compression/class.PluginCompression.php
  21. +12 −11 core/src/plugins/action.disclaimer/class.DisclaimerProvider.php
  22. +32 −26 core/src/plugins/action.powerfs/class.PowerFSController.php
  23. +2 −2 core/src/plugins/action.skeleton/class.PluginSkeleton.php
  24. +8 −6 core/src/plugins/action.timestamp/class.TimestampCreator.php
  25. +6 −5 core/src/plugins/conf.sql/class.sqlConfDriver.php
@@ -357,7 +357,7 @@ public function uploadAction(ServerRequestInterface &$request, ResponseInterface
}
// NOW DO THE ACTUAL COPY
- $this->copyUploadedData($uploadedFile, $destination, $userfile_name, $mess);
+ $this->copyUploadedData($uploadedFile, $destination, $mess);
// PARTIAL UPLOAD - PART II: APPEND DATA TO EXISTING PART
if (isSet($httpVars["appendto_urlencoded_part"])) {
@@ -1372,13 +1372,12 @@ public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
/**
* @param array|UploadedFileInterface $uploadData Php-upload array
- * @param String $destination Destination folder, including stream data
- * @param String $filename Destination filename
+ * @param String $destination Full path to destination file, including stream data
* @param array $messages Application messages table
* @return bool
* @throws \Exception
*/
- protected function copyUploadedData($uploadData, $destination, $filename, $messages){
+ protected function copyUploadedData($uploadData, $destination, $messages){
if(is_array($uploadData)){
$isInputStream = isSet($uploadData["input_upload"]);
$newFileSize = $uploadData["size"];
@@ -1395,7 +1394,7 @@ protected function copyUploadedData($uploadData, $destination, $filename, $messa
}else{
$input = $uploadData->getStream()->detach();
}
- $output = fopen("$destination/".$filename, "w");
+ $output = fopen($destination, "w");
$sizeRead = 0;
while ($sizeRead < intval($newFileSize)) {
$chunk = fread($input, 4096);
@@ -1410,20 +1409,20 @@ protected function copyUploadedData($uploadData, $destination, $filename, $messa
}
} else {
if(is_array($uploadData)){
- $result = @move_uploaded_file($uploadData["tmp_name"], "$destination/".$filename);
+ $result = @move_uploaded_file($uploadData["tmp_name"], $destination);
if (!$result) {
- $realPath = AJXP_MetaStreamWrapper::getRealFSReference("$destination/".$filename);
+ $realPath = AJXP_MetaStreamWrapper::getRealFSReference($destination);
$result = move_uploaded_file($uploadData["tmp_name"], $realPath);
}
}else{
$clone = clone $uploadData;
try{
- $uploadData->moveTo($destination."/".$filename);
+ $uploadData->moveTo($destination);
$result = true;
}catch(\Exception $e){
// Can be blocked by open_basedir, try to perform the move again, with the
// real FS reference.
- $realPath = AJXP_MetaStreamWrapper::getRealFSReference("$destination/".$filename);
+ $realPath = AJXP_MetaStreamWrapper::getRealFSReference($destination);
try{
$clone->moveTo($realPath);
$result = true;
@@ -1433,7 +1432,7 @@ protected function copyUploadedData($uploadData, $destination, $filename, $messa
}
}
if (!$result) {
- $errorMessage="$messages[33] ".$filename;
+ $errorMessage="$messages[33] ".Utils::safeBasename($destination);
throw new \Exception($errorMessage, 411);
}
}
@@ -22,9 +22,14 @@
namespace Pydio\Access\Driver\StreamProvider\FTP;
use DOMNode;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Message\UploadedFileInterface;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\RecycleBinManager;
use Pydio\Access\Driver\StreamProvider\FS\fsAccessDriver;
+use Pydio\Core\Http\Message\BgActionTrigger;
+use Pydio\Core\Http\Response\SerializableResponseStream;
use Pydio\Core\Services\AuthService;
use Pydio\Core\Services\ConfService;
use Pydio\Core\Controller\Controller;
@@ -85,17 +90,18 @@ public function initRepository()
//AJXP_PromptException::testOrPromptForCredentials("ftp_ws_credentials", $this->repository->getId());
}
- public function uploadActions($action, $httpVars, $filesVars)
+ public function uploadActions(ServerRequestInterface &$request, ResponseInterface &$response)
{
- switch ($action) {
+ switch ($request->getAttribute("action")) {
+
case "trigger_remote_copy":
if(!$this->hasFilesToCopy()) break;
$toCopy = $this->getFileNameToCopy();
- XMLWriter::header();
- XMLWriter::triggerBgAction("next_to_remote", array(), "Copying file ".$toCopy." to ftp server");
- XMLWriter::close();
- exit(1);
+ $x = new SerializableResponseStream();
+ $response = $response->withBody($x);
+ $x->addChunk(new BgActionTrigger("next_to_remote", array(), "Copying file ".$toCopy." to ftp server"));
break;
+
case "next_to_remote":
if(!$this->hasFilesToCopy()) break;
$fData = $this->getNextFileToCopy();
@@ -130,101 +136,118 @@ public function uploadActions($action, $httpVars, $filesVars)
$this->logDebug("Error during ftp copy", array($e->getMessage(), $e->getTrace()));
}
$this->logDebug("FTP Upload : shoud trigger next or reload nextFile=$nextFile");
- XMLWriter::header();
+ $x = new SerializableResponseStream();
+ $response = $response->withBody($x);
if ($nextFile!='') {
- XMLWriter::triggerBgAction("next_to_remote", array(), "Copying file ".TextEncoder::toUTF8($nextFile)." to remote server");
+ $x->addChunk(new BgActionTrigger("next_to_remote", array(), "Copying file ".TextEncoder::toUTF8($nextFile)." to remote server"));
} else {
- XMLWriter::triggerBgAction("reload_node", array(), "Upload done, reloading client.");
+ $x->addChunk(new BgActionTrigger("reload_node", array(), "Upload done, reloading client."));
}
- XMLWriter::close();
- exit(1);
break;
+
case "upload":
- $rep_source = Utils::securePath("/".$httpVars['dir']);
- $this->logDebug("Upload : rep_source ", array($rep_source));
- $logMessage = "";
- foreach ($filesVars as $boxName => $boxData) {
- if(substr($boxName, 0, 9) != "userfile_") continue;
- $this->logDebug("Upload : rep_source ", array($rep_source));
- $err = Utils::parseFileDataErrors($boxData);
- if ($err != null) {
- $errorCode = $err[0];
- $errorMessage = $err[1];
- break;
- }
- if (isSet($httpVars["auto_rename"])) {
- $destination = $this->urlBase.$rep_source;
- $boxData["name"] = fsAccessDriver::autoRenameForDest($destination, $boxData["name"]);
- }
- $boxData["destination"] = base64_encode($rep_source);
- $destCopy = XMLWriter::replaceAjxpXmlKeywords($this->repository->getOption("TMP_UPLOAD"));
- $this->logDebug("Upload : tmp upload folder", array($destCopy));
- if (!is_dir($destCopy)) {
- if (! @mkdir($destCopy)) {
- $this->logDebug("Upload error : cannot create temporary folder", array($destCopy));
- $errorCode = 413;
- $errorMessage = "Warning, cannot create folder for temporary copy.";
- break;
+ $httpVars = $request->getParsedBody();
+ $destinationFolder = Utils::securePath("/".$httpVars['dir']);
+
+ /** @var UploadedFileInterface[] $uploadedFiles */
+ $uploadedFiles = $request->getUploadedFiles();
+ if(!count($uploadedFiles)){
+ $this->writeUploadError($request, "Could not find any uploaded file", 411);
+ }
+ foreach ($uploadedFiles as $parameterName => $uploadedFile) {
+
+ if (substr($parameterName, 0, 9) != "userfile_") continue;
+ try {
+
+ $this->logDebug("Upload : rep_source ", array($destinationFolder));
+ $err = Utils::parseFileDataErrors($uploadedFile, true);
+ if ($err != null) {
+ $errorCode = $err[0];
+ $errorMessage = $err[1];
+ throw new \Exception($errorMessage, $errorCode);
}
- }
- if (!$this->isWriteable($destCopy)) {
- $this->logDebug("Upload error: cannot write into temporary folder");
- $errorCode = 414;
- $errorMessage = "Warning, cannot write into temporary folder.";
- break;
- }
- $this->logDebug("Upload : tmp upload folder", array($destCopy));
- if (isSet($boxData["input_upload"])) {
- try {
- $destName = tempnam($destCopy, "");
- $this->logDebug("Begining reading INPUT stream");
- $input = fopen("php://input", "r");
- $output = fopen($destName, "w");
- $sizeRead = 0;
- while ($sizeRead < intval($boxData["size"])) {
- $chunk = fread($input, 4096);
- $sizeRead += strlen($chunk);
- fwrite($output, $chunk, strlen($chunk));
+ $fileName = $uploadedFile->getClientFilename();
+
+ if (isSet($httpVars["auto_rename"])) {
+ $destination = $this->urlBase . $destinationFolder;
+ $fileName = fsAccessDriver::autoRenameForDest($destination, $fileName);
+ }
+ $boxData = [
+ "name" => $fileName,
+ "destination" => base64_encode($destinationFolder)
+ ];
+
+ $destCopy = XMLWriter::replaceAjxpXmlKeywords($this->repository->getOption("TMP_UPLOAD"));
+ $this->logDebug("Upload : tmp upload folder", array($destCopy));
+ if (!is_dir($destCopy)) {
+ if (!@mkdir($destCopy)) {
+ $this->logDebug("Upload error : cannot create temporary folder", array($destCopy));
+ throw new PydioException("Warning, cannot create folder for temporary copy", false, 413);
}
- fclose($input);
- fclose($output);
- $boxData["tmp_name"] = $destName;
- $this->storeFileToCopy($boxData);
- $this->logDebug("End reading INPUT stream");
- } catch (\Exception $e) {
- $errorCode=411;
- $errorMessage = $e->getMessage();
+ }
+ if (!$this->isWriteable($destCopy)) {
+ $this->logDebug("Upload error: cannot write into temporary folder");
+ throw new PydioException("Warning, cannot write into temporary folder", false, 414);
break;
}
- } else {
- $destName = $destCopy."/".basename($boxData["tmp_name"]);
- if ($destName == $boxData["tmp_name"]) $destName .= "1";
- if (move_uploaded_file($boxData["tmp_name"], $destName)) {
- $boxData["tmp_name"] = $destName;
- $this->storeFileToCopy($boxData);
+ $this->logDebug("Upload : tmp upload folder", array($destCopy));
+
+ $mess = ConfService::getMessages();
+ $destName = tempnam($destCopy, "");
+ $boxData["tmp_name"] = $destName;
+ $this->copyUploadedData($uploadedFile, $destName, $mess);
+ $this->storeFileToCopy($boxData);
+ /*
+ if (isSet($boxData["input_upload"])) {
+ try {
+ $destName = tempnam($destCopy, "");
+ $this->logDebug("Begining reading INPUT stream");
+ $input = fopen("php://input", "r");
+ $output = fopen($destName, "w");
+ $sizeRead = 0;
+ while ($sizeRead < intval($boxData["size"])) {
+ $chunk = fread($input, 4096);
+ $sizeRead += strlen($chunk);
+ fwrite($output, $chunk, strlen($chunk));
+ }
+ fclose($input);
+ fclose($output);
+ $boxData["tmp_name"] = $destName;
+ $this->storeFileToCopy($boxData);
+ $this->logDebug("End reading INPUT stream");
+ } catch (\Exception $e) {
+ $errorCode=411;
+ $errorMessage = $e->getMessage();
+ break;
+ }
} else {
- $mess = ConfService::getMessages();
- $errorCode = 411;
- $errorMessage="$mess[33] ".$boxData["name"];
- break;
+ $destName = $destCopy."/".basename($boxData["tmp_name"]);
+ if ($destName == $boxData["tmp_name"]) $destName .= "1";
+ if (move_uploaded_file($boxData["tmp_name"], $destName)) {
+ $boxData["tmp_name"] = $destName;
+ $this->storeFileToCopy($boxData);
+ } else {
+ $mess = ConfService::getMessages();
+ $errorCode = 411;
+ $errorMessage="$mess[33] ".$boxData["name"];
+ break;
+ }
}
+ }*/
+ $this->writeUploadSuccess($request, ["PREVENT_NOTIF" => true]);
+
+ } catch (\Exception $e) {
+ $errorCode = $e->getCode();
+ if(empty($errorCode)) $errorCode = 411;
+ $this->writeUploadError($request, $e->getMessage(), $errorCode);
}
}
- if (isSet($errorMessage)) {
- $this->logDebug("Return error $errorCode $errorMessage");
- return array("ERROR" => array("CODE" => $errorCode, "MESSAGE" => $errorMessage));
- } else {
- $this->logDebug("Return success");
- return array("SUCCESS" => true, "PREVENT_NOTIF" => true);
- }
-
break;
+
default:
break;
}
- session_write_close();
- exit;
-
+ return null;
}
public function isWriteable($path, $type="dir")
@@ -183,7 +183,7 @@ public function stream_flush()
if ($this->crtMode == 'write') {
rewind($this->fp);
AJXP_Logger::debug(__CLASS__,__FUNCTION__,"Ftp_fput", array("target"=>$this->crtTarget));
- set_error_handler(array("ftpAccessWrapper", "fput_quota_hack"), E_ALL & ~E_NOTICE );
+ set_error_handler(array("\\Pydio\\Access\\Driver\\StreamProvider\\FTP\\ftpAccessWrapper", "fput_quota_hack"), E_ALL & ~E_NOTICE );
ftp_fput($this->crtLink, $this->crtTarget, $this->fp, FTP_BINARY);
restore_error_handler();
AJXP_Logger::debug(__CLASS__,__FUNCTION__,"Ftp_fput end", array("target"=>$this->crtTarget));
@@ -91,10 +91,10 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
if ($dir == "/" || empty($dir)) {
// MAILBOXES CASE
$this->repository->addOption("PAGINATION_THRESHOLD", 500);
- $this->driverConf["SCANDIR_RESULT_SORTFONC"] = array("imapAccessDriver", "sortInboxFirst");
+ $this->driverConf["SCANDIR_RESULT_SORTFONC"] = array("Pydio\\Access\\Driver\\StreamProvider\\Imap\\imapAccessDriver", "sortInboxFirst");
} else {
// MAILS LISTING CASE
- $this->driverConf["SCANDIR_RESULT_SORTFONC"] = array("imapAccessDriver", "inverseSort");
+ $this->driverConf["SCANDIR_RESULT_SORTFONC"] = array("Pydio\\Access\\Driver\\StreamProvider\\Imap\\imapAccessDriver", "inverseSort");
}
}
parent::switchAction($request, $response);
Oops, something went wrong.

0 comments on commit c912858

Please sign in to comment.