mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-29 01:59:39 +01:00
Merging r51397ff from Trunk: moving VFS API classes into a namespaced PSR4 autoloadable structure:
- PSR4 autoloader exists beside our old autloader to support old as well as new structure until everything is ported over - moved ported API stuff from phpgwapi to new api directory (idea is phpgwapi become a compatibility layer for old code, while we only port selected stuff to new api directory) - namespaces use prefix "EGroupware", then (first letter capitalised) app-name or "Api", sub-system names like "Vfs" or for apps "Ui", "Bo, "So" and at least class name starting with a capital letter and without understores eg. "StreamWrapper" plus just ".php" - examples: + egw_vfs in phpgwapi/inc/class.egw_vfs.inc.php --> EGroupware\Api\Vfs in api/src/Vfs.php + sqlfs_stream_wrapper in phpgwapi/inc/class.sqlfs_stream_wrapper.inc.php --> EGroupware\Api\Vfs\Sqlfs\StreamWrapper in api/src/Vfs/Sqlfs/StreamWrapper.php + sqlfs_utils in phpgwapi/inc/class.sqlfs_utils.inc.php --> EGroupware\Api\Vfs\Sqlfs\Utils in api/src/Vfs/Sqlfs/Utils.php - api directory is no a new svn module but exists (like home) as sub-directory under base egroupware module
This commit is contained in:
commit
97d57fb2a0
@ -634,7 +634,7 @@ foreach($widgets as $app => $list)
|
||||
{
|
||||
try
|
||||
{
|
||||
__autoload($class);
|
||||
class_exists($class); // trigger autoloader
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,762 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare API: VFS - stream wrapper to access the regular filesystem (setting a given user, group and mode)
|
||||
*
|
||||
* @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-14 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* eGroupWare API: VFS - stream wrapper to access the regular filesystem (setting a given user, group and mode)
|
||||
*
|
||||
* This stream wrapper allows to mount parts of the regular filesystem, under specified permissions.
|
||||
* You can eg. mount an directory in the docroot to allow the Admin group to upload files there.
|
||||
*
|
||||
* This stream wrapper uses query parameters to pass certain options to it:
|
||||
* - user: uid or user-name owning the path, default root
|
||||
* - group: gid or group-name owning the path, default root
|
||||
* - mode: mode bit for the path, default 0005 (read and execute for nobody)
|
||||
* - exec: false (default) = do NOT allow to upload or modify scripts, true = allow it (if docroot is mounted, this allows to run scripts!)
|
||||
* scripts are considered every file having a script-extension (eg. .php, .pl, .py), defined with SCRIPT_EXTENSION_PREG constant
|
||||
* - url: download url, if NOT a regular webdav.php download should be used, eg. because directory already
|
||||
* lies within the docroot or is mapped via an alias
|
||||
*
|
||||
* Example mount command for an uploads directory in the docroot (needs to be writable by webserver!):
|
||||
*
|
||||
* filemanager/cli.php mount --user root_admin --password secret --domain default \
|
||||
* 'filesystem://egal/var/www/html/uploads?group=Admins&mode=075&url=http://domain.com/uploads' /uploads
|
||||
*
|
||||
* (admin / secret is username / password of setup user, "root_" prefix differenciate from regular EGw-user!)
|
||||
*
|
||||
* To correctly support characters with special meaning in url's (#?%), we urlencode them with egw_vfs::encodePathComponent
|
||||
* and urldecode all path again, before passing them to php's filesystem functions.
|
||||
*
|
||||
* @link http://www.php.net/manual/en/function.stream-wrapper-register.php
|
||||
*/
|
||||
class filesystem_stream_wrapper implements iface_stream_wrapper
|
||||
{
|
||||
/**
|
||||
* Scheme / protocol used for this stream-wrapper
|
||||
*/
|
||||
const SCHEME = 'filesystem';
|
||||
/**
|
||||
* Mime type of directories, the old vfs used 'Directory', while eg. WebDAV uses 'httpd/unix-directory'
|
||||
*/
|
||||
const DIR_MIME_TYPE = egw_vfs::DIR_MIME_TYPE ;
|
||||
|
||||
/**
|
||||
* mode-bits, which have to be set for files
|
||||
*/
|
||||
const MODE_FILE = 0100000;
|
||||
/**
|
||||
* mode-bits, which have to be set for directories
|
||||
*/
|
||||
const MODE_DIR = 040000;
|
||||
|
||||
/**
|
||||
* optional context param when opening the stream, null if no context passed
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
var $context;
|
||||
|
||||
/**
|
||||
* stream / ressouce this class is opened for by stream_open
|
||||
*
|
||||
* @var ressource
|
||||
*/
|
||||
private $opened_stream;
|
||||
|
||||
/**
|
||||
* URL of the opened stream, used to build the complete URL of files in the dir
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $opened_stream_url;
|
||||
|
||||
/**
|
||||
* directory-ressouce this class is opened for by dir_open
|
||||
*
|
||||
* @var ressource
|
||||
*/
|
||||
private $opened_dir;
|
||||
|
||||
/**
|
||||
* URL of the opened dir, used to build the complete URL of files in the dir
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $opened_dir_url;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Regular expression identifying scripts, to NOT allow updating them if exec mount option is NOT set
|
||||
*/
|
||||
const SCRIPT_EXTENSIONS_PREG = '/\.(php[0-9]*|pl|py)$/';
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
$this->opened_stream = $this->opened_stream_url = null;
|
||||
$read_only = str_replace('b','',$mode) == 'r';
|
||||
|
||||
// check access rights, based on the eGW mount perms
|
||||
if (!($stat = self::url_stat($url,0)) || $mode[0] == 'x') // file not found or file should NOT exist
|
||||
{
|
||||
$dir = egw_vfs::dirname($url);
|
||||
if ($mode[0] == 'r' || // does $mode require the file to exist (r,r+)
|
||||
$mode[0] == 'x' || // or file should not exist, but does
|
||||
!egw_vfs::check_access($dir,egw_vfs::WRITABLE,$dir_stat=self::url_stat($dir,0))) // or we are not allowed to create it
|
||||
{
|
||||
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);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
elseif (!$read_only && !egw_vfs::check_access($url,egw_vfs::WRITABLE,$stat)) // we are not allowed to edit it
|
||||
{
|
||||
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);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!$read_only && self::deny_script($url))
|
||||
{
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) permission denied, file is a script!");
|
||||
if (!($options & STREAM_URL_STAT_QUIET))
|
||||
{
|
||||
trigger_error(__METHOD__."($url,$mode,$options) permission denied, file is a script!",E_USER_WARNING);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// open the "real" file
|
||||
if (!($this->opened_stream = fopen($path=egw_vfs::decodePath(egw_vfs::parse_url($url,PHP_URL_PATH)),$mode,$options)))
|
||||
{
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) fopen('$path','$mode',$options) returned false!");
|
||||
return false;
|
||||
}
|
||||
$this->opened_stream_url = $url;
|
||||
|
||||
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 ( )
|
||||
{
|
||||
$ret = fclose($this->opened_stream);
|
||||
|
||||
$this->opened_stream = 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 )
|
||||
{
|
||||
return fread($this->opened_stream,$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 )
|
||||
{
|
||||
return fwrite($this->opened_stream,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ( )
|
||||
{
|
||||
return feof($this->opened_stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to ftell() calls on the stream.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* 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 - 0 - Set position equal to offset bytes
|
||||
* SEEK_CUR - 1 - Set position to current location plus offset.
|
||||
* SEEK_END - 2 - 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); // fseek returns 0 on success and -1 on failure
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ( )
|
||||
{
|
||||
return fflush($this->opened_stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ( )
|
||||
{
|
||||
return self::url_stat($this->opened_stream_url,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 )
|
||||
{
|
||||
$path = egw_vfs::decodePath(egw_vfs::parse_url($url,PHP_URL_PATH));
|
||||
|
||||
// check access rights (file need to exist and directory need to be writable
|
||||
if (!file_exists($path) || is_dir($path) || !egw_vfs::check_access(egw_vfs::dirname($url),egw_vfs::WRITABLE))
|
||||
{
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
|
||||
return false; // no permission or file does not exist
|
||||
}
|
||||
return unlink($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
$from = egw_vfs::parse_url($url_from);
|
||||
$to = egw_vfs::parse_url($url_to);
|
||||
|
||||
// check access rights
|
||||
if (!($from_stat = self::url_stat($url_from,0)) || !egw_vfs::check_access(egw_vfs::dirname($url_from),egw_vfs::WRITABLE))
|
||||
{
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $from[path] permission denied!");
|
||||
return false; // no permission or file does not exist
|
||||
}
|
||||
$to_dir = egw_vfs::dirname($url_to);
|
||||
if (!egw_vfs::check_access($to_dir,egw_vfs::WRITABLE,$to_dir_stat = self::url_stat($to_dir,0)))
|
||||
{
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $to_dir permission denied!");
|
||||
return false; // no permission or parent-dir does not exist
|
||||
}
|
||||
if (self::deny_script($url_to))
|
||||
{
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to) permission denied, file is a script!");
|
||||
return false;
|
||||
}
|
||||
// the filesystem stream-wrapper does NOT allow to rename files to directories, as this makes problems
|
||||
// for our vfs too, we abort here with an error, like the filesystem one does
|
||||
if (($to_stat = self::url_stat($to['path'],0)) &&
|
||||
($to_stat['mime'] === self::DIR_MIME_TYPE) !== ($from_stat['mime'] === self::DIR_MIME_TYPE))
|
||||
{
|
||||
$is_dir = $to_stat['mime'] === self::DIR_MIME_TYPE ? 'a' : 'no';
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) $to[path] is $is_dir directory!");
|
||||
return false; // no permission or file does not exist
|
||||
}
|
||||
// if destination file already exists, delete it
|
||||
if ($to_stat && !self::unlink($url_to,$operation))
|
||||
{
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!");
|
||||
return false;
|
||||
}
|
||||
return rename(egw_vfs::decodePath($from['path']),egw_vfs::decodePath($to['path']));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 not used, as we dont allow to change 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 )
|
||||
{
|
||||
$path = egw_vfs::decodePath(egw_vfs::parse_url($url,PHP_URL_PATH));
|
||||
$recursive = (bool)($options & STREAM_MKDIR_RECURSIVE);
|
||||
|
||||
// find the real parent (might be more then one level if $recursive!)
|
||||
do {
|
||||
$parent = dirname($parent ? $parent : $path);
|
||||
$parent_url = egw_vfs::dirname($parent_url ? $parent_url : $url);
|
||||
}
|
||||
while ($recursive && $parent != '/' && !file_exists($parent));
|
||||
//echo __METHOD__."($url,$mode,$options) path=$path, recursive=$recursive, parent=$parent, egw_vfs::check_access(parent_url=$parent_url,egw_vfs::WRITABLE)=".(int)egw_vfs::check_access($parent_url,egw_vfs::WRITABLE)."\n";
|
||||
|
||||
// check access rights (in real filesystem AND by mount perms)
|
||||
if (file_exists($path) || !file_exists($parent) || !is_writable($parent) || !egw_vfs::check_access($parent_url,egw_vfs::WRITABLE))
|
||||
{
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
|
||||
return false;
|
||||
}
|
||||
return mkdir($path,$mode=0700,$recursive); // setting mode 0700 allows (only) apache to write into the dir
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
$path = egw_vfs::decodePath(egw_vfs::parse_url($url,PHP_URL_PATH));
|
||||
$parent = dirname($path);
|
||||
|
||||
// check access rights (in real filesystem AND by mount perms)
|
||||
if (!file_exists($path) || !is_writable($parent) || !egw_vfs::check_access(egw_vfs::dirname($url),egw_vfs::WRITABLE))
|
||||
{
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
|
||||
return false;
|
||||
}
|
||||
return rmdir($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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($url,$time=null,$atime=null)
|
||||
{
|
||||
$path = egw_vfs::decodePath(egw_vfs::parse_url($url,PHP_URL_PATH));
|
||||
$parent = dirname($path);
|
||||
|
||||
// check access rights (in real filesystem AND by mount perms)
|
||||
if (!file_exists($path) || !is_writable($parent) || !egw_vfs::check_access(egw_vfs::dirname($url),egw_vfs::WRITABLE))
|
||||
{
|
||||
if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
|
||||
return false;
|
||||
}
|
||||
return touch($path,$time,$atime);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is not (yet) a stream-wrapper function, but it's necessary and can be used static
|
||||
*
|
||||
* Not supported, as it would require 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 false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is not (yet) a stream-wrapper function, but it's necessary and can be used static
|
||||
*
|
||||
* Not supported, as it would require root rights!
|
||||
*
|
||||
* @param string $path
|
||||
* @param int $owner numeric user id
|
||||
* @return boolean true on success, false otherwise
|
||||
*/
|
||||
static function chown($path,$owner)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is not (yet) a stream-wrapper function, but it's necessary and can be used static
|
||||
*
|
||||
* Not supported, as it would require root rights!
|
||||
*
|
||||
* @param string $path
|
||||
* @param int $group numeric group id
|
||||
* @return boolean true on success, false otherwise
|
||||
*/
|
||||
static function chgrp($path,$group)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called immediately when your stream object is created for examining directory contents with opendir().
|
||||
*
|
||||
* @param string $url URL that was passed to opendir() and that this object is expected to explore.
|
||||
* @param int $options
|
||||
* @return booelan
|
||||
*/
|
||||
function dir_opendir ( $url, $options )
|
||||
{
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options)");
|
||||
|
||||
$this->opened_dir = null;
|
||||
|
||||
$path = egw_vfs::decodePath(egw_vfs::parse_url($this->opened_dir_url = $url,PHP_URL_PATH));
|
||||
|
||||
// ToDo: check access rights
|
||||
|
||||
if (!($this->opened_dir = opendir($path)))
|
||||
{
|
||||
if (self::LOG_LEVEL > 0) error_log(__METHOD__."($url,$options) opendir('$path') failed!");
|
||||
return false;
|
||||
}
|
||||
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 $url
|
||||
* @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 )
|
||||
{
|
||||
$parts = egw_vfs::parse_url($url);
|
||||
$path = egw_vfs::decodePath($parts['path']);
|
||||
|
||||
$stat = @stat($path); // suppressed the stat failed warnings
|
||||
|
||||
if ($stat)
|
||||
{
|
||||
// set owner, group and mode from mount options
|
||||
if (!self::parse_query($parts['query'],$uid,$gid,$mode))
|
||||
{
|
||||
return false;
|
||||
if (self::LOG_LEVEL > 0) error_log(__METHOD__."($url,$flags) can NOT self::parse_query('$parts[query]')!");
|
||||
}
|
||||
$stat['uid'] = $stat[4] = $uid;
|
||||
$stat['gid'] = $stat[5] = $gid;
|
||||
$stat['mode'] = $stat[2] = $stat['mode'] & self::MODE_DIR ? self::MODE_DIR | $mode : self::MODE_FILE | ($mode & ~0111);
|
||||
// write rights also depend on the write rights of the webserver
|
||||
if (!is_writable($path))
|
||||
{
|
||||
$stat['mode'] = $stat[2] = $stat['mode'] & ~0222;
|
||||
}
|
||||
}
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$flags) path=$path, mount_mode=".sprintf('0%o',$mode).", mode=".sprintf('0%o',$stat['mode']).'='.egw_vfs::int2mode($stat['mode']));
|
||||
return $stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to readdir().
|
||||
*
|
||||
* It should return a string representing the next filename in the location opened by dir_opendir().
|
||||
*
|
||||
* 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).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function dir_readdir ( )
|
||||
{
|
||||
do {
|
||||
$file = readdir($this->opened_dir);
|
||||
|
||||
$ignore = !($file === false || // stop if no more dirs or
|
||||
($file != '.' && $file != '..' )); // file not . or ..
|
||||
if (self::LOG_LEVEL > 1 && $ignore) error_log(__METHOD__.'() ignoring '.array2string($file));
|
||||
}
|
||||
while ($ignore);
|
||||
|
||||
// encode special chars messing up url's
|
||||
if ($file !== false) $file = egw_vfs::encodePathComponent($file);
|
||||
|
||||
if (self::LOG_LEVEL > 1) error_log(__METHOD__.'() returning '.array2string($file));
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ( )
|
||||
{
|
||||
return rewinddir($this->opened_dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ( )
|
||||
{
|
||||
closedir($this->opened_dir);
|
||||
|
||||
$this->opened_dir = $this->extra_dirs = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse a query containing mount parameters: user, uid, group, gid or mode
|
||||
*
|
||||
* @param string|array $query query string or array returned by parse_url (key 'query' holds the value)
|
||||
* @param int &$uid default if not set is 0=root
|
||||
* @param int &$gid default if not set is 0=root
|
||||
* @param int &$mode default if not set is 05 r-x for others
|
||||
* @return boolean true on successfull parse, false on error
|
||||
*/
|
||||
static function parse_query($query,&$uid,&$gid,&$mode)
|
||||
{
|
||||
parse_str(is_array($query) ? $query['query'] : $query,$params);
|
||||
|
||||
// setting the default perms root.root r-x for other
|
||||
$uid = $gid = 0;
|
||||
$mode = 05;
|
||||
|
||||
foreach($params as $name => $value)
|
||||
{
|
||||
switch($name)
|
||||
{
|
||||
case 'user':
|
||||
if (!is_numeric($value))
|
||||
{
|
||||
if ($name === 'root')
|
||||
{
|
||||
$value = 0;
|
||||
}
|
||||
elseif (($value = $GLOBALS['egw']->accounts->name2id($value,'account_lid','u')) === false)
|
||||
{
|
||||
error_log(__METHOD__."('$query') unknown user-name '$value'!");
|
||||
return false; // wrong user-name
|
||||
}
|
||||
}
|
||||
// fall-through
|
||||
case 'uid':
|
||||
if (!is_numeric($value) || $value < 0 || !is_int($value) && !$GLOBALS['egw']->accounts->id2name($value))
|
||||
{
|
||||
error_log(__METHOD__."('$query') wrong numeric user-id '$value'!");
|
||||
return false;
|
||||
}
|
||||
$uid = (int)$value;
|
||||
break;
|
||||
case 'group':
|
||||
if (!is_numeric($value))
|
||||
{
|
||||
if ($name === 'root')
|
||||
{
|
||||
$value = 0;
|
||||
}
|
||||
elseif (($value = $GLOBALS['egw']->accounts->name2id($value,'account_lid','g')) === false)
|
||||
{
|
||||
error_log(__METHOD__."('$query') unknown group-name '$value'!");
|
||||
return false; // wrong group-name
|
||||
}
|
||||
$value = -$value; // vfs uses positiv gid's!
|
||||
}
|
||||
// fall-through
|
||||
case 'gid':
|
||||
if (!is_numeric($value) || $value < 0 || !is_int($value) && !$GLOBALS['egw']->accounts->id2name(-$value))
|
||||
{
|
||||
error_log(__METHOD__."('$query') wrong numeric group-id '$value'!");
|
||||
return false;
|
||||
}
|
||||
$gid = (int)$value;
|
||||
break;
|
||||
case 'mode':
|
||||
$mode = egw_vfs::mode2int($value);
|
||||
break;
|
||||
case 'url':
|
||||
// ignored, only used for download_url method
|
||||
break;
|
||||
default:
|
||||
error_log(__METHOD__."('$query') unknown option '$name'!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
//echo __METHOD__.'('.print_r($query,true).") uid=$uid, gid=$gid, mode=".sprintf('0%o',$mode)."\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if url is a script (self::$script_extentions) and exec mount option is NOT set
|
||||
*
|
||||
* @param string $url
|
||||
* @return boolean true if $url is a script AND exec is NOT set, false otherwise
|
||||
*/
|
||||
static function deny_script($url)
|
||||
{
|
||||
$parts = egw_vfs::parse_url($url);
|
||||
parse_str($parts['query'],$get);
|
||||
|
||||
$deny = !$get['exec'] && preg_match(self::SCRIPT_EXTENSIONS_PREG,$parts['path']);
|
||||
|
||||
if (self::LOG_LEVEL > 1 || self::LOG_LEVEL > 0 && $deny)
|
||||
{
|
||||
error_log(__METHOD__."($url) returning ".array2string($deny));
|
||||
}
|
||||
return $deny;
|
||||
}
|
||||
|
||||
/**
|
||||
* URL to download a file
|
||||
*
|
||||
* We use our webdav handler as download url instead of an own download method.
|
||||
* The webdav hander (filemanager/webdav.php) recognices eGW's session cookie and of cause understands regular GET requests.
|
||||
*
|
||||
* @param string $url
|
||||
* @param boolean $force_download=false add header('Content-disposition: filename="' . basename($path) . '"'), currently not supported!
|
||||
* @todo get $force_download working through webdav
|
||||
* @return string|false string with full download url or false to use default webdav.php url
|
||||
*/
|
||||
static function download_url($url,$force_download=false)
|
||||
{
|
||||
list(,$query) = explode('?',$url,2);
|
||||
parse_str($query,$get);
|
||||
if (empty($get['url'])) return false; // no download url given for this mount-point
|
||||
|
||||
if (!($mount_url = egw_vfs::mount_url($url))) return false; // no mount url found, should not happen
|
||||
list($mount_url) = explode('?',$mount_url);
|
||||
|
||||
list($url,$query) = explode('?',$url,2);
|
||||
$relpath = substr($url,strlen($mount_url));
|
||||
|
||||
$download_url = egw_vfs::concat($get['url'],$relpath);
|
||||
if ($download_url[0] == '/')
|
||||
{
|
||||
$download_url = ($_SERVER['HTTPS'] ? 'https://' : 'http://').
|
||||
$_SERVER['HTTP_HOST'].$download_url;
|
||||
}
|
||||
|
||||
//die(__METHOD__."('$url') --> relpath = $relpath --> $download_url");
|
||||
return $download_url;
|
||||
}
|
||||
}
|
||||
|
||||
stream_register_wrapper(filesystem_stream_wrapper::SCHEME ,'filesystem_stream_wrapper');
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare API: VFS - stream wrapper interface
|
||||
* EGroupware API: VFS - stream wrapper interface
|
||||
*
|
||||
* @link http://www.egroupware.org
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
@ -9,240 +9,9 @@
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
use EGroupware\Api\Vfs;
|
||||
|
||||
/**
|
||||
* eGroupWare API: VFS - stream wrapper interface
|
||||
*
|
||||
* The interface is according to the docu on php.net
|
||||
*
|
||||
* @link http://www.php.net/manual/en/function.stream-wrapper-register.php
|
||||
* @deprecated use EGroupware\Api\Vfs\StreamWrapperIface
|
||||
*/
|
||||
interface iface_stream_wrapper
|
||||
{
|
||||
/**
|
||||
* optional context param when opening the stream, null if no context passed
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
//var $context;
|
||||
|
||||
/**
|
||||
* This method is called immediately after your stream object is created.
|
||||
*
|
||||
* @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()
|
||||
* @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 ( $path, $mode, $options, &$opened_path );
|
||||
|
||||
/**
|
||||
* 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 ( );
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
/**
|
||||
* 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 ( );
|
||||
|
||||
/**
|
||||
* This method is called in response to ftell() calls on the stream.
|
||||
*
|
||||
* @return integer current read/write position of the stream
|
||||
*/
|
||||
function stream_tell ( );
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
/**
|
||||
* 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 ( );
|
||||
|
||||
/**
|
||||
* 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 ( );
|
||||
|
||||
/**
|
||||
* 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 $path
|
||||
* @return boolean TRUE on success or FALSE on failure
|
||||
*/
|
||||
static function unlink ( $path );
|
||||
|
||||
/**
|
||||
* 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 $path_from
|
||||
* @param string $path_to
|
||||
* @return boolean TRUE on success or FALSE on failure
|
||||
*/
|
||||
static function rename ( $path_from, $path_to );
|
||||
|
||||
/**
|
||||
* 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 $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 );
|
||||
|
||||
/**
|
||||
* 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 $path
|
||||
* @param int $options Possible values include STREAM_REPORT_ERRORS.
|
||||
* @return boolean TRUE on success or FALSE on failure.
|
||||
*/
|
||||
static function rmdir ( $path, $options );
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return booelan
|
||||
*/
|
||||
function dir_opendir ( $path, $options );
|
||||
|
||||
/**
|
||||
* 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 ( $path, $flags );
|
||||
|
||||
/**
|
||||
* 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 ( );
|
||||
|
||||
/**
|
||||
* 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 ( );
|
||||
|
||||
/**
|
||||
* 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 ( );
|
||||
}
|
||||
interface iface_stream_wrapper extends Vfs\StreamWrapperIface {}
|
||||
|
@ -1,321 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare API: VFS - stream wrapper for linked files
|
||||
*
|
||||
* @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-14 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @version $Id: class.sqlfs_stream_wrapper.inc.php 24997 2008-03-02 21:44:15Z ralfbecker $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define parent for links_stream_wrapper, if not already defined
|
||||
*
|
||||
* Allows to base links_stream_wrapper on an other wrapper
|
||||
*/
|
||||
if (!class_exists('links_stream_wrapper_parent',false))
|
||||
{
|
||||
class links_stream_wrapper_parent extends sqlfs_stream_wrapper {}
|
||||
}
|
||||
|
||||
/**
|
||||
* EGroupware API: stream wrapper for linked files
|
||||
*
|
||||
* The files stored by the sqlfs_stream_wrapper in a /apps/$app/$id directory
|
||||
*
|
||||
* The links stream wrapper extends the sqlfs one, to implement an own ACL based on the access
|
||||
* of the entry the files are linked to.
|
||||
*
|
||||
* Applications can define a 'file_access' method in the link registry with the following signature:
|
||||
*
|
||||
* boolean function file_access(string $id,int $check,string $rel_path)
|
||||
*
|
||||
* If the do not implement such a function the title function is used to test if the user has
|
||||
* at least read access to an entry, and if true full (write) access to the files is granted.
|
||||
*
|
||||
* Entry directories are always reported existing and empty, if not existing in sqlfs.
|
||||
*
|
||||
* The stream wrapper interface is according to the docu on php.net
|
||||
*
|
||||
* @link http://www.php.net/manual/en/function.stream-wrapper-register.php
|
||||
*/
|
||||
class links_stream_wrapper extends links_stream_wrapper_parent
|
||||
{
|
||||
/**
|
||||
* Scheme / protocoll used for this stream-wrapper
|
||||
*/
|
||||
const SCHEME = 'links';
|
||||
/**
|
||||
* Prefix to predend to get an url from a path
|
||||
*/
|
||||
const PREFIX = 'links://default';
|
||||
/**
|
||||
* Base url to store links
|
||||
*/
|
||||
const BASEURL = 'links://default/apps';
|
||||
/**
|
||||
* Enable some debug output to the error_log
|
||||
*/
|
||||
const DEBUG = false;
|
||||
|
||||
/**
|
||||
* Implements ACL based on the access of the user to the entry the files are linked to.
|
||||
*
|
||||
* @param string $url url to check
|
||||
* @param int $check mode to check: one or more or'ed together of: 4 = read, 2 = write, 1 = executable
|
||||
* @return boolean
|
||||
*/
|
||||
static function check_extended_acl($url,$check)
|
||||
{
|
||||
if (egw_vfs::$is_root)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
$path = egw_vfs::parse_url($url,PHP_URL_PATH);
|
||||
|
||||
list(,$apps,$app,$id,$rel_path) = explode('/',$path,5);
|
||||
|
||||
if ($apps != 'apps')
|
||||
{
|
||||
$access = false; // no access to anything, but /apps
|
||||
$what = '!= apps';
|
||||
}
|
||||
elseif (!$app)
|
||||
{
|
||||
$access = !($check & egw_vfs::WRITABLE); // always grant read access to /apps
|
||||
$what = '!$app';
|
||||
}
|
||||
elseif(!isset($GLOBALS['egw_info']['user']['apps'][$app]))
|
||||
{
|
||||
$access = false; // user has no access to the $app application
|
||||
$what = 'no app-rights';
|
||||
}
|
||||
elseif (!$id)
|
||||
{
|
||||
$access = true; // grant read&write access to /apps/$app
|
||||
$what = 'app dir';
|
||||
}
|
||||
// allow applications to implement their own access control to the file storage
|
||||
// otherwise use the title method to check if user has (at least read access) to the entry
|
||||
// which gives him then read AND write access to the file store of the entry
|
||||
else
|
||||
{
|
||||
// vfs & stream-wrapper use posix rights, egw_link::file_access uses EGW_ACL_{EDIT|READ}!
|
||||
$required = $check & egw_vfs::WRITABLE ? EGW_ACL_EDIT : EGW_ACL_READ;
|
||||
$access = egw_link::file_access($app,$id,$required,$rel_path,egw_vfs::$user);
|
||||
$what = "from egw_link::file_access('$app',$id,$required,'$rel_path,".egw_vfs::$user.")";
|
||||
}
|
||||
if (self::DEBUG) error_log(__METHOD__."($url,$check) user=".egw_vfs::$user." ($what) ".($access?"access granted ($app:$id:$rel_path)":'no access!!!'));
|
||||
return $access;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called in response to stat() calls on the URL paths associated with the wrapper.
|
||||
*
|
||||
* Reimplemented from sqlfs, as we have to pass the value of check_extends_acl(), due to the lack of late static binding.
|
||||
* And to return vcard for url /apps/addressbook/$id/.entry
|
||||
*
|
||||
* @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 )
|
||||
{
|
||||
$eacl_check=self::check_extended_acl($url,egw_vfs::READABLE);
|
||||
|
||||
// return vCard as /.entry
|
||||
if ( $eacl_check && substr($url,-7) == '/.entry' &&
|
||||
(list($app) = array_slice(explode('/',$url),-3,1)) && $app === 'addressbook')
|
||||
{
|
||||
$ret = array(
|
||||
'ino' => md5($url),
|
||||
'name' => '.entry',
|
||||
'mode' => self::MODE_FILE|egw_vfs::READABLE, // required by the stream wrapper
|
||||
'size' => 1024, // fmail does NOT attach files with size 0!
|
||||
'uid' => 0,
|
||||
'gid' => 0,
|
||||
'mtime' => time(),
|
||||
'ctime' => time(),
|
||||
'nlink' => 1,
|
||||
// eGW addition to return some extra values
|
||||
'mime' => $app == 'addressbook' ? 'text/vcard' : 'text/calendar',
|
||||
);
|
||||
}
|
||||
// if entry directory does not exist --> return fake directory
|
||||
elseif (!($ret = parent::url_stat($url,$flags,$eacl_check)) && $eacl_check)
|
||||
{
|
||||
list(,/*$apps*/,/*$app*/,$id,$rel_path) = explode('/', egw_vfs::parse_url($url, PHP_URL_PATH), 5);
|
||||
if ($id && !isset($rel_path))
|
||||
{
|
||||
$ret = array(
|
||||
'ino' => md5($url),
|
||||
'name' => $id,
|
||||
'mode' => self::MODE_DIR, // required by the stream wrapper
|
||||
'size' => 0,
|
||||
'uid' => 0,
|
||||
'gid' => 0,
|
||||
'mtime' => time(),
|
||||
'ctime' => time(),
|
||||
'nlink' => 2,
|
||||
// eGW addition to return some extra values
|
||||
'mime' => egw_vfs::DIR_MIME_TYPE,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (self::DEBUG) error_log(__METHOD__."('$url', $flags) calling parent::url_stat(,,".array2string($eacl_check).') returning '.array2string($ret));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set or delete extended acl for a given path and owner (or delete them if is_null($rights)
|
||||
*
|
||||
* Reimplemented, to NOT call the sqlfs functions, as we dont allow to modify the ACL (defined by the apps)
|
||||
*
|
||||
* @param string $path string with path
|
||||
* @param int $rights=null rights to set, or null to delete the entry
|
||||
* @param int/boolean $owner=null owner for whom to set the rights, null for the current user, or false to delete all rights for $path
|
||||
* @param int $fs_id=null fs_id to use, to not query it again (eg. because it's already deleted)
|
||||
* @return boolean true if acl is set/deleted, false on error
|
||||
*/
|
||||
static function eacl($path,$rights=null,$owner=null,$fs_id=null)
|
||||
{
|
||||
unset($path, $rights, $owner, $fs_id); // not used, but required by function signature
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all ext. ACL set for a path
|
||||
*
|
||||
* Reimplemented, to NOT call the sqlfs functions, as we dont allow to modify the ACL (defined by the apps)
|
||||
*
|
||||
* @param string $path
|
||||
* @return array/boolean array with array('path'=>$path,'owner'=>$owner,'rights'=>$rights) or false if $path not found
|
||||
*/
|
||||
function get_eacl($path)
|
||||
{
|
||||
unset($path); // not used, but required by function signature
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* mkdir for links
|
||||
*
|
||||
* Reimplemented as we have no static late binding to allow the extended sqlfs to call our eacl and to set no default rights for entry dirs
|
||||
*
|
||||
* 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 $path
|
||||
* @param int $mode not used(!), we inherit 005 for /apps/$app and set 000 for /apps/$app/$id
|
||||
* @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE, we allways use recursive!
|
||||
* @return boolean TRUE on success or FALSE on failure
|
||||
*/
|
||||
static function mkdir($path,$mode,$options)
|
||||
{
|
||||
unset($mode); // not used, but required by function signature
|
||||
|
||||
if($path[0] != '/')
|
||||
{
|
||||
if (strpos($path,'?') !== false) $query = egw_vfs::parse_url($path,PHP_URL_QUERY);
|
||||
$path = egw_vfs::parse_url($path,PHP_URL_PATH).($query ? '?'.$query : '');
|
||||
}
|
||||
list(,$apps,$app,$id) = explode('/',$path);
|
||||
|
||||
$ret = false;
|
||||
if ($apps == 'apps' && $app && !$id || self::check_extended_acl($path,egw_vfs::WRITABLE)) // app directory itself is allways ok
|
||||
{
|
||||
$current_is_root = egw_vfs::$is_root; egw_vfs::$is_root = true;
|
||||
$current_user = egw_vfs::$user; egw_vfs::$user = 0;
|
||||
|
||||
$ret = parent::mkdir($path,0,$options|STREAM_MKDIR_RECURSIVE);
|
||||
if ($id) parent::chmod($path,0); // no other rights
|
||||
|
||||
egw_vfs::$user = $current_user;
|
||||
egw_vfs::$is_root = $current_is_root;
|
||||
}
|
||||
//error_log(__METHOD__."($path,$mode,$options) apps=$apps, app=$app, id=$id: returning $ret");
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called immediately after your stream object is created.
|
||||
*
|
||||
* Reimplemented from sqlfs to ensure self::url_stat is called, to fill sqlfs stat cache with our eacl!
|
||||
* And to return vcard for url /apps/addressbook/$id/.entry
|
||||
*
|
||||
* @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 )
|
||||
{
|
||||
// the following call is necessary to fill sqlfs_stream_wrapper::$stat_cache, WITH the extendes ACL!
|
||||
$stat = self::url_stat($url,0);
|
||||
//error_log(__METHOD__."('$url', '$mode', $options) stat=".array2string($stat));
|
||||
|
||||
// return vCard as /.entry
|
||||
if ($stat && $mode[0] == 'r' && substr($url,-7) === '/.entry' &&
|
||||
(list($app) = array_slice(explode('/',$url),-3,1)) && $app === 'addressbook')
|
||||
{
|
||||
list($id) = array_slice(explode('/',$url),-2,1);
|
||||
$name = md5($url);
|
||||
$ab_vcard = new addressbook_vcal('addressbook','text/vcard');
|
||||
if (!($GLOBALS[$name] =& $ab_vcard->getVCard($id)))
|
||||
{
|
||||
error_log(__METHOD__."('$url', '$mode', $options) addressbook_vcal::getVCard($id) returned false!");
|
||||
return false;
|
||||
}
|
||||
//error_log(__METHOD__."('$url', '$mode', $options) addressbook_vcal::getVCard($id) returned ".$GLOBALS[$name]);
|
||||
require_once(EGW_API_INC.'/class.global_stream_wrapper.inc.php');
|
||||
$this->opened_stream = fopen('global://'.$name,'r');
|
||||
unset($GLOBALS[$name]); // unset it, so it does not use up memory, once the stream is closed
|
||||
return true;
|
||||
}
|
||||
// create not existing entry directories on the fly
|
||||
if ($mode[0] != 'r' && !parent::url_stat($dir = egw_vfs::dirname($url),0) && self::check_extended_acl($dir,egw_vfs::WRITABLE))
|
||||
{
|
||||
self::mkdir($dir,0,STREAM_MKDIR_RECURSIVE);
|
||||
}
|
||||
return parent::stream_open($url,$mode,$options,$opened_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called immediately when your stream object is created for examining directory contents with opendir().
|
||||
*
|
||||
* Reimplemented to give no error, if entry directory does not exist.
|
||||
*
|
||||
* @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 (!parent::url_stat($url, STREAM_URL_STAT_QUIET) && self::url_stat($url, STREAM_URL_STAT_QUIET))
|
||||
{
|
||||
$this->opened_dir = array();
|
||||
return true;
|
||||
}
|
||||
return parent::dir_opendir($url, $options);
|
||||
}
|
||||
}
|
||||
|
||||
stream_register_wrapper(links_stream_wrapper::SCHEME ,'links_stream_wrapper');
|
File diff suppressed because it is too large
Load Diff
@ -7,479 +7,13 @@
|
||||
* @package api
|
||||
* @subpackage vfs
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2008-14 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2008-15 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'class.iface_stream_wrapper.inc.php';
|
||||
require_once 'class.sqlfs_stream_wrapper.inc.php';
|
||||
use EGroupware\Api\Vfs\Sqlfs;
|
||||
|
||||
/**
|
||||
* sqlfs stream wrapper utilities: migration db-fs, fsck
|
||||
* @depredated use EGroupware\Api\Vfs\Sqlfs\Utils
|
||||
*/
|
||||
class sqlfs_utils extends sqlfs_stream_wrapper
|
||||
{
|
||||
/**
|
||||
* Migrate SQLFS content from DB to filesystem
|
||||
*
|
||||
* @param boolean $debug true to echo a message for each copied file
|
||||
*/
|
||||
static function migrate_db2fs($debug=true)
|
||||
{
|
||||
if (!is_object(self::$pdo))
|
||||
{
|
||||
self::_pdo();
|
||||
}
|
||||
$query = 'SELECT fs_id,fs_name,fs_size,fs_content'.
|
||||
' FROM '.self::TABLE.' WHERE fs_content IS NOT NULL'.
|
||||
' ORDER BY fs_id LIMIT 5 OFFSET :offset';
|
||||
|
||||
$fs_id = $fs_name = $fs_size = $fs_content = null;
|
||||
$n = 0;
|
||||
$stmt = self::$pdo->prepare($query);
|
||||
$stmt->bindColumn(1,$fs_id);
|
||||
$stmt->bindColumn(2,$fs_name);
|
||||
$stmt->bindColumn(3,$fs_size);
|
||||
$stmt->bindColumn(4,$fs_content,PDO::PARAM_LOB);
|
||||
$stmt->bindValue(':offset', $n, PDO::PARAM_INT);
|
||||
|
||||
while ($stmt->execute())
|
||||
{
|
||||
foreach($stmt as $row)
|
||||
{
|
||||
// hack to work around a current php bug (http://bugs.php.net/bug.php?id=40913)
|
||||
// PDOStatement::bindColumn(,,PDO::PARAM_LOB) is not working for MySQL, content is returned as string :-(
|
||||
if (is_string($fs_content))
|
||||
{
|
||||
$name = md5($fs_name.$fs_id);
|
||||
$GLOBALS[$name] =& $fs_content;
|
||||
require_once(EGW_API_INC.'/class.global_stream_wrapper.inc.php');
|
||||
$content = fopen('global://'.$name,'r');
|
||||
if (!$content) echo "fopen('global://$name','w' failed, strlen(\$GLOBALS['$name'])=".strlen($GLOBALS[$name]).", \$GLOBALS['$name']=".substr($GLOBALS['$name'],0,100)."...\n";
|
||||
unset($GLOBALS[$name]); // unset it, so it does not use up memory, once the stream is closed
|
||||
}
|
||||
else
|
||||
{
|
||||
$content = $fs_content;
|
||||
}
|
||||
if (!is_resource($content))
|
||||
{
|
||||
throw new egw_exception_assertion_failed(__METHOD__."(): fs_id=$fs_id ($fs_name, $fs_size bytes) content is NO resource! ".array2string($content));
|
||||
}
|
||||
$filename = self::_fs_path($fs_id);
|
||||
if (!file_exists($fs_dir=egw_vfs::dirname($filename)))
|
||||
{
|
||||
self::mkdir_recursive($fs_dir,0700,true);
|
||||
}
|
||||
if (!($dest = fopen($filename,'w')))
|
||||
{
|
||||
throw new egw_exception_assertion_failed(__METHOD__."(): fopen($filename,'w') failed!");
|
||||
}
|
||||
if (($bytes = stream_copy_to_stream($content,$dest)) != $fs_size)
|
||||
{
|
||||
throw new egw_exception_assertion_failed(__METHOD__."(): fs_id=$fs_id ($fs_name) $bytes bytes copied != size of $fs_size bytes!");
|
||||
}
|
||||
if ($debug) error_log("$fs_id: $fs_name: $bytes bytes copied to fs");
|
||||
fclose($dest);
|
||||
fclose($content); unset($content);
|
||||
|
||||
++$n;
|
||||
}
|
||||
if (!$n) break; // just in case nothing is found, statement will execute just fine
|
||||
|
||||
$stmt->bindValue(':offset', $n, PDO::PARAM_INT);
|
||||
}
|
||||
unset($row); // not used, as we access bound variables
|
||||
unset($stmt);
|
||||
|
||||
if ($n) // delete all content in DB, if there was some AND no error (exception thrown!)
|
||||
{
|
||||
$query = 'UPDATE '.self::TABLE.' SET fs_content=NULL';
|
||||
$stmt = self::$pdo->prepare($query);
|
||||
$stmt->execute();
|
||||
}
|
||||
return $n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and optionaly fix corruption in sqlfs
|
||||
*
|
||||
* @param boolean $check_only=true
|
||||
* @return array with messages / found problems
|
||||
*/
|
||||
public static function fsck($check_only=true)
|
||||
{
|
||||
if (!is_object(self::$pdo))
|
||||
{
|
||||
self::_pdo();
|
||||
}
|
||||
$msgs = array();
|
||||
foreach(array(
|
||||
self::fsck_fix_required_nodes($check_only),
|
||||
self::fsck_fix_multiple_active($check_only),
|
||||
self::fsck_fix_unconnected($check_only),
|
||||
self::fsck_fix_no_content($check_only),
|
||||
) as $check_msgs)
|
||||
{
|
||||
if ($check_msgs) $msgs = array_merge($msgs, $check_msgs);
|
||||
}
|
||||
|
||||
foreach ($GLOBALS['egw']->hooks->process(array(
|
||||
'location' => 'fsck',
|
||||
'check_only' => $check_only)
|
||||
) as $app_msgs)
|
||||
{
|
||||
if ($app_msgs) $msgs = array_merge($msgs, $app_msgs);
|
||||
}
|
||||
return $msgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and optionally create required nodes: /, /home, /apps
|
||||
*
|
||||
* @param boolean $check_only=true
|
||||
* @return array with messages / found problems
|
||||
*/
|
||||
private static function fsck_fix_required_nodes($check_only=true)
|
||||
{
|
||||
static $dirs = array(
|
||||
'/' => 1,
|
||||
'/home' => 2,
|
||||
'/apps' => 3,
|
||||
);
|
||||
$stmt = $delete_stmt = null;
|
||||
$msgs = array();
|
||||
foreach($dirs as $path => $id)
|
||||
{
|
||||
if (!($stat = self::url_stat($path, STREAM_URL_STAT_LINK)))
|
||||
{
|
||||
if ($check_only)
|
||||
{
|
||||
$msgs[] = lang('Required directory "%1" not found!', $path);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isset($stmt))
|
||||
{
|
||||
$stmt = self::$pdo->prepare('INSERT INTO '.self::TABLE.' (fs_id,fs_name,fs_dir,fs_mode,fs_uid,fs_gid,fs_size,fs_mime,fs_created,fs_modified,fs_creator'.
|
||||
') VALUES (:fs_id,:fs_name,:fs_dir,:fs_mode,:fs_uid,:fs_gid,:fs_size,:fs_mime,:fs_created,:fs_modified,:fs_creator)');
|
||||
}
|
||||
try {
|
||||
$ok = $stmt->execute($data = array(
|
||||
'fs_id' => $id,
|
||||
'fs_name' => substr($path,1),
|
||||
'fs_dir' => $path == '/' ? 0 : $dirs['/'],
|
||||
'fs_mode' => 05,
|
||||
'fs_uid' => 0,
|
||||
'fs_gid' => 0,
|
||||
'fs_size' => 0,
|
||||
'fs_mime' => 'httpd/unix-directory',
|
||||
'fs_created' => self::_pdo_timestamp(time()),
|
||||
'fs_modified' => self::_pdo_timestamp(time()),
|
||||
'fs_creator' => 0,
|
||||
));
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
$ok = false;
|
||||
unset($e); // ignore exception
|
||||
}
|
||||
if (!$ok) // can not insert it, try deleting it first
|
||||
{
|
||||
if (!isset($delete_stmt))
|
||||
{
|
||||
$delete_stmt = self::$pdo->prepare('DELETE FROM '.self::TABLE.' WHERE fs_id=:fs_id');
|
||||
}
|
||||
try {
|
||||
$ok = $delete_stmt->execute(array('fs_id' => $id)) && $stmt->execute($data);
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
unset($e); // ignore exception
|
||||
}
|
||||
}
|
||||
$msgs[] = $ok ? lang('Required directory "%1" created.', $path) :
|
||||
lang('Failed to create required directory "%1"!', $path);
|
||||
}
|
||||
}
|
||||
// check if directory is at least world readable and executable (r-x), we allow more but not less
|
||||
elseif (($stat['mode'] & 05) != 05)
|
||||
{
|
||||
if ($check_only)
|
||||
{
|
||||
$msgs[] = lang('Required directory "%1" has wrong mode %2 instead of %3!',
|
||||
$path, egw_vfs::int2mode($stat['mode']), egw_vfs::int2mode(05|0x4000));
|
||||
}
|
||||
else
|
||||
{
|
||||
$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_mode=:fs_mode WHERE fs_id=:fs_id');
|
||||
if (($ok = $stmt->execute(array(
|
||||
'fs_id' => $id,
|
||||
'fs_mode' => 05,
|
||||
))))
|
||||
{
|
||||
$msgs[] = lang('Mode of required directory "%1" changed to %2.', $path, egw_vfs::int2mode(05|0x4000));
|
||||
}
|
||||
else
|
||||
{
|
||||
$msgs[] = lang('Failed to change mode of required directory "%1" to %2!', $path, egw_vfs::int2mode(05|0x4000));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$check_only && $msgs)
|
||||
{
|
||||
global $oProc;
|
||||
if (!isset($oProc)) $oProc = new schema_proc();
|
||||
// PostgreSQL seems to require to update the sequenz, after manually inserting id's
|
||||
$oProc->UpdateSequence('egw_sqlfs', 'fs_id');
|
||||
}
|
||||
return $msgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and optionally remove files without content part in physical filesystem
|
||||
*
|
||||
* @param boolean $check_only=true
|
||||
* @return array with messages / found problems
|
||||
*/
|
||||
private static function fsck_fix_no_content($check_only=true)
|
||||
{
|
||||
$stmt = null;
|
||||
$msgs = array();
|
||||
foreach(self::$pdo->query('SELECT fs_id FROM '.self::TABLE.
|
||||
" WHERE fs_mime!='httpd/unix-directory' AND fs_content IS NULL AND fs_link IS NULL") as $row)
|
||||
{
|
||||
if (!file_exists($phy_path=self::_fs_path($row['fs_id'])))
|
||||
{
|
||||
$path = self::id2path($row['fs_id']);
|
||||
if ($check_only)
|
||||
{
|
||||
$msgs[] = lang('File %1 has no content in physical filesystem %2!',
|
||||
$path.' (#'.$row['fs_id'].')',$phy_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isset($stmt))
|
||||
{
|
||||
$stmt = self::$pdo->prepare('DELETE FROM '.self::TABLE.' WHERE fs_id=:fs_id');
|
||||
$stmt_props = self::$pdo->prepare('DELETE FROM '.self::PROPS_TABLE.' WHERE fs_id=:fs_id');
|
||||
}
|
||||
if ($stmt->execute(array('fs_id' => $row['fs_id'])) &&
|
||||
$stmt_props->execute(array('fs_id' => $row['fs_id'])))
|
||||
{
|
||||
$msgs[] = lang('File %1 has no content in physical filesystem %2 --> file removed!',$path,$phy_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
$msgs[] = lang('File %1 has no content in physical filesystem %2 --> failed to remove file!',
|
||||
$path.' (#'.$row['fs_id'].')',$phy_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($check_only && $msgs)
|
||||
{
|
||||
$msgs[] = lang('Files without content in physical filesystem will be removed.');
|
||||
}
|
||||
return $msgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of lost+found directory for unconnected nodes
|
||||
*/
|
||||
const LOST_N_FOUND = '/lost+found';
|
||||
const LOST_N_FOUND_MOD = 070;
|
||||
const LOST_N_FOUND_GRP = 'Admins';
|
||||
|
||||
/**
|
||||
* Check and optionally fix unconnected nodes - parent directory does not (longer) exists:
|
||||
*
|
||||
* SELECT fs.*
|
||||
* FROM egw_sqlfs fs
|
||||
* LEFT JOIN egw_sqlfs dir ON dir.fs_id=fs.fs_dir
|
||||
* WHERE fs.fs_id > 1 && dir.fs_id IS NULL
|
||||
*
|
||||
* @param boolean $check_only=true
|
||||
* @return array with messages / found problems
|
||||
*/
|
||||
private static function fsck_fix_unconnected($check_only=true)
|
||||
{
|
||||
$lostnfound = null;
|
||||
$msgs = array();
|
||||
foreach(self::$pdo->query('SELECT fs.* FROM '.self::TABLE.' fs'.
|
||||
' LEFT JOIN '.self::TABLE.' dir ON dir.fs_id=fs.fs_dir'.
|
||||
' WHERE fs.fs_id > 1 AND dir.fs_id IS NULL') as $row)
|
||||
{
|
||||
if ($check_only)
|
||||
{
|
||||
$msgs[] = lang('Found unconnected %1 %2!',
|
||||
mime_magic::mime2label($row['fs_mime']),
|
||||
egw_vfs::decodePath($row['fs_name']).' (#'.$row['fs_id'].')');
|
||||
continue;
|
||||
}
|
||||
if (!isset($lostnfound))
|
||||
{
|
||||
// check if we already have /lost+found, create it if not
|
||||
if (!($lostnfound = self::url_stat(self::LOST_N_FOUND, STREAM_URL_STAT_QUIET)))
|
||||
{
|
||||
egw_vfs::$is_root = true;
|
||||
if (!self::mkdir(self::LOST_N_FOUND, self::LOST_N_FOUND_MOD, 0) ||
|
||||
!(!($admins = $GLOBALS['egw']->accounts->name2id(self::LOST_N_FOUND_GRP)) ||
|
||||
self::chgrp(self::LOST_N_FOUND, $admins) && self::chmod(self::LOST_N_FOUND,self::LOST_N_FOUND_MOD)) ||
|
||||
!($lostnfound = self::url_stat(self::LOST_N_FOUND, STREAM_URL_STAT_QUIET)))
|
||||
{
|
||||
$msgs[] = lang("Can't create directory %1 to connect found unconnected nodes to it!",self::LOST_N_FOUND);
|
||||
}
|
||||
else
|
||||
{
|
||||
$msgs[] = lang('Successful created new directory %1 for unconnected nods.',self::LOST_N_FOUND);
|
||||
}
|
||||
egw_vfs::$is_root = false;
|
||||
if (!$lostnfound) break;
|
||||
}
|
||||
$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_dir=:fs_dir WHERE fs_id=:fs_id');
|
||||
}
|
||||
if ($stmt->execute(array(
|
||||
'fs_dir' => $lostnfound['ino'],
|
||||
'fs_id' => $row['fs_id'],
|
||||
)))
|
||||
{
|
||||
$msgs[] = lang('Moved unconnected %1 %2 to %3.',
|
||||
mime_magic::mime2label($row['fs_mime']),
|
||||
egw_vfs::decodePath($row['fs_name']).' (#'.$row['fs_id'].')',
|
||||
self::LOST_N_FOUND);
|
||||
}
|
||||
else
|
||||
{
|
||||
$msgs[] = lang('Failed to move unconnected %1 %2 to %3!',
|
||||
mime_magic::mime2label($row['fs_mime']), egw_vfs::decodePath($row['fs_name']), self::LOST_N_FOUND);
|
||||
}
|
||||
}
|
||||
if ($check_only && $msgs)
|
||||
{
|
||||
$msgs[] = lang('Unconnected nodes will be moved to %1.',self::LOST_N_FOUND);
|
||||
}
|
||||
return $msgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and optionally fix multiple active files and directories with identical path
|
||||
*
|
||||
* @param boolean $check_only=true
|
||||
* @return array with messages / found problems
|
||||
*/
|
||||
private static function fsck_fix_multiple_active($check_only=true)
|
||||
{
|
||||
$stmt = $inactivate_msg_added = null;
|
||||
$msgs = array();
|
||||
foreach(self::$pdo->query('SELECT fs_dir,fs_name,COUNT(*) FROM '.self::TABLE.
|
||||
' WHERE fs_active='.self::_pdo_boolean(true).
|
||||
' GROUP BY fs_dir,'.(self::$pdo_type == 'mysql' ? 'BINARY ' : '').'fs_name'. // fs_name is casesensitive!
|
||||
' HAVING COUNT(*) > 1') as $row)
|
||||
{
|
||||
if (!isset($stmt))
|
||||
{
|
||||
$stmt = self::$pdo->prepare('SELECT *,(SELECT COUNT(*) FROM '.self::TABLE.' sub WHERE sub.fs_dir=fs.fs_id) AS children'.
|
||||
' FROM '.self::TABLE.' fs'.
|
||||
' WHERE fs.fs_dir=:fs_dir AND fs.fs_active='.self::_pdo_boolean(true).' AND fs.fs_name'.self::$case_sensitive_equal.':fs_name'.
|
||||
" ORDER BY fs.fs_mime='httpd/unix-directory' DESC,children DESC,fs.fs_modified DESC");
|
||||
$inactivate_stmt = self::$pdo->prepare('UPDATE '.self::TABLE.
|
||||
' SET fs_active='.self::_pdo_boolean(false).
|
||||
' WHERE fs_dir=:fs_dir AND fs_active='.self::_pdo_boolean(true).
|
||||
' AND fs_name'.self::$case_sensitive_equal.':fs_name AND fs_id!=:fs_id');
|
||||
}
|
||||
//$msgs[] = array2string($row);
|
||||
$cnt = 0;
|
||||
$stmt->execute(array(
|
||||
'fs_dir' => $row['fs_dir'],
|
||||
'fs_name' => $row['fs_name'],
|
||||
));
|
||||
foreach($stmt as $n => $entry)
|
||||
{
|
||||
if ($entry['fs_mime'] == 'httpd/unix-directory')
|
||||
{
|
||||
if (!$n)
|
||||
{
|
||||
$dir = $entry; // directory to keep
|
||||
$msgs[] = lang('%1 directories %2 found!', $row[2], self::id2path($entry['fs_id']));
|
||||
if ($check_only) break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($entry['children'])
|
||||
{
|
||||
$msgs[] = lang('Moved %1 children from directory fs_id=%2 to %3',
|
||||
$children = self::$pdo->exec('UPDATE '.self::TABLE.' SET fs_dir='.(int)$dir['fs_id'].
|
||||
' WHERE fs_dir='.(int)$entry['fs_id']),
|
||||
$entry['fs_id'], $dir['fs_id']);
|
||||
|
||||
$dir['children'] += $children;
|
||||
}
|
||||
self::$pdo->query('DELETE FROM '.self::TABLE.' WHERE fs_id='.(int)$entry['fs_id']);
|
||||
$msgs[] = lang('Removed (now) empty directory fs_id=%1',$entry['fs_id']);
|
||||
}
|
||||
}
|
||||
elseif (isset($dir)) // file and directory with same name exist!
|
||||
{
|
||||
if (!$check_only)
|
||||
{
|
||||
$inactivate_stmt->execute(array(
|
||||
'fs_dir' => $row['fs_dir'],
|
||||
'fs_name' => $row['fs_name'],
|
||||
'fs_id' => $dir['fs_id'],
|
||||
));
|
||||
$cnt = $inactivate_stmt->rowCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
$cnt = ucfirst(lang('none of %1', $row[2]-1));
|
||||
}
|
||||
$msgs[] = lang('%1 active file(s) with same name as directory inactivated!',$cnt);
|
||||
break;
|
||||
}
|
||||
else // newest file --> set for all other fs_active=false
|
||||
{
|
||||
if (!$check_only)
|
||||
{
|
||||
$inactivate_stmt->execute(array(
|
||||
'fs_dir' => $row['fs_dir'],
|
||||
'fs_name' => $row['fs_name'],
|
||||
'fs_id' => $entry['fs_id'],
|
||||
));
|
||||
$cnt = $inactivate_stmt->rowCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
$cnt = lang('none of %1', $row[2]-1);
|
||||
}
|
||||
$msgs[] = lang('More then one active file %1 found, inactivating %2 older revisions!',
|
||||
self::id2path($entry['fs_id']), $cnt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($dir);
|
||||
if ($cnt && !isset($inactivate_msg_added))
|
||||
{
|
||||
$msgs[] = lang('To examine or reinstate inactived files, you might need to turn versioning on.');
|
||||
$inactivate_msg_added = true;
|
||||
}
|
||||
}
|
||||
return $msgs;
|
||||
}
|
||||
}
|
||||
|
||||
// fsck testcode, if this file is called via it's URL (you need to uncomment it!)
|
||||
/*if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__)
|
||||
{
|
||||
$GLOBALS['egw_info'] = array(
|
||||
'flags' => array(
|
||||
'currentapp' => 'admin',
|
||||
'nonavbar' => true,
|
||||
),
|
||||
);
|
||||
include_once '../../header.inc.php';
|
||||
|
||||
$msgs = sqlfs_utils::fsck(!isset($_GET['check_only']) || $_GET['check_only']);
|
||||
echo '<p>'.implode("</p>\n<p>", (array)$msgs)."</p>\n";
|
||||
}*/
|
||||
class sqlfs_utils extends Sqlfs\Utils {}
|
||||
|
@ -1624,16 +1624,44 @@ function json_php_unserialize($str, $allow_not_serialized=false)
|
||||
}
|
||||
|
||||
/**
|
||||
* php5 autoload function for eGroupWare understanding the following naming schema:
|
||||
* New PSR-4 autoloader for EGroupware
|
||||
*
|
||||
* class_exists('\\EGroupware\\Api\\Vfs'); // /api/src/Vfs.php
|
||||
* class_exists('\\EGroupware\\Api\\Vfs\\Dav\\Directory'); // /api/src/Vfs/Dav/Directory.php
|
||||
* class_exists('\\EGroupware\\Api\\Vfs\\Sqlfs\\StreamWrapper'); // /api/src/Vfs/Sqlfs/StreamWrapper.php
|
||||
* class_exists('\\EGroupware\\Api\\Vfs\\Sqlfs\\Utils'); // /api/src/Vfs/Sqlfs/Utils.php
|
||||
* class_exists('\\EGroupware\\Stylite\\Versioning\\StreamWrapper'); // /stylite/src/Versioning/StreamWrapper.php
|
||||
* class_exists('\\EGroupware\\Calendar\\Ui'); // /calendar/src/Ui.php
|
||||
* class_exists('\\EGroupware\\Calendar\\Ui\\Lists'); // /calendar/src/Ui/Lists.php
|
||||
* class_exists('\\EGroupware\\Calendar\\Ui\\Views'); // /calendar/src/Ui/Views.php
|
||||
*/
|
||||
spl_autoload_register(function($class)
|
||||
{
|
||||
$parts = explode('\\', $class);
|
||||
if (array_shift($parts) != 'EGroupware') return; // not our prefix
|
||||
|
||||
$app = lcfirst(array_shift($parts));
|
||||
$base = EGW_INCLUDE_ROOT.'/'.$app.'/src/';
|
||||
$path = $base.implode('/', $parts).'.php';
|
||||
|
||||
if (file_exists($path))
|
||||
{
|
||||
require_once $path;
|
||||
//error_log("PSR4_autoload('$class') --> require_once($path) --> class_exists('$class')=".array2string(class_exists($class,false)));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Old autoloader for EGroupware understanding the following naming schema:
|
||||
*
|
||||
* 1. new (prefered) nameing schema: app_class_something loading app/inc/class.class_something.inc.php
|
||||
* 2. API classes: classname loading phpgwapi/inc/class.classname.inc.php
|
||||
* 2a.API classes containing multiple classes per file eg. egw_exception* in class.egw_exception.inc.php
|
||||
* 3. eTemplate classes: classname loading etemplate/inc/class.classname.inc.php
|
||||
* 4. classes of the current app: classname loading $GLOBALS['egw_info']['flags']['currentapp']/inc/class.classname.inc.php
|
||||
*
|
||||
* @param string $class name of class to load
|
||||
*/
|
||||
function __autoload($class)
|
||||
spl_autoload_register(function($class)
|
||||
{
|
||||
// fixing warnings generated by php 5.3.8 is_a($obj) trying to autoload huge strings
|
||||
if (strlen($class) > 64 || strpos($class, '.') !== false) return;
|
||||
@ -1668,9 +1696,7 @@ function __autoload($class)
|
||||
{
|
||||
call_user_func($GLOBALS['egw_info']['flags']['autoload'],$class);
|
||||
}
|
||||
}
|
||||
// register our autoloader with sql, so other PHP code can use spl_autoload_register, without stalling our autoloader
|
||||
spl_autoload_register('__autoload');
|
||||
});
|
||||
|
||||
// if we have a Composer vendor directory, also load it's autoloader, to allow manage our requirements with Composer
|
||||
if (file_exists(EGW_SERVER_ROOT.'/vendor'))
|
||||
|
Loading…
Reference in New Issue
Block a user