/**
  * 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;
     }
 }
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
 /**
  * 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));
     }
 }
Esempio n. 5
0
 /**
  * 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++;
             }
         }
     }
 }
Esempio n. 6
0
 /**
  * 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++;
         }
     }
 }
Esempio n. 8
0
 /**
  * handle request and build XML
  * @access protected
  *
  */
 protected function buildXml()
 {
     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);
     }
     $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);
     }
     $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);
     }
     $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);
     }
 }
Esempio n. 9
0
 /**
  * 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));
 }
Esempio n. 10
0
 /**
  * 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;
 }
Esempio n. 11
0
 /**
  * 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);
     // }
     $fileNames = array();
     $fileData = 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);
     // }
     global $config;
     $s3 = s3_con();
     $items = $s3->getBucket($config['AmazonS3']['Bucket'], substr($_sServerDir, 1), null, null, '/', false);
     foreach ($items as $item) {
         //Make sure it's not empty (root folder usually) and not a sub-folder (evidenced from prefix key)
         if (array_key_exists('size', $item) && $item['size'] !== 0 && !array_key_exists('prefix', $item)) {
             $fileNames[] = $item['name'];
             $fileData[$item['name']] = $item;
         }
     }
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     if (sizeof($fileNames) > 0) {
         $_thumbnailsConfig = $_config->getThumbnailsConfig();
         $_thumbServerPath = '';
         $_showThumbs = !empty($_GET['showThumbs']) && $_GET['showThumbs'] == 1;
         if ($_thumbnailsConfig->getIsEnabled() && ($_thumbnailsConfig->getDirectAccess() || $_showThumbs)) {
             $_thumbServerPath = $this->_currentFolder->getThumbsServerPath();
         }
         natcasesort($fileNames);
         $i = 0;
         foreach ($fileNames as $file) {
             $filemtime = $fileData[$file]['time'];
             //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 = $fileData[$file]['size'];
                 if ($size && $size < 1024) {
                     $size = 1;
                 } else {
                     $size = (int) round($size / 1024);
                 }
                 $oFileNode[$i]->addAttribute("size", $size);
                 $i++;
             }
         }
     }
 }
Esempio n. 12
0
 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);
 }
Esempio n. 13
0
 /**
  * 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_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 = true;
     global $config;
     $s3 = s3_con();
     $copy = $s3->copyObject($config['AmazonS3']['Bucket'], substr($filePath, 1), $config['AmazonS3']['Bucket'], substr($newFilePath, 1));
     if ($copy === false) {
         $bMoved = false;
     }
     $bMoved = $bMoved && $s3->deleteObject($config['AmazonS3']['Bucket'], substr($filePath, 1));
     //        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);
     }
 }
Esempio n. 14
0
 /**
  * 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 = substr($this->_currentFolder->getServerPath(), 1);
     //        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();
     global $config;
     $s3 = s3_con();
     $items = $s3->getBucket($config['AmazonS3']['Bucket'], $_sServerDir, null, null, '/', true);
     foreach ($items as $key => $val) {
         if (array_key_exists('prefix', $val)) {
             //TODO: Replace the base directory in this URL
             $files[] = substr(str_replace($_sServerDir, "", $key), 0, -1);
             //$files[] = substr($key, 3, strlen($key) - 4);
         }
     }
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     if (sizeof($files) > 0) {
         natcasesort($files);
         $i = 0;
         foreach ($files as $file) {
             $oAcl = $_config->getAccessControlConfig();
             $folderPath = $this->_currentFolder->getClientPath() . $file . '/';
             $aclMask = $oAcl->getComputedMask($this->_currentFolder->getResourceTypeName(), $folderPath);
             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($folderPath, $resourceTypeInfo) ? "true" : "false");
             $oFolderNode[$i]->addAttribute("acl", $aclMask);
             $i++;
         }
     }
 }
Esempio n. 15
0
 /**
  * Add unzipped node to the list
  * @param obj $oUnzippedNodes
  * @param string $name
  * @param string $action
  */
 protected function appendUnzippedNode($oUnzippedNodes, $name, $action = 'ok')
 {
     $oUnzippedNode = new CKFinder_Connector_Utils_XmlNode("File");
     $oUnzippedNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name));
     $oUnzippedNode->addAttribute("action", $action);
     $oUnzippedNodes->addChild($oUnzippedNode);
 }
Esempio n. 16
0
 /**
  * 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++;
             }
         }
     }
 }
Esempio n. 17
0
 /**
  * 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));
 }
Esempio n. 18
0
 /**
  * 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);
     }
     $_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 ($_config->forceAscii()) {
         $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToAscii($sNewFolderName);
     }
     //        if (!CKFinder_Connector_Utils_FileSystem::checkFolderName($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;
     global $config;
     $s3 = s3_con();
     //Remove preceding slash, and add trailing slash (necessary for S3 to add a "folder")
     $bCreated = $s3->putObject("", $config['AmazonS3']['Bucket'], substr($sServerDir, 1) . "/");
     //TODO: File/folder already exists
     //        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));
     }
 }