[20] | 1 | <?php |
---|
| 2 | class ldap_im |
---|
| 3 | { |
---|
| 4 | private $ldap_host; |
---|
| 5 | private $ldap_context; |
---|
| 6 | private $conn; |
---|
| 7 | private $user; |
---|
[151] | 8 | private $jid; |
---|
[20] | 9 | private $password; |
---|
| 10 | |
---|
| 11 | function __construct() |
---|
| 12 | { |
---|
[151] | 13 | session_start(); |
---|
| 14 | $this->ldap_host = $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber']; |
---|
| 15 | $this->ldap_context = $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber']; |
---|
| 16 | $this->user = $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber']; |
---|
| 17 | $this->password = $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber']; |
---|
| 18 | $this->jid = $_SESSION['phpgw_info']['instant_messenger']['user']; |
---|
[33] | 19 | $this->connect_ldap(false); |
---|
[151] | 20 | session_write_close(); |
---|
[20] | 21 | } |
---|
| 22 | |
---|
| 23 | function __destruct() |
---|
| 24 | { |
---|
| 25 | ldap_close($this->conn); |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | function connect_ldap($refer) |
---|
| 29 | { |
---|
| 30 | $this->conn = ldap_connect($this->ldap_host); |
---|
| 31 | ldap_set_option($this->conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 32 | ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $refer); |
---|
| 33 | if(trim($this->user) != "") |
---|
[32] | 34 | @ldap_bind($this->conn,$this->user,$this->password); |
---|
[20] | 35 | else |
---|
[32] | 36 | @ldap_bind($this->conn); |
---|
[20] | 37 | } |
---|
| 38 | |
---|
[151] | 39 | function get_photo_ldap($pUser,$getPhoto) |
---|
[20] | 40 | { |
---|
[151] | 41 | $user = ( $pUser == "im_avatar" ) ? $this->jid : $pUser ; |
---|
[55] | 42 | |
---|
[151] | 43 | if ($this->conn) |
---|
| 44 | { |
---|
[33] | 45 | $filter="(&(uid=".$user.")(phpgwAccountType=u))"; |
---|
[20] | 46 | $justthese = array("jpegphoto"); |
---|
[151] | 47 | $search = @ldap_search($this->conn,$this->ldap_context, $filter, $justthese); |
---|
| 48 | $entry = @ldap_first_entry($this->conn, $search); |
---|
[33] | 49 | $jpeg_data = @ldap_get_values_len($this->conn, $entry, "jpegphoto"); |
---|
| 50 | |
---|
[151] | 51 | if( count($jpeg_data) > 1) |
---|
| 52 | { |
---|
[20] | 53 | $photo = imagecreatefromstring($jpeg_data[0]); |
---|
[151] | 54 | if($photo) |
---|
| 55 | { |
---|
| 56 | if($getPhoto) |
---|
| 57 | { |
---|
[20] | 58 | header("Content-Type: image/jpeg"); |
---|
| 59 | $width = imagesx($photo); |
---|
| 60 | $height = imagesy($photo); |
---|
| 61 | $twidth = 49; |
---|
| 62 | $theight = 65; |
---|
| 63 | $small_photo = imagecreatetruecolor ($twidth, $theight); |
---|
| 64 | imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height); |
---|
| 65 | imagejpeg($small_photo,'',100); |
---|
| 66 | return; |
---|
| 67 | }else{ |
---|
[151] | 68 | return "true"; |
---|
[20] | 69 | } |
---|
| 70 | }else{ |
---|
[151] | 71 | return "false"; |
---|
[20] | 72 | } |
---|
| 73 | }else{ |
---|
[151] | 74 | return "false"; |
---|
[20] | 75 | } |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | function photo_ldap($user) |
---|
| 80 | { |
---|
[151] | 81 | $uid = ( $user['uid'] == "im_avatar" ) ? $this->jid : $user['uid'] ; |
---|
[55] | 82 | return $this->get_photo_ldap($uid,false); |
---|
[20] | 83 | } |
---|
| 84 | |
---|
[33] | 85 | function list_users_ldap($search) |
---|
[20] | 86 | { |
---|
[68] | 87 | |
---|
[33] | 88 | if($this->conn){ |
---|
| 89 | $filter = "(&(".$search.")(phpgwAccountType=u))"; |
---|
| 90 | $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn"); |
---|
| 91 | $search = ldap_search($this->conn,$this->ldap_context,$filter,$justthese); |
---|
[32] | 92 | $entry = ldap_get_entries($this->conn,$search); |
---|
[20] | 93 | } |
---|
[33] | 94 | |
---|
[32] | 95 | if( $entry['count'] > 0){ |
---|
| 96 | $i = 0; |
---|
[33] | 97 | $result_user = array(); |
---|
[32] | 98 | foreach($entry as $tmp) |
---|
| 99 | { |
---|
[33] | 100 | if($tmp['uidnumber'][0] != "" && $tmp['phpgwaccountvisible'][0] != "-1"){ |
---|
[32] | 101 | $result_user[$i]['uidnumber'] = $tmp['uidnumber'][0]; |
---|
| 102 | $result_user[$i]['mail'] = $tmp['mail'][0]; |
---|
| 103 | $result_user[$i]['uid'] = $tmp['uid'][0]; |
---|
| 104 | $result_user[$i]['cn'] = $tmp['cn'][0]; |
---|
[33] | 105 | $ou = explode("dc=",$tmp['dn']); |
---|
| 106 | $ou = explode("ou=",$ou[0]); |
---|
| 107 | $ou = array_pop($ou); |
---|
| 108 | $result_user[$i]['dn'] = strtoupper(substr($ou,0,strlen($ou)-1)); |
---|
[32] | 109 | $i++; |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | return $result_user; |
---|
[20] | 113 | } |
---|
[32] | 114 | return 0; |
---|
[20] | 115 | } |
---|
| 116 | |
---|
[33] | 117 | function list_groups_ldap($search) |
---|
[20] | 118 | { |
---|
[41] | 119 | |
---|
[32] | 120 | if( $this->conn ){ |
---|
[41] | 121 | $filter = "(&(".$search.")(objectClass=posixGroup))"; |
---|
[32] | 122 | $justthese = array("gidnumber","cn","memberuid"); |
---|
| 123 | $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese); |
---|
| 124 | $entry = ldap_get_entries($this->conn,$search); |
---|
| 125 | } |
---|
[41] | 126 | |
---|
[33] | 127 | if($entry['count'] > 0){ |
---|
[32] | 128 | $i = 0; |
---|
[33] | 129 | $result_groups = array(); |
---|
| 130 | foreach($entry as $tmpg){ |
---|
| 131 | if($tmpg['gidnumber'] != ""){ |
---|
[41] | 132 | if(array_key_exists("memberuid", $tmpg)){ |
---|
| 133 | $result_groups[$i]['gidnumber'] = $tmpg['gidnumber'][0]; |
---|
| 134 | @array_shift($tmpg['memberuid']); |
---|
| 135 | foreach($tmpg['memberuid'] as $tmp) |
---|
| 136 | $result_groups[$i]['members'][] = $tmp; |
---|
| 137 | $i++; |
---|
| 138 | } |
---|
[32] | 139 | } |
---|
[33] | 140 | } |
---|
[41] | 141 | } |
---|
| 142 | |
---|
| 143 | if(count($result_groups) > 0 ){ |
---|
[32] | 144 | return $result_groups; |
---|
[41] | 145 | }else{ |
---|
| 146 | return 0; |
---|
[20] | 147 | } |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | function list_organizations_ldap() |
---|
| 151 | { |
---|
[151] | 152 | $result_org = "<organizations><ou></ou>"; |
---|
| 153 | |
---|
| 154 | if ($this->conn) |
---|
| 155 | { |
---|
[20] | 156 | $filter="ou=*"; |
---|
| 157 | $justthese = array("ou"); |
---|
| 158 | $search = ldap_list($this->conn,$this->ldap_context, $filter, $justthese); |
---|
| 159 | $entry = ldap_get_entries($this->conn, $search); |
---|
| 160 | } |
---|
| 161 | |
---|
[151] | 162 | foreach($entry as $tmp) |
---|
| 163 | if($tmp['ou'][0] != "") |
---|
| 164 | $result_org .= "<ou>" . $tmp['ou'][0] . "</ou>"; |
---|
| 165 | |
---|
| 166 | $result_org .= "</organizations>"; |
---|
| 167 | |
---|
[20] | 168 | return $result_org; |
---|
| 169 | } |
---|
| 170 | |
---|
[27] | 171 | function info_user($user) |
---|
| 172 | { |
---|
[33] | 173 | $uid = "uid=".$user['uid']; |
---|
[27] | 174 | $i= 0; |
---|
| 175 | |
---|
[33] | 176 | $entry = $this->list_users_ldap($uid); |
---|
[27] | 177 | |
---|
[33] | 178 | if( count($entry) > 0 ) |
---|
[32] | 179 | return $entry; |
---|
[33] | 180 | else |
---|
[32] | 181 | return false; |
---|
[27] | 182 | } |
---|
[20] | 183 | } |
---|
| 184 | |
---|
[151] | 185 | if(trim($_REQUEST['user']) != "") |
---|
| 186 | { |
---|
[20] | 187 | $obj_img = new ldap_im(); |
---|
| 188 | $obj_img->get_photo_ldap($_REQUEST['user'],true); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | ?> |
---|