source: trunk/expressoAdmin1_2/inc/class.socomputers.inc.php @ 396

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

Modificações referente a opção de configurar um ldap_master
no setup do Expresso, usado somente para escrita.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /************************************************************************************\
3        * Expresso Administração                                                                                                     *
4        * by Joao Alfredo Knopik Junior (joao.alfredo@gmail.com, jakjr@celepar.pr.gov.br)        *
5        * -----------------------------------------------------------------------------------*
6        *  This program is free software; you can redistribute it and/or modify it                       *
7        *  under the terms of the GNU General Public License as published by the                         *
8        *  Free Software Foundation; either version 2 of the License, or (at your                        *
9        *  option) any later version.                                                                                                            *
10        \************************************************************************************/
11
12        class socomputers
13        {
14                var $functions;
15                var $ldap_connection;
16               
17                function socomputers()
18                {
19                        $this->functions = CreateObject('expressoAdmin1_2.functions');
20                       
21                        if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) &&
22                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
23                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
24                        {
25                                $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'],
26                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'],
27                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
28                        }
29                        else
30                        {
31                                $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect();
32                        }
33                }
34
35                function write_ldap($dn, $info)
36                {
37                        if (ldap_add($this->ldap_connection, $dn, $info))
38                        {
39                                ldap_close($this->ldap_connection);
40                                return true;
41                        }
42                        else
43                        {
44                                echo "Erro na escrita no LDAP, funcao so->write_ldap:" . ldap_error($this->ldap_connection);
45                                ldap_close($this->ldap_connection);
46                                return false;
47                        }
48                }
49               
50                function exist_computer_uid($computer_cn)
51                {
52                        $search = ldap_search($this->ldap_connection, $GLOBALS['phpgw_info']['server']['ldap_context'], "uid=" . $computer_cn . '$');
53                        $result = ldap_get_entries($this->ldap_connection, $search);
54                        ldap_close($this->ldap_connection);
55                        if ($result['count'] == 0)
56                                return false;
57                        else
58                                return true;
59                }
60               
61                function get_computer_data($uidnumber)
62                {
63                        $manager_acl = $this->functions->read_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid']);
64                        $manager_contexts = $manager_acl['contexts'];
65                       
66                        foreach ($manager_contexts as $index=>$context)
67                        {
68                                $search = ldap_search($this->ldap_connection, $context, "uidNumber=$uidnumber");
69                                $result = ldap_get_entries($this->ldap_connection, $search);
70                       
71                                if ($result['count'])
72                                {
73                                        // Recupera o DN
74                                        $computer_data['dn'] = $result[0]['dn'];
75                       
76                                        //Recupera o Nome do Computador (CN)
77                                        $computer_data['computer_cn'] = $result[0]['cn'][0];
78
79                                        //Recupera a flag SAMBA
80                                        $computer_data['sambaAcctFlags'] = $result[0]['sambaacctflags'][0];
81                       
82                                        // Recupera a descrição
83                                        $computer_data['computer_description'] = utf8_decode($result[0]['description'][0]);
84                       
85                                        // Recupera o contexto do email_list
86                                        $tmp = explode(",", $computer_data['dn']);
87                                        for ($i = 1; $i < count($tmp); $i++)
88                                                $computer_data['context'] .= $tmp[$i] . ',';
89                                        $computer_data['context'] = substr($computer_data['context'],0,(strlen($computer_data['context']) - 1));
90                       
91                                        $a_tmp = explode("-", $result[0]['sambasid'][0]);
92                                        array_pop($a_tmp);
93                                        $computer_data['sambasid'] = implode("-", $a_tmp);
94                       
95                                        return $computer_data;
96                                }
97                        }
98                }
99               
100                function delete_computer_ldap($dn)
101                {
102                        $result = ldap_delete($this->ldap_connection, $dn);
103                        ldap_close($this->ldap_connection);
104                        return $result;                         
105                }
106               
107                function rename_ldap($old_dn, $new_rdn, $new_context)
108                {
109                        $result = ldap_rename($this->ldap_connection, $old_dn, $new_rdn, $new_context, true);
110                        ldap_close($this->ldap_connection);
111                        return $result;
112                }
113               
114                function ldap_add_attribute($ldap_add_attribute, $dn)
115                {
116                        $result = ldap_mod_add($this->ldap_connection, $dn, $ldap_add_attribute);
117                        ldap_close($this->ldap_connection);
118                        $this->functions->write_log($GLOBALS['phpgw']->accounts->data['account_lid'], 'add attributes in ldap in email list', $dn,'','','');                                           
119                        return $result;
120                }
121               
122                function ldap_remove_attribute($ldap_remove_attribute, $dn)
123                {
124                        $result = ldap_mod_del($this->ldap_connection, $dn, $ldap_remove_attribute);
125                        ldap_close($this->ldap_connection);
126                        //Escreve no log
127                        $this->functions->write_log($GLOBALS['phpgw']->accounts->data['account_lid'], 'remove attributes in ldap in email list', $dn,'','','');                                         
128                        return $result;
129                }
130
131                function ldap_replace_attribute($ldap_replace_attribute, $dn)
132                {
133                        $result = ldap_mod_replace($this->ldap_connection, $dn, $ldap_replace_attribute);
134                        ldap_close($this->ldap_connection);
135                        return $result;
136                }
137        }
138?>
Note: See TracBrowser for help on using the repository browser.