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 *
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;       
18        private $jabberName;
[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        {
[946]26                require_once('confLDAPInternal.php');
27                $handle   = unserialize(base64_decode($LDAP_INTERNAL));
[551]28
[946]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'];
[417]34               
[551]35                $this->refer    = true;
[417]36                $this->version3 = true;
37        }
[946]38       
[417]39        private final function ldapConnect()
40        {
41                if(!function_exists('ldap_connect'))
42                        return False;
43               
[946]44                if(!$this->conn = ldap_connect($this->serverLdap))
[417]45                        return False;
[551]46
[417]47                if( $this->version3 )
48                        if( !ldap_set_option($this->conn,LDAP_OPT_PROTOCOL_VERSION,3) )
49                                $this->version = false;
[946]50
[417]51                ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $this->refer);
[551]52
[946]53                // Bind as Admin
54                if($this->userDn && $this->passwd && !ldap_bind($this->conn, $this->userDn, $this->passwd))
55                        return False;
[417]56               
[946]57                // Bind as Anonymous
58                if(!$this->userDn && !$this->passwd && !@ldap_bind($this->conn))
[417]59                        return False;
[946]60        }
[551]61
[946]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();
[417]81        }
82       
[946]83        public final function getNameOrganization($pJid, $pCharset)
[551]84        {
[946]85                $uid = substr($pJid, 0, strpos($pJid,"@"));
[551]86               
[946]87                if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 )))
[551]88                {
[946]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 ));
[551]109
[946]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                }
[551]125
[946]126                if( $pCharset === "1" )
127                        return $return;
128                else
129                        return mb_convert_encoding($return, "ISO-8859-1", "UTF-8");
[551]130
[946]131                $return = utf8_encode("Nome : Não Identificado ;Organização : Não Identificado");                       
[551]132
[946]133                if( $pCharset === 1 )
134                        return $return;
135                else
136                        return mb_convert_encoding($return, "ISO-8859-1", "UTF-8");
137
[551]138        }
139       
[946]140        public final function getPhotoLdap($pJid)
[417]141        {
[946]142                $uid = substr($pJid, 0, strpos($pJid,"@"));
143       
144                if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 )))
[417]145                {
[946]146                        $this->ldapConnect();
147                       
148                        if( $this->conn )
[417]149                        {
[946]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                                }
[417]166                        }
167                }
[946]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                                       
[417]197                return false;
198        }
199       
[946]200        public final function getPhotoSession($pUid, $pOu)
[417]201        {
[946]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]) )
[382]207                {
[946]208                        $photo = imagecreatefromstring($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]);
209
[382]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);
[946]218
219                        unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]);
220
[382]221                        return;
222                }
223        }
[417]224}
[382]225
[946]226if(trim($_REQUEST['javaPhoto']) != "" )
[417]227{
[946]228        $obj = new webService();
229        $jid = $_REQUEST['javaPhoto'];
[417]230       
[946]231        $photo = $obj->getPhotoLdap($jid);
232        $photoWidth = 70;
233        $photoHeight = 90;
234        $newImage = imagecreatetruecolor($photoWidth,$photoHeight);             
235
236        if( $photo )
[382]237        {
[946]238                $photo = imagecreatefromstring($photo);
239                imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
[382]240        }
[417]241        else
242        {
[946]243                $photo = @imagecreatefrompng("../templates/default/images/photo.png");
244                imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
[417]245        }
[946]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       
[417]254}
[382]255
[551]256if(trim($_POST['jid']) != "")
257{
258        $jid = trim($_POST['jid']);
259        $charset = trim($_POST['charset']);
[946]260        $obj = new webService();
[551]261       
[946]262        printf("%s",$obj->getNameOrganization($jid, $charset));
[551]263}
[946]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
[439]274?>
Note: See TracBrowser for help on using the repository browser.