Changeset 946 for trunk/jabberit_messenger/inc/class.ldap_im.inc.php
- Timestamp:
- 06/04/09 10:30:18 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/jabberit_messenger/inc/class.ldap_im.inc.php
r892 r946 17 17 class ldap_im 18 18 { 19 private $attr_org; 20 private $common; 21 private $hostsJabber; 19 22 private $ldap; 20 private $ldap_host;21 23 private $ldap_context; 22 24 private $ldap_dn; 25 private $ldap_host; 23 26 private $ldap_pass; 24 private $common;25 private $jid;26 27 private $max_result; 27 private $ou_User;28 28 29 29 public final function __construct() 30 { 31 // Attributes org ldap; 32 $this->attr_org = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['attributes_org_ldap_jabberit']); 33 34 // Hosts Jabber 35 $this->hostsJabber = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']); 36 37 // Result Ldap 38 $this->max_result = 30; 39 } 40 41 public final function __destruct() 42 { 43 if( $this->ldap ) 44 ldap_close($this->ldap); 45 } 46 47 private final function ldapConn() 48 { 49 $this->common = new common(); 50 51 $GLOBALS['phpgw_info']['server']['ldap_version3'] = true; 52 53 $this->ldap = $this->common->ldapConnect( $this->ldap_host, $this->ldap_dn, $this->ldap_pass, false ); 54 } 55 56 private final function ldapRoot() 30 57 { 31 58 $this->ldap_host = (isset($_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_host']; … … 33 60 $this->ldap_dn = (isset($_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 34 61 $this->ldap_pass = (isset($_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 35 $this->jid = $_SESSION['phpgw_info']['jabberit_messenger']['user_jabber']; 36 $this->max_result = 50; 37 } 38 39 public final function __destruct() 40 { 41 if( $this->ldap ) 42 ldap_close($this->ldap); 43 } 44 45 private final function _connect_ldap() 46 { 47 $this->common = new common(); 48 49 if( !$this->ldap ) 50 { 51 $GLOBALS['phpgw_info']['server']['ldap_version3'] = true; 52 $this->ldap = $this->common->ldapConnect( $this->ldap_host,$this->ldap_dn,$this->ldap_pass, false ); 53 } 54 } 55 56 private final function _ldapConnect($refer = false) 57 { 58 function ldapRebindJabberit($ldap_connection, $ldap_url) 59 { 60 $acc = $_SESSION['phpgw_info']['jabberit_messenger']['ldapManager']['acc']; 61 $pw = $_SESSION['phpgw_info']['jabberit_messenger']['ldapManager']['pw']; 62 63 $this->ldapConn(); 64 } 65 66 private final function ldapCatalog() 67 { 68 $version3 = true; 69 $refer = true; 70 71 if(!function_exists('ldap_connect')) 72 return false; 73 74 if(!$conn = ldap_connect($this->ldap_host)) 75 return false; 76 77 if( $version3 ) 78 if( !ldap_set_option($conn,LDAP_OPT_PROTOCOL_VERSION,3) ) 79 $version3 = false; 80 81 ldap_set_option($conn, LDAP_OPT_REFERRALS, $refer); 82 83 // Bind as Admin 84 if($this->ldap_dn && $this->ldap_pass && !ldap_bind($conn, $this->ldap_dn, $this->ldap_pass)) 85 return false; 86 87 // Bind as Anonymous 88 if(!$this->ldap_dn && !$this->ldap_pass && !@ldap_bind($conn)) 89 return false; 62 90 63 @ldap_bind($ldap_connection, $acc,$pw); 64 } 65 66 // Using ContactCenter configuration. 67 $this->ldap_host = $_SESSION['phpgw_info']['jabberit_messenger']['ldapManager']['host']; 68 $this->ldap_context = $_SESSION['phpgw_info']['jabberit_messenger']['ldapManager']['dn']; 69 $this->ldap_dn = $_SESSION['phpgw_info']['jabberit_messenger']['ldapManager']['acc']; 70 $this->ldap_pass = $_SESSION['phpgw_info']['jabberit_messenger']['ldapManager']['pw']; 71 72 $this->ldap = ldap_connect($this->ldap_host); 73 ldap_set_option($this->ldap, LDAP_OPT_PROTOCOL_VERSION, 3); 74 ldap_set_option($this->ldap, LDAP_OPT_REFERRALS, $refer); 75 76 if ($refer) 77 { 78 ldap_set_rebind_proc($this->ldap, ldapRebindJabberit); 79 } 80 81 @ldap_bind($this->ldap,$this->ldap_dn,$this->ldap_pass); 82 } 83 84 public final function list_groups_memberUid($pGroup) 85 { 86 $this->_ldapConnect(); 91 return $conn; 92 } 93 94 public final function getGroupsLdap($pOrg) 95 { 96 $this->ldapRoot(); 97 98 if( $this->ldap ) 99 { 100 $organization = 'ou=' . $pOrg['ou'] .",". $this->ldap_context; 101 $filter = "(&(phpgwAccountType=g)(objectClass=posixGroup))"; 102 $justthese = array("cn","gidNumber"); 103 $search = ldap_list($this->ldap, $organization, $filter, $justthese); 104 $entry = ldap_get_entries( $this->ldap, $search ); 105 106 if( $entry ) 107 { 108 $result_groups = "<ldap>"; 109 foreach($entry as $tmp) 110 if( $tmp['gidnumber'][0] != "" ) 111 $result_groups .= "<org><cn>".$tmp['cn'][0]."</cn><gid>".$tmp['gidnumber'][0]."</gid></org>"; 112 113 $result_groups .= "</ldap>"; 114 } 115 } 116 117 return $result_groups; 118 } 119 120 public final function getGroupsMemberUid($pGroup) 121 { 122 $this->ldapRoot(); 87 123 88 124 if( $this->ldap ) … … 100 136 } 101 137 102 public final function list_participants_externals($pSearch) 103 { 104 $this->_ldapConnect(true); 105 106 $mail = $pSearch['mail']; 107 108 if( $this->ldap ) 109 { 110 $filter = "(&(phpgwaccounttype=u)(mail=".$mail."))"; 111 $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto"); 112 $search = ldap_search($this->ldap,$this->ldap_context,$filter,$justthese, 0, $this->max_result + 1); 113 $entry1 = ldap_get_entries($this->ldap,$search); 114 $entry = ldap_first_entry( $this->ldap, $search ); 115 } 116 117 if( $entry1['count'] > 0 ) 118 { 119 $i = 0; 120 $result_user = array(); 121 $result = array(); 122 123 while($entry) 124 { 125 126 if ( $entry1[$i]['phpgwaccountvisible'][0] != '-1' ) 127 { 128 $result['uidnumber'] = @ldap_get_values($this->ldap, $entry, 'uidnumber'); 129 $result['mail'] = @ldap_get_values($this->ldap, $entry, 'mail'); 130 $result['uid'] = @ldap_get_values($this->ldap, $entry, 'uid'); 131 $result['cn'] = @ldap_get_values($this->ldap, $entry, 'cn'); 132 133 foreach ( $result as $key => $value ) 134 $result_user[$i][$key] = $value[0]; 135 136 $ou = explode('dc=', $entry1[$i]['dn']); 137 $ou = explode("ou=",$ou[0]); 138 $ou = array_pop($ou); 139 $result_user[$i]['dn'] = strtoupper(substr($ou,0,strlen($ou)-1)); 140 141 $result_user[$i]['photo'] = 0; 142 143 $photo = @ldap_get_values_len($this->ldap, $entry, 'jpegphoto'); 144 145 if ( $photo ) 146 { 147 $result_user[$i]['photo'] = 1; 148 $_SESSION['phpgw_info']['jabberit_messenger']['photo'][trim($result_user[$i]['uid'])] = $photo[0]; 149 } 150 151 $i++; 152 } 153 $entry = ldap_next_entry($this->ldap,$entry); 154 } 155 156 $return = "<uids>"; 157 $return .= "<".$result_user[0]['dn']."><data>"; 158 $return .= "<cn>".$result_user[0]['cn']."</cn>"; 159 $return .= "<mail>".$result_user[0]['mail']."</mail>"; 160 $return .= "<uid>".$result_user[0]['uid']."</uid>"; 161 $return .= "<photo>".$result_user[0]['photo']."</photo>"; 162 $return .= "</data></".$result_user[0]['dn'].">"; 163 $return .= "</uids>"; 164 165 return $return; 166 } 167 168 return '<empty/>'; 169 } 170 171 public final function list_users_ldap( $search, $uidnumber, $ous = false ) 172 { 173 $this->_connect_ldap(); 174 175 if( $this->ldap ) 176 { 177 $filter = "(&(phpgwaccounttype=u)(|".$uidnumber.")(".$search ."))"; 178 $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto"); 179 // SERPRO 180 //$justthese = array("uid","uidNumber","cn","mail","description","phpgwAccountVisible","dn","jpegPhoto"); 181 182 if( $ous != false ) 183 $search = ldap_search($this->ldap,$ous.",".$this->ldap_context,$filter,$justthese, 0, $this->max_result + 1); 184 else 185 $search = ldap_search($this->ldap,$this->ldap_context,$filter,$justthese, 0, $this->max_result + 1); 186 187 $entry1 = ldap_get_entries($this->ldap,$search); 188 $entry = ldap_first_entry($this->ldap,$search); 189 } 190 191 if( $entry1['count'] > 0 ) 192 { 193 if( count($entry1) < $this->max_result ) 194 { 195 $i = 0; 196 $result_user = array(); 197 $result = array(); 198 199 while($entry) 200 { 201 202 if ( $entry1[$i]['phpgwaccountvisible'][0] != '-1' ) 203 { 204 $result['uidnumber'] = @ldap_get_values($this->ldap, $entry, 'uidnumber'); 205 $result['mail'] = @ldap_get_values($this->ldap, $entry, 'mail'); 206 $result['uid'] = @ldap_get_values($this->ldap, $entry, 'uid'); 207 $result['jid'] = @ldap_get_values($this->ldap, $entry, 'uid'); 208 $result['cn'] = @ldap_get_values($this->ldap, $entry, 'cn'); 209 // SERPRO 210 //$result['description'] = @ldap_get_values($this->ldap, $entry, 'description'); 211 212 foreach ( $result as $key => $value ) 213 $result_user[$i][$key] = $value[0]; 214 215 $ou = explode('dc=', $entry1[$i]['dn']); 216 $ou = explode("ou=",$ou[0]); 217 $ou = array_pop($ou); 218 $result_user[$i]['dn'] = strtoupper(substr($ou,0,strlen($ou)-1)); 219 220 $result_user[$i]['photo'] = 0; 221 $photo = @ldap_get_values_len($this->ldap, $entry, 'jpegphoto'); 222 if ( $photo ) 223 { 224 $result_user[$i]['photo'] = 1; 225 $_SESSION['phpgw_info']['jabberit_messenger']['photo'][trim($result_user[$i]['uid'])] = $photo[0]; 226 } 227 228 $organization = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['attributes_org_ldap_jabberit']); 229 230 if(is_array($organization)) 231 { 232 foreach($organization as $attr) 233 { 234 $tmp = explode(";",$attr); 235 if( strtolower(trim($tmp[0])) == strtolower(trim($result_user[$i]['dn'])) ) 236 { 237 switch(strtolower(trim($tmp[1]))) 238 { 239 case "mail" : 240 $uid = $result_user[$i]['mail']; 241 $uid = substr($uid,0,strpos($uid,"@")); 242 $result_user[$i]['uid'] = $uid; 243 break; 244 245 case "description" : 246 // SERPRO 247 // parte antes do arroba; 248 $result_user[$i]['uid'] = $result_user[$i]['description']; 249 break; 250 } 251 } 252 } 253 } 254 255 $i++; 256 } 257 $entry = ldap_next_entry($this->ldap,$entry); 258 } 259 260 return $result_user; 261 } 262 else 263 { 264 return "Many Results"; 265 } 266 } 267 return 0; 268 } 269 270 public final function listOrganizationsLdap() 271 { 272 273 $this->_connect_ldap(); 138 public final function getOrganizationsLdap() 139 { 140 $this->ldapRoot(); 274 141 275 142 if( $this->ldap ) … … 287 154 return $result_org; 288 155 } 289 290 public final function getGroupsLdap($pOrg) 291 { 292 $this->_ldapConnect(true); 293 $organization = 'ou=' . $pOrg['ou'] .",". $this->ldap_context; 294 295 if( $this->ldap ) 296 { 297 $filter = "(&(phpgwAccountType=g)(objectClass=posixGroup))"; 298 $justthese = array("cn","gidNumber"); 299 $search = ldap_list($this->ldap, $organization, $filter, $justthese); 156 157 public final function getUsersLdap( $search, $uidnumber, $ous = false) 158 { 159 // Ldap Principal 160 $ldapRoot = $this->getUsersLdapRoot($search, $uidnumber, $ous); 161 162 if( !$ous ) 163 { 164 // Ldap Outros 165 $ldapCatalog = $this->getUsersLdapCatalog( $search ); 166 $ldapRoot = array_merge( $ldapRoot, $ldapCatalog ); 167 } 168 169 return $ldapRoot; 170 } 171 172 private final function getUsersLdapCatalog( $search ) 173 { 174 $confHosts = $this->hostsJabber; 175 $result = array(); 176 $return = array(); 177 $conn = ""; 178 179 for($i = 0; $i < count($confHosts); $i++ ) 180 { 181 $this->ldap_host = $confHosts[$i]['serverLdap']; 182 $this->ldap_context = $confHosts[$i]['contextLdap']; 183 $this->ldap_dn = $confHosts[$i]['user']; 184 $this->ldap_pass = $confHosts[$i]['password']; 185 186 $conn = $this->ldapCatalog(); 187 188 if( $conn ) 189 { 190 $filter = "(&(phpgwaccounttype=u)(".$search ."))"; 191 $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto"); 192 $search1 = @ldap_search($conn, $this->ldap_context, $filter, $justthese, 0, $this->max_result + 1); 193 $entry1 = @ldap_get_entries( $conn, $search1 ); 194 195 $result = $this->resultArray($entry1, $conn ); 196 197 if( count($return) > 0 ) 198 $return = array_merge($return, $result); 199 else 200 $return = $result; 201 202 unset($result); 203 204 ldap_close($conn); 205 } 206 } 207 208 return $return; 209 } 210 211 private final function getUsersLdapRoot( $search, $uidnumber, $ous = false ) 212 { 213 $this->ldapRoot(); 214 $result = array(); 215 216 if( $this->ldap ) 217 { 218 $searchRoot = ( $ous ) ? $ous.",".$this->ldap_context : $this->ldap_context ; 219 $filter = "(&(phpgwaccounttype=u)(|".$uidnumber.")(".$search ."))"; 220 $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto"); 221 $search = ldap_search($this->ldap, $searchRoot, $filter, $justthese, 0, $this->max_result + 1); 300 222 $entry = ldap_get_entries( $this->ldap, $search ); 301 223 302 if( $entry ) 303 { 304 $result_groups = "<ldap>"; 305 foreach($entry as $tmp) 306 if( $tmp['gidnumber'][0] != "" ) 307 $result_groups .= "<org><cn>".$tmp['cn'][0]."</cn><gid>".$tmp['gidnumber'][0]."</gid></org>"; 308 309 $result_groups .= "</ldap>"; 310 } 311 } 312 313 return $result_groups; 224 $result = $this->resultArray($entry, $this->ldap ); 225 } 226 227 return $result; 228 } 229 230 private final function resultArray($pArray, $pConn) 231 { 232 $entry = $pArray; 233 $result = array(); 234 235 $j = 0; 236 for($i = 0 ; $i < $entry['count']; $i++) 237 { 238 if ( $entry[$i]['phpgwaccountvisible'][0] != '-1' ) 239 { 240 $result[$j]['uidnumber'] = $entry[$i]['uidnumber'][0]; 241 $result[$j]['mail'] = $entry[$i]['mail'][0]; 242 $result[$j]['uid'] = $entry[$i]['uid'][0]; 243 $result[$j]['jid'] = $entry[$i]['uid'][0]; 244 $ou = explode("dc=", $entry[$i]['dn']); 245 $ou = explode("ou=",$ou[0]); 246 $ou = array_pop($ou); 247 $result[$j]['ou'] = strtoupper(substr($ou,0,strlen($ou)-1)); 248 if( $entry[$i]['jpegphoto'][0] ) 249 { 250 $result[$j]['photo'] = "1"; 251 $filterPhoto = "(objectclass=*)"; 252 $photoLdap = ldap_read($pConn, $entry[$i]['dn'], $filterPhoto, array("jpegPhoto")); 253 $firstEntry = ldap_first_entry($pConn, $photoLdap); 254 $photo = ldap_get_values_len($pConn, $firstEntry, "jpegPhoto"); 255 $_SESSION['phpgw_info']['jabberit_messenger']['photo'][trim($result[$j]['ou'])][trim($result[$j]['uid'])] = $photo[0]; 256 } 257 else 258 $result[$j]['photo'] = "0"; 259 260 $result[$j++]['cn'] = $entry[$i]['cn'][0]; 261 } 262 263 $organization = $this->attr_org; 264 265 if(is_array($organization)) 266 { 267 foreach($organization as $attr) 268 { 269 $tmp = explode(";",$attr); 270 if( strtolower(trim($tmp[0])) == strtolower(trim($result[$i]['dn'])) ) 271 { 272 switch(strtolower(trim($tmp[1]))) 273 { 274 case "mail" : 275 $uid = $result[$i]['mail']; 276 $uid = substr($uid,0,strpos($uid,"@")); 277 $result[$i]['uid'] = $uid; 278 break; 279 280 case "description" : 281 // SERPRO 282 // parte antes do arroba; 283 $result[$i]['uid'] = $result[$i]['description']; 284 break; 285 } 286 } 287 } 288 } 289 } 290 return $result; 314 291 } 315 292 }
Note: See TracChangeset
for help on using the changeset viewer.