source: trunk/expressoAdmin1_2/inc/class.bocomputers.inc.php @ 705

Revision 705, 7.2 KB checked in by niltonneto, 15 years ago (diff)

Correção de problema. Atributos sambaLMPassword e sambaNTPassword estavam invertidos.

  • 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 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('expressoAdmin1_2.socomputers');
27                        $this->functions = $this->so->functions;
28                        $this->db_functions = CreateObject('expressoAdmin1_2.db_functions');
29                }
30
31                function create_computer()
32                {
33                        if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'create_computers'))
34                        {
35                                return false;
36                        }
37               
38                        $c = CreateObject('phpgwapi.config','expressoAdmin1_2');
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'] = lang('problems getting user id') . ".\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'] =
82                                                lang("the binary file /home/expressolivre/mkntpwd does not exist") . ".\\n" .
83                                                lang("it is needed to create samba passwords") . ".\\n" .
84                                                lang("alert your administrator about this") . ".";
85                                       
86                                        ExecMethod('expressoAdmin1_2.uiaccounts.add_computer');
87                                        return false;
88                                }
89                                $computer_info['sambaLMPassword']       = exec('/home/expressolivre/mkntpwd -L "' . $_POST['computer_password']. '"');
90                                $computer_info['sambaNTPassword']       = exec('/home/expressolivre/mkntpwd -N "' . $_POST['computer_password']. '"');
91                        }
92                       
93                        if ($_POST['computer_description'] != '')
94                                $computer_info['description'] = utf8_encode($_POST['computer_description']);
95                       
96                        // Chama funcao para escrever no OpenLDAP, case de erro, volta com msg de erro.
97                        if (!$this->so->write_ldap($dn, $computer_info))
98                        {
99                                $_POST['error_messages'] = lang('Error in OpenLDAP recording computer.');
100                                ExecMethod('expressoAdmin1_2.uicomputers.add_computer');
101                                return false;
102                        }
103                       
104                        // Volta para o ListGroups
105                        $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uicomputers.list_computers'));
106                        $GLOBALS['phpgw']->redirect($url);
107                }
108               
109                function save_computer()
110                {
111                        $old_dn                 = $_POST['old_computer_dn'];
112                        $new_rdn                = 'uid=' . $_POST['computer_cn'] . '$';
113                        $new_context    = $_POST['sector_context'];
114                        $new_dn                 = $new_rdn . ',' . $new_context;
115
116                         // Chama funcao para renomar no OpenLDAP, case de erro, volta com msg de erro.
117                        if (($_POST['old_computer_cn'] != $_POST['computer_cn']) || ($_POST['old_computer_context'] != $_POST['sector_context']))
118                        {
119                                if (!$this->so->rename_ldap($old_dn, $new_rdn, $new_context))
120                                {
121                                        $_POST['error_messages'] = lang('Error in OpenLDAP rename Computer');
122                                        ExecMethod('expressoAdmin1_2.uicomputers.edit_computer');
123                                        return false;
124                                }
125                                else
126                                {
127                                        $computer_mod_replace['cn'] = utf8_encode($_POST['computer_cn']);       
128                                }
129                        }
130
131                        //Verifica se a descrição do computador foi alterada.
132                        if (($_POST['computer_description'] == '') && ($_POST['old_computer_description'] == '')){}
133                        elseif ($_POST['computer_description'] == $_POST['old_computer_description']){}
134                        elseif (($_POST['old_computer_description'] != '') && ($_POST['computer_description'] == ''))
135                        {
136                                $computer_mod_remove['descriptions'] = $_POST['old_computer_description'];
137                        }
138                        elseif (($_POST['old_computer_description'] == '') && ($_POST['computer_description'] != ''))
139                        {
140                                $computer_mod_add['description'] = utf8_encode($_POST['computer_description']);
141                        }
142                        elseif ($_POST['computer_description'] != $_POST['old_computer_description'])
143                        {
144                                $computer_mod_replace['description'] = utf8_encode($_POST['computer_description']);
145                        }
146
147
148                        if ($_POST['sambaAcctFlags'] != $_POST['old_computer_sambaAcctFlags'])
149                        {
150                                $computer_mod_replace['sambaAcctFlags'] = $_POST['sambaAcctFlags'];
151                        }
152                       
153                        if ($_POST['computer_password'] != '')
154                        {
155                                $computer_mod_replace['sambaLMPassword']        = exec('/home/expressolivre/mkntpwd -L "'.$_POST['computer_password'] . '"');
156                                $computer_mod_replace['sambaNTPassword']        = exec('/home/expressolivre/mkntpwd -N "'.$_POST['computer_password'] . '"');
157                        }
158
159                        if ($_POST['sambasid'] != $_POST['old_sambasid'])
160                        {
161                                $computer_mod_replace['sambasid'] = $_POST['sambasid'] . '-' . ((2 * (int)$_POST['uidnumber'])+1000);
162                        }
163
164                       
165                        if (count($computer_mod_add) != 0)
166                                $this->so->ldap_add_attribute($computer_mod_add, $new_dn);
167
168                        if (count($computer_mod_remove) != 0)
169                                $this->so->ldap_remove_attribute($computer_mod_remove, $new_dn);
170
171                        if (count($computer_mod_replace) != 0)
172                                $this->so->ldap_replace_attribute($computer_mod_replace, $new_dn);
173
174                        // Volta para o ListGroups
175                        $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uicomputers.list_computers'));
176                        $GLOBALS['phpgw']->redirect($url);
177                }
178               
179                function delete_computer()
180                {
181                        //Delete from ldap.
182                        if (!$this->so->delete_computer_ldap($_POST['computer_dn']))
183                                {
184                                        $_POST['error_messages'] = lang('Error deleting Computer in OpenLDAP.');
185                                        ExecMethod('expressoAdmin1_2.uicomputers.list_computers');
186                                        return false;
187                                }
188                       
189                        // Volta para o ListGroups
190                        $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uicomputers.list_computers'));
191                        $GLOBALS['phpgw']->redirect($url);
192                }
193        }
194?>
Note: See TracBrowser for help on using the repository browser.