source: companies/serpro/expressoAdminSerpro/inc/class.socomputers.inc.php @ 903

Revision 903, 4.3 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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               
16                function socomputers()
17                {
18                        $this->functions = CreateObject('expressoAdminSerpro.functions');
19                }
20
21                function write_ldap($dn, $info)
22                {
23                        $connection = $GLOBALS['phpgw']->common->ldapConnect();
24                       
25                        if (ldap_add($connection, $dn, $info))
26                        {
27                                ldap_close($connection);
28                                return true;
29                        }
30                        else
31                        {
32                                echo 'Erro na escrita no LDAP, funcao so->write_ldap';
33                                ldap_close($connection);
34                                return false;
35                        }
36                }
37               
38                function exist_computer_uid($computer_cn)
39                {
40                        $connection = $GLOBALS['phpgw']->common->ldapConnect();
41                        $search = ldap_search($connection, $GLOBALS['phpgw_info']['server']['ldap_context'], "uid=" . $computer_cn . '$');
42                        $result = ldap_get_entries($connection, $search);
43                        if ($result['count'] == 0)
44                                return false;
45                        else
46                                return true;
47                }
48               
49                function get_computer_data($uidnumber)
50                {
51                        $manager_acl = $this->functions->read_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid']);
52                        $manager_contexts = $manager_acl['contexts'];
53                        $connection = $GLOBALS['phpgw']->common->ldapConnect();
54                       
55                        foreach ($manager_contexts as $index=>$context)
56                        {
57                                $search = ldap_search($connection, $context, "uidNumber=$uidnumber");
58                                $result = ldap_get_entries($connection, $search);
59                       
60                                if ($result['count'])
61                                {
62                                        // Recupera o DN
63                                        $computer_data['dn'] = $result[0]['dn'];
64                       
65                                        //Recupera o Nome do Computador (CN)
66                                        $computer_data['computer_cn'] = $result[0]['cn'][0];
67
68                                        //Recupera a flag SAMBA
69                                        $computer_data['sambaAcctFlags'] = $result[0]['sambaacctflags'][0];
70                       
71                                        // Recupera a descrição
72                                        $computer_data['computer_description'] = utf8_decode($result[0]['description'][0]);
73                       
74                                        // Recupera o contexto do email_list
75                                        $tmp = explode(",", $computer_data['dn']);
76                                        for ($i = 1; $i < count($tmp); $i++)
77                                                $computer_data['context'] .= $tmp[$i] . ',';
78                                        $computer_data['context'] = substr($computer_data['context'],0,(strlen($computer_data['context']) - 1));
79                       
80                                        $a_tmp = explode("-", $result[0]['sambasid'][0]);
81                                        array_pop($a_tmp);
82                                        $computer_data['sambasid'] = implode("-", $a_tmp);
83                       
84                                        return $computer_data;
85                                }
86                        }
87                }
88               
89                function delete_computer_ldap($dn)
90                {
91                        $connection = $GLOBALS['phpgw']->common->ldapConnect();
92                        $result = ldap_delete($connection, $dn);
93                        ldap_close($connection);
94                        return $result;                         
95                }
96               
97                function rename_ldap($old_dn, $new_rdn, $new_context)
98                {
99                        $connection = $GLOBALS['phpgw']->common->ldapConnect();
100                        $result = ldap_rename($connection, $old_dn, $new_rdn, $new_context, true);
101                        ldap_close($connection);
102                        return $result;
103                }
104               
105                function ldap_add_attribute($ldap_add_attribute, $dn)
106                {
107                        $connection = $GLOBALS['phpgw']->common->ldapConnect();
108                        $result = ldap_mod_add($connection, $dn, $ldap_add_attribute);
109                        ldap_close($connection);
110                        //Escreve no log
111                        $this->functions->write_log($GLOBALS['phpgw']->accounts->data['account_lid'], 'add attributes in ldap in email list', $dn,'','','');                                           
112                        return $result;
113                }
114               
115                function ldap_remove_attribute($ldap_remove_attribute, $dn)
116                {
117                        $connection = $GLOBALS['phpgw']->common->ldapConnect();
118                        $result = ldap_mod_del($connection, $dn, $ldap_remove_attribute);
119                        ldap_close($connection);
120                        //Escreve no log
121                        $this->functions->write_log($GLOBALS['phpgw']->accounts->data['account_lid'], 'remove attributes in ldap in email list', $dn,'','','');                                         
122                        return $result;
123                }
124
125                function ldap_replace_attribute($ldap_replace_attribute, $dn)
126                {
127                        $connection = $GLOBALS['phpgw']->common->ldapConnect();
128                        $result = ldap_mod_replace($connection, $dn, $ldap_replace_attribute);
129                        ldap_close($connection);
130                        return $result;
131                }
132        }
133?>
Note: See TracBrowser for help on using the repository browser.