Skip to content
Snippets Groups Projects
Commit 5dd3e34f authored by Thomas Müller's avatar Thomas Müller
Browse files

Merge pull request #8444 from owncloud/cleanup-list-code

Cleanup code of files_sharing/ajax/ a little bit
parents 555b9cc2 51a6764f
No related branches found
No related tags found
No related merge requests found
......@@ -20,12 +20,10 @@
*
*/
if(!\OC_App::isEnabled('files_sharing')){
exit;
}
OCP\JSON::checkAppEnabled('files_sharing');
if(!isset($_GET['t'])){
\OC_Response::setStatus(400); //400 Bad Request
\OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
\OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG);
exit;
}
......@@ -53,13 +51,12 @@ $dir = $data['realPath'];
$dir = \OC\Files\Filesystem::normalizePath($dir);
if (!\OC\Files\Filesystem::is_dir($dir . '/')) {
\OC_Response::setStatus(404);
\OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND);
\OCP\JSON::error(array('success' => false));
exit();
}
$data = array();
$baseUrl = OCP\Util::linkTo('files_sharing', 'index.php') . '?t=' . urlencode($token) . '&dir=';
// make filelist
$files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
......
......@@ -5,9 +5,8 @@
* later.
* See the COPYING-README file.
*/
if(!\OC_App::isEnabled('files_sharing')){
exit;
}
OCP\JSON::checkAppEnabled('files_sharing');
\OC_User::setIncognitoMode(true);
......@@ -19,20 +18,20 @@ $token = array_key_exists('t', $_GET) ? (string) $_GET['t'] : '';
$keepAspect = array_key_exists('a', $_GET) ? true : false;
if($token === ''){
\OC_Response::setStatus(400); //400 Bad Request
\OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
\OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG);
exit;
}
$linkedItem = \OCP\Share::getShareByToken($token);
if($linkedItem === false || ($linkedItem['item_type'] !== 'file' && $linkedItem['item_type'] !== 'folder')) {
\OC_Response::setStatus(404);
\OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND);
\OC_Log::write('core-preview', 'Passed token parameter is not valid', \OC_Log::DEBUG);
exit;
}
if(!isset($linkedItem['uid_owner']) || !isset($linkedItem['file_source'])) {
\OC_Response::setStatus(500);
\OC_Response::setStatus(\OC_Response::STATUS_INTERNAL_SERVER_ERROR);
\OC_Log::write('core-preview', 'Passed token seems to be valid, but it does not contain all necessary information . ("' . $token . '")', \OC_Log::WARN);
exit;
}
......@@ -51,9 +50,9 @@ $pathInfo = $view->getFileInfo($path);
$sharedFile = null;
if($linkedItem['item_type'] === 'folder') {
$isvalid = \OC\Files\Filesystem::isValidPath($file);
if(!$isvalid) {
\OC_Response::setStatus(400); //400 Bad Request
$isValid = \OC\Files\Filesystem::isValidPath($file);
if(!$isValid) {
\OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
\OC_Log::write('core-preview', 'Passed filename is not valid, might be malicious (file:"' . $file . '";ip:"' . $_SERVER['REMOTE_ADDR'] . '")', \OC_Log::WARN);
exit;
}
......@@ -76,7 +75,7 @@ if ($keepAspect === true) {
}
if($maxX === 0 || $maxY === 0) {
\OC_Response::setStatus(400); //400 Bad Request
\OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
\OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
exit;
}
......@@ -93,6 +92,6 @@ try{
$preview->showPreview();
} catch (\Exception $e) {
\OC_Response::setStatus(500);
\OC_Response::setStatus(\OC_Response::STATUS_INTERNAL_SERVER_ERROR);
\OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG);
}
......@@ -10,6 +10,7 @@ class OC_Response {
const STATUS_FOUND = 304;
const STATUS_NOT_MODIFIED = 304;
const STATUS_TEMPORARY_REDIRECT = 307;
const STATUS_BAD_REQUEST = 400;
const STATUS_NOT_FOUND = 404;
const STATUS_INTERNAL_SERVER_ERROR = 500;
const STATUS_SERVICE_UNAVAILABLE = 503;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment