"VFS bugfixes:

- fixed not working creation, rename and deletion of user- and group-dirs
- WebDAV showed all user- and group-dirs in /home and not only the ones the user has read access too"
This commit is contained in:
Ralf Becker 2007-04-29 12:06:17 +00:00
parent 335b0eb97a
commit 410dadba14
2 changed files with 215 additions and 10 deletions

View File

@ -0,0 +1,204 @@
<?php
/**
* eGroupWare API: VFS - Homedirectories
*
* @link http://www.egroupware.org
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package api
* @subpackage vfs
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2007 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @version $Id$
*/
require_once(EGW_API_INC.'/class.vfs.inc.php');
/**
* eGroupWare API: VFS - Homedirectories
*
* This class implements some necessary stuff for user- and group-directories ontop the vfs class.
*
* Some of it is already implemented in the filemanager app, but it's also needed for the WebDAV access:
* - show only directories in /home, to which the user has at least read-access
*
* Stuff dealing with creation, renaming or deletion of users via some hooks from admin:
* - create the homedir if a new user gets created
* - rename the homedir if the user-name changes
* - delete the homedir or copy its content to an other users homedir, if a user gets deleted
* --> these hooks are registered via phpgwapi/setup/setup.inc.php and called by the admin app
*/
class vfs_home extends vfs
{
/**
* List a directory, reimplemented to hide dirs the user has no rights to read
*
* @param array $data
* @param string $data['string'] path
* @param array $data['relatives'] Relativity array (default: RELATIVE_CURRENT)
* @param boolean $data['checksubdirs'] If true return information for all subdirectories recursively
* @param string $data['mime'] Only return information for locations with MIME type specified (eg. 'Directory')
* @param boolean $data['nofiles'] If set and $data['string'] is a directory, return information about the directory, not the files in it.
* @return array of arrays of file information.
*/
function ls($data)
{
//error_log("vfs_home(".print_r($data,true).")");
$fileinfos = parent::ls($data);
if (!$this->override_acl && !$data['nofiles'] && ($data['string'] == $this->fakebase || $data['string'].$this->fakebase.'/'))
{
//error_log("vfs_home() grants=".print_r($this->grants,true));
// remove directories the user has no rights to see, no grant from the owner
foreach($fileinfos as $key => $info)
{
//error_log("vfs_home() ".(!$this->grants[$info['owner_id']] ? 'hidding' : 'showing')." $info[directory]/$info[name] (owner=$info[owner_id])");
if (!$this->grants[$info['owner_id']])
{
unset($fileinfos[$key]);
}
}
}
return $fileinfos;
}
/**
* Hook called after new accounts have been added
*
* @param array $data
* @param int $data['account_id'] numerical id
* @param string $data['account_lid'] account-name
*/
function addAccount($data)
{
// create a user-dir
$save_id = $this->working_id;
$this->working_id = $data['account_id'];
$save_currentapp = $GLOBALS['egw_info']['flags']['currentapp'];
$GLOBALS['egw_info']['flags']['currentapp'] = 'filemanager';
$this->override_acl = true;
$this->mkdir(array(
'string' => $this->fakebase.'/'.$data['account_lid'],
'relatives' => array(RELATIVE_ROOT),
));
$this->override_acl = false;
$this->working_id = $save_id;
$GLOBALS['egw_info']['flags']['currentapp'] = $currentapp;
}
/**
* Hook called after accounts has been modified
*
* @param array $data
* @param int $data['account_id'] numerical id
* @param string $data['account_lid'] new account-name
* @param string $data['old_loginid'] old account-name
*/
function editAccount($data)
{
if ($data['account_lid'] == $data['old_loginid']) return; // nothing to do here
// rename the user-dir
$this->override_acl = true;
$this->mv(array(
'from' => $this->fakebase.'/'.$data['old_loginid'],
'to' => $this->fakebase.'/'.$data['account_lid'],
'relatives' => array(RELATIVE_ROOT,RELATIVE_ROOT),
));
$this->override_acl = false;
}
/**
* Hook called before an account get deleted
*
* @param array $data
* @param int $data['account_id'] numerical id
* @param string $data['account_lid'] account-name
* @param int $data['new_owner'] account-id of new owner, or false if data should get deleted
*/
function deleteAccount($data)
{
if ($data['new_owner'])
{
// ToDo: copy content of user-dir to new owner's user-dir
}
// delete the user-directory
$this->override_acl = true;
$this->delete(array(
'string' => $this->fakebase.'/'.$data['account_lid'],
'relatives' => array(RELATIVE_ROOT),
));
$this->override_acl = false;
}
/**
* Hook called after new groups have been added
*
* @param array $data
* @param int $data['account_id'] numerical id
* @param string $data['account_name'] group-name
*/
function addGroup($data)
{
// create a group-dir
$save_id = $this->working_id;
$this->working_id = $data['account_id'];
$save_currentapp = $GLOBALS['egw_info']['flags']['currentapp'];
$GLOBALS['egw_info']['flags']['currentapp'] = 'filemanager';
$this->override_acl = true;
$this->mkdir(array(
'string' => $this->fakebase.'/'.$data['account_name'],
'relatives' => array(RELATIVE_ROOT),
));
$this->override_acl = false;
$this->working_id = $save_id;
$GLOBALS['egw_info']['flags']['currentapp'] = $currentapp;
}
/**
* Hook called after group has been modified
*
* @param array $data
* @param int $data['account_id'] numerical id
* @param string $data['account_name'] new group-name
* @param string $data['old_name'] old account-name
*/
function editGroup($data)
{
if ($data['account_name'] == $data['old_name']) return; // nothing to do here
// rename the group-dir
$this->override_acl = true;
$this->mv(array(
'from' => $this->fakebase.'/'.$data['old_name'],
'to' => $this->fakebase.'/'.$data['account_name'],
'relatives' => array(RELATIVE_ROOT,RELATIVE_ROOT),
));
$this->override_acl = false;
}
/**
* Hook called before a group get deleted
*
* @param array $data
* @param int $data['account_id'] numerical id
* @param string $data['account_name'] account-name
*/
function deleteGroup($data)
{
// delete the group-directory
$this->override_acl = true;
$this->delete(array(
'string' => $this->fakebase.'/'.$data['account_name'],
'relatives' => array(RELATIVE_ROOT),
));
$this->override_acl = false;
}
}

