2008-01-30 07:51:54 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* eGroupWare API: VFS - stream wrapper interface
|
|
|
|
*
|
|
|
|
* @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) 2008 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eGroupWare API: VFS - stream wrapper interface
|
|
|
|
*
|
|
|
|
* The new vfs stream wrapper uses a kind of fstab to mount different filesystems / stream wrapper types
|
|
|
|
* together for eGW's virtual file system.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-03-18 14:17:13 +01:00
|
|
|
* @ToDo extended ACL with inheritance and specific rights for users or groups
|
|
|
|
* Backends can implement them, in which case they get stored independent of the current mount-points.
|
|
|
|
* If the backend does not implement them, they get stored by the VFS under the final URL of the backend,
|
|
|
|
* to also allow mounts to change. The URL's to these extended attributes need to be renamed, when the
|
|
|
|
* file or an underlaying directory get's renamed. That's the task of the backend, if it chooses to
|
|
|
|
* implement extended ACL itself.
|
|
|
|
* @ToDo storage for WebDAV properties
|
|
|
|
* @ToDo implement the necessary function of WebDAV locks
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* @link http://www.php.net/manual/en/function.stream-wrapper-register.php
|
|
|
|
*/
|
|
|
|
class vfs_stream_wrapper implements iface_stream_wrapper
|
|
|
|
{
|
2008-02-07 07:37:45 +01:00
|
|
|
/**
|
2008-02-18 07:43:49 +01:00
|
|
|
* Scheme / protocol used for this stream-wrapper
|
2008-02-07 07:37:45 +01:00
|
|
|
*/
|
|
|
|
const SCHEME = 'vfs';
|
2008-02-18 07:43:49 +01:00
|
|
|
/**
|
|
|
|
* Mime type of directories, the old vfs used 'Directory', while eg. WebDAV uses 'httpd/unix-directory'
|
|
|
|
*/
|
|
|
|
const DIR_MIME_TYPE = 'httpd/unix-directory';
|
2008-04-14 07:52:24 +02:00
|
|
|
/**
|
|
|
|
* Should unreadable entries in a not writable directory be hidden, default yes
|
|
|
|
*/
|
|
|
|
const HIDE_UNREADABLES = true;
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
/**
|
|
|
|
* optional context param when opening the stream, null if no context passed
|
|
|
|
*
|
|
|
|
* @var mixed
|
|
|
|
*/
|
|
|
|
var $context;
|
2009-03-19 21:12:35 +01:00
|
|
|
/**
|
|
|
|
* mode-bits, which have to be set for links
|
|
|
|
*/
|
|
|
|
const MODE_LINK = 0120000;
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
/**
|
|
|
|
* Our fstab in the form mount-point => url
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* The entry for root has to be the first, or more general if you mount into subdirs the parent has to be before!
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2008-02-07 07:37:45 +01:00
|
|
|
protected static $fstab = array(
|
2008-04-19 11:46:58 +02:00
|
|
|
'/' => 'sqlfs://$host/',
|
|
|
|
'/apps' => 'links://$host/apps',
|
2008-01-30 07:51:54 +01:00
|
|
|
);
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
/**
|
|
|
|
* stream / ressouce this class is opened for by stream_open
|
|
|
|
*
|
|
|
|
* @var ressource
|
|
|
|
*/
|
|
|
|
private $opened_stream;
|
|
|
|
/**
|
|
|
|
* directory-ressouce this class is opened for by dir_open
|
|
|
|
*
|
|
|
|
* @var ressource
|
|
|
|
*/
|
|
|
|
private $opened_dir;
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
/**
|
|
|
|
* URL of the opened dir, used to build the complete URL of files in the dir
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $opened_dir_url;
|
|
|
|
/**
|
|
|
|
* Flag if opened dir is writable, in which case we return un-readable entries too
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
private $opened_dir_writable;
|
2008-01-30 07:51:54 +01:00
|
|
|
/**
|
|
|
|
* Extra dirs from our fstab in the current opened dir
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $extra_dirs;
|
|
|
|
/**
|
|
|
|
* Pointer in the extra dirs
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
private $extra_dir_ptr;
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
private static $wrappers;
|
|
|
|
|
2009-03-19 21:12:35 +01:00
|
|
|
/**
|
|
|
|
* Resolve the given path according to our fstab AND symlinks
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param boolean $file_exists=true true if file needs to exists, false if not
|
|
|
|
* @return string|boolean false if the url cant be resolved, should not happen if fstab has a root entry
|
|
|
|
*/
|
|
|
|
static function resolve_url_symlinks($path,$file_exists=true,$resolve_last_symlink=true)
|
|
|
|
{
|
|
|
|
if (!($stat = self::url_stat($path,$resolve_last_symlink?0:STREAM_URL_STAT_LINK)) && !$file_exists)
|
|
|
|
{
|
|
|
|
$ret = self::check_symlink_components($path,0,$url);
|
|
|
|
//error_log(__METHOD__."('$path',$file_exists) check_symlink_components()=$ret, url='$url'");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$url = $stat['url'];
|
|
|
|
}
|
|
|
|
//error_log(__METHOD__."($path,file_exists=$file_exists,resolve_last_symlink=$resolve_last_symlink) = '$url'");
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
/**
|
|
|
|
* Resolve the given path according to our fstab
|
|
|
|
*
|
|
|
|
* @param string $path
|
2009-03-19 21:12:35 +01:00
|
|
|
* @return string|boolean false if the url cant be resolved, should not happen if fstab has a root entry
|
2008-01-30 07:51:54 +01:00
|
|
|
*/
|
|
|
|
static function resolve_url($path)
|
|
|
|
{
|
|
|
|
static $cache = array();
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
// we do some caching here
|
|
|
|
if (isset($cache[$path]))
|
|
|
|
{
|
|
|
|
return $cache[$path];
|
|
|
|
}
|
2008-02-18 07:43:49 +01:00
|
|
|
// setting default user, passwd and domain, if it's not contained int the url
|
|
|
|
static $defaults;
|
|
|
|
if (is_null($defaults))
|
|
|
|
{
|
|
|
|
$defaults = array(
|
|
|
|
'user' => $GLOBALS['egw_info']['user']['account_lid'],
|
|
|
|
'pass' => $GLOBALS['egw_info']['user']['passwd'],
|
|
|
|
'host' => $GLOBALS['egw_info']['user']['domain'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$parts = array_merge(parse_url($path),$defaults);
|
2008-10-14 16:57:35 +02:00
|
|
|
if (!$parts['host']) $parts['host'] = 'default'; // otherwise we get an invalid url (scheme:///path/to/something)!
|
2008-01-30 07:51:54 +01:00
|
|
|
|
2008-04-14 07:52:24 +02:00
|
|
|
if (!empty($parts['scheme']) && $parts['scheme'] != self::SCHEME)
|
|
|
|
{
|
|
|
|
return $path; // path is already a non-vfs url --> nothing to do
|
|
|
|
}
|
2008-01-30 07:51:54 +01:00
|
|
|
if (empty($parts['path'])) $parts['path'] = '/';
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
foreach(array_reverse(self::$fstab) as $mounted => $url)
|
|
|
|
{
|
2008-04-14 07:52:24 +02:00
|
|
|
if ($mounted == '/' || $mounted == $parts['path'] || $mounted.'/' == substr($parts['path'],0,strlen($mounted)+1))
|
2008-01-30 07:51:54 +01:00
|
|
|
{
|
|
|
|
$scheme = parse_url($url,PHP_URL_SCHEME);
|
|
|
|
if (is_null(self::$wrappers) || !in_array($scheme,self::$wrappers))
|
|
|
|
{
|
|
|
|
self::load_wrapper($scheme);
|
|
|
|
}
|
2008-09-30 13:52:56 +02:00
|
|
|
$url = egw_vfs::concat($url,substr($parts['path'],strlen($mounted)));
|
2008-01-30 07:51:54 +01:00
|
|
|
|
|
|
|
$url = str_replace(array('$user','$pass','$host'),array($parts['user'],$parts['pass'],$parts['host']),$url);
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-04-14 07:52:24 +02:00
|
|
|
if ($parts['query']) $url .= '?'.$parts['query'];
|
|
|
|
if ($parts['fragment']) $url .= '#'.$parts['fragment'];
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
//error_log(__METHOD__."($path) = $url");
|
|
|
|
return $cache[$path] = $url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//error_log(__METHOD__."($path) can't resolve path!\n");
|
|
|
|
trigger_error(__METHOD__."($path) can't resolve path!\n",E_USER_WARNING);
|
|
|
|
return false;
|
|
|
|
}
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
/**
|
|
|
|
* This method is called immediately after your stream object is created.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* @param string $path 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()
|
2008-04-19 11:46:58 +02:00
|
|
|
* @param int $options additional flags set by the streams API (or'ed together):
|
2008-01-30 07:51:54 +01:00
|
|
|
* - STREAM_USE_PATH If path is relative, search for the resource using the include_path.
|
2008-04-19 11:46:58 +02:00
|
|
|
* - STREAM_REPORT_ERRORS If this flag is set, you are responsible for raising errors using trigger_error() during opening of the stream.
|
2008-01-30 07:51:54 +01:00
|
|
|
* 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 ( $path, $mode, $options, &$opened_path )
|
|
|
|
{
|
|
|
|
$this->opened_stream = null;
|
|
|
|
|
2009-03-19 21:12:35 +01:00
|
|
|
if (!($url = self::resolve_url_symlinks($path,$mode[0]=='r')))
|
2008-01-30 07:51:54 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!($this->opened_stream = fopen($url,$mode,$options)))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
/**
|
2008-04-19 11:46:58 +02:00
|
|
|
* This method is called when the stream is closed, using fclose().
|
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* You must release any resources that were locked or allocated by the stream.
|
|
|
|
*/
|
|
|
|
function stream_close ( )
|
|
|
|
{
|
|
|
|
$ret = fclose($this->opened_stream);
|
|
|
|
|
|
|
|
$this->opened_stream = null;
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
return $ret;
|
|
|
|
}
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
/**
|
|
|
|
* This method is called in response to fread() and fgets() calls on the stream.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2008-01-30 07:51:54 +01:00
|
|
|
* 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 )
|
|
|
|
{
|
|
|
|
return fread($this->opened_stream,$count);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called in response to fwrite() calls on the stream.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2008-01-30 07:51:54 +01:00
|
|
|
* 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 )
|
|
|
|
{
|
|
|
|
return fwrite($this->opened_stream,$data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called in response to feof() calls on the stream.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* Important: PHP 5.0 introduced a bug that wasn't fixed until 5.1: the return value has to be the oposite!
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* if(version_compare(PHP_VERSION,'5.0','>=') && version_compare(PHP_VERSION,'5.1','<'))
|
|
|
|
* {
|
|
|
|
* $eof = !$eof;
|
|
|
|
* }
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* @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 ( )
|
|
|
|
{
|
|
|
|
return feof($this->opened_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called in response to ftell() calls on the stream.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* @return integer current read/write position of the stream
|
|
|
|
*/
|
|
|
|
function stream_tell ( )
|
|
|
|
{
|
|
|
|
return ftell($this->opened_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called in response to fseek() calls on the stream.
|
|
|
|
*
|
2008-04-19 11:46:58 +02:00
|
|
|
* You should update the read/write position of the stream according to offset and whence.
|
|
|
|
* See fseek() for more information about these parameters.
|
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* @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 )
|
|
|
|
{
|
|
|
|
return fseek($this->opened_stream,$offset,$whence);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called in response to fflush() calls on the stream.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* If you have cached data in your stream but not yet stored it into the underlying storage, you should do so now.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* @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 ( )
|
|
|
|
{
|
|
|
|
return fflush($this->opened_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called in response to fstat() calls on the stream.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
|
|
|
* If you plan to use your wrapper in a require_once you need to define stream_stat().
|
2008-01-30 07:51:54 +01:00
|
|
|
* If you plan to allow any other tests like is_file()/is_dir(), you have to define url_stat().
|
2008-04-19 11:46:58 +02:00
|
|
|
* stream_stat() must define the size of the file, or it will never be included.
|
2008-01-30 07:51:54 +01:00
|
|
|
* url_stat() must define mode, or is_file()/is_dir()/is_executable(), and any of those functions affected by clearstatcache() simply won't work.
|
2008-04-19 11:46:58 +02:00
|
|
|
* 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.
|
2008-01-30 07:51:54 +01:00
|
|
|
*
|
|
|
|
* @return array containing the same values as appropriate for the stream.
|
|
|
|
*/
|
|
|
|
function stream_stat ( )
|
|
|
|
{
|
|
|
|
return fstat($this->opened_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called in response to unlink() calls on URL paths associated with the wrapper.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* 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 $path
|
|
|
|
* @return boolean TRUE on success or FALSE on failure
|
|
|
|
*/
|
|
|
|
static function unlink ( $path )
|
|
|
|
{
|
2009-03-19 21:12:35 +01:00
|
|
|
if (!($url = self::resolve_url_symlinks($path,true,false))) // true,false file need to exist, but do not resolve last component
|
2008-01-30 07:51:54 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return unlink($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called in response to rename() calls on URL paths associated with the wrapper.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
|
|
|
* It should attempt to rename the item specified by path_from to the specification given by path_to.
|
2008-01-30 07:51:54 +01:00
|
|
|
* 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 $path_from
|
|
|
|
* @param string $path_to
|
|
|
|
* @return boolean TRUE on success or FALSE on failure
|
|
|
|
*/
|
|
|
|
static function rename ( $path_from, $path_to )
|
|
|
|
{
|
2009-03-19 21:12:35 +01:00
|
|
|
if (!($url_from = self::resolve_url_symlinks($path_from,true,false)) ||
|
|
|
|
!($url_to = self::resolve_url_symlinks($path_to,false)))
|
2008-01-30 07:51:54 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return rename($url_from,$url_to);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called in response to mkdir() calls on URL paths associated with the wrapper.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2008-01-30 07:51:54 +01:00
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @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 ( $path, $mode, $options )
|
|
|
|
{
|
2009-03-19 21:12:35 +01:00
|
|
|
if (!($url = self::resolve_url_symlinks($path,false))) // false = directory does not need to exists
|
2008-01-30 07:51:54 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-02-18 07:43:49 +01:00
|
|
|
return mkdir($url,$mode,$options);
|
2008-01-30 07:51:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called in response to rmdir() calls on URL paths associated with the wrapper.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
|
|
|
* It should attempt to remove the directory specified by path.
|
2008-01-30 07:51:54 +01:00
|
|
|
* 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 $path
|
|
|
|
* @param int $options Possible values include STREAM_REPORT_ERRORS.
|
|
|
|
* @return boolean TRUE on success or FALSE on failure.
|
|
|
|
*/
|
|
|
|
static function rmdir ( $path, $options )
|
|
|
|
{
|
2009-03-19 21:12:35 +01:00
|
|
|
if (!($url = self::resolve_url_symlinks($path)))
|
2008-01-30 07:51:54 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-02-18 07:43:49 +01:00
|
|
|
return rmdir($url);
|
2008-01-30 07:51:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
* Allow to call methods of the underlying stream wrapper: touch, chmod, chgrp, chown, ...
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
* We cant use a magic __call() method, as it does not work for static methods!
|
2008-01-30 07:51:54 +01:00
|
|
|
*
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
* @param string $name
|
|
|
|
* @param array $params first param has to be the path, otherwise we can not determine the correct wrapper
|
2008-04-19 11:46:58 +02:00
|
|
|
* @param boolean $fail_silent=false should only false be returned if function is not supported by the backend,
|
2008-04-14 07:52:24 +02:00
|
|
|
* or should an E_USER_WARNING error be triggered (default)
|
2009-03-19 21:12:35 +01:00
|
|
|
* @param int $path_param_key=0 key in params containing the path, default 0
|
2008-04-14 07:52:24 +02:00
|
|
|
* @return mixed return value of backend or false if function does not exist on backend
|
2008-01-30 07:51:54 +01:00
|
|
|
*/
|
2009-03-19 21:12:35 +01:00
|
|
|
static protected function _call_on_backend($name,$params,$fail_silent=false,$path_param_key=0)
|
2008-01-30 07:51:54 +01:00
|
|
|
{
|
2009-03-19 21:12:35 +01:00
|
|
|
$pathes = $params[$path_param_key];
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-10-05 19:07:36 +02:00
|
|
|
$scheme2urls = array();
|
|
|
|
foreach(is_array($pathes) ? $pathes : array($pathes) as $path)
|
|
|
|
{
|
2009-03-19 21:12:35 +01:00
|
|
|
if (!($url = self::resolve_url_symlinks($path,false,false)))
|
2008-10-05 19:07:36 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$scheme2urls[(string)parse_url($url,PHP_URL_SCHEME)][] = $url;
|
|
|
|
}
|
|
|
|
$ret = array();
|
|
|
|
foreach($scheme2urls as $scheme => $urls)
|
|
|
|
{
|
|
|
|
if ($scheme)
|
|
|
|
{
|
|
|
|
if (!class_exists($class = $scheme.'_stream_wrapper') || !method_exists($class,$name))
|
|
|
|
{
|
|
|
|
if (!$fail_silent) trigger_error("Can't $name for scheme $scheme!\n",E_USER_WARNING);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!is_array($pathes))
|
|
|
|
{
|
2009-03-19 21:12:35 +01:00
|
|
|
$params[$path_param_key] = $url;
|
2008-10-05 19:07:36 +02:00
|
|
|
|
|
|
|
return call_user_func_array(array($scheme.'_stream_wrapper',$name),$params);
|
|
|
|
}
|
2009-03-19 21:12:35 +01:00
|
|
|
$params[$path_param_key] = $urls;
|
2008-10-05 19:07:36 +02:00
|
|
|
if (!is_array($r = call_user_func_array(array($scheme.'_stream_wrapper',$name),$params)))
|
|
|
|
{
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
$ret += $r;
|
|
|
|
}
|
|
|
|
// call the filesystem specific function (dont allow to use arrays!)
|
|
|
|
elseif(!function_exists($name) || is_array($pathes))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $name($url,$time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is not (yet) a stream-wrapper function, but it's necessary and can be used static
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @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!
|
|
|
|
* @return boolean true on success, false otherwise
|
|
|
|
*/
|
|
|
|
static function touch($path,$time=null,$atime=null)
|
|
|
|
{
|
|
|
|
return self::_call_on_backend('touch',array($path,$time,$atime));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is not (yet) a stream-wrapper function, but it's necessary and can be used static
|
|
|
|
*
|
|
|
|
* Requires owner or root rights!
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param string $mode mode string see egw_vfs::mode2int
|
|
|
|
* @return boolean true on success, false otherwise
|
|
|
|
*/
|
|
|
|
static function chmod($path,$mode)
|
|
|
|
{
|
|
|
|
return self::_call_on_backend('chmod',array($path,$mode));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is not (yet) a stream-wrapper function, but it's necessary and can be used static
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
* Requires root rights!
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param int $owner numeric user id
|
|
|
|
* @return boolean true on success, false otherwise
|
|
|
|
*/
|
|
|
|
static function chown($path,$owner)
|
|
|
|
{
|
|
|
|
return self::_call_on_backend('chown',array($path,$owner));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is not (yet) a stream-wrapper function, but it's necessary and can be used static
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
* Requires owner or root rights!
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param int $group numeric group id
|
|
|
|
* @return boolean true on success, false otherwise
|
|
|
|
*/
|
|
|
|
static function chgrp($path,$group)
|
|
|
|
{
|
|
|
|
return self::_call_on_backend('chgrp',array($path,$group));
|
2008-01-30 07:51:54 +01:00
|
|
|
}
|
|
|
|
|
2009-03-19 21:12:35 +01:00
|
|
|
/**
|
|
|
|
* Returns the target of a symbolic link
|
|
|
|
*
|
|
|
|
* This is not (yet) a stream-wrapper function, but it's necessary and can be used static
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @return string|boolean link-data or false if no link
|
|
|
|
*/
|
|
|
|
static function readlink($path)
|
|
|
|
{
|
|
|
|
return self::_call_on_backend('readlink',array($path));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a symbolic link
|
|
|
|
*
|
|
|
|
* This is not (yet) a stream-wrapper function, but it's necessary and can be used static
|
|
|
|
*
|
|
|
|
* @param string $target target of the link
|
|
|
|
* @param string $link path of the link to create
|
|
|
|
* @return boolean true on success, false on error
|
|
|
|
*/
|
|
|
|
static function symlink($target,$link)
|
|
|
|
{
|
|
|
|
return self::_call_on_backend('symlink',array($target,$link),false,1); // 1=path is in $link!
|
|
|
|
}
|
|
|
|
|
2008-02-18 07:43:49 +01:00
|
|
|
/**
|
|
|
|
* This is not (yet) a stream-wrapper function, but it's necessary and can be used static
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-02-18 07:43:49 +01:00
|
|
|
* The methods use the following ways to get the mime type (in that order)
|
|
|
|
* - directories (is_dir()) --> self::DIR_MIME_TYPE
|
|
|
|
* - stream implemented by class defining the STAT_RETURN_MIME_TYPE constant --> use mime-type returned by url_stat
|
|
|
|
* - for regular filesystem use mime_content_type function if available
|
|
|
|
* - use eGW's mime-magic class
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @return string mime-type (self::DIR_MIME_TYPE for directories)
|
|
|
|
*/
|
|
|
|
static function mime_content_type($path)
|
|
|
|
{
|
2009-03-19 21:12:35 +01:00
|
|
|
if (!($url = self::resolve_url_symlinks($path)))
|
2008-02-18 07:43:49 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (is_dir($url))
|
|
|
|
{
|
|
|
|
$mime = self::DIR_MIME_TYPE;
|
|
|
|
}
|
|
|
|
if (!$mime && ($scheme = parse_url($url,PHP_URL_SCHEME)))
|
|
|
|
{
|
|
|
|
// check it it's an eGW stream wrapper returning mime-type via url_stat
|
2008-09-30 13:52:56 +02:00
|
|
|
if (class_exists($class = $scheme.'_stream_wrapper') && ($mime_attr = @constant($class.'::STAT_RETURN_MIME_TYPE')))
|
2008-02-18 07:43:49 +01:00
|
|
|
{
|
|
|
|
$stat = call_user_func(array($scheme.'_stream_wrapper','url_stat'),parse_url($url,PHP_URL_PATH),0);
|
|
|
|
if ($stat[$mime_attr])
|
|
|
|
{
|
|
|
|
$mime = $stat[$mime_attr];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if we operate on the regular filesystem and the mime_content_type function is available --> use it
|
|
|
|
if (!$mime && !$scheme && function_exists('mime_content_type'))
|
|
|
|
{
|
|
|
|
$mime = mime_content_type($path);
|
|
|
|
}
|
|
|
|
// using eGW's own mime magic
|
|
|
|
// ToDo: rework mime_magic as all methods cound be static!
|
|
|
|
if (!$mime)
|
|
|
|
{
|
|
|
|
static $mime_magic;
|
|
|
|
if (is_null($mime_magic))
|
|
|
|
{
|
2008-03-02 22:44:15 +01:00
|
|
|
$mime_magic = new mime_magic();
|
2008-02-18 07:43:49 +01:00
|
|
|
}
|
|
|
|
$mime = $mime_magic->filename2mime(parse_url($url,PHP_URL_PATH));
|
|
|
|
}
|
|
|
|
//error_log(__METHOD__."($path) mime=$mime");
|
|
|
|
return $mime;
|
|
|
|
}
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
/**
|
2008-04-19 11:46:58 +02:00
|
|
|
* This method is called immediately when your stream object is created for examining directory contents with opendir().
|
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* @param string $path URL that was passed to opendir() and that this object is expected to explore.
|
2008-04-19 11:46:58 +02:00
|
|
|
* @return booelan
|
2008-01-30 07:51:54 +01:00
|
|
|
*/
|
|
|
|
function dir_opendir ( $path, $options )
|
|
|
|
{
|
2009-01-29 19:58:52 +01:00
|
|
|
//error_log(__METHOD__." called with ".$path);
|
2008-01-30 07:51:54 +01:00
|
|
|
$this->opened_dir = $this->extra_dirs = null;
|
|
|
|
$this->extra_dir_ptr = 0;
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2009-03-19 21:12:35 +01:00
|
|
|
if (!($this->opened_dir_url = self::resolve_url_symlinks($path)))
|
2008-01-30 07:51:54 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-03-19 21:12:35 +01:00
|
|
|
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
if (!($this->opened_dir = opendir($this->opened_dir_url)))
|
2008-01-30 07:51:54 +01:00
|
|
|
{
|
2009-01-29 19:58:52 +01:00
|
|
|
//error_log(__METHOD__." dir failed: ".$this->opened_dir);
|
2008-01-30 07:51:54 +01:00
|
|
|
return false;
|
|
|
|
}
|
2008-04-14 07:52:24 +02:00
|
|
|
$this->opened_dir_writable = egw_vfs::check_access($this->opened_dir_url,egw_vfs::WRITABLE);
|
2009-01-29 19:58:52 +01:00
|
|
|
#error_log(__METHOD__." check for ".$this->opened_dir_url);
|
2008-01-30 07:51:54 +01:00
|
|
|
// check our fstab if we need to add some of the mountpoints
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
$basepath = parse_url($this->opened_dir_url,PHP_URL_PATH);
|
2009-01-29 19:58:52 +01:00
|
|
|
#error_log(__METHOD__." basepath here: ".print_r($basepath,true));
|
2008-01-30 07:51:54 +01:00
|
|
|
foreach(self::$fstab as $mounted => $nul)
|
|
|
|
{
|
2009-01-29 19:58:52 +01:00
|
|
|
#error_log(__METHOD__." dirname mounted: ".print_r(dirname($mounted),true));
|
|
|
|
if ((dirname($mounted) == $basepath || dirname($mounted)."/" == $basepath) && $mounted != '/')
|
2008-01-30 07:51:54 +01:00
|
|
|
{
|
2009-01-29 19:58:52 +01:00
|
|
|
#error_log(__METHOD__." mounted dir: ".print_r($mounted,true));
|
2008-01-30 07:51:54 +01:00
|
|
|
$this->extra_dirs[] = basename($mounted);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called in response to stat() calls on the URL paths associated with the wrapper.
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
|
|
|
* It should return as many elements in common with the system function as possible.
|
2008-01-30 07:51:54 +01:00
|
|
|
* Unknown or unavailable values should be set to a rational value (usually 0).
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
|
|
|
* If you plan to use your wrapper in a require_once you need to define stream_stat().
|
2008-01-30 07:51:54 +01:00
|
|
|
* If you plan to allow any other tests like is_file()/is_dir(), you have to define url_stat().
|
2008-04-19 11:46:58 +02:00
|
|
|
* stream_stat() must define the size of the file, or it will never be included.
|
2008-01-30 07:51:54 +01:00
|
|
|
* url_stat() must define mode, or is_file()/is_dir()/is_executable(), and any of those functions affected by clearstatcache() simply won't work.
|
2008-04-19 11:46:58 +02:00
|
|
|
* 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.
|
2008-01-30 07:51:54 +01:00
|
|
|
*
|
|
|
|
* @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:
|
2008-04-19 11:46:58 +02:00
|
|
|
* - 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.
|
2008-01-30 07:51:54 +01:00
|
|
|
* This flag is set in response to calls to lstat(), is_link(), or filetype().
|
2008-04-19 11:46:58 +02:00
|
|
|
* - STREAM_URL_STAT_QUIET If this flag is set, your wrapper should not raise any errors. If this flag is not set,
|
2008-01-30 07:51:54 +01:00
|
|
|
* 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!
|
2009-03-19 21:12:35 +01:00
|
|
|
* @param boolean $try_create_home=true should a user home-directory be created automatic, if it does not exist
|
|
|
|
* @param boolean $check_symlink_components=true check if path contains symlinks in path components other then the last one
|
2008-04-19 11:46:58 +02:00
|
|
|
* @return array
|
2008-01-30 07:51:54 +01:00
|
|
|
*/
|
2009-03-19 21:12:35 +01:00
|
|
|
static function url_stat ( $path, $flags, $try_create_home=true, $check_symlink_components=true )
|
2008-01-30 07:51:54 +01:00
|
|
|
{
|
|
|
|
//error_log(__METHOD__."('$path',$flags)");
|
|
|
|
|
|
|
|
if (!($url = self::resolve_url($path)))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
//error_log(__METHOD__."('$path',$flags) calling stat($url)");
|
2009-03-19 21:12:35 +01:00
|
|
|
if ($flags & STREAM_URL_STAT_LINK)
|
|
|
|
{
|
|
|
|
$stat = @lstat($url); // suppressed the stat failed warnings
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$stat = @stat($url); // suppressed the stat failed warnings
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2009-03-19 21:12:35 +01:00
|
|
|
if ($stat && ($stat['mode'] & self::MODE_LINK) && ($l=$lpath = self::readlink($url)))
|
|
|
|
{
|
|
|
|
if ($lpath[0] != '/') // contact releative path
|
|
|
|
{
|
|
|
|
$url = egw_vfs::concat($url,'../'.$lpath);
|
|
|
|
}
|
|
|
|
else // or replace absolute path in url
|
|
|
|
{
|
|
|
|
$url_parts = parse_url($url);
|
|
|
|
$url_parts['path'] = $lpath;
|
|
|
|
$url = egw_vfs::build_url($url_parts);
|
|
|
|
}
|
|
|
|
//error_log(__METHOD__."($path,$flags) symlink found and resolved to $url");
|
|
|
|
$stat = @stat($url);
|
|
|
|
}
|
|
|
|
}
|
2008-04-19 11:46:58 +02:00
|
|
|
// check if a failed url_stat was for a home dir, in that case silently create it
|
|
|
|
if (!$stat && dirname(parse_url($path,PHP_URL_PATH)) == '/home' && ($id = $GLOBALS['egw']->accounts->name2id(basename($path))))
|
|
|
|
{
|
|
|
|
$hook_data = array(
|
|
|
|
'location' => $GLOBALS['egw']->accounts->get_type($id) == 'g' ? 'addgroup' : 'addaccount',
|
|
|
|
'account_id' => $id,
|
|
|
|
'account_lid' => basename($path),
|
|
|
|
'account_name' => basename($path),
|
|
|
|
);
|
|
|
|
call_user_func(array('vfs_home_hooks',$hook_data['location']),$hook_data);
|
2009-03-19 21:12:35 +01:00
|
|
|
$stat = self::url_stat($path,$flags,false);
|
|
|
|
}
|
|
|
|
if (!$stat && $check_symlink_components) // check if there's a symlink somewhere inbetween the path
|
|
|
|
{
|
|
|
|
$stat = self::check_symlink_components($path,$flags,$urlx=$url);
|
|
|
|
}
|
|
|
|
elseif(is_array($stat) && !isset($stat['url']))
|
|
|
|
{
|
|
|
|
$stat['url'] = $url;
|
2008-04-19 11:46:58 +02:00
|
|
|
}
|
|
|
|
return $stat;
|
2008-04-14 07:52:24 +02:00
|
|
|
|
|
|
|
// Todo: if we hide non readables, we should return false on url_stat for consitency (if dir is not writabel)
|
|
|
|
// Problem: this does NOT stop (calles itself infinit recursive)!
|
|
|
|
if (self::HIDE_UNREADABLES && !egw_vfs::check_access($path,egw_vfs::READABLE,$stat) &&
|
|
|
|
!egw_vfs::check_access(dirname($path,egw_vfs::WRITABLE)))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return $stat;
|
2008-01-30 07:51:54 +01:00
|
|
|
}
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2009-03-19 21:12:35 +01:00
|
|
|
/**
|
|
|
|
* Check if path (which fails the stat call) contains symlinks in path-components other then the last one
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param int $flags=0 see url_stat
|
|
|
|
* @param string &$url=null already resolved path
|
|
|
|
* @return array|boolean stat array or false if not found
|
|
|
|
*/
|
|
|
|
static private function check_symlink_components($path,$flags=0,&$url=null)
|
|
|
|
{
|
|
|
|
if (is_null($url) && !($url = self::resolve_url($path)))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//echo "<p>".__METHOD__."('$path',$flags,'$url'): ".function_backtrace(1)."</p>\n";
|
|
|
|
while (($rel_path = egw_vfs::basename($url).($rel_path ? '/'.$rel_path : '')) &&
|
|
|
|
($url = egw_vfs::dirname($url)))
|
|
|
|
{
|
|
|
|
$stat = self::url_stat($url,0,false,false);
|
|
|
|
//echo "<p>rel_path='$rel_path', stat(url='$url')=".array2string($stat)."</p>\n";
|
|
|
|
if (($stat = self::url_stat($url,0,false,false)))
|
|
|
|
{
|
|
|
|
if (is_link($url) && ($lpath = self::readlink($url)))
|
|
|
|
{
|
|
|
|
//echo "<p>rel_path='$rel_path', url='$url': lpath='$lpath'\n";
|
|
|
|
if ($lpath[0] != '/')
|
|
|
|
{
|
|
|
|
$url = egw_vfs::concat($url,'../'.$lpath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$url_parts = parse_url($url);
|
|
|
|
$url_parts['path'] = $lpath;
|
|
|
|
$url = egw_vfs::build_url($url_parts);
|
|
|
|
}
|
|
|
|
$url = egw_vfs::concat($url,$rel_path);
|
|
|
|
//echo "--> <b>url='$url'</b></p>\n";
|
|
|
|
return self::url_stat($url,$flags);
|
|
|
|
}
|
|
|
|
$url = egw_vfs::concat($url,$rel_path);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false; // $path does not exist
|
|
|
|
}
|
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
/**
|
|
|
|
* This method is called in response to readdir().
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* It should return a string representing the next filename in the location opened by dir_opendir().
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
* Unless other filesystem, we only return files readable by the user, if the dir is not writable for him.
|
|
|
|
* This is done to hide files and dirs not accessible by the user (eg. other peoples home-dirs in /home).
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function dir_readdir ( )
|
|
|
|
{
|
2009-01-29 19:58:52 +01:00
|
|
|
#error_log(__METHOD__." called.");
|
2008-01-30 07:51:54 +01:00
|
|
|
if ($this->extra_dirs && count($this->extra_dirs) > $this->extra_dir_ptr)
|
|
|
|
{
|
|
|
|
return $this->extra_dirs[$this->extra_dir_ptr++];
|
|
|
|
}
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
// only return children readable by the user, if dir is not writable
|
|
|
|
do {
|
2009-01-29 19:58:52 +01:00
|
|
|
//error_log(__METHOD__." called with:".$this->opened_dir_url);
|
2008-04-14 07:52:24 +02:00
|
|
|
$file = readdir($this->opened_dir);
|
2009-01-29 19:58:52 +01:00
|
|
|
//error_log(__METHOD__." got:".$file);
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
}
|
2008-05-10 23:47:16 +02:00
|
|
|
while($file !== false && (is_array($this->extra_dirs) && in_array($file,$this->extra_dirs) || // dont return mountpoints twice
|
|
|
|
self::HIDE_UNREADABLES && !$this->opened_dir_writable &&
|
|
|
|
!egw_vfs::check_access(egw_vfs::concat($this->opened_dir_url,$file),egw_vfs::READABLE)));
|
2008-04-19 11:46:58 +02:00
|
|
|
|
More improvments of the sqlfs code and the command line interface:
- read rights are not checks in each traversed directory (via sql in a single query to locate the path)
- diropen additionally checks for execute rights
- fopen checks for read or write depending on the mode
- chmod, chgrp, chown methods in sqlfs and egw_vfs/vfs plus an egw_vfs::$is_root var used to grant root rights (no access controll and chown or chgrp without being the owner of a file)
- find method (some more params to come) to recursivly search and optionaly execute some callback
- egw_vfs::remove doing a "rm -r" / recursive remove or dirs and files
- new files or dirs inherit the perms and ownership from the parent directory (no umask)
- files/dirs the user has no read rights, in a directory where he has no write rights, get hidden (eg. not showing all the other users / groups home dirs
- many new cli commands (chmod, chgrp, chown, find), recursive option for most commands and the ability to use it with root rights, see the usage message if called without options
- "cp -r -p" to copy a whole tree incl. ownership and perms, eg. backing up /home to /backup
2008-02-26 09:51:42 +01:00
|
|
|
return $file;
|
2008-01-30 07:51:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called in response to rewinddir().
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
|
|
|
* It should reset the output generated by dir_readdir(). i.e.:
|
2008-01-30 07:51:54 +01:00
|
|
|
* The next call to dir_readdir() should return the first entry in the location returned by dir_opendir().
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function dir_rewinddir ( )
|
|
|
|
{
|
|
|
|
$this->extra_dir_ptr = 0;
|
|
|
|
|
|
|
|
return rewinddir($this->opened_dir);
|
|
|
|
}
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
/**
|
|
|
|
* This method is called in response to closedir().
|
2008-04-19 11:46:58 +02:00
|
|
|
*
|
|
|
|
* You should release any resources which were locked or allocated during the opening and use of the directory stream.
|
|
|
|
*
|
2008-01-30 07:51:54 +01:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function dir_closedir ( )
|
|
|
|
{
|
|
|
|
$ret = closedir($this->opened_dir);
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
$this->opened_dir = $this->extra_dirs = null;
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
return $ret;
|
|
|
|
}
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
/**
|
|
|
|
* Load stream wrapper for a given schema
|
|
|
|
*
|
|
|
|
* @param string $scheme
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
static function load_wrapper($scheme)
|
|
|
|
{
|
|
|
|
if (!in_array($scheme,self::get_wrappers()))
|
|
|
|
{
|
|
|
|
switch($scheme)
|
|
|
|
{
|
|
|
|
case 'webdav':
|
|
|
|
require_once('HTTP/WebDAV/Client.php');
|
|
|
|
self::$wrappers[] = 'webdav';
|
|
|
|
break;
|
|
|
|
case '':
|
2008-04-14 07:52:24 +02:00
|
|
|
break; // default file, always loaded
|
2008-01-30 07:51:54 +01:00
|
|
|
default:
|
2008-04-14 07:52:24 +02:00
|
|
|
// check if scheme is buildin in php or one of our own stream wrappers
|
|
|
|
if (in_array($scheme,stream_get_wrappers()) || class_exists($scheme.'_stream_wrapper'))
|
|
|
|
{
|
|
|
|
self::$wrappers[] = $scheme;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trigger_error("Can't load stream-wrapper for scheme '$scheme'!",E_USER_WARNING);
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-30 07:51:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-01-30 07:51:54 +01:00
|
|
|
/**
|
|
|
|
* Return already loaded stream wrappers
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
static function get_wrappers()
|
|
|
|
{
|
|
|
|
if (is_null(self::$wrappers))
|
|
|
|
{
|
|
|
|
self::$wrappers = stream_get_wrappers();
|
|
|
|
}
|
|
|
|
return self::$wrappers;
|
|
|
|
}
|
2008-04-19 11:46:58 +02:00
|
|
|
|
2008-02-07 07:37:45 +01:00
|
|
|
static function init_static()
|
|
|
|
{
|
|
|
|
stream_register_wrapper(self::SCHEME,__CLASS__);
|
2008-03-03 13:17:08 +01:00
|
|
|
|
2008-04-19 11:46:58 +02:00
|
|
|
if ($GLOBALS['egw_info']['server']['vfs_fstab'] &&
|
2008-04-19 11:13:50 +02:00
|
|
|
is_array($fstab = unserialize($GLOBALS['egw_info']['server']['vfs_fstab'])) && count($fstab))
|
2008-02-07 07:37:45 +01:00
|
|
|
{
|
2008-04-19 11:46:58 +02:00
|
|
|
self::$fstab = $fstab;
|
2008-02-07 07:37:45 +01:00
|
|
|
}
|
|
|
|
}
|
2008-01-30 07:51:54 +01:00
|
|
|
}
|
|
|
|
|
2009-01-29 19:58:52 +01:00
|
|
|
vfs_stream_wrapper::init_static();
|