1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003-2005 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 class userinfo
22 {
23 var $dn;
24 var $ip;
25 var $username;
26 var $cn;
27 var $gidNumber= -1;
28 var $language= "";
29 var $config;
30 var $gosaUnitTag= "";
31 var $subtreeACL= array();
33 /* get acl's an put them into the userinfo object
34 attr subtreeACL (userdn:components, userdn:component1#sub1#sub2,component2,...) */
35 function userinfo($config, $userdn){
36 $this->config= $config;
37 $ldap= $this->config->get_ldap_link();
38 $ldap->cat($userdn,array('sn', 'givenName', 'uid', 'gidNumber', 'preferredLanguage', 'gosaUnitTag'));
39 $attrs= $ldap->fetch();
41 if (isset($attrs['givenName'][0]) && isset($attrs['sn'][0])){
42 $this->cn= $attrs['givenName'][0]." ".$attrs['sn'][0];
43 } else {
44 $this->cn= $attrs['uid'][0];
45 }
46 if (isset($attrs['gidNumber'][0])){
47 $this->gidNumber= $attrs['gidNumber'][0];
48 }
50 /* Assign user language */
51 if (isset($attrs['preferredLanguage'][0])){
52 $this->language= $attrs['preferredLanguage'][0];
53 }
55 if (isset($attrs['gosaUnitTag'][0])){
56 $this->gosaUnitTag= $attrs['gosaUnitTag'][0];
57 }
59 $this->dn= $userdn;
60 $this->ip= $_SERVER['REMOTE_ADDR'];
61 }
64 function loadACL()
65 {
66 $ldap= $this->config->get_ldap_link();
68 /* Load ACL's from all groups we're in */
69 $this->subtreeACL= array();
70 $ldap->cd($this->config->current['BASE']);
71 if ($this->gidNumber == -1){
72 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaObject)".
73 "(memberUid=$this->username))");
74 } else {
75 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaObject)".
76 "(|(memberUid=$this->username)(gidNumber=$this->gidNumber)))");
77 }
79 while($attrs = $ldap->fetch()){
80 $base= preg_replace('/^[^,]+,ou=[^,]+,/i', "",$ldap->getDN());
81 $base= preg_replace("/[ ]*,[ ]*/", ",", $base);
83 for ($i= 0; $i<$attrs["gosaSubtreeACL"]["count"]; $i++){
84 $this->subtreeACL[$base][]= $attrs["gosaSubtreeACL"][$i];
85 }
86 }
87 }
89 }
91 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
92 ?>