/** * Throw file upload error, return true if error has been thrown, false if error has been catched * * @param int $number * @param string $text * @access public */ public function throwError($number, $uploaded = false, $exit = true) { if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) { return false; } $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry"); $sFileName = $oRegistry->get("FileUpload_fileName"); $sFileUrl = $oRegistry->get("FileUpload_url"); $sEncodedFileName = CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($sFileName); header('Content-Type: text/html; charset=utf-8'); $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sEncodedFileName); if (!$uploaded) { $sFileName = ""; $sEncodedFileName = ""; } if (!empty($_GET['response_type']) && $_GET['response_type'] == 'txt') { echo $sFileName . "|" . $errorMessage; } else { echo "<script type=\"text/javascript\">"; if (!empty($_GET['CKFinderFuncNum'])) { if (!$uploaded) { $sFileUrl = ""; $sFileName = ""; } $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKFinderFuncNum']); echo "window.parent.CKFinder.tools.callFunction({$funcNum}, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "');"; } else { echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sEncodedFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;"; } echo "</script>"; } if ($exit) { exit; } }
function buildXml() { // A "must have", checking whether the connector is enabled and the basic parameters (like current folder) are safe. $this->checkConnector(); $this->checkRequest(); // Checking ACL permissions, we're just getting an information about a file, so FILE_VIEW permission seems to be ok. if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } // Make sure we actually received a file name if (!isset($_GET["fileName"])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["fileName"]); $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); // Use the resource type configuration object to check whether the extension of a file to check is really allowed. if (!$resourceTypeInfo->checkExtension($fileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); } // Make sure that the file name is really ok and has not been sent by a hacker if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $resourceTypeInfo->checkIsHiddenFile($fileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); if (!file_exists($filePath) || !is_file($filePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); } //set session values to be check by process.php upon returning from pixlr.com $maketoken = md5(session_id()); /////////////////// //HACK KOEZIONCMS// $thumbFolder = $this->_currentFolder->getThumbsServerPath(); $pixlrSession = array('token' => substr($maketoken, 0, 16), 'ImagePath' => $filePath, 'clientImagePath' => $this->_currentFolder->getUrl(), 'fileName' => $fileName, 'return' => $_SERVER['HTTP_REFERER'], 'thumbLocation' => $thumbFolder . $fileName); Session::write('Pixlr', $pixlrSession); //$_SESSION['pixlr']['token'] = substr($maketoken,0,16); //$_SESSION['pixlr']['ImagePath'] = $filePath; //$_SESSION['pixlr']['clientImagePath'] = $this->_currentFolder->getUrl(); // ie: /CMSfiles/images/subdirectory/ //$_SESSION['pixlr']['fileName'] = $fileName; //$_SESSION['pixlr']['return'] = $_SERVER['HTTP_REFERER']; //$thumbFolder = $this->_currentFolder->getThumbsServerPath(); //$_SESSION['pixlr']['thumbLocation'] = $thumbFolder . $fileName; //get the client-side absolute path to the image being edited //$absolute_filePath = "http://".$_SERVER['HTTP_HOST'].$_SESSION['pixlr']['clientImagePath'].$_SESSION['pixlr']['fileName']; $absolute_filePath = "http://" . $_SERVER['HTTP_HOST'] . $pixlrSession['clientImagePath'] . $pixlrSession['fileName']; //get teh directory this plugin is in so we can return to the process.php script in this folder $pluginFolder = dirname(__FILE__); //the directory holding this plugin //make the directory a client-side absolute URL $clientPluginFolder = preg_replace("@" . $_SERVER['DOCUMENT_ROOT'] . "@", "http://" . $_SERVER['HTTP_HOST'], $pluginFolder); //parameters to send to pixlr.com $pixlr_params = array("referrer" => $_SERVER['HTTP_HOST'], "loc" => "en", "exit" => $_SERVER['HTTP_REFERER'] != "" ? urlencode($_SERVER['HTTP_REFERER']) : "http://www.pixlr.com", "image" => $absolute_filePath, "title" => $fileName, "method" => "GET", "target" => urlencode($clientPluginFolder . "/process.php?token=" . $pixlrSession['token']), "locktarget" => "TRUE", "locktitle" => "TRUE", "locktype" => "TRUE", "lockquality" => "80"); $pixlr_link = "http://www.pixlr.com/editor?"; foreach ($pixlr_params as $key => $val) { $pixlr_link .= $key . "=" . $val . "&"; } $pixlr_link = rtrim($pixlr_link, "&"); $oNode = new Ckfinder_Connector_Utils_XmlNode("Pixlr"); $oNode->addAttribute("pixlr_link", $pixlr_link); $this->_connectorNode->addChild($oNode); }
/** * send response * @access public * */ function sendResponse() { $xml =& CKFinder_Connector_Core_Factory::getInstance("Core_Xml"); $this->_connectorNode =& $xml->getConnectorNode(); $this->checkConnector(); if ($this->mustCheckRequest()) { $this->checkRequest(); } $resourceTypeName = $this->_currentFolder->getResourceTypeName(); if (!empty($resourceTypeName)) { $this->_connectorNode->addAttribute("resourceType", $this->_currentFolder->getResourceTypeName()); } if ($this->mustAddCurrentFolderNode()) { $_currentFolder = new Ckfinder_Connector_Utils_XmlNode("CurrentFolder"); $this->_connectorNode->addChild($_currentFolder); $_currentFolder->addAttribute("path", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($this->_currentFolder->getClientPath())); $this->_errorHandler->setCatchAllErros(true); $_url = $this->_currentFolder->getUrl(); $_currentFolder->addAttribute("url", is_null($_url) ? "" : CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($_url)); $this->_errorHandler->setCatchAllErros(false); $_currentFolder->addAttribute("acl", $this->_currentFolder->getAclMask()); } $this->buildXml(); $_oErrorNode =& $xml->getErrorNode(); $_oErrorNode->addAttribute("number", "0"); echo $this->_connectorNode->asXML(); exit; }
/** * handle request and build XML * @access protected * */ protected function buildXml() { $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_CREATE)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); $sNewFolderName = isset($_GET["NewFolderName"]) ? $_GET["NewFolderName"] : ""; $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($sNewFolderName); if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sNewFolderName) || $_resourceTypeConfig->checkIsHiddenFolder($sNewFolderName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } $sServerDir = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $sNewFolderName); if (!is_writeable($this->_currentFolder->getServerPath())) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } $bCreated = false; if (file_exists($sServerDir)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST); } if ($perms = $_config->getChmodFolders()) { $oldUmask = umask(0); $bCreated = @mkdir($sServerDir, $perms); umask($oldUmask); } else { $bCreated = @mkdir($sServerDir); } if (!$bCreated) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } else { $oNewFolderNode = new Ckfinder_Connector_Utils_XmlNode("NewFolder"); $this->_connectorNode->addChild($oNewFolderNode); $oNewFolderNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($sNewFolderName)); } }
/** * handle request and build XML * @access protected * */ function buildXml() { if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } if (!isset($_GET["FileName"])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["FileName"]); $_resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $_resourceTypeInfo->checkIsHiddenFile($fileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } if (!$_resourceTypeInfo->checkExtension($fileName, false)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); $bDeleted = false; if (!file_exists($filePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); } if (!@unlink($filePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } else { $bDeleted = true; } if ($bDeleted) { $thumbPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getThumbsServerPath(), $fileName); @unlink($thumbPath); $oDeleteFileNode = new Ckfinder_Connector_Utils_XmlNode("DeletedFile"); $this->_connectorNode->addChild($oDeleteFileNode); $oDeleteFileNode->addAttribute("name", $fileName); } }
/** * send response (file) * @access public * */ function sendResponse() { if (!function_exists('ob_list_handlers') || !ob_list_handlers()) { @ob_end_clean(); } header("Content-Encoding: none"); $this->checkConnector(); $this->checkRequest(); if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["FileName"]); $_resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } if (!$_resourceTypeInfo->checkExtension($fileName, false)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); if ($_resourceTypeInfo->checkIsHiddenFile($fileName) || !file_exists($filePath) || !is_file($filePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); } $fileName = CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($fileName); header("Cache-Control: cache, must-revalidate"); header("Pragma: public"); header("Expires: 0"); header("Content-type: application/octet-stream; name=\"" . $fileName . "\""); header("Content-Disposition: attachment; filename=\"" . str_replace("\"", "\\\"", $fileName) . "\""); header("Content-Length: " . filesize($filePath)); CKFinder_Connector_Utils_FileSystem::readfileChunked($filePath); exit; }
/** * handle request and build XML * @access protected * */ protected function buildXml() { $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } // Map the virtual path to the local server path. $_sServerDir = $this->_currentFolder->getServerPath(); // Create the "Files" node. $oFilesNode = new Ckfinder_Connector_Utils_XmlNode("Files"); $this->_connectorNode->addChild($oFilesNode); if (!is_dir($_sServerDir)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); } $files = array(); if ($dh = @opendir($_sServerDir)) { while (($file = readdir($dh)) !== false) { if ($file != "." && $file != ".." && !is_dir($_sServerDir . $file)) { $files[] = $file; } } closedir($dh); } else { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); if (sizeof($files) > 0) { natcasesort($files); $i = 0; foreach ($files as $file) { $filemtime = @filemtime($_sServerDir . $file); //otherwise file doesn't exist or we can't get it's filename properly if ($filemtime !== false) { $filename = basename($file); if (!$resourceTypeInfo->checkExtension($filename, false)) { continue; } if ($resourceTypeInfo->checkIsHiddenFile($filename)) { continue; } $oFileNode[$i] = new Ckfinder_Connector_Utils_XmlNode("File"); $oFilesNode->addChild($oFileNode[$i]); $oFileNode[$i]->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding(basename($file))); $oFileNode[$i]->addAttribute("date", @date("YmdHi", $filemtime)); $size = filesize($_sServerDir . $file); if ($size && $size < 1024) { $size = 1; } else { $size = (int) round($size / 1024); } $oFileNode[$i]->addAttribute("size", $size); $i++; } } } }
/** * Throw file upload error, return true if error has been thrown, false if error has been catched * * @param int $number * @param string $text * @access public */ public function throwError($number, $uploaded = false, $exit = true) { if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) { return false; } $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry"); $sFileName = $oRegistry->get("FileUpload_fileName"); $sFileUrl = $oRegistry->get("FileUpload_url"); $sEncodedFileName = CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($sFileName); $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sEncodedFileName); if (!empty($_GET['responseType']) && $_GET['responseType'] == 'json') { header('Content-Type: application/json; charset=utf-8'); $data = array('fileName' => $sEncodedFileName, 'uploaded' => (int) $uploaded); if ($uploaded) { $data['url'] = $sFileUrl . CKFinder_Connector_Utils_Misc::encodeURIComponent($sEncodedFileName); } if ($number !== CKFINDER_CONNECTOR_ERROR_NONE) { $data['error'] = array('number' => $number, 'message' => $errorMessage); } echo json_encode($data); } else { header('Content-Type: text/html; charset=utf-8'); /** * echo <script> is not called before CKFinder_Connector_Utils_Misc::getErrorMessage * because PHP has problems with including files that contain BOM character. * Having BOM character after <script> tag causes a javascript error. */ echo "<script type=\"text/javascript\">"; if (!empty($_GET['CKEditor'])) { if (!$uploaded) { $sFileUrl = ""; $sFileName = ""; $sEncodedFileName = ""; } $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']); echo "window.parent.CKEDITOR.tools.callFunction({$funcNum}, '" . str_replace("'", "\\'", $sFileUrl . CKFinder_Connector_Utils_Misc::encodeURIComponent($sEncodedFileName)) . "', '" . str_replace("'", "\\'", $errorMessage) . "');"; } else { if (!$uploaded) { echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;"; } else { echo "window.parent.OnUploadCompleted(" . $number . ", '" . str_replace("'", "\\'", $sFileUrl . CKFinder_Connector_Utils_Misc::encodeURIComponent($sEncodedFileName)) . "', '" . str_replace("'", "\\'", $sEncodedFileName) . "', '') ;"; } } echo "</script>"; } if ($exit) { exit; } }
/** * handle request and build XML * @access protected * */ protected function buildXml() { $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_VIEW)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } // Map the virtual path to the local server path. $_sServerDir = $this->_currentFolder->getServerPath(); if (!is_dir($_sServerDir)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); } // Create the "Folders" node. $oFoldersNode = new Ckfinder_Connector_Utils_XmlNode("Folders"); $this->_connectorNode->addChild($oFoldersNode); $files = array(); if ($dh = @opendir($_sServerDir)) { while (($file = readdir($dh)) !== false) { if ($file != "." && $file != ".." && is_dir($_sServerDir . $file)) { $files[] = $file; } } closedir($dh); } else { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); if (sizeof($files) > 0) { natcasesort($files); $i = 0; foreach ($files as $file) { $oAcl = $_config->getAccessControlConfig(); $aclMask = $oAcl->getComputedMask($this->_currentFolder->getResourceTypeName(), $this->_currentFolder->getClientPath() . $file . "/"); if (($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) != CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) { continue; } if ($resourceTypeInfo->checkIsHiddenFolder($file)) { continue; } // Create the "Folder" node. $oFolderNode[$i] = new Ckfinder_Connector_Utils_XmlNode("Folder"); $oFoldersNode->addChild($oFolderNode[$i]); $oFolderNode[$i]->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($file)); $oFolderNode[$i]->addAttribute("hasChildren", CKFinder_Connector_Utils_FileSystem::hasChildren($_sServerDir . $file) ? "true" : "false"); $oFolderNode[$i]->addAttribute("acl", $aclMask); $i++; } } }
/** * handle request and build XML * @access protected * */ protected function buildXml() { if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_DELETE)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } // The root folder cannot be deleted. if ($this->_currentFolder->getClientPath() == "/") { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $folderServerPath = $this->_currentFolder->getServerPath(); if (!file_exists($folderServerPath) || !is_dir($folderServerPath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); } if (!CKFinder_Connector_Utils_FileSystem::unlink($folderServerPath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } CKFinder_Connector_Utils_FileSystem::unlink($this->_currentFolder->getThumbsServerPath()); }
/** * handle request and build XML * @access protected * */ function buildXml() { if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_RENAME)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } if (!isset($_GET["NewFolderName"])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } $newFolderName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["NewFolderName"]); $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); if (!CKFinder_Connector_Utils_FileSystem::checkFileName($newFolderName) || $resourceTypeInfo->checkIsHiddenFolder($newFolderName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } // The root folder cannot be deleted. if ($this->_currentFolder->getClientPath() == "/") { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $oldFolderPath = $this->_currentFolder->getServerPath(); $bMoved = false; if (!is_dir($oldFolderPath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } //let's calculate new folder name $newFolderPath = dirname($oldFolderPath) . DIRECTORY_SEPARATOR . $newFolderName . DIRECTORY_SEPARATOR; if (file_exists(rtrim($newFolderPath, DIRECTORY_SEPARATOR))) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST); } $bMoved = @rename($oldFolderPath, $newFolderPath); if (!$bMoved) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } else { $newThumbsServerPath = dirname($this->_currentFolder->getThumbsServerPath()) . '/' . $newFolderName . '/'; if (!@rename($this->_currentFolder->getThumbsServerPath(), $newThumbsServerPath)) { CKFinder_Connector_Utils_FileSystem::unlink($this->_currentFolder->getThumbsServerPath()); } } $newFolderPath = preg_replace(",[^/]+/?\$,", $newFolderName, $this->_currentFolder->getClientPath()) . '/'; $newFolderUrl = $resourceTypeInfo->getUrl() . ltrim($newFolderPath, '/'); $oRenameNode = new Ckfinder_Connector_Utils_XmlNode("RenamedFolder"); $this->_connectorNode->addChild($oRenameNode); $oRenameNode->addAttribute("newName", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($newFolderName)); $oRenameNode->addAttribute("newPath", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($newFolderPath)); $oRenameNode->addAttribute("newUrl", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($newFolderUrl)); }
/** * handle request and build XML * @access protected */ function buildXml() { if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $this->checkConnector(); $this->checkRequest(); // Saving empty file is equal to deleting a file, that's why FILE_DELETE permissions are required if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } if (!isset($_POST["fileName"])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } if (!isset($_POST["content"])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_POST["fileName"]); $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); if (!$resourceTypeInfo->checkExtension($fileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); } if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $resourceTypeInfo->checkIsHiddenFile($fileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); if (!file_exists($filePath) || !is_file($filePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); } if (!is_writable(dirname($filePath))) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } $fp = @fopen($filePath, 'wb'); if ($fp === false || !flock($fp, LOCK_EX)) { $result = false; } else { $result = fwrite($fp, $_POST["content"]); flock($fp, LOCK_UN); fclose($fp); } if ($result === false) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } }
/** * send response (file) * @access public * */ public function sendResponse() { if (!function_exists('ob_list_handlers') || ob_list_handlers()) { @ob_end_clean(); } header("Content-Encoding: none"); $this->checkConnector(); $this->checkRequest(); if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["FileName"]); $_resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } if (!$_resourceTypeInfo->checkExtension($fileName, false)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); if ($_resourceTypeInfo->checkIsHiddenFile($fileName) || !file_exists($filePath) || !is_file($filePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); } $fileName = CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($fileName); header("Cache-Control: cache, must-revalidate"); header("Pragma: public"); header("Expires: 0"); if (!empty($_GET['format']) && $_GET['format'] == 'text') { header("Content-Type: text/plain; charset=utf-8"); } else { $user_agent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; $encodedName = str_replace("\"", "\\\"", $fileName); if (strpos($user_agent, "MSIE") !== false) { $encodedName = str_replace(array("+", "%2E"), array(" ", "."), urlencode($encodedName)); } header("Content-type: application/octet-stream; name=\"" . $fileName . "\""); header("Content-Disposition: attachment; filename=\"" . $encodedName . "\""); } header("Content-Length: " . filesize($filePath)); CKFinder_Connector_Utils_FileSystem::readfileChunked($filePath); exit; }
function buildXml() { // A "must have", checking whether the connector is enabled and the basic parameters (like current folder) are safe. $this->checkConnector(); $this->checkRequest(); // Checking ACL permissions, we're just getting an information about a file, so FILE_VIEW permission seems to be ok. if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } // Make sure we actually received a file name if (!isset($_GET["fileName"])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["fileName"]); $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); // Use the resource type configuration object to check whether the extension of a file to check is really allowed. if (!$resourceTypeInfo->checkExtension($fileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); } // Make sure that the file name is really ok and has not been sent by a hacker if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $resourceTypeInfo->checkIsHiddenFile($fileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); if (!file_exists($filePath) || !is_file($filePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); } $size = filesize($filePath); // *** The main part of this plugin **** // Adding a <FileSize> element to the XML response. //$oNode = new Ckfinder_Connector_Utils_XmlNode("FileSize"); //$oNode->addAttribute("size", $size); //$this->_connectorNode->addChild($oNode); $myNode = new Ckfinder_Connector_Utils_XmlNode("MyMessage"); $myNode->addAttribute("message", "Hello world!"); $this->_connectorNode->addChild($myNode); }
/** * Check request * @access protected * */ protected function checkRequest() { if (preg_match(CKFINDER_REGEX_INVALID_PATH, $this->_currentFolder->getClientPath())) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); if (is_null($_resourceTypeConfig)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_TYPE); } $_clientPath = $this->_currentFolder->getClientPath(); $_clientPathParts = explode("/", trim($_clientPath, "/")); if ($_clientPathParts) { foreach ($_clientPathParts as $_part) { if ($_resourceTypeConfig->checkIsHiddenFolder($_part)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } } } if (!is_dir($this->_currentFolder->getServerPath())) { if ($_clientPath == "/") { if (!CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively($this->_currentFolder->getServerPath())) { /** * @todo handle error */ } } else { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); } } }
/** * handle request and build XML * @access protected * */ function buildXml() { if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } if (!isset($_GET["fileName"])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } if (!isset($_GET["newFileName"])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["fileName"]); $newFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["newFileName"]); $oRenamedFileNode = new Ckfinder_Connector_Utils_XmlNode("RenamedFile"); $this->_connectorNode->addChild($oRenamedFileNode); $oRenamedFileNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($fileName)); $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); if (!$resourceTypeInfo->checkExtension($newFileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); } if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $resourceTypeInfo->checkIsHiddenFile($fileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } if (!CKFinder_Connector_Utils_FileSystem::checkFileName($newFileName) || $resourceTypeInfo->checkIsHiddenFile($newFileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } if (!$resourceTypeInfo->checkExtension($fileName, false)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } if ($_config->forceAscii()) { $newFileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($newFileName); } $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); $newFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $newFileName); $bMoved = false; if (!file_exists($filePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); } if (!is_writable(dirname($newFilePath))) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } if (!is_writable($filePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } if (file_exists($newFilePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST); } $bMoved = @rename($filePath, $newFilePath); if (!$bMoved) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNKNOWN, "File " . CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($fileName) . "has not been renamed"); } else { $oRenamedFileNode->addAttribute("newName", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($newFileName)); $thumbPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getThumbsServerPath(), $fileName); CKFinder_Connector_Utils_FileSystem::unlink($thumbPath); } }
/** * Create directory recursively * * @static * @access public * @param string $dir * @param int $mode * @return boolean */ function createDirectoryRecursively($dir) { if (is_dir($dir)) { return true; } //attempt to create directory $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); if ($perms = $_config->getChmodFolders()) { $oldUmask = umask(0); $bCreated = @mkdir($dir, $perms); umask($oldUmask); } else { $bCreated = @mkdir($dir); } if ($bCreated) { return true; } //failed to create directory, perhaps we need to create parent directories first if (!CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively(dirname($dir))) { return false; } //parent directories created successfully, let's try to create directory once again if ($perms) { $old_umask = umask(0); $result = @mkdir($dir, $perms); umask($old_umask); } else { $result = @mkdir($dir); } return $result; }
/** * handle request and build XML * @access protected * */ protected function buildXml() { $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); // Create the "ConnectorInfo" node. $_oConnInfo = new Ckfinder_Connector_Utils_XmlNode("ConnectorInfo"); $this->_connectorNode->addChild($_oConnInfo); $_oConnInfo->addAttribute("enabled", $_config->getIsEnabled() ? "true" : "false"); if (!$_config->getIsEnabled()) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CONNECTOR_DISABLED); } $_ln = ''; $_lc = $_config->getLicenseKey() . ' '; if (1 == strpos(CKFINDER_CHARS, $_lc[0]) % 5) { $_ln = $_config->getLicenseName(); } $_oConnInfo->addAttribute("s", $_ln); $_oConnInfo->addAttribute("c", trim($_lc[11] . $_lc[0] . $_lc[8] . $_lc[12] . $_lc[26] . $_lc[2] . $_lc[3] . $_lc[25] . $_lc[1])); $_thumbnailsConfig = $_config->getThumbnailsConfig(); $_thumbnailsEnabled = $_thumbnailsConfig->getIsEnabled(); $_oConnInfo->addAttribute("thumbsEnabled", $_thumbnailsEnabled ? "true" : "false"); if ($_thumbnailsEnabled) { $_oConnInfo->addAttribute("thumbsUrl", $_thumbnailsConfig->getUrl()); $_oConnInfo->addAttribute("thumbsDirectAccess", $_thumbnailsConfig->getDirectAccess() ? "true" : "false"); } $_imagesConfig = $_config->getImagesConfig(); $_oConnInfo->addAttribute("imgWidth", $_imagesConfig->getMaxWidth()); $_oConnInfo->addAttribute("imgHeight", $_imagesConfig->getMaxHeight()); // Create the "ResourceTypes" node. $_oResourceTypes = new Ckfinder_Connector_Utils_XmlNode("ResourceTypes"); $this->_connectorNode->addChild($_oResourceTypes); // Create the "PluginsInfo" node. $_oPluginsInfo = new Ckfinder_Connector_Utils_XmlNode("PluginsInfo"); $this->_connectorNode->addChild($_oPluginsInfo); // Load the resource types in an array. $_aTypes = $_config->getDefaultResourceTypes(); if (!sizeof($_aTypes)) { $_aTypes = $_config->getResourceTypeNames(); } $_aTypesSize = sizeof($_aTypes); if ($_aTypesSize) { for ($i = 0; $i < $_aTypesSize; $i++) { $_resourceTypeName = $_aTypes[$i]; $_acl = $_config->getAccessControlConfig(); $_aclMask = $_acl->getComputedMask($_resourceTypeName, "/"); if (($_aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) != CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) { continue; } if (!isset($_GET['type']) || $_GET['type'] === $_resourceTypeName) { //print $_resourceTypeName; $_oTypeInfo = $_config->getResourceTypeConfig($_resourceTypeName); //print_r($_oTypeInfo); $_oResourceType[$i] = new Ckfinder_Connector_Utils_XmlNode("ResourceType"); $_oResourceTypes->addChild($_oResourceType[$i]); $_oResourceType[$i]->addAttribute("name", $_resourceTypeName); $_oResourceType[$i]->addAttribute("url", $_oTypeInfo->getUrl()); $_oResourceType[$i]->addAttribute("allowedExtensions", implode(",", $_oTypeInfo->getAllowedExtensions())); $_oResourceType[$i]->addAttribute("deniedExtensions", implode(",", $_oTypeInfo->getDeniedExtensions())); $_oResourceType[$i]->addAttribute("hash", substr(md5($_oTypeInfo->getDirectory()), 0, 16)); $_oResourceType[$i]->addAttribute("hasChildren", CKFinder_Connector_Utils_FileSystem::hasChildren($_oTypeInfo->getDirectory()) ? "true" : "false"); $_oResourceType[$i]->addAttribute("acl", $_aclMask); } } } $config = $GLOBALS['config']; if (!empty($config['Plugins']) && is_array($config['Plugins'])) { $_oConnInfo->addAttribute("plugins", implode(",", $config['Plugins'])); } CKFinder_Connector_Core_Hooks::run('InitCommand', array(&$this->_connectorNode)); }
/** * Get the dditional Nginx X-Sendfile configuration (location => root) */ public function getXSendfileNginx() { $xsendfileNginx = array(); foreach ($this->_xsendfileNginx as $location => $root) { $root = (string) $root; $location = rtrim((string) $location, '/') . '/'; if (substr($root, -1, 1) != '/' && substr($root, -1, 1) != '\\') { // root and location paths are concatenated // @see http://wiki.nginx.org/XSendfile $root = CKFinder_Connector_Utils_FileSystem::combinePaths(rtrim($root, '/'), $location); } $xsendfileNginx[$location] = $root; } return $xsendfileNginx; }
* Handle FileUpload command * * @package CKFinder * @subpackage CommandHandlers * @copyright CKSource - Frederico Knabben */ class CKFinder_Connector_CommandHandler_FileUpload extends CKFinder_Connector_CommandHandler_CommandHandlerBase { /** * Command name * * @access protected * @var string */ protected $command = "FileUpload"; /** * send response (save uploaded file, resize if required) * @access public * */ public function sendResponse() { $iErrorNumber = CKFINDER_CONNECTOR_ERROR_NONE; $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry"); $oRegistry->set("FileUpload_fileName", "unknown file"); $uploadedFile = array_shift($_FILES); if (!isset($uploadedFile['name'])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID); } $sUnsafeFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(CKFinder_Connector_Utils_Misc::mbBasename($uploadedFile['name'])); $sFileName = CKFinder_Connector_Utils_FileSystem::secureFileName($sUnsafeFileName); if ($sFileName != $sUnsafeFileName) { $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED; } $oRegistry->set("FileUpload_fileName", $sFileName); $this->checkConnector(); $this->checkRequest(); if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $_resourceTypeConfig->checkIsHiddenFile($sFileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); if (!$resourceTypeInfo->checkExtension($sFileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); } $oRegistry->set("FileUpload_fileName", $sFileName); $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl()); $maxSize = $resourceTypeInfo->getMaxSize(); if (!$_config->checkSizeAfterScaling() && $maxSize && $uploadedFile['size'] > $maxSize) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG); } $htmlExtensions = $_config->getHtmlExtensions(); $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileName); if ($htmlExtensions && !CKFinder_Connector_Utils_Misc::inArrayCaseInsensitive($sExtension, $htmlExtensions) && ($detectHtml = CKFinder_Connector_Utils_FileSystem::detectHtml($uploadedFile['tmp_name'])) === true) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE); } $secureImageUploads = $_config->getSecureImageUploads(); if ($secureImageUploads && ($isImageValid = CKFinder_Connector_Utils_FileSystem::isImageValid($uploadedFile['tmp_name'], $sExtension)) === false) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT); } switch ($uploadedFile['error']) { case UPLOAD_ERR_OK: break; case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG); break; case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_NO_FILE: $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT); break; case UPLOAD_ERR_NO_TMP_DIR: $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_NO_TMP_DIR); break; case UPLOAD_ERR_CANT_WRITE: $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); break; case UPLOAD_ERR_EXTENSION: $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); break; } $sServerDir = $this->_currentFolder->getServerPath(); while (true) { $sFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($sServerDir, $sFileName); if (file_exists($sFilePath)) { $sFileName = CKFinder_Connector_Utils_FileSystem::autoRename($sServerDir, $sFileName); $oRegistry->set("FileUpload_fileName", $sFileName); $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED; } else { if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) { $iErrorNumber = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; } else { if (isset($detectHtml) && $detectHtml === -1 && CKFinder_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) { @unlink($sFilePath); $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE); } else { if (isset($isImageValid) && $isImageValid === -1 && CKFinder_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) { @unlink($sFilePath); $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT); } } }
/** * handle request and build XML * @access protected * */ function buildXml() { $this->checkConnector(); $this->checkRequest(); if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); if (!isset($_GET["fileName"])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["fileName"]); if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $resourceTypeInfo->checkIsHiddenFile($fileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } if (!$resourceTypeInfo->checkExtension($fileName, false)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); if (!file_exists($filePath) || !is_file($filePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); } list($width, $height) = getimagesize($filePath); $oNode = new Ckfinder_Connector_Utils_XmlNode("ImageInfo"); $oNode->addAttribute("width", $width); $oNode->addAttribute("height", $height); $this->_connectorNode->addChild($oNode); }
/** * handle request and build XML * @access protected * */ protected function buildXml() { if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_RENAME)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } if (!isset($_GET["NewFolderName"])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } $newFolderName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["NewFolderName"]); $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); if ($_config->forceAscii()) { $newFolderName = CKFinder_Connector_Utils_FileSystem::convertToAscii($newFolderName); } $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); if (!CKFinder_Connector_Utils_FileSystem::checkFolderName($newFolderName) || $resourceTypeInfo->checkIsHiddenFolder($newFolderName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } // The root folder cannot be deleted. if ($this->_currentFolder->getClientPath() == "/") { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $oldFolderPath = substr($this->_currentFolder->getServerPath(), 1, -1); $newFolderPath = dirname($oldFolderPath) . '/' . $newFolderName; global $config; $s3 = s3_con(); $copied = true; $items = $s3->getBucket($config['AmazonS3']['Bucket'], $oldFolderPath); foreach ($items as $item) { //TODO: Possible bug, if repeating paths occur, it will mess up folder structure. Need to replace only first instance $newItemName = str_replace($oldFolderPath, $newFolderPath, $item['name']); $copy = $s3->copyObject($config['AmazonS3']['Bucket'], $item['name'], $config['AmazonS3']['Bucket'], $newItemName); if ($copy === false) { $copied = false; } } $deleted = true; foreach ($items as $item) { $deleted = $deleted && $s3->deleteObject($config['AmazonS3']['Bucket'], $item['name']); } // $bMoved = false; // if (!is_dir($oldFolderPath)) { // $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); // } //let's calculate new folder name // if (file_exists(rtrim($newFolderPath, '/'))) { // $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST); // } // $bMoved = @rename($oldFolderPath, $newFolderPath); if (!$copied || !$deleted) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } else { // $newThumbsServerPath = dirname($this->_currentFolder->getThumbsServerPath()) . '/' . $newFolderName . '/'; // if (!@rename($this->_currentFolder->getThumbsServerPath(), $newThumbsServerPath)) { // CKFinder_Connector_Utils_FileSystem::unlink($this->_currentFolder->getThumbsServerPath()); // } } $newFolderPath = preg_replace(",[^/]+/?\$,", $newFolderName, $this->_currentFolder->getClientPath()) . '/'; $newFolderUrl = $resourceTypeInfo->getUrl() . ltrim($newFolderPath, '/'); $oRenameNode = new Ckfinder_Connector_Utils_XmlNode("RenamedFolder"); $this->_connectorNode->addChild($oRenameNode); $oRenameNode->addAttribute("newName", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($newFolderName)); $oRenameNode->addAttribute("newPath", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($newFolderPath)); $oRenameNode->addAttribute("newUrl", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($newFolderUrl)); }
/** * Unlink file/folder * * @static * @access public * @param string $path * @return boolean */ public static function unlink($path) { /* make sure the path exists */ if (!file_exists($path)) { return false; } /* If it is a file or link, just delete it */ if (is_file($path) || is_link($path)) { return @unlink($path); } /* Scan the dir and recursively unlink */ $files = scandir($path); if ($files) { foreach ($files as $filename) { if ($filename == '.' || $filename == '..') { continue; } $file = str_replace('//', '/', $path . '/' . $filename); CKFinder_Connector_Utils_FileSystem::unlink($file); } } /* Remove the parent dir */ if (!@rmdir($path)) { return false; } return true; }
/** * Send files using X-Sendfile server module * * @param string $filePath */ public static function sendWithXSendfile($filePath) { if (stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== FALSE) { $fallback = true; $config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $XSendfileNginx = $config->getXSendfileNginx(); foreach ($XSendfileNginx as $location => $root) { if (false !== stripos($filePath, $root)) { $fallback = false; $filePath = str_ireplace($root, $location, $filePath); header("X-Accel-Redirect: " . $filePath); // Nginx break; } } // fallback to standar method if ($fallback) { CKFinder_Connector_Utils_FileSystem::readfileChunked($filePath); } } elseif (stripos($_SERVER['SERVER_SOFTWARE'], 'lighttpd/1.4') !== FALSE) { header("X-LIGHTTPD-send-file: " . $filePath); // Lighttpd v1.4 } else { header("X-Sendfile: " . $filePath); // Apache, Lighttpd v1.5, Cherokee } }
function appendErrorNode(&$oErrorsNode, $errorCode, $name, $type, $path) { $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); $oErrorNode->addAttribute("code", $errorCode); $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); $oErrorNode->addAttribute("type", $type); $oErrorNode->addAttribute("folder", $path); $oErrorsNode->addChild($oErrorNode); }
/** * build XML * @access protected * */ function buildXml() { $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } // Map the virtual path to the local server path. $_sServerDir = $this->_currentFolder->getServerPath(); // Create the "Files" node. $oFilesNode = new Ckfinder_Connector_Utils_XmlNode("Files"); $this->_connectorNode->addChild($oFilesNode); if (!is_dir($_sServerDir)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); } $files = array(); $thumbFiles = array(); if ($dh = @opendir($_sServerDir)) { while (($file = readdir($dh)) !== false) { if ($file != "." && $file != ".." && !is_dir($_sServerDir . $file)) { $files[] = $file; } } closedir($dh); } else { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); if (sizeof($files) > 0) { $_thumbnailsConfig = $_config->getThumbnailsConfig(); $_thumbServerPath = ''; $_showThumbs = !empty($_GET['showThumbs']) && $_GET['showThumbs'] == 1; if ($_thumbnailsConfig->getIsEnabled() && ($_thumbnailsConfig->getDirectAccess() || $_showThumbs)) { $_thumbServerPath = $this->_currentFolder->getThumbsServerPath(); } natcasesort($files); $i = 0; foreach ($files as $file) { $filemtime = @filemtime($_sServerDir . $file); //otherwise file doesn't exist or we can't get it's filename properly if ($filemtime !== false) { $filename = CKFinder_Connector_Utils_Misc::mbBasename($file); if (!$resourceTypeInfo->checkExtension($filename, false)) { continue; } if ($resourceTypeInfo->checkIsHiddenFile($filename)) { continue; } $oFileNode[$i] = new Ckfinder_Connector_Utils_XmlNode("File"); $oFilesNode->addChild($oFileNode[$i]); $oFileNode[$i]->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding(CKFinder_Connector_Utils_Misc::mbBasename($file))); $oFileNode[$i]->addAttribute("date", date("YmdHi", $filemtime)); if (!empty($_thumbServerPath) && preg_match(CKFINDER_REGEX_IMAGES_EXT, $filename)) { if (file_exists($_thumbServerPath . $filename)) { $oFileNode[$i]->addAttribute("thumb", $filename); } elseif ($_showThumbs) { $oFileNode[$i]->addAttribute("thumb", "?" . $filename); } } $size = filesize($_sServerDir . $file); if ($size && $size < 1024) { $size = 1; } else { $size = (int) round($size / 1024); } $oFileNode[$i]->addAttribute("size", $size); $i++; } } } }
/** * Get server path to thumbnails directory * * @access public * @return string */ function getThumbsServerPath() { if (is_null($this->_thumbsServerPath)) { $this->_resourceTypeConfig = $this->getResourceTypeConfig(); $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $_thumbnailsConfig = $_config->getThumbnailsConfig(); // Get the resource type directory. $this->_thumbsServerPath = CKFinder_Connector_Utils_FileSystem::combinePaths($_thumbnailsConfig->getDirectory(), $this->_resourceTypeConfig->getName()); // Return the resource type directory combined with the required path. $this->_thumbsServerPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_thumbsServerPath, ltrim($this->_clientPath, '/')); if (!is_dir($this->_thumbsServerPath)) { if (!CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively($this->_thumbsServerPath)) { /** * @todo Ckfinder_Connector_Utils_Xml::raiseError(); perhaps we should return error * */ } } } return $this->_thumbsServerPath; }
/** * handle request and send response * @access public * */ public function sendResponse() { // Get rid of BOM markers if (ob_get_level()) { while (@ob_end_clean() && ob_get_level()) { } } header("Content-Encoding: none"); $this->checkConnector(); $this->checkRequest(); $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $_thumbnails = $_config->getThumbnailsConfig(); if (!$_thumbnails->getIsEnabled()) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_THUMBNAILS_DISABLED); } if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } if (!isset($_GET["FileName"])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["FileName"]); $_resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $sourceFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); if ($_resourceTypeInfo->checkIsHiddenFile($fileName) || !file_exists($sourceFilePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); } $thumbFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getThumbsServerPath(), $fileName); // If the thumbnail file doesn't exists, create it now. if (!file_exists($thumbFilePath)) { if (!$this->createThumb($sourceFilePath, $thumbFilePath, $_thumbnails->getMaxWidth(), $_thumbnails->getMaxHeight(), $_thumbnails->getQuality(), true, $_thumbnails->getBmpSupported())) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } } $size = filesize($thumbFilePath); $sourceImageAttr = getimagesize($thumbFilePath); $mime = $sourceImageAttr["mime"]; $rtime = isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) ? @strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) : 0; $mtime = filemtime($thumbFilePath); $etag = dechex($mtime) . "-" . dechex($size); $is304 = false; if (isset($_SERVER["HTTP_IF_NONE_MATCH"]) && $_SERVER["HTTP_IF_NONE_MATCH"] === $etag) { $is304 = true; } else { if ($rtime == $mtime) { $is304 = true; } } if ($is304) { header("HTTP/1.0 304 Not Modified"); exit; } //header("Cache-Control: cache, must-revalidate"); //header("Pragma: public"); //header("Expires: 0"); header('Cache-control: public'); header('Etag: ' . $etag); header("Content-type: " . $mime . "; name=\"" . CKFinder_Connector_Utils_Misc::mbBasename($thumbFilePath) . "\""); header("Last-Modified: " . gmdate('D, d M Y H:i:s', $mtime) . " GMT"); //header("Content-type: application/octet-stream; name=\"{$file}\""); //header("Content-Disposition: attachment; filename=\"{$file}\""); header("Content-Length: " . $size); readfile($thumbFilePath); exit; }
/** * handle request and build XML * @access protected * */ function buildXml() { $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); // Create the "ConnectorInfo" node. $_oConnInfo = new Ckfinder_Connector_Utils_XmlNode("ConnectorInfo"); $this->_connectorNode->addChild($_oConnInfo); $_oConnInfo->addAttribute("enabled", $_config->getIsEnabled() ? "true" : "false"); if (!$_config->getIsEnabled()) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CONNECTOR_DISABLED); } $_ln = ''; $_lc = $_config->getLicenseKey() . ' '; $pos = strpos(CKFINDER_CHARS, $_lc[0]) % 5; if ($pos == 1 || $pos == 4) { $_ln = $_config->getLicenseName(); } $_oConnInfo->addAttribute("s", $_ln); $_oConnInfo->addAttribute("c", trim($_lc[11] . $_lc[0] . $_lc[8] . $_lc[12] . $_lc[26] . $_lc[2] . $_lc[3] . $_lc[25] . $_lc[1])); $_thumbnailsConfig = $_config->getThumbnailsConfig(); $_thumbnailsEnabled = $_thumbnailsConfig->getIsEnabled(); $_oConnInfo->addAttribute("thumbsEnabled", $_thumbnailsEnabled ? "true" : "false"); if ($_thumbnailsEnabled) { $_oConnInfo->addAttribute("thumbsUrl", $_thumbnailsConfig->getUrl()); $_oConnInfo->addAttribute("thumbsDirectAccess", $_thumbnailsConfig->getDirectAccess() ? "true" : "false"); } $_imagesConfig = $_config->getImagesConfig(); $_oConnInfo->addAttribute("imgWidth", $_imagesConfig->getMaxWidth()); $_oConnInfo->addAttribute("imgHeight", $_imagesConfig->getMaxHeight()); // Create the "ResourceTypes" node. $_oResourceTypes = new Ckfinder_Connector_Utils_XmlNode("ResourceTypes"); $this->_connectorNode->addChild($_oResourceTypes); // Create the "PluginsInfo" node. $_oPluginsInfo = new Ckfinder_Connector_Utils_XmlNode("PluginsInfo"); $this->_connectorNode->addChild($_oPluginsInfo); // Load the resource types in an array. $_aTypes = $_config->getDefaultResourceTypes(); if (!sizeof($_aTypes)) { $_aTypes = $_config->getResourceTypeNames(); } $_aTypesSize = sizeof($_aTypes); if ($_aTypesSize) { $phpMaxSize = 0; $max_upload = CKFinder_Connector_Utils_Misc::returnBytes(ini_get('upload_max_filesize')); if ($max_upload) { $phpMaxSize = $max_upload; } $max_post = CKFinder_Connector_Utils_Misc::returnBytes(ini_get('post_max_size')); if ($max_post) { $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $max_post) : $max_post; } //ini_get('memory_limit') only works if compiled with "--enable-memory-limit" $memory_limit = CKFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit')); if ($memory_limit && $memory_limit != -1) { $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $memory_limit) : $memory_limit; } $_oConnInfo->addAttribute("uploadMaxSize", $phpMaxSize); $_oConnInfo->addAttribute("uploadCheckImages", $_config->checkSizeAfterScaling() ? "false" : "true"); for ($i = 0; $i < $_aTypesSize; $i++) { $_resourceTypeName = $_aTypes[$i]; $_acl = $_config->getAccessControlConfig(); $_aclMask = $_acl->getComputedMask($_resourceTypeName, "/"); if (($_aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) != CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) { continue; } if (!isset($_GET['type']) || $_GET['type'] === $_resourceTypeName) { //print $_resourceTypeName; $_oTypeInfo = $_config->getResourceTypeConfig($_resourceTypeName); //print_r($_oTypeInfo); $_oResourceType[$i] = new Ckfinder_Connector_Utils_XmlNode("ResourceType"); $_oResourceTypes->addChild($_oResourceType[$i]); $_oResourceType[$i]->addAttribute("name", $_resourceTypeName); $_oResourceType[$i]->addAttribute("url", $_oTypeInfo->getUrl()); $_oResourceType[$i]->addAttribute("allowedExtensions", implode(",", $_oTypeInfo->getAllowedExtensions())); $_oResourceType[$i]->addAttribute("deniedExtensions", implode(",", $_oTypeInfo->getDeniedExtensions())); $_oResourceType[$i]->addAttribute("hash", substr(md5($_oTypeInfo->getDirectory()), 0, 16)); $_oResourceType[$i]->addAttribute("hasChildren", CKFinder_Connector_Utils_FileSystem::hasChildren($_oTypeInfo->getDirectory()) ? "true" : "false"); $_oResourceType[$i]->addAttribute("acl", $_aclMask); $maxSize = $_oTypeInfo->getMaxSize(); if ($phpMaxSize) { $maxSize = $maxSize ? min($maxSize, $phpMaxSize) : $phpMaxSize; } $_oResourceType[$i]->addAttribute("maxSize", $maxSize); } } } $config = $GLOBALS['config']; if (!empty($config['Plugins']) && is_array($config['Plugins'])) { $_oConnInfo->addAttribute("plugins", implode(",", $config['Plugins'])); } CKFinder_Connector_Core_Hooks::run('InitCommand', array(&$this->_connectorNode)); }
/** * Sends generated zip file to the user */ protected function sendZipFile() { if (!function_exists('ob_list_handlers') || ob_list_handlers()) { @ob_end_clean(); } header("Content-Encoding: none"); $this->checkConnector(); $this->checkRequest(); // empty wystarczy if (empty($_GET['FileName'])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); } $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); $hash = $resourceTypeInfo->getHash(); if ($hash !== $_GET['hash'] || $hash !== substr($_GET['FileName'], 16, 16)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(trim($_GET['FileName'])); if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } if (strtolower(pathinfo($fileName, PATHINFO_EXTENSION)) !== 'zip') { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); } $dest_dir = CKFinder_Connector_Utils_FileSystem::getTmpDir(); $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($dest_dir, $fileName); if (!file_exists($filePath) || !is_file($filePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); } if (!is_readable($filePath)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); } $zipFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(trim($_GET['ZipName'])); if (!CKFinder_Connector_Utils_FileSystem::checkFileName($zipFileName)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $fileFilename = pathinfo($zipFileName, PATHINFO_BASENAME); header("Content-Encoding: none"); header("Cache-Control: cache, must-revalidate"); header("Pragma: public"); header("Expires: 0"); $user_agent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; $encodedName = str_replace("\"", "\\\"", $fileFilename); if (strpos($user_agent, "MSIE") !== false) { $encodedName = str_replace(array("+", "%2E"), array(" ", "."), urlencode($encodedName)); } header("Content-type: application/octet-stream; name=\"" . $fileFilename . "\""); header("Content-Disposition: attachment; filename=\"" . $encodedName . "\""); header("Content-Length: " . filesize($filePath)); CKFinder_Connector_Utils_FileSystem::sendFile($filePath); exit; }