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

Revision 903, 7.2 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 bocomputers
13        {
14                var $public_functions = array(
15                        'create_computer'       => True,
16                        'save_computer'         => True,
17                        'delete_computer'       => True
18                );
19       
20                var $so;
21                var $db_functions;
22                var $functions;
23
24                function bocomputers()
25                {
26                        $this->so = CreateObject('expressoAdminSerpro.socomputers');
27                        $this->functions = $this->so->functions;
28                        $this->db_functions = CreateObject('expressoAdminSerpro.db_functions');
29                }
30
31                function create_computer()
32                {
33                        if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'create_computers'))
34                        {
35                                return false;
36                        }
37               
38                        $c = CreateObject('phpgwapi.config','expressoAdminSerpro');
39                        $c->read_repository();
40                        $current_config = $c->config_data;
41                        // Leio o ID a ser usado na criação do objecto.
42                        $next_id = ($this->db_functions->get_next_id('accounts'));
43                       
44                        if ((!is_numeric($next_id['id'])) || (!$next_id['status']))
45                        {
46                               
47                                $return['status'] = false;
48                                $return['msg'] = "Problemas obtendo ID do usuário.\n" . $id['msg'];
49                                return $return;
50                        }
51                        else
52                        {
53                                $id = $next_id['id'];
54                        }       
55                        // Incrementa o id no BD.
56                        //$this->functions->increment_id($id,'accounts');
57                       
58                        // Cria array para incluir no LDAP
59                        $dn = 'uid=' . $_POST['computer_cn'] . '$,' . $_POST['sector_context'];
60                        $computer_info = array();
61                        $computer_info['uid']                                   = $_POST['computer_cn'] . '$';
62                        $computer_info['cn']                                    = $_POST['computer_cn'];
63                        $computer_info['uidnumber']                             = $id;
64                        $computer_info['gidNumber']                             = $current_config['expressoAdmin_sambaGIDcomputers']; /* nas configurações globais */
65                        $computer_info['homeDirectory']                 = '/dev/null';
66                        $computer_info['objectClass'][0]                = 'posixAccount';
67                        $computer_info['objectClass'][1]                = 'account';
68                        $computer_info['objectClass'][2]                = 'sambaSamAccount';
69                        $computer_info['objectClass'][3]                = 'top';
70                        $computer_info['sambaAcctFlags']                = $_POST['sambaAcctFlags'];
71                        $computer_info['sambaPwdCanChange']             = strtotime("now");
72                        $computer_info['sambaPwdLastSet']               = strtotime("now");
73                        $computer_info['sambaPwdMustChange']    = '2147483647';
74                        $computer_info['sambasid']                              = $_POST['sambasid'] . '-' . ((2 * (int)$id)+1000);
75                       
76                        /* Trust Account */
77                        if ($_POST['sambaAcctFlags'] == '[I          ]')
78                        {
79                                if (!is_file('/home/expressolivre/mkntpwd'))
80                                {
81                                        $_POST['error_messages'] = "O arquivo binário /home/expressolivre/mkntpwd não exite.\\nEle é necessário para a criação das senhas usadas pelo SAMBA.\\nInforme o administrador ExpressoLivre sobre isto.";
82                                        ExecMethod('expressoAdminSerpro.uiaccounts.add_computer');
83                                        return false;
84                                }
85                                $computer_info['sambaNTPassword']       = exec('/home/expressolivre/mkntpwd -L '.$_POST['computer_password']);
86                                $computer_info['sambaLMPassword']       = exec('/home/expressolivre/mkntpwd -N '.$_POST['computer_password']);
87                        }
88                       
89                        if ($_POST['computer_description'] != '')
90                                $computer_info['description'] = utf8_encode($_POST['computer_description']);
91                       
92                        // Chama funcao para escrever no OpenLDAP, case de erro, volta com msg de erro.
93                        if (!$this->so->write_ldap($dn, $computer_info))
94                        {
95                                $_POST['error_messages'] = lang('Error in OpenLDAP recording computer.');
96                                ExecMethod('expressoAdminSerpro.uicomputers.add_computer');
97                                return false;
98                        }
99                       
100                        // Volta para o ListGroups
101                        $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdminSerpro.uicomputers.list_computers'));
102                        $GLOBALS['phpgw']->redirect($url);
103                }
104               
105                function save_computer()
106                {
107                        $old_dn                 = $_POST['old_computer_dn'];
108                        $new_rdn                = 'uid=' . $_POST['computer_cn'] . '$';
109                        $new_context    = $_POST['sector_context'];
110                        $new_dn                 = $new_rdn . ',' . $new_context;
111
112                         // Chama funcao para renomar no OpenLDAP, case de erro, volta com msg de erro.
113                        if (($_POST['old_computer_cn'] != $_POST['computer_cn']) || ($_POST['old_computer_context'] != $_POST['sector_context']))
114                        {
115                                if (!$this->so->rename_ldap($old_dn, $new_rdn, $new_context))
116                                {
117                                        $_POST['error_messages'] = lang('Error in OpenLDAP rename Computer');
118                                        ExecMethod('expressoAdminSerpro.uicomputers.edit_computer');
119                                        return false;
120                                }
121                                else
122                                {
123                                        $computer_mod_replace['cn'] = utf8_encode($_POST['computer_cn']);       
124                                }
125                        }
126
127                        //Verifica se a descrição do computador foi alterada.
128                        if (($_POST['computer_description'] == '') && ($_POST['old_computer_description'] == '')){}
129                        elseif ($_POST['computer_description'] == $_POST['old_computer_description']){}
130                        elseif (($_POST['old_computer_description'] != '') && ($_POST['computer_description'] == ''))
131                        {
132                                $computer_mod_remove['descriptions'] = $_POST['old_computer_description'];
133                        }
134                        elseif (($_POST['old_computer_description'] == '') && ($_POST['computer_description'] != ''))
135                        {
136                                $computer_mod_add['description'] = utf8_encode($_POST['computer_description']);
137                        }
138                        elseif ($_POST['computer_description'] != $_POST['old_computer_description'])
139                        {
140                                $computer_mod_replace['description'] = utf8_encode($_POST['computer_description']);
141                        }
142
143
144                        if ($_POST['sambaAcctFlags'] != $_POST['old_computer_sambaAcctFlags'])
145                        {
146                                $computer_mod_replace['sambaAcctFlags'] = $_POST['sambaAcctFlags'];
147                        }
148                       
149                        if ($_POST['computer_password'] != '')
150                        {
151                                $computer_mod_replace['sambaNTPassword']        = exec('/home/expressolivre/mkntpwd -L '.$_POST['computer_password']);
152                                $computer_mod_replace['sambaLMPassword']        = exec('/home/expressolivre/mkntpwd -N '.$_POST['computer_password']);
153                        }
154
155                        if ($_POST['sambasid'] != $_POST['old_sambasid'])
156                        {
157                                $computer_mod_replace['sambasid'] = $_POST['sambasid'] . '-' . ((2 * (int)$_POST['uidnumber'])+1000);
158                        }
159
160                       
161                        if (count($computer_mod_add) != 0)
162                                $this->so->ldap_add_attribute($computer_mod_add, $new_dn);
163
164                        if (count($computer_mod_remove) != 0)
165                                $this->so->ldap_remove_attribute($computer_mod_remove, $new_dn);
166
167                        if (count($computer_mod_replace) != 0)
168                                $this->so->ldap_replace_attribute($computer_mod_replace, $new_dn);
169
170                        // Volta para o ListGroups
171                        $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdminSerpro.uicomputers.list_computers'));
172                        $GLOBALS['phpgw']->redirect($url);
173                }
174               
175                function delete_computer()
176                {
177                        //Delete from ldap.
178                        if (!$this->so->delete_computer_ldap($_POST['computer_dn']))
179                                {
180                                        $_POST['error_messages'] = lang('Error deleting Computer in OpenLDAP.');
181                                        ExecMethod('expressoAdminSerpro.uicomputers.list_computers');
182                                        return false;
183                                }
184                       
185                        // Volta para o ListGroups
186                        $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdminSerpro.uicomputers.list_computers'));
187                        $GLOBALS['phpgw']->redirect($url);
188                }
189        }
190?>
Note: See TracBrowser for help on using the repository browser.