[3102] | 1 | <?php |
---|
| 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 | \***************************************************************************/ |
---|
| 12 | |
---|
| 13 | class webService |
---|
| 14 | { |
---|
| 15 | private $attribute; |
---|
| 16 | private $conn; |
---|
| 17 | private $contextLdap; |
---|
| 18 | private $userLDAP; |
---|
| 19 | private $jabberName = null; |
---|
| 20 | private $passwd; |
---|
| 21 | private $photo_user = array(); |
---|
| 22 | private $refer; |
---|
| 23 | private $serverLdap; |
---|
| 24 | private $fileLdapInternal = false; |
---|
| 25 | private $fileLdapExternal = false; |
---|
| 26 | private $version3; |
---|
| 27 | |
---|
| 28 | function __construct() |
---|
| 29 | { |
---|
| 30 | if ( file_exists('confLDAPInternal.php') ) |
---|
| 31 | { |
---|
| 32 | require_once('confLDAPInternal.php'); |
---|
| 33 | $handle = unserialize(base64_decode($LDAP_INTERNAL)); |
---|
| 34 | |
---|
| 35 | $this->jabberName = $handle['jabberName']; |
---|
| 36 | $this->serverLdap = $handle['serverLdap']; |
---|
| 37 | $this->contextLdap = $handle['contextLdap']; |
---|
| 38 | $this->userLDAP = $handle['user']; |
---|
| 39 | $this->passwd = $handle['password']; |
---|
| 40 | |
---|
| 41 | $this->refer = true; |
---|
| 42 | $this->version3 = true; |
---|
| 43 | |
---|
| 44 | $this->fileLdapInternal = true; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | $this->attribute = "uid"; |
---|
| 48 | |
---|
| 49 | if ( file_exists('attributeLdap.php') ) |
---|
| 50 | { |
---|
| 51 | require_once('attributeLdap.php'); |
---|
| 52 | $this->attribute = trim($attributeTypeName); |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | private final function ldapConnect() |
---|
| 57 | { |
---|
| 58 | if(!function_exists('ldap_connect')) |
---|
| 59 | return False; |
---|
| 60 | |
---|
| 61 | if(!$this->conn = ldap_connect($this->serverLdap)) |
---|
| 62 | return False; |
---|
| 63 | |
---|
| 64 | if( $this->version3 ) |
---|
| 65 | if( !ldap_set_option($this->conn,LDAP_OPT_PROTOCOL_VERSION,3) ) |
---|
| 66 | $this->version3 = false; |
---|
| 67 | |
---|
| 68 | ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $this->refer); |
---|
| 69 | |
---|
| 70 | // Bind as Admin |
---|
| 71 | if( $this->userLDAP && $this->passwd && !ldap_bind($this->conn, $this->userLDAP . "," . $this->contextLdap, $this->passwd) ) |
---|
| 72 | return False; |
---|
| 73 | |
---|
| 74 | // Bind as Anonymous |
---|
| 75 | if( !$this->userLDAP && !$this->passwd && !@ldap_bind($this->conn) ) |
---|
| 76 | return False; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | private final function ldapConnectExternal($pHostJabber) |
---|
| 80 | { |
---|
| 81 | if( file_exists('confLDAPExternal.php')) |
---|
| 82 | { |
---|
| 83 | require_once('confLDAPExternal.php'); |
---|
| 84 | $handle = unserialize(base64_decode($LDAP_EXTERNAL)); |
---|
| 85 | foreach($handle as $itens) |
---|
| 86 | { |
---|
| 87 | if(trim($pHostJabber) == $itens['jabberName']) |
---|
| 88 | { |
---|
| 89 | $this->jabberName = $itens['jabberName']; |
---|
| 90 | $this->serverLdap = $itens['serverLdap']; |
---|
| 91 | $this->contextLdap = $itens['contextLdap']; |
---|
| 92 | $this->userLDAP = $itens['user']; |
---|
| 93 | $this->passwd = $itens['password']; |
---|
| 94 | |
---|
| 95 | $this->fileLdapExternal = true; |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | $this->refer = true; |
---|
| 100 | $this->version3 = true; |
---|
| 101 | |
---|
| 102 | $this->ldapConnect(); |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | public final function CallVoipConnect($pVoipFrom, $pVoipTo) |
---|
| 107 | { |
---|
| 108 | $this->ldapConnect(); |
---|
| 109 | |
---|
| 110 | if( $this->conn ) |
---|
| 111 | { |
---|
| 112 | $filter = "(|(&(phpgwaccounttype=u)(uid=".$pVoipFrom."))(&(phpgwaccounttype=u)(uid=".$pVoipTo.")))"; |
---|
| 113 | $justthese = array("telephoneNumber", "uid"); |
---|
| 114 | $search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese); |
---|
| 115 | $entry = ldap_get_entries($this->conn,$search); |
---|
| 116 | |
---|
| 117 | $fromNumber = $entry[0]['telephonenumber'][0]; |
---|
| 118 | $toNumber = $entry[1]['telephonenumber'][0]; |
---|
| 119 | |
---|
| 120 | if ( trim($entry[0]['uid'][0]) !== trim($pVoipFrom) ) |
---|
| 121 | { |
---|
| 122 | $fromNumber = $entry[1]['telephonenumber'][0]; |
---|
| 123 | $toNumber = $entry[0]['telephonenumber'][0]; |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | if( $fromNumber && $toNumber ) |
---|
| 128 | { |
---|
| 129 | $voipServer = "www.pabx.celepar.parana"; |
---|
| 130 | $voipUrl = "/telefoniaip/servicos/voip.php"; |
---|
| 131 | $voipPort = "80"; |
---|
| 132 | |
---|
| 133 | if( !$voipServer || !$voipUrl || !$voipPort ) |
---|
| 134 | return false; |
---|
| 135 | |
---|
| 136 | $url = "http://".$voipServer.":".$voipPort.$voipUrl."?magic=1333&acao=liga&ramal=".$fromNumber."&numero=".$toNumber; |
---|
| 137 | $sMethod = 'GET '; |
---|
| 138 | $crlf = "\r\n"; |
---|
| 139 | $sRequest = " HTTP/1.1" . $crlf; |
---|
| 140 | $sRequest .= "Host: localhost" . $crlf; |
---|
| 141 | $sRequest .= "Accept: */* " . $crlf; |
---|
| 142 | $sRequest .= "Connection: Close" . $crlf . $crlf; |
---|
| 143 | $sRequest = $sMethod . $url . $sRequest; |
---|
| 144 | $sockHttp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); |
---|
| 145 | |
---|
| 146 | if ( !$sockHttp ) |
---|
| 147 | return false; |
---|
| 148 | |
---|
| 149 | $resSocketConnect = socket_connect($sockHttp, $voipServer, $voipPort); |
---|
| 150 | |
---|
| 151 | if ( !$resSocketConnect ) |
---|
| 152 | return false; |
---|
| 153 | |
---|
| 154 | $resSocketWrite = socket_write($sockHttp, $sRequest, strlen($sRequest)); |
---|
| 155 | |
---|
| 156 | if ( !$resSocketWrite ) |
---|
| 157 | return false; |
---|
| 158 | |
---|
| 159 | $sResponse = ''; |
---|
| 160 | |
---|
| 161 | while ($sRead = socket_read($sockHttp, 512)) |
---|
| 162 | { |
---|
| 163 | $sResponse .= $sRead; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | socket_close($sockHttp); |
---|
| 167 | |
---|
| 168 | $pos = strpos($sResponse, $crlf . $crlf); |
---|
| 169 | |
---|
| 170 | return substr($sResponse, $pos + 2 * strlen($crlf)); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | return "ERRO"; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | public final function getNameOrganization($pJid, $pCharset) |
---|
| 178 | { |
---|
| 179 | $uid = substr($pJid, 0, strpos($pJid,"@")); |
---|
| 180 | $return = utf8_encode("Nome : Não Identificado ;Organização : Não Identificado"); |
---|
| 181 | |
---|
| 182 | if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 ))) |
---|
| 183 | { |
---|
| 184 | $this->ldapConnect(); |
---|
| 185 | |
---|
| 186 | if( $this->fileLdapInternal ) |
---|
| 187 | { |
---|
| 188 | if( $this->conn ) |
---|
| 189 | { |
---|
| 190 | $filter = "(&(phpgwaccounttype=u)(".$this->attribute."=".$uid.")(!(phpgwaccountvisible=-1)))"; |
---|
| 191 | $justthese = array($this->attribute,"cn","dn"); |
---|
| 192 | $search = ldap_search( $this->conn, $this->contextLdap, $filter,$justthese); |
---|
| 193 | $get_entries = ldap_get_entries( $this->conn, $search); |
---|
| 194 | |
---|
| 195 | if( $get_entries['count'] > 0 ) |
---|
| 196 | { |
---|
| 197 | $cn = $get_entries[0]['cn'][0]; |
---|
| 198 | $ou = explode("dc=", $get_entries[0]['dn']); |
---|
| 199 | $ou = explode("ou=",$ou[0]); |
---|
| 200 | $ou = array_pop($ou); |
---|
| 201 | $dn = strtoupper(substr($ou,0,strlen($ou)-1)); |
---|
| 202 | $return = utf8_encode("Nome : " . $cn . ";Organização : " . $dn); |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | } |
---|
| 207 | else |
---|
| 208 | { |
---|
| 209 | $this->ldapConnectExternal(substr($pJid, strpos($pJid, "@") + 1 )); |
---|
| 210 | |
---|
| 211 | if( $this->fileLdapExternal ) |
---|
| 212 | { |
---|
| 213 | if( $this->conn ) |
---|
| 214 | { |
---|
| 215 | $filter = "(&(phpgwaccounttype=u)(".$this->attribute."=".$uid.")(!(phpgwaccountvisible=-1)))"; |
---|
| 216 | $justthese = array($this->attribute,"cn","dn"); |
---|
| 217 | $search = ldap_search( $this->conn, $this->contextLdap, $filter, $justthese); |
---|
| 218 | $get_entries = ldap_get_entries( $this->conn, $search); |
---|
| 219 | |
---|
| 220 | if( $get_entries['count'] > 0 ) |
---|
| 221 | { |
---|
| 222 | $cn = $get_entries[0]['cn'][0]; |
---|
| 223 | $ou = explode("dc=", $get_entries[0]['dn']); |
---|
| 224 | $ou = explode("ou=",$ou[0]); |
---|
| 225 | $ou = array_pop($ou); |
---|
| 226 | $dn = strtoupper(substr($ou,0,strlen($ou)-1)); |
---|
| 227 | $return = utf8_encode("Nome : " . $cn . ";Organização : " . $dn); |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | if( $pCharset === "1" || $pCharset === 1 ) |
---|
| 234 | return $return; |
---|
| 235 | else |
---|
| 236 | return mb_convert_encoding($return, "ISO-8859-1", "UTF-8"); |
---|
| 237 | |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | public final function getPhotoLdap( $pJid , $pLdapInternal ) |
---|
| 241 | { |
---|
| 242 | $uid = substr($pJid, 0, strpos($pJid, "@")); |
---|
| 243 | |
---|
| 244 | if( $pLdapInternal ) |
---|
| 245 | { |
---|
| 246 | if( !$this->fileLdapInternal ) |
---|
| 247 | return false; |
---|
| 248 | |
---|
| 249 | if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 ))) |
---|
| 250 | { |
---|
| 251 | |
---|
| 252 | $this->ldapConnect(); |
---|
| 253 | |
---|
| 254 | if( $this->conn ) |
---|
| 255 | { |
---|
| 256 | $filter = "(&(phpgwaccounttype=u)(".$this->attribute."=".$uid.")(!(phpgwaccountvisible=-1)))"; |
---|
| 257 | $justthese = array($this->attribute,"jpegPhoto"); |
---|
| 258 | $search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese); |
---|
| 259 | $get_entries = ldap_get_entries($this->conn,$search); |
---|
| 260 | |
---|
| 261 | if( $get_entries['count'] > 0 ) |
---|
| 262 | { |
---|
| 263 | $first_entry = ldap_first_entry( $this->conn, $search ); |
---|
| 264 | $photo = @ldap_get_values_len($this->conn, $first_entry, 'jpegphoto'); |
---|
| 265 | |
---|
| 266 | if ( $photo ) |
---|
| 267 | return $photo[0]; |
---|
| 268 | |
---|
| 269 | return false; |
---|
| 270 | } |
---|
| 271 | } |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | else |
---|
| 275 | { |
---|
| 276 | $jabberName = substr($pJid, strpos($pJid, "@") + 1 ); |
---|
| 277 | |
---|
| 278 | if( strpos($jabberName, "/") ) |
---|
| 279 | $jabberName = substr($jabberName, 0, strpos($jabberName, "/")); |
---|
| 280 | |
---|
| 281 | $this->ldapConnectExternal($jabberName); |
---|
| 282 | |
---|
| 283 | if( !$this->fileLdapExternal ) |
---|
| 284 | return false; |
---|
| 285 | |
---|
| 286 | if( $this->conn ) |
---|
| 287 | { |
---|
| 288 | $filter = "(&(phpgwaccounttype=u)(".$this->attribute."=".$uid.")(!(phpgwaccountvisible=-1)))"; |
---|
| 289 | $justthese = array($this->attribute,"jpegPhoto"); |
---|
| 290 | $search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese); |
---|
| 291 | $get_entries = ldap_get_entries($this->conn,$search); |
---|
| 292 | |
---|
| 293 | if( $get_entries['count'] > 0 ) |
---|
| 294 | { |
---|
| 295 | $first_entry = ldap_first_entry( $this->conn, $search ); |
---|
| 296 | $photo = @ldap_get_values_len($this->conn, $first_entry, 'jpegphoto'); |
---|
| 297 | |
---|
| 298 | if ( $photo ) |
---|
| 299 | return $photo[0]; |
---|
| 300 | |
---|
| 301 | return false; |
---|
| 302 | } |
---|
| 303 | } |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | return false; |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | public final function getPhotoSession($pUid, $pOu) |
---|
| 310 | { |
---|
| 311 | $uid = $pUid; |
---|
| 312 | if( strpos($pUid, "@") ) |
---|
| 313 | $uid = substr($pUid, 0, strpos($pUid, "@")); |
---|
| 314 | |
---|
| 315 | require_once("../../header.session.inc.php"); |
---|
| 316 | |
---|
| 317 | if( isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]) ) |
---|
| 318 | { |
---|
| 319 | $photo = imagecreatefromstring($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]); |
---|
| 320 | |
---|
| 321 | header("Content-Type: image/jpeg"); |
---|
| 322 | $width = imagesx($photo); |
---|
| 323 | $height = imagesy($photo); |
---|
| 324 | $twidth = 60; |
---|
| 325 | $theight = 80; |
---|
| 326 | $small_photo = imagecreatetruecolor ($twidth, $theight); |
---|
| 327 | imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height); |
---|
| 328 | imagejpeg($small_photo,'',100); |
---|
| 329 | |
---|
| 330 | unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]); |
---|
| 331 | |
---|
| 332 | return; |
---|
| 333 | } |
---|
| 334 | } |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | // Applet - utilizando o serviço Voip; |
---|
| 338 | if(trim($_REQUEST['javaVoipFrom']) != "" && trim($_REQUEST['javaVoipTo']) != "" ) |
---|
| 339 | { |
---|
| 340 | $obj = new webService(); |
---|
| 341 | $voipFrom = $_REQUEST['javaVoipFrom']; |
---|
| 342 | $voipTo = $_REQUEST['javaVoipTo']; |
---|
| 343 | printf("%s",$obj->CallVoipConnect($voipFrom, $voipTo)); |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | // Applet - fotos pelo applet; |
---|
| 347 | if(trim($_REQUEST['javaPhoto']) != "" ) |
---|
| 348 | { |
---|
| 349 | $obj = new webService(); |
---|
| 350 | $jid = $_REQUEST['javaPhoto']; |
---|
| 351 | $jid = ( strpos($jid, "/") !== false ) ? substr($jid, 0, strpos($jid, "/")) : $jid; |
---|
| 352 | $photo = $obj->getPhotoLdap( $jid, true ); |
---|
| 353 | $photoWidth = 70; |
---|
| 354 | $photoHeight = 90; |
---|
| 355 | $newImage = imagecreatetruecolor($photoWidth,$photoHeight); |
---|
| 356 | |
---|
| 357 | if( $photo ) |
---|
| 358 | { |
---|
| 359 | $photo = imagecreatefromstring($photo); |
---|
| 360 | imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo)); |
---|
| 361 | } |
---|
| 362 | else |
---|
| 363 | { |
---|
| 364 | $photo = $obj->getPhotoLdap($jid, false); |
---|
| 365 | if( $photo ) |
---|
| 366 | { |
---|
| 367 | $photo = imagecreatefromstring($photo); |
---|
| 368 | imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo)); |
---|
| 369 | } |
---|
| 370 | else |
---|
| 371 | { |
---|
| 372 | $photo = @imagecreatefrompng("../templates/default/images/photo.png"); |
---|
| 373 | imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo)); |
---|
| 374 | } |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | ob_start(); |
---|
| 378 | imagepng($newImage); |
---|
| 379 | $imagePhoto = ob_get_contents(); |
---|
| 380 | imagedestroy($newImage); |
---|
| 381 | ob_end_clean(); |
---|
| 382 | printf("%s",base64_encode($imagePhoto)); |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | // Applet - jid; |
---|
| 386 | if(trim($_REQUEST['jid']) != "") |
---|
| 387 | { |
---|
| 388 | |
---|
| 389 | $jid = trim($_REQUEST['jid']); |
---|
| 390 | $charset = trim($_REQUEST['charset']); |
---|
| 391 | $obj = new webService(); |
---|
| 392 | |
---|
| 393 | printf("%s",$obj->getNameOrganization($jid, $charset)); |
---|
| 394 | } |
---|
| 395 | |
---|
| 396 | // Php - fotos pelo php; |
---|
| 397 | if(trim($_REQUEST['phpPhoto']) != "") |
---|
| 398 | { |
---|
| 399 | $obj = new webservice(); |
---|
| 400 | $ou = $_REQUEST['phpOu']; |
---|
| 401 | $jid = $_REQUEST['phpPhoto']; |
---|
| 402 | |
---|
| 403 | $obj->getPhotoSession($jid, $ou); |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | ?> |
---|