Changeset 946 for trunk/jabberit_messenger/inc/webservice.php
- Timestamp:
- 06/04/09 10:30:18 (15 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/jabberit_messenger/inc/webservice.php
r697 r946 11 11 \***************************************************************************/ 12 12 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 19 class ldapPhoto 20 { 21 private $host; 22 private $dn; 13 class webService 14 { 15 private $conn; 16 private $contextLdap; 17 private $userDn; 18 private $jabberName; 23 19 private $passwd; 20 private $photo_user = array(); 24 21 private $refer; 25 private $user_referral; 26 private $password_referral; 27 private $conn; 28 private $context; 29 private $photo_user = array(); 30 private $handle; 31 32 22 private $serverLdap; 23 33 24 function __construct() 34 25 { 35 require_once('conf_Ldap_Photos.php'); 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']; 26 require_once('confLDAPInternal.php'); 27 $handle = unserialize(base64_decode($LDAP_INTERNAL)); 28 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']; 42 34 43 35 $this->refer = true; 44 36 $this->version3 = true; 45 37 } 46 47 38 48 39 private final function ldapConnect() 49 40 { 50 41 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 } 42 return False; 43 44 if(!$this->conn = ldap_connect($this->serverLdap)) 45 return False; 61 46 62 47 if( $this->version3 ) 63 {64 48 if( !ldap_set_option($this->conn,LDAP_OPT_PROTOCOL_VERSION,3) ) 65 49 $this->version = false; 66 } 50 67 51 ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $this->refer); 68 52 69 // verifica refer 70 if( $this->refer ) 71 { 72 @ldap_set_rebind_proc($this->conn, ldap_rebind); 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 } 80 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 89 public final function getNameOrganization($pUid, $pCharset) 90 { 53 // Bind as Admin 54 if($this->userDn && $this->passwd && !ldap_bind($this->conn, $this->userDn, $this->passwd)) 55 return False; 56 57 // Bind as Anonymous 58 if(!$this->userDn && !$this->passwd && !@ldap_bind($this->conn)) 59 return False; 60 } 61 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 91 80 $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 121 public final function getPhotoLdap($uid) 122 { 123 $this->ldapConnect(); 124 if( $this->conn ) 125 { 126 $filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))"; 127 $justthese = array("uid","jpegPhoto"); 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 = ""; 136 $photo = @ldap_get_values_len($this->conn, $entry, 'jpegphoto'); 137 if ($photo) 138 $return_photo = $photo[0]; 139 return $return_photo; 140 } 141 } 81 } 82 83 public final function getNameOrganization($pJid, $pCharset) 84 { 85 $uid = substr($pJid, 0, strpos($pJid,"@")); 86 87 if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 ))) 88 { 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 )); 109 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 } 125 126 if( $pCharset === "1" ) 127 return $return; 128 else 129 return mb_convert_encoding($return, "ISO-8859-1", "UTF-8"); 130 131 $return = utf8_encode("Nome : Não Identificado ;Organização : Não Identificado"); 132 133 if( $pCharset === 1 ) 134 return $return; 135 else 136 return mb_convert_encoding($return, "ISO-8859-1", "UTF-8"); 137 138 } 139 140 public final function getPhotoLdap($pJid) 141 { 142 $uid = substr($pJid, 0, strpos($pJid,"@")); 143 144 if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 ))) 145 { 146 $this->ldapConnect(); 147 148 if( $this->conn ) 149 { 150 $filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))"; 151 $justthese = array("uid","jpegPhoto"); 152 $search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese); 153 $entry1 = ldap_get_entries($this->conn,$search); 154 $entry = ldap_first_entry( $this->conn, $search ); 155 if( $entry1['count'] > 0 ) 156 { 157 $i = 0; 158 $photo = ""; 159 $return_photo = ""; 160 $photo = @ldap_get_values_len($this->conn, $entry, 'jpegphoto'); 161 162 if ($photo) 163 $return_photo = $photo[0]; 164 return $return_photo; 165 } 166 } 167 } 168 else 169 { 170 $jabberName = substr($pJid, strpos($pJid, "@") + 1 ); 171 172 if( strpos($jabberName, "/") ) 173 $jabberName = substr($jabberName, 0, strpos($jabberName, "/")); 174 175 $this->ldapConnectExternal($jabberName); 176 177 if( $this->conn ) 178 { 179 $filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))"; 180 $justthese = array("uid","jpegPhoto"); 181 $search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese); 182 $entry1 = ldap_get_entries($this->conn,$search); 183 $entry = ldap_first_entry( $this->conn, $search ); 184 if( $entry1['count'] > 0 ) 185 { 186 $i = 0; 187 $photo = ""; 188 $return_photo = ""; 189 $photo = @ldap_get_values_len($this->conn, $entry, 'jpegphoto'); 190 if ($photo) 191 $return_photo = $photo[0]; 192 return $return_photo; 193 } 194 } 195 } 196 142 197 return false; 143 198 } 144 199 145 public final function getPhotoSession($pUid) 146 { 147 if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pUid])) 148 { 149 $photo = imagecreatefromstring($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pUid]); 150 200 public final function getPhotoSession($pUid, $pOu) 201 { 202 $uid = $pUid; 203 if( strpos($pUid, "@") ) 204 $uid = substr($pUid, 0, strpos($pUid, "@")); 205 206 if( isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]) ) 207 { 208 $photo = imagecreatefromstring($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]); 209 151 210 header("Content-Type: image/jpeg"); 152 211 $width = imagesx($photo); … … 157 216 imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height); 158 217 imagejpeg($small_photo,'',100); 159 160 unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pUid]); 218 219 unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]); 220 161 221 return; 162 222 } … … 164 224 } 165 225 166 if(trim($_REQUEST['uid']) != "") 167 { 168 $uid = trim($_REQUEST['uid']); 169 $a = new ldapPhoto(); 170 171 if( strpos($uid,"@")) 172 { 173 $uid = substr($uid, 0, strpos($uid,"@")); 174 $photo = $a->getPhotoLdap($uid); 175 $photoWidth = 70; 176 $photoHeight = 90; 177 $newImage = imagecreatetruecolor($photoWidth,$photoHeight); 178 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 { 186 $photo = @imagecreatefrompng("../templates/default/images/photo.png"); 187 imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo)); 188 } 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)); 226 if(trim($_REQUEST['javaPhoto']) != "" ) 227 { 228 $obj = new webService(); 229 $jid = $_REQUEST['javaPhoto']; 230 231 $photo = $obj->getPhotoLdap($jid); 232 $photoWidth = 70; 233 $photoHeight = 90; 234 $newImage = imagecreatetruecolor($photoWidth,$photoHeight); 235 236 if( $photo ) 237 { 238 $photo = imagecreatefromstring($photo); 239 imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo)); 196 240 } 197 241 else 198 242 { 199 $a->getPhotoSession($uid); 200 } 243 $photo = @imagecreatefrompng("../templates/default/images/photo.png"); 244 imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo)); 245 } 246 247 ob_start(); 248 imagepng($newImage); 249 $imagePhoto = ob_get_contents(); 250 imagedestroy($newImage); 251 ob_end_clean(); 252 printf("%s",base64_encode($imagePhoto)); 253 201 254 } 202 255 … … 204 257 { 205 258 $jid = trim($_POST['jid']); 206 if( strpos($jid,"@"))207 $jid = substr($jid, 0, strpos($jid,"@"));208 259 $charset = trim($_POST['charset']); 209 $a = new ldapPhoto(); 210 211 printf("%s",$a->getNameOrganization($jid, $charset)); 212 } 260 $obj = new webService(); 261 262 printf("%s",$obj->getNameOrganization($jid, $charset)); 263 } 264 265 if(trim($_REQUEST['phpPhoto']) != "") 266 { 267 $obj = new webservice(); 268 $ou = $_REQUEST['phpOu']; 269 $jid = $_REQUEST['phpPhoto']; 270 271 $obj->getPhotoSession($jid, $ou); 272 } 273 213 274 ?>
Note: See TracChangeset
for help on using the changeset viewer.