forked from extern/egroupware
removed not longer used old vfs classes and the first stream_wrapper (oldvfs://), I have not yet droped the vfs table, to give the update script more testing with the change to restore
This commit is contained in:
parent
9e615429e9
commit
80367bb943
@ -1,871 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare API: VFS - old (until eGW 1.4 inclusive) VFS stream wrapper
|
||||
*
|
||||
* @link http://www.egroupware.org
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package api
|
||||
* @subpackage vfs
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2007-8 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* eGroupWare API: VFS - old (until eGW 1.4 inclusive) VFS stream wrapper
|
||||
*
|
||||
* This class uses eGW's vfs_home class to access the vfs.
|
||||
*
|
||||
* The interface is according to the docu on php.net
|
||||
*
|
||||
* @link http://de.php.net/manual/de/function.stream-wrapper-register.php
|
||||
*/
|
||||
class oldvfs_stream_wrapper implements iface_stream_wrapper
|
||||
{
|
||||
/**
|
||||
* If this class should do the operations direct in the filesystem, instead of going through the vfs
|
||||
*/
|
||||
const USE_FILESYSTEM_DIRECT = true;
|
||||
/**
|
||||
* Mime type of directories, the old vfs uses 'Directory', while eg. WebDAV uses 'httpd/unix-directory'
|
||||
*/
|
||||
const DIR_MIME_TYPE = 'Directory';
|
||||
/**
|
||||
* Scheme / protocoll used for this stream-wrapper
|
||||
*/
|
||||
const SCHEME = 'oldvfs';
|
||||
/**
|
||||
* Does url_stat returns a mime type, or has it to be determined otherwise (string with attribute name)
|
||||
*/
|
||||
const STAT_RETURN_MIME_TYPE = 'mime';
|
||||
/**
|
||||
* How much should be logged to the apache error-log
|
||||
*
|
||||
* 0 = Nothing
|
||||
* 1 = only errors
|
||||
* 2 = all function calls and errors (contains passwords too!)
|
||||
*/
|
||||
const LOG_LEVEL = 1;
|
||||
|
||||
/**
|
||||
* optional context param when opening the stream, null if no context passed
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
var $context;
|
||||
|
||||
/**
|
||||
* Instance of the old vfs class
|
||||
*
|
||||
* @var vfs_home
|
||||
*/
|
||||
static protected $old_vfs;
|
||||
|
||||
/**
|
||||
* Path off the file opened by stream_open
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $opened_path;
|
||||
/**
|
||||
* Mode of the file opened by stream_open
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $opened_mode;
|
||||
/**
|
||||
* Content of the opened file, as the old vfs can only read/write the whole file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $opened_data;
|
||||
/**
|
||||
* Position in the opened file
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $opened_pos;
|
||||
/**
|
||||
* Directory vfs::ls() of dir opened with dir_opendir()
|
||||
*
|
||||
* This static var gets overwritten by each new dir_opendir, it helps to not read the entries twice.
|
||||
*
|
||||
* @var array $path => info-array pairs
|
||||
*/
|
||||
static private $stat_cache;
|
||||
/**
|
||||
* Array with filenames of dir opened with dir_opendir
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $opened_dir;
|
||||
|
||||
/**
|
||||
* This method is called immediately after your stream object is created.
|
||||
*
|
||||
* @param string $url URL that was passed to fopen() and that this object is expected to retrieve
|
||||
* @param string $mode mode used to open the file, as detailed for fopen()
|
||||
* @param int $options additional flags set by the streams API (or'ed together):
|
||||
* - STREAM_USE_PATH If path is relative, search for the resource using the include_path.
|
||||
* - STREAM_REPORT_ERRORS If this flag is set, you are responsible for raising errors using trigger_error() during opening of the stream.
|
||||
* If this flag is not set, you should not raise any errors.
|
||||
* @param string $opened_path full path of the file/resource, if the open was successfull and STREAM_USE_PATH was set
|
||||
* @return boolean true if the ressource was opened successful, otherwise false
|
||||
*/
|
||||
function stream_open ( $url, $mode, $options, &$opened_path )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)");
|
||||
|
||||
$path = parse_url($url,PHP_URL_PATH);
|
||||
|
||||
$this->opened_path = $path;
|
||||
$this->opened_mode = $mode;
|
||||
$this->opened_data = null;
|
||||
|
||||
if (!self::$old_vfs->file_exists($data = array( // file does not exists
|
||||
'string' => $path,
|
||||
'relatives' => array(RELATIVE_ROOT),
|
||||
)) || $mode[0] == 'x') // or file should NOT exist
|
||||
{
|
||||
if ($mode[0] == 'r' || // does $mode require the file to exist (r,r+)
|
||||
$mode[0] == 'x' || // or file should not exist, but does
|
||||
!self::$old_vfs->acl_check($data+array( // or we are not allowed to create it
|
||||
'operation' => EGW_ACL_ADD,
|
||||
)))
|
||||
{
|
||||
self::_remove_password($url);
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!");
|
||||
if (!($options & STREAM_URL_STAT_QUIET))
|
||||
{
|
||||
trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!",E_USER_WARNING);
|
||||
}
|
||||
$this->opened_data = $this->opened_path = $this->opened_mode = null;
|
||||
return false;
|
||||
}
|
||||
// new file
|
||||
$this->opened_data = '';
|
||||
$this->opened_pos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($mode != 'r' && !self::$old_vfs->acl_check($data+array( // we are not allowed to edit it
|
||||
'operation' => EGW_ACL_EDIT,
|
||||
)))
|
||||
{
|
||||
self::_remove_password($url);
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file can not be edited!");
|
||||
if (!($options & STREAM_URL_STAT_QUIET))
|
||||
{
|
||||
trigger_error(__METHOD__."($url,$mode,$options) file can not be edited!",E_USER_WARNING);
|
||||
}
|
||||
$this->opened_data = $this->opened_path = $this->opened_mode = null;
|
||||
return false;
|
||||
}
|
||||
if ($mode[0] == 'w') // w or w+ truncates the file to 0 size
|
||||
{
|
||||
$this->opened_data = '';
|
||||
$this->opened_pos = 0;
|
||||
}
|
||||
}
|
||||
// can we operate directly on a filesystem stream?
|
||||
if (self::$old_vfs->file_actions && self::USE_FILESYSTEM_DIRECT)
|
||||
{
|
||||
$p = self::$old_vfs->path_parts($data);
|
||||
|
||||
if (!($this->opened_data = fopen($p->real_full_path,$mode,false)))
|
||||
{
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file $p->real_full_path can not be opened!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ($mode[0] == 'a') // append modes: a, a+
|
||||
{
|
||||
$this->stream_seek(0,SEEK_END);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the stream is closed, using fclose().
|
||||
*
|
||||
* You must release any resources that were locked or allocated by the stream.
|
||||
*/
|
||||
function stream_close ( )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
|
||||
|
||||
if (is_null($this->opened_path)) return false;
|
||||
|
||||
$ret = true;
|
||||
if (is_resource($this->opened_data))
|
||||
{
|
||||
$ret = fclose($this->opened_data);
|
||||
|
||||
if ($this->opened_mode != 'r')
|
||||
{
|
||||
// touch creates file (if necessary) and sets the modification or creation time and owner
|
||||
self::$old_vfs->touch($data = array(
|
||||
'string' => $this->opened_path,
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
));
|
||||
// we read the size from the filesystem and write it to our db-based metadata
|
||||
$p = self::$old_vfs->path_parts($data);
|
||||
$data['attributes'] = array(
|
||||
'size' => filesize($p->real_full_path),
|
||||
);
|
||||
self::$old_vfs->set_attributes($data);
|
||||
}
|
||||
}
|
||||
elseif ($this->opened_mode != 'r')
|
||||
{
|
||||
// store the changes
|
||||
self::$old_vfs->write($this->opened_data);
|
||||
}
|
||||
$this->opened_data = $this->opened_path = $this->opened_mode = null;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to fread() and fgets() calls on the stream.
|
||||
*
|
||||
* You must return up-to count bytes of data from the current read/write position as a string.
|
||||
* If there are less than count bytes available, return as many as are available.
|
||||
* If no more data is available, return either FALSE or an empty string.
|
||||
* You must also update the read/write position of the stream by the number of bytes that were successfully read.
|
||||
*
|
||||
* @param int $count
|
||||
* @return string/false up to count bytes read or false on EOF
|
||||
*/
|
||||
function stream_read ( $count )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($count) pos=$this->opened_pos");
|
||||
|
||||
if (is_resource($this->opened_data))
|
||||
{
|
||||
return fread($this->opened_data,$count);
|
||||
}
|
||||
if (is_null($this->opened_data))
|
||||
{
|
||||
if (($this->opened_data = self::$old_vfs->read(array(
|
||||
'string' => $this->opened_path,
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
))) === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$this->opened_pos = 0;
|
||||
}
|
||||
if ($this->stream_eof()) return false; // nothing more to read
|
||||
|
||||
$start = $this->opened_pos;
|
||||
$this->opened_pos += $count;
|
||||
|
||||
// multibyte save substr!
|
||||
return self::substr($this->opened_data,$start,$count);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to fwrite() calls on the stream.
|
||||
*
|
||||
* You should store data into the underlying storage used by your stream.
|
||||
* If there is not enough room, try to store as many bytes as possible.
|
||||
* You should return the number of bytes that were successfully stored in the stream, or 0 if none could be stored.
|
||||
* You must also update the read/write position of the stream by the number of bytes that were successfully written.
|
||||
*
|
||||
* @param string $data
|
||||
* @return integer
|
||||
*/
|
||||
function stream_write ( $data )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($data)");
|
||||
|
||||
if (is_resource($this->opened_data))
|
||||
{
|
||||
return fwrite($this->opened_data,$data);
|
||||
}
|
||||
$len = bytes($data);
|
||||
// multibyte save substr!
|
||||
self::substr($this->opened_data,$this->opened_pos);
|
||||
|
||||
$this->opened_pos += $len;
|
||||
|
||||
return $len;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to feof() calls on the stream.
|
||||
*
|
||||
* Important: PHP 5.0 introduced a bug that wasn't fixed until 5.1: the return value has to be the oposite!
|
||||
*
|
||||
* if(version_compare(PHP_VERSION,'5.0','>=') && version_compare(PHP_VERSION,'5.1','<'))
|
||||
* {
|
||||
* $eof = !$eof;
|
||||
* }
|
||||
*
|
||||
* @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise
|
||||
*/
|
||||
function stream_eof ( )
|
||||
{
|
||||
if (is_resource($this->opened_data))
|
||||
{
|
||||
return feof($this->opened_data);
|
||||
}
|
||||
if (!is_null($this->opened_data))
|
||||
{
|
||||
$len = bytes($this->opened_data);
|
||||
$eof = $this->opened_pos >= $len;
|
||||
}
|
||||
if (self::LOG_LEVEL > 1)
|
||||
{
|
||||
error_log(__METHOD__."() pos=$this->opened_pos >= $len=len --> ".($eof ? 'true' : 'false'));
|
||||
}
|
||||
return $eof;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to ftell() calls on the stream.
|
||||
*
|
||||
* @return integer current read/write position of the stream
|
||||
*/
|
||||
function stream_tell ( )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
|
||||
|
||||
if (is_resource($this->opened_data))
|
||||
{
|
||||
return ftell($this->opened_data);
|
||||
}
|
||||
return $this->opened_pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to fseek() calls on the stream.
|
||||
*
|
||||
* You should update the read/write position of the stream according to offset and whence.
|
||||
* See fseek() for more information about these parameters.
|
||||
*
|
||||
* @param integer $offset
|
||||
* @param integer $whence SEEK_SET - Set position equal to offset bytes
|
||||
* SEEK_CUR - Set position to current location plus offset.
|
||||
* SEEK_END - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.)
|
||||
* @return boolean TRUE if the position was updated, FALSE otherwise.
|
||||
*/
|
||||
function stream_seek ( $offset, $whence )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($offset,$whence)");
|
||||
|
||||
if (is_resource($this->opened_data))
|
||||
{
|
||||
return fseek($this->opened_data,$offset,$whence);
|
||||
}
|
||||
if (is_null($this->opened_path)) return false;
|
||||
|
||||
switch($whence)
|
||||
{
|
||||
default:
|
||||
case SEEK_SET:
|
||||
$this->opened_pos = $offset;
|
||||
break;
|
||||
case SEEK_END:
|
||||
$this->opened_pos = bytes($this->opened_data);
|
||||
// fall through
|
||||
case SEEK_CUR:
|
||||
$this->opened_pos += $offset;
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to fflush() calls on the stream.
|
||||
*
|
||||
* If you have cached data in your stream but not yet stored it into the underlying storage, you should do so now.
|
||||
*
|
||||
* @return booelan TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
|
||||
*/
|
||||
function stream_flush ( )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
|
||||
|
||||
if (is_resource($this->opened_data))
|
||||
{
|
||||
return fflush($this->opened_data);
|
||||
}
|
||||
// we cant flush, as the old vfs can only write the whole data as once
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to fstat() calls on the stream.
|
||||
*
|
||||
* If you plan to use your wrapper in a require_once you need to define stream_stat().
|
||||
* If you plan to allow any other tests like is_file()/is_dir(), you have to define url_stat().
|
||||
* stream_stat() must define the size of the file, or it will never be included.
|
||||
* url_stat() must define mode, or is_file()/is_dir()/is_executable(), and any of those functions affected by clearstatcache() simply won't work.
|
||||
* It's not documented, but directories must be a mode like 040777 (octal), and files a mode like 0100666.
|
||||
* If you wish the file to be executable, use 7s instead of 6s.
|
||||
* The last 3 digits are exactly the same thing as what you pass to chmod.
|
||||
* 040000 defines a directory, and 0100000 defines a file.
|
||||
*
|
||||
* @return array containing the same values as appropriate for the stream.
|
||||
*/
|
||||
function stream_stat ( )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($this->opened_path)");
|
||||
|
||||
return $this->url_stat($this->opened_path,0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to unlink() calls on URL paths associated with the wrapper.
|
||||
*
|
||||
* It should attempt to delete the item specified by path.
|
||||
* In order for the appropriate error message to be returned, do not define this method if your wrapper does not support unlinking!
|
||||
*
|
||||
* @param string $url
|
||||
* @return boolean TRUE on success or FALSE on failure
|
||||
*/
|
||||
static function unlink ( $url )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)");
|
||||
|
||||
$path = parse_url($url,PHP_URL_PATH);
|
||||
|
||||
$data=array(
|
||||
'string' => $path,
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
);
|
||||
if (!self::$old_vfs->acl_check($data+array(
|
||||
'operation' => EGW_ACL_DELETE,
|
||||
'must_exist' => true,
|
||||
)) || ($type = self::$old_vfs->file_type($data)) === self::DIR_MIME_TYPE)
|
||||
{
|
||||
self::_remove_password($url);
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url) (type=$type) permission denied!");
|
||||
return false; // no permission or file does not exist
|
||||
}
|
||||
unset(self::$stat_cache[$path]);
|
||||
|
||||
return self::$old_vfs->rm($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to rename() calls on URL paths associated with the wrapper.
|
||||
*
|
||||
* It should attempt to rename the item specified by path_from to the specification given by path_to.
|
||||
* In order for the appropriate error message to be returned, do not define this method if your wrapper does not support renaming.
|
||||
*
|
||||
* The regular filesystem stream-wrapper returns an error, if $url_from and $url_to are not either both files or both dirs!
|
||||
*
|
||||
* @param string $url_from
|
||||
* @param string $url_to
|
||||
* @return boolean TRUE on success or FALSE on failure
|
||||
*/
|
||||
static function rename ( $url_from, $url_to )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url_from,$url_to)");
|
||||
|
||||
$path_from = parse_url($url_from,PHP_URL_PATH);
|
||||
$path_to = parse_url($url_to,PHP_URL_PATH);
|
||||
|
||||
$data_from = array(
|
||||
'string' => $path_from,
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
);
|
||||
if (!self::$old_vfs->acl_check($data_from+array(
|
||||
'operation' => EGW_ACL_DELETE,
|
||||
'must_exist'=> true,
|
||||
)))
|
||||
{
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_from permission denied!");
|
||||
return false; // no permission or file does not exist
|
||||
}
|
||||
$data_to = array(
|
||||
'string' => $path_to,
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
);
|
||||
if (!self::$old_vfs->acl_check($data_to+array(
|
||||
'operation' => EGW_ACL_ADD,
|
||||
)))
|
||||
{
|
||||
self::_remove_password($url_from);
|
||||
self::_remove_password($url_to);
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_to permission denied!");
|
||||
return false; // no permission or file does not exist
|
||||
}
|
||||
// the filesystem stream-wrapper does NOT allow to rename files to directories, as this makes problems
|
||||
// for our vfs too, we give abort here with an error, like the filesystem one does
|
||||
if (($type_to = self::$old_vfs->file_type($data_to)) &&
|
||||
($type_to === self::DIR_MIME_TYPE) !== (self::$old_vfs->file_type($data_from) === self::DIR_MIME_TYPE))
|
||||
{
|
||||
$is_dir = $type_to === self::DIR_MIME_TYPE ? 'a' : 'no';
|
||||
self::_remove_password($url_from);
|
||||
self::_remove_password($url_to);
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) $path_to is $is_dir directory!");
|
||||
return false; // no permission or file does not exist
|
||||
}
|
||||
unset(self::$stat_cache[$path_from]);
|
||||
|
||||
return self::$old_vfs->mv(array(
|
||||
'from' => $path_from,
|
||||
'to' => $path_to,
|
||||
'relatives' => array(RELATIVE_ROOT,RELATIVE_ROOT),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to mkdir() calls on URL paths associated with the wrapper.
|
||||
*
|
||||
* It should attempt to create the directory specified by path.
|
||||
* In order for the appropriate error message to be returned, do not define this method if your wrapper does not support creating directories.
|
||||
*
|
||||
* @param string $url
|
||||
* @param int $mode
|
||||
* @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE
|
||||
* @return boolean TRUE on success or FALSE on failure
|
||||
*/
|
||||
static function mkdir ( $url, $mode, $options )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)");
|
||||
|
||||
$path = parse_url($url,PHP_URL_PATH);
|
||||
|
||||
// check if we should also create all non-existing path components and our parent does not exist,
|
||||
// if yes call ourself recursive with the parent directory
|
||||
if (($options & STREAM_MKDIR_RECURSIVE) && $path != '/' && !self::$old_vfs->file_exists(array(
|
||||
'string' => dirname($path),
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
)))
|
||||
{
|
||||
if (!self::mkdir(dirname($path),$mode,$options))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$data=array(
|
||||
'string' => $path,
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
);
|
||||
if (!self::$old_vfs->acl_check($data+array(
|
||||
'operation' => EGW_ACL_ADD,
|
||||
'must_exist' => false,
|
||||
)))
|
||||
{
|
||||
self::_remove_password($url);
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
|
||||
if (!($options & STREAM_URL_STAT_QUIET))
|
||||
{
|
||||
trigger_error(__METHOD__."('$url',$mode,$options) permission denied!",E_USER_WARNING);
|
||||
}
|
||||
return false; // no permission or file does not exist
|
||||
}
|
||||
return self::$old_vfs->mkdir($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to rmdir() calls on URL paths associated with the wrapper.
|
||||
*
|
||||
* It should attempt to remove the directory specified by path.
|
||||
* In order for the appropriate error message to be returned, do not define this method if your wrapper does not support removing directories.
|
||||
*
|
||||
* @param string $url
|
||||
* @param int $options Possible values include STREAM_REPORT_ERRORS.
|
||||
* @return boolean TRUE on success or FALSE on failure.
|
||||
*/
|
||||
static function rmdir ( $url, $options )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)");
|
||||
|
||||
$path = parse_url($url,PHP_URL_PATH);
|
||||
|
||||
$data=array(
|
||||
'string' => $path,
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
);
|
||||
if (!self::$old_vfs->acl_check($data+array(
|
||||
'operation' => EGW_ACL_DELETE,
|
||||
'must_exist' => true,
|
||||
)) || ($type = self::$old_vfs->file_type($data)) !== self::DIR_MIME_TYPE)
|
||||
{
|
||||
self::_remove_password($url);
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url,$options) (type=$type) permission denied!");
|
||||
if (!($options & STREAM_URL_STAT_QUIET))
|
||||
{
|
||||
trigger_error(__METHOD__."('$url',$options) (type=$type) permission denied!",E_USER_WARNING);
|
||||
}
|
||||
return false; // no permission or file does not exist
|
||||
}
|
||||
// abort with an error, if the dir is not empty
|
||||
// our vfs deletes recursive, while the stream-wrapper interface does not!
|
||||
if (($files = self::$old_vfs->ls($data)))
|
||||
{
|
||||
self::_remove_password($url);
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url,$options) dir is not empty!");
|
||||
if (!($options & STREAM_URL_STAT_QUIET))
|
||||
{
|
||||
trigger_error(__METHOD__."('$url',$options) dir is not empty!",E_USER_WARNING);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
unset(self::$stat_cache[$path]);
|
||||
|
||||
return self::$old_vfs->rm($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is not (yet) a stream-wrapper function, but it's necessary and can be used static
|
||||
*
|
||||
* @param string $url
|
||||
* @param int $time=null modification time (unix timestamp), default null = current time
|
||||
* @param int $atime=null access time (unix timestamp), default null = current time, not implemented in the vfs!
|
||||
*/
|
||||
static function touch($url,$time=null,$atime=null)
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)");
|
||||
|
||||
$path = parse_url($url,PHP_URL_PATH);
|
||||
|
||||
$data=array(
|
||||
'string' => $path,
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
);
|
||||
if (!is_null($time)) $data['time'] = $time;
|
||||
|
||||
return self::$old_vfs->touch($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called immediately when your stream object is created for examining directory contents with opendir().
|
||||
*
|
||||
* @param string $path URL that was passed to opendir() and that this object is expected to explore.
|
||||
* @param $options
|
||||
* @return booelan
|
||||
*/
|
||||
function dir_opendir ( $url, $options )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$url',$options)");
|
||||
|
||||
$this->opened_dir = null;
|
||||
|
||||
$path = parse_url($url,PHP_URL_PATH);
|
||||
|
||||
$files = self::$old_vfs->ls(array(
|
||||
'string' => $path,
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
'checksubdirs' => false,
|
||||
'nofiles' => false,
|
||||
'orderby' => 'name',
|
||||
//'mime_type' => '',
|
||||
));
|
||||
if (!is_array($files) ||
|
||||
// we also need to return false, if $url is not a directory!
|
||||
count($files) == 1 && $path == egw_vfs::concat($files[0]['directory'],$files[0]['name']) &&
|
||||
$files[0]['mime_type'] != self::DIR_MIME_TYPE)
|
||||
{
|
||||
self::_remove_password($url);
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$options) $url is not directory!");
|
||||
$this->opened_dir = null;
|
||||
return false;
|
||||
}
|
||||
self::$stat_cache = $this->opened_dir = array();
|
||||
foreach($files as $file)
|
||||
{
|
||||
$this->opened_dir[] = $file['name'];
|
||||
self::$stat_cache[egw_vfs::concat($file['directory'],$file['name'])] = $file;
|
||||
}
|
||||
//print_r($this->opened_dir);
|
||||
reset($this->opened_dir);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to stat() calls on the URL paths associated with the wrapper.
|
||||
*
|
||||
* It should return as many elements in common with the system function as possible.
|
||||
* Unknown or unavailable values should be set to a rational value (usually 0).
|
||||
*
|
||||
* If you plan to use your wrapper in a require_once you need to define stream_stat().
|
||||
* If you plan to allow any other tests like is_file()/is_dir(), you have to define url_stat().
|
||||
* stream_stat() must define the size of the file, or it will never be included.
|
||||
* url_stat() must define mode, or is_file()/is_dir()/is_executable(), and any of those functions affected by clearstatcache() simply won't work.
|
||||
* It's not documented, but directories must be a mode like 040777 (octal), and files a mode like 0100666.
|
||||
* If you wish the file to be executable, use 7s instead of 6s.
|
||||
* The last 3 digits are exactly the same thing as what you pass to chmod.
|
||||
* 040000 defines a directory, and 0100000 defines a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param int $flags holds additional flags set by the streams API. It can hold one or more of the following values OR'd together:
|
||||
* - STREAM_URL_STAT_LINK For resources with the ability to link to other resource (such as an HTTP Location: forward,
|
||||
* or a filesystem symlink). This flag specified that only information about the link itself should be returned,
|
||||
* not the resource pointed to by the link.
|
||||
* This flag is set in response to calls to lstat(), is_link(), or filetype().
|
||||
* - STREAM_URL_STAT_QUIET If this flag is set, your wrapper should not raise any errors. If this flag is not set,
|
||||
* you are responsible for reporting errors using the trigger_error() function during stating of the path.
|
||||
* stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper!
|
||||
* @return array
|
||||
*/
|
||||
static function url_stat ( $url, $flags )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$url',$flags)");
|
||||
|
||||
$path = parse_url($url,PHP_URL_PATH);
|
||||
|
||||
// check if we already have the info from the last dir_open call, as the old vfs reads it anyway from the db
|
||||
if (self::$stat_cache && isset(self::$stat_cache[$path]))
|
||||
{
|
||||
return self::_vfsinfo2stat(self::$stat_cache[$path]);
|
||||
}
|
||||
|
||||
list($info) = self::$old_vfs->ls(array(
|
||||
'string' => $path,
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
'checksubdirs' => false,
|
||||
'nofiles' => true,
|
||||
//'orderby' => 'name',
|
||||
//'mime_type' => '',
|
||||
));
|
||||
//print_r($info);
|
||||
if (!$info)
|
||||
{
|
||||
self::_remove_password($url);
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$flags) file or directory not found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return self::_vfsinfo2stat($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to readdir().
|
||||
*
|
||||
* It should return a string representing the next filename in the location opened by dir_opendir().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function dir_readdir ( )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
|
||||
|
||||
if (!is_array($this->opened_dir)) return false;
|
||||
|
||||
$file = current($this->opened_dir); next($this->opened_dir);
|
||||
|
||||
return $file ? $file : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to rewinddir().
|
||||
*
|
||||
* It should reset the output generated by dir_readdir(). i.e.:
|
||||
* The next call to dir_readdir() should return the first entry in the location returned by dir_opendir().
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function dir_rewinddir ( )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
|
||||
|
||||
if (!is_array($this->opened_dir)) return false;
|
||||
|
||||
reset($this->opened_dir);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to closedir().
|
||||
*
|
||||
* You should release any resources which were locked or allocated during the opening and use of the directory stream.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function dir_closedir ( )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
|
||||
|
||||
if (!is_array($this->opened_dir)) return false;
|
||||
|
||||
$this->opened_dir = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a vfs-file-info into a stat array
|
||||
*
|
||||
* @param array $info
|
||||
* @return array
|
||||
*/
|
||||
static private function _vfsinfo2stat($info)
|
||||
{
|
||||
$stat = array(
|
||||
'ino' => $info['file_id'],
|
||||
'name' => $info['name'],
|
||||
'mode' => $info['owner_id'] > 0 ?
|
||||
($info['mime_type'] == self::DIR_MIME_TYPE ? 040700 : 0100600) :
|
||||
($info['mime_type'] == self::DIR_MIME_TYPE ? 040070 : 0100060),
|
||||
'size' => $info['size'],
|
||||
'uid' => $info['owner_id'] > 0 ? $info['owner_id'] : 0,
|
||||
'gid' => $info['owner_id'] < 0 ? -$info['owner_id'] : 0,
|
||||
'mtime' => strtotime($info['modified'] ? $info['modified'] : $info['created']),
|
||||
'ctime' => strtotime($info['created']),
|
||||
'nlink' => $info['mime_type'] == self::DIR_MIME_TYPE ? 2 : 1,
|
||||
// eGW addition to return the mime type
|
||||
'mime' => $info['mime_type'],
|
||||
);
|
||||
//error_log(__METHOD__."($info[name]) = ".print_r($stat,true));
|
||||
return $stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multibyte save substr
|
||||
*
|
||||
* @param string $str
|
||||
* @param int $start
|
||||
* @param int $length=null
|
||||
* @return string
|
||||
*/
|
||||
static function substr($str,$start,$length=null)
|
||||
{
|
||||
static $func_overload;
|
||||
|
||||
if (is_null($func_overload)) $func_overload = extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
|
||||
|
||||
return $func_overload & 2 ? mb_substr($str,$start,$length,'ascii') : substr($str,$start,$length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the password of an url with '...' for error messages
|
||||
*
|
||||
* @param string &$url
|
||||
*/
|
||||
static private function _remove_password(&$url)
|
||||
{
|
||||
$parts = parse_url($url);
|
||||
|
||||
if ($parts['pass'] || $parts['scheme'])
|
||||
{
|
||||
$url = $parts['scheme'].'://'.($parts['user'] ? $parts['user'].($parts['pass']?':...':'').'@' : '').
|
||||
$parts['host'].$parts['path'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise our static vars
|
||||
*
|
||||
*/
|
||||
function init_static()
|
||||
{
|
||||
stream_register_wrapper(self::SCHEME ,__CLASS__);
|
||||
|
||||
if (!is_object(self::$old_vfs))
|
||||
{
|
||||
self::$old_vfs =& new vfs_home();
|
||||
self::$old_vfs->override_acl =& egw_vfs::$is_root;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oldvfs_stream_wrapper::init_static();
|
@ -1,459 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare API: VFS - WebDAV access
|
||||
*
|
||||
* Using the PEAR HTTP/WebDAV/Server class (which need to be installed!)
|
||||
*
|
||||
* @link http://www.egroupware.org
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package api
|
||||
* @subpackage vfs
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2006 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once('HTTP/WebDAV/Server.php');
|
||||
require_once(EGW_API_INC.'/class.vfs_home.inc.php');
|
||||
|
||||
/**
|
||||
* FileManger - WebDAV access
|
||||
*
|
||||
* Using the PEAR HTTP/WebDAV/Server class (which need to be installed!)
|
||||
*/
|
||||
class oldvfs_webdav_server extends HTTP_WebDAV_Server
|
||||
{
|
||||
/**
|
||||
* instance of the vfs class
|
||||
*
|
||||
* @var vfs_home
|
||||
*/
|
||||
var $vfs;
|
||||
|
||||
var $dav_powered_by = 'eGroupWare WebDAV server';
|
||||
|
||||
/**
|
||||
* Debug level: 0 = nothing, 1 = function calls, 2 = more info, eg. complete $_SERVER array
|
||||
*
|
||||
* The debug messages are send to the apache error_log
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
var $debug = 0;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
if ($this->debug === 2) foreach($_SERVER as $name => $val) error_log("vfs_webdav_server: \$_SERVER[$name]='$val'");
|
||||
|
||||
parent::HTTP_WebDAV_Server();
|
||||
|
||||
$this->vfs =& new vfs_home;
|
||||
}
|
||||
|
||||
/**
|
||||
* PROPFIND method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @param array return array for file properties
|
||||
* @return bool true on success
|
||||
*/
|
||||
function PROPFIND(&$options, &$files)
|
||||
{
|
||||
$vfs_data = array(
|
||||
'string' => $GLOBALS['egw']->translation->convert($options['path'],'utf-8'),
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
// at first only list the given path itself
|
||||
'checksubdirs' => False,
|
||||
'nofiles' => True
|
||||
);
|
||||
if (!($vfs_files = $this->vfs->ls($vfs_data))) // path not found
|
||||
{
|
||||
// check if the users home-dir is just not yet created (should be done by the vfs-class!)
|
||||
// ToDo: group-dirs
|
||||
if ($vfs_data['string'] == '/home/'.$GLOBALS['egw_info']['user']['account_lid'])
|
||||
{
|
||||
$this->vfs->override_acl = true; // user has no right to create dir in /home
|
||||
$created = $this->vfs->mkdir(array(
|
||||
'string' => $GLOBALS['egw']->translation->convert($options['path'],'utf-8'),
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
));
|
||||
$this->vfs->override_acl = false;
|
||||
|
||||
if (!$created)
|
||||
{
|
||||
if ($this->debug) error_log("vfs_webdav_server::PROPFIND(path='$options[path]',depth=$options[depth]) could not create home dir");
|
||||
}
|
||||
$vfs_files = $this->vfs->ls($vfs_data);
|
||||
}
|
||||
if (!$vfs_files)
|
||||
{
|
||||
if ($this->debug) error_log("vfs_webdav_server::PROPFIND(path='$options[path]',depth=$options[depth]) return false (path not found)");
|
||||
return false; // path not found
|
||||
}
|
||||
}
|
||||
// if depth > 0 and path is a directory => show it's contents
|
||||
if (!empty($options['depth']) && $vfs_files[0]['mime_type'] == 'Directory')
|
||||
{
|
||||
$vfs_data['checksubdirs'] = (int) $options['depth'] != 1;
|
||||
$vfs_data['nofiles'] = false;
|
||||
|
||||
if ($vfs_files[0]['directory'] == '/') // sub-dirs of the root?
|
||||
{
|
||||
$vfs_files = array(); // dont return the directory, it shows up double in konq
|
||||
}
|
||||
else // return the dir itself with a trailing slash, otherwise empty dirs are reported as non-existent
|
||||
{
|
||||
$vfs_files[0]['name'] .= '/';
|
||||
}
|
||||
$vfs_files = array_merge($vfs_files,$this->vfs->ls($vfs_data));
|
||||
}
|
||||
if ($this->debug) error_log("vfs_webdav_server::PROPFIND(path='$options[path]',depth=$options[depth]) ".count($vfs_files).' files');
|
||||
|
||||
$files['files'] = array();
|
||||
$egw_charset = $GLOBALS['egw']->translation->charset();
|
||||
foreach($vfs_files as $fileinfo)
|
||||
{
|
||||
if ($this->debug) error_log('dir="'.$fileinfo['directory'].'", name="'.$fileinfo['name'].'": '.$fileinfo['mime_type']);
|
||||
foreach(array('modified','created') as $date)
|
||||
{
|
||||
// our vfs has no modified set, if never modified, use created
|
||||
list($y,$m,$d,$h,$i,$s) = split("[- :]",$fileinfo[$date] ? $fileinfo[$date] : $fileinfo['created']);
|
||||
$fileinfo[$date] = mktime((int)$h,(int)$i,(int)$s,(int)$m,(int)$d,(int)$y);
|
||||
}
|
||||
$info = array(
|
||||
'path' => $GLOBALS['egw']->translation->convert($fileinfo['directory'].'/'.$fileinfo['name'],$egw_charset,'utf-8'),
|
||||
'props' => array(
|
||||
$this->mkprop('displayname',$GLOBALS['egw']->translation->convert($fileinfo['name'],$egw_charset,'utf-8')),
|
||||
$this->mkprop('creationdate',$fileinfo['created']),
|
||||
$this->mkprop('getlastmodified',$fileinfo['modified']),
|
||||
),
|
||||
);
|
||||
if ($fileinfo['mime_type'] == 'Directory')
|
||||
{
|
||||
$info['props'][] = $this->mkprop('resourcetype', 'collection');
|
||||
$info['props'][] = $this->mkprop('getcontenttype', 'httpd/unix-directory');
|
||||
}
|
||||
else
|
||||
{
|
||||
$info['props'][] = $this->mkprop('resourcetype', '');
|
||||
$info['props'][] = $this->mkprop('getcontenttype', $fileinfo['mime_type']);
|
||||
$info['props'][] = $this->mkprop('getcontentlength', $fileinfo['size']);
|
||||
}
|
||||
$files['files'][] = $info;
|
||||
}
|
||||
if ($this->debug == 2) foreach($files['files'] as $info) error_log(print_r($info,true));
|
||||
// ok, all done
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET method handler
|
||||
*
|
||||
* @param array parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function GET(&$options)
|
||||
{
|
||||
if ($this->debug) error_log('vfs_webdav_server::GET('.print_r($options,true).')');
|
||||
|
||||
$vfs_data = array(
|
||||
'string' => $GLOBALS['egw']->translation->convert($options['path'],'utf-8'),
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
'checksubdirs' => False,
|
||||
'nofiles' => True
|
||||
);
|
||||
// sanity check
|
||||
if (!($vfs_file = $this->vfs->ls($vfs_data)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$options['mimetype'] = $vfs_file[0]['mime_type'];
|
||||
$options['size'] = $vfs_file[0]['size'];
|
||||
|
||||
if (($options['data'] = $this->vfs->read($vfs_data)) === false)
|
||||
{
|
||||
return '403 Forbidden'; // not sure if this is the right code for access denied
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT method handler
|
||||
*
|
||||
* @param array parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function PUT(&$options)
|
||||
{
|
||||
if ($this->debug) error_log('vfs_webdav_server::PUT('.print_r($options,true).')');
|
||||
|
||||
$vfs_data = array(
|
||||
'string' => dirname($GLOBALS['egw']->translation->convert($options['path'],'utf-8')),
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
'checksubdirs' => False,
|
||||
'nofiles' => True
|
||||
);
|
||||
if (!($vfs_file = $this->vfs->ls($vfs_data)) || $vfs_file[0]['mime_type'] != 'Directory')
|
||||
{
|
||||
return '409 Conflict';
|
||||
}
|
||||
$vfs_data = array(
|
||||
'string' => $GLOBALS['egw']->translation->convert($options['path'],'utf-8'),
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
);
|
||||
$options['new'] = !$this->vfs->file_exists($vfs_data);
|
||||
|
||||
$vfs_data['content'] = '';
|
||||
while(!feof($options['stream']))
|
||||
{
|
||||
$vfs_data['content'] .= fread($options['stream'],8192);
|
||||
}
|
||||
return $this->vfs->write($vfs_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* MKCOL method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function MKCOL($options)
|
||||
{
|
||||
if ($this->debug) error_log('vfs_webdav_server::MKCOL('.print_r($options,true).')');
|
||||
|
||||
$vfs_data = array(
|
||||
'string' => dirname($GLOBALS['egw']->translation->convert($options['path'],'utf-8')),
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
'checksubdirs' => False,
|
||||
'nofiles' => True
|
||||
);
|
||||
if (!($vfs_file = $this->vfs->ls($vfs_data)))
|
||||
{
|
||||
return '409 Conflict';
|
||||
}
|
||||
if ($this->debug) error_log(print_r($vfs_file,true));
|
||||
|
||||
if ($vfs_file[0]['mime_type'] != 'Directory')
|
||||
{
|
||||
return '403 Forbidden';
|
||||
}
|
||||
|
||||
$vfs_data = array(
|
||||
'string' => $GLOBALS['egw']->translation->convert($options['path'],'utf-8'),
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
);
|
||||
if ($this->vfs->file_exists($vfs_data) )
|
||||
{
|
||||
return '405 Method not allowed';
|
||||
}
|
||||
|
||||
if (!empty($_SERVER['CONTENT_LENGTH'])) // no body parsing yet
|
||||
{
|
||||
return '415 Unsupported media type';
|
||||
}
|
||||
|
||||
if (!$this->vfs->mkdir($vfs_data))
|
||||
{
|
||||
return '403 Forbidden';
|
||||
}
|
||||
|
||||
return '201 Created';
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function DELETE($options)
|
||||
{
|
||||
if ($this->debug) error_log('vfs_webdav_server::DELETE('.print_r($options,true).')');
|
||||
|
||||
$vfs_data = array(
|
||||
'string' => $GLOBALS['egw']->translation->convert($options['path'],'utf-8'),
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
);
|
||||
if (!$this->vfs->file_exists($vfs_data))
|
||||
{
|
||||
return '404 Not found';
|
||||
}
|
||||
if (!$this->vfs->rm($vfs_data))
|
||||
{
|
||||
return '403 Forbidden';
|
||||
}
|
||||
return '204 No Content';
|
||||
}
|
||||
|
||||
/**
|
||||
* MOVE method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function MOVE($options)
|
||||
{
|
||||
return $this->COPY($options, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* COPY method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function COPY($options, $del=false)
|
||||
{
|
||||
if ($this->debug) error_log('vfs_webdav_server::'.($del ? 'MOVE' : 'COPY').'('.print_r($options,true).')');
|
||||
|
||||
// TODO Property updates still broken (Litmus should detect this?)
|
||||
|
||||
if (!empty($_SERVER['CONTENT_LENGTH'])) // no body parsing yet
|
||||
{
|
||||
return '415 Unsupported media type';
|
||||
}
|
||||
|
||||
// no copying to different WebDAV Servers yet
|
||||
if (isset($options['dest_url']))
|
||||
{
|
||||
return '502 bad gateway';
|
||||
}
|
||||
|
||||
$source = array(
|
||||
'string' => $GLOBALS['egw']->translation->convert($options['path'],'utf-8'),
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
);
|
||||
if (!$this->vfs->file_exists($source))
|
||||
{
|
||||
return '404 Not found';
|
||||
}
|
||||
|
||||
$dest = array(
|
||||
'string' => $options['dest'],
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
);
|
||||
$new = !$this->vfs->file_exists($dest);
|
||||
$existing_col = false;
|
||||
|
||||
if (!$new)
|
||||
{
|
||||
if ($del && $this->vfs->file_type($dest) == 'Directory')
|
||||
{
|
||||
if (!$options['overwrite'])
|
||||
{
|
||||
return '412 precondition failed';
|
||||
}
|
||||
$dest['string'] .= basename($GLOBALS['egw']->translation->convert($options['path'],'utf-8'));
|
||||
if ($this->vfs->file_exists($dest))
|
||||
{
|
||||
$options['dest'] .= basename($GLOBALS['egw']->translation->convert($options['path'],'utf-8'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$new = true;
|
||||
$existing_col = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$new)
|
||||
{
|
||||
if ($options['overwrite'])
|
||||
{
|
||||
$stat = $this->DELETE(array('path' => $options['dest']));
|
||||
if (($stat{0} != '2') && (substr($stat, 0, 3) != '404'))
|
||||
{
|
||||
return $stat;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return '412 precondition failed';
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->vfs->file_type($source) == 'Directory' && ($options['depth'] != 'infinity'))
|
||||
{
|
||||
// RFC 2518 Section 9.2, last paragraph
|
||||
return '400 Bad request';
|
||||
}
|
||||
|
||||
$op = $del ? 'mv' : 'cp';
|
||||
$vfs_data = array(
|
||||
'from' => $source['string'],
|
||||
'to' => $dest['string'],
|
||||
'relatives' => array(RELATIVE_ROOT,RELATIVE_ROOT)
|
||||
);
|
||||
if (!$this->vfs->$op($vfs_data))
|
||||
{
|
||||
return '500 Internal server error';
|
||||
}
|
||||
return ($new && !$existing_col) ? '201 Created' : '204 No Content';
|
||||
}
|
||||
|
||||
/**
|
||||
* PROPPATCH method handler
|
||||
*
|
||||
* The current version only allows Webdrive to set creation and modificaton dates.
|
||||
* They are not stored as (arbitrary) WebDAV properties with their own namespace and name,
|
||||
* but in the regular vfs attributes.
|
||||
*
|
||||
* @todo Store a properties in the DB and retrieve them in PROPFIND again.
|
||||
* @param array general parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function PROPPATCH(&$options)
|
||||
{
|
||||
foreach ($options["props"] as $key => $prop) {
|
||||
$attributes = array();
|
||||
switch($prop['ns'])
|
||||
{
|
||||
// allow Webdrive to set creation and modification time
|
||||
case 'http://www.southrivertech.com/':
|
||||
switch($prop['name'])
|
||||
{
|
||||
case 'srt_modifiedtime':
|
||||
case 'getlastmodified':
|
||||
$attributes['modified'] = strtotime($prop['val']);
|
||||
break;
|
||||
case 'srt_creationtime':
|
||||
$attributes['created'] = strtotime($prop['val']);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'DAV:':
|
||||
switch($prop['name'])
|
||||
{
|
||||
// allow netdrive to change the modification time
|
||||
case 'getlastmodified':
|
||||
$attributes['modified'] = strtotime($prop['val']);
|
||||
break;
|
||||
// not sure why, the filesystem example of the WebDAV class does it ...
|
||||
default:
|
||||
$options["props"][$key]['status'] = "403 Forbidden";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($this->debug) $props[] = '('.$prop["ns"].')'.$prop['name'].'='.$prop['val'];
|
||||
}
|
||||
if ($attributes)
|
||||
{
|
||||
$vfs_data = array(
|
||||
'string' => $GLOBALS['egw']->translation->convert($options['path'],'utf-8'),
|
||||
'relatives' => array(RELATIVE_ROOT), // filename is relative to the vfs-root
|
||||
'attributes'=> $attributes,
|
||||
);
|
||||
$this->vfs->set_attributes($vfs_data);
|
||||
}
|
||||
if ($this->debug)
|
||||
{
|
||||
error_log(__CLASS__.'::'.__METHOD__.": path=$options[path], props=".implode(', ',$props));
|
||||
if ($attributes) error_log(__CLASS__.'::'.__METHOD__.": path=$options[path], set attributes=".str_replace("\n",' ',print_r($attributes,true)));
|
||||
}
|
||||
|
||||
|
||||
return ""; // this is as the filesystem example handler does it, no true or false ...
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,204 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare API: VFS - Homedirectories
|
||||
*
|
||||
* @link http://www.egroupware.org
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package api
|
||||
* @subpackage vfs
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2007 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once(EGW_API_INC.'/class.vfs.inc.php');
|
||||
|
||||
/**
|
||||
* eGroupWare API: VFS - Homedirectories
|
||||
*
|
||||
* This class implements some necessary stuff for user- and group-directories ontop the vfs class.
|
||||
*
|
||||
* Some of it is already implemented in the filemanager app, but it's also needed for the WebDAV access:
|
||||
* - show only directories in /home, to which the user has at least read-access
|
||||
*
|
||||
* Stuff dealing with creation, renaming or deletion of users via some hooks from admin:
|
||||
* - create the homedir if a new user gets created
|
||||
* - rename the homedir if the user-name changes
|
||||
* - delete the homedir or copy its content to an other users homedir, if a user gets deleted
|
||||
* --> these hooks are registered via phpgwapi/setup/setup.inc.php and called by the admin app
|
||||
*/
|
||||
class vfs_home extends vfs
|
||||
{
|
||||
/**
|
||||
* List a directory, reimplemented to hide dirs the user has no rights to read
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $data['string'] path
|
||||
* @param array $data['relatives'] Relativity array (default: RELATIVE_CURRENT)
|
||||
* @param boolean $data['checksubdirs'] If true return information for all subdirectories recursively
|
||||
* @param string $data['mime'] Only return information for locations with MIME type specified (eg. 'Directory')
|
||||
* @param boolean $data['nofiles'] If set and $data['string'] is a directory, return information about the directory, not the files in it.
|
||||
* @return array of arrays of file information.
|
||||
*/
|
||||
function ls($data)
|
||||
{
|
||||
//error_log("vfs_home(".print_r($data,true).")");
|
||||
$fileinfos = parent::ls($data);
|
||||
|
||||
if (!$this->override_acl && !$data['nofiles'] && ($data['string'] == $this->fakebase || $data['string'].$this->fakebase.'/'))
|
||||
{
|
||||
//error_log("vfs_home() grants=".print_r($this->grants,true));
|
||||
|
||||
// remove directories the user has no rights to see, no grant from the owner
|
||||
foreach($fileinfos as $key => $info)
|
||||
{
|
||||
//error_log("vfs_home() ".(!$this->grants[$info['owner_id']] ? 'hidding' : 'showing')." $info[directory]/$info[name] (owner=$info[owner_id])");
|
||||
|
||||
if (!$this->grants[$info['owner_id']])
|
||||
{
|
||||
unset($fileinfos[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $fileinfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called after new accounts have been added
|
||||
*
|
||||
* @param array $data
|
||||
* @param int $data['account_id'] numerical id
|
||||
* @param string $data['account_lid'] account-name
|
||||
*/
|
||||
function addAccount($data)
|
||||
{
|
||||
// create a user-dir
|
||||
$save_id = $this->working_id;
|
||||
$this->working_id = $data['account_id'];
|
||||
$save_currentapp = $GLOBALS['egw_info']['flags']['currentapp'];
|
||||
$GLOBALS['egw_info']['flags']['currentapp'] = 'filemanager';
|
||||
|
||||
$this->override_acl = true;
|
||||
$this->mkdir(array(
|
||||
'string' => $this->fakebase.'/'.$data['account_lid'],
|
||||
'relatives' => array(RELATIVE_ROOT),
|
||||
));
|
||||
$this->override_acl = false;
|
||||
|
||||
$this->working_id = $save_id;
|
||||
$GLOBALS['egw_info']['flags']['currentapp'] = $currentapp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called after accounts has been modified
|
||||
*
|
||||
* @param array $data
|
||||
* @param int $data['account_id'] numerical id
|
||||
* @param string $data['account_lid'] new account-name
|
||||
* @param string $data['old_loginid'] old account-name
|
||||
*/
|
||||
function editAccount($data)
|
||||
{
|
||||
if ($data['account_lid'] == $data['old_loginid']) return; // nothing to do here
|
||||
|
||||
// rename the user-dir
|
||||
$this->override_acl = true;
|
||||
$this->mv(array(
|
||||
'from' => $this->fakebase.'/'.$data['old_loginid'],
|
||||
'to' => $this->fakebase.'/'.$data['account_lid'],
|
||||
'relatives' => array(RELATIVE_ROOT,RELATIVE_ROOT),
|
||||
));
|
||||
$this->override_acl = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called before an account get deleted
|
||||
*
|
||||
* @param array $data
|
||||
* @param int $data['account_id'] numerical id
|
||||
* @param string $data['account_lid'] account-name
|
||||
* @param int $data['new_owner'] account-id of new owner, or false if data should get deleted
|
||||
*/
|
||||
function deleteAccount($data)
|
||||
{
|
||||
if ($data['new_owner'])
|
||||
{
|
||||
// ToDo: copy content of user-dir to new owner's user-dir
|
||||
|
||||
}
|
||||
// delete the user-directory
|
||||
$this->override_acl = true;
|
||||
$this->delete(array(
|
||||
'string' => $this->fakebase.'/'.$data['account_lid'],
|
||||
'relatives' => array(RELATIVE_ROOT),
|
||||
));
|
||||
$this->override_acl = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called after new groups have been added
|
||||
*
|
||||
* @param array $data
|
||||
* @param int $data['account_id'] numerical id
|
||||
* @param string $data['account_name'] group-name
|
||||
*/
|
||||
function addGroup($data)
|
||||
{
|
||||
// create a group-dir
|
||||
$save_id = $this->working_id;
|
||||
$this->working_id = $data['account_id'];
|
||||
$save_currentapp = $GLOBALS['egw_info']['flags']['currentapp'];
|
||||
$GLOBALS['egw_info']['flags']['currentapp'] = 'filemanager';
|
||||
|
||||
$this->override_acl = true;
|
||||
$this->mkdir(array(
|
||||
'string' => $this->fakebase.'/'.$data['account_name'],
|
||||
'relatives' => array(RELATIVE_ROOT),
|
||||
));
|
||||
$this->override_acl = false;
|
||||
|
||||
$this->working_id = $save_id;
|
||||
$GLOBALS['egw_info']['flags']['currentapp'] = $currentapp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called after group has been modified
|
||||
*
|
||||
* @param array $data
|
||||
* @param int $data['account_id'] numerical id
|
||||
* @param string $data['account_name'] new group-name
|
||||
* @param string $data['old_name'] old account-name
|
||||
*/
|
||||
function editGroup($data)
|
||||
{
|
||||
if ($data['account_name'] == $data['old_name']) return; // nothing to do here
|
||||
|
||||
// rename the group-dir
|
||||
$this->override_acl = true;
|
||||
$this->mv(array(
|
||||
'from' => $this->fakebase.'/'.$data['old_name'],
|
||||
'to' => $this->fakebase.'/'.$data['account_name'],
|
||||
'relatives' => array(RELATIVE_ROOT,RELATIVE_ROOT),
|
||||
));
|
||||
$this->override_acl = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called before a group get deleted
|
||||
*
|
||||
* @param array $data
|
||||
* @param int $data['account_id'] numerical id
|
||||
* @param string $data['account_name'] account-name
|
||||
*/
|
||||
function deleteGroup($data)
|
||||
{
|
||||
// delete the group-directory
|
||||
$this->override_acl = true;
|
||||
$this->delete(array(
|
||||
'string' => $this->fakebase.'/'.$data['account_name'],
|
||||
'relatives' => array(RELATIVE_ROOT),
|
||||
));
|
||||
$this->override_acl = false;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user