2001-01-11 10:52:33 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2004-05-05 14:06:13 +02:00
|
|
|
* eGroupWare API - Access Control List *
|
2001-01-13 11:18:50 +01:00
|
|
|
* This file written by Dan Kuykendall <seek3r@phpgroupware.org> *
|
|
|
|
* Security scheme based on ACL design *
|
|
|
|
* Copyright (C) 2000, 2001 Dan Kuykendall *
|
|
|
|
* -------------------------------------------------------------------------*
|
2004-05-05 14:06:13 +02:00
|
|
|
* This library is part of the eGroupWare API *
|
|
|
|
* http://www.egroupware.org/api *
|
2001-01-16 14:52:32 +01:00
|
|
|
* ------------------------------------------------------------------------ *
|
2001-01-13 11:18:50 +01:00
|
|
|
* This library is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, *
|
|
|
|
* or any later version. *
|
|
|
|
* This library is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
|
|
* See the GNU Lesser General Public License for more details. *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this library; if not, write to the Free Software Foundation, *
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
2001-01-11 10:52:33 +01:00
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
2001-05-02 14:28:10 +02:00
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
2005-07-22 11:05:01 +02:00
|
|
|
* Access Control List System
|
|
|
|
*
|
|
|
|
* This class provides an ACL security scheme.
|
|
|
|
* This can manage rights to 'run' applications, and limit certain features within an application.
|
|
|
|
* It is also used for granting a user "membership" to a group, or making a user have the security equivilance of another user.
|
|
|
|
* It is also used for granting a user or group rights to various records, such as todo or calendar items of another user.
|
|
|
|
* $acl =& CreateObject('phpgwapi.acl',5); // 5 is the user id
|
|
|
|
*
|
|
|
|
* @author Seek3r and others
|
|
|
|
* @copyright LGPL
|
|
|
|
* @package api
|
|
|
|
* @subpackage accounts
|
|
|
|
* @access public
|
2005-03-12 17:30:25 +01:00
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
class acl
|
2001-12-11 02:14:43 +01:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
|
|
|
* @var int $account_id the account-id this class is instanciated for
|
|
|
|
*/
|
|
|
|
var $account_id = 0;
|
|
|
|
/**
|
|
|
|
* @var $account_type
|
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
var $account_type;
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
|
|
|
* @var array $data internal repository with acl rows for the given app and account-id (incl. memberships)
|
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
var $data = Array();
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
2006-10-15 11:21:59 +02:00
|
|
|
* internal copy of the db-object
|
|
|
|
*
|
|
|
|
* @var egw_db
|
2005-03-12 17:30:25 +01:00
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
var $db;
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
|
|
|
* @var string $table_name name of the acl_table
|
|
|
|
*/
|
2005-11-02 12:45:52 +01:00
|
|
|
var $table_name = 'egw_acl';
|
2001-01-20 00:45:37 +01:00
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
|
|
|
* ACL constructor for setting account id
|
|
|
|
*
|
2005-04-13 10:53:42 +02:00
|
|
|
* Sets the ID for $acl->account_id. Can be used to change a current instances id as well.
|
|
|
|
* Some functions are specific to this account, and others are generic.
|
|
|
|
*
|
|
|
|
* @example acl->acl(5); // 5 is the user id
|
2005-03-12 17:30:25 +01:00
|
|
|
* @param int $account_id int-the user id
|
|
|
|
*/
|
2005-03-12 18:55:48 +01:00
|
|
|
function acl($account_id = '')
|
2001-03-21 06:09:14 +01:00
|
|
|
{
|
2005-11-24 21:48:31 +01:00
|
|
|
if (is_object($GLOBALS['egw_setup']->db))
|
|
|
|
{
|
|
|
|
$this->db = clone($GLOBALS['egw_setup']->db);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->db = clone($GLOBALS['egw']->db);
|
|
|
|
}
|
2005-03-07 17:59:32 +01:00
|
|
|
$this->db->set_app('phpgwapi');
|
|
|
|
|
2003-12-14 18:07:16 +01:00
|
|
|
if ((int)$this->account_id != (int)$account_id)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-07 18:06:01 +01:00
|
|
|
$this->account_id = get_account_id((int)$account_id,@$GLOBALS['egw_info']['user']['account_id']);
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
2001-03-21 06:09:14 +01:00
|
|
|
}
|
2001-01-20 00:45:37 +01:00
|
|
|
|
2003-10-18 13:15:48 +02:00
|
|
|
function DONTlist_methods($_type='xmlrpc')
|
2003-05-17 22:26:49 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
This handles introspection or discovery by the logged in client,
|
|
|
|
in which case the input might be an array. The server always calls
|
|
|
|
this function to fill the server dispatch map using a string.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (is_array($_type))
|
|
|
|
{
|
|
|
|
$_type = $_type['type'] ? $_type['type'] : $_type[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
switch($_type)
|
|
|
|
{
|
|
|
|
case 'xmlrpc':
|
|
|
|
$xml_functions = array(
|
|
|
|
'read_repository' => array(
|
|
|
|
'function' => 'read_repository',
|
|
|
|
'signature' => array(array(xmlrpcStruct)),
|
|
|
|
'docstring' => lang('FIXME!')
|
|
|
|
),
|
|
|
|
'get_rights' => array(
|
|
|
|
'function' => 'get_rights',
|
|
|
|
'signature' => array(array(xmlrpcStruct,xmlrpcStruct)),
|
|
|
|
'docstring' => lang('FIXME!')
|
|
|
|
|
|
|
|
),
|
|
|
|
'list_methods' => array(
|
|
|
|
'function' => 'list_methods',
|
|
|
|
'signature' => array(array(xmlrpcStruct,xmlrpcString)),
|
|
|
|
'docstring' => lang('Read this list of methods.')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return $xml_functions;
|
|
|
|
break;
|
|
|
|
case 'soap':
|
|
|
|
return $this->soap_functions;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return array();
|
|
|
|
break;
|
|
|
|
}
|
2003-10-18 13:15:48 +02:00
|
|
|
}
|
2003-05-17 22:26:49 +02:00
|
|
|
|
2001-05-02 14:28:10 +02:00
|
|
|
/**************************************************************************\
|
|
|
|
* These are the standard $this->account_id specific functions *
|
|
|
|
\**************************************************************************/
|
2001-01-20 00:45:37 +01:00
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
2005-04-13 10:53:42 +02:00
|
|
|
* Read acl records for $acl->account_id from reposity
|
2005-03-12 17:30:25 +01:00
|
|
|
*
|
2005-04-13 10:53:42 +02:00
|
|
|
* @internal
|
|
|
|
* @return array along with storing it in $acl->data. <br>
|
2005-03-12 17:30:25 +01:00
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function read_repository()
|
|
|
|
{
|
2003-05-17 22:26:49 +02:00
|
|
|
// For some reason, calling this via XML-RPC doesn't call the constructor.
|
|
|
|
// Here is yet another work around(tm) (jengo)
|
2005-03-12 17:30:25 +01:00
|
|
|
if (!$this->account_id)
|
2003-05-17 22:26:49 +02:00
|
|
|
{
|
|
|
|
$this->acl();
|
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
$acl_acc_list = $GLOBALS['egw']->accounts->memberships($this->account_id,true);
|
2006-12-25 12:02:54 +01:00
|
|
|
@array_unshift($acl_acc_list,$this->account_id);
|
2005-04-13 10:53:42 +02:00
|
|
|
$this->db->select($this->table_name,'*',array('acl_account' => $acl_acc_list ),__LINE__,__FILE__);
|
|
|
|
|
2001-05-02 14:28:10 +02:00
|
|
|
$this->data = Array();
|
2006-10-15 11:21:59 +02:00
|
|
|
while(($row = $this->db->row(true,'acl_')))
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2006-10-15 11:21:59 +02:00
|
|
|
$this->data[$row['appname'].'-'.$row['location'].'-'.$row['account']] = $row;
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
return $this->data;
|
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
|
|
|
* Read acl records from $acl->data
|
|
|
|
*
|
|
|
|
* @return array all ACL records from $this->data.
|
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function read()
|
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
if (!count($this->data))
|
2001-12-11 02:14:43 +01:00
|
|
|
{
|
|
|
|
$this->read_repository();
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
return $this->data;
|
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
|
|
|
* Adds ACL record to the repository of the class
|
|
|
|
*
|
|
|
|
* Adds ACL record to $this->data.
|
|
|
|
*
|
|
|
|
* @param string $appname default False derives value from $GLOBALS['egw_info']['flags']['currentapp']
|
|
|
|
* @param string $location location
|
|
|
|
* @param int $rights rights
|
|
|
|
* @return array all ACL records from $this->data.
|
|
|
|
*/
|
|
|
|
function add($appname,$location,$rights)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
|
2006-10-15 11:21:59 +02:00
|
|
|
$row = array(
|
2005-03-12 17:30:25 +01:00
|
|
|
'appname' => $appname,
|
|
|
|
'location' => $location,
|
|
|
|
'account' => (int) $this->account_id,
|
|
|
|
'rights' => (int) $rights
|
|
|
|
);
|
2006-10-15 11:21:59 +02:00
|
|
|
$this->data[$row['appname'].'-'.$row['location'].'-'.$row['account']] = $row;
|
2005-03-12 17:30:25 +01:00
|
|
|
|
2001-05-02 14:28:10 +02:00
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
|
|
|
* Delete ACL record in the repository of the class
|
|
|
|
*
|
|
|
|
* @param string $appname appname or '' for $GLOBALS['egw_info']['flags']['currentapp']
|
2006-06-07 01:42:36 +02:00
|
|
|
* @param string/boolean $location location or false for all locations
|
2005-03-12 17:30:25 +01:00
|
|
|
* @return array all ACL records from $this->data.
|
|
|
|
*/
|
|
|
|
function delete($appname,$location)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
|
|
|
|
foreach($this->data as $idx => $value)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2006-10-15 11:21:59 +02:00
|
|
|
if ($value['appname'] == $appname &&
|
|
|
|
($location === false || $value['location'] == $location) &&
|
|
|
|
$value['account'] == $this->account_id)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
unset($this->data[$idx]);
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->data;
|
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
|
|
|
* save the internal repository or the class
|
|
|
|
*
|
|
|
|
* @return array all ACL records from $this->data.
|
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function save_repository()
|
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
$this->db->delete($this->table_name,array(
|
|
|
|
'acl_account' => $this->account_id,
|
|
|
|
),__LINE__,__FILE__);
|
2001-05-02 14:28:10 +02:00
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
foreach($this->data as $value)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
if ($value['account'] == $this->account_id)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
$this->db->insert($this->table_name,array(
|
|
|
|
'acl_appname' => $value['appname'],
|
|
|
|
'acl_location' => $value['location'],
|
|
|
|
'acl_account' => $this->account_id,
|
|
|
|
'acl_rights' => $value['rights'],
|
|
|
|
),false,__LINE__,__FILE__);
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
}
|
2005-11-24 21:08:09 +01:00
|
|
|
if ($this->account_id == $GLOBALS['egw_info']['user']['account_id'] &&
|
|
|
|
method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited
|
2005-07-22 11:05:01 +02:00
|
|
|
{
|
|
|
|
$GLOBALS['egw']->invalidate_session_cache();
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************\
|
|
|
|
* These are the non-standard $this->account_id specific functions *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
|
|
|
* get rights from the class repository (included rights of $this->account_id and all it's memberships)
|
|
|
|
*
|
|
|
|
* @param string $location app location to get rights from
|
|
|
|
* @param string $appname optional defaults to $GLOBALS['egw_info']['flags']['currentapp'];
|
2005-03-29 17:30:08 +02:00
|
|
|
* @return int all rights or'ed together
|
2005-03-12 17:30:25 +01:00
|
|
|
*/
|
|
|
|
function get_rights($location,$appname = '')
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2003-05-17 22:26:49 +02:00
|
|
|
// For XML-RPC, change this once its working correctly for passing parameters (jengo)
|
|
|
|
if (is_array($location))
|
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
$appname = $location['appname'];
|
|
|
|
$location = $location['location'];
|
2003-05-17 22:26:49 +02:00
|
|
|
}
|
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
if (!count($this->data))
|
2001-12-11 02:14:43 +01:00
|
|
|
{
|
|
|
|
$this->read_repository();
|
|
|
|
}
|
2005-03-12 17:30:25 +01:00
|
|
|
if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
|
|
|
|
if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny')
|
2001-12-11 02:14:43 +01:00
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
$rights = 0;
|
2005-03-12 17:30:25 +01:00
|
|
|
foreach($this->data as $idx => $value)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
if ($value['appname'] == $appname)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
if ($value['location'] == $location || $value['location'] == 'everywhere')
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
if ($value['rights'] == 0)
|
2001-12-11 02:14:43 +01:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2005-03-12 17:30:25 +01:00
|
|
|
$rights |= $value['rights'];
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $rights;
|
|
|
|
}
|
2005-03-12 17:30:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* check required rights agains the internal repository (included rights of $this->account_id and all it's memberships)
|
|
|
|
*
|
|
|
|
* @param $location app location
|
|
|
|
* @param $required required right to check against
|
|
|
|
* @param $appname optional defaults to currentapp
|
2005-03-29 17:30:08 +02:00
|
|
|
* @return boolean
|
2005-03-12 17:30:25 +01:00
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function check($location, $required, $appname = False)
|
|
|
|
{
|
|
|
|
$rights = $this->get_rights($location,$appname);
|
2005-03-12 17:30:25 +01:00
|
|
|
|
2001-05-02 14:28:10 +02:00
|
|
|
return !!($rights & $required);
|
|
|
|
}
|
2005-03-12 17:30:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get specific rights for this->account_id for an app location
|
|
|
|
*
|
|
|
|
* @param string $location app location
|
2005-11-02 12:45:52 +01:00
|
|
|
* @param string $appname='' optional defaults to currentapp
|
|
|
|
* @param int $account_id=0 optional defaults to $this->account_id
|
2005-03-12 17:30:25 +01:00
|
|
|
* @return int $rights
|
|
|
|
*/
|
|
|
|
function get_specific_rights($location, $appname = '')
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
|
2001-05-02 14:28:10 +02:00
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny')
|
2001-12-11 02:14:43 +01:00
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
$rights = 0;
|
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
foreach($this->data as $idx => $value)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
if ($value['appname'] == $appname &&
|
|
|
|
($value['location'] == $location || $value['location'] == 'everywhere') &&
|
|
|
|
$value['account'] == $this->account_id)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
if ($value['rights'] == 0)
|
2001-12-11 02:14:43 +01:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2005-03-12 17:30:25 +01:00
|
|
|
$rights |= $value['rights'];
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $rights;
|
|
|
|
}
|
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
|
|
|
* check specific rights
|
|
|
|
*
|
|
|
|
* @param string $location app location
|
|
|
|
* @param int $required required rights
|
|
|
|
* @param string $appname optional defaults to currentapp
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function check_specific($location, $required, $appname = '')
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
$rights = $this->get_specific_rights($location,$appname);
|
2001-05-02 14:28:10 +02:00
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
return !!($rights & $required);
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
2001-01-28 13:07:20 +01:00
|
|
|
|
2001-05-02 14:28:10 +02:00
|
|
|
/**************************************************************************\
|
|
|
|
* These are the generic functions. Not specific to $this->account_id *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
2005-03-07 17:59:32 +01:00
|
|
|
/**
|
2005-03-12 17:30:25 +01:00
|
|
|
* add repository information / rights for app/location/account_id to the database
|
2005-03-07 17:59:32 +01:00
|
|
|
*
|
2005-03-12 17:30:25 +01:00
|
|
|
* @param string $app appname
|
|
|
|
* @param string $location location
|
|
|
|
* @param int $account_id account id
|
|
|
|
* @param int $rights rights
|
|
|
|
* @return boolean allways true
|
2005-03-07 17:59:32 +01:00
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function add_repository($app, $location, $account_id, $rights)
|
|
|
|
{
|
2005-03-07 17:59:32 +01:00
|
|
|
//echo "<p>acl::add_repository('$app','$location',$account_id,$rights);</p>\n";
|
|
|
|
$this->db->insert($this->table_name,array(
|
|
|
|
'acl_rights' => $rights,
|
|
|
|
),array(
|
|
|
|
'acl_appname' => $app,
|
|
|
|
'acl_location' => $location,
|
|
|
|
'acl_account' => $account_id,
|
|
|
|
),__LINE__,__FILE__);
|
|
|
|
|
2005-11-24 21:08:09 +01:00
|
|
|
if ($account_id == $GLOBALS['egw_info']['user']['account_id'] &&
|
|
|
|
method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited
|
2005-07-22 11:05:01 +02:00
|
|
|
{
|
|
|
|
$GLOBALS['egw']->invalidate_session_cache();
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
return True;
|
|
|
|
}
|
2001-03-19 21:25:04 +01:00
|
|
|
|
2005-03-07 17:59:32 +01:00
|
|
|
/**
|
2005-03-12 17:30:25 +01:00
|
|
|
* delete repository information / rights for app/location[/account_id] from the DB
|
|
|
|
*
|
2005-03-07 17:59:32 +01:00
|
|
|
* @param string $app appname
|
|
|
|
* @param string $location location
|
|
|
|
* @param int/boolean $account_id account id, default 0=$this->account_id, or false to delete all entries for $app/$location
|
|
|
|
* @return int number of rows deleted
|
|
|
|
*/
|
2005-03-12 18:55:48 +01:00
|
|
|
function delete_repository($app, $location, $accountid='')
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
static $cache_accountid;
|
|
|
|
|
2005-03-07 17:59:32 +01:00
|
|
|
$where = array(
|
|
|
|
'acl_appname' => $app,
|
|
|
|
'acl_location' => $location,
|
|
|
|
);
|
|
|
|
if ($accountid !== false)
|
2001-09-02 01:42:16 +02:00
|
|
|
{
|
2005-03-07 17:59:32 +01:00
|
|
|
if(isset($cache_accountid[$accountid]) && $cache_accountid[$accountid])
|
|
|
|
{
|
|
|
|
$where['acl_account'] = $cache_accountid[$accountid];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id);
|
|
|
|
}
|
2001-09-02 01:42:16 +02:00
|
|
|
}
|
2005-11-24 21:08:09 +01:00
|
|
|
if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->invalidate_session_cache();
|
|
|
|
}
|
2005-03-30 16:42:32 +02:00
|
|
|
if ($app == '%' || $app == '%%') unset($where['acl_appname']);
|
|
|
|
|
2005-03-07 17:59:32 +01:00
|
|
|
$this->db->delete($this->table_name,$where,__LINE__,__FILE__);
|
|
|
|
|
|
|
|
return $this->db->affected_rows();
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get rights for a given account, location and application
|
|
|
|
*
|
|
|
|
* @param int $account_id
|
|
|
|
* @param string $location
|
|
|
|
* @param string $appname='' defaults to current app
|
|
|
|
* @return int/boolean rights or false if none exist
|
|
|
|
*/
|
|
|
|
function get_specific_rights_for_account($account_id,$location,$appname='')
|
|
|
|
{
|
|
|
|
if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
|
|
|
|
$this->db->select($this->table_name,'acl_rights',array(
|
|
|
|
'acl_location' => $location,
|
|
|
|
'acl_account' => $account_id,
|
|
|
|
'acl_appname' => $appname,
|
|
|
|
),__LINE__,__FILE__);
|
|
|
|
|
|
|
|
return $this->db->next_record() ? $this->db->f('acl_rights') : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all rights for a given location and application
|
|
|
|
*
|
|
|
|
* @param string $location
|
|
|
|
* @param string $appname='' defaults to current app
|
|
|
|
* @return array with account => rights pairs
|
|
|
|
*/
|
|
|
|
function get_all_rights($location,$appname='')
|
|
|
|
{
|
|
|
|
if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
|
|
|
|
$this->db->select($this->table_name,'acl_account,acl_rights',array(
|
|
|
|
'acl_location' => $location,
|
|
|
|
'acl_appname' => $appname,
|
|
|
|
),__LINE__,__FILE__);
|
|
|
|
|
|
|
|
$rights = array();
|
|
|
|
while($this->db->next_record())
|
|
|
|
{
|
|
|
|
$rights[$this->db->f('acl_account')] = $this->db->f('acl_rights');
|
|
|
|
}
|
|
|
|
return $rights;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the rights for all locations
|
|
|
|
*
|
|
|
|
* @param int $account_id
|
|
|
|
* @param string $appname='' defaults to current app
|
|
|
|
* @param boolean $use_memberships=true
|
|
|
|
* @return array with location => rights pairs
|
|
|
|
*/
|
|
|
|
function get_all_location_rights($account_id,$appname='',$use_memberships=true)
|
|
|
|
{
|
|
|
|
if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
|
2005-11-10 22:36:51 +01:00
|
|
|
$accounts = array($account_id);
|
2005-11-02 12:45:52 +01:00
|
|
|
if ($use_memberships)
|
|
|
|
{
|
|
|
|
foreach((array)$GLOBALS['egw']->accounts->membership($account_id) as $group)
|
|
|
|
{
|
|
|
|
$accounts[] = $group['account_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->db->select($this->table_name,'acl_location,acl_rights',array(
|
|
|
|
'acl_account' => $accounts,
|
|
|
|
'acl_appname' => $appname,
|
|
|
|
),__LINE__,__FILE__);
|
|
|
|
|
|
|
|
$rights = array();
|
|
|
|
while($this->db->next_record())
|
|
|
|
{
|
|
|
|
$rights[$this->db->f('acl_location')] |= $this->db->f('acl_rights');
|
|
|
|
}
|
|
|
|
return $rights;
|
|
|
|
}
|
2001-01-11 10:52:33 +01:00
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
|
|
|
* get application list for an account id
|
|
|
|
*
|
|
|
|
* @param string $location location
|
|
|
|
* @param int $required required rights
|
|
|
|
* @param int $account_id account id defaults to $GLOBALS['egw_info']['user']['account_id'];
|
|
|
|
* @return array/boolean false if there are no matching row in the db, else array with app-names
|
|
|
|
*/
|
2005-03-12 18:55:48 +01:00
|
|
|
function get_app_list_for_id($location, $required, $accountid = '')
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
static $cache_accountid;
|
|
|
|
|
|
|
|
if($cache_accountid[$accountid])
|
|
|
|
{
|
|
|
|
$account_id = $cache_accountid[$accountid];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$account_id = get_account_id($accountid,$this->account_id);
|
|
|
|
$cache_accountid[$accountid] = $account_id;
|
|
|
|
}
|
2005-03-12 17:30:25 +01:00
|
|
|
$this->db->select($this->table_name,array('acl_appname','acl_rights'),array(
|
|
|
|
'acl_location' => $location,
|
|
|
|
'acl_account' => $account_id,
|
|
|
|
),__LINE__,__FILE__);
|
|
|
|
|
2001-05-02 14:28:10 +02:00
|
|
|
$rights = 0;
|
2005-03-12 17:30:25 +01:00
|
|
|
$apps = false;
|
2001-05-02 14:28:10 +02:00
|
|
|
while ($this->db->next_record())
|
|
|
|
{
|
2001-12-11 02:14:43 +01:00
|
|
|
if ($this->db->f('acl_rights') == 0)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
$rights |= $this->db->f('acl_rights');
|
2005-03-12 17:30:25 +01:00
|
|
|
if (!!($rights & $required))
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
|
|
|
$apps[] = $this->db->f('acl_appname');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $apps;
|
|
|
|
}
|
2001-03-19 21:25:04 +01:00
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
|
|
|
* get location list for id
|
|
|
|
*
|
|
|
|
* @param string $app app
|
|
|
|
* @param int $required required rights
|
2005-03-12 18:55:48 +01:00
|
|
|
* @param int $accountid optional defaults to $GLOBALS['egw_info']['user']['account_id'];
|
2005-03-12 17:30:25 +01:00
|
|
|
* @return array/boolean false if there are no matching rows in the db or array with location-strings
|
|
|
|
*/
|
2005-03-12 18:55:48 +01:00
|
|
|
function get_location_list_for_id($app, $required, $accountid = '')
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
static $cache_accountid;
|
2005-03-12 18:55:48 +01:00
|
|
|
|
2001-09-02 01:42:16 +02:00
|
|
|
if($cache_accountid[$accountid])
|
|
|
|
{
|
2005-03-07 17:59:32 +01:00
|
|
|
$accountid = $cache_accountid[$accountid];
|
2001-09-02 01:42:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-07 17:59:32 +01:00
|
|
|
$accountid = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id);
|
2001-12-11 02:14:43 +01:00
|
|
|
}
|
2005-03-07 17:59:32 +01:00
|
|
|
$this->db->select($this->table_name,'acl_location,acl_rights',array(
|
|
|
|
'acl_appname' => $app,
|
|
|
|
'acl_account' => $accountid,
|
|
|
|
),__LINE__,__FILE__);
|
|
|
|
|
|
|
|
$locations = false;
|
2001-05-02 14:28:10 +02:00
|
|
|
while ($this->db->next_record())
|
|
|
|
{
|
2005-03-07 17:59:32 +01:00
|
|
|
if ($this->db->f('acl_rights') & $required)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-07 17:59:32 +01:00
|
|
|
$locations[] = $this->db->f('acl_location');
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $locations;
|
|
|
|
}
|
2005-03-12 17:30:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get ids for location
|
|
|
|
*
|
|
|
|
* @param string $location location
|
|
|
|
* @param int $required required rights
|
|
|
|
* @param string $app app optional defaults to $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
* @return boolean/array false if there are no matching rows in the db or array of account-ids
|
|
|
|
*/
|
|
|
|
function get_ids_for_location($location, $required, $app = '')
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
|
|
|
|
$this->db->select($this->table_name,array('acl_account','acl_rights'),array(
|
|
|
|
'acl_appname' => $app,
|
|
|
|
'acl_location' => $location,
|
|
|
|
),__LINE__,__FILE__);
|
|
|
|
|
|
|
|
$accounts = false;
|
2001-05-02 14:28:10 +02:00
|
|
|
while ($this->db->next_record())
|
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
if (!!($this->db->f('acl_rights') & $required))
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
$accounts[] = (int) $this->db->f('acl_account');
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $accounts;
|
|
|
|
}
|
2001-03-19 21:25:04 +01:00
|
|
|
|
2005-03-29 17:30:08 +02:00
|
|
|
/**
|
|
|
|
* get the locations for an app (excluding the run location !!!)
|
|
|
|
*
|
|
|
|
* @param string $app app optional defaults to $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
* @return boolean/array false if there are no matching location in the db or array of locations
|
|
|
|
*/
|
|
|
|
function get_locations_for_app($app='')
|
|
|
|
{
|
|
|
|
if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
|
|
|
|
$this->db->select($this->table_name,'DISTINCT '.'acl_location',array(
|
|
|
|
'acl_appname' => $app,
|
|
|
|
),__LINE__,__FILE__);
|
|
|
|
|
|
|
|
$locations = false;
|
|
|
|
while ($this->db->next_record())
|
|
|
|
{
|
|
|
|
if (($location = $this->db->f(0)) != 'run')
|
|
|
|
{
|
|
|
|
$locations[] = $location;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $locations;
|
|
|
|
}
|
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
/**
|
|
|
|
* get a list of applications a user has rights to
|
|
|
|
*
|
|
|
|
* @param int $account_id optional defaults to $GLOBALS['egw_info']['user']['account_id'];
|
|
|
|
* @return boolean/array containing list of apps or false if there are none
|
|
|
|
*/
|
2005-03-12 18:55:48 +01:00
|
|
|
function get_user_applications($accountid = '')
|
2001-03-11 23:38:19 +01:00
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
static $cache_accountid;
|
2001-03-11 23:38:19 +01:00
|
|
|
|
2001-09-02 01:42:16 +02:00
|
|
|
if($cache_accountid[$accountid])
|
|
|
|
{
|
|
|
|
$account_id = $cache_accountid[$accountid];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$account_id = get_account_id($accountid,$this->account_id);
|
|
|
|
$cache_accountid[$accountid] = $account_id;
|
|
|
|
}
|
2005-03-12 17:30:25 +01:00
|
|
|
$memberships = array($account_id);
|
|
|
|
foreach((array)$GLOBALS['egw']->accounts->membership($account_id) as $group)
|
2001-03-11 23:38:19 +01:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
$memberships[] = $group['account_id'];
|
2001-03-11 23:38:19 +01:00
|
|
|
}
|
2005-03-12 17:30:25 +01:00
|
|
|
$db2 = clone($this->db);
|
|
|
|
$db2->select($this->table_name,array('acl_appname','acl_rights'),array(
|
|
|
|
'acl_location' => 'run',
|
|
|
|
'acl_account' => $memberships,
|
|
|
|
),__LINE__,__FILE__);
|
2001-05-02 14:28:10 +02:00
|
|
|
|
2005-03-12 17:30:25 +01:00
|
|
|
$apps = false;
|
2001-05-02 14:28:10 +02:00
|
|
|
while ($db2->next_record())
|
2001-03-11 23:38:19 +01:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
$app = $db2->f('acl_appname');
|
|
|
|
if(!isset($apps[$app]))
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
$apps[$app] = 0;
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
2005-03-12 17:30:25 +01:00
|
|
|
$apps[$app] |= (int) $db2->f('acl_rights');
|
2001-03-11 23:38:19 +01:00
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
return $apps;
|
2001-03-11 23:38:19 +01:00
|
|
|
}
|
2005-03-12 17:30:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read the grants other users gave $this->account_id for $app, group ACL is taken into account
|
|
|
|
*
|
2006-04-23 16:46:38 +02:00
|
|
|
* @param string $app optional defaults to $GLOBALS['egw_info']['flags']['currentapp']
|
2007-12-21 19:55:37 +01:00
|
|
|
* @param boolean/array $enum_group_acls=true should group acls be returned for all members of that group, default yes
|
|
|
|
* if an array of group-id's is given, that id's will NOT be enumerated!
|
2005-03-12 17:30:25 +01:00
|
|
|
* @return array with account-ids (of owners) and granted rights as values
|
|
|
|
*/
|
2006-04-23 16:46:38 +02:00
|
|
|
function get_grants($app='',$enum_group_acls=true)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
|
2001-05-02 14:28:10 +02:00
|
|
|
|
2005-03-29 17:30:08 +02:00
|
|
|
$memberships = array($this->account_id);
|
|
|
|
foreach((array)$GLOBALS['egw']->accounts->membership($this->account_id) as $group)
|
2001-06-30 16:55:46 +02:00
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
$memberships[] = $group['account_id'];
|
2001-06-30 16:55:46 +02:00
|
|
|
}
|
2005-03-12 17:30:25 +01:00
|
|
|
$db2 = clone($this->db);
|
2006-04-23 16:46:38 +02:00
|
|
|
$db2->select($this->table_name,array('acl_account','acl_rights','acl_location'),array(
|
2005-03-12 17:30:25 +01:00
|
|
|
'acl_appname' => $app,
|
|
|
|
'acl_location' => $memberships,
|
|
|
|
),__LINE__,__FILE__);
|
|
|
|
|
|
|
|
$grants = $accounts = Array();
|
2001-05-02 14:28:10 +02:00
|
|
|
while ($db2->next_record())
|
|
|
|
{
|
2006-04-23 16:46:38 +02:00
|
|
|
$grantor = $db2->f('acl_account');
|
|
|
|
$rights = $db2->f('acl_rights');
|
|
|
|
$granted_to = (int) $db2->f('acl_location');
|
|
|
|
|
|
|
|
if(!isset($grants[$grantor]))
|
2001-06-18 05:03:48 +02:00
|
|
|
{
|
2006-04-23 16:46:38 +02:00
|
|
|
$grants[$grantor] = 0;
|
2001-06-18 05:03:48 +02:00
|
|
|
}
|
2006-04-23 16:46:38 +02:00
|
|
|
$grants[$grantor] |= $rights;
|
|
|
|
|
2006-09-01 13:03:29 +02:00
|
|
|
// if the right is granted from a group and we enummerated group ACL's
|
2007-12-21 19:55:37 +01:00
|
|
|
if ($GLOBALS['egw']->accounts->get_type($grantor) == 'g' && $enum_group_acls &&
|
|
|
|
(!is_array($enum_group_acls) || in_array($grantor,$enum_group_acls)))
|
2001-06-18 05:03:48 +02:00
|
|
|
{
|
2006-04-23 16:46:38 +02:00
|
|
|
// return the grant for each member of the group
|
|
|
|
foreach((array)$GLOBALS['egw']->accounts->member($grantor) as $member)
|
2001-06-18 05:03:48 +02:00
|
|
|
{
|
2006-04-23 16:46:38 +02:00
|
|
|
if (!$member) continue; // can happen if group has no members
|
|
|
|
|
|
|
|
// Don't allow to override private with group ACL's!
|
|
|
|
$rights &= ~EGW_ACL_PRIVATE;
|
|
|
|
|
|
|
|
$grantor = $member['account_id'];
|
|
|
|
|
|
|
|
if(!isset($grants[$grantor]))
|
|
|
|
{
|
|
|
|
$grants[$grantor] = 0;
|
|
|
|
}
|
|
|
|
$grants[$grantor] |= $rights;
|
2001-06-18 05:03:48 +02:00
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
}
|
2006-04-23 16:46:38 +02:00
|
|
|
// user has implizit all rights on own data
|
2005-03-07 18:06:01 +01:00
|
|
|
$grants[$GLOBALS['egw_info']['user']['account_id']] = ~0;
|
2003-10-08 02:00:55 +02:00
|
|
|
|
2006-04-23 16:46:38 +02:00
|
|
|
//echo "acl::get_grants('$app',$enum_group_acls) ".function_backtrace(); _debug_array($grants);
|
2001-06-18 05:03:48 +02:00
|
|
|
return $grants;
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
2004-08-07 14:46:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes all ACL entries for an account (user or group)
|
|
|
|
*
|
|
|
|
* @param int $account_id acount-id
|
|
|
|
*/
|
|
|
|
function delete_account($account_id)
|
|
|
|
{
|
|
|
|
if ((int) $account_id)
|
|
|
|
{
|
2005-03-12 17:30:25 +01:00
|
|
|
$this->db->delete($this->table_name,array(
|
|
|
|
'acl_account' => $account_id
|
|
|
|
),__LINE__,__FILE__);
|
2004-08-21 18:17:04 +02:00
|
|
|
// delete all memberships in account_id (if it is a group)
|
2005-03-12 17:30:25 +01:00
|
|
|
$this->db->delete($this->table_name,array(
|
|
|
|
'acl_appname' => 'phpgw_group',
|
|
|
|
'acl_location' => $account_id,
|
|
|
|
),__LINE__,__FILE__);
|
2004-08-07 14:46:58 +02:00
|
|
|
}
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
} //end of acl class
|