[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 | |
---|
[551] | 13 | function ldap_rebind($ldap_connection, $ldap_url){ |
---|
| 14 | include('conf_Ldap_Photos.php'); |
---|
| 15 | $handle = unserialize(base64_decode($CONF_SERVER)); |
---|
| 16 | @ldap_bind($ldap_connection, $handle['dn'],$handle['passwd']); |
---|
| 17 | } |
---|
| 18 | |
---|
[417] | 19 | class ldapPhoto |
---|
| 20 | { |
---|
| 21 | private $host; |
---|
| 22 | private $dn; |
---|
| 23 | private $passwd; |
---|
| 24 | private $refer; |
---|
| 25 | private $user_referral; |
---|
| 26 | private $password_referral; |
---|
| 27 | private $conn; |
---|
| 28 | private $context; |
---|
| 29 | private $photo_user = array(); |
---|
[439] | 30 | private $handle; |
---|
[417] | 31 | |
---|
[439] | 32 | |
---|
[417] | 33 | function __construct() |
---|
[382] | 34 | { |
---|
[439] | 35 | require_once('conf_Ldap_Photos.php'); |
---|
[551] | 36 | $handle = unserialize(base64_decode($CONF_SERVER)); |
---|
| 37 | |
---|
| 38 | $this->host = $handle['host']; |
---|
| 39 | $this->context = $handle['context']; |
---|
| 40 | $this->dn = $handle['dn']; |
---|
| 41 | $this->passwd = $handle['passwd']; |
---|
[417] | 42 | |
---|
[551] | 43 | $this->refer = true; |
---|
[417] | 44 | $this->version3 = true; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | private final function ldapConnect() |
---|
| 49 | { |
---|
| 50 | if(!function_exists('ldap_connect')) |
---|
| 51 | { |
---|
| 52 | printf("<b>Erro : Ldap Não suportado %s</b><br>" , $this->host); |
---|
| 53 | return False; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | if(!$this->conn = ldap_connect($this->host)) |
---|
| 57 | { |
---|
| 58 | printf("<b>Erro: não pode conectar no servidor ldap %s!</b><br>", $this->host); |
---|
| 59 | return False; |
---|
| 60 | } |
---|
[551] | 61 | |
---|
[417] | 62 | if( $this->version3 ) |
---|
| 63 | { |
---|
| 64 | if( !ldap_set_option($this->conn,LDAP_OPT_PROTOCOL_VERSION,3) ) |
---|
| 65 | $this->version = false; |
---|
| 66 | } |
---|
| 67 | ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $this->refer); |
---|
[551] | 68 | |
---|
[417] | 69 | // verifica refer |
---|
| 70 | if( $this->refer ) |
---|
| 71 | { |
---|
[551] | 72 | @ldap_set_rebind_proc($this->conn, ldap_rebind); |
---|
[417] | 73 | } |
---|
| 74 | |
---|
| 75 | // bind as admin |
---|
| 76 | if($this->dn && $this->passwd && !ldap_bind($this->conn, $this->dn, $this->passwd)){ |
---|
| 77 | echo "<center><b>ExpressoLivre indisponível no momento</b></center>"; |
---|
| 78 | return False; |
---|
| 79 | } |
---|
[551] | 80 | |
---|
[417] | 81 | // bind as anonymous |
---|
| 82 | if(!$this->dn && !$this->passwd && !@ldap_bind($this->conn)) |
---|
| 83 | { |
---|
| 84 | echo "<center><b>ExpressoLivre indisponível no momento</b></center>"; |
---|
| 85 | return False; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
[551] | 89 | public final function getNameOrganization($pUid, $pCharset) |
---|
| 90 | { |
---|
| 91 | $this->ldapConnect(); |
---|
| 92 | |
---|
| 93 | if( $this->conn ) |
---|
| 94 | { |
---|
| 95 | $filter = "(&(phpgwaccounttype=u)(uid=".$pUid.")(!(phpgwaccountvisible=-1)))"; |
---|
| 96 | $justthese = array("uid","cn","dn"); |
---|
| 97 | $search = ldap_search($this->conn,$this->context,$filter,$justthese); |
---|
| 98 | $entry = ldap_get_entries($this->conn,$search); |
---|
| 99 | $cn = $entry[0]['cn'][0]; |
---|
| 100 | $ou = explode("dc=", $entry[0]['dn']); |
---|
| 101 | $ou = explode("ou=",$ou[0]); |
---|
| 102 | $ou = array_pop($ou); |
---|
| 103 | $dn = strtoupper(substr($ou,0,strlen($ou)-1)); |
---|
| 104 | |
---|
| 105 | $return = utf8_encode("Nome : " . $cn . ";Organização : " . $dn); |
---|
| 106 | |
---|
| 107 | if( $pCharset === "1" ) |
---|
| 108 | return $return; |
---|
| 109 | else |
---|
| 110 | return mb_convert_encoding($return, "ISO-8859-1", "UTF-8"); |
---|
| 111 | |
---|
| 112 | $return = utf8_encode("Nome : Não Identificado ;Organização : Não Identificado"); |
---|
| 113 | |
---|
| 114 | if( $pCharset === 1 ) |
---|
| 115 | return $return; |
---|
| 116 | else |
---|
| 117 | return mb_convert_encoding($return, "ISO-8859-1", "UTF-8"); |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | |
---|
[417] | 121 | public final function getPhotoLdap($uid) |
---|
| 122 | { |
---|
| 123 | $this->ldapConnect(); |
---|
| 124 | if( $this->conn ) |
---|
| 125 | { |
---|
[551] | 126 | $filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))"; |
---|
| 127 | $justthese = array("uid","jpegPhoto"); |
---|
[417] | 128 | $search = ldap_search($this->conn,$this->context,$filter,$justthese); |
---|
| 129 | $entry1 = ldap_get_entries($this->conn,$search); |
---|
| 130 | $entry = ldap_first_entry( $this->conn, $search ); |
---|
| 131 | if( $entry1['count'] > 0 ) |
---|
| 132 | { |
---|
| 133 | $i = 0; |
---|
| 134 | $photo = ""; |
---|
| 135 | $return_photo = ""; |
---|
[551] | 136 | $photo = @ldap_get_values_len($this->conn, $entry, 'jpegphoto'); |
---|
| 137 | if ($photo) |
---|
| 138 | $return_photo = $photo[0]; |
---|
[417] | 139 | return $return_photo; |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | return false; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | public final function getPhotoSession($pUid) |
---|
| 146 | { |
---|
[382] | 147 | if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pUid])) |
---|
| 148 | { |
---|
| 149 | $photo = imagecreatefromstring($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pUid]); |
---|
| 150 | |
---|
| 151 | header("Content-Type: image/jpeg"); |
---|
| 152 | $width = imagesx($photo); |
---|
| 153 | $height = imagesy($photo); |
---|
| 154 | $twidth = 60; |
---|
| 155 | $theight = 80; |
---|
| 156 | $small_photo = imagecreatetruecolor ($twidth, $theight); |
---|
| 157 | imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height); |
---|
| 158 | imagejpeg($small_photo,'',100); |
---|
| 159 | |
---|
| 160 | unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pUid]); |
---|
| 161 | return; |
---|
| 162 | } |
---|
| 163 | } |
---|
[417] | 164 | } |
---|
[382] | 165 | |
---|
[417] | 166 | if(trim($_REQUEST['uid']) != "") |
---|
| 167 | { |
---|
| 168 | $uid = trim($_REQUEST['uid']); |
---|
| 169 | $a = new ldapPhoto(); |
---|
| 170 | |
---|
| 171 | if( strpos($uid,"@")) |
---|
[382] | 172 | { |
---|
[417] | 173 | $uid = substr($uid, 0, strpos($uid,"@")); |
---|
| 174 | $photo = $a->getPhotoLdap($uid); |
---|
| 175 | $photoWidth = 70; |
---|
| 176 | $photoHeight = 90; |
---|
| 177 | $newImage = imagecreatetruecolor($photoWidth,$photoHeight); |
---|
[697] | 178 | |
---|
[417] | 179 | if($photo) |
---|
| 180 | { |
---|
| 181 | $photo = imagecreatefromstring($photo); |
---|
| 182 | imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo)); |
---|
| 183 | } |
---|
| 184 | else |
---|
| 185 | { |
---|
[494] | 186 | $photo = @imagecreatefrompng("../templates/default/images/photo.png"); |
---|
[417] | 187 | imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo)); |
---|
| 188 | } |
---|
[697] | 189 | |
---|
| 190 | ob_start(); |
---|
| 191 | imagepng($newImage); |
---|
| 192 | $imagePhoto = ob_get_contents(); |
---|
| 193 | imagedestroy($newImage); |
---|
| 194 | ob_end_clean(); |
---|
| 195 | printf("%s",base64_encode($imagePhoto)); |
---|
[382] | 196 | } |
---|
[417] | 197 | else |
---|
| 198 | { |
---|
| 199 | $a->getPhotoSession($uid); |
---|
| 200 | } |
---|
| 201 | } |
---|
[382] | 202 | |
---|
[551] | 203 | if(trim($_POST['jid']) != "") |
---|
| 204 | { |
---|
| 205 | $jid = trim($_POST['jid']); |
---|
| 206 | if( strpos($jid,"@")) |
---|
| 207 | $jid = substr($jid, 0, strpos($jid,"@")); |
---|
| 208 | $charset = trim($_POST['charset']); |
---|
| 209 | $a = new ldapPhoto(); |
---|
| 210 | |
---|
| 211 | printf("%s",$a->getNameOrganization($jid, $charset)); |
---|
| 212 | } |
---|
[439] | 213 | ?> |
---|