Esempio n. 1
0
 /**
  * handle request and build XML
  * @access protected
  *
  */
 function buildXml()
 {
     $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     $sNewFolderName = isset($_POST["newFolderName"]) ? $_POST["newFolderName"] : "";
     $sNewFolderName = CKEditor_Connector_Utils_FileSystem::convertToFilesystemEncoding($sNewFolderName);
     if (!CKEditor_Connector_Utils_FileSystem::checkFileName($sNewFolderName)) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_NAME);
     }
     $sServerDir = CKEditor_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $sNewFolderName);
     if (!is_writeable($this->_currentFolder->getServerPath())) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     }
     $bCreated = false;
     if (file_exists($sServerDir)) {
         $this->_errorHandler->throwError(CKEDITOR_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(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     } else {
         $oNewFolderNode = new CKEditor_Connector_Utils_XmlNode("NewFolder");
         $this->_connectorNode->addChild($oNewFolderNode);
         $oNewFolderNode->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($sNewFolderName));
     }
 }
 /**
  * handle request and build XML
  * @access protected
  *
  */
 function buildXml()
 {
     $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     // Map the virtual path to the local server path.
     $_sServerDir = $this->_currentFolder->getServerPath();
     if (!is_dir($_sServerDir)) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
     }
     // Create the "Folders" node.
     $oFoldersNode = new CKEditor_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(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     }
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     if (sizeof($files) > 0) {
         natcasesort($files);
         $i = 0;
         foreach ($files as $file) {
             // Create the "Folder" node.
             $oFolderNode[$i] = new CKEditor_Connector_Utils_XmlNode("Folder");
             $oFoldersNode->addChild($oFolderNode[$i]);
             $oFolderNode[$i]->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($file));
             $i++;
         }
     }
 }
 /**
  * send response
  * @access public
  *
  */
 function sendResponse()
 {
     $xml =& CKEditor_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 CKEditor_Connector_Utils_XmlNode("CurrentFolder");
         $this->_connectorNode->addChild($_currentFolder);
         $_currentFolder->addAttribute("path", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($this->_currentFolder->getClientPath()));
         $this->_errorHandler->setCatchAllErros(true);
         $_url = $this->_currentFolder->getUrl();
         $_currentFolder->addAttribute("url", is_null($_url) ? "" : CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($_url));
         $this->_errorHandler->setCatchAllErros(false);
     }
     $this->buildXml();
     $_oErrorNode =& $xml->getErrorNode();
     $_oErrorNode->addAttribute("number", "0");
     echo $this->_connectorNode->asXML();
     exit;
 }
Esempio n. 4
0
 /**
  * Get server path
  *
  * @return string
  * @access public
  */
 public function getServerPath()
 {
     if (is_null($this->_serverPath)) {
         $this->_resourceTypeConfig = $this->getResourceTypeConfig();
         $this->_serverPath = CKEditor_Connector_Utils_FileSystem::combinePaths($this->_resourceTypeConfig->getDirectory(), ltrim($this->_clientPath, "/"));
     }
     return $this->_serverPath;
 }
