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

Revision 27, 6.8 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

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