source: trunk/jabberit_messenger/inc/webservice.php @ 946

Revision 946, 7.5 KB checked in by alexandrecorreia, 15 years ago (diff)

Ticket #505 - Arquivos modificados para a administração de hosts virtuais no servidor Jabber.

  • Property svn:executable set to *
Line 
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
13class webService
14{
15        private $conn;
16        private $contextLdap;
17        private $userDn;       
18        private $jabberName;
19        private $passwd;
20        private $photo_user = array();
21        private $refer;
22        private $serverLdap;
23       
24        function __construct()
25        {
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'];
34               
35                $this->refer    = true;
36                $this->version3 = true;
37        }
38       
39        private final function ldapConnect()
40        {
41                if(!function_exists('ldap_connect'))
42                        return False;
43               
44                if(!$this->conn = ldap_connect($this->serverLdap))
45                        return False;
46
47                if( $this->version3 )
48                        if( !ldap_set_option($this->conn,LDAP_OPT_PROTOCOL_VERSION,3) )
49                                $this->version = false;
50
51                ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $this->refer);
52
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               
80                $this->ldapConnect();
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                                       
197                return false;
198        }
199       
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
210                        header("Content-Type: image/jpeg");
211                        $width = imagesx($photo);
212                        $height = imagesy($photo);
213                        $twidth = 60;
214                        $theight = 80;
215                        $small_photo = imagecreatetruecolor ($twidth, $theight);
216                        imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
217                        imagejpeg($small_photo,'',100);
218
219                        unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]);
220
221                        return;
222                }
223        }
224}
225
226if(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));
240        }
241        else
242        {
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       
254}
255
256if(trim($_POST['jid']) != "")
257{
258        $jid = trim($_POST['jid']);
259        $charset = trim($_POST['charset']);
260        $obj = new webService();
261       
262        printf("%s",$obj->getNameOrganization($jid, $charset));
263}
264
265if(trim($_REQUEST['phpPhoto']) != "")
266{
267        $obj = new webservice();
268        $ou = $_REQUEST['phpOu'];
269        $jid = $_REQUEST['phpPhoto'];
270       
271        $obj->getPhotoSession($jid, $ou);
272}
273
274?>
Note: See TracBrowser for help on using the repository browser.