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

Revision 1695, 9.0 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #777 - Correcao do problema descrito no ticket em questao

  • Property svn:executable set to *
RevLine 
[382]1<?php
[417]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  \***************************************************************************/
[382]12
[417]13
[382]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;
[1438]21        private $dn_User;
[697]22        private $ou_User;
[895]23        private $serverJabber;
[697]24               
[977]25        function __construct()
[382]26        {
27                $this->ldap = new ldap_im();
[697]28                $this->db = new db_im();
29
[1438]30                // (DN) User
31                $this->dn_User = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn'];
32
[697]33                // (OU) User
[1438]34                $this->ou_User = $this->dn_User;
[697]35                $this->ou_User = substr($this->ou_User,strpos($this->ou_User, "ou="));
36                $this->ou_User = strtoupper(substr($this->ou_User, 0, strpos($this->ou_User, ",dc=")));
[895]37               
38                // Server Name Jabber
39                $this->serverJabber = $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit'];
[1160]40               
[382]41        }
42
[558]43        private final function groupsLocked()
44        {
45                $memberShip = array();
46                $groupsLocked =  explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
47               
48                foreach($_SESSION['phpgw_info']['jabberit_messenger']['membership'] as $tmp)
49                        $memberShip[] = $tmp['account_name'];
[598]50               
[558]51                foreach($groupsLocked as $tmp)
52                {
53                        $groups = explode(":", $tmp);
[697]54                        if( array_search($groups[1], $memberShip) !== False )
55                        {       
56                                $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked'] = $groups[2];
[558]57                                return true;
[697]58                        }
[558]59                }
60               
61                return false;
62        }
63
[382]64        public final function list_contacts($param)
65        {
[946]66                $order          = array();
67                $ou_User        = substr($this->ou_User, (strpos($this->ou_User,"=")+1));
68                $return         = '<empty/>';
69                $users          = $this->users_auth_im($param['name']);
[895]70               
[382]71                if (!is_array($users) && trim($users) === 'Many Results')
72                        return "<error>Many Results</error>";
73
[977]74                // Hosts Jabber
75                $hostsJabber = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']);
[1160]76
[1695]77                if( is_array($users) && !empty($users))
[382]78                {       
[946]79                        for($i = 0; $i < count($users); $i++)                           
[895]80                        {
[977]81                                if( is_array($hostsJabber) )
[895]82                                {
[977]83                                        foreach($hostsJabber as $itens)
[895]84                                        {
[1160]85                                                if( trim($users[$i]['ou']) === trim($itens['org']) && strpos($users[$i]['jid'],"@") === false )
[946]86                                                {
[1160]87                                                        $users[$i]['jid'] = $users[$i]['jid']."@".$itens['jabberName'];
[946]88                                                }
[895]89                                        }
90                                }
[1160]91
92                                if( strpos($users[$i]['jid'],"@") === false )
93                                {
94                                        $users[$i]['jid'] = $users[$i]['jid']."@".$this->serverJabber;
95                                }
[895]96                        }
[946]97
[382]98                        foreach($users as $tmp)
99                        {
[946]100                                if ( !array_key_exists($tmp['ou'], $order) )
101                                        $order[$tmp['ou']] = array();
[382]102
[946]103                                $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>';
[382]104                        }
105                       
106                        ksort($order);
107                               
108                        $return = '<uids>';
109                        foreach ( $order as $key => $val )
110                                $return .= '<'.$key.'>'.implode('',$val).'</'.$key.'>';
111                        $return .= '</uids>';
112                }
113               
114                return $return;
115        }
[697]116
[551]117        private final function users_auth_im($pName)
118        {   
119        $array_uids = $this->db->get_accounts_acl();
[988]120        $members = array();
[697]121        $result = array();
[988]122               
[987]123        for( $i = 0; $i < count($array_uids) ; $i+=50 )
124        {   
125            $partial_uids = array_slice($array_uids,$i,50);
126            $filter_uid = implode(")(uidnumber=",$partial_uids);
127            $filter_uid = "(uidnumber=". $filter_uid. ")";
128
129                        if( $this->groupsLocked() )
130                        {
131                    $orgs[] = $this->ou_User;
132                    $orgsGroupsLocked = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']);
133                   
134                                foreach( $orgsGroupsLocked as $tmp )
[697]135                                {
[987]136                                        if( $tmp != "" )
[1438]137                                        {
138                                                if( strpos($tmp, "/") !== false )
139                                                {
140                                                        $tt = explode("/", $tmp);
141                                                        $newOU = implode(",OU=",array_reverse($tt));
142                                                        $orgs[] = "OU=". $newOU ;
143                                                }
144                                                else
145                                                        $orgs[] = "OU=". $tmp;
146                                        }           
[697]147                                }
[1438]148
[987]149                    $orgs = array_unique($orgs);
[1438]150       
[988]151                                foreach( $orgs as $orgB )                               
152                                        $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid, $orgB );
[987]153                        }
154                        else
[988]155                                $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid);
[987]156        }
[1160]157       
158        if( !$this->groupsLocked() )
[988]159                $result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*");
[987]160
[697]161        if ( is_array($result) )
162        {
[946]163                for( $i = 0; $i < count($result); $i++ )
164                        if( is_array($result[$i]) )
165                                $members = array_merge($members,$result[$i]);
[697]166        }
[946]167             
168        if( count($members) > 150)
[697]169        {
[946]170                $ou = substr( $this->ou_User, strpos($this->ou_User, "=") + 1 );
171                        for($i = 0 ; $i < count($members); $i++ )
172                        {
173                                if( $ou == $members[$i]['ou'] )
174                                        $uids_org[] = $members[$i];
175                                else
176                                        if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo']))
177                                                unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$members[$i]['ou']]);
178                        }
179                        return $uids_org;
[697]180        }           
[977]181
[946]182                return $members;       
[551]183        }
[697]184       
[1438]185        private final function strallpos($haystack, $needle, $offset = 0)
186        {
187            $result = array();
188            for($i = $offset; $i< strlen($haystack); $i++ )
189            {
190                $pos = strpos($haystack,$needle,$i);
191                if($pos !== FALSE)
192                {
193                    $offset =  $pos;
194                    if($offset >= $i)
195                        $result[] = $i = $offset;
196                }
197            }
198       
199        return $result;
200        }
201
[697]202        public final function verifyAddNewContact($pUid)
203        {
204                $groupsLocked =  explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
205                $gidNumbers = array();
206                $uid = $pUid['uid'];
[1438]207                $uid_User = substr($this->dn_User, 0, strpos($this->dn_User, ","));
208                $uid_User = substr($uid_User, 4);
[697]209
210                foreach($groupsLocked as $tmp)
211                {
212                        $groups = explode(":", $tmp);
213                        $gidNumbers[] = $groups[1];
214                }
215               
216                $filter_gid = implode(")(gidnumber=",$gidNumbers);
217            $filter_gid = "(gidnumber=". $filter_gid. ")";
218               
[946]219                $result = $this->ldap->getGroupsMemberUid($filter_gid);
[1438]220               
[697]221                if( $result && is_array($result) )
222                {
223                        array_shift($result);
224                        $i = 0;
225                       
226                        foreach($result as $value)
227                        {
228                                $Groups[$i]['dn'] = $value['dn'];
229                                $Groups[$i]['gidnumber'] = $value['gidnumber'][0];
230                                if(array_key_exists('memberuid',$value))
231                                {
232                                        array_shift($value['memberuid']);
233                                        $Groups[$i++]['memberuid'] = $value['memberuid'];
234                                }
235                        }
236
237                        $search = array();
238                        $search_Gid = array();
[1438]239
[697]240                        // Verifica Uid em Grupo Bloqueado
241                        foreach($Groups as $value)
242                        {                       
243                                if( array_search( $uid , $value['memberuid'] ) !== false )
244                                {
245                                        $ou = substr($value['dn'],strpos($value['dn'], "ou="));
[1438]246                                        if( array_search($uid_User, $value['memberuid']) === false )
247                                        {
248                                                $search[] = strtoupper(substr($ou, 0, strpos($ou, ",dc=")));
249                                                $search_Gid[] = $value['gidnumber'];
250                                        }
251                                }
[697]252                        }
253                }
[1438]254               
255       
[697]256                if( $this->groupsLocked() )
257                {
258                        if( count($search) > 0 )
259                        {
260                                // Verifica permissões do grupo
261                                foreach($groupsLocked as $value)
262                                {                                                       
263                                        $tpGroups = explode(":",$value);
264                                        if( $tpGroups[1] == $search_Gid[0] )
265                                        {
266                                                $ousTp = explode(",",$tpGroups[2]);
[1438]267                                                $ou_User = strtoupper(trim($this->dn_User));
[697]268                                               
[1438]269                                                $posAll = $this->strallpos($ou_User, "OU=" );
270                                                $orgs = array();
271                               
272                                                for( $i = 0 ; $i < count($posAll); $i++ )
273                                                {
274                                                        $pos = strpos($ou_User, ",");
275                                                        $tmpString = substr($ou_User, $posAll[$i] + 3);
276                                                        $orgs[] = substr($tmpString, 0, strpos($tmpString, ","));
277                                                }
278                               
279                                                $ou_User = implode("/", array_reverse($orgs));
280
[697]281                                                if( array_search( $ou_User, $ousTp) !== false )
282                                                        return "true";
283                                        }
284                                }
285                                return "false";
286                        }
287                        else
288                                return "true";
289                }
290                else
291                {               
292                        // Se Bloqueado verifica o Grupo       
293                        if( count($search) > 0 )
294                        {
295                                if( array_search($this->ou_User, $search) === false )
296                                {
297                                        // Verifica permissões do grupo
298                                        foreach($groupsLocked as $value)
299                                        {                                                       
300                                                $tpGroups = explode(":",$value);
[1438]301                                               
[697]302                                                if( $tpGroups[1] == $search_Gid[0] )
303                                                {
304                                                        $ousTp = explode(",",$tpGroups[2]);
[1438]305                                                        $ou_User = strtoupper(trim($this->dn_User));
306                                       
307                                                        $posAll = $this->strallpos($ou_User, "OU=" );
308                                                        $orgs = array();
309                                       
310                                                        for( $i = 0 ; $i < count($posAll); $i++ )
311                                                        {
312                                                                $pos = strpos($ou_User, ",");
313                                                                $tmpString = substr($ou_User, $posAll[$i] + 3);
314                                                                $orgs[] = substr($tmpString, 0, strpos($tmpString, ","));
315                                                        }
316                                       
317                                                        $ou_User = implode("/", array_reverse($orgs));
318                                                       
[697]319                                                        if( array_search( $ou_User, $ousTp) !== false )
320                                                                return "true";
321                                                }
322                                        }
323                                        return "false";
324                                }
325                                return "true";
326                        }                                       
327                        return "true";
328                }
329        }
[382]330}
[946]331
[697]332?>
Note: See TracBrowser for help on using the repository browser.