Changeset 1757
- Timestamp:
- 12/04/09 16:42:32 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/jabberit_messenger/inc/class.ldap_im.inc.php
r1504 r1757 11 11 \***************************************************************************/ 12 12 13 define('PHPGW_INCLUDE_ROOT', '../'); 14 define('PHPGW_API_INC','../phpgwapi/inc'); 13 if( is_dir('../phpgwapi/inc') ) 14 define('PHPGW_API_INC','../phpgwapi/inc'); 15 else 16 define('PHPGW_API_INC','../../phpgwapi/inc'); 17 15 18 require_once( PHPGW_API_INC . '/class.common.inc.php'); 16 19 … … 30 33 public final function __construct() 31 34 { 35 $this->ldap_host = $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit']; 36 $this->ldap_context = $_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit']; 37 $this->ldap_user = $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit']; 38 $this->ldap_pass = $_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit']; 39 32 40 // Attributes org ldap; 33 41 $this->attr_org = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['attributes_org_ldap_jabberit']); … … 38 46 // Result Ldap 39 47 $this->max_result = 30; 48 40 49 } 41 50 … … 60 69 private final function ldapRoot() 61 70 { 62 $this->ldap_host = $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit'];63 $this->ldap_context = $_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit'];64 $this->ldap_user = $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit'];65 $this->ldap_pass = $_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit'];66 67 71 $this->ldapConn(); 68 72 } … … 96 100 } 97 101 98 public final function getGroupsLdap($pOrg) 99 { 100 $this->ldapRoot(); 102 public final function getGroupsLdap($pData) 103 { 101 104 $result_groups = ""; 102 103 if( $this->ldap && $pOrg['ou'] != "-1") 104 { 105 $organization = 'ou=' . $pOrg['ou'] .",". $this->ldap_context; 106 $filter = "(&(phpgwAccountType=g)(objectClass=posixGroup))"; 107 $justthese = array("cn","gidNumber"); 108 $search = ldap_list($this->ldap, $organization, $filter, $justthese); 109 $entry = ldap_get_entries( $this->ldap, $search ); 110 111 if( $entry ) 105 106 if( $pData['serverLdap'] == $this->ldap_host || $pData['serverLdap'] == 'localhost' ) 107 { 108 $this->ldapRoot(); 109 } 110 else 111 { 112 $confHosts = $this->hostsJabber; 113 114 for($i = 0; $i < count($confHosts); $i++ ) 115 { 116 if( $pData['serverLdap'] == $confHosts[$i]['serverLdap'] ) 117 { 118 $this->ldap_host = $confHosts[$i]['serverLdap']; 119 $this->ldap_context = $confHosts[$i]['contextLdap']; 120 $this->ldap_user = $confHosts[$i]['user']; 121 $this->ldap_org = $confHosts[$i]['org']; 122 $this->ldap_pass = $confHosts[$i]['password']; 123 124 $this->ldap = $this->ldapCatalog(); 125 } 126 } 127 } 128 129 if( $this->ldap ) 130 { 131 if( !$pData['search'] && $pData['ou'] != "-1" ) 132 { 133 $filter = "(&(phpgwAccountType=g)(objectClass=posixGroup))"; 134 $justthese = array("cn","gidNumber"); 135 $search = ldap_list( $this->ldap, $pData['ou'] , $filter, $justthese ); 136 $entry = ldap_get_entries( $this->ldap, $search ); 137 } 138 139 if( $pData['search'] ) 140 { 141 $filter = "(&(phpgwAccountType=g)(&(objectClass=posixGroup)(cn=".$pData['search']."*)))"; 142 $justthese = array("cn","gidNumber"); 143 $search = ldap_search( $this->ldap, $this->ldap_context , $filter, $justthese ); 144 $entry = ldap_get_entries( $this->ldap, $search ); 145 } 146 147 if( $entry && $entry['count'] > 0 ) 112 148 { 149 array_shift($entry); 150 151 foreach($entry as $tmp) 152 $groups[] = $tmp['cn'][0]."/".$tmp['gidnumber'][0]; 153 154 natsort($groups); 155 113 156 $result_groups = "<ldap>"; 114 foreach($entry as $tmp) 115 if( $tmp['gidnumber'][0] != "" ) 116 $result_groups .= "<org><cn>".$tmp['cn'][0]."</cn><gid>".$tmp['gidnumber'][0]."</gid></org>"; 157 foreach($groups as $gtmp) 158 { 159 $tmp = explode("/",$gtmp); 160 $result_groups .= "<org><cn>".$tmp[0]."</cn><gid>".$tmp[1]."</gid></org>"; 161 } 162 $result_groups .= "</ldap>"; 163 } 164 } 165 166 return $result_groups; 167 } 168 169 public final function getGroupsMemberUid( $pGroup, $pLdap ) 170 { 171 if( $pLdap == $this->ldap_host || $pLdap == 'localhost' ) 172 { 173 $this->ldapRoot(); 174 175 if( $this->ldap ) 176 { 177 $filter = "(&(objectclass=posixgroup)(cn=".$pGroup."))"; 178 $justthese = array("memberuid","gidnumber"); 179 $search = ldap_search($this->ldap,$this->ldap_context,$filter, $justthese); 180 $result = ldap_get_entries($this->ldap,$search); 181 } 182 } 183 else 184 { 185 $confHosts = $this->hostsJabber; 186 187 for($i = 0; $i < count($confHosts); $i++ ) 188 { 189 if( $this->ldap ) 190 ldap_close($this->ldap); 191 192 if( $pLdap == $confHosts[$i]['serverLdap'] ) 193 { 194 $this->ldap_host = $confHosts[$i]['serverLdap']; 195 $this->ldap_context = $confHosts[$i]['contextLdap']; 196 $this->ldap_user = $confHosts[$i]['user']; 197 $this->ldap_org = $confHosts[$i]['org']; 198 $this->ldap_pass = $confHosts[$i]['password']; 117 199 118 $result_groups .= "</ldap>"; 119 } 120 121 return $result_groups; 122 } 123 124 return $result_groups; 125 } 126 127 public final function getGroupsMemberUid($pGroup) 128 { 129 $this->ldapRoot(); 130 131 if( $this->ldap ) 132 { 133 $filter = "(&(objectclass=posixgroup)(|".$pGroup."))"; 134 $justthese = array("dn","memberuid","gidnumber"); 135 $search = ldap_search($this->ldap,$this->ldap_context,$filter, $justthese); 136 $result = ldap_get_entries($this->ldap,$search); 137 138 if( $result['count'] > 0 ) 139 return $result; 140 } 141 200 $this->ldap = $this->ldapCatalog(); 201 202 if( $this->ldap ) 203 { 204 $filter = "(&(objectclass=posixgroup)(cn=".$pGroup."))"; 205 $justthese = array("memberuid","gidnumber"); 206 $search = ldap_search($this->ldap,$this->ldap_context,$filter, $justthese); 207 $result = ldap_get_entries($this->ldap,$search); 208 } 209 } 210 } 211 } 212 213 if( $result['count'] > 0 ) 214 { 215 array_shift($result[0]['memberuid']); 216 return $result[0]['memberuid']; 217 } 218 142 219 return false; 143 220 } 144 221 145 public final function getOrganizationsLdap() 146 { 147 $this->ldapRoot(); 222 public final function getOrganizationsLdap($pLdap_host) 223 { 224 225 if( $pLdap_host == $this->ldap_host || $pLdap_host == 'localhost' ) 226 { 227 $this->ldapRoot(); 228 } 229 else 230 { 231 $confHosts = $this->hostsJabber; 232 233 for($i = 0; $i < count($confHosts); $i++ ) 234 { 235 if( $pLdap_host == $confHosts[$i]['serverLdap'] ) 236 { 237 $this->ldap_host = $confHosts[$i]['serverLdap']; 238 $this->ldap_context = $confHosts[$i]['contextLdap']; 239 $this->ldap_user = $confHosts[$i]['user']; 240 $this->ldap_org = $confHosts[$i]['org']; 241 $this->ldap_pass = $confHosts[$i]['password']; 242 243 $this->ldap = $this->ldapCatalog(); 244 } 245 } 246 } 148 247 149 248 if( $this->ldap ) … … 155 254 156 255 for ($i=0; $i<$info["count"]; $i++) 157 $a_sectors[] = $info[$i]['dn']; 256 { 257 $a_sectors[] = $info[$i]['dn']; 258 } 158 259 } 159 260 … … 198 299 } 199 300 200 public final function getUsersLdapCatalog( $search )301 public final function getUsersLdapCatalog( $search, $uid = false, $pLdap = false ) 201 302 { 202 303 $confHosts = $this->hostsJabber; … … 205 306 $conn = ""; 206 307 207 for($i = 0; $i < count($confHosts); $i++ ) 208 { 209 $this->ldap_host = $confHosts[$i]['serverLdap']; 210 $this->ldap_context = $confHosts[$i]['contextLdap']; 211 $this->ldap_user = $confHosts[$i]['user']; 212 $this->ldap_org = $confHosts[$i]['org']; 213 $this->ldap_pass = $confHosts[$i]['password']; 214 215 $conn = $this->ldapCatalog(); 216 217 if( $conn ) 218 { 219 $filter = "(&(phpgwaccounttype=u)(".$search ."))"; 220 $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto"); 221 $searchRoot = ( $this->ldap_org != "*" ) ? "ou=".$this->ldap_org.",".$this->ldap_context : $this->ldap_context; 222 223 $search1 = @ldap_search($conn, $searchRoot, $filter, $justthese, 0, $this->max_result + 1); 224 $entry1 = @ldap_get_entries( $conn, $search1 ); 225 $result = $this->resultArray($entry1, $conn ); 226 308 for( $i = 0; $i < count($confHosts); $i++ ) 309 { 310 if( $this->ldap ) 311 ldap_close($this->ldap); 312 313 if( $pLdap && $pLdap == $confHosts[$i]['serverLdap'] ) 314 { 315 $this->ldap_host = $confHosts[$i]['serverLdap']; 316 $this->ldap_context = $confHosts[$i]['contextLdap']; 317 $this->ldap_user = $confHosts[$i]['user']; 318 $this->ldap_org = $confHosts[$i]['org']; 319 $this->ldap_pass = $confHosts[$i]['password']; 320 $this->ldap = $this->ldapCatalog(); 321 } 322 else 323 { 324 $this->ldap_host = $confHosts[$i]['serverLdap']; 325 $this->ldap_context = $confHosts[$i]['contextLdap']; 326 $this->ldap_user = $confHosts[$i]['user']; 327 $this->ldap_org = $confHosts[$i]['org']; 328 $this->ldap_pass = $confHosts[$i]['password']; 329 $this->ldap = $this->ldapCatalog(); 330 } 331 332 if( $this->ldap ) 333 { 334 $filter = ( $uid ) ? "(&(phpgwaccounttype=u)(|".$uid.")(".$search ."))" : "(&(phpgwaccounttype=u)(".$search ."))"; 335 $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto"); 336 $searchRoot = ( $this->ldap_org != "*" ) ? "ou=".$this->ldap_org.",".$this->ldap_context : $this->ldap_context; 337 $search1 = @ldap_search($this->ldap, $searchRoot, $filter, $justthese, 0, $this->max_result + 1); 338 $entry1 = @ldap_get_entries( $this->ldap, $search1 ); 339 $result = $this->resultArray( $entry1, $this->ldap ); 340 227 341 if( count($return) > 0 ) 228 342 $return = array_merge($return, $result); 229 343 else 230 344 $return = $result; 231 232 unset($result);233 234 ldap_close($conn);235 345 } 236 346 } … … 241 351 public final function getUsersLdapRoot( $search, $uidnumber, $ous = false ) 242 352 { 353 $result = array(); 243 354 $this->ldapRoot(); 244 $result = array();245 355 246 356 if( $this->ldap ) 247 357 { 248 $searchRoot = ( $ous ) ? $ous.",".$this->ldap_context : $this->ldap_context ; 249 $filter = "(&(phpgwaccounttype=u)(|".$uidnumber.")(".$search ."))"; 250 $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto"); 251 $search = ldap_search($this->ldap, $searchRoot, $filter, $justthese, 0, $this->max_result + 1); 252 $entry = ldap_get_entries( $this->ldap, $search ); 253 254 $result = $this->resultArray($entry, $this->ldap ); 358 $searchRoot = ( $ous ) ? $ous.",".$this->ldap_context : $this->ldap_context ; 359 $filter = "(&(phpgwaccounttype=u)(|".$uidnumber.")(".$search ."))"; 360 $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto"); 361 $search = ldap_search($this->ldap, $searchRoot, $filter, $justthese, 0, $this->max_result + 1); 362 $entry = ldap_get_entries( $this->ldap, $search ); 363 $result = $this->resultArray($entry, $this->ldap ); 255 364 } 256 365
Note: See TracChangeset
for help on using the changeset viewer.