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
|
|
|
|
2001-03-13 05:27:22 +01:00
|
|
|
/*!
|
2001-07-13 10:37:56 +02:00
|
|
|
@class acl
|
2003-10-18 13:15:48 +02:00
|
|
|
@abstract Access Control List Security System
|
2001-07-13 10:37:56 +02:00
|
|
|
@discussion 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.
|
|
|
|
@syntax CreateObject('phpgwapi.acl',int account_id);
|
|
|
|
@example $acl = CreateObject('phpgwapi.acl',5); // 5 is the user id
|
|
|
|
@example $acl = CreateObject('phpgwapi.acl',10); // 10 is the user id
|
|
|
|
@author Seek3r
|
|
|
|
@copyright LGPL
|
|
|
|
@package phpgwapi
|
2001-12-11 02:14:43 +01:00
|
|
|
@access public
|
2001-02-13 11:53:18 +01:00
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
class acl
|
2001-12-11 02:14:43 +01:00
|
|
|
{
|
|
|
|
/*! @var $account_id */
|
2001-05-02 14:28:10 +02:00
|
|
|
var $account_id;
|
|
|
|
/*! @var $account_type */
|
|
|
|
var $account_type;
|
|
|
|
/*! @var $data */
|
|
|
|
var $data = Array();
|
|
|
|
/*! @var $db */
|
|
|
|
var $db;
|
2001-01-20 00:45:37 +01:00
|
|
|
|
2001-03-13 05:27:22 +01:00
|
|
|
/*!
|
|
|
|
@function acl
|
|
|
|
@abstract ACL constructor for setting account id
|
|
|
|
@discussion Author: Seek3r <br>
|
|
|
|
Sets the ID for $acl->account_id. Can be used to change a current instances id as well. <br>
|
|
|
|
Some functions are specific to this account, and others are generic. <br>
|
2001-11-12 19:01:42 +01:00
|
|
|
@syntax int acl(int account_id) <br>
|
|
|
|
@example1 acl->acl(5); // 5 is the user id <br>
|
2001-03-13 05:27:22 +01:00
|
|
|
@param account_id int-the user id
|
2001-02-13 11:53:18 +01:00
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function acl($account_id = '')
|
2001-03-21 06:09:14 +01:00
|
|
|
{
|
2003-12-14 18:07:16 +01:00
|
|
|
copyobj($GLOBALS['phpgw']->db,$this->db);
|
|
|
|
if ((int)$this->account_id != (int)$account_id)
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2003-12-14 18:07:16 +01:00
|
|
|
$this->account_id = get_account_id((int)$account_id,@$GLOBALS['phpgw_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
|
|
|
|
2001-03-13 05:27:22 +01:00
|
|
|
/*!
|
|
|
|
@function read_repository
|
|
|
|
@abstract Read acl records from reposity
|
|
|
|
@discussion Author: Seek3r <br>
|
|
|
|
Reads ACL records for $acl->account_id and returns array along with storing it in $acl->data. <br>
|
|
|
|
Syntax: array read_repository() <br>
|
2001-03-19 04:16:56 +01:00
|
|
|
Example1: acl->read_repository(); <br>
|
|
|
|
Should only be called within this class
|
2001-02-13 11:53:18 +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)
|
|
|
|
if (! $this->account_id)
|
|
|
|
{
|
|
|
|
$this->acl();
|
|
|
|
}
|
|
|
|
|
2001-05-02 14:28:10 +02:00
|
|
|
$sql = 'select * from phpgw_acl where (acl_account in ('.$this->account_id.', 0';
|
2001-06-18 05:03:48 +02:00
|
|
|
|
|
|
|
$groups = $this->get_location_list_for_id('phpgw_group', 1, $this->account_id);
|
|
|
|
while($groups && list($key,$value) = each($groups))
|
|
|
|
{
|
2003-09-21 21:43:29 +02:00
|
|
|
if($value != '')
|
|
|
|
$sql .= ','.$value;
|
2001-06-18 05:03:48 +02:00
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
$sql .= '))';
|
|
|
|
$this->db->query($sql ,__LINE__,__FILE__);
|
|
|
|
$count = $this->db->num_rows();
|
|
|
|
$this->data = Array();
|
|
|
|
for ($idx = 0; $idx < $count; ++$idx)
|
|
|
|
{
|
|
|
|
//reset ($this->data);
|
|
|
|
//while(list($idx,$value) = each($this->data)){
|
|
|
|
$this->db->next_record();
|
|
|
|
$this->data[] = array(
|
|
|
|
'appname' => $this->db->f('acl_appname'),
|
|
|
|
'location' => $this->db->f('acl_location'),
|
|
|
|
'account' => $this->db->f('acl_account'),
|
|
|
|
'rights' => $this->db->f('acl_rights')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
reset ($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
|
2001-03-13 05:27:22 +01:00
|
|
|
/*!
|
|
|
|
@function read
|
|
|
|
@abstract Read acl records from $acl->data
|
|
|
|
@discussion Author: Seek3r <br>
|
|
|
|
Returns ACL records from $acl->data. <br>
|
|
|
|
Syntax: array read() <br>
|
2001-03-19 04:16:56 +01:00
|
|
|
Example1: acl->read(); <br>
|
2001-02-13 11:53:18 +01:00
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function read()
|
|
|
|
{
|
2001-12-11 02:14:43 +01:00
|
|
|
if (count($this->data) == 0)
|
|
|
|
{
|
|
|
|
$this->read_repository();
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
reset ($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
|
2001-03-13 05:27:22 +01:00
|
|
|
/*!
|
|
|
|
@function add
|
|
|
|
@abstract Adds ACL record to $acl->data
|
|
|
|
@discussion Adds ACL record to $acl->data. <br>
|
|
|
|
Syntax: array add() <br>
|
|
|
|
Example1: acl->add();
|
2001-03-19 04:16:56 +01:00
|
|
|
@param $appname default False derives value from $phpgw_info['flags']['currentapp']
|
|
|
|
@param $location location
|
|
|
|
@param $rights rights
|
2001-02-13 11:53:18 +01:00
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function add($appname = False, $location, $rights)
|
|
|
|
{
|
|
|
|
if ($appname == False)
|
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
settype($appname,'string');
|
|
|
|
$appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
$this->data[] = array('appname' => $appname, 'location' => $location, 'account' => $this->account_id, 'rights' => $rights);
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function delete
|
|
|
|
@abstract Delete ACL record
|
|
|
|
@discussion
|
|
|
|
Syntax <br>
|
|
|
|
Example: <br>
|
|
|
|
@param $appname optional defaults to $phpgw_info['flags']['currentapp']
|
|
|
|
@param $location app location
|
|
|
|
*/
|
|
|
|
function delete($appname = False, $location)
|
|
|
|
{
|
|
|
|
if ($appname == False)
|
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
settype($appname,'string');
|
|
|
|
$appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
$count = count($this->data);
|
|
|
|
reset ($this->data);
|
|
|
|
while(list($idx,$value) = each($this->data))
|
|
|
|
{
|
|
|
|
if ($this->data[$idx]['appname'] == $appname && $this->data[$idx]['location'] == $location && $this->data[$idx]['account'] == $this->account_id)
|
|
|
|
{
|
|
|
|
$this->data[$idx] = Array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
|
2001-03-13 05:27:22 +01:00
|
|
|
/*!
|
|
|
|
@function save_repostiory
|
|
|
|
@abstract save repository
|
|
|
|
@discussion save the repository <br>
|
|
|
|
Syntax: save_repository() <br>
|
|
|
|
example: acl->save_repository()
|
|
|
|
*/
|
|
|
|
|
2001-05-02 14:28:10 +02:00
|
|
|
function save_repository()
|
|
|
|
{
|
|
|
|
reset($this->data);
|
|
|
|
|
2003-12-14 18:07:16 +01:00
|
|
|
$sql = 'delete from phpgw_acl where acl_account = '. (int)$this->account_id;
|
2001-05-02 14:28:10 +02:00
|
|
|
$this->db->query($sql ,__LINE__,__FILE__);
|
|
|
|
|
|
|
|
$count = count($this->data);
|
|
|
|
reset ($this->data);
|
|
|
|
while(list($idx,$value) = each($this->data))
|
|
|
|
{
|
|
|
|
if ($this->data[$idx]['account'] == $this->account_id)
|
|
|
|
{
|
|
|
|
$sql = 'insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_rights)';
|
|
|
|
$sql .= " values('".$this->data[$idx]['appname']."', '"
|
|
|
|
. $this->data[$idx]['location']."', ".$this->account_id.', '.$this->data[$idx]['rights'].')';
|
|
|
|
$this->db->query($sql ,__LINE__,__FILE__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************\
|
|
|
|
* These are the non-standard $this->account_id specific functions *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
2001-03-13 05:27:22 +01:00
|
|
|
/*!
|
|
|
|
@function get_rights
|
2001-03-19 04:16:56 +01:00
|
|
|
@abstract get rights from the repository not specific to this->account_id (?)
|
2001-03-13 05:27:22 +01:00
|
|
|
@discussion
|
2001-03-19 04:16:56 +01:00
|
|
|
@param $location app location to get rights from
|
|
|
|
@param $appname optional defaults to $phpgw_info['flags']['currentapp'];
|
2001-03-13 05:27:22 +01:00
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function get_rights($location,$appname = False)
|
|
|
|
{
|
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))
|
|
|
|
{
|
|
|
|
$a = $location;
|
|
|
|
$location = $a['location'];
|
|
|
|
$appname = $a['appname'];
|
|
|
|
}
|
|
|
|
|
2001-12-11 02:14:43 +01:00
|
|
|
if (count($this->data) == 0)
|
|
|
|
{
|
|
|
|
$this->read_repository();
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
reset ($this->data);
|
|
|
|
if ($appname == False)
|
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
settype($appname,'string');
|
|
|
|
$appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
$count = count($this->data);
|
2001-12-11 02:14:43 +01:00
|
|
|
if ($count == 0 && $GLOBALS['phpgw_info']['server']['acl_default'] != 'deny')
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
$rights = 0;
|
|
|
|
//for ($idx = 0; $idx < $count; ++$idx){
|
|
|
|
reset ($this->data);
|
|
|
|
while(list($idx,$value) = each($this->data))
|
|
|
|
{
|
|
|
|
if ($this->data[$idx]['appname'] == $appname)
|
|
|
|
{
|
|
|
|
if ($this->data[$idx]['location'] == $location || $this->data[$idx]['location'] == 'everywhere')
|
|
|
|
{
|
2001-12-11 02:14:43 +01:00
|
|
|
if ($this->data[$idx]['rights'] == 0)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2003-05-17 22:26:49 +02:00
|
|
|
|
2001-05-02 14:28:10 +02:00
|
|
|
$rights |= $this->data[$idx]['rights'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $rights;
|
|
|
|
}
|
2001-03-19 04:16:56 +01:00
|
|
|
/*!
|
|
|
|
@function check
|
|
|
|
@abstract check required rights (not specific to this->account_id?)
|
|
|
|
@param $location app location
|
|
|
|
@param $required required right to check against
|
|
|
|
@param $appname optional defaults to currentapp
|
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function check($location, $required, $appname = False)
|
|
|
|
{
|
|
|
|
$rights = $this->get_rights($location,$appname);
|
|
|
|
return !!($rights & $required);
|
|
|
|
}
|
2001-03-19 04:16:56 +01:00
|
|
|
/*!
|
|
|
|
@function get_specific_rights
|
|
|
|
@abstract get specific rights for this->account_id for an app location
|
|
|
|
@param $location app location
|
|
|
|
@param $appname optional defaults to currentapp
|
|
|
|
@result $rights ?
|
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function get_specific_rights($location, $appname = False)
|
|
|
|
{
|
|
|
|
if ($appname == False)
|
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
settype($appname,'string');
|
|
|
|
$appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$count = count($this->data);
|
2001-12-11 02:14:43 +01:00
|
|
|
if ($count == 0 && $GLOBALS['phpgw_info']['server']['acl_default'] != 'deny')
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
$rights = 0;
|
|
|
|
|
|
|
|
reset ($this->data);
|
|
|
|
while(list($idx,$value) = each($this->data))
|
|
|
|
{
|
|
|
|
if ($this->data[$idx]['appname'] == $appname &&
|
|
|
|
($this->data[$idx]['location'] == $location ||
|
|
|
|
$this->data[$idx]['location'] == 'everywhere') &&
|
|
|
|
$this->data[$idx]['account'] == $this->account_id)
|
|
|
|
{
|
2001-12-11 02:14:43 +01:00
|
|
|
if ($this->data[$idx]['rights'] == 0)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
$rights |= $this->data[$idx]['rights'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $rights;
|
|
|
|
}
|
2001-03-19 04:16:56 +01:00
|
|
|
/*!
|
|
|
|
@function check_specific
|
|
|
|
@abstract check specific
|
|
|
|
@param $location app location
|
|
|
|
@param $required required rights
|
|
|
|
@param $appname optional defaults to currentapp
|
|
|
|
@result boolean
|
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function check_specific($location, $required, $appname = False)
|
|
|
|
{
|
|
|
|
$rights = $this->get_specific_rights($location,$appname);
|
|
|
|
return !!($rights & $required);
|
|
|
|
}
|
2001-03-19 04:16:56 +01:00
|
|
|
/*!
|
|
|
|
@function get_location_list
|
|
|
|
@abstract ?
|
|
|
|
@param $app appname
|
|
|
|
@param $required ?
|
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function get_location_list($app, $required)
|
|
|
|
{
|
|
|
|
// User piece
|
|
|
|
$sql = "select acl_location, acl_rights from phpgw_acl where acl_appname = '$app' ";
|
|
|
|
$sql .= " and (acl_account in ('".$this->account_id."', 0"; // group 0 covers all users
|
2001-09-02 01:42:16 +02:00
|
|
|
$equalto = $GLOBALS['phpgw']->accounts->security_equals($this->account_id);
|
2001-05-02 14:28:10 +02:00
|
|
|
if (is_array($equalto) && count($equalto) > 0)
|
|
|
|
{
|
|
|
|
for ($idx = 0; $idx < count($equalto); ++$idx)
|
|
|
|
{
|
|
|
|
$sql .= ','.$equalto[$idx][0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$sql .= ')))';
|
|
|
|
|
|
|
|
$this->db->query($sql ,__LINE__,__FILE__);
|
|
|
|
$rights = 0;
|
2001-12-11 02:14:43 +01:00
|
|
|
if ($this->db->num_rows() == 0 )
|
|
|
|
{
|
|
|
|
return 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');
|
|
|
|
if (!!($rights & $required) == True)
|
|
|
|
{
|
|
|
|
$locations[] = $this->db->f('acl_location');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $locations;
|
|
|
|
}
|
2001-01-28 13:07:20 +01:00
|
|
|
|
2001-02-03 11:48:41 +01:00
|
|
|
/*
|
2001-05-02 14:28:10 +02:00
|
|
|
This is kinda how the function SHOULD work, so that it doesnt need to do its own sql query.
|
|
|
|
It should use the values in the $this->data
|
|
|
|
|
|
|
|
function get_location_list($app, $required)
|
|
|
|
{
|
|
|
|
if ($appname == False)
|
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
$appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$count = count($this->data);
|
2001-09-02 01:42:16 +02:00
|
|
|
if ($count == 0 && $GLOBALS['phpgw_info']['server']['acl_default'] != 'deny'){ return True; }
|
2001-05-02 14:28:10 +02:00
|
|
|
$rights = 0;
|
|
|
|
|
|
|
|
reset ($this->data);
|
|
|
|
while(list($idx,$value) = each($this->data))
|
|
|
|
{
|
|
|
|
if ($this->data[$idx]['appname'] == $appname && $this->data[$idx]['rights'] != 0)
|
|
|
|
{
|
|
|
|
$location_rights[$this->data[$idx]['location']] |= $this->data[$idx]['rights'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reset($location_rights);
|
|
|
|
for ($idx = 0; $idx < count($location_rights); ++$idx)
|
|
|
|
{
|
|
|
|
if (!!($location_rights[$idx] & $required) == True)
|
|
|
|
{
|
|
|
|
$location_rights[] = $this->data[$idx]['location'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $locations;
|
|
|
|
}
|
2001-02-03 11:48:41 +01: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 *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
2001-03-19 04:16:56 +01:00
|
|
|
/*!
|
|
|
|
@function add_repository
|
|
|
|
@abstract add repository information for an app
|
|
|
|
@param $app appname
|
|
|
|
@param $location location
|
|
|
|
@param $account_id account id
|
|
|
|
@param $rights rights
|
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function add_repository($app, $location, $account_id, $rights)
|
|
|
|
{
|
|
|
|
$this->delete_repository($app, $location, $account_id);
|
|
|
|
$sql = 'insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_rights)';
|
|
|
|
$sql .= " values ('" . $app . "','" . $location . "','" . $account_id . "','" . $rights . "')";
|
|
|
|
$this->db->query($sql ,__LINE__,__FILE__);
|
|
|
|
return True;
|
|
|
|
}
|
2001-03-19 21:25:04 +01:00
|
|
|
|
2001-03-19 04:16:56 +01:00
|
|
|
/*!
|
|
|
|
@function delete_repository
|
|
|
|
@abstract delete repository information for an app
|
|
|
|
@param $app appname
|
|
|
|
@param $location location
|
|
|
|
@param $account_id account id
|
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function delete_repository($app, $location, $accountid = '')
|
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
static $cache_accountid;
|
|
|
|
|
2001-09-04 05:15:03 +02:00
|
|
|
if(isset($cache_accountid[$accountid]) && $cache_accountid[$accountid])
|
2001-09-02 01:42:16 +02:00
|
|
|
{
|
|
|
|
$account_id = $cache_accountid[$accountid];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$account_id = get_account_id($accountid,$this->account_id);
|
|
|
|
$cache_accountid[$accountid] = $account_id;
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
$sql = "delete from phpgw_acl where acl_appname like '".$app."'"
|
|
|
|
. " and acl_location like '".$location."' and "
|
|
|
|
. " acl_account = ".$account_id;
|
|
|
|
$this->db->query($sql ,__LINE__,__FILE__);
|
|
|
|
return $this->db->num_rows();
|
|
|
|
}
|
2001-01-11 10:52:33 +01:00
|
|
|
|
2001-03-19 04:16:56 +01:00
|
|
|
/*!
|
|
|
|
@function get_app_list_for_id
|
|
|
|
@abstract get application list for an account id
|
|
|
|
@param $location location
|
|
|
|
@param $required ?
|
|
|
|
@param $account_id account id defaults to $phpgw_info['user']['account_id'];
|
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function get_app_list_for_id($location, $required, $accountid = '')
|
|
|
|
{
|
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;
|
|
|
|
}
|
2003-10-08 02:00:55 +02:00
|
|
|
$sql = 'SELECT acl_appname, acl_rights from phpgw_acl ';
|
|
|
|
$sql .= "where acl_location = '" . $this->db->db_addslashes($location) . "' ";
|
2003-12-14 18:07:16 +01:00
|
|
|
$sql .= 'AND acl_account = ' . (int)$account_id;
|
2001-05-02 14:28:10 +02:00
|
|
|
$this->db->query($sql ,__LINE__,__FILE__);
|
|
|
|
$rights = 0;
|
2001-12-11 02:14:43 +01:00
|
|
|
if ($this->db->num_rows() == 0 )
|
|
|
|
{
|
|
|
|
return 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');
|
|
|
|
if (!!($rights & $required) == True)
|
|
|
|
{
|
|
|
|
$apps[] = $this->db->f('acl_appname');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $apps;
|
|
|
|
}
|
2001-03-19 21:25:04 +01:00
|
|
|
|
2001-03-19 04:16:56 +01:00
|
|
|
/*!
|
|
|
|
@function get_location_list_for_id
|
|
|
|
@abstract get location list for id
|
|
|
|
@discussion ?
|
|
|
|
@param $app app
|
|
|
|
@param $required required
|
|
|
|
@param $account_id optional defaults to $phpgw_info['user']['account_id'];
|
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function get_location_list_for_id($app, $required, $accountid = '')
|
|
|
|
{
|
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;
|
|
|
|
}
|
2003-10-08 02:00:55 +02:00
|
|
|
$sql = 'SELECT acl_location, acl_rights ';
|
|
|
|
$sql .= "FROM phpgw_acl where acl_appname = '" . $this->db->db_addslashes($app) . "' ";
|
2003-12-14 18:07:16 +01:00
|
|
|
$sql .= 'AND acl_account =' . (int)$account_id;
|
2003-10-08 02:00:55 +02:00
|
|
|
|
2001-05-02 14:28:10 +02:00
|
|
|
$this->db->query($sql ,__LINE__,__FILE__);
|
|
|
|
$rights = 0;
|
2001-12-11 02:14:43 +01:00
|
|
|
if ($this->db->num_rows() == 0 )
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
while ($this->db->next_record())
|
|
|
|
{
|
|
|
|
if ($this->db->f('acl_rights'))
|
|
|
|
{
|
|
|
|
$rights |= $this->db->f('acl_rights');
|
|
|
|
if (!!($rights & $required) == True)
|
|
|
|
{
|
|
|
|
$locations[] = $this->db->f('acl_location');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $locations;
|
|
|
|
}
|
2001-03-19 04:16:56 +01:00
|
|
|
/*!
|
|
|
|
@function get_ids_for_location
|
|
|
|
@abstract get ids for location
|
|
|
|
@param $location location
|
|
|
|
@param $required required
|
|
|
|
@param $app app optional defaults to $phpgw_info['flags']['currentapp'];
|
|
|
|
*/
|
2001-05-02 14:28:10 +02:00
|
|
|
function get_ids_for_location($location, $required, $app = False)
|
|
|
|
{
|
|
|
|
if ($app == False)
|
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
$app = $GLOBALS['phpgw_info']['flags']['currentapp'];
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
$sql = "select acl_account, acl_rights from phpgw_acl where acl_appname = '$app' and ";
|
|
|
|
$sql .= "acl_location = '".$location."'";
|
|
|
|
$this->db->query($sql ,__LINE__,__FILE__);
|
|
|
|
$rights = 0;
|
2001-12-11 02:14:43 +01:00
|
|
|
if ($this->db->num_rows() == 0 )
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
while ($this->db->next_record())
|
|
|
|
{
|
|
|
|
$rights = 0;
|
|
|
|
$rights |= $this->db->f('acl_rights');
|
|
|
|
if (!!($rights & $required) == True)
|
|
|
|
{
|
2003-12-14 18:07:16 +01:00
|
|
|
$accounts[] = (int)$this->db->f('acl_account');
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
}
|
2001-09-04 05:15:03 +02:00
|
|
|
@reset($accounts);
|
2001-05-02 14:28:10 +02:00
|
|
|
return $accounts;
|
|
|
|
}
|
2001-03-19 21:25:04 +01:00
|
|
|
|
2001-03-19 04:16:56 +01:00
|
|
|
/*!
|
|
|
|
@function get_user_applications
|
|
|
|
@abstract get a list of applications a user has rights to
|
|
|
|
@param $account_id optional defaults to $phpgw_info['user']['account_id'];
|
|
|
|
@result $apps array containing list of apps
|
|
|
|
*/
|
2001-05-02 14:28:10 +02: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;
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
$db2 = $this->db;
|
2001-09-02 01:42:16 +02:00
|
|
|
$memberships = $GLOBALS['phpgw']->accounts->membership($account_id);
|
2001-05-02 14:28:10 +02:00
|
|
|
$sql = "select acl_appname, acl_rights from phpgw_acl where acl_location = 'run' and "
|
|
|
|
. 'acl_account in ';
|
|
|
|
$security = '('.$account_id;
|
|
|
|
while($groups = @each($memberships))
|
2001-03-11 23:38:19 +01:00
|
|
|
{
|
2001-05-02 14:28:10 +02:00
|
|
|
$group = each($groups);
|
|
|
|
$security .= ','.$group[1]['account_id'];
|
2001-03-11 23:38:19 +01:00
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
$security .= ')';
|
|
|
|
$db2->query($sql . $security ,__LINE__,__FILE__);
|
|
|
|
|
2001-12-11 02:14:43 +01:00
|
|
|
if ($db2->num_rows() == 0)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
while ($db2->next_record())
|
2001-03-11 23:38:19 +01:00
|
|
|
{
|
2001-05-02 14:28:10 +02:00
|
|
|
if(isset($apps[$db2->f('acl_appname')]))
|
|
|
|
{
|
|
|
|
$rights = $apps[$db2->f('acl_appname')];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$rights = 0;
|
2001-05-14 05:54:40 +02:00
|
|
|
$apps[$db2->f('acl_appname')] = 0;
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
$rights |= $db2->f('acl_rights');
|
|
|
|
$apps[$db2->f('acl_appname')] |= $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
|
|
|
}
|
2001-03-19 04:16:56 +01:00
|
|
|
/*!
|
|
|
|
@function get_grants
|
|
|
|
@abstract ?
|
|
|
|
@param $app optional defaults to $phpgw_info['flags']['currentapp'];
|
|
|
|
*/
|
2001-06-07 14:10:15 +02:00
|
|
|
function get_grants($app='')
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
|
|
|
$db2 = $this->db;
|
|
|
|
|
2001-06-07 14:10:15 +02:00
|
|
|
if ($app=='')
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
$app = $GLOBALS['phpgw_info']['flags']['currentapp'];
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "select acl_account, acl_rights from phpgw_acl where acl_appname = '$app' and "
|
|
|
|
. "acl_location in ";
|
2001-06-18 05:03:48 +02:00
|
|
|
$security = "('". $this->account_id ."'";
|
2001-05-31 12:11:18 +02:00
|
|
|
$myaccounts = CreateObject('phpgwapi.accounts');
|
2001-08-04 16:26:10 +02:00
|
|
|
$my_memberships = $myaccounts->membership($this->account_id);
|
2001-06-23 04:00:12 +02:00
|
|
|
unset($myaccounts);
|
2001-06-07 14:10:15 +02:00
|
|
|
@reset($my_memberships);
|
|
|
|
while($my_memberships && list($key,$group) = each($my_memberships))
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2001-06-07 14:10:15 +02:00
|
|
|
$security .= ",'" . $group['account_id'] . "'";
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
|
|
|
$security .= ')';
|
|
|
|
$db2->query($sql . $security ,__LINE__,__FILE__);
|
|
|
|
$rights = 0;
|
|
|
|
$accounts = Array();
|
2001-06-30 16:55:46 +02:00
|
|
|
if ($db2->num_rows() == 0)
|
|
|
|
{
|
2003-10-08 02:00:55 +02:00
|
|
|
$grants[$GLOBALS['phpgw_info']['user']['account_id']] = ~0;
|
2001-06-30 16:55:46 +02:00
|
|
|
return $grants;
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
while ($db2->next_record())
|
|
|
|
{
|
|
|
|
$grantor = $db2->f('acl_account');
|
|
|
|
$rights = $db2->f('acl_rights');
|
|
|
|
|
|
|
|
if(!isset($accounts[$grantor]))
|
2001-06-18 05:03:48 +02:00
|
|
|
// cache the group-members for performance
|
2001-05-02 14:28:10 +02:00
|
|
|
{
|
2001-06-18 05:03:48 +02:00
|
|
|
// if $grantor is a group, get its members
|
|
|
|
$members = $this->get_ids_for_location($grantor,1,'phpgw_group');
|
|
|
|
if(!$members)
|
|
|
|
{
|
|
|
|
$accounts[$grantor] = Array($grantor);
|
|
|
|
$is_group[$grantor] = False;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$accounts[$grantor] = $members;
|
|
|
|
$is_group[$grantor] = True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(@$is_group[$grantor])
|
|
|
|
{
|
|
|
|
// Don't allow to override private!
|
|
|
|
$rights &= (~ PHPGW_ACL_PRIVATE);
|
2001-10-23 12:58:53 +02:00
|
|
|
if(!isset($grants[$grantor]))
|
|
|
|
{
|
|
|
|
$grants[$grantor] = 0;
|
|
|
|
}
|
2001-11-29 04:12:01 +01:00
|
|
|
$grants[$grantor] |= $rights;
|
2001-10-23 13:10:31 +02:00
|
|
|
if(!!($rights & PHPGW_ACL_READ))
|
|
|
|
{
|
2001-11-29 04:12:01 +01:00
|
|
|
$grants[$grantor] |= PHPGW_ACL_READ;
|
2001-10-23 13:10:31 +02:00
|
|
|
}
|
2001-06-18 05:03:48 +02:00
|
|
|
}
|
|
|
|
while(list($nul,$grantors) = each($accounts[$grantor]))
|
|
|
|
{
|
|
|
|
if(!isset($grants[$grantors]))
|
|
|
|
{
|
|
|
|
$grants[$grantors] = 0;
|
|
|
|
}
|
|
|
|
$grants[$grantors] |= $rights;
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
2001-06-30 16:55:46 +02:00
|
|
|
reset($accounts[$grantor]);
|
2001-05-02 14:28:10 +02:00
|
|
|
}
|
2003-10-08 02:00:55 +02:00
|
|
|
$grants[$GLOBALS['phpgw_info']['user']['account_id']] = ~0;
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
$this->db->query('DELETE FROM phpgw_acl WHERE acl_account='.(int)$account_id,__LINE__,__FILE__);
|
|
|
|
}
|
|
|
|
}
|
2001-05-02 14:28:10 +02:00
|
|
|
} //end of acl class
|
2001-01-30 03:12:03 +01:00
|
|
|
?>
|