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

Revision 986, 8.0 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 *
RevLine 
[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]13class 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       
[946]86        public final function getNameOrganization($pJid, $pCharset)
[551]87        {
[946]88                $uid = substr($pJid, 0, strpos($pJid,"@"));
[551]89               
[946]90                if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 )))
[551]91                {
[946]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 ));
[551]112
[946]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                }
[551]128
[946]129                if( $pCharset === "1" )
130                        return $return;
131                else
132                        return mb_convert_encoding($return, "ISO-8859-1", "UTF-8");
[551]133
[946]134                $return = utf8_encode("Nome : Não Identificado ;Organização : Não Identificado");                       
[551]135
[946]136                if( $pCharset === 1 )
137                        return $return;
138                else
139                        return mb_convert_encoding($return, "ISO-8859-1", "UTF-8");
140
[551]141        }
142       
[986]143        public final function getPhotoLdap( $pJid, $pCatalog )
[417]144        {
[957]145                if ( ! $this->jabberName )
146                        return false;
147
[946]148                $uid = substr($pJid, 0, strpos($pJid,"@"));
[948]149               
[986]150                if( ($this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 ))) && $pCatalog)
[417]151                {
[946]152                        $this->ldapConnect();
153                       
154                        if( $this->conn )
[417]155                        {
[946]156                                $filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
157                                $justthese = array("uid","jpegPhoto");
[948]158                               
[946]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                                }
[417]173                        }
174                }
[946]175                else
[948]176                {                                       
[946]177                        $jabberName = substr($pJid, strpos($pJid, "@") + 1 );
178                       
179                        if( strpos($jabberName, "/") )
180                                $jabberName = substr($jabberName, 0, strpos($jabberName, "/"));
[948]181
[946]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                                       
[417]204                return false;
205        }
206       
[946]207        public final function getPhotoSession($pUid, $pOu)
[417]208        {
[946]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]) )
[382]214                {
[946]215                        $photo = imagecreatefromstring($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]);
216
[382]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);
[946]225
226                        unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]);
227
[382]228                        return;
229                }
230        }
[417]231}
[382]232
[946]233if(trim($_REQUEST['javaPhoto']) != "" )
[417]234{
[946]235        $obj = new webService();
236        $jid = $_REQUEST['javaPhoto'];
[948]237        $jid = strpos($jid, "/") ? substr($jid, 0, strpos($jid, "/")) : $jid;
[417]238       
[986]239        $photo = $obj->getPhotoLdap($jid, true);
[946]240        $photoWidth = 70;
241        $photoHeight = 90;
242        $newImage = imagecreatetruecolor($photoWidth,$photoHeight);             
243
244        if( $photo )
[382]245        {
[946]246                $photo = imagecreatefromstring($photo);
247                imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
[382]248        }
[417]249        else
250        {
[986]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                }
[417]262        }
[946]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       
[417]271}
[382]272
[551]273if(trim($_POST['jid']) != "")
274{
275        $jid = trim($_POST['jid']);
276        $charset = trim($_POST['charset']);
[946]277        $obj = new webService();
[551]278       
[946]279        printf("%s",$obj->getNameOrganization($jid, $charset));
[551]280}
[946]281
282if(trim($_REQUEST['phpPhoto']) != "")
283{
284        $obj = new webservice();
285        $ou = $_REQUEST['phpOu'];
286        $jid = $_REQUEST['phpPhoto'];
287       
288        $obj->getPhotoSession($jid, $ou);
289}
290
[439]291?>
Note: See TracBrowser for help on using the repository browser.