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

Revision 946, 7.8 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        $count = count($array_uids);
133        $members = array();;
134        $result = array();
135       
136        for( $i = 0; $i < $count ; $i+=50 )
137        {   
138            $partial_uids = array_slice($array_uids,$i,50);
139            $filter_uid = implode(")(uidnumber=",$partial_uids);
140            $filter_uid = "(uidnumber=". $filter_uid. ")";
141
142                        if( $this->groupsLocked() )
143                        {
144                    $orgs[] = $this->ou_User;
145                    $orgsGroupsLocked = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']);
146                   
147                                foreach( $orgsGroupsLocked as $tmp )
148                                {
149                                        if( $tmp != "" )
150                                                $orgs[] = "OU=". $tmp;           
151                                }
152                               
153                    $orgs = array_unique($orgs);
154
155                                foreach( $orgs as $orgB )
156                                        $result[] = $this->ldap->getUsersLdap("cn=*".$pName."*", $filter_uid, $orgB );
157                        }
158                        else
159                    $result[] = $this->ldap->getUsersLdap("cn=*".$pName."*", $filter_uid, "" );
160        }
161
162        if ( is_array($result) )
163        {
164                for( $i = 0; $i < count($result); $i++ )
165                        if( is_array($result[$i]) )
166                                $members = array_merge($members,$result[$i]);
167        }
168             
169        if( count($members) > 150)
170        {
171                $ou = substr( $this->ou_User, strpos($this->ou_User, "=") + 1 );
172                        for($i = 0 ; $i < count($members); $i++ )
173                        {
174                                if( $ou == $members[$i]['ou'] )
175                                        $uids_org[] = $members[$i];
176                                else
177                                        if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo']))
178                                                unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$members[$i]['ou']]);
179                        }
180                        return $uids_org;
181        }           
182                return $members;       
183        }
184       
185        public final function verifyAddNewContact($pUid)
186        {
187                $groupsLocked =  explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
188                $gidNumbers = array();
189                $uid = $pUid['uid'];
190
191                foreach($groupsLocked as $tmp)
192                {
193                        $groups = explode(":", $tmp);
194                        $gidNumbers[] = $groups[1];
195                }
196               
197                $filter_gid = implode(")(gidnumber=",$gidNumbers);
198            $filter_gid = "(gidnumber=". $filter_gid. ")";
199               
200                $result = $this->ldap->getGroupsMemberUid($filter_gid);
201
202                if( $result && is_array($result) )
203                {
204                        array_shift($result);
205                        $i = 0;
206                       
207                        foreach($result as $value)
208                        {
209                                $Groups[$i]['dn'] = $value['dn'];
210                                $Groups[$i]['gidnumber'] = $value['gidnumber'][0];
211                                if(array_key_exists('memberuid',$value))
212                                {
213                                        array_shift($value['memberuid']);
214                                        $Groups[$i++]['memberuid'] = $value['memberuid'];
215                                }
216                        }
217
218                        $search = array();
219                        $search_Gid = array();
220                       
221                        // Verifica Uid em Grupo Bloqueado
222                        foreach($Groups as $value)
223                        {                       
224                                if( array_search( $uid , $value['memberuid'] ) !== false )
225                                {
226                                        $ou = substr($value['dn'],strpos($value['dn'], "ou="));
227                                        $search[] = strtoupper(substr($ou, 0, strpos($ou, ",dc=")));
228                                        $search_Gid[] = $value['gidnumber'];
229                                }       
230                        }
231                }
232
233                if( $this->groupsLocked() )
234                {
235                        if( count($search) > 0 )
236                        {
237                                // Verifica permissões do grupo
238                                foreach($groupsLocked as $value)
239                                {                                                       
240                                        $tpGroups = explode(":",$value);
241                                        if( $tpGroups[1] == $search_Gid[0] )
242                                        {
243                                                $ousTp = explode(",",$tpGroups[2]);
244                                                $ou_User = substr($this->ou_User,3);
245                                               
246                                                if( array_search( $ou_User, $ousTp) !== false )
247                                                        return "true";
248                                        }
249                                }
250                                return "false";
251                        }
252                        else
253                                return "true";
254                }
255                else
256                {               
257                        // Se Bloqueado verifica o Grupo       
258                        if( count($search) > 0 )
259                        {
260                                if( array_search($this->ou_User, $search) === false )
261                                {
262                                        // Verifica permissões do grupo
263                                        foreach($groupsLocked as $value)
264                                        {                                                       
265                                                $tpGroups = explode(":",$value);
266                                                if( $tpGroups[1] == $search_Gid[0] )
267                                                {
268                                                        $ousTp = explode(",",$tpGroups[2]);
269                                                        $ou_User = substr($this->ou_User,3);
270                                                               
271                                                        if( array_search( $ou_User, $ousTp) !== false )
272                                                                return "true";
273                                                }
274                                        }
275                                        return "false";
276                                }
277                                return "true";
278                        }                                       
279                        return "true";
280                }
281        }
282}
283
284?>
Note: See TracBrowser for help on using the repository browser.