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

Commit bca0a1b

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 49acfcb + 508fa2b commit bca0a1b

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

core/src/core/src/pydio/Core/Http/Wopi/AuthFrontend.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ function retrieveParams(ServerRequestInterface &$request, ResponseInterface &$re
7575
$httpVars["auth_token"] = $payload->token;
7676
$httpVars["auth_hash"] = $payload->hash;
7777

78-
// NOT GREAT - WE REMOVE /contents from the uri to ensure that the auth_hash works fine
7978
$uri = $request->getUri();
80-
$path = str_replace("/contents", "", $uri->getPath());
81-
$uri = $uri->withPath($path);
79+
$query = $uri->getQuery();
80+
$uri = $uri->withPath($payload->uri);
81+
$path = $uri->getPath();
8282

83-
$_SERVER["REQUEST_URI"] = $uri->getPath() . '?' . $uri->getQuery();
83+
$_SERVER["REQUEST_URI"] = $path . '?' . $query;
8484

8585
// Handle upload case
8686
if ($action == "upload") {
@@ -92,7 +92,7 @@ function retrieveParams(ServerRequestInterface &$request, ResponseInterface &$re
9292
$stream,
9393
$size,
9494
0,
95-
basename($path)
95+
basename($payload->uri)
9696
);
9797

9898
$request = $request->withUploadedFiles(["userfile_0" => $uploadedFile]);
@@ -159,4 +159,4 @@ function tryToLogUser(ServerRequestInterface &$request, ResponseInterface &$resp
159159
// We're through
160160
return true;
161161
}
162-
}
162+
}

core/src/core/src/pydio/Core/Http/Wopi/Middleware.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function emitResponse(ServerRequestInterface $request, ResponseInterface
9696
$meta = $node->getNodeInfoMeta();
9797
$userId = $node->getUser()->getId();
9898
$data = [
99-
"BaseFileName" => $node->getLabel(),
99+
"BaseFileName" => urlencode($node->getLabel()),
100100
"OwnerId" => $userId,
101101
"Size" => $meta["bytesize"],
102102
"UserId" => $userId,
@@ -126,12 +126,15 @@ public function emitResponse(ServerRequestInterface $request, ResponseInterface
126126
}
127127
}
128128

129-
if($response !== false && ($response->getBody()->getSize() || $response instanceof EmptyResponse) || $response->getStatusCode() != 200) {
129+
if( $response->getBody()->getSize() === null
130+
|| $response->getBody()->getSize() > 0
131+
|| $response instanceof \Zend\Diactoros\Response\EmptyResponse
132+
|| $response->getStatusCode() != 200) {
130133
$emitter = new SapiEmitter();
131134
ShutdownScheduler::setCloseHeaders($response);
132135
$emitter->emit($response);
133136
ShutdownScheduler::getInstance()->callRegisteredShutdown();
134137
}
135138
}
136139

137-
}
140+
}

core/src/plugins/editor.libreoffice/Driver.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
9494

9595
$selection = UserSelection::fromContext($ctx, $httpVars);
9696
$destStreamURL = $selection->currentBaseUrl();
97-
$filePath = str_replace('%2F', '/', rawurlencode($httpVars['file']));
97+
$node = $selection->getUniqueNode();
9898

99-
$nodeUrl = $destStreamURL . $filePath;
100-
101-
if (empty($userId) || empty($filePath) || empty($repository)) return false;
99+
if (empty($userId) || empty($node) || empty($repository)) return false;
102100

103101
if ($action == "libreoffice_get_file_url") {
104102

@@ -114,23 +112,30 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
114112

115113
// Generating the auth hash and token
116114
$nonce = sha1(rand());
117-
$uri = '/wopi/files/' . $repositoryId . $filePath;
118115

119-
$msg = $uri . ':' . $nonce . ':' . $private;
116+
$nodePath = $node->getPath();
117+
$nodeUrl = $node->getUrl();
118+
119+
$escapedNodePath = str_replace('%2F', '/', rawurlencode($node->getPath()));
120+
121+
$uri = '/wopi/files/' . $repositoryId . $nodePath;
122+
$escapedUri = '/wopi/files/' . $repositoryId . $escapedNodePath;
123+
124+
$msg = $escapedUri . ':' . $nonce . ':' . $private;
120125
$hmac = hash_hmac('sha256', $msg, $token);
121126
$auth_hash = $nonce . ':' . $hmac;
122127

123128
// Generating the jwt token for the file
124129
$payload["token"] = $token;
125130
$payload["hash"] = $auth_hash;
126-
$payload["file"] = $uri;
131+
$payload["uri"] = $uri;
127132
$payload["task"] = $task;
128133

129134
$jwt = JWT::encode($payload, $private);
130135

131136
$resp = [
132137
'host' => ApplicationState::detectServerURL(),
133-
'uri' => $uri,
138+
'uri' => $escapedUri,
134139
'jwt' => $jwt,
135140
'permission' => $user->canWrite($repositoryId) && is_writeable($nodeUrl) ? 'edit' : 'readonly'
136141
];
@@ -198,4 +203,4 @@ public function listEmptyFormatsAction(ServerRequestInterface $requestInterface,
198203
$responseInterface = new JsonResponse($list);
199204

200205
}
201-
}
206+
}

0 commit comments

Comments
 (0)