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:
Ralf Becker 2015-01-26 09:15:07 +00:00
parent e9d851b143
commit 70b603ac77
13 changed files with 5008 additions and 4805 deletions

2116
api/src/Vfs.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,20 @@
<?php
/**
* eGroupWare API: VFS - stream wrapper to access the regular filesystem (setting a given user, group and mode)
* 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>
* @copyright (c) 2008-15 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @version $Id$
*/
namespace EGroupware\Api\Vfs\Filesystem;
use EGroupware\Api\Vfs;
/**
* eGroupWare API: VFS - stream wrapper to access the regular filesystem (setting a given user, group and mode)
*
@ -33,12 +37,12 @@
*
* (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
* To correctly support characters with special meaning in url's (#?%), we urlencode them with 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
class StreamWrapper implements Vfs\StreamWrapperIface
{
/**
* Scheme / protocol used for this stream-wrapper
@ -47,7 +51,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
/**
* 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 ;
const DIR_MIME_TYPE = Vfs::DIR_MIME_TYPE ;
/**
* mode-bits, which have to be set for files
@ -121,16 +125,18 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
*/
function stream_open ( $url, $mode, $options, &$opened_path )
{
unset($opened_path); // not used, but required by interface
$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);
$dir = 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
!Vfs::check_access($dir,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))
@ -140,7 +146,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
return false;
}
}
elseif (!$read_only && !egw_vfs::check_access($url,egw_vfs::WRITABLE,$stat)) // we are not allowed to edit it
elseif (!$read_only && !Vfs::check_access($url,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))
@ -160,7 +166,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
}
// open the "real" file
if (!($this->opened_stream = fopen($path=egw_vfs::decodePath(egw_vfs::parse_url($url,PHP_URL_PATH)),$mode,$options)))
if (!($this->opened_stream = fopen($path=Vfs::decodePath(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;
@ -302,10 +308,10 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
*/
static function unlink ( $url )
{
$path = egw_vfs::decodePath(egw_vfs::parse_url($url,PHP_URL_PATH));
$path = Vfs::decodePath(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 (!file_exists($path) || is_dir($path) || !Vfs::check_access(Vfs::dirname($url),Vfs::WRITABLE))
{
if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
return false; // no permission or file does not exist
@ -327,17 +333,17 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
*/
static function rename ( $url_from, $url_to )
{
$from = egw_vfs::parse_url($url_from);
$to = egw_vfs::parse_url($url_to);
$from = Vfs::parse_url($url_from);
$to = 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 (!($from_stat = self::url_stat($url_from,0)) || !Vfs::check_access(Vfs::dirname($url_from),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)))
$to_dir = Vfs::dirname($url_to);
if (!Vfs::check_access($to_dir,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
@ -357,12 +363,12 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
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 ($to_stat && !self::unlink($url_to))
{
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']));
return rename(Vfs::decodePath($from['path']),Vfs::decodePath($to['path']));
}
/**
@ -378,24 +384,26 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
*/
static function mkdir ( $url, $mode, $options )
{
$path = egw_vfs::decodePath(egw_vfs::parse_url($url,PHP_URL_PATH));
unset($mode); // not used, but required by interface
$path = Vfs::decodePath(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);
$parent_url = 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";
//echo __METHOD__."($url,$mode,$options) path=$path, recursive=$recursive, parent=$parent, Vfs::check_access(parent_url=$parent_url,Vfs::WRITABLE)=".(int)Vfs::check_access($parent_url,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 (file_exists($path) || !file_exists($parent) || !is_writable($parent) || !Vfs::check_access($parent_url,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
return mkdir($path, 0700, $recursive); // setting mode 0700 allows (only) apache to write into the dir
}
/**
@ -410,11 +418,13 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
*/
static function rmdir ( $url, $options )
{
$path = egw_vfs::decodePath(egw_vfs::parse_url($url,PHP_URL_PATH));
unset($options); // not used, but required by interface
$path = Vfs::decodePath(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 (!file_exists($path) || !is_writable($parent) || !Vfs::check_access(Vfs::dirname($url),Vfs::WRITABLE))
{
if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
return false;
@ -425,18 +435,18 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
/**
* 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!
* @param string $url
* @param int $time =null modification time (unix timestamp), default null = current time
* @param int $atime =null access time (unix timestamp), default null = current time, not implemented in the vfs!
* @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));
$path = Vfs::decodePath(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 (!file_exists($path) || !is_writable($parent) || !Vfs::check_access(Vfs::dirname($url),Vfs::WRITABLE))
{
if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
return false;
@ -450,11 +460,13 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
* Not supported, as it would require root rights!
*
* @param string $path
* @param string $mode mode string see egw_vfs::mode2int
* @param string $mode mode string see Vfs::mode2int
* @return boolean true on success, false otherwise
*/
static function chmod($path,$mode)
{
unset($path, $mode); // not used, but required by interface
return false;
}
@ -469,6 +481,8 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
*/
static function chown($path,$owner)
{
unset($path, $owner); // not used, but required by interface
return false;
}
@ -483,6 +497,8 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
*/
static function chgrp($path,$group)
{
unset($path, $group); // not used, but required by interface
return false;
}
@ -499,7 +515,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
$this->opened_dir = null;
$path = egw_vfs::decodePath(egw_vfs::parse_url($this->opened_dir_url = $url,PHP_URL_PATH));
$path = Vfs::decodePath(Vfs::parse_url($this->opened_dir_url = $url,PHP_URL_PATH));
// ToDo: check access rights
@ -539,18 +555,18 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
*/
static function url_stat ( $url, $flags )
{
$parts = egw_vfs::parse_url($url);
$path = egw_vfs::decodePath($parts['path']);
$parts = Vfs::parse_url($url);
$path = Vfs::decodePath($parts['path']);
$stat = @stat($path); // suppressed the stat failed warnings
if ($stat)
{
// set owner, group and mode from mount options
$uid = $gid = $mode = null;
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;
@ -561,7 +577,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
$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']));
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$flags) path=$path, mount_mode=".sprintf('0%o',$mode).", mode=".sprintf('0%o',$stat['mode']).'='.Vfs::int2mode($stat['mode']));
return $stat;
}
@ -587,7 +603,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
while ($ignore);
// encode special chars messing up url's
if ($file !== false) $file = egw_vfs::encodePathComponent($file);
if ($file !== false) $file = Vfs::encodePathComponent($file);
if (self::LOG_LEVEL > 1) error_log(__METHOD__.'() returning '.array2string($file));
@ -634,6 +650,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
*/
static function parse_query($query,&$uid,&$gid,&$mode)
{
$params = null;
parse_str(is_array($query) ? $query['query'] : $query,$params);
// setting the default perms root.root r-x for other
@ -690,7 +707,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
$gid = (int)$value;
break;
case 'mode':
$mode = egw_vfs::mode2int($value);
$mode = Vfs::mode2int($value);
break;
case 'url':
// ignored, only used for download_url method
@ -712,7 +729,8 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
*/
static function deny_script($url)
{
$parts = egw_vfs::parse_url($url);
$parts = Vfs::parse_url($url);
$get = null;
parse_str($parts['query'],$get);
$deny = !$get['exec'] && preg_match(self::SCRIPT_EXTENSIONS_PREG,$parts['path']);
@ -730,24 +748,26 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
* 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!
* @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)
static function download_url($_url,$force_download=false)
{
list(,$query) = explode('?',$url,2);
unset($force_download); // not used, but required by interface
list($url,$query) = explode('?',$_url,2);
$get = null;
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
if (!($mount_url = 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);
$download_url = Vfs::concat($get['url'],$relpath);
if ($download_url[0] == '/')
{
$download_url = ($_SERVER['HTTPS'] ? 'https://' : 'http://').
@ -757,6 +777,14 @@ class filesystem_stream_wrapper implements iface_stream_wrapper
//die(__METHOD__."('$url') --> relpath = $relpath --> $download_url");
return $download_url;
}
/**
* Register our stream-wrapper
*/
public static function register()
{
stream_register_wrapper(self::SCHEME, __CLASS__);
}
}
stream_register_wrapper(filesystem_stream_wrapper::SCHEME ,'filesystem_stream_wrapper');
StreamWrapper::register();

View File

@ -7,18 +7,26 @@
* @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: class.sqlfs_stream_wrapper.inc.php 24997 2008-03-02 21:44:15Z ralfbecker $
*/
namespace EGroupware\Api\Vfs\Links;
use EGroupware\Api\Vfs;
// explicitly import old phpgwapi classes used:
use egw_link;
use addressbook_vcal;
/**
* Define parent for links_stream_wrapper, if not already defined
* Define parent for Vfs\Links\StreamWrapper, if not already defined
*
* Allows to base links_stream_wrapper on an other wrapper
* Allows to base Vfs\Links\StreamWrapper on an other wrapper
*/
if (!class_exists('links_stream_wrapper_parent',false))
if (!class_exists('EGroupware\\Api\\Vfs\\Links\\LinksParent', false))
{
class links_stream_wrapper_parent extends sqlfs_stream_wrapper {}
class LinksParent extends Vfs\Sqlfs\StreamWrapper {}
}
/**
@ -42,7 +50,7 @@ if (!class_exists('links_stream_wrapper_parent',false))
*
* @link http://www.php.net/manual/en/function.stream-wrapper-register.php
*/
class links_stream_wrapper extends links_stream_wrapper_parent
class StreamWrapper extends LinksParent
{
/**
* Scheme / protocoll used for this stream-wrapper
@ -70,11 +78,11 @@ class links_stream_wrapper extends links_stream_wrapper_parent
*/
static function check_extended_acl($url,$check)
{
if (egw_vfs::$is_root)
if (Vfs::$is_root)
{
return true;
}
$path = egw_vfs::parse_url($url,PHP_URL_PATH);
$path = Vfs::parse_url($url,PHP_URL_PATH);
list(,$apps,$app,$id,$rel_path) = explode('/',$path,5);
@ -85,7 +93,7 @@ class links_stream_wrapper extends links_stream_wrapper_parent
}
elseif (!$app)
{
$access = !($check & egw_vfs::WRITABLE); // always grant read access to /apps
$access = !($check & Vfs::WRITABLE); // always grant read access to /apps
$what = '!$app';
}
elseif(!isset($GLOBALS['egw_info']['user']['apps'][$app]))
@ -104,11 +112,11 @@ class links_stream_wrapper extends links_stream_wrapper_parent
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.")";
$required = $check & Vfs::WRITABLE ? EGW_ACL_EDIT : EGW_ACL_READ;
$access = egw_link::file_access($app,$id,$required,$rel_path,Vfs::$user);
$what = "from egw_link::file_access('$app',$id,$required,'$rel_path,".Vfs::$user.")";
}
if (self::DEBUG) error_log(__METHOD__."($url,$check) user=".egw_vfs::$user." ($what) ".($access?"access granted ($app:$id:$rel_path)":'no access!!!'));
if (self::DEBUG) error_log(__METHOD__."($url,$check) user=".Vfs::$user." ($what) ".($access?"access granted ($app:$id:$rel_path)":'no access!!!'));
return $access;
}
@ -118,7 +126,7 @@ class links_stream_wrapper extends links_stream_wrapper_parent
* 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 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,
@ -131,7 +139,7 @@ class links_stream_wrapper extends links_stream_wrapper_parent
*/
static function url_stat ( $url, $flags )
{
$eacl_check=self::check_extended_acl($url,egw_vfs::READABLE);
$eacl_check=self::check_extended_acl($url,Vfs::READABLE);
// return vCard as /.entry
if ( $eacl_check && substr($url,-7) == '/.entry' &&
@ -140,7 +148,7 @@ class links_stream_wrapper extends links_stream_wrapper_parent
$ret = array(
'ino' => md5($url),
'name' => '.entry',
'mode' => self::MODE_FILE|egw_vfs::READABLE, // required by the stream wrapper
'mode' => self::MODE_FILE|Vfs::READABLE, // required by the stream wrapper
'size' => 1024, // fmail does NOT attach files with size 0!
'uid' => 0,
'gid' => 0,
@ -154,7 +162,7 @@ class links_stream_wrapper extends links_stream_wrapper_parent
// 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);
list(,/*$apps*/,/*$app*/,$id,$rel_path) = explode('/', Vfs::parse_url($url, PHP_URL_PATH), 5);
if ($id && !isset($rel_path))
{
$ret = array(
@ -168,7 +176,7 @@ class links_stream_wrapper extends links_stream_wrapper_parent
'ctime' => time(),
'nlink' => 2,
// eGW addition to return some extra values
'mime' => egw_vfs::DIR_MIME_TYPE,
'mime' => Vfs::DIR_MIME_TYPE,
);
}
}
@ -182,9 +190,9 @@ class links_stream_wrapper extends links_stream_wrapper_parent
* 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)
* @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)
@ -230,22 +238,22 @@ class links_stream_wrapper extends links_stream_wrapper_parent
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 : '');
if (strpos($path,'?') !== false) $query = Vfs::parse_url($path,PHP_URL_QUERY);
$path = 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
if ($apps == 'apps' && $app && !$id || self::check_extended_acl($path,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;
$current_is_root = Vfs::$is_root; Vfs::$is_root = true;
$current_user = Vfs::$user; 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;
Vfs::$user = $current_user;
Vfs::$is_root = $current_is_root;
}
//error_log(__METHOD__."($path,$mode,$options) apps=$apps, app=$app, id=$id: returning $ret");
return $ret;
@ -277,21 +285,20 @@ class links_stream_wrapper extends links_stream_wrapper_parent
(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)))
if (!($vcard =& $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
$this->opened_stream = fopen('php://temp', 'wb');
fwrite($this->opened_stream, $vcard);
fseek($this->opened_stream, 0, SEEK_SET);
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))
if ($mode[0] != 'r' && !parent::url_stat($dir = Vfs::dirname($url),0) && self::check_extended_acl($dir,Vfs::WRITABLE))
{
self::mkdir($dir,0,STREAM_MKDIR_RECURSIVE);
}
@ -303,7 +310,7 @@ class links_stream_wrapper extends links_stream_wrapper_parent
*
* 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 string $url URL that was passed to opendir() and that this object is expected to explore.
* @param $options
* @return booelan
*/
@ -316,6 +323,14 @@ class links_stream_wrapper extends links_stream_wrapper_parent
}
return parent::dir_opendir($url, $options);
}
/**
* Register this stream-wrapper
*/
public static function register()
{
stream_register_wrapper(self::SCHEME, __CLASS__);
}
}
stream_register_wrapper(links_stream_wrapper::SCHEME ,'links_stream_wrapper');
StreamWrapper::register();

File diff suppressed because it is too large Load Diff

483
api/src/Vfs/Sqlfs/Utils.php Normal file
View File

@ -0,0 +1,483 @@
<?php
/**
* EGroupware API: sqlfs stream wrapper utilities: migration db-fs, fsck
*
* @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-15 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @version $Id$
*/
namespace EGroupware\Api\Vfs\Sqlfs;
use EGroupware\Api\Vfs;
// explicitly import old phpgwapi classes used:
use mime_magic;
use egw_exception_assertion_failed;
/**
* sqlfs stream wrapper utilities: migration db-fs, fsck
*/
class Utils extends StreamWrapper
{
/**
* Migrate SQLFS content from DB to filesystem
*
* @param boolean $debug true to echo a message for each copied file
*/
static function migrate_db2fs($debug=false)
{
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';
$fs_id = $fs_name = $fs_size = $fs_content = null;
$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);
if ($stmt->execute())
{
$n = 0;
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))
{
$content = fopen('php://temp', 'wb');
fwrite($content, $fs_content);
fseek($content, 0, SEEK_SET);
unset($fs_content);
}
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=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) echo "$fs_id: $fs_name: $bytes bytes copied to fs\n";
fclose($dest);
fclose($content); unset($content);
++$n;
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 WHERE fs_content IS NOT 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, Vfs::int2mode($stat['mode']), 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, Vfs::int2mode(05|0x4000));
}
else
{
$msgs[] = lang('Failed to change mode of required directory "%1" to %2!', $path, 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']),
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)))
{
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);
}
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']),
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']), 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 = Utils::fsck(!isset($_GET['check_only']) || $_GET['check_only']);
echo '<p>'.implode("</p>\n<p>", (array)$msgs)."</p>\n";
}*/

View File

@ -1,16 +1,24 @@
<?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
* @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$
*/
namespace EGroupware\Api\Vfs;
use EGroupware\Api\Vfs;
// explicitly import old phpgwapi classes used:
use mime_magic;
use egw_exception_db;
/**
* eGroupWare API: VFS - stream wrapper interface
*
@ -19,7 +27,7 @@
*
* @link http://www.php.net/manual/en/function.stream-wrapper-register.php
*/
class vfs_stream_wrapper implements iface_stream_wrapper
class StreamWrapper implements StreamWrapperIface
{
/**
* Scheme / protocol used for this stream-wrapper
@ -224,7 +232,7 @@ class vfs_stream_wrapper implements iface_stream_wrapper
{
self::load_wrapper($scheme);
}
$url = egw_vfs::concat($url,substr($parts['path'],strlen($mounted)));
$url = Vfs::concat($url,substr($parts['path'],strlen($mounted)));
if ($replace_user_pass_host)
{
@ -703,7 +711,7 @@ class vfs_stream_wrapper implements iface_stream_wrapper
* Requires owner or root rights!
*
* @param string $path
* @param string $mode mode string see egw_vfs::mode2int
* @param string $mode mode string see Vfs::mode2int
* @return boolean true on success, false otherwise
*/
static function chmod($path,$mode)
@ -845,15 +853,15 @@ class vfs_stream_wrapper implements iface_stream_wrapper
if (self::LOG_LEVEL > 0) error_log(__METHOD__."( $path,$options) opendir($this->opened_dir_url) failed!");
return false;
}
$this->opened_dir_writable = egw_vfs::check_access($this->opened_dir_url,egw_vfs::WRITABLE);
$this->opened_dir_writable = Vfs::check_access($this->opened_dir_url,Vfs::WRITABLE);
// check our fstab if we need to add some of the mountpoints
$basepath = self::parse_url($path,PHP_URL_PATH);
foreach(array_keys(self::$fstab) as $mounted)
{
if (((egw_vfs::dirname($mounted) == $basepath || egw_vfs::dirname($mounted).'/' == $basepath) && $mounted != '/') &&
if (((Vfs::dirname($mounted) == $basepath || Vfs::dirname($mounted).'/' == $basepath) && $mounted != '/') &&
// only return children readable by the user, if dir is not writable
(!self::HIDE_UNREADABLES || $this->opened_dir_writable ||
egw_vfs::check_access($mounted,egw_vfs::READABLE)))
Vfs::check_access($mounted,Vfs::READABLE)))
{
$this->extra_dirs[] = basename($mounted);
}
@ -918,9 +926,9 @@ class vfs_stream_wrapper implements iface_stream_wrapper
{
if ($lpath[0] != '/') // concat relative path
{
$lpath = egw_vfs::concat(self::parse_url($path,PHP_URL_PATH),'../'.$lpath);
$lpath = Vfs::concat(self::parse_url($path,PHP_URL_PATH),'../'.$lpath);
}
$url = egw_vfs::PREFIX.$lpath;
$url = Vfs::PREFIX.$lpath;
if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path,$flags) symlif (substr($path,-1) == '/' && $path != '/') $path = substr($path,0,-1); // remove trailing slash eg. added by WebDAVink found and resolved to $url");
// try reading the stat of the link
if (($stat = self::url_stat($lpath, STREAM_URL_STAT_QUIET, false, true, $check_symlink_depth-1)))
@ -934,19 +942,19 @@ class vfs_stream_wrapper implements iface_stream_wrapper
}
catch (egw_exception_db $e) {
// some long running operations, eg. merge-print, run into situation that DB closes our separate sqlfs connection
// we try now to reconnect sqlfs_stream_wrapper once
// we try now to reconnect Vfs\Sqlfs\StreamWrapper once
// it's done here in vfs_stream_wrapper as situation can happen in sqlfs, links, stylite.links or stylite.versioning
if ($try_reconnect)
{
// reconnect to db
sqlfs_stream_wrapper::reconnect();
Vfs\Sqlfs\StreamWrapper::reconnect();
return self::url_stat($path, $flags, $try_create_home, $check_symlink_components, $check_symlink_depth, false);
}
// if numer of tries is exceeded, re-throw exception
throw $e;
}
// check if a failed url_stat was for a home dir, in that case silently create it
if (!$stat && $try_create_home && egw_vfs::dirname(self::parse_url($path,PHP_URL_PATH)) == '/home' &&
if (!$stat && $try_create_home && Vfs::dirname(self::parse_url($path,PHP_URL_PATH)) == '/home' &&
($id = $GLOBALS['egw']->accounts->name2id(basename($path))) &&
$GLOBALS['egw']->accounts->id2name($id) == basename($path)) // make sure path has the right case!
{
@ -979,8 +987,8 @@ class vfs_stream_wrapper implements iface_stream_wrapper
/* 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(egw_vfs::dirname($path,egw_vfs::WRITABLE)))
if (self::HIDE_UNREADABLES && !Vfs::check_access($path,Vfs::READABLE,$stat) &&
!Vfs::check_access(Vfs::dirname($path,Vfs::WRITABLE)))
{
return false;
}
@ -1004,8 +1012,8 @@ class vfs_stream_wrapper implements iface_stream_wrapper
}
if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url'): ".function_backtrace(1));
while (($rel_path = egw_vfs::basename($url).($rel_path ? '/'.$rel_path : '')) &&
($url = egw_vfs::dirname($url)))
while (($rel_path = Vfs::basename($url).($rel_path ? '/'.$rel_path : '')) &&
($url = Vfs::dirname($url)))
{
if (($stat = self::url_stat($url,0,false,false)))
{
@ -1015,14 +1023,14 @@ class vfs_stream_wrapper implements iface_stream_wrapper
if ($lpath[0] != '/')
{
$lpath = egw_vfs::concat(self::parse_url($url,PHP_URL_PATH),'../'.$lpath);
$lpath = Vfs::concat(self::parse_url($url,PHP_URL_PATH),'../'.$lpath);
}
//self::symlinkCache_add($path,egw_vfs::PREFIX.$lpath);
$url = egw_vfs::PREFIX.egw_vfs::concat($lpath,$rel_path);
//self::symlinkCache_add($path,Vfs::PREFIX.$lpath);
$url = Vfs::PREFIX.Vfs::concat($lpath,$rel_path);
if (self::LOG_LEVEL > 1) error_log("$log --> lpath='$lpath', url='$url'");
return self::url_stat($url,$flags);
}
$url = egw_vfs::concat($url,$rel_path);
$url = Vfs::concat($url,$rel_path);
if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url') returning null");
return null;
}
@ -1110,10 +1118,10 @@ class vfs_stream_wrapper implements iface_stream_wrapper
/**
* Clears our internal stat and symlink cache
*
* Normaly not necessary, as it is automatically cleared/updated, UNLESS egw_vfs::$user changes!
* Normaly not necessary, as it is automatically cleared/updated, UNLESS Vfs::$user changes!
*
* We have to clear the symlink cache before AND after calling the backend,
* because auf traversal rights may be different when egw_vfs::$user changes!
* because auf traversal rights may be different when Vfs::$user changes!
*
* @param string $path ='/' path of backend, whos cache to clear
*/
@ -1150,7 +1158,7 @@ class vfs_stream_wrapper implements iface_stream_wrapper
while($file !== false &&
(is_array($this->extra_dirs) && in_array($file,$this->extra_dirs) || // do NOT return extra_dirs twice
self::HIDE_UNREADABLES && !$this->opened_dir_writable &&
!egw_vfs::check_access(egw_vfs::concat($this->opened_dir_url,$file),egw_vfs::READABLE)));
!Vfs::check_access(Vfs::concat($this->opened_dir_url,$file),Vfs::READABLE)));
}
if (self::LOG_LEVEL > 1) error_log(__METHOD__."( $this->opened_dir ) = '$file'");
return $file;
@ -1247,7 +1255,16 @@ class vfs_stream_wrapper implements iface_stream_wrapper
*/
static function scheme2class($scheme)
{
return str_replace('.','_',$scheme).'_stream_wrapper';
list($app, $app_scheme) = explode('.', $scheme);
foreach(array(
empty($app_scheme) ? 'EGroupware\\Api\\Vfs\\'.ucfirst($scheme).'\\StreamWrapper' : // streamwrapper in Api\Vfs
'EGroupware\\'.ucfirst($app).'\\Vfs\\'.ucfirst($app_scheme).'\\StreamWrapper', // streamwrapper in $app\Vfs
str_replace('.','_',$scheme).'_stream_wrapper', // old (flat) name
) as $class)
{
//error_log(__METHOD__."('$scheme') class_exists('$class')=".array2string(class_exists($class)));
if (class_exists($class)) return $class;
}
}
/**
@ -1360,4 +1377,4 @@ class vfs_stream_wrapper implements iface_stream_wrapper
}
}
vfs_stream_wrapper::init_static();
StreamWrapper::init_static();

View File

@ -0,0 +1,250 @@
<?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
* @version $Id$
*/
namespace EGroupware\Api\Vfs;
/**
* 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
*/
interface StreamWrapperIface
{
/**
* 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 ( );
}

View File

@ -624,7 +624,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

View File

@ -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 {}

File diff suppressed because it is too large Load Diff

View File

@ -7,474 +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=false)
{
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';
$fs_id = $fs_name = $fs_size = $fs_content = null;
$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);
if ($stmt->execute())
{
$n = 0;
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) echo "$fs_id: $fs_name: $bytes bytes copied to fs\n";
fclose($dest);
fclose($content); unset($content);
++$n;
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 WHERE fs_content IS NOT 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 {}

View File

@ -1616,16 +1616,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;
@ -1660,9 +1688,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'))