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