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