Пример #1
0
 /**
  * Method to determine if script owns the path.
  *
  * @param   string  $path  Path to check ownership.
  *
  * @return  boolean  True if the php script owns the path passed.
  *
  * @since   11.1
  */
 public static function isOwner($path)
 {
     jimport('joomla.filesystem.file');
     $tmp = md5(JCrypt::genRandomBytes());
     $ssp = ini_get('session.save_path');
     $jtp = JPATH_SITE . '/tmp';
     // Try to find a writable directory
     $dir = is_writable('/tmp') ? '/tmp' : false;
     $dir = !$dir && is_writable($ssp) ? $ssp : false;
     $dir = !$dir && is_writable($jtp) ? $jtp : false;
     if ($dir) {
         $fileObject = new JFilesystemWrapperFile();
         $test = $dir . '/' . $tmp;
         // Create the test file
         $blank = '';
         $fileObject->write($test, $blank, false);
         // Test ownership
         $return = fileowner($test) == fileowner($path);
         // Delete the test file
         $fileObject->delete($test);
         return $return;
     }
     return false;
 }
Пример #2
0
 /**
  * Method to determine if script owns the path.
  *
  * @param   string  $path  Path to check ownership.
  *
  * @return  boolean  True if the php script owns the path passed.
  *
  * @since   11.1
  */
 public static function isOwner($path)
 {
     jimport('joomla.filesystem.file');
     $tmp = md5(JCrypt::genRandomBytes());
     $ssp = ini_get('session.save_path');
     $jtp = JPATH_SITE . '/tmp';
     // Try to find a writable directory
     $dir = false;
     foreach (array($jtp, $ssp, '/tmp') as $currentDir) {
         if (is_writable($currentDir)) {
             $dir = $currentDir;
             break;
         }
     }
     if ($dir) {
         $fileObject = new JFilesystemWrapperFile();
         $test = $dir . '/' . $tmp;
         // Create the test file
         $blank = '';
         $fileObject->write($test, $blank, false);
         // Test ownership
         $return = fileowner($test) == fileowner($path);
         // Delete the test file
         $fileObject->delete($test);
         return $return;
     }
     return false;
 }
Пример #3
0
 /**
  * Delete a folder.
  *
  * @param   string  $path  The path to the folder to delete.
  *
  * @return  boolean  True on success.
  *
  * @since   11.1
  */
 public static function delete($path)
 {
     @set_time_limit(ini_get('max_execution_time'));
     $pathObject = new JFilesystemWrapperPath();
     // Sanity check
     if (!$path) {
         // Bad programmer! Bad Bad programmer!
         JLog::add(__METHOD__ . ': ' . JText::_('JLIB_FILESYSTEM_ERROR_DELETE_BASE_DIRECTORY'), JLog::WARNING, 'jerror');
         return false;
     }
     $FTPOptions = JClientHelper::getCredentials('ftp');
     // Check to make sure the path valid and clean
     $path = $pathObject->clean($path);
     // Is this really a folder?
     if (!is_dir($path)) {
         JLog::add(JText::sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER', $path), JLog::WARNING, 'jerror');
         return false;
     }
     // Remove all the files in folder if they exist; disable all filtering
     $files = self::files($path, '.', false, true, array(), array());
     if (!empty($files)) {
         $file = new JFilesystemWrapperFile();
         if ($file->delete($files) !== true) {
             // JFile::delete throws an error
             return false;
         }
     }
     // Remove sub-folders of folder; disable all filtering
     $folders = self::folders($path, '.', false, true, array(), array());
     foreach ($folders as $folder) {
         if (is_link($folder)) {
             // Don't descend into linked directories, just delete the link.
             $file = new JFilesystemWrapperFile();
             if ($file->delete($folder) !== true) {
                 // JFile::delete throws an error
                 return false;
             }
         } elseif (self::delete($folder) !== true) {
             // JFolder::delete throws an error
             return false;
         }
     }
     if ($FTPOptions['enabled'] == 1) {
         // Connect the FTP client
         $ftp = JClientFtp::getInstance($FTPOptions['host'], $FTPOptions['port'], array(), $FTPOptions['user'], $FTPOptions['pass']);
     }
     // In case of restricted permissions we zap it one way or the other
     // as long as the owner is either the webserver or the ftp.
     if (@rmdir($path)) {
         $ret = true;
     } elseif ($FTPOptions['enabled'] == 1) {
         // Translate path and delete
         $path = $pathObject->clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $path), '/');
         // FTP connector throws an error
         $ret = $ftp->delete($path);
     } else {
         JLog::add(JText::sprintf('JLIB_FILESYSTEM_ERROR_FOLDER_DELETE', $path), JLog::WARNING, 'jerror');
         $ret = false;
     }
     return $ret;
 }