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