[382] | 1 | <?php |
---|
[417] | 2 | /***************************************************************************\ |
---|
| 3 | * Expresso - Expresso Messenger * |
---|
| 4 | * - Alexandre Correia / Rodrigo Souza * |
---|
| 5 | * - JETI - http://jeti-im.org/ * |
---|
| 6 | * ------------------------------------------------------------------------- * |
---|
| 7 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 8 | * under the terms of the GNU General Public License as published by the * |
---|
| 9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 10 | * option) any later version. * |
---|
| 11 | \***************************************************************************/ |
---|
[382] | 12 | |
---|
| 13 | define('PHPGW_INCLUDE_ROOT', '../'); |
---|
| 14 | define('PHPGW_API_INC','../phpgwapi/inc'); |
---|
| 15 | require_once( PHPGW_API_INC . '/class.common.inc.php'); |
---|
| 16 | |
---|
| 17 | class ldap_im |
---|
| 18 | { |
---|
| 19 | private $ldap; |
---|
| 20 | private $ldap_host; |
---|
| 21 | private $ldap_context; |
---|
| 22 | private $ldap_dn; |
---|
| 23 | private $ldap_pass; |
---|
| 24 | private $common; |
---|
| 25 | private $jid; |
---|
| 26 | private $max_result; |
---|
| 27 | |
---|
| 28 | public final function __construct() |
---|
| 29 | { |
---|
| 30 | $this->ldap_host = $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit']; |
---|
| 31 | $this->ldap_context = $_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit']; |
---|
| 32 | $this->ldap_dn = $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit']; |
---|
| 33 | $this->ldap_pass = $_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit']; |
---|
| 34 | $this->jid = $_SESSION['phpgw_info']['jabberit_messenger']['user']; |
---|
| 35 | $this->max_result = 50; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | public final function __destruct() |
---|
| 39 | { |
---|
| 40 | if( $this->ldap ) |
---|
| 41 | ldap_close($this->ldap); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | private final function _connect_ldap() |
---|
| 45 | { |
---|
| 46 | $this->common = new common(); |
---|
| 47 | |
---|
[417] | 48 | if( !$this->ldap ) |
---|
| 49 | { |
---|
[382] | 50 | $GLOBALS['phpgw_info']['server']['ldap_version3'] = true; |
---|
[519] | 51 | $this->ldap = $this->common->ldapConnect( $this->ldap_host,$this->ldap_dn,$this->ldap_pass, true ); |
---|
[382] | 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | public final function list_users_ldap($search, $uidnumber) |
---|
| 56 | { |
---|
| 57 | $this->_connect_ldap(); |
---|
| 58 | |
---|
| 59 | if( $this->ldap ) |
---|
| 60 | { |
---|
| 61 | $filter = "(&(phpgwaccounttype=u)(|".$uidnumber.")(".$search ."))"; |
---|
| 62 | $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto"); |
---|
| 63 | $search = ldap_search($this->ldap,$this->ldap_context,$filter,$justthese, 0, $this->max_result + 1); |
---|
| 64 | $entry1 = ldap_get_entries($this->ldap,$search); |
---|
| 65 | $entry = ldap_first_entry( $this->ldap, $search ); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | if( $entry1['count'] > 0 ) |
---|
| 69 | { |
---|
| 70 | if( count($entry1) < $this->max_result ) |
---|
| 71 | { |
---|
| 72 | $i = 0; |
---|
| 73 | $result_user = array(); |
---|
| 74 | $result = array(); |
---|
| 75 | |
---|
| 76 | while($entry) |
---|
| 77 | { |
---|
| 78 | |
---|
| 79 | if ( $entry1[$i]['phpgwaccountvisible'][0] != '-1' ) |
---|
| 80 | { |
---|
| 81 | $result['uidnumber'] = @ldap_get_values($this->ldap, $entry, 'uidnumber'); |
---|
| 82 | $result['mail'] = @ldap_get_values($this->ldap, $entry, 'mail'); |
---|
| 83 | $result['uid'] = @ldap_get_values($this->ldap, $entry, 'uid'); |
---|
| 84 | $result['cn'] = @ldap_get_values($this->ldap, $entry, 'cn'); |
---|
| 85 | |
---|
| 86 | foreach ( $result as $key => $value ) |
---|
| 87 | $result_user[$i][$key] = $value[0]; |
---|
| 88 | |
---|
| 89 | $ou = explode('dc=', $entry1[$i]['dn']); |
---|
| 90 | $ou = explode("ou=",$ou[0]); |
---|
| 91 | $ou = array_pop($ou); |
---|
| 92 | $result_user[$i]['dn'] = strtoupper(substr($ou,0,strlen($ou)-1)); |
---|
| 93 | |
---|
| 94 | $result_user[$i]['photo'] = 0; |
---|
| 95 | $photo = @ldap_get_values_len($this->ldap, $entry, 'jpegphoto'); |
---|
| 96 | if ( $photo ) |
---|
| 97 | { |
---|
| 98 | $result_user[$i]['photo'] = 1; |
---|
| 99 | $_SESSION['phpgw_info']['jabberit_messenger']['photo'][trim($result_user[$i]['uid'])] = $photo[0]; |
---|
| 100 | } |
---|
| 101 | $i++; |
---|
| 102 | } |
---|
| 103 | $entry = ldap_next_entry($this->ldap,$entry); |
---|
| 104 | } |
---|
| 105 | return $result_user; |
---|
| 106 | } |
---|
| 107 | else |
---|
| 108 | { |
---|
| 109 | return "Many Results"; |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | return 0; |
---|
| 113 | } |
---|
[417] | 114 | |
---|
[519] | 115 | public final function list_organizations_ldap() |
---|
[417] | 116 | { |
---|
[519] | 117 | $result_org = "<organizations>"; |
---|
| 118 | |
---|
| 119 | $this->_connect_ldap(); |
---|
| 120 | |
---|
| 121 | if( $this->ldap ) |
---|
| 122 | { |
---|
| 123 | $filter="ou=*"; |
---|
| 124 | $justthese = array("ou"); |
---|
| 125 | $search = ldap_search($this->ldap,$this->ldap_context,$filter,$justthese); |
---|
| 126 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | foreach($entry as $tmp) |
---|
| 130 | if($tmp['ou'][0] != "") |
---|
| 131 | $result_org .= "<ou>" . $tmp['ou'][0] . "</ou>"; |
---|
| 132 | |
---|
| 133 | $result_org .= "</organizations>"; |
---|
| 134 | |
---|
| 135 | return $result_org; |
---|
[417] | 136 | } |
---|
[382] | 137 | } |
---|
| 138 | |
---|
[519] | 139 | ?> |
---|