Changeset 180 for trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php
- Timestamp:
- 02/26/08 17:04:07 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php
r81 r180 433 433 $denied_uidnumber = $params['denied_uidnumber']; 434 434 435 $justthese = array("cn", "uidNumber"); 435 $justthese = array("cn", "uidNumber", "mail"); 436 436 437 $users_filter="(phpgwAccountType=u)"; 437 438 $lists_filter = $denied_uidnumber == '' ? "(phpgwAccountType=l)" : "(&(phpgwAccountType=l)(!(uidnumber=$denied_uidnumber)))"; … … 440 441 $lists = Array(); 441 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 442 456 if ($recursive == 'true') 443 457 { 444 $lists_search = ldap_search($this->ldap, $context, $lists_filter, $justthese); 445 $users_search = ldap_search($this->ldap, $context, $users_filter, $justthese); 446 } 447 else 448 { 449 $lists_search = ldap_list($this->ldap, $context, $lists_filter, $justthese); 450 $users_search = ldap_list($this->ldap, $context, $users_filter, $justthese); 451 } 452 453 $lists_entries = ldap_get_entries($this->ldap, $lists_search); 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 454 470 for ($i=0; $i<$lists_entries["count"]; $i++) 455 471 { 456 $l_tmp[$lists_entries[$i][" uidnumber"][0]] = $lists_entries[$i]["cn"][0];472 $l_tmp[$lists_entries[$i]["mail"][0]] = $lists_entries[$i]["cn"][0]; 457 473 } 458 474 … … 466 482 if (count($l_tmp)) 467 483 { 468 foreach ($l_tmp as $ uidnumber=> $cn)469 { 470 $options .= "<option value=$ uidnumber>$cn</option>";484 foreach ($l_tmp as $mail => $cn) 485 { 486 $options .= "<option value=$mail>$cn</option>"; 471 487 } 472 488 unset($l_tmp); 473 489 } 474 490 475 $users_entries = ldap_get_entries($this->ldap, $users_search); 491 /* users */ 492 $users_entries = ldap_get_entries($ldap_conn_following_ref, $users_search); 476 493 for ($i=0; $i<$users_entries["count"]; $i++) 477 494 { 478 $u_tmp[$users_entries[$i][" uidnumber"][0]] = $users_entries[$i]["cn"][0];495 $u_tmp[$users_entries[$i]["mail"][0]] = $users_entries[$i]["cn"][0]; 479 496 } 480 497 … … 488 505 if (count($u_tmp)) 489 506 { 490 foreach ($u_tmp as $ uidnumber=> $cn)491 { 492 $options .= "<option value=$ uidnumberclass='line-above'>$cn</option>";507 foreach ($u_tmp as $mail => $cn) 508 { 509 $options .= "<option value=$mail class='line-above'>$cn</option>"; 493 510 } 494 511 unset($u_tmp); 495 512 } 496 513 514 ldap_close($ldap_conn_following_ref); 497 515 return $options; 498 516 } … … 957 975 function get_maillist_info($uidnumber) 958 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 959 989 foreach ($this->manager_contexts as $index=>$context) 960 990 { … … 975 1005 $result['context'] = $sector_dn; 976 1006 $result['uidnumber'] = $entry[0]['uidnumber'][0]; 977 $result['uid'] = $entry[0]['uid'][0];1007 $result['uid'] = strtolower($entry[0]['uid'][0]); 978 1008 $result['cn'] = $entry[0]['cn'][0]; 979 1009 $result['mail'] = $entry[0]['mail'][0]; … … 986 1016 $justthese = array("cn", "uidnumber", "uid", "phpgwaccounttype", "mail"); 987 1017 988 // Montagem dinamica do filtro 1018 // Montagem dinamica do filtro, para nao ter muitas conexoes com o ldap 989 1019 $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|"; 990 1020 for ($k=0; (($k<10) && ($i<$entry[0]['mailforwardingaddress']['count'])); $k++) … … 996 1026 $filter .= "))"; 997 1027 998 $search = ldap_search($ this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);999 $user_entry = ldap_get_entries($ this->ldap, $search);1000 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 1001 1031 for ($j=0; $j<$user_entry['count']; $j++) 1002 1032 { 1003 $result['members_info'][$user_entry[$j]['uidnumber'][0]]['uid'] = $user_entry[$j]['uid'][0]; 1004 $result['members_info'][$user_entry[$j]['uidnumber'][0]]['cn'] = $user_entry[$j]['cn'][0]; 1005 $result['members_info'][$user_entry[$j]['uidnumber'][0]]['type'] = $user_entry[$j]['phpgwaccounttype'][0]; 1006 $result['members_info'][$user_entry[$j]['uidnumber'][0]]['mail'] = $user_entry[$j]['mail'][0]; 1007 $result['members'][] = $user_entry[$j]['uidnumber'][0]; 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]; 1008 1037 } 1009 1038 } 1010 1039 1011 // Retira o count do array 1012 array_shift($entry[0]['mailforwardingaddress']); 1013 1014 // Checamos e-mails que não fazem parte do expresso. 1015 // Criamos um array temporario 1016 $tmp_array = array(); 1017 foreach ($result['members_info'] as $uid => $user_data) 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) 1018 1046 { 1019 $tmp_array[] = $user_data['mail']; 1047 $result['mailForwardingAddress_info'][$mailforwardingaddress]['uid'] = $mailforwardingaddress; 1048 $result['mailForwardingAddress_info'][$mailforwardingaddress]['cn'] = 'E-Mail nao encontrado'; 1049 $result['mailForwardingAddress'][] = $mailforwardingaddress; 1020 1050 } 1021 1022 // Vemos a diferença 1023 $array_diff = array_diff($entry[0]['mailforwardingaddress'], $tmp_array); 1024 1025 // Incluimos no resultado 1026 foreach ($array_diff as $index=>$mailforwardingaddress) 1027 { 1028 $result['members_info'][$mailforwardingaddress]['uid'] = $mailforwardingaddress; 1029 $result['members_info'][$mailforwardingaddress]['cn'] = 'E-Mail nao encontrado'; 1030 $result['members_info'][$mailforwardingaddress]['mailforwardingaddress'] = $mailforwardingaddress; 1031 $result['members'][] = $mailforwardingaddress; 1032 } 1051 1052 ldap_close($ldap_conn_following_ref); 1033 1053 return $result; 1034 1054 } … … 1292 1312 } 1293 1313 1294 function delete_maillist($uidnumber )1314 function delete_maillist($uidnumber, $mail) 1295 1315 { 1296 1316 $return['status'] = true; 1297 1317 1298 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 1299 1331 $filter="(&(phpgwAccountType=l)(uidnumber=".$uidnumber."))"; 1300 1332 $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); … … 1519 1551 return $return; 1520 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 1521 1581 } 1522 1582 ?>
Note: See TracChangeset
for help on using the changeset viewer.