Ignore:
Timestamp:
06/08/07 15:18:19 (17 years ago)
Author:
niltonneto
Message:

* empty log message *

Location:
trunk/instant_messenger/inc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/instant_messenger/inc/class.Socket.inc.php

    r20 r32  
    11<?php 
    22        /************************************************************ 
    3          *      Classe Jabber - Expresso                                                                * 
     3         *      Classe Jabber - Expresso                                                                                * 
    44         *  ------------------------------------------------------- *   
    5          *  Com Autenticação no Servidor Jabber com Tls                         *        
    6          *  Rodrigo Souza - rodsouza@celepar.pr.gov.br                          * 
    7          *      Alexandre Correia - alexandrecorreia@celepar.pr.gov.br  * 
     5         *  Com Autenticação no Servidor Jabber com Tls                                 *        
     6         *  Rodrigo Souza - rodsouza@celepar.pr.gov.br                                  * 
     7         *  Alexandre Correia - alexandrecorreia@celepar.pr.gov.br  * 
    88         ************************************************************/ 
    99 
     
    1212        private $socket; 
    1313                 
    14         protected final function open($pRemoteSocket, $pTimeOut = 1, $pBlockingMode = 0 ) 
     14        protected final function open($pRemoteSocket, $pTimeOut = 1, $pBlockingMode = 1 ) 
    1515        { 
    1616                if ( ($this->socket = stream_socket_client($pRemoteSocket, $errno, $errstr)) ) 
     
    1818         //$this->socket = stream_socket_client($pRemoteSocket, $errno, $errstr);//, 1, STREAM_CLIENT_CONNECT+STREAM_CLIENT_PERSISTENT); 
    1919         //stream_set_write_buffer($this->socket, 0); 
    20          stream_set_blocking($this->socket, $pBlockingMode); 
    21          stream_set_timeout($this->socket, 1);//$pTimeOut); 
     20         stream_set_timeout( $this->socket, 1 );//$pTimeOut); 
     21         stream_set_blocking( $this->socket, true ); 
     22          
    2223         return true; 
    2324      } 
  • trunk/instant_messenger/inc/class.Ujabber.inc.php

    r29 r32  
    2222         
    2323        private $jid = false; 
     24        private $email = ""; 
     25        private $contacts = ""; 
    2426         
    2527        private $log_error_file = 'erro.log'; 
     
    3638                 
    3739                parent :: __construct($this->jid, $this->password, $this->port); 
    38  
     40                 
    3941        } 
    4042         
     
    5961         
    6062                // VCARD - PESSOAL 
    61  
    6263                $VCARD_P = $this->getVcard($this->username."@".$this->server); 
    6364                 
    64                 $group_nusers[0]['VCARD_FN'] = $VCARD_P['FN']; 
    65                 $group_nusers[0]['VCARD_NICKNAME'] = $VCARD_P['NICKNAME'];  
    66                 $group_nusers[0]['VCARD_ORGNAME'] = $VCARD_P['ORGNAME']; 
    67                 $group_nusers[0]['VCARD_ORGUNIT'] = $VCARD_P['ORGUNIT'];  
    68                 $group_nusers[0]['VCARD_ROLE'] = $VCARD_P['ROLE'];  
    69                 $group_nusers[0]['VCARD_BDAY'] = $VCARD_P['BDAY'];  
    70                 $group_nusers[0]['VCARD_DESC'] = $VCARD_P['DESC']; 
    71                 $group_nusers[0]['VCARD_JID'] = $VCARD_P['JID'];                                 
    72                  
     65                $group_nusers[0]['VCARD_FN'] = $VCARD_P[0]['FN']; 
     66                $group_nusers[0]['VCARD_NICKNAME'] = $VCARD_P[0]['NICKNAME'];  
     67                $group_nusers[0]['VCARD_ORGNAME'] = $VCARD_P[0]['ORGNAME']; 
     68                $group_nusers[0]['VCARD_ORGUNIT'] = $VCARD_P[0]['ORGUNIT'];  
     69                $group_nusers[0]['VCARD_ROLE'] = $VCARD_P[0]['ROLE'];  
     70                $group_nusers[0]['VCARD_BDAY'] = $VCARD_P[0]['BDAY'];  
     71                $group_nusers[0]['VCARD_DESC'] = $VCARD_P[0]['DESC']; 
     72                $group_nusers[0]['VCARD_JID'] = $VCARD_P[0]['JID'];                              
     73         
     74                unset($VCARD_P); 
    7375                natcasesort($group_users);               
    7476                $i=1; 
     
    8789                        $VCARD_U = $this->getVcard($aux_jid[0]."@".$this->server); 
    8890                 
    89                         $group_nusers[$i]['VCARD_FN'] = $VCARD_U['FN']; 
    90                         $group_nusers[$i]['VCARD_NICKNAME'] = $VCARD_U['NICKNAME']; 
    91                         $group_nusers[$i]['VCARD_ORGNAME']  = $VCARD_U['ORGNAME']; 
    92                         $group_nusers[$i]['VCARD_ORGUNIT']  = $VCARD_U['ORGUNIT']; 
    93                         $group_nusers[$i]['VCARD_ROLE'] = $VCARD_U['ROLE']; 
    94                         $group_nusers[$i]['VCARD_BDAY'] = $VCARD_U['BDAY']; 
    95                         $group_nusers[$i]['VCARD_DESC'] = $VCARD_U['DESC']; 
    96                         $group_nusers[$i]['VCARD_JID']  = $VCARD_U['JID'];                               
    97                  
     91                        $group_nusers[$i]['VCARD_FN'] = $VCARD_U[0]['FN']; 
     92                        $group_nusers[$i]['VCARD_NICKNAME'] = $VCARD_U[0]['NICKNAME']; 
     93                        $group_nusers[$i]['VCARD_ORGNAME']  = $VCARD_U[0]['ORGNAME']; 
     94                        $group_nusers[$i]['VCARD_ORGUNIT']  = $VCARD_U[0]['ORGUNIT']; 
     95                        $group_nusers[$i]['VCARD_ROLE'] = $VCARD_U[0]['ROLE']; 
     96                        $group_nusers[$i]['VCARD_BDAY'] = $VCARD_U[0]['BDAY']; 
     97                        $group_nusers[$i]['VCARD_DESC'] = $VCARD_U[0]['DESC']; 
     98                        $group_nusers[$i]['VCARD_JID']  = $VCARD_U[0]['JID']; 
     99                                 
     100                        unset($VCARD_U); 
    98101                        $i++;                                                                            
    99102                } 
    100  
     103                 
    101104                return $group_nusers; 
    102105        } 
     
    113116 
    114117                $this->sendIq('get', 'update1', NULL, NULL, 'jabber:iq:roster'); 
    115         usleep(50000); 
     118                usleep(50000); 
    116119                $result = $this->readSocketFromServer(); 
    117120                 
     
    240243         
    241244        /* 
    242          * GetVcard 
     245         * Vcard 
    243246         */ 
    244247         
     
    250253 
    251254                $this->sendIq('get',$id,$pJid,NULL,"vcard-temp","<vCard xmlns='vcard-temp'/>");          
    252                 usleep(50000); 
    253                 $result = $this->readSocketFromServer(); 
    254                 $arr = $result['iq'][0]['#']['vCard'][0]['#']; 
    255                  
    256                 // vCard 
    257                 $array_vcard['FN'] = trim($arr['FN']['0']['#']) ? urldecode($arr['FN']['0']['#']): $id; 
    258                 $array_vcard['NICKNAME'] = trim($arr['NICKNAME']['0']['#']) ? urldecode($arr['NICKNAME']['0']['#']) : $pJid; 
    259                 $array_vcard['ORGNAME'] = trim($arr['ORG']['0']['#']['ORGNAME']['0']['#']) ? urldecode($arr['ORG']['0']['#']['ORGNAME']['0']['#']) : ""; 
    260                 $array_vcard['ORGUNIT'] = trim($arr['ORG']['0']['#']['ORGUNIT']['0']['#']) ? urldecode($arr['ORG']['0']['#']['ORGUNIT']['0']['#']) : "";                 
    261                 $array_vcard['ROLE'] = trim($arr['ROLE']['0']['#']) ? urldecode($arr['ROLE']['0']['#']) : "";                            
    262                 $array_vcard['BDAY'] = trim($arr['BDAY']['0']['#']) ? urldecode($arr['BDAY']['0']['#']) : ""; 
    263                 $array_vcard['DESC'] = trim($arr['DESC']['0']['#']) ? urldecode($arr['DESC']['0']['#']) : ""; 
    264                 $array_vcard['JID'] = $pJid; 
     255                 
     256                while(($result = $this->readSocketFromServer()) == NULL ){ 
     257                        usleep(40); 
     258                } 
     259                 
     260                if( trim($result['iq'][0]['@']['type']) === trim("result") ){ 
     261 
     262                                $arr = $result['iq'][0]['#']['vCard'][0]['#']; 
     263                                         
     264                                // vCard 
     265                                $array_vcard[0]['FN'] = urldecode($arr['FN']['0']['#']); 
     266                                $array_vcard[0]['NICKNAME'] = urldecode($arr['NICKNAME']['0']['#']); 
     267                                $array_vcard[0]['ORGNAME'] = urldecode($arr['ORG']['0']['#']['ORGNAME']['0']['#']); 
     268                                $array_vcard[0]['ORGUNIT'] = urldecode($arr['ORG']['0']['#']['ORGUNIT']['0']['#']);              
     269                                $array_vcard[0]['ROLE'] = urldecode($arr['ROLE']['0']['#']);                             
     270                                $array_vcard[0]['BDAY'] = urldecode($arr['BDAY']['0']['#']); 
     271                                $array_vcard[0]['DESC'] = urldecode($arr['DESC']['0']['#']); 
     272                                $array_vcard[0]['JID'] = $pJid; 
     273 
     274                }else{ 
     275                                $array_vcard[0]['FN'] = $pJid; 
     276                                $array_vcard[0]['NICKNAME'] = $id; 
     277                                $array_vcard[0]['ORGNAME'] = ""; 
     278                                $array_vcard[0]['ORGUNIT'] = "";                 
     279                                $array_vcard[0]['ROLE'] = "";                            
     280                                $array_vcard[0]['BDAY'] = ""; 
     281                                $array_vcard[0]['DESC'] = ""; 
     282                                $array_vcard[0]['JID'] = $pJid; 
     283                } 
     284         
    265285                return $array_vcard; 
    266286        } 
     
    268288        function newVcard($pVcard_User) 
    269289        { 
    270                  
    271290                $pVcard = explode(";",$pVcard_User['vcard']); 
    272291                $nid = explode("@",$this->jid); 
    273292                $id = $nid[0]; 
    274293                $xmlVcard = ""; 
    275                  
     294 
    276295                // Vcard                         
    277296                $xmlVcard  = "<iq id='$id' type='set'>"; 
     
    326345        function SendMessage($pSendMessage) 
    327346        { 
    328                 //$this->presence(); 
    329347                $to = $pSendMessage['to']; 
    330348                $type = "normal"; 
     
    392410        $result = array(); 
    393411                $this->sendIq('get',$id,$pJid,NULL,'jabber:iq:last'); 
    394         usleep(50000); 
    395  
     412                 
     413                usleep(50000); 
    396414                $result = $this->readSocketFromServer(); 
    397  
     415                 
    398416                $time_offline = $result['iq'][0]['#']['query'][0]['@']['seconds']; 
    399417                return $this->time_off_line($time_offline); 
     
    457475                return ($to) ? $this->presence("unsubscribe", $to) : FALSE; 
    458476        } 
     477 
    459478// TESTE  
    460479 
  • trunk/instant_messenger/inc/class.contacts_im.inc.php

    r27 r32  
    1414                $this->db_user = new db_im();            
    1515        } 
     16         
     17        function set_session_ldap_users() 
     18        { 
     19                if(!isset($_SESSION['instant_messenger']['users_ldap'])) 
     20                        $this->users_auth_im(); 
     21                 
     22        } 
     23                 
     24        function users_auth_im() 
     25        { 
     26                $db_acls = $this->db_user->get_accounts_acl(); 
     27                 
     28                // UidNumbers db; 
     29                foreach($db_acls as $tmp) 
     30                        $uid_users .= "(uidNumber=".$tmp['acl_account'].")"; 
     31                 
     32                foreach($db_acls as $tmp) 
     33                        $uid_groups .= "(gidNumber=".$tmp['acl_account'].")"; 
     34                 
     35                // usuários; 
     36                $result_users = $this->ldap_users->list_users_ldap($uid_users); 
     37                 
     38                // grupos; 
     39                $result_groups = $this->ldap_users->list_groups_ldap($uid_groups); 
     40                 
     41                foreach($result_groups as $group_tmp){ 
     42                        $tmp = $group_tmp['members']; 
     43                        foreach($tmp as $value) 
     44                                $uid_members_group .= "(uid=".$value.")"; 
     45                } 
     46                 
     47                $uid_members = $this->ldap_users->list_users_ldap($uid_members_group); 
     48                $count = count($result_users); 
     49 
     50                for($i = 0; $i < count($uid_members); $i++){ 
     51                        $result_users[$count] = $uid_members[$i]; 
     52                        $count++; 
     53                } 
     54 
     55                foreach($result_users as $rs){ 
     56                        $uid[] = $rs['cn'].";".$rs['mail'].";".$rs['ou']; 
     57                } 
     58 
     59                natsort($uid); 
     60                $uid_un = @array_values(@array_unique($uid)); 
     61                 
     62                $t = 0; 
     63                foreach($uid_un as $utmp){ 
     64                        $array = explode(";",$utmp); 
     65                        $list_ldap[$t]['cn'] = $array[0]; 
     66                        $list_ldap[$t]['mail'] = $array[1]; 
     67                        $list_ldap[$t]['ou'] = $array[2]; 
     68                        $t++;                    
     69                } 
     70 
     71                $_SESSION['instant_messenger']['users_ldap'] = $list_ldap; 
     72                 
     73        } 
    1674                 
    1775        function list_contacts($param) 
    1876        { 
     77                $result_users = array(); 
    1978                $org_ldap = $param['ou']; 
    20                 $array_db = $this->db_user->get_accounts_acl(); 
    21                 $array_groups_ldap = array(); 
    22                 $j = 0; 
    23  
    24                 for($i=0 ; $i < count($array_db); $i++) 
    25                         $array_1[] = $this->ldap_users->list_users_ldap($org_ldap,"uidNumber", $array_db[$i]['acl_account']); 
    26          
    27                 for($i=0; $i < count($array_1); $i++){ 
    28                         if(array_key_exists("count",$array_1[$i])){ 
    29                                 $array_groups_ldap[] = $array_1[$i]['uidnumber']; 
    30                         }                
    31                 } 
     79                $i = 0; 
     80                $this->set_session_ldap_users(); 
    3281                 
    33                 for($i=0; $i < count($array_groups_ldap); $i++) 
    34                         $array_2[]['members'] = $this->ldap_users->list_groups_ldap($org_ldap,$array_groups_ldap[$i]); 
    35          
    36                 foreach($array_2 as $tmp){ 
    37                         if($tmp['members'] > 0){ 
    38                                 foreach($tmp['members'] as $tmp1)        
    39                                         $array_3[] = $tmp1; 
    40                         } 
    41                 } 
    42                  
    43                 for($i=0; $i < count($array_1); $i++) 
    44                         if($array_1[$i]['uid'] != "") 
    45                                 $array_3[] = $array_1[$i]['uid']; 
    46          
    47                 @natsort($array_3); 
    48                  
    49                 $array_4 = @array_values(@array_unique($array_3)); 
    50  
    51                 for($i=0; $i < count($array_4); $i++) 
    52                         $array_5[] = $this->ldap_users->list_users_ldap($org_ldap,"uid", $array_4[$i]); 
    53  
    54                 for($i=0 ; $i < count($array_5); $i++){ 
    55                         if($array_5[$i]['phpgwAccountVisible'] != "-1"){ 
    56                                 $array_6[] = $array_5[$i]['cn'] . ";" . $array_5[$i]['mail']; 
     82                foreach($_SESSION['instant_messenger']['users_ldap'] as $users){ 
     83                        if($users['ou'] == ("OU=".$org_ldap)){ 
     84                                $result_users[$i]['cn'] = $users['cn']; 
     85                                $result_users[$i]['mail'] = $users['mail']; 
     86                                $i++; 
    5787                        } 
    5888                } 
    5989 
    60                 sort($array_6);  
    61                  
    62                 for($i=0; $i < count($array_6); $i++){ 
    63                         $aux = explode(";", $array_6[$i]); 
    64                         $array_7[$j]['cn'] = $aux[0]; 
    65                         $array_7[$j]['mail'] = $aux[1];                  
    66                         $j++; 
    67                 } 
    68                  
    69                 if(count($array_7) > 0) 
    70                         return $array_7; 
     90                if(count($result_users) > 0) 
     91                        return $result_users; 
    7192                else 
    7293                        return 0; 
  • trunk/instant_messenger/inc/class.ldap_im.inc.php

    r27 r32  
    1414                $this->user             = $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber']; 
    1515                $this->password         = $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber']; 
    16                 $this->connect_ldap(false); 
     16                $this->connect_ldap(true); 
    1717        } 
    1818         
     
    2828                ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $refer); 
    2929                if(trim($this->user) != "") 
    30                         ldap_bind($this->conn,$this->user,$this->password); 
     30                        @ldap_bind($this->conn,$this->user,$this->password); 
    3131                else             
    32                         ldap_bind($this->conn); 
     32                        @ldap_bind($this->conn); 
    3333        } 
    3434         
     
    7272        } 
    7373         
    74         function list_users_ldap($orgLdap = false,$type,$uid) 
     74        function list_users_ldap($filter) 
    7575        { 
    76                 $result_users = array(); 
    77                 $i = 0; 
    78                  
    79                 if ($this->conn) { 
    80                         $filter = $type ."=". $uid;              
    81                         $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible"); 
    82                         if($orgLdap) 
    83                                 $search = ldap_search($this->conn,"ou=".$orgLdap.",".$this->ldap_context, $filter, $justthese); 
    84                         else 
    85                                 $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese); 
    86                         $entry = ldap_get_entries($this->conn, $search); 
     76 
     77                if( $this->conn ){ 
     78                        $filter = "(&(|".$filter.")(phpgwAccountType=u))"; 
     79                        $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn");                    
     80                        $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese); 
     81                        $entry = ldap_get_entries($this->conn,$search); 
     82                } 
     83 
     84                if( $entry['count'] > 0){ 
     85                        $i = 0; 
     86                        foreach($entry as $tmp) 
     87                        { 
     88                                if($tmp['uidnumber'][0] != ""){ 
     89                                        $result_user[$i]['uidnumber'] = $tmp['uidnumber'][0];                    
     90                                        $result_user[$i]['mail'] = $tmp['mail'][0]; 
     91                                        $result_user[$i]['uid'] = $tmp['uid'][0]; 
     92                                        $result_user[$i]['cn'] = $tmp['cn'][0]; 
     93                                        $dn = explode(",dc=",$tmp['dn']); 
     94                                        $ou = explode(",",$dn[0]); 
     95                                        $result_user[$i]['ou'] = strtoupper(array_pop($ou)); 
     96                                        $i++; 
     97                                }                                
     98                        } 
     99                        return $result_user; 
     100                } 
     101                return 0; 
     102        } 
     103         
     104        function list_groups_ldap($filter) 
     105        { 
     106 
     107                if( $this->conn ){ 
     108                        $filter = "(&(|".$filter.")(phpgwAccountType=g))"; 
     109                        $justthese = array("gidnumber","cn","memberuid");                        
     110                        $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese); 
     111                        $entry = ldap_get_entries($this->conn,$search); 
    87112                } 
    88113                 
    89                 if($entry['count'] == 0){ 
    90                         $result_users['count'] = 0; 
    91                         $result_users['uidnumber'] = $uid; 
    92                         return $result_users;    
     114                if( $entry['count'] > 0 ){ 
     115                        $i = 0; 
     116                        foreach($entry as $tmp) 
     117                        { 
     118                                if($tmp['gidnumber'][0] != ""){ 
     119                                        $result_groups[$i]['gidnumber'] = $tmp['gidnumber'][0]; 
     120                                        $org = explode(",",$tmp['dn']); 
     121                                        $result_groups[$i]['ou'] = strtoupper($org[1]); 
     122                                        array_shift($tmp['memberuid']); 
     123                                        foreach($tmp['memberuid'] as $mb) 
     124                                                $result_groups[$i]['members'][] = $mb; 
     125                                        $i++; 
     126                                } 
     127                        } 
     128                        return $result_groups; 
    93129                } 
    94                  
    95                 $result_users['uid'] = $entry[0]['uid'][0]; 
    96                 $result_users['uidnumber'] = $entry[0]['uidnumber'][0]; 
    97                 $result_users['cn'] = $entry[0]['cn'][0]; 
    98                 $result_users['mail'] = $entry[0]['mail'][0]; 
    99                 $result_users['phpgwAccountVisible'] = @$entry[0]['phpgwaccountvisible'][0]; 
     130                return 0; 
    100131 
    101                 return $result_users; 
    102         } 
    103          
    104         function list_groups_ldap($orgLdap, $gid) 
    105         { 
    106                 $result_groups = ""; 
    107                 $i = 0; 
    108                  
    109                 if ($this->conn) { 
    110                         $filter="(&(gidNumber=".$gid.")(objectClass=posixGroup))";               
    111                         $justthese = array("gidnumber","cn","memberuid"); 
    112                         $search = ldap_search($this->conn,"ou=".$orgLdap.",".$this->ldap_context, $filter, $justthese); 
    113                         $entry = ldap_get_entries($this->conn, $search); 
    114                 } 
    115          
    116                 if($entry['count'] == "1"){ 
    117                         $result_groups = array_shift($entry[0]['memberuid']); 
    118                         return $entry[0]['memberuid']; 
    119                 }                
    120                 return false; 
    121132        } 
    122133         
     
    134145                foreach($entry as $tmp){ 
    135146                        if($tmp['ou'][0] != ""){ 
    136                                 $result_org[$i]['ou'] = $tmp['ou'][0]; 
     147                                $result_org[$i] = $tmp['ou'][0]; 
    137148                                $i++; 
    138149                        } 
    139150                } 
     151                 
     152                sort($result_org); 
     153 
    140154                return $result_org; 
    141155        } 
     
    144158        { 
    145159                $uid = $user['uid']; 
     160                $filter = "(uid=".$uid.")"; 
    146161                $i= 0; 
    147162                 
    148                 $entry = $this->list_users_ldap(false,"uid",$uid); 
     163                $entry = $this->list_users_ldap($filter); 
    149164                 
    150                 $result_users[0]['uid'] = $entry['uid']; 
    151                 $result_users[0]['cn'] = $entry['cn']; 
    152                 $result_users[0]['mail'] = $entry['mail']; 
    153  
    154                 $_SESSION['debug'] = $result_users; 
    155                  
    156                 return $result_users; 
    157                  
     165                if( count($entry) > 0 ){ 
     166                        return $entry; 
     167                }else{ 
     168                        return false;    
     169                } 
    158170        } 
    159171} 
Note: See TracChangeset for help on using the changeset viewer.