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

Revision 952, 7.9 KB checked in by alexandrecorreia, 15 years ago (diff)

Ticket #505 - Arquivos modificados para a administração de hosts virtuais no servidor Jabber.

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