Esempio n. 5
0
 /**
  * Check request
  * @access protected
  *
  */
 function checkRequest()
 {
     if (preg_match(",(/\\.)|[[:cntrl:]]|(//)|(\\\\)|([\\:\\*\\?\"\\<\\>\\|]),", $this->_currentFolder->getClientPath())) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_NAME);
     }
     $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     if (is_null($_resourceTypeConfig)) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_TYPE);
     }
     $_clientPath = $this->_currentFolder->getClientPath();
     if (!is_dir($this->_currentFolder->getServerPath())) {
         if ($_clientPath == "/") {
             if (!CKEditor_Connector_Utils_FileSystem::createDirectoryRecursively($this->_currentFolder->getServerPath())) {
                 /**
                  * @todo handle error
                  */
             }
         } else {
             $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
         }
     }
 }
 /**
  * handle request and build XML
  * @access protected
  *
  */
 function buildXml()
 {
     $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     // Map the virtual path to the local server path.
     $_sServerDir = $this->_currentFolder->getServerPath();
     $files = array();
     $folders = array();
     if ($dh = @opendir($_sServerDir)) {
         while (($file = readdir($dh)) !== false) {
             if ($file == "." || $file == "..") {
                 continue;
             } else {
                 if (!is_dir($_sServerDir . $file)) {
                     $files[] = $file;
                 } else {
                     $folders[] = $file;
                 }
             }
         }
         closedir($dh);
     } else {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     }
     // Create the "Folders" node.
     $oFoldersNode = new CKEditor_Connector_Utils_XmlNode("Folders");
     $this->_connectorNode->addChild($oFoldersNode);
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     if (sizeof($folders) > 0) {
         natcasesort($folders);
         $i = 0;
         foreach ($folders as $file) {
             // Create the "Folder" node.
             $oFolderNode[$i] = new CKEditor_Connector_Utils_XmlNode("Folder");
             $oFoldersNode->addChild($oFolderNode[$i]);
             $oFolderNode[$i]->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($file));
             $i++;
         }
     }
     // Create the "Files" node.
     $oFilesNode = new CKEditor_Connector_Utils_XmlNode("Files");
     $this->_connectorNode->addChild($oFilesNode);
     if (!is_dir($_sServerDir)) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
     }
     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;
                 }
                 $oFileNode[$i] = new CKEditor_Connector_Utils_XmlNode("File");
                 $oFilesNode->addChild($oFileNode[$i]);
                 $oFileNode[$i]->addAttribute("name", CKEditor_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++;
             }
         }
     }
 }
 /**
  * send response (save uploaded file)
  * @access public
  *
  */
 function sendResponse()
 {
     $iErrorNumber = CKEDITOR_CONNECTOR_ERROR_NONE;
     $oRegistry =& CKEditor_Connector_Core_Factory::getInstance("Core_Registry");
     $oRegistry->set("FileUpload_fileName", "unknown file");
     $uploadedFile = array_shift($_FILES);
     if (!isset($uploadedFile['name'])) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_INVALID);
     }
     $sFileName = CKEditor_Connector_Utils_FileSystem::convertToFilesystemEncoding(basename($uploadedFile['name']));
     $oRegistry->set("FileUpload_fileName", $sFileName);
     $this->checkConnector();
     $this->checkRequest();
     if (!CKEditor_Connector_Utils_FileSystem::checkFileName($sFileName)) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_NAME);
     }
     $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     if (!$resourceTypeInfo->checkExtension($sFileName)) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_EXTENSION);
     }
     $sFileNameOrginal = $sFileName;
     $oRegistry->set("FileUpload_fileName", $sFileName);
     $htmlExtensions = $_config->getHtmlExtensions();
     $sExtension = CKEditor_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
     if ($htmlExtensions && !CKEditor_Connector_Utils_Misc::inArrayCaseInsensitive($sExtension, $htmlExtensions) && ($detectHtml = CKEditor_Connector_Utils_FileSystem::detectHtml($uploadedFile['tmp_name'])) === true) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
     }
     $sExtension = CKEditor_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
     $secureImageUploads = $_config->getSecureImageUploads();
     if ($secureImageUploads && ($isImageValid = CKEditor_Connector_Utils_FileSystem::isImageValid($uploadedFile['tmp_name'], $sExtension)) === false) {
         $this->_errorHandler->throwError(CKEDITOR_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(CKEDITOR_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
             break;
         case UPLOAD_ERR_PARTIAL:
         case UPLOAD_ERR_NO_FILE:
             $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_CORRUPT);
             break;
         case UPLOAD_ERR_NO_TMP_DIR:
             $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_NO_TMP_DIR);
             break;
         case UPLOAD_ERR_CANT_WRITE:
             $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
             break;
         case UPLOAD_ERR_EXTENSION:
             $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
             break;
     }
     $sServerDir = $this->_currentFolder->getServerPath();
     $iCounter = 0;
     while (true) {
         $sFilePath = CKEditor_Connector_Utils_FileSystem::combinePaths($sServerDir, $sFileName);
         if (file_exists($sFilePath)) {
             $iCounter++;
             $sFileName = CKEditor_Connector_Utils_FileSystem::getFileNameWithoutExtension($sFileNameOrginal) . "(" . $iCounter . ")" . "." . CKEditor_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
             $oRegistry->set("FileUpload_fileName", $sFileName);
             $iErrorNumber = CKEDITOR_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED;
         } else {
             if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) {
                 $iErrorNumber = CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED;
             } else {
                 if (isset($detectHtml) && $detectHtml === -1 && CKEditor_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) {
                     @unlink($sFilePath);
                     $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
                 } else {
                     if (isset($isImageValid) && $isImageValid === -1 && CKEditor_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) {
                         @unlink($sFilePath);
                         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_CORRUPT);
                     }
                 }
             }
             if (is_file($sFilePath) && ($perms = $_config->getChmodFiles())) {
                 $oldumask = umask(0);
                 chmod($sFilePath, $perms);
                 umask($oldumask);
             }
             break;
         }
     }
     $this->_errorHandler->throwError($iErrorNumber, $sFileName, false);
 }
 /**
  * Unlink file/folder
  *
  * @static
  * @access public
  * @param string $path
  * @return boolean
  */
 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);
             CKEditor_Connector_Utils_FileSystem::unlink($file);
         }
     }
     /*    Remove the parent dir    */
     if (!@rmdir($path)) {
         return false;
     }
     return true;
 }