Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Handle remote upload via pytio uploader tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ghecquet committed Aug 24, 2016
1 parent 09f5395 commit 84277b3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
4 changes: 2 additions & 2 deletions core/src/.htaccess
Expand Up @@ -21,8 +21,8 @@ RewriteRule (.*) index.php [L]
# to make sure that authorization is transmitted.
# Just remove the # at the beginning of the line

#SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

</IfModule>

AddType application/json .json
AddType application/json .json
19 changes: 12 additions & 7 deletions core/src/plugins/core.mq/MqManager.php
Expand Up @@ -500,12 +500,14 @@ public function generateCaddyFile($params) {
// Getting URLs of the Pydio system
$serverURL = ApplicationState::detectServerURL();
$tokenURL = $serverURL . "?get_action=keystore_generate_auth_token";
$authURL = $serverURL . "/api/pydio/ws_authenticate?key=" . $configs["WS_SERVER_ADMIN"];

// Websocket Server Config
$active = $params["WS_ACTIVE"];

if ($active) {

$authURL = $serverURL . "/api/pydio/ws_authenticate?key=" . $configs["WS_SERVER_ADMIN"];

$host = $params["WS_HOST"];
$port = $params["WS_PORT"];
$secure = $params["WS_SECURE"];
Expand All @@ -525,6 +527,9 @@ public function generateCaddyFile($params) {
$active = $params["UPLOAD_ACTIVE"];

if ($active) {

$authURL = $serverURL . "/api/{repo}/upload/put";

$host = $params["UPLOAD_HOST"];
$port = $params["UPLOAD_PORT"];
$secure = $params["UPLOAD_SECURE"];
Expand All @@ -535,12 +540,12 @@ public function generateCaddyFile($params) {
(array)$hosts[$key],
[
"header " . $path => ["{\n" .
"\tAccess-Control-Allow-Origin " . $serverURL . "\n" .
"\tAccess-Control-Request-Headers *\n" .
"\tAccess-Control-Allow-Methods POST\n" .
"\tAccess-Control-Allow-Headers Range\n" .
"\tAccess-Control-Allow-Credentials true\n" .
"}"
"\t\tAccess-Control-Allow-Origin " . $serverURL . "\n" .
"\t\tAccess-Control-Request-Headers *\n" .
"\t\tAccess-Control-Allow-Methods POST\n" .
"\t\tAccess-Control-Allow-Headers Range\n" .
"\t\tAccess-Control-Allow-Credentials true\n" .
"\t}"
],
"pydioauth " . $path => [$authURL, $tokenURL . "&device=upload"],
"pydioupload " . $path => []
Expand Down
42 changes: 28 additions & 14 deletions core/src/plugins/uploader.html/SimpleUpload.php
Expand Up @@ -73,19 +73,6 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \
return;
}

// Mandatory headers
if (!isset($serverData['CONTENT_LENGTH'], $serverData['HTTP_X_FILE_NAME'])) {
throw new PydioException("Warning, missing headers!");
}

$fileNameH = $serverData['HTTP_X_FILE_NAME'];
$fileSizeH = (int)$serverData['HTTP_X_FILE_SIZE'];
// Clean up dir name (backward compat)
if (dirname($httpVars["dir"]) == "/" && basename($httpVars["dir"]) == $fileNameH) {
$httpVars["dir"] = "/";
}
$clientFileName = TextEncoder::fromUTF8(basename($fileNameH));

$this->logDebug("SimpleUpload::preProcess", $httpVars);

// Setting the stream data
Expand All @@ -97,6 +84,16 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \
exit('Warning, wrong headers');
}

$fileNameH = $serverData['HTTP_X_FILE_NAME'];
$fileSizeH = (int)$serverData['HTTP_X_FILE_SIZE'];

// Clean up dir name (backward compat)
if (dirname($httpVars["dir"]) == "/" && basename($httpVars["dir"]) == $fileNameH) {
$httpVars["dir"] = "/";
}

$clientFileName = TextEncoder::fromUTF8(basename($fileNameH));

// Setting the stream to point to the file location
$streamOrFile = $serverData['HTTP_X_FILE_TMP_LOCATION'];
$errorStatus = UPLOAD_ERR_OK;
Expand All @@ -111,16 +108,33 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \

} else if(isSet($serverData['HTTP_X_FILE_DIRECT_UPLOAD'])){

// Mandatory headers
$externalUploadStatus = $serverData['HTTP_X_FILE_DIRECT_UPLOAD'];
if(!ExternalUploadedFile::isValidStatus($externalUploadStatus)){
throw new PydioException("Unrecognized direct upload status ". $externalUploadStatus);
}
$uploadedFile = new ExternalUploadedFile($externalUploadStatus, $fileSizeH, $fileNameH);
$uploadedFile = new ExternalUploadedFile($externalUploadStatus, 1, "fake-name");

} else {

// The file is the post data stream

// Mandatory headers
if (!isset($serverData['CONTENT_LENGTH'], $serverData['HTTP_X_FILE_NAME'])) {
throw new PydioException("Warning, missing headers!");
}

$fileNameH = $serverData['HTTP_X_FILE_NAME'];
$fileSizeH = (int)$serverData['HTTP_X_FILE_SIZE'];

// Clean up dir name (backward compat)
if (dirname($httpVars["dir"]) == "/" && basename($httpVars["dir"]) == $fileNameH) {
$httpVars["dir"] = "/";
}

$clientFileName = TextEncoder::fromUTF8(basename($fileNameH));


// Checking headers
if (isSet($serverData['HTTP_X_FILE_SIZE'])) {
if ($serverData['CONTENT_LENGTH'] != $serverData['HTTP_X_FILE_SIZE']) {
Expand Down

0 comments on commit 84277b3

Please sign in to comment.