Ignore:
Timestamp:
09/06/11 17:30:57 (13 years ago)
Author:
airton
Message:

Ticket #2266 - Atualizar documentacao dos arquivos PHP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/services/class.ldap.php

    r4828 r5068  
    11<?php 
    2  
     2/** 
     3* 
     4* Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     5* 
     6* This program is free software; you can redistribute it and/or modify it under 
     7* the terms of the GNU Affero General Public License version 3 as published by 
     8* the Free Software Foundation with the addition of the following permission 
     9* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED 
     10* WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
     11* WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS. 
     12* 
     13* This program is distributed in the hope that it will be useful, but WITHOUT 
     14* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
     15* FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
     16* details. 
     17* 
     18* You should have received a copy of the GNU Affero General Public License 
     19* along with this program; if not, see www.gnu.org/licenses or write to 
     20* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
     21* MA 02110-1301 USA. 
     22* 
     23* This code is based on the OpenXchange Connector and on the Prognus pSync 
     24* Connector both developed by the community and licensed under the GPL 
     25* version 2 or above as published by the Free Software Foundation. 
     26* 
     27* You can contact Prognus Software Livre headquarters at Av. Tancredo Neves, 
     28* 6731, PTI, Bl. 05, Esp. 02, Sl. 10, Foz do Iguaçu - PR - Brasil or at 
     29* e-mail address prognus@prognus.com.br. 
     30* 
     31* Serviço de LDAP 
     32* 
     33* @package    Services 
     34* @license    http://www.gnu.org/copyleft/gpl.html GPL 
     35* @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     36* @version    1.0 
     37* @sponsor    Caixa Econômica Federal 
     38*/ 
     39 
     40 
     41 
     42 
     43/** 
     44* Serviço Ldap 
     45* 
     46* Classe responsável pelas operações com o LDAP 
     47* 
     48* @package    Service 
     49* @license    http://www.gnu.org/copyleft/gpl.html GPL 
     50* @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     51* @sponsor    Caixa Econômica Federal 
     52* @version    1.0 
     53*/ 
    354class LdapService 
    455{ 
     
    1465    } 
    1566 
     67         
     68        /** 
     69     * Conecta com o LDAP 
     70     * 
     71     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     72         * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     73         * @sponsor    Caixa Econômica Federal 
     74     * @param   $host 
     75     * @param   $dn 
     76     * @param   $passwd 
     77     * @param   $ldapreferral 
     78     */ 
    1679    function connect($host='', $dn='', $passwd='', $ldapreferral=false) 
    1780    { 
     
    47110    function _or( $toWrap ) 
    48111    { 
    49         if( !is_array( $toWrap ) ) 
    50             return( $toWrap ); 
    51  
    52 //      if( count( $toWrap ) <= 1 ) 
    53 //          return implode( "", $toWrap ); 
    54  
    55         return $this->wrap( $toWrap, '|' ); 
     112                if( !is_array( $toWrap ) ) 
     113                        return( $toWrap ); 
     114         
     115                //      if( count( $toWrap ) <= 1 ) 
     116                //          return implode( "", $toWrap ); 
     117         
     118                return $this->wrap( $toWrap, '|' ); 
    56119    } 
    57120 
    58121    function _and( $toWrap ) 
    59122    { 
    60         if( !is_array( $toWrap ) ) 
    61             return( $toWrap ); 
    62  
    63 //      if( count( $toWrap ) <= 1 ) 
    64 //          return implode( "", $toWrap ); 
    65  
    66         return $this->wrap( $toWrap, '&' ); 
     123                if( !is_array( $toWrap ) ) 
     124                        return( $toWrap ); 
     125         
     126                //      if( count( $toWrap ) <= 1 ) 
     127                //          return implode( "", $toWrap ); 
     128         
     129                return $this->wrap( $toWrap, '&' ); 
    67130    } 
    68131 
    69132    function _not( $toWrap ) 
    70133    { 
    71         return $this->wrap( $toWrap, '!' ); 
     134                return $this->wrap( $toWrap, '!' ); 
    72135    } 
    73136 
    74137    function wrap( $toWrap, $conditional = "" ) 
    75138    { 
    76         if( !is_array( $toWrap ) ) 
    77             $toWrap = array( $toWrap ); 
    78  
    79         $toWrap = array_unique( $toWrap ); 
    80  
    81         return "(".$conditional.implode( "", $toWrap ).")"; 
    82     } 
    83  
     139                if( !is_array( $toWrap ) ) 
     140                        $toWrap = array( $toWrap ); 
     141         
     142                $toWrap = array_unique( $toWrap ); 
     143 
     144                return "(".$conditional.implode( "", $toWrap ).")"; 
     145    } 
     146 
     147        /** 
     148     * Manipula o filtro de busca 
     149     * 
     150     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     151         * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     152         * @sponsor    Caixa Econômica Federal 
     153     * @param   $search 
     154     * @param   $targetTypes 
     155     * @param   $customFilter 
     156     * @param   $exact 
     157     */ 
    84158    function getSearchFilter( $search, $targetTypes = false, $customFilter = '', $exact = false ) 
    85159    { 
    86160        $search = utf8_encode( $search ); 
    87161 
    88         if( !$targetTypes ) 
    89             $targetTypes = $this->allTargetTypes; 
    90  
    91         if( !is_array( $targetTypes ) ) 
    92             $targetTypes = array( $targetTypes ); 
    93  
    94         $searchFilter = ''; 
    95  
    96         foreach( $targetTypes as $targetType ) 
    97         { 
    98             switch( $targetType ) 
    99             { 
    100                 case 'g': 
     162                if( !$targetTypes ) 
     163                                $targetTypes = $this->allTargetTypes; 
     164         
     165                if( !is_array( $targetTypes ) ) 
     166                        $targetTypes = array( $targetTypes ); 
     167         
     168                $searchFilter = ''; 
     169         
     170                foreach( $targetTypes as $targetType ) 
    101171                { 
    102                     //no caso de grupos, a busca so precisa ser feita em cima do CN 
    103                     $searchFilter = $this->stemFilter( $search, 'cn' ); 
     172                        switch( $targetType ) 
     173                        { 
     174                        case 'g': 
     175                        { 
     176                                //no caso de grupos, a busca so precisa ser feita em cima do CN 
     177                                $searchFilter = $this->stemFilter( $search, 'cn' ); 
     178                        } 
     179                        break; 
     180         
     181                        default : 
     182                        { 
     183                        //parametros que a busca tem que ser sintaticas 
     184                                $searchFilter = /*array( */$this->stemFilter( $search, array( 
     185                                                        // UID e employeeNumber podem ser iguais ou muito similares, dependendo da organizacao 
     186                                                        'uid', /*'employeeNumber', */'cn', 
     187                                                        // givenName e SN sao complementares (nome e sobrenome) 
     188                                                        'givenName', 'sn', 'displayName' ) //), 
     189                                                        //parametros que a busca pode ser por aproximacao fonetica 
     190                                                /*$this->approxFilter( $search, array(  
     191                                                        // O CN e displayName geralmente sao a mesma coisa 
     192                                                        'cn', 'displayName' ))*/  ); 
     193         
     194                                $searchFilter = $this->stemFilter( $search, array( 'cn', 'givenName', 'uid', 
     195                                                                                'sn', 'displayName' ) ); 
     196                        } 
     197                        break; 
     198                        } 
    104199                } 
    105                 break; 
    106  
    107                 default : 
     200 
     201                $filter = array(); 
     202         
     203                if( $customFilter ) 
     204                        $filter[] = $customFilter; 
     205                if( $search ) 
     206                        $filter[] = $searchFilter; 
     207         
     208                return $this->_and( array( 
     209                        // Somente objetos relacionados com o Expresso 
     210                        $this->accountFilter( $targetTypes ), 
     211                        // Objetos ocultados e/ou desativados pelo Administrador nao podem ser exibidos nas consultas do Expresso 
     212                        $this->securityFilter( $targetTypes ), 
     213                        //foco da busca 
     214                        ( $exact ? $this->_and( $filter ) : $this->_or( $filter ) ) 
     215                        )); 
     216         
     217                // Verificoes extras para validar o resultado 
     218                //  (& 
     219                //     // Somente objetos com e-mail no formato da RFC822 
     220                //    (mail=*@*) 
     221                //  ) 
     222        } 
     223 
     224         
     225        /** 
     226     * Manipula o filtro de segurança 
     227     * 
     228     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     229         * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     230         * @sponsor    Caixa Econômica Federal 
     231     * @param   $targetTypes 
     232     */ 
     233        function securityFilter( $targetTypes ) 
     234    { 
     235                if( !$targetTypes ) 
     236                                $targetTypes = $this->allTargetTypes; 
     237 
     238                if( !is_array( $targetTypes ) ) 
     239                        $targetTypes = array( $targetTypes ); 
     240         
     241                $typeFilter = array(); 
     242         
     243                foreach( $targetTypes as $targetType ) 
    108244                { 
    109                    //parametros que a busca tem que ser sintaticas 
    110                     $searchFilter = /*array( */$this->stemFilter( $search, array( 
    111                                                 // UID e employeeNumber podem ser iguais ou muito similares, dependendo da organizacao 
    112                                                 'uid', /*'employeeNumber', */'cn', 
    113                                                 // givenName e SN sao complementares (nome e sobrenome) 
    114                                                 'givenName', 'sn', 'displayName' ) //), 
    115                                             //parametros que a busca pode ser por aproximacao fonetica 
    116                                            /*$this->approxFilter( $search, array(  
    117                                                 // O CN e displayName geralmente sao a mesma coisa 
    118                                                 'cn', 'displayName' ))*/  ); 
    119  
    120                     $searchFilter = $this->stemFilter( $search, array( 'cn', 'givenName', 'uid', 
    121                                                                        'sn', 'displayName' ) ); 
     245                        switch( $targetType ) 
     246                        { 
     247                        case 'g': $typeFilter[] = "(objectClass=posixGroup)"; 
     248                        break; 
     249                         
     250                        default : $typeFilter[] = "(phpgwAccountStatus=A)"; 
     251                        break; 
     252                        } 
    122253                } 
    123                 break; 
    124             } 
     254 
     255                return $this->_and( array( '(!(phpgwAccountVisible=-1))', $this->_or( $typeFilter ) ) ); 
    125256        } 
    126257 
    127         $filter = array(); 
    128  
    129         if( $customFilter ) 
    130             $filter[] = $customFilter; 
    131         if( $search ) 
    132             $filter[] = $searchFilter; 
    133  
    134         return $this->_and( array( 
    135             // Somente objetos relacionados com o Expresso 
    136             $this->accountFilter( $targetTypes ), 
    137             // Objetos ocultados e/ou desativados pelo Administrador nao podem ser exibidos nas consultas do Expresso 
    138             $this->securityFilter( $targetTypes ), 
    139             //foco da busca 
    140             ( $exact ? $this->_and( $filter ) : $this->_or( $filter ) ) 
    141             )); 
    142  
    143         // Verificoes extras para validar o resultado 
    144         //  (& 
    145         //     // Somente objetos com e-mail no formato da RFC822 
    146         //    (mail=*@*) 
    147         //  ) 
    148     } 
    149  
    150     function securityFilter( $targetTypes ) 
    151     { 
    152         if( !$targetTypes ) 
    153             $targetTypes = $this->allTargetTypes; 
    154  
    155         if( !is_array( $targetTypes ) ) 
    156             $targetTypes = array( $targetTypes ); 
    157  
    158         $typeFilter = array(); 
    159  
    160         foreach( $targetTypes as $targetType ) 
    161         { 
    162             switch( $targetType ) 
    163             { 
    164                 case 'g': $typeFilter[] = "(objectClass=posixGroup)"; 
    165                 break; 
    166                  
    167                 default : $typeFilter[] = "(phpgwAccountStatus=A)"; 
    168                 break; 
    169             } 
    170         } 
    171  
    172         return $this->_and( array( '(!(phpgwAccountVisible=-1))', $this->_or( $typeFilter ) ) ); 
    173     } 
    174  
     258         
     259        /** 
     260     * Manipula o filtro da conta 
     261     * 
     262     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     263         * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     264         * @sponsor    Caixa Econômica Federal 
     265     * @param   $targetTypes 
     266     */ 
    175267    function accountFilter( $targetTypes ) 
    176268    { 
     
    189281    } 
    190282 
    191     function stemFilter( $search, $params ) 
    192     { 
    193         $search = str_replace( ' ', '*', $search ); 
    194  
    195         if( !is_array( $params ) ) 
    196             $params = array( $params ); 
    197  
    198         foreach( $params as $i => $param ) 
    199             $params[$i] = "($param=*$search*)"; 
    200          
    201         return $this->_or( $params ); 
    202     } 
    203  
    204     function phoneticFilter( $search, $params ) 
    205     { 
    206         if( eregi( "\d", $search ) ) 
    207             return( "" ); 
    208  
    209         if( !is_array( $params ) ) 
    210             $params = array( $params ); 
    211  
    212         foreach( $params as $i => $param ) 
    213             $params[$i] = "($param~=$search)"; 
    214          
    215         return $this->_or( $params ); 
    216     } 
    217  
     283     
     284         
     285        /** 
     286     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     287         * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     288         * @sponsor    Caixa Econômica Federal 
     289     * @param   $search 
     290     * @param   $params 
     291     */ 
     292        function stemFilter( $search, $params ) 
     293    { 
     294                $search = str_replace( ' ', '*', $search ); 
     295         
     296                if( !is_array( $params ) ) 
     297                        $params = array( $params ); 
     298         
     299                foreach( $params as $i => $param ) 
     300                        $params[$i] = "($param=*$search*)"; 
     301                 
     302                return $this->_or( $params ); 
     303    } 
     304 
     305     
     306        /** 
     307     * Manipula o filtro fonético 
     308     * 
     309     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     310         * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     311         * @sponsor    Caixa Econômica Federal 
     312     * @param   $search 
     313     * @param   $params 
     314     */ 
     315        function phoneticFilter( $search, $params ) 
     316    { 
     317                if( eregi( "\d", $search ) ) 
     318                        return( "" ); 
     319         
     320                if( !is_array( $params ) ) 
     321                        $params = array( $params ); 
     322         
     323                foreach( $params as $i => $param ) 
     324                        $params[$i] = "($param~=$search)"; 
     325                 
     326                return $this->_or( $params ); 
     327    } 
     328 
     329         
     330         
     331         
    218332    function approxFilter( $search, $params ) 
    219333    { 
    220         return $this->_or( array( $this->stemFilter( $search, $params ), 
     334                return $this->_or( array( $this->stemFilter( $search, $params ), 
    221335                                  $this->phoneticFilter( $search, $params ) ) ); 
    222336    } 
     
    227341//     } 
    228342 
    229     public function accountSearch($search, $justthese = "*", $context = false , $accountType = false, $sort = false) 
     343     
     344        /** 
     345     * Método que realiza a busca no LDAP 
     346     * 
     347     * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     348         * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     349         * @sponsor    Caixa Econômica Federal 
     350     * @param   $search 
     351     * @param   $justthese 
     352     * @param   $context 
     353     * @param   $accountType 
     354     * @param   $sort 
     355     */ 
     356        public function accountSearch($search, $justthese = "*", $context = false , $accountType = false, $sort = false) 
    230357    { 
    231358         if( !$this->connection ) 
Note: See TracChangeset for help on using the changeset viewer.