[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 | |
---|
[946] | 13 | class webService |
---|
[417] | 14 | { |
---|
[946] | 15 | private $conn; |
---|
| 16 | private $contextLdap; |
---|
| 17 | private $userDn; |
---|
| 18 | private $jabberName; |
---|
[417] | 19 | private $passwd; |
---|
[946] | 20 | private $photo_user = array(); |
---|
[417] | 21 | private $refer; |
---|
[946] | 22 | private $serverLdap; |
---|
| 23 | |
---|
[417] | 24 | function __construct() |
---|
[382] | 25 | { |
---|
[946] | 26 | require_once('confLDAPInternal.php'); |
---|
| 27 | $handle = unserialize(base64_decode($LDAP_INTERNAL)); |
---|
[551] | 28 | |
---|
[946] | 29 | $this->jabberName = $handle['jabberName']; |
---|
| 30 | $this->serverLdap = $handle['serverLdap']; |
---|
| 31 | $this->contextLdap = $handle['contextLdap']; |
---|
| 32 | $this->userDn = $handle['user']; |
---|
| 33 | $this->passwd = $handle['password']; |
---|
[417] | 34 | |
---|
[551] | 35 | $this->refer = true; |
---|
[417] | 36 | $this->version3 = true; |
---|
| 37 | } |
---|
[946] | 38 | |
---|
[417] | 39 | private final function ldapConnect() |
---|
| 40 | { |
---|
| 41 | if(!function_exists('ldap_connect')) |
---|
| 42 | return False; |
---|
| 43 | |
---|
[946] | 44 | if(!$this->conn = ldap_connect($this->serverLdap)) |
---|
[417] | 45 | return False; |
---|
[551] | 46 | |
---|
[417] | 47 | if( $this->version3 ) |
---|
| 48 | if( !ldap_set_option($this->conn,LDAP_OPT_PROTOCOL_VERSION,3) ) |
---|
| 49 | $this->version = false; |
---|
[946] | 50 | |
---|
[417] | 51 | ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $this->refer); |
---|
[551] | 52 | |
---|
[946] | 53 | // Bind as Admin |
---|
| 54 | if($this->userDn && $this->passwd && !ldap_bind($this->conn, $this->userDn, $this->passwd)) |
---|
| 55 | return False; |
---|
[417] | 56 | |
---|
[946] | 57 | // Bind as Anonymous |
---|
| 58 | if(!$this->userDn && !$this->passwd && !@ldap_bind($this->conn)) |
---|
[417] | 59 | return False; |
---|
[946] | 60 | } |
---|
[551] | 61 | |
---|
[946] | 62 | private final function ldapConnectExternal($pHostJabber) |
---|
| 63 | { |
---|
| 64 | require_once('confLDAPExternal.php'); |
---|
| 65 | $handle = unserialize(base64_decode($LDAP_EXTERNAL)); |
---|
| 66 | |
---|
| 67 | foreach($handle as $itens) |
---|
| 68 | if(trim($pHostJabber) == $itens['jabberName']) |
---|
| 69 | { |
---|
| 70 | $this->jabberName = $itens['jabberName']; |
---|
| 71 | $this->serverLdap = $itens['serverLdap']; |
---|
| 72 | $this->contextLdap = $itens['contextLdap']; |
---|
| 73 | $this->userDn = $itens['user']; |
---|
| 74 | $this->passwd = $itens['password']; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | $this->refer = true; |
---|
| 78 | $this->version3 = true; |
---|
| 79 | |
---|
| 80 | $this->ldapConnect(); |
---|
[417] | 81 | } |
---|
| 82 | |
---|
[946] | 83 | public final function getNameOrganization($pJid, $pCharset) |
---|
[551] | 84 | { |
---|
[946] | 85 | $uid = substr($pJid, 0, strpos($pJid,"@")); |
---|
[551] | 86 | |
---|
[946] | 87 | if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 ))) |
---|
[551] | 88 | { |
---|
[946] | 89 | $this->ldapConnect(); |
---|
| 90 | |
---|
| 91 | if( $this->conn ) |
---|
| 92 | { |
---|
| 93 | $filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))"; |
---|
| 94 | $justthese = array("uid","cn","dn"); |
---|
| 95 | $search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese); |
---|
| 96 | $entry = ldap_get_entries($this->conn,$search); |
---|
| 97 | $cn = $entry[0]['cn'][0]; |
---|
| 98 | $ou = explode("dc=", $entry[0]['dn']); |
---|
| 99 | $ou = explode("ou=",$ou[0]); |
---|
| 100 | $ou = array_pop($ou); |
---|
| 101 | $dn = strtoupper(substr($ou,0,strlen($ou)-1)); |
---|
| 102 | |
---|
| 103 | $return = utf8_encode("Nome : " . $cn . ";Organização : " . $dn); |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | else |
---|
| 107 | { |
---|
| 108 | $this->ldapConnectExternal(substr($pJid, strpos($pJid, "@") + 1 )); |
---|
[551] | 109 | |
---|
[946] | 110 | if( $this->conn ) |
---|
| 111 | { |
---|
| 112 | $filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))"; |
---|
| 113 | $justthese = array("uid","cn","dn"); |
---|
| 114 | $search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese); |
---|
| 115 | $entry = ldap_get_entries($this->conn,$search); |
---|
| 116 | $cn = $entry[0]['cn'][0]; |
---|
| 117 | $ou = explode("dc=", $entry[0]['dn']); |
---|
| 118 | $ou = explode("ou=",$ou[0]); |
---|
| 119 | $ou = array_pop($ou); |
---|
| 120 | $dn = strtoupper(substr($ou,0,strlen($ou)-1)); |
---|
| 121 | |
---|
| 122 | $return = utf8_encode("Nome : " . $cn . ";Organização : " . $dn); |
---|
| 123 | } |
---|
| 124 | } |
---|
[551] | 125 | |
---|
[946] | 126 | if( $pCharset === "1" ) |
---|
| 127 | return $return; |
---|
| 128 | else |
---|
| 129 | return mb_convert_encoding($return, "ISO-8859-1", "UTF-8"); |
---|
[551] | 130 | |
---|
[946] | 131 | $return = utf8_encode("Nome : Não Identificado ;Organização : Não Identificado"); |
---|
[551] | 132 | |
---|
[946] | 133 | if( $pCharset === 1 ) |
---|
| 134 | return $return; |
---|
| 135 | else |
---|
| 136 | return mb_convert_encoding($return, "ISO-8859-1", "UTF-8"); |
---|
| 137 | |
---|
[551] | 138 | } |
---|
| 139 | |
---|
[946] | 140 | public final function getPhotoLdap($pJid) |
---|
[417] | 141 | { |
---|
[946] | 142 | $uid = substr($pJid, 0, strpos($pJid,"@")); |
---|
[948] | 143 | |
---|
[946] | 144 | if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 ))) |
---|
[417] | 145 | { |
---|
[946] | 146 | $this->ldapConnect(); |
---|
| 147 | |
---|
| 148 | if( $this->conn ) |
---|
[417] | 149 | { |
---|
[946] | 150 | $filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))"; |
---|
| 151 | $justthese = array("uid","jpegPhoto"); |
---|
[948] | 152 | |
---|
[946] | 153 | $search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese); |
---|
| 154 | $entry1 = ldap_get_entries($this->conn,$search); |
---|
| 155 | $entry = ldap_first_entry( $this->conn, $search ); |
---|
| 156 | if( $entry1['count'] > 0 ) |
---|
| 157 | { |
---|
| 158 | $i = 0; |
---|
| 159 | $photo = ""; |
---|
| 160 | $return_photo = ""; |
---|
| 161 | $photo = @ldap_get_values_len($this->conn, $entry, 'jpegphoto'); |
---|
| 162 | |
---|
| 163 | if ($photo) |
---|
| 164 | $return_photo = $photo[0]; |
---|
| 165 | return $return_photo; |
---|
| 166 | } |
---|
[417] | 167 | } |
---|
| 168 | } |
---|
[946] | 169 | else |
---|
[948] | 170 | { |
---|
[946] | 171 | $jabberName = substr($pJid, strpos($pJid, "@") + 1 ); |
---|
| 172 | |
---|
| 173 | if( strpos($jabberName, "/") ) |
---|
| 174 | $jabberName = substr($jabberName, 0, strpos($jabberName, "/")); |
---|
[948] | 175 | |
---|
[946] | 176 | $this->ldapConnectExternal($jabberName); |
---|
| 177 | |
---|
| 178 | if( $this->conn ) |
---|
| 179 | { |
---|
| 180 | $filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))"; |
---|
| 181 | $justthese = array("uid","jpegPhoto"); |
---|
| 182 | $search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese); |
---|
| 183 | $entry1 = ldap_get_entries($this->conn,$search); |
---|
| 184 | $entry = ldap_first_entry( $this->conn, $search ); |
---|
| 185 | if( $entry1['count'] > 0 ) |
---|
| 186 | { |
---|
| 187 | $i = 0; |
---|
| 188 | $photo = ""; |
---|
| 189 | $return_photo = ""; |
---|
| 190 | $photo = @ldap_get_values_len($this->conn, $entry, 'jpegphoto'); |
---|
| 191 | if ($photo) |
---|
| 192 | $return_photo = $photo[0]; |
---|
| 193 | return $return_photo; |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | } |
---|
| 197 | |
---|
[417] | 198 | return false; |
---|
| 199 | } |
---|
| 200 | |
---|
[946] | 201 | public final function getPhotoSession($pUid, $pOu) |
---|
[417] | 202 | { |
---|
[946] | 203 | $uid = $pUid; |
---|
| 204 | if( strpos($pUid, "@") ) |
---|
| 205 | $uid = substr($pUid, 0, strpos($pUid, "@")); |
---|
| 206 | |
---|
| 207 | if( isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]) ) |
---|
[382] | 208 | { |
---|
[946] | 209 | $photo = imagecreatefromstring($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]); |
---|
| 210 | |
---|
[382] | 211 | header("Content-Type: image/jpeg"); |
---|
| 212 | $width = imagesx($photo); |
---|
| 213 | $height = imagesy($photo); |
---|
| 214 | $twidth = 60; |
---|
| 215 | $theight = 80; |
---|
| 216 | $small_photo = imagecreatetruecolor ($twidth, $theight); |
---|
| 217 | imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height); |
---|
| 218 | imagejpeg($small_photo,'',100); |
---|
[946] | 219 | |
---|
| 220 | unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]); |
---|
| 221 | |
---|
[382] | 222 | return; |
---|
| 223 | } |
---|
| 224 | } |
---|
[417] | 225 | } |
---|
[382] | 226 | |
---|
[946] | 227 | if(trim($_REQUEST['javaPhoto']) != "" ) |
---|
[417] | 228 | { |
---|
[946] | 229 | $obj = new webService(); |
---|
| 230 | $jid = $_REQUEST['javaPhoto']; |
---|
[948] | 231 | $jid = strpos($jid, "/") ? substr($jid, 0, strpos($jid, "/")) : $jid; |
---|
[417] | 232 | |
---|
[946] | 233 | $photo = $obj->getPhotoLdap($jid); |
---|
| 234 | $photoWidth = 70; |
---|
| 235 | $photoHeight = 90; |
---|
| 236 | $newImage = imagecreatetruecolor($photoWidth,$photoHeight); |
---|
| 237 | |
---|
| 238 | if( $photo ) |
---|
[382] | 239 | { |
---|
[946] | 240 | $photo = imagecreatefromstring($photo); |
---|
| 241 | imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo)); |
---|
[382] | 242 | } |
---|
[417] | 243 | else |
---|
| 244 | { |
---|
[946] | 245 | $photo = @imagecreatefrompng("../templates/default/images/photo.png"); |
---|
| 246 | imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo)); |
---|
[417] | 247 | } |
---|
[946] | 248 | |
---|
| 249 | ob_start(); |
---|
| 250 | imagepng($newImage); |
---|
| 251 | $imagePhoto = ob_get_contents(); |
---|
| 252 | imagedestroy($newImage); |
---|
| 253 | ob_end_clean(); |
---|
| 254 | printf("%s",base64_encode($imagePhoto)); |
---|
| 255 | |
---|
[417] | 256 | } |
---|
[382] | 257 | |
---|
[551] | 258 | if(trim($_POST['jid']) != "") |
---|
| 259 | { |
---|
| 260 | $jid = trim($_POST['jid']); |
---|
| 261 | $charset = trim($_POST['charset']); |
---|
[946] | 262 | $obj = new webService(); |
---|
[551] | 263 | |
---|
[946] | 264 | printf("%s",$obj->getNameOrganization($jid, $charset)); |
---|
[551] | 265 | } |
---|
[946] | 266 | |
---|
| 267 | if(trim($_REQUEST['phpPhoto']) != "") |
---|
| 268 | { |
---|
| 269 | $obj = new webservice(); |
---|
| 270 | $ou = $_REQUEST['phpOu']; |
---|
| 271 | $jid = $_REQUEST['phpPhoto']; |
---|
| 272 | |
---|
| 273 | $obj->getPhotoSession($jid, $ou); |
---|
| 274 | } |
---|
| 275 | |
---|
[439] | 276 | ?> |
---|