source: trunk/instant_messenger/inc/class.ldap_im.inc.php @ 151

Revision 151, 4.7 KB checked in by niltonneto, 16 years ago (diff)

Commit da nova versão do módulo, usando agente em C.
Vide Página do módulo do Trac:
http://www.expressolivre.org/dev/wiki/messenger

A versão anterior encontra-se na subpasta bkp (32/64).

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2class ldap_im
3{
4        private $ldap_host;
5        private $ldap_context;
6        private $conn;
7        private $user;
8        private $jid;
9        private $password;
10       
11        function __construct()
12        {
13                session_start();
14                $this->ldap_host                = $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber'];
15                $this->ldap_context     = $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber'];
16                $this->user                     = $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber'];
17                $this->password                 = $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber'];
18                $this->jid                              = $_SESSION['phpgw_info']['instant_messenger']['user'];
19                $this->connect_ldap(false);
20                session_write_close();
21        }
22       
23        function __destruct()
24        {
25                ldap_close($this->conn);
26        }
27       
28        function connect_ldap($refer)
29        {
30                $this->conn = ldap_connect($this->ldap_host);
31                ldap_set_option($this->conn, LDAP_OPT_PROTOCOL_VERSION, 3);
32                ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $refer);
33                if(trim($this->user) != "")
34                        @ldap_bind($this->conn,$this->user,$this->password);
35                else           
36                        @ldap_bind($this->conn);
37        }
38       
39        function get_photo_ldap($pUser,$getPhoto)
40        {
41                $user = ( $pUser == "im_avatar" ) ? $this->jid : $pUser ;
42               
43                if ($this->conn)
44                {
45                        $filter="(&(uid=".$user.")(phpgwAccountType=u))";               
46                        $justthese = array("jpegphoto");
47                        $search = @ldap_search($this->conn,$this->ldap_context, $filter, $justthese);
48                        $entry = @ldap_first_entry($this->conn, $search);
49                        $jpeg_data = @ldap_get_values_len($this->conn, $entry, "jpegphoto");
50                       
51                        if( count($jpeg_data) > 1)
52                        {
53                                $photo = imagecreatefromstring($jpeg_data[0]);
54                                if($photo)
55                                {
56                                        if($getPhoto)
57                                        {
58                                                header("Content-Type: image/jpeg");
59                                                $width = imagesx($photo);
60                                                $height = imagesy($photo);
61                                                $twidth = 49;
62                                                $theight = 65;
63                                                $small_photo = imagecreatetruecolor ($twidth, $theight);
64                                                imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
65                                                imagejpeg($small_photo,'',100);
66                                                return;         
67                                        }else{
68                                                return "true";
69                                        }                               
70                                }else{
71                                        return "false";
72                                }
73                        }else{
74                                return "false";
75                        }
76                }
77        }
78       
79        function photo_ldap($user)
80        {
81                $uid = ( $user['uid'] == "im_avatar" ) ? $this->jid : $user['uid'] ;
82                return $this->get_photo_ldap($uid,false);
83        }
84       
85        function list_users_ldap($search)
86        {
87
88                if($this->conn){
89                        $filter = "(&(".$search.")(phpgwAccountType=u))";
90                        $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn");
91                        $search = ldap_search($this->conn,$this->ldap_context,$filter,$justthese);
92                        $entry = ldap_get_entries($this->conn,$search);
93                }
94               
95                if( $entry['count'] > 0){
96                        $i = 0;
97                        $result_user = array();
98                        foreach($entry as $tmp)
99                        {
100                                if($tmp['uidnumber'][0] != "" && $tmp['phpgwaccountvisible'][0] != "-1"){
101                                        $result_user[$i]['uidnumber'] = $tmp['uidnumber'][0];                   
102                                        $result_user[$i]['mail'] = $tmp['mail'][0];
103                                        $result_user[$i]['uid'] = $tmp['uid'][0];
104                                        $result_user[$i]['cn'] = $tmp['cn'][0];
105                                        $ou = explode("dc=",$tmp['dn']);
106                                        $ou = explode("ou=",$ou[0]);
107                                        $ou = array_pop($ou);
108                                        $result_user[$i]['dn'] = strtoupper(substr($ou,0,strlen($ou)-1));                                       
109                                        $i++;
110                                }                               
111                        }
112                        return $result_user;
113                }
114                return 0;
115        }
116       
117        function list_groups_ldap($search)
118        {
119       
120                if( $this->conn ){
121                        $filter = "(&(".$search.")(objectClass=posixGroup))";
122                        $justthese = array("gidnumber","cn","memberuid");                       
123                        $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese);
124                        $entry = ldap_get_entries($this->conn,$search);
125                }
126
127                if($entry['count'] > 0){
128                        $i = 0;
129                        $result_groups = array();
130                        foreach($entry as $tmpg){
131                                if($tmpg['gidnumber'] != ""){
132                                        if(array_key_exists("memberuid", $tmpg)){
133                                                $result_groups[$i]['gidnumber'] = $tmpg['gidnumber'][0];                                               
134                                                @array_shift($tmpg['memberuid']);
135                                                foreach($tmpg['memberuid'] as $tmp)
136                                                        $result_groups[$i]['members'][] = $tmp;                                 
137                                                $i++;
138                                        }
139                                }
140                        }       
141                }
142               
143                if(count($result_groups) > 0 ){
144                        return $result_groups;
145                }else{
146                        return 0;
147                }
148        }
149       
150        function list_organizations_ldap()
151        {
152                $result_org = "<organizations><ou></ou>";
153
154                if ($this->conn)
155                {
156                        $filter="ou=*";         
157                        $justthese = array("ou");
158                        $search = ldap_list($this->conn,$this->ldap_context, $filter, $justthese);
159                        $entry = ldap_get_entries($this->conn, $search);
160                }
161               
162                foreach($entry as $tmp)
163                        if($tmp['ou'][0] != "")
164                                $result_org .= "<ou>" . $tmp['ou'][0] . "</ou>"; 
165
166                $result_org .= "</organizations>";
167               
168                return $result_org;
169        }
170       
171        function info_user($user)
172        {
173                $uid = "uid=".$user['uid'];
174                $i= 0;
175               
176                $entry = $this->list_users_ldap($uid);
177               
178                if( count($entry) > 0 )
179                        return $entry;
180                else
181                        return false;   
182        }
183}
184
185if(trim($_REQUEST['user']) != "")
186{
187        $obj_img = new ldap_im();
188        $obj_img->get_photo_ldap($_REQUEST['user'],true);
189}
190
191?>
Note: See TracBrowser for help on using the repository browser.