View File

@ -1,32 +1,33 @@
<?php <?php
/** /**
* FileManger - WebDAV access * eGroupWare API: VFS - WebDAV access
* *
* Using the PEAR HTTP/WebDAV/Server class (which need to be installed!) * Using the PEAR HTTP/WebDAV/Server class (which need to be installed!)
* *
* @link http://www.egroupware.org * @link http://www.egroupware.org
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package filemanger * @package api
* @subpackage vfs
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2006 by Ralf Becker <RalfBecker-AT-outdoor-training.de> * @copyright (c) 2006 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @version $Id: class.boetemplate.inc.php 21437 2006-04-24 20:42:42Z ralfbecker $ * @version $Id$
*/ */
require_once('HTTP/WebDAV/Server.php'); require_once('HTTP/WebDAV/Server.php');
require_once(EGW_API_INC.'/class.vfs_home.inc.php');
/** /**
* FileManger - WebDAV access * FileManger - WebDAV access
* *
* Using the PEAR HTTP/WebDAV/Server class (which need to be installed!) * Using the PEAR HTTP/WebDAV/Server class (which need to be installed!)
*
* @package filemanger
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2006 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
*/ */
class vfs_webdav_server extends HTTP_WebDAV_Server class vfs_webdav_server extends HTTP_WebDAV_Server
{ {
/**
* instance of the vfs class
*
* @var vfs_home
*/
var $vfs; var $vfs;
var $dav_powered_by = 'eGroupWare WebDAV server'; var $dav_powered_by = 'eGroupWare WebDAV server';
@ -46,7 +47,7 @@ class vfs_webdav_server extends HTTP_WebDAV_Server
parent::HTTP_WebDAV_Server(); parent::HTTP_WebDAV_Server();
$this->vfs =& CreateObject('phpgwapi.vfs'); $this->vfs =& new vfs_home;
} }
/** /**