From 0b7d9e2668e3a2e2049eb84f9c49fac41d71d35e Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Sun, 4 May 2014 15:51:08 +0200 Subject: Cleanup code a little bit - Use OCP\Response constants instead of the HTTP error code - Use checkAppEnabled() instead of OC_App::isEnabled with an if statement - Remove uneeded variable $baseURL - Rename $isvalid to $isValid --- apps/files_sharing/ajax/list.php | 16 ++++------------ apps/files_sharing/ajax/publicpreview.php | 21 ++++++++++----------- 2 files changed, 14 insertions(+), 23 deletions(-) (limited to 'apps') diff --git a/apps/files_sharing/ajax/list.php b/apps/files_sharing/ajax/list.php index 4b645496253..76926d84b22 100644 --- a/apps/files_sharing/ajax/list.php +++ b/apps/files_sharing/ajax/list.php @@ -20,17 +20,10 @@ * */ -// only need filesystem apps -$RUNTIME_APPTYPES=array('filesystem'); - -// Init owncloud - -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; } @@ -55,13 +48,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); @@ -88,4 +80,4 @@ if (OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes') === 'n $data['permissions'] = $permissions; -OCP\JSON::success(array('data' => $data)); +OCP\JSON::success(array('data' => $data)); \ No newline at end of file diff --git a/apps/files_sharing/ajax/publicpreview.php b/apps/files_sharing/ajax/publicpreview.php index d12d212a2e6..6ba47e5b3a6 100644 --- a/apps/files_sharing/ajax/publicpreview.php +++ b/apps/files_sharing/ajax/publicpreview.php @@ -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); @@ -18,20 +17,20 @@ $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : $token = array_key_exists('t', $_GET) ? (string) $_GET['t'] : ''; 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; } @@ -50,9 +49,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; } @@ -71,7 +70,7 @@ if(substr($path, 0, 1) === '/') { } 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; } @@ -87,6 +86,6 @@ try{ $preview->show(); } 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); } -- cgit v1.2.3 From 2c483fdca21fc32bf6ef8eaf5835e8e4614acd3a Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Sun, 4 May 2014 15:52:25 +0200 Subject: Add missing \ --- apps/files_sharing/ajax/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps') diff --git a/apps/files_sharing/ajax/list.php b/apps/files_sharing/ajax/list.php index 76926d84b22..c31b3a0e06f 100644 --- a/apps/files_sharing/ajax/list.php +++ b/apps/files_sharing/ajax/list.php @@ -48,7 +48,7 @@ $dir = $data['realPath']; $dir = \OC\Files\Filesystem::normalizePath($dir); if (!\OC\Files\Filesystem::is_dir($dir . '/')) { - \OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND); + \OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND); \OCP\JSON::error(array('success' => false)); exit(); } -- cgit v1.2.3