1 | <?php |
---|
2 | define('PHPGW_INCLUDE_ROOT','../'); |
---|
3 | define('PHPGW_API_INC','../phpgwapi/inc'); |
---|
4 | include_once(PHPGW_API_INC.'/class.common.inc.php'); |
---|
5 | include_once('class.functions.inc.php'); |
---|
6 | |
---|
7 | class ldap_functions |
---|
8 | { |
---|
9 | var $ldap; |
---|
10 | var $current_config; |
---|
11 | var $functions; |
---|
12 | var $manager_contexts; |
---|
13 | |
---|
14 | function ldap_functions(){ |
---|
15 | $GLOBALS['phpgw_info']['server'] = $_SESSION['phpgw_info']['expresso']['server']; |
---|
16 | $this->current_config = $_SESSION['phpgw_info']['expresso']['expressoAdmin']; |
---|
17 | $common = new common(); |
---|
18 | $this->ldap = $common->ldapConnect(); |
---|
19 | |
---|
20 | $this->functions = new functions; |
---|
21 | $manager_acl = $this->functions->read_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid']); |
---|
22 | $this->manager_contexts = $manager_acl['contexts']; |
---|
23 | } |
---|
24 | |
---|
25 | function validate_fields($params) |
---|
26 | { |
---|
27 | /* ldap connection following referals and using Contac Center config*/ |
---|
28 | if (is_array($_SESSION['phpgw_info']['expresso']['cc_ldap_server'])) |
---|
29 | { |
---|
30 | $ldap_connection = ldap_connect($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['host']); |
---|
31 | if ($ldap_connection) |
---|
32 | { |
---|
33 | ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
34 | ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, true); |
---|
35 | |
---|
36 | if ( ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'] != '') && ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw'] != '') ) |
---|
37 | ldap_bind($ldap_connection, $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'], $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw']); |
---|
38 | $context = $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['dn']; |
---|
39 | } |
---|
40 | else |
---|
41 | { |
---|
42 | $result['status'] = false; |
---|
43 | $result['msg'] = 'Falha na conexao com o ldap.'; |
---|
44 | return $result; |
---|
45 | } |
---|
46 | } |
---|
47 | else |
---|
48 | { |
---|
49 | $ldap_connection = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
50 | ldap_set_option($ldap_connection,LDAP_OPT_PROTOCOL_VERSION,3); |
---|
51 | ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, true); |
---|
52 | ldap_bind($ldap_connection, $GLOBALS['phpgw_info']['server']['ldap_root_dn'], $GLOBALS['phpgw_info']['server']['ldap_root_pw']); |
---|
53 | $context = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
54 | } |
---|
55 | |
---|
56 | $result['status'] = true; |
---|
57 | |
---|
58 | $params = unserialize($params['attributes']); |
---|
59 | $type = $params['type']; |
---|
60 | $uid = $params['uid']; |
---|
61 | $mail = $params['mail']; |
---|
62 | $mailalternateaddress = $params['mailalternateaddress']; |
---|
63 | |
---|
64 | if ($_SESSION['phpgw_info']['expresso']['global_denied_users'][$uid]) |
---|
65 | { |
---|
66 | $result['status'] = false; |
---|
67 | $result['msg'] = 'Este LOGIN não pode ser usado pois é uma conta de sistema.'; |
---|
68 | return $result; |
---|
69 | } |
---|
70 | |
---|
71 | if (($type == 'create_user') || ($type == 'rename_user')) |
---|
72 | { |
---|
73 | //UID |
---|
74 | if (($type == 'rename_user') && ($this->current_config['expressoAdmin_prefix_org'] == 'true')) |
---|
75 | { |
---|
76 | //Obtenho UID sem a organização. Na criação o uid já vem sem a organização |
---|
77 | $tmp_uid_without_org = split("-", $params['uid']); |
---|
78 | $tmp_reverse_uid_without_org = array_reverse($tmp_uid_without_org); |
---|
79 | array_pop($tmp_reverse_uid_without_org); |
---|
80 | $uid_without_org = implode("-", $tmp_reverse_uid_without_org); |
---|
81 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|(uid=$uid)(uid=$uid_without_org)))"; |
---|
82 | } |
---|
83 | else |
---|
84 | { |
---|
85 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uid=$uid))"; |
---|
86 | } |
---|
87 | $justthese = array("uid", "mail", "cn"); |
---|
88 | $search = ldap_search($ldap_connection, $context, $filter, $justthese); |
---|
89 | $count_entries = ldap_count_entries($ldap_connection,$search); |
---|
90 | if ($count_entries > 0) |
---|
91 | { |
---|
92 | $entries = ldap_get_entries($ldap_connection, $search); |
---|
93 | |
---|
94 | for ($i=0; $i<$entries['count']; $i++) |
---|
95 | { |
---|
96 | $users .= $entries[$i]['cn'][0] . ' - ' . $entries[$i]['mail'][0] . "\n"; |
---|
97 | } |
---|
98 | |
---|
99 | $result['status'] = false; |
---|
100 | $result['msg'] = "LOGIN já está sendo utilizado por:\n" . $users; |
---|
101 | return $result; |
---|
102 | } |
---|
103 | |
---|
104 | // GRUPOS |
---|
105 | $filter = "(&(phpgwAccountType=g)(cn=$uid))"; |
---|
106 | $justthese = array("cn"); |
---|
107 | $search = ldap_search($ldap_connection, $context, $filter, $justthese); |
---|
108 | $count_entries = ldap_count_entries($ldap_connection,$search); |
---|
109 | if ($count_entries > 0) |
---|
110 | { |
---|
111 | $result['status'] = false; |
---|
112 | $result['msg'] = 'LOGIN do usuário já esta sendo usado por um grupo.'; |
---|
113 | return $result; |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | // UID em outras organizações, pesquiso apenas na maquina local e se utilizar prefix_org |
---|
118 | if ($this->current_config['expressoAdmin_prefix_org'] == 'true') |
---|
119 | { |
---|
120 | $ldap_connection2 = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
121 | ldap_set_option($ldap_connection2,LDAP_OPT_PROTOCOL_VERSION,3); |
---|
122 | ldap_set_option($ldap_connection2, LDAP_OPT_REFERRALS, false); |
---|
123 | ldap_bind($ldap_connection2, $GLOBALS['phpgw_info']['server']['ldap_root_dn'], $GLOBALS['phpgw_info']['server']['ldap_root_pw']); |
---|
124 | $context = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
125 | |
---|
126 | //Obtenho UID sem a organização |
---|
127 | /* |
---|
128 | $tmp_uid_without_org = split("-", $params['uid']); |
---|
129 | if (count($tmp_uid_without_org) < 2) |
---|
130 | { |
---|
131 | $result['status'] = false; |
---|
132 | $result['msg'] = 'Novo login sem organização.'; |
---|
133 | return $result; |
---|
134 | } |
---|
135 | $tmp_reverse_uid_without_org = array_reverse($tmp_uid_without_org); |
---|
136 | array_pop($tmp_reverse_uid_without_org); |
---|
137 | $uid_without_org = implode("-", $tmp_reverse_uid_without_org); |
---|
138 | */ |
---|
139 | |
---|
140 | $filter = "(ou=*)"; |
---|
141 | $justthese = array("ou"); |
---|
142 | $search = ldap_list($ldap_connection2, $context, $filter, $justthese); |
---|
143 | $entries = ldap_get_entries($ldap_connection2 ,$search); |
---|
144 | |
---|
145 | foreach ($entries as $index=>$org) |
---|
146 | { |
---|
147 | $organization = $org['ou'][0]; |
---|
148 | $organization = strtolower($organization); |
---|
149 | |
---|
150 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uid=$organization-$uid))"; |
---|
151 | |
---|
152 | $justthese = array("uid"); |
---|
153 | $search = ldap_search($ldap_connection2, $context, $filter, $justthese); |
---|
154 | $count_entries = ldap_count_entries($ldap_connection2,$search); |
---|
155 | if ($count_entries > 0) |
---|
156 | { |
---|
157 | $result['status'] = false; |
---|
158 | $result['msg'] = 'LOGIN já esta sendo usado por outro usuário em outra organização.'; |
---|
159 | ldap_close($ldap_connection2); |
---|
160 | return $result; |
---|
161 | } |
---|
162 | } |
---|
163 | ldap_close($ldap_connection2); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | if ($type == 'rename_user') |
---|
168 | { |
---|
169 | return $result; |
---|
170 | } |
---|
171 | |
---|
172 | // MAIL |
---|
173 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|(mail=$mail)(mailalternateaddress=$mail)))"; |
---|
174 | $justthese = array("mail", "uid"); |
---|
175 | $search = ldap_search($ldap_connection, $context, $filter, $justthese); |
---|
176 | $entries = ldap_get_entries($ldap_connection,$search); |
---|
177 | if ($entries['count'] == 1){ |
---|
178 | if ($entries[0]['uid'][0] != $uid){ |
---|
179 | $result['status'] = false; |
---|
180 | $result['msg'] = 'E-MAIL está sendo usado por 1 usuário: ' . $entries[0]['uid'][0]; |
---|
181 | //ldap_close($ldap_connection); |
---|
182 | return $result; |
---|
183 | } |
---|
184 | } |
---|
185 | else if ($entries['count'] > 1){ |
---|
186 | $result['status'] = false; |
---|
187 | $result['msg'] = 'E-MAIL está sendo usado por 2 ou mais usuários.'; |
---|
188 | //ldap_close($ldap_connection); |
---|
189 | return $result; |
---|
190 | } |
---|
191 | |
---|
192 | // MAILAlternateAddress |
---|
193 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|(mail=$mailalternateaddress)(mailalternateaddress=$mailalternateaddress)))"; |
---|
194 | $justthese = array("mail", "uid"); |
---|
195 | $search = ldap_search($ldap_connection, $context, $filter, $justthese); |
---|
196 | $entries = ldap_get_entries($ldap_connection,$search); |
---|
197 | if ($entries['count'] == 1){ |
---|
198 | if ($entries[0]['uid'][0] != $uid){ |
---|
199 | $result['status'] = false; |
---|
200 | $result['msg'] = "E-MAIL alternativo está sendo usado por 1 usuário: " . $entries[0]['uid'][0]; |
---|
201 | //ldap_close($ldap_connection); |
---|
202 | return $result; |
---|
203 | } |
---|
204 | } |
---|
205 | else if ($entries['count'] > 1){ |
---|
206 | $result['status'] = false; |
---|
207 | $result['msg'] = 'E-MAIL alternativo está sendo usado por 2 ou mais usuários.'; |
---|
208 | return $result; |
---|
209 | } |
---|
210 | |
---|
211 | return $result; |
---|
212 | } |
---|
213 | |
---|
214 | function validate_fields_group($params) |
---|
215 | { |
---|
216 | /* ldap connection following referals and using Contac Center config*/ |
---|
217 | if (is_array($_SESSION['phpgw_info']['expresso']['cc_ldap_server'])) |
---|
218 | { |
---|
219 | $ldap_connection = ldap_connect($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['host']); |
---|
220 | if ($ldap_connection) |
---|
221 | { |
---|
222 | ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
223 | ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, true); |
---|
224 | if ( ($GLOBALS['phpgw_info']['expresso']['cc_ldap_server']['acc'] != '') && ($GLOBALS['phpgw_info']['expresso']['cc_ldap_server']['pw'] != '') ) |
---|
225 | ldap_bind($ldap_connection, $GLOBALS['phpgw_info']['expresso']['cc_ldap_server']['acc'], $GLOBALS['phpgw_info']['expresso']['cc_ldap_server']['pw']); |
---|
226 | $context = $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['dn']; |
---|
227 | } |
---|
228 | else |
---|
229 | { |
---|
230 | $result['status'] = false; |
---|
231 | $result['msg'] = 'Falha na conexao com o ldap.'; |
---|
232 | return $result; |
---|
233 | } |
---|
234 | } |
---|
235 | else |
---|
236 | { |
---|
237 | $ldap_connection = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
238 | ldap_set_option($ldap_connection,LDAP_OPT_PROTOCOL_VERSION,3); |
---|
239 | ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, true); |
---|
240 | ldap_bind($ldap_connection, $GLOBALS['phpgw_info']['server']['ldap_root_dn'], $GLOBALS['phpgw_info']['server']['ldap_root_pw']); |
---|
241 | $context = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
242 | } |
---|
243 | |
---|
244 | $cn = $params['cn']; |
---|
245 | $result['status'] = true; |
---|
246 | |
---|
247 | if ($_SESSION['phpgw_info']['expresso']['global_denied_groups'][$cn]) |
---|
248 | { |
---|
249 | $result['status'] = false; |
---|
250 | $result['msg'] = 'Este nome de grupo não pode ser usado pois é um grupo de sistema.'; |
---|
251 | return $result; |
---|
252 | } |
---|
253 | |
---|
254 | // CN |
---|
255 | $filter = "(&(phpgwAccountType=g)(cn=$cn))"; |
---|
256 | $justthese = array("cn"); |
---|
257 | $search = ldap_search($ldap_connection, $context, $filter, $justthese); |
---|
258 | $count_entries = ldap_count_entries($ldap_connection,$search); |
---|
259 | if ($count_entries > 0) |
---|
260 | { |
---|
261 | $result['status'] = false; |
---|
262 | $result['msg'] = 'NOME do grupo já está sendo usado.'; |
---|
263 | return $result; |
---|
264 | } |
---|
265 | |
---|
266 | // UID |
---|
267 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uid=$cn))"; |
---|
268 | $justthese = array("uid"); |
---|
269 | $search = ldap_search($ldap_connection, $context, $filter, $justthese); |
---|
270 | $count_entries = ldap_count_entries($ldap_connection,$search); |
---|
271 | if ($count_entries > 0) |
---|
272 | { |
---|
273 | $result['status'] = false; |
---|
274 | $result['msg'] = 'NOME do grupo já esta sendo usado por um usuário.'; |
---|
275 | return $result; |
---|
276 | } |
---|
277 | |
---|
278 | return $result; |
---|
279 | } |
---|
280 | |
---|
281 | function validate_fields_maillist($params) |
---|
282 | { |
---|
283 | /* ldap connection following referals and using Contac Center config*/ |
---|
284 | if (is_array($_SESSION['phpgw_info']['expresso']['cc_ldap_server'])) |
---|
285 | { |
---|
286 | $ldap_connection = ldap_connect($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['host']); |
---|
287 | if ($ldap_connection) |
---|
288 | { |
---|
289 | ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
290 | ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, true); |
---|
291 | if ( ($GLOBALS['phpgw_info']['expresso']['cc_ldap_server']['acc'] != '') && ($GLOBALS['phpgw_info']['expresso']['cc_ldap_server']['pw'] != '') ) |
---|
292 | ldap_bind($ldap_connection, $GLOBALS['phpgw_info']['expresso']['cc_ldap_server']['acc'], $GLOBALS['phpgw_info']['expresso']['cc_ldap_server']['pw']); |
---|
293 | $context = $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['dn']; |
---|
294 | } |
---|
295 | else |
---|
296 | { |
---|
297 | $result['status'] = false; |
---|
298 | $result['msg'] = 'Falha na conexao com o ldap.'; |
---|
299 | return $result; |
---|
300 | } |
---|
301 | } |
---|
302 | else |
---|
303 | { |
---|
304 | $ldap_connection = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
305 | ldap_set_option($ldap_connection,LDAP_OPT_PROTOCOL_VERSION,3); |
---|
306 | ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, true); |
---|
307 | ldap_bind($ldap_connection, $GLOBALS['phpgw_info']['server']['ldap_root_dn'], $GLOBALS['phpgw_info']['server']['ldap_root_pw']); |
---|
308 | $context = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
309 | } |
---|
310 | |
---|
311 | $uid = $params['uid']; |
---|
312 | $mail = $params['mail']; |
---|
313 | $result['status'] = true; |
---|
314 | |
---|
315 | if ($_SESSION['phpgw_info']['expresso']['global_denied_users'][$uid]) |
---|
316 | { |
---|
317 | $result['status'] = false; |
---|
318 | $result['msg'] = 'Este LOGIN não pode ser usado pois é uma conta de sistema.'; |
---|
319 | return $result; |
---|
320 | } |
---|
321 | |
---|
322 | // UID |
---|
323 | $filter = "(&(phpgwAccountType=l)(uid=$uid))"; |
---|
324 | $justthese = array("uid"); |
---|
325 | $search = ldap_search($ldap_connection, $context, $filter, $justthese); |
---|
326 | $count_entries = ldap_count_entries($ldap_connection,$search); |
---|
327 | if ($count_entries > 0) |
---|
328 | { |
---|
329 | $result['status'] = false; |
---|
330 | $result['msg'] = 'LOGIN da lista já está sendo usado.'; |
---|
331 | return $result; |
---|
332 | } |
---|
333 | |
---|
334 | // MAIL |
---|
335 | /* |
---|
336 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|(mail=$mail)(mailalternateaddress=$mail)))"; |
---|
337 | $justthese = array("mail"); |
---|
338 | $search = ldap_search($ldap_connection, $context, $filter, $justthese); |
---|
339 | $count_entries = ldap_count_entries($ldap_connection,$search); |
---|
340 | if ($count_entries > 0) |
---|
341 | { |
---|
342 | $result['status'] = false; |
---|
343 | $result['msg'] = 'E-MAIL da lista já está sendo usado.'; |
---|
344 | return $result; |
---|
345 | }*/ |
---|
346 | |
---|
347 | return $result; |
---|
348 | } |
---|
349 | |
---|
350 | //Busca usuários de um contexto e já retorna as options do select; |
---|
351 | function get_available_users($params) |
---|
352 | { |
---|
353 | $context = $params['context']; |
---|
354 | $recursive = $params['recursive']; |
---|
355 | $justthese = array("cn", "uidNumber"); |
---|
356 | $filter="(phpgwAccountType=u)"; |
---|
357 | |
---|
358 | if ($recursive == 'true') |
---|
359 | $groups_list=ldap_search($this->ldap, $context, $filter, $justthese); |
---|
360 | else |
---|
361 | $groups_list=ldap_list($this->ldap, $context, $filter, $justthese); |
---|
362 | |
---|
363 | $entries = ldap_get_entries($this->ldap, $groups_list); |
---|
364 | |
---|
365 | for ($i=0; $i<$entries["count"]; $i++){ |
---|
366 | $u_tmp[$entries[$i]["uidnumber"][0]] = $entries[$i]["cn"][0]; |
---|
367 | } |
---|
368 | |
---|
369 | if (count($u_tmp)) |
---|
370 | natcasesort($u_tmp); |
---|
371 | |
---|
372 | $i = 0; |
---|
373 | $users = array(); |
---|
374 | |
---|
375 | if (count($u_tmp)) |
---|
376 | { |
---|
377 | foreach ($u_tmp as $uidnumber => $cn) |
---|
378 | { |
---|
379 | $options .= "<option value=$uidnumber>$cn</option>"; |
---|
380 | } |
---|
381 | unset($u_tmp); |
---|
382 | } |
---|
383 | |
---|
384 | return $options; |
---|
385 | } |
---|
386 | |
---|
387 | //Busca usuários de um contexto e já retorna as options do select; |
---|
388 | /* |
---|
389 | function get_available_users_and_maillist($params) |
---|
390 | { |
---|
391 | $context = $params['context']; |
---|
392 | $recursive = $params['recursive']; |
---|
393 | $justthese = array("cn", "uidNumber"); |
---|
394 | $filter="(|(phpgwAccountType=u)(phpgwAccountType=l))"; |
---|
395 | |
---|
396 | if ($recursive == 'true') |
---|
397 | $groups_list=ldap_search($this->ldap, $context, $filter, $justthese); |
---|
398 | else |
---|
399 | $groups_list=ldap_list($this->ldap, $context, $filter, $justthese); |
---|
400 | |
---|
401 | $entries = ldap_get_entries($this->ldap, $groups_list); |
---|
402 | |
---|
403 | for ($i=0; $i<$entries["count"]; $i++){ |
---|
404 | $u_tmp[$entries[$i]["uidnumber"][0]] = $entries[$i]["cn"][0]; |
---|
405 | } |
---|
406 | |
---|
407 | if (count($u_tmp)) |
---|
408 | natcasesort($u_tmp); |
---|
409 | |
---|
410 | $i = 0; |
---|
411 | $users = array(); |
---|
412 | |
---|
413 | if (count($u_tmp)) |
---|
414 | { |
---|
415 | foreach ($u_tmp as $uidnumber => $cn) |
---|
416 | { |
---|
417 | $options .= "<option value=$uidnumber>$cn</option>"; |
---|
418 | } |
---|
419 | unset($u_tmp); |
---|
420 | } |
---|
421 | |
---|
422 | return $options; |
---|
423 | } |
---|
424 | */ |
---|
425 | |
---|
426 | //Busca usuários e listas de um contexto e já retorna as options do select; |
---|
427 | function get_available_users_and_maillist($params) |
---|
428 | { |
---|
429 | $context = $params['context']; |
---|
430 | $recursive = $params['recursive']; |
---|
431 | |
---|
432 | //Usado para retirar a própria lista das possibilidades de inclusão. |
---|
433 | $denied_uidnumber = $params['denied_uidnumber']; |
---|
434 | |
---|
435 | $justthese = array("cn", "uidNumber", "mail"); |
---|
436 | |
---|
437 | $users_filter="(phpgwAccountType=u)"; |
---|
438 | $lists_filter = $denied_uidnumber == '' ? "(phpgwAccountType=l)" : "(&(phpgwAccountType=l)(!(uidnumber=$denied_uidnumber)))"; |
---|
439 | |
---|
440 | $users = Array(); |
---|
441 | $lists = Array(); |
---|
442 | |
---|
443 | /* folling referral connection */ |
---|
444 | $ldap_conn_following_ref = ldap_connect($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['host']); |
---|
445 | if ($ldap_conn_following_ref) |
---|
446 | { |
---|
447 | ldap_set_option($ldap_conn_following_ref, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
448 | ldap_set_option($ldap_conn_following_ref, LDAP_OPT_REFERRALS, 1); |
---|
449 | |
---|
450 | if ( ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'] != '') && ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw'] != '') ) |
---|
451 | ldap_bind($ldap_conn_following_ref, $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'], $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw']); |
---|
452 | } |
---|
453 | else |
---|
454 | return false; |
---|
455 | |
---|
456 | if ($recursive == 'true') |
---|
457 | { |
---|
458 | $lists_search = ldap_search($ldap_conn_following_ref, $context, $lists_filter, $justthese); |
---|
459 | $users_search = ldap_search($ldap_conn_following_ref, $context, $users_filter, $justthese); |
---|
460 | } |
---|
461 | else |
---|
462 | { |
---|
463 | $lists_search = ldap_list($ldap_conn_following_ref, $context, $lists_filter, $justthese); |
---|
464 | $users_search = ldap_list($ldap_conn_following_ref, $context, $users_filter, $justthese); |
---|
465 | } |
---|
466 | |
---|
467 | /* email lists */ |
---|
468 | $lists_entries = ldap_get_entries($ldap_conn_following_ref, $lists_search); |
---|
469 | |
---|
470 | for ($i=0; $i<$lists_entries["count"]; $i++) |
---|
471 | { |
---|
472 | $l_tmp[$lists_entries[$i]["mail"][0]] = $lists_entries[$i]["cn"][0]; |
---|
473 | } |
---|
474 | |
---|
475 | if (count($l_tmp)) |
---|
476 | natcasesort($l_tmp); |
---|
477 | |
---|
478 | $i = 0; |
---|
479 | $lists = array(); |
---|
480 | |
---|
481 | $options .= '<option value="-1" disabled>------------------------------ Listas ------------------------------ </option>'."\n"; |
---|
482 | if (count($l_tmp)) |
---|
483 | { |
---|
484 | foreach ($l_tmp as $mail => $cn) |
---|
485 | { |
---|
486 | $options .= "<option value=$mail>$cn</option>"; |
---|
487 | } |
---|
488 | unset($l_tmp); |
---|
489 | } |
---|
490 | |
---|
491 | /* users */ |
---|
492 | $users_entries = ldap_get_entries($ldap_conn_following_ref, $users_search); |
---|
493 | for ($i=0; $i<$users_entries["count"]; $i++) |
---|
494 | { |
---|
495 | $u_tmp[$users_entries[$i]["mail"][0]] = $users_entries[$i]["cn"][0]; |
---|
496 | } |
---|
497 | |
---|
498 | if (count($u_tmp)) |
---|
499 | natcasesort($u_tmp); |
---|
500 | |
---|
501 | $i = 0; |
---|
502 | $users = array(); |
---|
503 | |
---|
504 | $options .= '<option value="-1" disabled>----------------------------- Usuários ---------------------------- </option>'."\n"; |
---|
505 | if (count($u_tmp)) |
---|
506 | { |
---|
507 | foreach ($u_tmp as $mail => $cn) |
---|
508 | { |
---|
509 | $options .= "<option value=$mail class='line-above'>$cn</option>"; |
---|
510 | } |
---|
511 | unset($u_tmp); |
---|
512 | } |
---|
513 | |
---|
514 | ldap_close($ldap_conn_following_ref); |
---|
515 | return $options; |
---|
516 | } |
---|
517 | |
---|
518 | function get_available_groups($params) |
---|
519 | { |
---|
520 | $context = $params['context']; |
---|
521 | $justthese = array("cn", "gidNumber"); |
---|
522 | $groups_list=ldap_list($this->ldap, $context, ("(phpgwAccountType=g)"), $justthese); |
---|
523 | ldap_sort($this->ldap, $groups_list, "cn"); |
---|
524 | |
---|
525 | $entries = ldap_get_entries($this->ldap, $groups_list); |
---|
526 | |
---|
527 | $options = ''; |
---|
528 | for ($i=0; $i<$entries['count']; $i++) |
---|
529 | { |
---|
530 | $options .= "<option value=" . $entries[$i]['gidnumber'][0] . ">" . $entries[$i]['cn'][0] . "</option>"; |
---|
531 | } |
---|
532 | |
---|
533 | return $options; |
---|
534 | } |
---|
535 | |
---|
536 | function get_available_maillists($params) |
---|
537 | { |
---|
538 | $context = $params['context']; |
---|
539 | $justthese = array("uid","mail","uidNumber"); |
---|
540 | $maillists=ldap_list($this->ldap, $context, ("(phpgwAccountType=l)"), $justthese); |
---|
541 | ldap_sort($this->ldap, $maillists, "uid"); |
---|
542 | |
---|
543 | $entries = ldap_get_entries($this->ldap, $maillists); |
---|
544 | |
---|
545 | $options = ''; |
---|
546 | for ($i=0; $i<$entries['count']; $i++) |
---|
547 | { |
---|
548 | $options .= "<option value=" . $entries[$i]['uidnumber'][0] . ">" . $entries[$i]['uid'][0] . " (" . $entries[$i]['mail'][0] . ")" . "</option>"; |
---|
549 | } |
---|
550 | return $options; |
---|
551 | } |
---|
552 | |
---|
553 | function ldap_add_entry($dn, $entry) |
---|
554 | { |
---|
555 | $result = array(); |
---|
556 | if (!@ldap_add ( $this->ldap, $dn, $entry )) |
---|
557 | { |
---|
558 | $result['status'] = false; |
---|
559 | $result['msg'] = "Erro na funcao ldap_functions->ldap_add_entry ($dn).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
560 | } |
---|
561 | else |
---|
562 | $result['status'] = true; |
---|
563 | |
---|
564 | return $result; |
---|
565 | } |
---|
566 | |
---|
567 | function ldap_save_photo($dn, $pathphoto, $photo_exist=false) |
---|
568 | { |
---|
569 | $fd = fopen($pathphoto, "r"); |
---|
570 | $fsize = filesize($pathphoto); |
---|
571 | $jpegStr = fread($fd, $fsize); |
---|
572 | fclose ($fd); |
---|
573 | $attrs['jpegPhoto'] = $jpegStr; |
---|
574 | |
---|
575 | if ($photo_exist) |
---|
576 | $res = @ldap_mod_replace($this->ldap, $dn, $attrs); |
---|
577 | else |
---|
578 | $res = @ldap_mod_add($this->ldap, $dn, $attrs); |
---|
579 | |
---|
580 | if ($res) |
---|
581 | { |
---|
582 | $result['status'] = true; |
---|
583 | } |
---|
584 | else |
---|
585 | { |
---|
586 | $result['status'] = false; |
---|
587 | $result['msg'] = "Erro na funcao ldap_functions->ldap_save_photo ($dn).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
588 | } |
---|
589 | |
---|
590 | return $result; |
---|
591 | } |
---|
592 | |
---|
593 | function ldap_remove_photo($dn) |
---|
594 | { |
---|
595 | $attrs['jpegPhoto'] = array(); |
---|
596 | $res = ldap_mod_del($this->ldap, $dn, $attrs); |
---|
597 | |
---|
598 | if ($res) |
---|
599 | { |
---|
600 | $result['status'] = true; |
---|
601 | } |
---|
602 | else |
---|
603 | { |
---|
604 | $result['status'] = false; |
---|
605 | $result['msg'] = "Erro na funcao ldap_functions->ldap_remove_photo ($dn).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
606 | } |
---|
607 | |
---|
608 | return $result; |
---|
609 | } |
---|
610 | |
---|
611 | // Pode receber tanto um único memberUid quanto um array de memberUid's |
---|
612 | function add_user2group($gidNumber, $memberUid) |
---|
613 | { |
---|
614 | $filter = "(&(phpgwAccountType=g)(gidNumber=$gidNumber))"; |
---|
615 | $justthese = array("dn"); |
---|
616 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
617 | $entry = ldap_get_entries($this->ldap, $search); |
---|
618 | $group_dn = $entry[0]['dn']; |
---|
619 | $attrs['memberUid'] = $memberUid; |
---|
620 | |
---|
621 | $res = @ldap_mod_add($this->ldap, $group_dn, $attrs); |
---|
622 | |
---|
623 | if ($res) |
---|
624 | { |
---|
625 | $result['status'] = true; |
---|
626 | } |
---|
627 | else |
---|
628 | { |
---|
629 | $result['status'] = false; |
---|
630 | $result['msg'] = "Erro na funcao ldap_functions->add_user2group ($memberUid).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
631 | } |
---|
632 | return $result; |
---|
633 | } |
---|
634 | |
---|
635 | function remove_user2group($gidNumber, $memberUid) |
---|
636 | { |
---|
637 | $filter = "(&(phpgwAccountType=g)(gidNumber=$gidNumber))"; |
---|
638 | $justthese = array("dn"); |
---|
639 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
640 | $entry = ldap_get_entries($this->ldap, $search); |
---|
641 | $group_dn = $entry[0]['dn']; |
---|
642 | $attrs['memberUid'] = $memberUid; |
---|
643 | $res = @ldap_mod_del($this->ldap, $group_dn, $attrs); |
---|
644 | |
---|
645 | /*echo 'usuarios recebidos para remocao no ldap'; |
---|
646 | echo '<pre>'; |
---|
647 | print_r($memberUid);*/ |
---|
648 | |
---|
649 | if ($res) |
---|
650 | { |
---|
651 | $result['status'] = true; |
---|
652 | } |
---|
653 | else |
---|
654 | { |
---|
655 | $result['status'] = false; |
---|
656 | $result['msg'] = "Erro na funcao ldap_functions->remove_user2group ($memberUid).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
657 | } |
---|
658 | return $result; |
---|
659 | } |
---|
660 | |
---|
661 | function add_user2maillist($uidNumber, $mail) |
---|
662 | { |
---|
663 | $filter = "(&(phpgwAccountType=l)(uidNumber=$uidNumber))"; |
---|
664 | $justthese = array("dn"); |
---|
665 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
666 | $entry = ldap_get_entries($this->ldap, $search); |
---|
667 | $group_dn = $entry[0]['dn']; |
---|
668 | $attrs['mailForwardingAddress'] = $mail; |
---|
669 | $res = @ldap_mod_add($this->ldap, $group_dn, $attrs); |
---|
670 | |
---|
671 | if ($res) |
---|
672 | { |
---|
673 | $result['status'] = true; |
---|
674 | } |
---|
675 | else |
---|
676 | { |
---|
677 | $result['status'] = false; |
---|
678 | $result['msg'] = "Erro na funcao ldap_functions->add_user2maillist ($mail).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
679 | } |
---|
680 | return $result; |
---|
681 | } |
---|
682 | |
---|
683 | function add_user2maillist_scl($dn, $array_emails) |
---|
684 | { |
---|
685 | $attrs['mailSenderAddress'] = $array_emails; |
---|
686 | $res = @ldap_mod_add($this->ldap, $dn, $attrs); |
---|
687 | |
---|
688 | if ($res) |
---|
689 | { |
---|
690 | $result['status'] = true; |
---|
691 | } |
---|
692 | else |
---|
693 | { |
---|
694 | $result['status'] = false; |
---|
695 | $result['msg'] = "Erro na funcao ldap_functions->add_user2maillist_scp ($dn).\n\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
696 | } |
---|
697 | return $result; |
---|
698 | } |
---|
699 | |
---|
700 | function remove_user2maillist($uidNumber, $mail) |
---|
701 | { |
---|
702 | $filter = "(&(phpgwAccountType=l)(uidNumber=$uidNumber))"; |
---|
703 | $justthese = array("dn"); |
---|
704 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
705 | $entry = ldap_get_entries($this->ldap, $search); |
---|
706 | $group_dn = $entry[0]['dn']; |
---|
707 | $attrs['mailForwardingAddress'] = $mail; |
---|
708 | $res = @ldap_mod_del($this->ldap, $group_dn, $attrs); |
---|
709 | |
---|
710 | if ($res) |
---|
711 | { |
---|
712 | $result['status'] = true; |
---|
713 | } |
---|
714 | else |
---|
715 | { |
---|
716 | $result['status'] = false; |
---|
717 | $result['msg'] = "Erro na funcao ldap_functions->remove_user2maillist ($mail).\n\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
718 | } |
---|
719 | return $result; |
---|
720 | } |
---|
721 | |
---|
722 | function remove_user2maillist_scl($dn, $array_emails) |
---|
723 | { |
---|
724 | $attrs['mailSenderAddress'] = $array_emails; |
---|
725 | $res = @ldap_mod_del($this->ldap, $dn, $attrs); |
---|
726 | |
---|
727 | if ($res) |
---|
728 | { |
---|
729 | $result['status'] = true; |
---|
730 | } |
---|
731 | else |
---|
732 | { |
---|
733 | $result['status'] = false; |
---|
734 | $result['msg'] = "Erro na funcao ldap_functions->remove_user2maillist_scp ($dn).\n\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
735 | } |
---|
736 | return $result; |
---|
737 | } |
---|
738 | |
---|
739 | function replace_user2maillists($new_mail, $old_mail) |
---|
740 | { |
---|
741 | $filter = "(&(phpgwAccountType=l)(mailforwardingaddress=$old_mail))"; |
---|
742 | $justthese = array("dn"); |
---|
743 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
744 | $entries = ldap_get_entries($this->ldap, $search); |
---|
745 | $result['status'] = true; |
---|
746 | for ($i=0; $i<$entries['count']; $i++) |
---|
747 | { |
---|
748 | $attrs['mailforwardingaddress'] = $old_mail; |
---|
749 | $res1 = @ldap_mod_del($this->ldap, $entries[$i]['dn'], $attrs); |
---|
750 | $attrs['mailforwardingaddress'] = $new_mail; |
---|
751 | $res2 = @ldap_mod_add($this->ldap, $entries[$i]['dn'], $attrs); |
---|
752 | |
---|
753 | if ((!$res1) || (!$res2)) |
---|
754 | { |
---|
755 | $result['status'] = false; |
---|
756 | $result['msg'] = "Erro na funcao ldap_functions->replace_user2maillists ($old_mail).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
757 | } |
---|
758 | } |
---|
759 | |
---|
760 | return $result; |
---|
761 | } |
---|
762 | |
---|
763 | function get_user_info($uidnumber) |
---|
764 | { |
---|
765 | foreach ($this->manager_contexts as $index=>$context) |
---|
766 | { |
---|
767 | $filter="(&(phpgwAccountType=u)(uidNumber=".$uidnumber."))"; |
---|
768 | $search = ldap_search($this->ldap, $context, $filter); |
---|
769 | $entry = ldap_get_entries($this->ldap, $search); |
---|
770 | |
---|
771 | if ($entry['count']) |
---|
772 | { |
---|
773 | //Pega o dn do setor do usuario. |
---|
774 | $entry[0]['dn'] = strtolower($entry[0]['dn']); |
---|
775 | $sector_dn_array = explode(",", $entry[0]['dn']); |
---|
776 | for($i=1; $i<count($sector_dn_array); $i++) |
---|
777 | $sector_dn .= $sector_dn_array[$i] . ','; |
---|
778 | //Retira ultimo pipe. |
---|
779 | $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); |
---|
780 | |
---|
781 | $result['context'] = $sector_dn; |
---|
782 | $result['uid'] = $entry[0]['uid'][0]; |
---|
783 | $result['uidnumber'] = $entry[0]['uidnumber'][0]; |
---|
784 | $result['gidnumber'] = $entry[0]['gidnumber'][0]; |
---|
785 | $result['departmentnumber'] = $entry[0]['departmentnumber'][0]; |
---|
786 | $result['givenname'] = $entry[0]['givenname'][0]; |
---|
787 | $result['sn'] = $entry[0]['sn'][0]; |
---|
788 | $result['telephonenumber'] = $entry[0]['telephonenumber'][0]; |
---|
789 | $result['passwd_expired'] = $entry[0]['phpgwlastpasswdchange'][0]; |
---|
790 | $result['phpgwaccountstatus'] = $entry[0]['phpgwaccountstatus'][0]; |
---|
791 | $result['phpgwaccountvisible'] = $entry[0]['phpgwaccountvisible'][0]; |
---|
792 | $result['accountstatus'] = $entry[0]['accountstatus'][0]; |
---|
793 | $result['mail'] = $entry[0]['mail'][0]; |
---|
794 | $result['mailalternateaddress'] = $entry[0]['mailalternateaddress']; |
---|
795 | $result['mailforwardingaddress']= $entry[0]['mailforwardingaddress']; |
---|
796 | $result['deliverymode'] = $entry[0]['deliverymode'][0]; |
---|
797 | $result['userPasswordRFC2617'] = $entry[0]['userpasswordrfc2617'][0]; |
---|
798 | |
---|
799 | //Photo |
---|
800 | if ($entry[0]['jpegphoto']['count'] == 1) |
---|
801 | $result['photo_exist'] = 'true'; |
---|
802 | |
---|
803 | // Samba |
---|
804 | for ($i=0; $i<$entry[0]['objectclass']['count']; $i++) |
---|
805 | { |
---|
806 | if ($entry[0]['objectclass'][$i] == 'sambaSamAccount') |
---|
807 | $result['sambaUser'] = true; |
---|
808 | } |
---|
809 | if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($result['sambaUser'])) |
---|
810 | { |
---|
811 | $result['sambaaccflags'] = $entry[0]['sambaacctflags'][0]; |
---|
812 | $result['sambalogonscript'] = $entry[0]['sambalogonscript'][0]; |
---|
813 | $result['homedirectory'] = $entry[0]['homedirectory'][0]; |
---|
814 | $a_tmp = explode("-", $entry[0]['sambasid'][0]); |
---|
815 | array_pop($a_tmp); |
---|
816 | $result['sambasid'] = implode("-", $a_tmp); |
---|
817 | } |
---|
818 | |
---|
819 | // Verifica o acesso do gerente aos atributos corporativos |
---|
820 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'manipulate_corporative_information')) |
---|
821 | { |
---|
822 | $result['corporative_information_employeenumber']= $entry[0]['employeenumber'][0]; |
---|
823 | $result['corporative_information_cpf'] = $entry[0]['cpf'][0]; |
---|
824 | $result['corporative_information_rg'] = $entry[0]['rg'][0]; |
---|
825 | $result['corporative_information_rguf'] = $entry[0]['rguf'][0]; |
---|
826 | } |
---|
827 | |
---|
828 | // MailLists |
---|
829 | $result['maillists_info'] = $this->get_user_maillists($result['mail']); |
---|
830 | if($result['maillists_info']) |
---|
831 | foreach ($result['maillists_info'] as $maillist) |
---|
832 | { |
---|
833 | $result['maillists'][] = $maillist['uidnumber']; |
---|
834 | } |
---|
835 | |
---|
836 | // Groups |
---|
837 | $justthese = array("gidnumber","cn"); |
---|
838 | $filter="(&(phpgwAccountType=g)(memberuid=".$result['uid']."))"; |
---|
839 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
840 | ldap_sort($this->ldap, $search, "cn"); |
---|
841 | $entries = ldap_get_entries($this->ldap, $search); |
---|
842 | for ($i=0; $i<$entries['count']; $i++) |
---|
843 | { |
---|
844 | $result['groups_ldap'][ $entries[$i]['gidnumber'][0] ] = $entries[$i]['cn'][0]; |
---|
845 | } |
---|
846 | } |
---|
847 | } |
---|
848 | return $result; |
---|
849 | } |
---|
850 | |
---|
851 | function get_user_maillists($mail) |
---|
852 | { |
---|
853 | $result = array(); |
---|
854 | |
---|
855 | //Mostra somente os mailists dos contextos do gerente |
---|
856 | $justthese = array("uid","mail","uidnumber"); |
---|
857 | $filter="(&(phpgwAccountType=l)(mailforwardingaddress=$mail))"; |
---|
858 | |
---|
859 | foreach ($this->manager_contexts as $index=>$context) |
---|
860 | { |
---|
861 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
862 | //ldap_sort($this->ldap, $search, "uid"); |
---|
863 | $entries = ldap_get_entries($this->ldap, $search); |
---|
864 | |
---|
865 | for ($i=0; $i<$entries['count']; $i++) |
---|
866 | { |
---|
867 | $result[ $entries[$i]['uid'][0] ]['uidnumber'] = $entries[$i]['uidnumber'][0]; |
---|
868 | $result[ $entries[$i]['uid'][0] ]['uid'] = $entries[$i]['uid'][0]; |
---|
869 | $result[ $entries[$i]['uid'][0] ]['mail'] = $entries[$i]['mail'][0]; |
---|
870 | |
---|
871 | $a_tmp[] = $entries[$i]['uid'][0]; |
---|
872 | } |
---|
873 | } |
---|
874 | |
---|
875 | if($a_tmp) { |
---|
876 | natcasesort($a_tmp); |
---|
877 | |
---|
878 | foreach ($a_tmp as $uid) |
---|
879 | { |
---|
880 | $return[$uid]['uidnumber'] = $result[$uid]['uidnumber']; |
---|
881 | $return[$uid]['uid'] = $result[$uid]['uid']; |
---|
882 | $return[$uid]['mail'] = $result[$uid]['mail']; |
---|
883 | } |
---|
884 | } |
---|
885 | return $return; |
---|
886 | } |
---|
887 | |
---|
888 | function get_group_info($gidnumber) |
---|
889 | { |
---|
890 | foreach ($this->manager_contexts as $index=>$context) |
---|
891 | { |
---|
892 | $filter="(&(phpgwAccountType=g)(gidNumber=".$gidnumber."))"; |
---|
893 | $search = ldap_search($this->ldap, $context, $filter); |
---|
894 | $entry = ldap_get_entries($this->ldap, $search); |
---|
895 | |
---|
896 | if ($entry['count']) |
---|
897 | { |
---|
898 | //Pega o dn do setor do grupo. |
---|
899 | $entry[0]['dn'] = strtolower($entry[0]['dn']); |
---|
900 | $sector_dn_array = explode(",", $entry[0]['dn']); |
---|
901 | for($i=1; $i<count($sector_dn_array); $i++) |
---|
902 | $sector_dn .= $sector_dn_array[$i] . ','; |
---|
903 | //Retira ultimo pipe. |
---|
904 | $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); |
---|
905 | |
---|
906 | $result['context'] = $sector_dn; |
---|
907 | $result['cn'] = $entry[0]['cn'][0]; |
---|
908 | $result['description'] = $entry[0]['description'][0]; |
---|
909 | $result['gidnumber'] = $entry[0]['gidnumber'][0]; |
---|
910 | $result['phpgwaccountvisible'] = $entry[0]['phpgwaccountvisible'][0]; |
---|
911 | $result['email'] = $entry[0]['mail'][0]; |
---|
912 | |
---|
913 | //MemberUid |
---|
914 | for ($i=0; $i<$entry[0]['memberuid']['count']; $i++) |
---|
915 | { |
---|
916 | $justthese = array("cn","uid","uidnumber"); |
---|
917 | |
---|
918 | // Montagem dinamica do filtro |
---|
919 | $filter="(&(phpgwAccountType=u)(|"; |
---|
920 | for ($k=0; (($k<10) && ($i<$entry[0]['memberuid']['count'])); $k++) |
---|
921 | { |
---|
922 | $filter .= "(uid=".$entry[0]['memberuid'][$i].")"; |
---|
923 | $i++; |
---|
924 | } |
---|
925 | $i--; |
---|
926 | $filter .= "))"; |
---|
927 | |
---|
928 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
929 | $user_entry = ldap_get_entries($this->ldap, $search); |
---|
930 | |
---|
931 | for ($j=0; $j<$user_entry['count']; $j++) |
---|
932 | { |
---|
933 | $result['memberuid_info'][$user_entry[$j]['uid'][0]]['cn'] = $user_entry[$j]['cn'][0]; |
---|
934 | $result['memberuid_info'][$user_entry[$j]['uid'][0]]['uidnumber'] = $user_entry[$j]['uidnumber'][0]; |
---|
935 | $result['memberuid_info'][$user_entry[$j]['uid'][0]]['type'] = 'u'; |
---|
936 | } |
---|
937 | } |
---|
938 | |
---|
939 | // Checamos e-mails que não fazem parte do expresso. |
---|
940 | // Criamos um array temporario |
---|
941 | $tmp_array = array(); |
---|
942 | if($result['memberuid_info']) |
---|
943 | foreach ($result['memberuid_info'] as $uid => $user_data) |
---|
944 | { |
---|
945 | $tmp_array[] = $uid; |
---|
946 | } |
---|
947 | |
---|
948 | if($entry[0]['memberuid']) { |
---|
949 | // Retira o count do array |
---|
950 | array_shift($entry[0]['memberuid']); |
---|
951 | // Vemos a diferença |
---|
952 | $array_diff = array_diff($entry[0]['memberuid'], $tmp_array); |
---|
953 | // Incluimos no resultado |
---|
954 | foreach ($array_diff as $index=>$uid) |
---|
955 | { |
---|
956 | $result['memberuid_info'][$uid]['cn'] = $uid; |
---|
957 | } |
---|
958 | } |
---|
959 | |
---|
960 | // Samba |
---|
961 | for ($i=0; $i<$entry[0]['objectclass']['count']; $i++) |
---|
962 | { |
---|
963 | if ($entry[0]['objectclass'][$i] == 'sambaGroupMapping') |
---|
964 | $result['sambaGroup'] = true; |
---|
965 | |
---|
966 | $a_tmp = explode("-", $entry[0]['sambasid'][0]); |
---|
967 | array_pop($a_tmp); |
---|
968 | $result['sambasid'] = implode("-", $a_tmp); |
---|
969 | } |
---|
970 | return $result; |
---|
971 | } |
---|
972 | } |
---|
973 | } |
---|
974 | |
---|
975 | function get_maillist_info($uidnumber) |
---|
976 | { |
---|
977 | |
---|
978 | /* folling referral connection */ |
---|
979 | $ldap_conn_following_ref = ldap_connect($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['host']); |
---|
980 | if ($ldap_conn_following_ref) |
---|
981 | { |
---|
982 | ldap_set_option($ldap_conn_following_ref, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
983 | ldap_set_option($ldap_conn_following_ref, LDAP_OPT_REFERRALS, 1); |
---|
984 | |
---|
985 | if ( ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'] != '') && ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw'] != '') ) |
---|
986 | ldap_bind($ldap_conn_following_ref, $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'], $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw']); |
---|
987 | } |
---|
988 | |
---|
989 | foreach ($this->manager_contexts as $index=>$context) |
---|
990 | { |
---|
991 | $filter="(&(phpgwAccountType=l)(uidNumber=".$uidnumber."))"; |
---|
992 | $search = ldap_search($this->ldap, $context, $filter); |
---|
993 | $entry = ldap_get_entries($this->ldap, $search); |
---|
994 | |
---|
995 | if ($entry['count']) |
---|
996 | { |
---|
997 | //Pega o dn do setor do usuario. |
---|
998 | $entry[0]['dn'] = strtolower($entry[0]['dn']); |
---|
999 | $sector_dn_array = explode(",", $entry[0]['dn']); |
---|
1000 | for($i=1; $i<count($sector_dn_array); $i++) |
---|
1001 | $sector_dn .= $sector_dn_array[$i] . ','; |
---|
1002 | //Retira ultimo pipe. |
---|
1003 | $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); |
---|
1004 | |
---|
1005 | $result['context'] = $sector_dn; |
---|
1006 | $result['uidnumber'] = $entry[0]['uidnumber'][0]; |
---|
1007 | $result['uid'] = strtolower($entry[0]['uid'][0]); |
---|
1008 | $result['cn'] = $entry[0]['cn'][0]; |
---|
1009 | $result['mail'] = $entry[0]['mail'][0]; |
---|
1010 | $result['accountStatus'] = $entry[0]['accountstatus'][0]; |
---|
1011 | $result['phpgwAccountVisible'] = $entry[0]['phpgwaccountvisible'][0]; |
---|
1012 | |
---|
1013 | //Members |
---|
1014 | for ($i=0; $i<$entry[0]['mailforwardingaddress']['count']; $i++) |
---|
1015 | { |
---|
1016 | $justthese = array("cn", "uidnumber", "uid", "phpgwaccounttype", "mail"); |
---|
1017 | |
---|
1018 | // Montagem dinamica do filtro, para nao ter muitas conexoes com o ldap |
---|
1019 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|"; |
---|
1020 | for ($k=0; (($k<10) && ($i<$entry[0]['mailforwardingaddress']['count'])); $k++) |
---|
1021 | { |
---|
1022 | $filter .= "(mail=".$entry[0]['mailforwardingaddress'][$i].")"; |
---|
1023 | $i++; |
---|
1024 | } |
---|
1025 | $i--; |
---|
1026 | $filter .= "))"; |
---|
1027 | |
---|
1028 | $search = ldap_search($ldap_conn_following_ref, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1029 | $user_entry = ldap_get_entries($ldap_conn_following_ref, $search); |
---|
1030 | |
---|
1031 | for ($j=0; $j<$user_entry['count']; $j++) |
---|
1032 | { |
---|
1033 | $result['mailForwardingAddress_info'][$user_entry[$j]['mail'][0]]['uid'] = $user_entry[$j]['uid'][0]; |
---|
1034 | $result['mailForwardingAddress_info'][$user_entry[$j]['mail'][0]]['cn'] = $user_entry[$j]['cn'][0]; |
---|
1035 | $result['mailForwardingAddress_info'][$user_entry[$j]['mail'][0]]['type'] = $user_entry[$j]['phpgwaccounttype'][0]; |
---|
1036 | $result['mailForwardingAddress'][] = $user_entry[$j]['mail'][0]; |
---|
1037 | } |
---|
1038 | } |
---|
1039 | |
---|
1040 | // Emails não encontrados no ldap |
---|
1041 | array_shift($entry[0]['mailforwardingaddress']); //Retira o count do array |
---|
1042 | $missing_emails = array_diff($entry[0]['mailforwardingaddress'], $result['mailForwardingAddress']); |
---|
1043 | |
---|
1044 | // Incluimos estes no resultado |
---|
1045 | foreach ($missing_emails as $index=>$mailforwardingaddress) |
---|
1046 | { |
---|
1047 | $result['mailForwardingAddress_info'][$mailforwardingaddress]['uid'] = $mailforwardingaddress; |
---|
1048 | $result['mailForwardingAddress_info'][$mailforwardingaddress]['cn'] = 'E-Mail nao encontrado'; |
---|
1049 | $result['mailForwardingAddress'][] = $mailforwardingaddress; |
---|
1050 | } |
---|
1051 | |
---|
1052 | ldap_close($ldap_conn_following_ref); |
---|
1053 | return $result; |
---|
1054 | } |
---|
1055 | } |
---|
1056 | } |
---|
1057 | |
---|
1058 | function get_maillist_scl_info($uidnumber) |
---|
1059 | { |
---|
1060 | foreach ($this->manager_contexts as $index=>$context) |
---|
1061 | { |
---|
1062 | $filter="(&(phpgwAccountType=l)(uidNumber=$uidnumber))"; |
---|
1063 | $search = ldap_search($this->ldap, $context, $filter); |
---|
1064 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1065 | |
---|
1066 | if ($entry['count']) |
---|
1067 | { |
---|
1068 | //Pega o dn do setor do usuario. |
---|
1069 | $entry[0]['dn'] = strtolower($entry[0]['dn']); |
---|
1070 | $sector_dn_array = explode(",", $entry[0]['dn']); |
---|
1071 | for($i=1; $i<count($sector_dn_array); $i++) |
---|
1072 | $sector_dn .= $sector_dn_array[$i] . ','; |
---|
1073 | //Retira ultimo pipe. |
---|
1074 | $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); |
---|
1075 | |
---|
1076 | $result['dn'] = $entry[0]['dn']; |
---|
1077 | $result['context'] = $sector_dn; |
---|
1078 | $result['uidnumber'] = $entry[0]['uidnumber'][0]; |
---|
1079 | $result['uid'] = $entry[0]['uid'][0]; |
---|
1080 | $result['cn'] = $entry[0]['cn'][0]; |
---|
1081 | $result['mail'] = $entry[0]['mail'][0]; |
---|
1082 | $result['accountStatus'] = $entry[0]['accountstatus'][0]; |
---|
1083 | $result['phpgwAccountVisible'] = $entry[0]['phpgwaccountvisible'][0]; |
---|
1084 | $result['accountRestrictive'] = $entry[0]['accountrestrictive'][0]; |
---|
1085 | $result['participantCanSendMail'] = $entry[0]['participantcansendmail'][0]; |
---|
1086 | |
---|
1087 | //Senders |
---|
1088 | for ($i=0; $i<$entry[0]['mailsenderaddress']['count']; $i++) |
---|
1089 | { |
---|
1090 | $justthese = array("cn", "uidnumber", "uid", "mail"); |
---|
1091 | $filter="(&(phpgwAccountType=u)(mail=".$entry[0]['mailsenderaddress'][$i]."))"; |
---|
1092 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1093 | $user_entry = ldap_get_entries($this->ldap, $search); |
---|
1094 | |
---|
1095 | $result['senders_info'][$user_entry[0]['uidnumber'][0]]['uid'] = $user_entry[0]['uid'][0]; |
---|
1096 | $result['senders_info'][$user_entry[0]['uidnumber'][0]]['cn'] = $user_entry[0]['cn'][0]; |
---|
1097 | $result['senders_info'][$user_entry[0]['uidnumber'][0]]['mail'] = $user_entry[0]['mail'][0]; |
---|
1098 | $result['members'][] = $user_entry[0]['uidnumber'][0]; |
---|
1099 | } |
---|
1100 | return $result; |
---|
1101 | } |
---|
1102 | } |
---|
1103 | } |
---|
1104 | |
---|
1105 | function group_exist($gidnumber) |
---|
1106 | { |
---|
1107 | $justthese = array("cn"); |
---|
1108 | $filter="(&(phpgwAccountType=g)(gidNumber=".$gidnumber."))"; |
---|
1109 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1110 | |
---|
1111 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1112 | if ($entry['count'] == 0) |
---|
1113 | return false; |
---|
1114 | else |
---|
1115 | return true; |
---|
1116 | } |
---|
1117 | |
---|
1118 | function gidnumbers2cn($gidnumbers) |
---|
1119 | { |
---|
1120 | $result = array(); |
---|
1121 | if (count($gidnumbers)) |
---|
1122 | { |
---|
1123 | $justthese = array("cn"); |
---|
1124 | $i = 0; |
---|
1125 | foreach ($gidnumbers as $gidnumber) |
---|
1126 | { |
---|
1127 | $filter="(&(phpgwAccountType=g)(gidNumber=".$gidnumber."))"; |
---|
1128 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1129 | |
---|
1130 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1131 | if ($entry['count'] == 0) |
---|
1132 | $result['groups_info'][$i]['cn'] = '_Grupo existe no BD mas não no LDAP'; |
---|
1133 | else |
---|
1134 | $result['groups_info'][$i]['cn'] = $entry[0]['cn'][0]; |
---|
1135 | $result['groups_info'][$i]['gidnumber'] = $gidnumber; |
---|
1136 | |
---|
1137 | /* o gerente pode excluir um grupo de um usuario onde este grupo esta em outra OU ? */ |
---|
1138 | /* é o mesmo que o manager editar um grupo de outra OU */ |
---|
1139 | $result['groups_info'][$i]['group_disabled'] = 'true'; |
---|
1140 | foreach ($this->manager_contexts as $index=>$context) |
---|
1141 | { |
---|
1142 | if (strpos(strtolower($entry[0]['dn']), strtolower($context))) |
---|
1143 | { |
---|
1144 | $result['groups_info'][$i]['group_disabled'] = 'false'; |
---|
1145 | } |
---|
1146 | } |
---|
1147 | |
---|
1148 | $i++; |
---|
1149 | } |
---|
1150 | } |
---|
1151 | return $result; |
---|
1152 | } |
---|
1153 | |
---|
1154 | function uidnumber2uid($uidnumber) |
---|
1155 | { |
---|
1156 | $justthese = array("uid"); |
---|
1157 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uidNumber=".$uidnumber."))"; |
---|
1158 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1159 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1160 | return $entry[0]['uid'][0]; |
---|
1161 | } |
---|
1162 | |
---|
1163 | function uidnumber2mail($uidnumber) |
---|
1164 | { |
---|
1165 | $justthese = array("mail"); |
---|
1166 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uidNumber=".$uidnumber."))"; |
---|
1167 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1168 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1169 | return $entry[0]['mail'][0]; |
---|
1170 | } |
---|
1171 | |
---|
1172 | |
---|
1173 | function change_user_context($dn, $newrdn, $newparent) |
---|
1174 | { |
---|
1175 | if (!ldap_rename ( $this->ldap, $dn, $newrdn, $newparent, true )) |
---|
1176 | { |
---|
1177 | $return['status'] = false; |
---|
1178 | $return['msg'] = 'Erro em ldap_funcitons->change_user_context: ' . ldap_error($this->ldap); |
---|
1179 | } |
---|
1180 | else |
---|
1181 | $return['status'] = true; |
---|
1182 | |
---|
1183 | return $return; |
---|
1184 | } |
---|
1185 | |
---|
1186 | function replace_user_attributes($dn, $ldap_mod_replace) |
---|
1187 | { |
---|
1188 | if (!@ldap_mod_replace ( $this->ldap, $dn, $ldap_mod_replace )) |
---|
1189 | { |
---|
1190 | $return['status'] = false; |
---|
1191 | $return['msg'] = 'Erro em ldap_funcitons->replace_user_attributes: ' . ldap_error($this->ldap); |
---|
1192 | } |
---|
1193 | else |
---|
1194 | $return['status'] = true; |
---|
1195 | |
---|
1196 | return $return; |
---|
1197 | } |
---|
1198 | |
---|
1199 | function add_user_attributes($dn, $ldap_add) |
---|
1200 | { |
---|
1201 | if (!@ldap_mod_add ( $this->ldap, $dn, $ldap_add )) |
---|
1202 | { |
---|
1203 | $return['status'] = false; |
---|
1204 | $return['msg'] = 'Erro em ldap_funcitons->add_user_attributes: ' . ldap_error($this->ldap); |
---|
1205 | } |
---|
1206 | else |
---|
1207 | $return['status'] = true; |
---|
1208 | |
---|
1209 | return $return; |
---|
1210 | } |
---|
1211 | |
---|
1212 | function remove_user_attributes($dn, $ldap_remove) |
---|
1213 | { |
---|
1214 | if (!@ldap_mod_del ( $this->ldap, $dn, $ldap_remove )) |
---|
1215 | { |
---|
1216 | $return['status'] = false; |
---|
1217 | $return['msg'] = 'Erro em ldap_funcitons->remove_user_attributes: ' . ldap_error($this->ldap); |
---|
1218 | } |
---|
1219 | else |
---|
1220 | $return['status'] = true; |
---|
1221 | |
---|
1222 | return $return; |
---|
1223 | } |
---|
1224 | |
---|
1225 | function set_user_password($uid, $password) |
---|
1226 | { |
---|
1227 | $justthese = array("userPassword"); |
---|
1228 | $filter="(&(phpgwAccountType=u)(uid=".$uid."))"; |
---|
1229 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1230 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1231 | $dn = $entry[0]['dn']; |
---|
1232 | $userPassword = $entry[0]['userpassword'][0]; |
---|
1233 | $ldap_mod_replace['userPassword'] = $password; |
---|
1234 | $this->replace_user_attributes($dn, $ldap_mod_replace); |
---|
1235 | return $userPassword; |
---|
1236 | } |
---|
1237 | |
---|
1238 | function delete_user($user_info) |
---|
1239 | { |
---|
1240 | // Verifica acesso do gerente (OU) ao tentar deletar um usuário. |
---|
1241 | $manager_access = false; |
---|
1242 | foreach ($this->manager_contexts as $index=>$context) |
---|
1243 | { |
---|
1244 | if ( (strpos(strtolower($user_info['context']), strtolower($context))) || (strtolower($user_info['context']) == strtolower($context)) ) |
---|
1245 | { |
---|
1246 | $manager_access = true; |
---|
1247 | break; |
---|
1248 | } |
---|
1249 | } |
---|
1250 | if (!$manager_access) |
---|
1251 | { |
---|
1252 | $return['status'] = false; |
---|
1253 | $return['msg'] .= 'Você não tem acesso para deletar este usuário.'; |
---|
1254 | return $return; |
---|
1255 | } |
---|
1256 | |
---|
1257 | $return['status'] = true; |
---|
1258 | |
---|
1259 | // GROUPS |
---|
1260 | $attrs = array(); |
---|
1261 | $attrs['memberUid'] = $user_info['uid']; |
---|
1262 | if (count($user_info['groups_info'])) |
---|
1263 | { |
---|
1264 | foreach ($user_info['groups_info'] as $group_info) |
---|
1265 | { |
---|
1266 | $gidnumber = $group_info['gidnumber']; |
---|
1267 | $justthese = array("dn"); |
---|
1268 | $filter="(&(phpgwAccountType=g)(gidnumber=".$gidnumber."))"; |
---|
1269 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1270 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1271 | $dn = $entry[0]['dn']; |
---|
1272 | |
---|
1273 | if (!@ldap_mod_del($this->ldap, $dn, $attrs)) |
---|
1274 | { |
---|
1275 | $return['status'] = false; |
---|
1276 | $return['msg'] .= 'Erro em ldap_funcitons->delete_user, grupos: ' . ldap_error($this->ldap); |
---|
1277 | } |
---|
1278 | } |
---|
1279 | } |
---|
1280 | |
---|
1281 | // MAILLISTS |
---|
1282 | $attrs = array(); |
---|
1283 | $attrs['mailForwardingAddress'] = $user_info['mail']; |
---|
1284 | if (count($user_info['maillists_info'])) |
---|
1285 | { |
---|
1286 | foreach ($user_info['maillists_info'] as $maillists_info) |
---|
1287 | { |
---|
1288 | $uidnumber = $maillists_info['uidnumber']; |
---|
1289 | $justthese = array("dn"); |
---|
1290 | $filter="(&(phpgwAccountType=l)(uidnumber=".$uidnumber."))"; |
---|
1291 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1292 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1293 | $dn = $entry[0]['dn']; |
---|
1294 | |
---|
1295 | if (!@ldap_mod_del($this->ldap, $dn, $attrs)) |
---|
1296 | { |
---|
1297 | $return['status'] = false; |
---|
1298 | $return['msg'] .= 'Erro em ldap_funcitons->delete_user, listas de email: ' . ldap_error($this->ldap); |
---|
1299 | } |
---|
1300 | } |
---|
1301 | } |
---|
1302 | |
---|
1303 | // UID |
---|
1304 | $dn = "uid=" . $user_info['uid'] . "," . $user_info['context']; |
---|
1305 | if (!@ldap_delete($this->ldap, $dn)) |
---|
1306 | { |
---|
1307 | $return['status'] = false; |
---|
1308 | $return['msg'] .= 'Erro em ldap_funcitons->delete_user, listas de email: ' . ldap_error($this->ldap); |
---|
1309 | } |
---|
1310 | |
---|
1311 | return $return; |
---|
1312 | } |
---|
1313 | |
---|
1314 | function delete_maillist($uidnumber, $mail) |
---|
1315 | { |
---|
1316 | $return['status'] = true; |
---|
1317 | |
---|
1318 | $justthese = array("dn"); |
---|
1319 | |
---|
1320 | // remove listas dentro de listas |
---|
1321 | $filter="(&(phpgwAccountType=l)(mailForwardingAddress=".$mail."))"; |
---|
1322 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1323 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1324 | $attrs['mailForwardingAddress'] = $mail; |
---|
1325 | for ($i=0; $i<=$entry['count']; $i++) |
---|
1326 | { |
---|
1327 | $dn = $entry[$i]['dn']; |
---|
1328 | @ldap_mod_del ( $this->ldap, $dn, $attrs); |
---|
1329 | } |
---|
1330 | |
---|
1331 | $filter="(&(phpgwAccountType=l)(uidnumber=".$uidnumber."))"; |
---|
1332 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1333 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1334 | $dn = $entry[0]['dn']; |
---|
1335 | |
---|
1336 | if (!@ldap_delete($this->ldap, $dn)) |
---|
1337 | { |
---|
1338 | $return['status'] = false; |
---|
1339 | $return['msg'] .= 'Erro em ldap_funcitons->delete_maillist, listas de email: ' . ldap_error($this->ldap); |
---|
1340 | } |
---|
1341 | |
---|
1342 | return $return; |
---|
1343 | } |
---|
1344 | |
---|
1345 | function delete_group($gidnumber) |
---|
1346 | { |
---|
1347 | $return['status'] = true; |
---|
1348 | |
---|
1349 | $justthese = array("dn"); |
---|
1350 | $filter="(&(phpgwAccountType=g)(gidnumber=".$gidnumber."))"; |
---|
1351 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1352 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1353 | $dn = $entry[0]['dn']; |
---|
1354 | |
---|
1355 | if (!@ldap_delete($this->ldap, $dn)) |
---|
1356 | { |
---|
1357 | $return['status'] = false; |
---|
1358 | $return['msg'] .= 'Erro em ldap_funcitons->delete_maillist, listas de email: ' . ldap_error($this->ldap); |
---|
1359 | } |
---|
1360 | |
---|
1361 | return $return; |
---|
1362 | } |
---|
1363 | |
---|
1364 | function check_access_to_renamed($uid) |
---|
1365 | { |
---|
1366 | $justthese = array("dn"); |
---|
1367 | $filter="(&(phpgwAccountType=u)(uid=$uid))"; |
---|
1368 | |
---|
1369 | foreach ($this->manager_contexts as $index=>$context) |
---|
1370 | { |
---|
1371 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
1372 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1373 | if ($entry['count']) |
---|
1374 | return true; |
---|
1375 | } |
---|
1376 | return false; |
---|
1377 | } |
---|
1378 | |
---|
1379 | function rename_uid($uid, $new_uid) |
---|
1380 | { |
---|
1381 | $return['status'] = true; |
---|
1382 | |
---|
1383 | $justthese = array("dn"); |
---|
1384 | $filter="(&(phpgwAccountType=u)(uid=".$uid."))"; |
---|
1385 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1386 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1387 | $dn = $entry[0]['dn']; |
---|
1388 | |
---|
1389 | $explode_dn = ldap_explode_dn($dn, 0); |
---|
1390 | $rdn = "uid=" . $new_uid; |
---|
1391 | |
---|
1392 | $parent = array(); |
---|
1393 | for ($j=1; $j<(count($explode_dn)-1); $j++) |
---|
1394 | $parent[] = $explode_dn[$j]; |
---|
1395 | $parent = implode(",", $parent); |
---|
1396 | |
---|
1397 | $return['new_dn'] = $rdn . ',' . $parent; |
---|
1398 | |
---|
1399 | if (!@ldap_rename($this->ldap, $dn, $rdn, $parent, false)) |
---|
1400 | { |
---|
1401 | $return['status'] = false; |
---|
1402 | $return['msg'] .= 'Erro em ldap_funcitons->rename_uid: ' . ldap_error($this->ldap); |
---|
1403 | } |
---|
1404 | |
---|
1405 | //Grupos |
---|
1406 | $justthese = array("dn"); |
---|
1407 | $filter="(&(phpgwAccountType=g)(memberuid=".$uid."))"; |
---|
1408 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1409 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1410 | $array_mod_add['memberUid'] = $new_uid; |
---|
1411 | $array_mod_del['memberUid'] = $uid; |
---|
1412 | |
---|
1413 | for ($i=0; $i<=$entry['count']; $i++) |
---|
1414 | { |
---|
1415 | $dn = $entry[$i]['dn']; |
---|
1416 | @ldap_mod_add ( $this->ldap, $dn, $array_mod_add); |
---|
1417 | @ldap_mod_del ( $this->ldap, $dn, $array_mod_del); |
---|
1418 | } |
---|
1419 | return $return; |
---|
1420 | } |
---|
1421 | |
---|
1422 | function rename_cn($cn, $new_cn) |
---|
1423 | { |
---|
1424 | $return['status'] = true; |
---|
1425 | |
---|
1426 | $justthese = array("dn"); |
---|
1427 | $filter="(&(phpgwAccountType=g)(uid=".$cn."))"; |
---|
1428 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
1429 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1430 | $dn = $entry[0]['dn']; |
---|
1431 | |
---|
1432 | $explode_dn = ldap_explode_dn($dn, 0); |
---|
1433 | $rdn = "cn=" . $new_cn; |
---|
1434 | |
---|
1435 | $parent = array(); |
---|
1436 | for ($j=1; $j<(count($explode_dn)-1); $j++) |
---|
1437 | $parent[] = $explode_dn[$j]; |
---|
1438 | $parent = implode(",", $parent); |
---|
1439 | |
---|
1440 | $return['new_dn'] = $rdn . ',' . $parent; |
---|
1441 | |
---|
1442 | if (!@ldap_rename($this->ldap, $dn, $rdn, $parent, false)) |
---|
1443 | { |
---|
1444 | $return['status'] = false; |
---|
1445 | } |
---|
1446 | |
---|
1447 | return $return; |
---|
1448 | } |
---|
1449 | |
---|
1450 | function exist_sambadomains($contexts, $sambaDomainName) |
---|
1451 | { |
---|
1452 | $justthese = array("dn"); |
---|
1453 | $filter="(&(objectClass=sambaDomain)(sambaDomainName=$sambaDomainName))"; |
---|
1454 | |
---|
1455 | foreach ($contexts as $index=>$context) |
---|
1456 | { |
---|
1457 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
1458 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1459 | |
---|
1460 | if ($entry['count']) |
---|
1461 | return true; |
---|
1462 | } |
---|
1463 | return false; |
---|
1464 | } |
---|
1465 | |
---|
1466 | // Primeiro nilvel de organização. |
---|
1467 | function exist_sambadomains_in_context($params) |
---|
1468 | { |
---|
1469 | $dn = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
1470 | $array_dn = ldap_explode_dn ( $dn, 0 ); |
---|
1471 | |
---|
1472 | $context = $params['context']; |
---|
1473 | $array_context = ldap_explode_dn ( $context, 0 ); |
---|
1474 | |
---|
1475 | // Pego o setor no caso do contexto ser um sub-setor. |
---|
1476 | if (($array_dn['count']+1) < ($array_context['count'])) |
---|
1477 | { |
---|
1478 | // inverto o array_dn para poder retirar o count |
---|
1479 | $array_dn_reverse = array_reverse ( $array_dn, false ); |
---|
1480 | |
---|
1481 | //retiro o count |
---|
1482 | array_pop($array_dn_reverse); |
---|
1483 | |
---|
1484 | //incluo o setor no dn |
---|
1485 | array_push ( $array_dn_reverse, $array_context[ $array_context['count'] - 1 - $array_dn['count']]); |
---|
1486 | |
---|
1487 | // Volto a ordem natural |
---|
1488 | $array_dn = array_reverse ( $array_dn_reverse, false ); |
---|
1489 | |
---|
1490 | // Implodo |
---|
1491 | $context = implode ( ",", $array_dn ); |
---|
1492 | } |
---|
1493 | |
---|
1494 | $justthese = array("dn","sambaDomainName"); |
---|
1495 | $filter="(objectClass=sambaDomain)"; |
---|
1496 | $search = ldap_list($this->ldap, $context, $filter, $justthese); |
---|
1497 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1498 | |
---|
1499 | for ($i=0; $i<$entry['count']; $i++) |
---|
1500 | { |
---|
1501 | $return['sambaDomains'][$i] = $entry[$i]['sambadomainname'][0]; |
---|
1502 | } |
---|
1503 | |
---|
1504 | if ($entry['count']) |
---|
1505 | $return['status'] = true; |
---|
1506 | else |
---|
1507 | $return['status'] = false; |
---|
1508 | |
---|
1509 | return $return; |
---|
1510 | } |
---|
1511 | |
---|
1512 | function add_sambadomain($sambadomainname, $sambasid, $context) |
---|
1513 | { |
---|
1514 | $result = array(); |
---|
1515 | |
---|
1516 | $dn = "sambaDomainName=$sambadomainname,$context"; |
---|
1517 | $entry['sambaSID'] = $sambasid; |
---|
1518 | $entry['objectClass'] = 'sambaDomain'; |
---|
1519 | $entry['sambaAlgorithmicRidBase'] = '1000'; |
---|
1520 | $entry['sambaDomainName'] = $sambadomainname; |
---|
1521 | |
---|
1522 | if (!@ldap_add ( $this->ldap, $dn, $entry )) |
---|
1523 | { |
---|
1524 | $return['status'] = false; |
---|
1525 | $return['msg'] = "Erro na funcao ldap_functions->add_sambadomain ($dn).\nRetorno do servidor: " . ldap_error($this->ldap); |
---|
1526 | } |
---|
1527 | else |
---|
1528 | $return['status'] = true; |
---|
1529 | |
---|
1530 | return $return; |
---|
1531 | } |
---|
1532 | |
---|
1533 | function delete_sambadomain($sambadomainname) |
---|
1534 | { |
---|
1535 | $return['status'] = true; |
---|
1536 | $filter="(sambaDomainName=$sambadomainname)"; |
---|
1537 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter); |
---|
1538 | $entry = ldap_get_entries($this->ldap, $search); |
---|
1539 | |
---|
1540 | if ($entry['count'] != 0) |
---|
1541 | { |
---|
1542 | $dn = $entry[0]['dn']; |
---|
1543 | |
---|
1544 | if (!@ldap_delete($this->ldap, $dn)) |
---|
1545 | { |
---|
1546 | $return['status'] = false; |
---|
1547 | $return['msg'] .= "Erro em ldap_funcitons->delete_sambadomain ($sambadomainname).\nRetorno do servidor: " . ldap_error($this->ldap); |
---|
1548 | } |
---|
1549 | } |
---|
1550 | |
---|
1551 | return $return; |
---|
1552 | } |
---|
1553 | |
---|
1554 | function search_user($params) |
---|
1555 | { |
---|
1556 | $search = $params['search']; |
---|
1557 | $justthese = array("cn","uid", "mail"); |
---|
1558 | $users_list=ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], "(&(phpgwAccountType=u) (|(cn=*$search*)(mail=$search*)) )", $justthese); |
---|
1559 | |
---|
1560 | if (ldap_count_entries($this->ldap, $users_list) == 0) |
---|
1561 | { |
---|
1562 | $return['status'] = 'false'; |
---|
1563 | $return['msg'] = 'Nenhum resultado encontrado.'; |
---|
1564 | return $return; |
---|
1565 | } |
---|
1566 | |
---|
1567 | ldap_sort($this->ldap, $users_list, "cn"); |
---|
1568 | |
---|
1569 | $entries = ldap_get_entries($this->ldap, $users_list); |
---|
1570 | |
---|
1571 | $options = ''; |
---|
1572 | for ($i=0; $i<$entries['count']; $i++) |
---|
1573 | { |
---|
1574 | $options .= "<option value=" . $entries[$i]['uid'][0] . ">" . $entries[$i]['cn'][0] . " (".$entries[$i]['mail'][0].")" . "</option>"; |
---|
1575 | } |
---|
1576 | |
---|
1577 | return $options; |
---|
1578 | } |
---|
1579 | |
---|
1580 | |
---|
1581 | } |
---|
1582 | ?> |
---|