Ignore:
Timestamp:
02/26/08 17:04:07 (16 years ago)
Author:
niltonneto
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php

    r81 r180  
    433433                $denied_uidnumber = $params['denied_uidnumber']; 
    434434                 
    435                 $justthese = array("cn", "uidNumber"); 
     435                $justthese = array("cn", "uidNumber", "mail"); 
     436                 
    436437                $users_filter="(phpgwAccountType=u)"; 
    437438                $lists_filter = $denied_uidnumber == '' ? "(phpgwAccountType=l)" : "(&(phpgwAccountType=l)(!(uidnumber=$denied_uidnumber)))"; 
     
    440441                $lists = Array();                
    441442 
     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 
    442456                if ($recursive == 'true') 
    443457                { 
    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                 
    454470                for ($i=0; $i<$lists_entries["count"]; $i++) 
    455471                { 
    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]; 
    457473                } 
    458474                         
     
    466482                if (count($l_tmp)) 
    467483                { 
    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>"; 
    471487                        } 
    472488                        unset($l_tmp); 
    473489                } 
    474490                 
    475                 $users_entries = ldap_get_entries($this->ldap, $users_search); 
     491                /* users */ 
     492                $users_entries = ldap_get_entries($ldap_conn_following_ref, $users_search); 
    476493                for ($i=0; $i<$users_entries["count"]; $i++) 
    477494                { 
    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]; 
    479496                } 
    480497                         
     
    488505                if (count($u_tmp)) 
    489506                { 
    490                         foreach ($u_tmp as $uidnumber => $cn) 
    491                         { 
    492                                 $options .= "<option value=$uidnumber class='line-above'>$cn</option>"; 
     507                        foreach ($u_tmp as $mail => $cn) 
     508                        { 
     509                                $options .= "<option value=$mail class='line-above'>$cn</option>"; 
    493510                        } 
    494511                        unset($u_tmp); 
    495512                } 
    496                          
     513                 
     514                ldap_close($ldap_conn_following_ref); 
    497515                return $options; 
    498516        } 
     
    957975        function get_maillist_info($uidnumber) 
    958976        { 
     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                 
    959989                foreach ($this->manager_contexts as $index=>$context) 
    960990                { 
     
    9751005                                $result['context']                              = $sector_dn; 
    9761006                                $result['uidnumber']                    = $entry[0]['uidnumber'][0]; 
    977                                 $result['uid']                                  = $entry[0]['uid'][0]; 
     1007                                $result['uid']                                  = strtolower($entry[0]['uid'][0]); 
    9781008                                $result['cn']                                   = $entry[0]['cn'][0]; 
    9791009                                $result['mail']                                 = $entry[0]['mail'][0]; 
     
    9861016                                        $justthese = array("cn", "uidnumber", "uid", "phpgwaccounttype", "mail"); 
    9871017                                 
    988                                         // Montagem dinamica do filtro 
     1018                                        // Montagem dinamica do filtro, para nao ter muitas conexoes com o ldap 
    9891019                                        $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|"; 
    9901020                                        for ($k=0; (($k<10) && ($i<$entry[0]['mailforwardingaddress']['count'])); $k++) 
     
    9961026                                        $filter .= "))"; 
    9971027                                 
    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                                                                         
    10011031                                        for ($j=0; $j<$user_entry['count']; $j++) 
    10021032                                        { 
    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]; 
    10081037                                        } 
    10091038                                } 
    10101039 
    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) 
    10181046                                { 
    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; 
    10201050                                } 
    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); 
    10331053                                return $result; 
    10341054                        } 
     
    12921312        } 
    12931313         
    1294         function delete_maillist($uidnumber) 
     1314        function delete_maillist($uidnumber, $mail) 
    12951315        { 
    12961316                $return['status'] = true; 
    12971317                 
    12981318                $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                 
    12991331                $filter="(&(phpgwAccountType=l)(uidnumber=".$uidnumber."))"; 
    13001332                $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
     
    15191551                return $return; 
    15201552        } 
     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         
    15211581} 
    15221582?> 
Note: See TracChangeset for help on using the changeset viewer.