source: trunk/jabberit_messenger/inc/class.contacts_im.inc.php @ 977

Revision 977, 7.7 KB checked in by alexandrecorreia, 15 years ago (diff)

Ticket #541 - O arquivo confLDAPInternal.php não é criado, gera um erro no applet java.

  • Property svn:executable set to *
Line 
1<?php
2  /***************************************************************************\
3  *  Expresso - Expresso Messenger                                            *
4  *     - Alexandre Correia / Rodrigo Souza                                                               *
5  *     - JETI - http://jeti-im.org/                                                                              *
6  * ------------------------------------------------------------------------- *
7  *  This program is free software; you can redistribute it and/or modify it  *
8  *  under the terms of the GNU General Public License as published by the    *
9  *  Free Software Foundation; either version 2 of the License, or (at your   *
10  *  option) any later version.                                               *
11  \***************************************************************************/
12
13
14require_once "class.ldap_im.inc.php";
15require_once "class.db_im.inc.php";
16
17class contacts_im
18{
19        private $ldap;
20        private $db;
21        private $ou_User;
22        private $serverJabber;
23               
24        function __construct()
25        {
26                $this->ldap = new ldap_im();
27                $this->db = new db_im();
28
29                // (OU) User
30                $this->ou_User = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn'];
31                $this->ou_User = substr($this->ou_User,strpos($this->ou_User, "ou="));
32                $this->ou_User = strtoupper(substr($this->ou_User, 0, strpos($this->ou_User, ",dc=")));
33               
34                // Server Name Jabber
35                $this->serverJabber = $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit'];
36        }
37
38        private final function groupsLocked()
39        {
40                $memberShip = array();
41                $groupsLocked =  explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
42               
43                foreach($_SESSION['phpgw_info']['jabberit_messenger']['membership'] as $tmp)
44                        $memberShip[] = $tmp['account_name'];
45               
46                foreach($groupsLocked as $tmp)
47                {
48                        $groups = explode(":", $tmp);
49                        if( array_search($groups[1], $memberShip) !== False )
50                        {       
51                                $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked'] = $groups[2];
52                                return true;
53                        }
54                }
55               
56                return false;
57        }
58
59        public final function list_contacts($param)
60        {
61                $order          = array();
62                $ou_User        = substr($this->ou_User, (strpos($this->ou_User,"=")+1));
63                $return         = '<empty/>';
64                $users          = $this->users_auth_im($param['name']);
65               
66                if (!is_array($users) && trim($users) === 'Many Results')
67                        return "<error>Many Results</error>";
68
69                // Hosts Jabber
70                $hostsJabber = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']);
71
72                foreach($hostsJabber as $conf )
73                        if( array_search("*", $conf) )
74                                $hostDefault = $conf['jabberName'];
75                       
76                if( is_array($users) )
77                {       
78                        for($i = 0; $i < count($users); $i++)                           
79                        {
80                                if( is_array($hostsJabber) )
81                                {
82                                        foreach($hostsJabber as $itens)
83                                        {
84                                                if( trim($users[$i]['ou']) === trim($itens['org']) )
85                                                        $users[$i]['jid'] = $users[$i]['jid']."@".$itens['jabberName'];
86                                                else
87                                                {
88                                                        if( $users[$i]['ou'] === $ou_User )
89                                                                if(strpos($users[$i]['jid'],"@") === false)
90                                                                        $users[$i]['jid'] = $users[$i]['jid']."@".$this->serverJabber;
91                                                        else
92                                                                if(strpos($users[$i]['jid'],"@") === false)
93                                                                        $users[$i]['jid'] = $users[$i]['jid']."@".$hostDefault;
94                                                }
95                                        }
96                                }
97                        }
98
99                        foreach($users as $tmp)
100                        {
101                                if ( !array_key_exists($tmp['ou'], $order) )
102                                        $order[$tmp['ou']] = array();
103
104                                $order[$tmp['ou']][] = '<data><ou>'.$tmp['ou'].'</ou><cn>'.$tmp['cn'].'</cn><mail>'.$tmp['mail'].'</mail><uid>'.$tmp['uid'].'</uid><jid>'.$tmp['jid'].'</jid><photo>'.$tmp['photo'].'</photo></data>';
105                        }
106                       
107                        ksort($order);
108                               
109                        $return = '<uids>';
110                        foreach ( $order as $key => $val )
111                                $return .= '<'.$key.'>'.implode('',$val).'</'.$key.'>';
112                        $return .= '</uids>';
113                }
114               
115                return $return;
116        }
117
118        private final function users_auth_im($pName)
119        {   
120        $array_uids = $this->db->get_accounts_acl();
121        $members = array();;
122        $result = array();
123
124                if( is_array($array_uids) )
125                {
126                for( $i = 0; $i < count($array_uids) ; $i+=50 )
127                {   
128                    $partial_uids = array_slice($array_uids,$i,50);
129                    $filter_uid = implode(")(uidnumber=",$partial_uids);
130                    $filter_uid = "(uidnumber=". $filter_uid. ")";
131       
132                                if( $this->groupsLocked() )
133                                {
134                            $orgs[] = $this->ou_User;
135                            $orgsGroupsLocked = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']);
136                           
137                                        foreach( $orgsGroupsLocked as $tmp )
138                                        {
139                                                if( $tmp != "" )
140                                                        $orgs[] = "OU=". $tmp;           
141                                        }
142                                       
143                            $orgs = array_unique($orgs);
144       
145                                        foreach( $orgs as $orgB )
146                                                $result[] = $this->ldap->getUsersLdap("cn=*".$pName."*", $filter_uid, $orgB );
147                                }
148                                else
149                            $result[] = $this->ldap->getUsersLdap("cn=*".$pName."*", $filter_uid, "" );
150                }
151                }
152                else           
153                        $result[] = $this->ldap->getUsersLdap("cn=*".$pName."*", "", "");
154
155        if ( is_array($result) )
156        {
157                for( $i = 0; $i < count($result); $i++ )
158                        if( is_array($result[$i]) )
159                                $members = array_merge($members,$result[$i]);
160        }
161             
162        if( count($members) > 150)
163        {
164                $ou = substr( $this->ou_User, strpos($this->ou_User, "=") + 1 );
165                        for($i = 0 ; $i < count($members); $i++ )
166                        {
167                                if( $ou == $members[$i]['ou'] )
168                                        $uids_org[] = $members[$i];
169                                else
170                                        if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo']))
171                                                unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$members[$i]['ou']]);
172                        }
173                        return $uids_org;
174        }           
175
176                return $members;       
177        }
178       
179        public final function verifyAddNewContact($pUid)
180        {
181                $groupsLocked =  explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
182                $gidNumbers = array();
183                $uid = $pUid['uid'];
184
185                foreach($groupsLocked as $tmp)
186                {
187                        $groups = explode(":", $tmp);
188                        $gidNumbers[] = $groups[1];
189                }
190               
191                $filter_gid = implode(")(gidnumber=",$gidNumbers);
192            $filter_gid = "(gidnumber=". $filter_gid. ")";
193               
194                $result = $this->ldap->getGroupsMemberUid($filter_gid);
195
196                if( $result && is_array($result) )
197                {
198                        array_shift($result);
199                        $i = 0;
200                       
201                        foreach($result as $value)
202                        {
203                                $Groups[$i]['dn'] = $value['dn'];
204                                $Groups[$i]['gidnumber'] = $value['gidnumber'][0];
205                                if(array_key_exists('memberuid',$value))
206                                {
207                                        array_shift($value['memberuid']);
208                                        $Groups[$i++]['memberuid'] = $value['memberuid'];
209                                }
210                        }
211
212                        $search = array();
213                        $search_Gid = array();
214                       
215                        // Verifica Uid em Grupo Bloqueado
216                        foreach($Groups as $value)
217                        {                       
218                                if( array_search( $uid , $value['memberuid'] ) !== false )
219                                {
220                                        $ou = substr($value['dn'],strpos($value['dn'], "ou="));
221                                        $search[] = strtoupper(substr($ou, 0, strpos($ou, ",dc=")));
222                                        $search_Gid[] = $value['gidnumber'];
223                                }       
224                        }
225                }
226
227                if( $this->groupsLocked() )
228                {
229                        if( count($search) > 0 )
230                        {
231                                // Verifica permissões do grupo
232                                foreach($groupsLocked as $value)
233                                {                                                       
234                                        $tpGroups = explode(":",$value);
235                                        if( $tpGroups[1] == $search_Gid[0] )
236                                        {
237                                                $ousTp = explode(",",$tpGroups[2]);
238                                                $ou_User = substr($this->ou_User,3);
239                                               
240                                                if( array_search( $ou_User, $ousTp) !== false )
241                                                        return "true";
242                                        }
243                                }
244                                return "false";
245                        }
246                        else
247                                return "true";
248                }
249                else
250                {               
251                        // Se Bloqueado verifica o Grupo       
252                        if( count($search) > 0 )
253                        {
254                                if( array_search($this->ou_User, $search) === false )
255                                {
256                                        // Verifica permissões do grupo
257                                        foreach($groupsLocked as $value)
258                                        {                                                       
259                                                $tpGroups = explode(":",$value);
260                                                if( $tpGroups[1] == $search_Gid[0] )
261                                                {
262                                                        $ousTp = explode(",",$tpGroups[2]);
263                                                        $ou_User = substr($this->ou_User,3);
264                                                               
265                                                        if( array_search( $ou_User, $ousTp) !== false )
266                                                                return "true";
267                                                }
268                                        }
269                                        return "false";
270                                }
271                                return "true";
272                        }                                       
273                        return "true";
274                }
275        }
276}
277
278?>
Note: See TracBrowser for help on using the repository browser.