Changeset 5130 for trunk/services/class.ldap.php
- Timestamp:
- 11/03/11 11:13:40 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/services/class.ldap.php
r5068 r5130 4 4 * Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 5 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. 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 19 * 27 20 * You can contact Prognus Software Livre headquarters at Av. Tancredo Neves, … … 29 22 * e-mail address prognus@prognus.com.br. 30 23 * 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 24 * 25 * @package LdapService 49 26 * @license http://www.gnu.org/copyleft/gpl.html GPL 50 27 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 51 28 * @sponsor Caixa Econômica Federal 52 29 * @version 1.0 30 * @since 2.4.0 53 31 */ 32 54 33 class LdapService 55 34 { … … 62 41 function LdapService() 63 42 { 64 65 } 66 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 */ 43 if(isset($GLOBALS['phpgw_info']['server']['ldap_context']) ) 44 $this->context = $GLOBALS['phpgw_info']['server']['ldap_context']; 45 } 46 47 public function setContext( $pContext ) 48 { 49 $this->context = $pContext; 50 } 51 79 52 function connect($host='', $dn='', $passwd='', $ldapreferral=false) 80 53 { … … 113 86 return( $toWrap ); 114 87 115 // if( count( $toWrap ) <= 1 )116 // return implode( "", $toWrap );117 118 88 return $this->wrap( $toWrap, '|' ); 119 89 } … … 124 94 return( $toWrap ); 125 95 126 // if( count( $toWrap ) <= 1 )127 // return implode( "", $toWrap );128 129 96 return $this->wrap( $toWrap, '&' ); 130 97 } … … 145 112 } 146 113 147 /**148 * Manipula o filtro de busca149 *150 * @license http://www.gnu.org/copyleft/gpl.html GPL151 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)152 * @sponsor Caixa Econômica Federal153 * @param $search154 * @param $targetTypes155 * @param $customFilter156 * @param $exact157 */158 114 function getSearchFilter( $search, $targetTypes = false, $customFilter = '', $exact = false ) 159 115 { … … 186 142 'uid', /*'employeeNumber', */'cn', 187 143 // givenName e SN sao complementares (nome e sobrenome) 188 'givenName', 'sn', 'displayName' ) //),144 'givenName', 'sn', 'displayName', 'mail', 'mailAlternateAddress' ) //), 189 145 //parametros que a busca pode ser por aproximacao fonetica 190 146 /*$this->approxFilter( $search, array( … … 193 149 194 150 $searchFilter = $this->stemFilter( $search, array( 'cn', 'givenName', 'uid', 195 'sn', 'displayName' ) );151 'sn', 'displayName', 'mail', 'mailAlternateAddress' ) ); 196 152 } 197 153 break; … … 215 171 )); 216 172 217 // Verificoes extras para validar o resultado218 // (&219 // // Somente objetos com e-mail no formato da RFC822220 // (mail=*@*)221 // )222 173 } 223 174 224 225 /**226 * Manipula o filtro de segurança227 *228 * @license http://www.gnu.org/copyleft/gpl.html GPL229 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)230 * @sponsor Caixa Econômica Federal231 * @param $targetTypes232 */233 175 function securityFilter( $targetTypes ) 234 176 { … … 248 190 break; 249 191 250 default : $typeFilter[] = "(phpgwAccountStatus=A)";192 default : $typeFilter[] = "(phpgwAccountStatus=A)(accountStatus=active)"; 251 193 break; 252 194 } … … 256 198 } 257 199 258 259 /**260 * Manipula o filtro da conta261 *262 * @license http://www.gnu.org/copyleft/gpl.html GPL263 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)264 * @sponsor Caixa Econômica Federal265 * @param $targetTypes266 */267 200 function accountFilter( $targetTypes ) 268 201 { … … 281 214 } 282 215 283 284 285 /**286 * @license http://www.gnu.org/copyleft/gpl.html GPL287 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)288 * @sponsor Caixa Econômica Federal289 * @param $search290 * @param $params291 */292 216 function stemFilter( $search, $params ) 293 217 { … … 303 227 } 304 228 305 306 /**307 * Manipula o filtro fonético308 *309 * @license http://www.gnu.org/copyleft/gpl.html GPL310 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)311 * @sponsor Caixa Econômica Federal312 * @param $search313 * @param $params314 */315 229 function phoneticFilter( $search, $params ) 316 230 { … … 336 250 } 337 251 338 // public function search()339 // {340 //341 // }342 343 344 /**345 * Método que realiza a busca no LDAP346 *347 * @license http://www.gnu.org/copyleft/gpl.html GPL348 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)349 * @sponsor Caixa Econômica Federal350 * @param $search351 * @param $justthese352 * @param $context353 * @param $accountType354 * @param $sort355 */356 252 public function accountSearch($search, $justthese = "*", $context = false , $accountType = false, $sort = false) 357 253 { … … 362 258 363 259 if( !$context ) 364 $context = $GLOBALS['phpgw_info']['server']['ldap_context']; 365 366 $ls = ldap_search( $this->connection, utf8_encode($context), $filter, $justthese, 0, $this->limit ); 260 $context = $this->context; 261 262 $sr = ldap_search( $this->connection, utf8_encode($context), $filter, $justthese, 0, $this->limit ); 263 264 if(!$sr) return false; 367 265 368 266 if($sort) 369 ldap_sort( $this->connection, $ls, $sort ); 370 371 $entries = ldap_get_entries( $this->connection, $ls ); 372 373 if( !$entries ) return( null ); 267 ldap_sort( $this->connection, $sr, $sort ); 268 269 return $this->formatEntries( ldap_get_entries( $this->connection, $sr ) ); 270 } 271 272 private function formatEntries ( $pEntries ) 273 { 274 275 if( !$pEntries ) return( false ); 374 276 375 277 $return = array(); 376 278 377 for ($i=0; $i < $ entries["count"]; $i++)279 for ($i=0; $i < $pEntries["count"]; $i++) 378 280 { 379 281 $entrieTmp = array(); 380 foreach ($ entries[$i] as $index => $value)282 foreach ($pEntries[$i] as $index => $value) 381 283 { 382 284 if(!is_numeric($index) && $index != 'count') … … 406 308 } 407 309 310 /** 311 * Retorna o endereço de e-mail da conta pelo uidNumber 312 * 313 * @license http://www.gnu.org/copyleft/gpl.html GPL 314 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 315 * @sponsor Caixa Econômica Federal 316 * @author Cristiano Corrêa Schmidt 317 * @param int $pUidNumber uidNumber da conta 318 * @return string 319 * @access public 320 */ 321 public function getMailByUidNumber( $pUidNumber ) 322 { 323 if( !$this->connection ) $this->connect(); 324 $sr = ldap_search( $this->connection, $this->context, '(uidNumber='.$pUidNumber.')', array('mail') ); 325 if(!$sr) return false; 326 327 $return = ldap_get_entries( $this->connection, $sr ); 328 return $return[0]['mail'][0]; 329 } 330 331 /** 332 * Retorna em um array os endereços de e-mails alternativos da conta pelo uidNumber 333 * 334 * @license http://www.gnu.org/copyleft/gpl.html GPL 335 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 336 * @sponsor Caixa Econômica Federal 337 * @author Cristiano Corrêa Schmidt 338 * @param int $pUidNumber uidNumber da conta 339 * @return Array 340 * @access public 341 */ 342 public function getMailAlternateByUidNumber( $pUidNumber ) 343 { 344 if( !$this->connection ) $this->connect(); 345 346 $sr = ldap_search( $this->connection, $this->context, '(uidNumber='.$pUidNumber.')', array('mailAlternateAddress')); 347 if(!$sr) return false; 348 349 $returnL = ldap_get_entries( $this->connection,$sr); 350 $return = array(); 351 foreach ($returnL[0]['mailalternateaddress'] as $i => $v) 352 { 353 if($i === 'count') continue; 354 $return[] = $v; 355 } 356 return $return; 357 } 358 408 359 } 409 360
Note: See TracChangeset
for help on using the changeset viewer.