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