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 | include_once('class.ldap_functions.inc.php'); |
---|
13 | include_once('class.db_functions.inc.php'); |
---|
14 | include_once('class.imap_functions.inc.php'); |
---|
15 | include_once('class.functions.inc.php'); |
---|
16 | |
---|
17 | class user |
---|
18 | { |
---|
19 | var $ldap_functions; |
---|
20 | var $db_functions; |
---|
21 | var $imap_functions; |
---|
22 | var $functions; |
---|
23 | var $current_config; |
---|
24 | |
---|
25 | function user() |
---|
26 | { |
---|
27 | $this->ldap_functions = new ldap_functions; |
---|
28 | $this->db_functions = new db_functions; |
---|
29 | $this->imap_functions = new imap_functions; |
---|
30 | $this->functions = new functions; |
---|
31 | $this->current_config = $_SESSION['phpgw_info']['expresso']['expressoAdmin']; |
---|
32 | } |
---|
33 | |
---|
34 | function create($params) |
---|
35 | { |
---|
36 | $return['status'] = true; |
---|
37 | |
---|
38 | if($this->db_functions->use_cota_control()) { |
---|
39 | //Verifica quota de usuários e disco |
---|
40 | $setor = $this->functions->get_info($params['context']); |
---|
41 | if (!$this->functions->existe_quota_usuario($setor[0])) { |
---|
42 | $return['status'] = false; |
---|
43 | $return['msg'] = $this->functions->lang("user cota exceeded");//TODO colocar valor de acordo com tabela de traduções. |
---|
44 | return $return; |
---|
45 | } |
---|
46 | if (!$this->functions->existe_quota_disco($setor[0],$params['mailquota'])) { |
---|
47 | $return['status'] = false; |
---|
48 | $return['msg'] = $this->functions->lang("disk cota exceeded");//TODO colocar valor de acordo com tabela de traduções. |
---|
49 | return $return; |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | // Verifica o acesso do gerente |
---|
54 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'add_users')) |
---|
55 | { |
---|
56 | // Adiciona a organização na frente do uid. |
---|
57 | if ($this->current_config['expressoAdmin_prefix_org'] == 'true') |
---|
58 | { |
---|
59 | $context_dn = ldap_explode_dn(strtolower($GLOBALS['phpgw_info']['server']['ldap_context']), 1); |
---|
60 | |
---|
61 | $explode_dn = ldap_explode_dn(strtolower($params['context']), 1); |
---|
62 | $explode_dn = array_reverse($explode_dn); |
---|
63 | //$params['uid'] = $explode_dn[3] . '-' . $params['uid']; |
---|
64 | $params['uid'] = $explode_dn[$context_dn['count']] . '-' . $params['uid']; |
---|
65 | } |
---|
66 | |
---|
67 | // Leio o ID a ser usado na criação do objecto. Esta função já incrementa o ID no BD. |
---|
68 | $next_id = ($this->db_functions->get_next_id('accounts')); |
---|
69 | if ((!is_numeric($next_id['id'])) || (!$next_id['status'])) |
---|
70 | { |
---|
71 | $return['status'] = false; |
---|
72 | $return['msg'] = $this->functions->lang('problems getting user id') . ".\n" . $id['msg']; |
---|
73 | return $return; |
---|
74 | } |
---|
75 | else |
---|
76 | { |
---|
77 | $id = $next_id['id']; |
---|
78 | } |
---|
79 | |
---|
80 | // Cria array para incluir no LDAP |
---|
81 | $dn = 'uid=' . $params['uid'] . ',' . $params['context']; |
---|
82 | |
---|
83 | $user_info = array(); |
---|
84 | $user_info['accountStatus'] = $params['accountstatus'] == 1 ? 'active' : 'desactive'; |
---|
85 | $user_info['cn'] = $params['givenname'] . ' ' . $params['sn']; |
---|
86 | $user_info['gidNumber'] = $params['gidnumber']; |
---|
87 | $user_info['givenName'] = $params['givenname']; |
---|
88 | $user_info['homeDirectory'] = '/home/' . $params['uid']; |
---|
89 | $user_info['mail'] = $params['mail']; |
---|
90 | $user_info['objectClass'][] = 'posixAccount'; |
---|
91 | $user_info['objectClass'][] = 'inetOrgPerson'; |
---|
92 | $user_info['objectClass'][] = 'shadowAccount'; |
---|
93 | $user_info['objectClass'][] = 'qmailuser'; |
---|
94 | $user_info['objectClass'][] = 'phpgwAccount'; |
---|
95 | $user_info['objectClass'][] = 'top'; |
---|
96 | $user_info['objectClass'][] = 'person'; |
---|
97 | $user_info['objectClass'][] = 'organizationalPerson'; |
---|
98 | $user_info['phpgwAccountExpires'] = '-1'; |
---|
99 | $user_info['phpgwAccountType'] = 'u'; |
---|
100 | $user_info['sn'] = $params['sn']; |
---|
101 | $user_info['uid'] = $params['uid']; |
---|
102 | $user_info['uidnumber'] = $id; |
---|
103 | $user_info['userPassword'] = '{md5}' . base64_encode(pack("H*",md5($params['password1']))); |
---|
104 | |
---|
105 | if ($params['passwd_expired'] == '1') |
---|
106 | $user_info['phpgwLastPasswdChange'] = '0'; |
---|
107 | |
---|
108 | // Gerenciar senhas RFC2617 |
---|
109 | if ($this->current_config['expressoAdmin_userPasswordRFC2617'] == 'true') |
---|
110 | { |
---|
111 | $realm = $this->current_config['expressoAdmin_realm_userPasswordRFC2617']; |
---|
112 | $uid = $user_info['uid']; |
---|
113 | $password = $params['password1']; |
---|
114 | $user_info['userPasswordRFC2617'] = $realm . ': ' . md5("$uid:$realm:$password"); |
---|
115 | } |
---|
116 | |
---|
117 | if ($params['phpgwaccountstatus'] == '1') |
---|
118 | $user_info['phpgwAccountStatus'] = 'A'; |
---|
119 | |
---|
120 | if ($params['departmentnumber'] != '') |
---|
121 | $user_info['departmentnumber'] = $params['departmentnumber']; |
---|
122 | |
---|
123 | if ($params['telephonenumber'] != '') |
---|
124 | $user_info['telephoneNumber'] = $params['telephonenumber']; |
---|
125 | |
---|
126 | // Cria user_info no caso de ter alias e forwarding email. |
---|
127 | foreach ($params['mailalternateaddress'] as $index=>$mailalternateaddress) |
---|
128 | { |
---|
129 | if ($mailalternateaddress != '') |
---|
130 | $user_info['mailAlternateAddress'][] = $mailalternateaddress; |
---|
131 | } |
---|
132 | |
---|
133 | foreach ($params['mailforwardingaddress'] as $index=>$mailforwardingaddress) |
---|
134 | { |
---|
135 | if ($mailforwardingaddress != '') |
---|
136 | $user_info['mailForwardingAddress'][] = $mailforwardingaddress; |
---|
137 | } |
---|
138 | |
---|
139 | if ($params['deliverymode']) |
---|
140 | $user_info['deliveryMode'] = 'forwardOnly'; |
---|
141 | |
---|
142 | //Ocultar da pesquisa e do catálogo |
---|
143 | if ($params['phpgwaccountvisible']) |
---|
144 | $user_info['phpgwAccountVisible'] = '-1'; |
---|
145 | |
---|
146 | // Suporte ao SAMBA |
---|
147 | if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($params['use_attrs_samba'] == 'on')) |
---|
148 | { |
---|
149 | |
---|
150 | // Qualquer um que crie um usuário, deve ter permissão para adicionar a senha samba. |
---|
151 | // Verifica o acesso do gerente aos atributos samba |
---|
152 | //if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_sambausers_attributes')) |
---|
153 | //{ |
---|
154 | //Verifica se o binario para criar as senhas do samba exite. |
---|
155 | if (!is_file('/home/expressolivre/mkntpwd')) |
---|
156 | { |
---|
157 | $return['status'] = false; |
---|
158 | $return['msg'] .= |
---|
159 | $this->functions->lang("the binary file /home/expressolivre/mkntpwd does not exist") . ".\\n" . |
---|
160 | $this->functions->lang("it is needed to create samba passwords") . ".\\n" . |
---|
161 | $this->functions->lang("alert your administrator about this") . "."; |
---|
162 | } |
---|
163 | else |
---|
164 | { |
---|
165 | $user_info['objectClass'][] = 'sambaSamAccount'; |
---|
166 | $user_info['loginShell'] = '/bin/bash'; |
---|
167 | |
---|
168 | $user_info['sambaSID'] = $params['sambadomain'] . '-' . ((2 * $id)+1000); |
---|
169 | $user_info['sambaPrimaryGroupSID'] = $params['sambadomain'] . '-' . ((2 * $user_info['gidNumber'])+1001); |
---|
170 | |
---|
171 | $user_info['sambaAcctFlags'] = $params['sambaacctflags']; |
---|
172 | |
---|
173 | $user_info['sambaLogonScript'] = $params['sambalogonscript']; |
---|
174 | $user_info['homeDirectory'] = $params['sambahomedirectory']; |
---|
175 | |
---|
176 | $user_info['sambaLMPassword'] = exec('/home/expressolivre/mkntpwd -L "'.$params['password1'] . '"'); |
---|
177 | $user_info['sambaNTPassword'] = exec('/home/expressolivre/mkntpwd -N "'.$params['password1'] . '"'); |
---|
178 | |
---|
179 | $user_info['sambaPasswordHistory'] = '0000000000000000000000000000000000000000000000000000000000000000'; |
---|
180 | |
---|
181 | $user_info['sambaPwdCanChange'] = strtotime("now"); |
---|
182 | $user_info['sambaPwdLastSet'] = strtotime("now"); |
---|
183 | $user_info['sambaPwdMustChange'] = '2147483647'; |
---|
184 | } |
---|
185 | //} |
---|
186 | } |
---|
187 | |
---|
188 | // Verifica o acesso do gerente aos atributos corporativos |
---|
189 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'manipulate_corporative_information')) |
---|
190 | { |
---|
191 | //retira caracteres que não são números. |
---|
192 | $params['corporative_information_cpf'] = ereg_replace("[^0-9]", "", $params['corporative_information_cpf']); |
---|
193 | //description |
---|
194 | $params['corporative_information_description'] = utf8_encode($params['corporative_information_description']); |
---|
195 | foreach ($params as $atribute=>$value) |
---|
196 | { |
---|
197 | $pos = strstr($atribute, 'corporative_information_'); |
---|
198 | if ($pos !== false) |
---|
199 | { |
---|
200 | if ($params[$atribute]) |
---|
201 | { |
---|
202 | $ldap_atribute = str_replace("corporative_information_", "", $atribute); |
---|
203 | $user_info[$ldap_atribute] = $params[$atribute]; |
---|
204 | } |
---|
205 | } |
---|
206 | } |
---|
207 | } |
---|
208 | |
---|
209 | $result = $this->ldap_functions->ldap_add_entry($dn, $user_info); |
---|
210 | if (!$result['status']) |
---|
211 | { |
---|
212 | $return['status'] = false; |
---|
213 | $return['msg'] .= $result['msg']; |
---|
214 | } |
---|
215 | |
---|
216 | // Chama funcao para salvar foto no OpenLDAP. |
---|
217 | if ( ($_FILES['photo']['name'] != '') && ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users_picture')) ) |
---|
218 | { |
---|
219 | $result = $this->ldap_functions->ldap_save_photo($dn, $_FILES['photo']['tmp_name']); |
---|
220 | if (!$result['status']) |
---|
221 | { |
---|
222 | $return['status'] = false; |
---|
223 | $return['msg'] .= $result['msg']; |
---|
224 | } |
---|
225 | } |
---|
226 | |
---|
227 | //GROUPS |
---|
228 | if ($params['groups']) |
---|
229 | { |
---|
230 | foreach ($params['groups'] as $gidnumber) |
---|
231 | { |
---|
232 | $result = $this->ldap_functions->add_user2group($gidnumber, $user_info['uid']); |
---|
233 | if (!$result['status']) |
---|
234 | { |
---|
235 | $return['status'] = false; |
---|
236 | $return['msg'] .= $result['msg']; |
---|
237 | } |
---|
238 | $result = $this->db_functions->add_user2group($gidnumber, $id); |
---|
239 | if (!$result['status']) |
---|
240 | { |
---|
241 | $return['status'] = false; |
---|
242 | $return['msg'] .= $result['msg']; |
---|
243 | } |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | // Inclusao do Mail do usuário nas listas de email selecionadas. |
---|
248 | if ($params['maillists']) |
---|
249 | { |
---|
250 | foreach($params['maillists'] as $uid) |
---|
251 | { |
---|
252 | $result = $this->ldap_functions->add_user2maillist($uid, $user_info['mail']); |
---|
253 | if (!$result['status']) |
---|
254 | { |
---|
255 | $return['status'] = false; |
---|
256 | $return['msg'] .= $result['msg']; |
---|
257 | } |
---|
258 | } |
---|
259 | } |
---|
260 | |
---|
261 | // APPS |
---|
262 | if (count($params['apps'])) |
---|
263 | { |
---|
264 | $result = $this->db_functions->add_id2apps($id, $params['apps']); |
---|
265 | if (!$result['status']) |
---|
266 | { |
---|
267 | $return['status'] = false; |
---|
268 | $return['msg'] .= $result['msg']; |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | // Chama funcao para incluir no pgsql as preferencia de alterar senha. |
---|
273 | if ($params['changepassword']) |
---|
274 | { |
---|
275 | $result = $this->db_functions->add_pref_changepassword($id); |
---|
276 | if (!$result['status']) |
---|
277 | { |
---|
278 | $return['status'] = false; |
---|
279 | $return['msg'] .= $result['msg']; |
---|
280 | } |
---|
281 | } |
---|
282 | |
---|
283 | // Chama funcao para criar mailbox do usuario, no imap-cyrus. |
---|
284 | $result = $this->imap_functions->create($params['uid'], $params['mailquota']); |
---|
285 | if (!$result['status']) |
---|
286 | { |
---|
287 | $return['status'] = false; |
---|
288 | $return['msg'] .= $result['msg']; |
---|
289 | } |
---|
290 | |
---|
291 | $this->db_functions->write_log("created user",$dn); |
---|
292 | } |
---|
293 | |
---|
294 | return $return; |
---|
295 | } |
---|
296 | |
---|
297 | function save($new_values) |
---|
298 | { |
---|
299 | $return['status'] = true; |
---|
300 | |
---|
301 | $old_values = $this->get_user_info($new_values['uidnumber']); |
---|
302 | |
---|
303 | $dn = 'uid=' . $old_values['uid'] . ',' . strtolower($old_values['context']); |
---|
304 | |
---|
305 | //retira caracteres que não são números. |
---|
306 | $new_values['corporative_information_cpf'] = ereg_replace("[^0-9]", "", $new_values['corporative_information_cpf']); |
---|
307 | |
---|
308 | $diff = array_diff($new_values, $old_values); |
---|
309 | |
---|
310 | /* |
---|
311 | echo '<pre>'; |
---|
312 | echo '--- OLD: '; |
---|
313 | print_r($old_values); |
---|
314 | echo '<br>--- NEW: '; |
---|
315 | print_r($new_values); |
---|
316 | echo '<br>'; |
---|
317 | exit; |
---|
318 | */ |
---|
319 | |
---|
320 | //Verifica quota de disco, como estou alterando, não preciso checar quota de usuários. |
---|
321 | if($this->db_functions->use_cota_control()) { |
---|
322 | $setor = $this->functions->get_info($new_values['context']); |
---|
323 | if (!$this->functions->existe_quota_disco($setor[0],$new_values['mailquota'])) { |
---|
324 | $return['status'] = false; |
---|
325 | $return['msg'] = "Quota em disco excedida...";//TODO colocar valor de acordo com tabela de traduções. |
---|
326 | return $return; |
---|
327 | } |
---|
328 | } |
---|
329 | |
---|
330 | $manager_account_lid = $_SESSION['phpgw_session']['session_lid']; |
---|
331 | if ((!$this->functions->check_acl($manager_account_lid,'edit_users')) && |
---|
332 | (!$this->functions->check_acl($manager_account_lid,'change_users_password')) && |
---|
333 | (!$this->functions->check_acl($manager_account_lid,'edit_sambausers_attributes')) && |
---|
334 | (!$this->functions->check_acl($manager_account_lid,'manipulate_corporative_information')) && |
---|
335 | (!$this->functions->check_acl($manager_account_lid,'edit_users_phonenumber')) |
---|
336 | ) |
---|
337 | { |
---|
338 | $return['status'] = false; |
---|
339 | $return['msg'] = $this->functions->lang('You do not have access to edit user informations') . '.'; |
---|
340 | return $return; |
---|
341 | } |
---|
342 | |
---|
343 | // Check manager access |
---|
344 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) |
---|
345 | { |
---|
346 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
347 | // Change user organization |
---|
348 | if ($diff['context']) |
---|
349 | { |
---|
350 | if (strcasecmp($old_values['context'], $new_values['context']) != 0) |
---|
351 | { |
---|
352 | $newrdn = 'uid=' . $new_values['uid']; |
---|
353 | $newparent = $new_values['context']; |
---|
354 | $result = $this->ldap_functions->change_user_context($dn, $newrdn, $newparent); |
---|
355 | if (!$result['status']) |
---|
356 | { |
---|
357 | $return['status'] = false; |
---|
358 | $return['msg'] .= $result['msg']; |
---|
359 | } |
---|
360 | else |
---|
361 | { |
---|
362 | $dn = $newrdn . ',' . $newparent; |
---|
363 | $this->db_functions->write_log('modified user context', $dn . ': ' . $old_values['uid'] . '->' . $new_values['context']); |
---|
364 | } |
---|
365 | } |
---|
366 | } |
---|
367 | |
---|
368 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
369 | // REPLACE some attributes |
---|
370 | if ($diff['givenname']) |
---|
371 | { |
---|
372 | $ldap_mod_replace['givenname'] = $new_values['givenname']; |
---|
373 | $ldap_mod_replace['cn'] = $new_values['givenname'] . ' ' . $new_values['sn']; |
---|
374 | $this->db_functions->write_log("modified first name", "$dn: " . $old_values['givenname'] . "->" . $new_values['givenname']); |
---|
375 | } |
---|
376 | if ($diff['sn']) |
---|
377 | { |
---|
378 | $ldap_mod_replace['sn'] = $new_values['sn']; |
---|
379 | $ldap_mod_replace['cn'] = $new_values['givenname'] . ' ' . $new_values['sn']; |
---|
380 | $this->db_functions->write_log("modified last name", "$dn: " . $old_values['sn'] . "->" . $new_values['sn']); |
---|
381 | } |
---|
382 | if ($diff['mail']) |
---|
383 | { |
---|
384 | $ldap_mod_replace['mail'] = $new_values['mail']; |
---|
385 | $this->ldap_functions->replace_user2maillists($new_values['mail'], $old_values['mail']); |
---|
386 | $this->ldap_functions->replace_mail_from_institutional_account($new_values['mail'], $old_values['mail']); |
---|
387 | $this->db_functions->write_log("modified user email", "$dn: " . $old_values['mail'] . "->" . $new_values['mail']); |
---|
388 | } |
---|
389 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
390 | // Passwd Expired - Com atributo |
---|
391 | if (($old_values['passwd_expired'] != 0) && ($new_values['passwd_expired'] == '1')) |
---|
392 | { |
---|
393 | $ldap_mod_replace['phpgwlastpasswdchange'] = '0'; |
---|
394 | $this->db_functions->write_log("Expired user password","$dn"); |
---|
395 | } |
---|
396 | } |
---|
397 | |
---|
398 | if ( ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) || |
---|
399 | ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'change_users_password')) ) |
---|
400 | { |
---|
401 | if ($diff['password1']) |
---|
402 | { |
---|
403 | $ldap_mod_replace['userPassword'] = '{md5}' . base64_encode(pack("H*",md5($new_values['password1']))); |
---|
404 | |
---|
405 | // Suporte ao SAMBA |
---|
406 | if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($new_values['userSamba']) && ($new_values['use_attrs_samba'] == 'on')) |
---|
407 | { |
---|
408 | $ldap_mod_replace['sambaLMPassword'] = exec('/home/expressolivre/mkntpwd -L "'.$new_values['password1'] . '"'); |
---|
409 | $ldap_mod_replace['sambaNTPassword'] = exec('/home/expressolivre/mkntpwd -N "'.$new_values['password1'] . '"'); |
---|
410 | } |
---|
411 | |
---|
412 | // Gerenciar senhas RFC2617 |
---|
413 | if ($this->current_config['expressoAdmin_userPasswordRFC2617'] == 'true') |
---|
414 | { |
---|
415 | $realm = $this->current_config['expressoAdmin_realm_userPasswordRFC2617']; |
---|
416 | $uid = $new_values['uid']; |
---|
417 | $password = $new_values['password1']; |
---|
418 | $passUserRFC2617 = $realm . ': ' . md5("$uid:$realm:$password"); |
---|
419 | |
---|
420 | if ($old_values['userPasswordRFC2617'] != '') |
---|
421 | $ldap_mod_replace['userPasswordRFC2617'] = $passUserRFC2617; |
---|
422 | else |
---|
423 | $ldap_add['userPasswordRFC2617'] = $passUserRFC2617; |
---|
424 | } |
---|
425 | |
---|
426 | $this->db_functions->write_log("modified user password",$dn); |
---|
427 | } |
---|
428 | } |
---|
429 | |
---|
430 | if ( ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) || |
---|
431 | ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users_phonenumber')) ) |
---|
432 | { |
---|
433 | if (($diff['telephonenumber']) && ($old_values['telephonenumber'] != '')) |
---|
434 | { |
---|
435 | $ldap_mod_replace['telephonenumber'] = $new_values['telephonenumber']; |
---|
436 | $this->db_functions->write_log('modified user telephonenumber', $dn . ': ' . $old_values['telephonenumber'] . '->' . $new_values['telephonenumber']); |
---|
437 | } |
---|
438 | } |
---|
439 | |
---|
440 | // REPLACE, ADD & REMOVE COPORATIVEs ATRIBUTES |
---|
441 | // Verifica o acesso do gerente aos atributos corporativos |
---|
442 | |
---|
443 | if ( ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) || |
---|
444 | ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'manipulate_corporative_information')) ) |
---|
445 | { |
---|
446 | foreach ($new_values as $atribute=>$value) |
---|
447 | { |
---|
448 | $pos = strstr($atribute, 'corporative_information_'); |
---|
449 | if ($pos !== false) |
---|
450 | { |
---|
451 | $ldap_atribute = str_replace("corporative_information_", "", $atribute); |
---|
452 | // REPLACE CORPORATIVE ATTRIBUTES |
---|
453 | if (($diff[$atribute]) && ($old_values[$atribute] != '')) |
---|
454 | { |
---|
455 | $ldap_atribute = str_replace("corporative_information_", "", $atribute); |
---|
456 | $ldap_mod_replace[$ldap_atribute] = utf8_encode($new_values[$atribute]); |
---|
457 | $this->db_functions->write_log('modified user attribute', $dn . ': ' . $ldap_atribute . ': ' . $old_values[$atribute] . '->' . $new_values[$atribute]); |
---|
458 | } |
---|
459 | //ADD CORPORATIVE ATTRIBUTES |
---|
460 | elseif (($old_values[$atribute] == '') && ($new_values[$atribute] != '')) |
---|
461 | { |
---|
462 | $ldap_add[$ldap_atribute] = utf8_encode($new_values[$atribute]); |
---|
463 | $this->db_functions->write_log('added user attribute', $dn . ': ' . $ldap_atribute . ': ' . $old_values[$atribute] . '->' . $new_values[$atribute]); |
---|
464 | } |
---|
465 | //REMOVE CORPORATIVE ATTRIBUTES |
---|
466 | elseif (($old_values[$atribute] != '') && ($new_values[$atribute] == '')) |
---|
467 | { |
---|
468 | $ldap_remove[$ldap_atribute] = array(); |
---|
469 | $this->db_functions->write_log('removed user attribute', $dn . ': ' . $ldap_atribute . ': ' . $old_values[$atribute] . '->' . $new_values[$atribute]); |
---|
470 | } |
---|
471 | } |
---|
472 | } |
---|
473 | } |
---|
474 | |
---|
475 | //Suporte ao SAMBA |
---|
476 | if ( ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) || |
---|
477 | ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_sambausers_attributes')) ) |
---|
478 | { |
---|
479 | |
---|
480 | if ($diff['gidnumber']) |
---|
481 | { |
---|
482 | $ldap_mod_replace['gidnumber'] = $new_values['gidnumber']; |
---|
483 | $this->db_functions->write_log('modified user primary group', $dn . ': ' . $old_values['gidnumber'] . '->' . $new_values['gidnumber']); |
---|
484 | } |
---|
485 | |
---|
486 | if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($new_values['userSamba']) && ($new_values['use_attrs_samba'] == 'on')) |
---|
487 | { |
---|
488 | if ($diff['gidnumber']) |
---|
489 | { |
---|
490 | $ldap_mod_replace['sambaPrimaryGroupSID'] = $this->current_config['expressoAdmin_sambaSID'] . '-' . ((2 * $new_values['gidnumber'])+1001); |
---|
491 | $this->db_functions->write_log('modified user sambaPrimaryGroupSID', $dn); |
---|
492 | } |
---|
493 | |
---|
494 | if ($diff['sambaacctflags']) |
---|
495 | { |
---|
496 | $ldap_mod_replace['sambaacctflags'] = $new_values['sambaacctflags']; |
---|
497 | $this->db_functions->write_log("modified user sambaacctflags",$dn); |
---|
498 | } |
---|
499 | if ($diff['sambalogonscript']) |
---|
500 | { |
---|
501 | $ldap_mod_replace['sambalogonscript'] = $new_values['sambalogonscript']; |
---|
502 | $this->db_functions->write_log("modified user sambalogonscript",$dn); |
---|
503 | } |
---|
504 | if ($diff['sambahomedirectory']) |
---|
505 | { |
---|
506 | $ldap_mod_replace['homedirectory'] = $new_values['sambahomedirectory']; |
---|
507 | $this->db_functions->write_log("modified user homedirectory",$dn); |
---|
508 | } |
---|
509 | if ($diff['sambadomain']) |
---|
510 | { |
---|
511 | $ldap_mod_replace['sambaSID'] = $diff['sambadomain'] . '-' . ((2 * $old_values['uidnumber'])+1000); |
---|
512 | $ldap_mod_replace['sambaPrimaryGroupSID'] = $diff['sambadomain'] . '-' . ((2 * $old_values['gidnumber'])+1001); |
---|
513 | $this->db_functions->write_log('modified user samba domain', $dn . ': ' . $old_values['sambadomain'] . '->' . $new_values['sambadomain']); |
---|
514 | } |
---|
515 | } |
---|
516 | } |
---|
517 | |
---|
518 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
519 | // ADD or REMOVE some attributes |
---|
520 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
521 | |
---|
522 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
523 | // PHOTO |
---|
524 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users_picture')) |
---|
525 | { |
---|
526 | if ($new_values['delete_photo']) |
---|
527 | { |
---|
528 | $this->ldap_functions->ldap_remove_photo($dn); |
---|
529 | $this->db_functions->write_log("removed user photo",$dn); |
---|
530 | } |
---|
531 | elseif ($_FILES['photo']['name'] != '') |
---|
532 | { |
---|
533 | |
---|
534 | $size_conf = $this->current_config['expressoAdmin_photo_length'] == '' ? 10000:$this->current_config['expressoAdmin_photo_length'] ; |
---|
535 | if ($_FILES['photo']['size'] > $size_conf) |
---|
536 | { |
---|
537 | $return['status'] = false; |
---|
538 | $return['msg'] .= $this->functions->lang('User photo could not be save because is bigger the').' '.($size_conf/1024).' kb.'; |
---|
539 | } |
---|
540 | else |
---|
541 | { |
---|
542 | if ($new_values['photo_exist']) |
---|
543 | { |
---|
544 | $photo_exist = true; |
---|
545 | $this->db_functions->write_log("mofified user photo",$dn); |
---|
546 | } |
---|
547 | else |
---|
548 | { |
---|
549 | $photo_exist = false; |
---|
550 | $this->db_functions->write_log("added user photo",$dn); |
---|
551 | } |
---|
552 | $this->ldap_functions->ldap_save_photo($dn, $_FILES['photo']['tmp_name'], $new_values['photo_exist'], $photo_exist); |
---|
553 | } |
---|
554 | } |
---|
555 | } |
---|
556 | |
---|
557 | // Verifica o acesso ára adicionar ou remover tais atributos |
---|
558 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) |
---|
559 | { |
---|
560 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
561 | // TELEPHONE |
---|
562 | if (($old_values['telephonenumber'] == '') && ($new_values['telephonenumber'] != '')) |
---|
563 | { |
---|
564 | $ldap_add['telephonenumber'] = $new_values['telephonenumber']; |
---|
565 | $this->db_functions->write_log("added user phone",$dn); |
---|
566 | } |
---|
567 | if (($old_values['telephonenumber'] != '') && ($new_values['telephonenumber'] == '')) |
---|
568 | { |
---|
569 | $ldap_remove['telephonenumber'] = array(); |
---|
570 | $this->db_functions->write_log("removed user phone",$dn); |
---|
571 | } |
---|
572 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
573 | // Passwd Expired - Sem atributo |
---|
574 | if (($old_values['passwd_expired'] == '') && ($new_values['passwd_expired'] == '1')) |
---|
575 | { |
---|
576 | $ldap_add['phpgwlastpasswdchange'] = '0'; |
---|
577 | $this->db_functions->write_log("expired user password",$dn); |
---|
578 | } |
---|
579 | if (($old_values['passwd_expired'] == '0') && ($new_values['passwd_expired'] == '')) |
---|
580 | { |
---|
581 | $ldap_remove['phpgwlastpasswdchange'] = array(); |
---|
582 | $this->db_functions->write_log("removed expiry from user password",$dn); |
---|
583 | } |
---|
584 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
585 | // PREF_CHANGEPASSWORD |
---|
586 | if (($old_values['changepassword'] == '') && ($new_values['changepassword'] != '')) |
---|
587 | { |
---|
588 | $this->db_functions->add_pref_changepassword($new_values['uidnumber']); |
---|
589 | $this->db_functions->write_log("turn on changepassword",$dn); |
---|
590 | } |
---|
591 | if (($old_values['changepassword'] != '') && ($new_values['changepassword'] == '')) |
---|
592 | { |
---|
593 | $this->db_functions->remove_pref_changepassword($new_values['uidnumber']); |
---|
594 | $this->db_functions->write_log("turn of changepassword",$dn); |
---|
595 | } |
---|
596 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
597 | // ACCOUNT STATUS |
---|
598 | if (($old_values['phpgwaccountstatus'] == '') && ($new_values['phpgwaccountstatus'] != '')) |
---|
599 | { |
---|
600 | $ldap_add['phpgwaccountstatus'] = 'A'; |
---|
601 | $this->db_functions->write_log("turn on user account",$dn); |
---|
602 | } |
---|
603 | if (($old_values['phpgwaccountstatus'] != '') && ($new_values['phpgwaccountstatus'] == '')) |
---|
604 | { |
---|
605 | $ldap_remove['phpgwaccountstatus'] = array(); |
---|
606 | $this->db_functions->write_log("turn off user account",$dn); |
---|
607 | } |
---|
608 | |
---|
609 | if ($new_values['phpgwaccountexpired'] == '1') ///////////////////////// |
---|
610 | { |
---|
611 | $this->db_functions->write_log("Reactivated blocked user by downtime",'',$dn,'',''); |
---|
612 | $this->db_functions->reactivate_inactive_user($old_values['uidnumber']); |
---|
613 | } |
---|
614 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
615 | // ACCOUNT VISIBLE |
---|
616 | if (($old_values['phpgwaccountvisible'] == '') && ($new_values['phpgwaccountvisible'] != '')) |
---|
617 | { |
---|
618 | $ldap_add['phpgwaccountvisible'] = '-1'; |
---|
619 | $this->db_functions->write_log("turn on phpgwaccountvisible",$dn); |
---|
620 | } |
---|
621 | if (($old_values['phpgwaccountvisible'] != '') && ($new_values['phpgwaccountvisible'] == '')) |
---|
622 | { |
---|
623 | $ldap_remove['phpgwaccountvisible'] = array(); |
---|
624 | $this->db_functions->write_log("turn off phpgwaccountvisible",$dn); |
---|
625 | } |
---|
626 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
627 | // Mail Account STATUS |
---|
628 | if (($old_values['accountstatus'] == '') && ($new_values['accountstatus'] != '')) |
---|
629 | { |
---|
630 | $ldap_add['accountstatus'] = 'active'; |
---|
631 | $this->db_functions->write_log("turn on user account email",$dn); |
---|
632 | } |
---|
633 | if (($old_values['accountstatus'] != '') && ($new_values['accountstatus'] == '')) |
---|
634 | { |
---|
635 | $ldap_remove['accountstatus'] = array(); |
---|
636 | $this->db_functions->write_log("turn off user account email",$dn); |
---|
637 | } |
---|
638 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
639 | // MAILALTERNATEADDRESS |
---|
640 | if (!$new_values['mailalternateaddress']) |
---|
641 | $new_values['mailalternateaddress'] = array(); |
---|
642 | if (!$old_values['mailalternateaddress']) |
---|
643 | $old_values['mailalternateaddress'] = array(); |
---|
644 | $add_mailalternateaddress = array_diff($new_values['mailalternateaddress'], $old_values['mailalternateaddress']); |
---|
645 | $remove_mailalternateaddress = array_diff($old_values['mailalternateaddress'], $new_values['mailalternateaddress']); |
---|
646 | foreach ($add_mailalternateaddress as $index=>$mailalternateaddress) |
---|
647 | { |
---|
648 | if ($mailalternateaddress != '') |
---|
649 | { |
---|
650 | $ldap_add['mailalternateaddress'][] = $mailalternateaddress; |
---|
651 | $this->db_functions->write_log("added mailalternateaddress","$dn: $mailalternateaddress"); |
---|
652 | } |
---|
653 | } |
---|
654 | foreach ($remove_mailalternateaddress as $index=>$mailalternateaddress) |
---|
655 | { |
---|
656 | if ($mailalternateaddress != '') |
---|
657 | { |
---|
658 | if ($index !== 'count') |
---|
659 | { |
---|
660 | $ldap_remove['mailalternateaddress'][] = $mailalternateaddress; |
---|
661 | $this->db_functions->write_log("removed mailalternateaddress","$dn: $mailalternateaddress"); |
---|
662 | } |
---|
663 | } |
---|
664 | } |
---|
665 | |
---|
666 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
667 | // MAILFORWARDINGADDRESS |
---|
668 | if (!$new_values['mailforwardingaddress']) |
---|
669 | $new_values['mailforwardingaddress'] = array(); |
---|
670 | if (!$old_values['mailforwardingaddress']) |
---|
671 | $old_values['mailforwardingaddress'] = array(); |
---|
672 | $add_mailforwardingaddress = array_diff($new_values['mailforwardingaddress'], $old_values['mailforwardingaddress']); |
---|
673 | $remove_mailforwardingaddress = array_diff($old_values['mailforwardingaddress'], $new_values['mailforwardingaddress']); |
---|
674 | foreach ($add_mailforwardingaddress as $index=>$mailforwardingaddress) |
---|
675 | { |
---|
676 | if ($mailforwardingaddress != '') |
---|
677 | { |
---|
678 | $ldap_add['mailforwardingaddress'][] = $mailforwardingaddress; |
---|
679 | $this->db_functions->write_log("added mailforwardingaddress","$dn: $mailforwardingaddress"); |
---|
680 | } |
---|
681 | } |
---|
682 | foreach ($remove_mailforwardingaddress as $index=>$mailforwardingaddress) |
---|
683 | { |
---|
684 | if ($mailforwardingaddress != '') |
---|
685 | { |
---|
686 | if ($index !== 'count') |
---|
687 | { |
---|
688 | $ldap_remove['mailforwardingaddress'][] = $mailforwardingaddress; |
---|
689 | $this->db_functions->write_log("removed mailforwardingaddress","$dn: $mailforwardingaddress"); |
---|
690 | } |
---|
691 | } |
---|
692 | } |
---|
693 | |
---|
694 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
695 | // Delivery Mode |
---|
696 | if (($old_values['deliverymode'] == '') && ($new_values['deliverymode'] != '')) |
---|
697 | { |
---|
698 | $ldap_add['deliverymode'] = 'forwardOnly'; |
---|
699 | $this->db_functions->write_log("added forwardOnly", $dn); |
---|
700 | } |
---|
701 | if (($old_values['deliverymode'] != '') && ($new_values['deliverymode'] == '')) |
---|
702 | { |
---|
703 | $ldap_remove['deliverymode'] = array(); |
---|
704 | $this->db_functions->write_log("removed forwardOnly", $dn); |
---|
705 | } |
---|
706 | } |
---|
707 | |
---|
708 | if ( ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) || |
---|
709 | ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'change_users_quote')) ) |
---|
710 | { |
---|
711 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
712 | // MAILQUOTA |
---|
713 | if ( ($new_values['mailquota'] != $old_values['mailquota']) && (is_numeric($new_values['mailquota'])) ) |
---|
714 | { |
---|
715 | $result_change_user_quota = $this->imap_functions->change_user_quota($new_values['uid'], $new_values['mailquota']); |
---|
716 | |
---|
717 | if ($result_change_user_quota['status']) |
---|
718 | { |
---|
719 | $this->db_functions->write_log("modified user email quota" , $dn . ':' . $old_values['mailquota'] . '->' . $new_values['mailquota']); |
---|
720 | } |
---|
721 | else |
---|
722 | { |
---|
723 | $return['status'] = false; |
---|
724 | $return['msg'] .= $result_change_user_quota['msg']; |
---|
725 | } |
---|
726 | } |
---|
727 | } |
---|
728 | |
---|
729 | if ( ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) || |
---|
730 | ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_sambausers_attributes')) ) |
---|
731 | { |
---|
732 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
733 | // REMOVE ATTRS OF SAMBA |
---|
734 | if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($new_values['userSamba']) && ($new_values['use_attrs_samba'] != 'on')) |
---|
735 | { |
---|
736 | $ldap_remove['objectclass'] = 'sambaSamAccount'; |
---|
737 | $ldap_remove['loginShell'] = array(); |
---|
738 | $ldap_remove['sambaSID'] = array(); |
---|
739 | $ldap_remove['sambaPrimaryGroupSID'] = array(); |
---|
740 | $ldap_remove['sambaAcctFlags'] = array(); |
---|
741 | $ldap_remove['sambaLogonScript'] = array(); |
---|
742 | $ldap_remove['sambaLMPassword'] = array(); |
---|
743 | $ldap_remove['sambaNTPassword'] = array(); |
---|
744 | $ldap_remove['sambaPasswordHistory'] = array(); |
---|
745 | $ldap_remove['sambaPwdCanChange'] = array(); |
---|
746 | $ldap_remove['sambaPwdLastSet'] = array(); |
---|
747 | $ldap_remove['sambaPwdMustChange'] = array(); |
---|
748 | $this->db_functions->write_log("removed user samba attributes", $dn); |
---|
749 | } |
---|
750 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
751 | // ADD ATTRS OF SAMBA |
---|
752 | if (($this->current_config['expressoAdmin_samba_support'] == 'true') && (!$new_values['userSamba']) && ($new_values['use_attrs_samba'] == 'on')) |
---|
753 | { |
---|
754 | if (!is_file('/home/expressolivre/mkntpwd')) |
---|
755 | { |
---|
756 | $return['status'] = false; |
---|
757 | $return['msg'] .= $this->functions->lang("The file /home/expressolivre/mkntpwd does not exist") . ".\n"; |
---|
758 | $return['msg'] .= $this->functions->lang("It is necessery to create samba passwords") . ".\n"; |
---|
759 | $return['msg'] .= $this->functions->lang("Inform your system administrator about this") . ".\n"; |
---|
760 | } |
---|
761 | else |
---|
762 | { |
---|
763 | $ldap_add['objectClass'][] = 'sambaSamAccount'; |
---|
764 | $ldap_mod_replace['loginShell'] = '/bin/bash'; |
---|
765 | $ldap_add['sambaSID'] = $new_values['sambadomain'] . '-' . ((2 * $new_values['uidnumber'])+1000); |
---|
766 | $ldap_add['sambaPrimaryGroupSID'] = $new_values['sambadomain'] . '-' . ((2 * $new_values['gidnumber'])+1001); |
---|
767 | $ldap_add['sambaAcctFlags'] = $new_values['sambaacctflags']; |
---|
768 | $ldap_add['sambaLogonScript'] = $new_values['sambalogonscript']; |
---|
769 | $ldap_mod_replace['homeDirectory'] = $new_values['sambahomedirectory']; |
---|
770 | $ldap_add['sambaLMPassword'] = exec('/home/expressolivre/mkntpwd -L '.'senha'); |
---|
771 | $ldap_add['sambaNTPassword'] = exec('/home/expressolivre/mkntpwd -N '.'senha'); |
---|
772 | $ldap_add['sambaPasswordHistory'] = '0000000000000000000000000000000000000000000000000000000000000000'; |
---|
773 | $ldap_add['sambaPwdCanChange'] = strtotime("now"); |
---|
774 | $ldap_add['sambaPwdLastSet'] = strtotime("now"); |
---|
775 | $ldap_add['sambaPwdMustChange'] = '2147483647'; |
---|
776 | $this->db_functions->write_log("added user samba attribute", $dn); |
---|
777 | } |
---|
778 | } |
---|
779 | } |
---|
780 | |
---|
781 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
782 | // GROUPS |
---|
783 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_groups')) |
---|
784 | { |
---|
785 | // If the manager does not have the suficient access, the new_values.uid is empty. |
---|
786 | if (empty($new_values['uid'])) |
---|
787 | $user_uid = $old_values['uid']; |
---|
788 | else |
---|
789 | $user_uid = $new_values['uid']; |
---|
790 | |
---|
791 | if (!$new_values['groups']) |
---|
792 | $new_values['groups'] = array(); |
---|
793 | if (!$old_values['groups']) |
---|
794 | $old_values['groups'] = array(); |
---|
795 | |
---|
796 | $add_groups = array_diff($new_values['groups'], $old_values['groups']); |
---|
797 | $remove_groups = array_diff($old_values['groups'], $new_values['groups']); |
---|
798 | |
---|
799 | if (count($add_groups)>0) |
---|
800 | { |
---|
801 | foreach($add_groups as $gidnumber) |
---|
802 | { |
---|
803 | $this->db_functions->add_user2group($gidnumber, $new_values['uidnumber']); |
---|
804 | $this->ldap_functions->add_user2group($gidnumber, $user_uid); |
---|
805 | $this->db_functions->write_log("included user to group", "uid:$user_uid -> gid:$gidnumber"); |
---|
806 | } |
---|
807 | } |
---|
808 | |
---|
809 | if (count($remove_groups)>0) |
---|
810 | { |
---|
811 | foreach($remove_groups as $gidnumber) |
---|
812 | { |
---|
813 | foreach($old_values['groups_info'] as $group) |
---|
814 | { |
---|
815 | if (($group['gidnumber'] == $gidnumber) && ($group['group_disabled'] == 'false')) |
---|
816 | { |
---|
817 | $this->db_functions->remove_user2group($gidnumber, $new_values['uidnumber']); |
---|
818 | $this->ldap_functions->remove_user2group($gidnumber, $user_uid); |
---|
819 | $this->db_functions->write_log("removed user from group", "$dn: $gidnumber"); |
---|
820 | } |
---|
821 | } |
---|
822 | } |
---|
823 | } |
---|
824 | } |
---|
825 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
826 | // LDAP_MOD_REPLACE |
---|
827 | if (count($ldap_mod_replace)) |
---|
828 | { |
---|
829 | $result = $this->ldap_functions->replace_user_attributes($dn, $ldap_mod_replace); |
---|
830 | if (!$result['status']) |
---|
831 | { |
---|
832 | $return['status'] = false; |
---|
833 | $return['msg'] .= $result['msg']; |
---|
834 | } |
---|
835 | } |
---|
836 | |
---|
837 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
838 | // LDAP_MOD_ADD |
---|
839 | if (count($ldap_add)) |
---|
840 | { |
---|
841 | $result = $this->ldap_functions->add_user_attributes($dn, $ldap_add); |
---|
842 | if (!$result['status']) |
---|
843 | { |
---|
844 | $return['status'] = false; |
---|
845 | $return['msg'] .= $result['msg']; |
---|
846 | } |
---|
847 | } |
---|
848 | |
---|
849 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
850 | // LDAP_MOD_REMOVE |
---|
851 | if (count($ldap_remove)) |
---|
852 | { |
---|
853 | $result = $this->ldap_functions->remove_user_attributes($dn, $ldap_remove); |
---|
854 | if (!$result['status']) |
---|
855 | { |
---|
856 | $return['status'] = false; |
---|
857 | $return['msg'] .= $result['msg']; |
---|
858 | } |
---|
859 | } |
---|
860 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
861 | |
---|
862 | |
---|
863 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) |
---|
864 | { |
---|
865 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
866 | // MAILLISTS |
---|
867 | if (!$new_values['maillists']) |
---|
868 | $new_values['maillists'] = array(); |
---|
869 | if (!$old_values['maillists']) |
---|
870 | $old_values['maillists'] = array(); |
---|
871 | |
---|
872 | $add_maillists = array_diff($new_values['maillists'], $old_values['maillists']); |
---|
873 | $remove_maillists = array_diff($old_values['maillists'], $new_values['maillists']); |
---|
874 | |
---|
875 | if (count($add_maillists)>0) |
---|
876 | { |
---|
877 | foreach($add_maillists as $uid) |
---|
878 | { |
---|
879 | $this->ldap_functions->add_user2maillist($uid, $new_values['mail']); |
---|
880 | $this->db_functions->write_log("included user to maillist","$uid: $dn"); |
---|
881 | } |
---|
882 | } |
---|
883 | |
---|
884 | if (count($remove_maillists)>0) |
---|
885 | { |
---|
886 | foreach($remove_maillists as $uid) |
---|
887 | { |
---|
888 | $this->ldap_functions->remove_user2maillist($uid, $new_values['mail']); |
---|
889 | $this->db_functions->write_log("removed user from maillist","$dn: $uid"); |
---|
890 | } |
---|
891 | } |
---|
892 | |
---|
893 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
894 | // APPS |
---|
895 | $new_values2 = array(); |
---|
896 | $old_values2 = array(); |
---|
897 | if (count($new_values['apps'])>0) |
---|
898 | { |
---|
899 | foreach ($new_values['apps'] as $app=>$tmp) |
---|
900 | { |
---|
901 | $new_values2[] = $app; |
---|
902 | } |
---|
903 | } |
---|
904 | if (count($old_values['apps'])>0) |
---|
905 | { |
---|
906 | foreach ($old_values['apps'] as $app=>$tmp) |
---|
907 | { |
---|
908 | $old_values2[] = $app; |
---|
909 | } |
---|
910 | } |
---|
911 | $add_apps = array_flip(array_diff($new_values2, $old_values2)); |
---|
912 | $remove_apps = array_flip(array_diff($old_values2, $new_values2)); |
---|
913 | |
---|
914 | if (count($add_apps)>0) |
---|
915 | { |
---|
916 | $this->db_functions->add_id2apps($new_values['uidnumber'], $add_apps); |
---|
917 | |
---|
918 | foreach ($add_apps as $app => $index) |
---|
919 | $this->db_functions->write_log("added application to user","$dn: $app"); |
---|
920 | } |
---|
921 | if (count($remove_apps)>0) |
---|
922 | { |
---|
923 | //Verifica se o gerente tem acesso a aplicação antes de remove-la do usuario. |
---|
924 | $manager_apps = $this->db_functions->get_apps($_SESSION['phpgw_session']['session_lid']); |
---|
925 | |
---|
926 | foreach ($remove_apps as $app => $app_index) |
---|
927 | { |
---|
928 | if ($manager_apps[$app] == 'run') |
---|
929 | $remove_apps2[$app] = $app_index; |
---|
930 | } |
---|
931 | $this->db_functions->remove_id2apps($new_values['uidnumber'], $remove_apps2); |
---|
932 | |
---|
933 | foreach ($remove_apps2 as $app => $access) |
---|
934 | $this->db_functions->write_log("removed application to user","$dn: $app"); |
---|
935 | } |
---|
936 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
937 | } |
---|
938 | return $return; |
---|
939 | } |
---|
940 | |
---|
941 | function get_user_info($uidnumber) |
---|
942 | { |
---|
943 | if (!$user_info_ldap = $this->ldap_functions->get_user_info($uidnumber)) |
---|
944 | return false; |
---|
945 | $user_info_db1 = $this->db_functions->get_user_info($uidnumber); |
---|
946 | $user_info_db2 = $this->ldap_functions->gidnumbers2cn($user_info_db1['groups']); |
---|
947 | $user_info_imap = $this->imap_functions->get_user_info($user_info_ldap['uid']); |
---|
948 | $user_info = array_merge($user_info_ldap, $user_info_db1, $user_info_db2, $user_info_imap); |
---|
949 | return $user_info; |
---|
950 | } |
---|
951 | |
---|
952 | function set_user_default_password($params) |
---|
953 | { |
---|
954 | $return['status'] = 1; |
---|
955 | $uid = $params['uid']; |
---|
956 | $defaultUserPassword = '{md5}'.base64_encode(pack("H*",md5($this->current_config['expressoAdmin_defaultUserPassword']))); |
---|
957 | |
---|
958 | if (!$this->db_functions->default_user_password_is_set($uid)) |
---|
959 | { |
---|
960 | $userPassword = $this->ldap_functions->set_user_password($uid, $defaultUserPassword); |
---|
961 | $this->db_functions->set_user_password($uid, $userPassword); |
---|
962 | $this->db_functions->write_log("inserted default password",$uid); |
---|
963 | } |
---|
964 | else |
---|
965 | { |
---|
966 | $return['status'] = 0; |
---|
967 | $return['msg'] = $this->functions->lang('default password already registered') . '!'; |
---|
968 | } |
---|
969 | |
---|
970 | return $return; |
---|
971 | } |
---|
972 | |
---|
973 | function return_user_password($params) |
---|
974 | { |
---|
975 | $return['status'] = 1; |
---|
976 | $uid = $params['uid']; |
---|
977 | |
---|
978 | if ($this->db_functions->default_user_password_is_set($uid)) |
---|
979 | { |
---|
980 | $userPassword = $this->db_functions->get_user_password($uid); |
---|
981 | $this->ldap_functions->set_user_password($uid, $userPassword); |
---|
982 | } |
---|
983 | else |
---|
984 | { |
---|
985 | $return['status'] = 0; |
---|
986 | $return['msg'] = $this->functions->lang('default password not registered') . '!'; |
---|
987 | } |
---|
988 | |
---|
989 | $this->db_functions->write_log("returned user password",$uid); |
---|
990 | |
---|
991 | return $return; |
---|
992 | } |
---|
993 | |
---|
994 | function delete($params) |
---|
995 | { |
---|
996 | $return['status'] = true; |
---|
997 | $this->db_functions->write_log('delete user: start', $params['uid']); |
---|
998 | |
---|
999 | // Verifica o acesso do gerente |
---|
1000 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'delete_users')) |
---|
1001 | { |
---|
1002 | $uidnumber = $params['uidnumber']; |
---|
1003 | if (!$user_info = $this->get_user_info($uidnumber)) |
---|
1004 | { |
---|
1005 | $this->db_functions->write_log('delete user: error getting users info', $user_info['uid']); |
---|
1006 | $return['status'] = false; |
---|
1007 | $return['msg'] = $this->functions->lang('error getting users info'); |
---|
1008 | return $return; |
---|
1009 | } |
---|
1010 | |
---|
1011 | //LDAP |
---|
1012 | $result_ldap = $this->ldap_functions->delete_user($user_info); |
---|
1013 | if (!$result_ldap['status']) |
---|
1014 | { |
---|
1015 | $return['status'] = false; |
---|
1016 | $return['msg'] = 'user.delete(ldap): ' . $result_ldap['msg']; |
---|
1017 | return $return; |
---|
1018 | } |
---|
1019 | else |
---|
1020 | { |
---|
1021 | $this->db_functions->write_log("deleted users data from ldap", $user_info['uid']); |
---|
1022 | |
---|
1023 | //DB |
---|
1024 | $result_db = $this->db_functions->delete_user($user_info); |
---|
1025 | if (!$result_db['status']) |
---|
1026 | { |
---|
1027 | $return['status'] = false; |
---|
1028 | $return['msg'] .= 'user.delete(db): ' . $result_db['msg']; |
---|
1029 | } |
---|
1030 | else |
---|
1031 | { |
---|
1032 | $this->db_functions->write_log("deleted users data from DB", $user_info['uid']); |
---|
1033 | } |
---|
1034 | |
---|
1035 | //IMAP |
---|
1036 | $result_imap = $this->imap_functions->delete_mailbox($user_info['uid']); |
---|
1037 | if (!$result_imap['status']) |
---|
1038 | { |
---|
1039 | $return['status'] = false; |
---|
1040 | $return['msg'] .= $result_imap['msg']; |
---|
1041 | } |
---|
1042 | else |
---|
1043 | { |
---|
1044 | $this->db_functions->write_log("deleted users data from IMAP", $user_info['uid']); |
---|
1045 | } |
---|
1046 | |
---|
1047 | } |
---|
1048 | } |
---|
1049 | else |
---|
1050 | { |
---|
1051 | $this->db_functions->write_log('delete user: manager does not have access', $params['uidnumber']); |
---|
1052 | } |
---|
1053 | |
---|
1054 | $this->db_functions->write_log('delete user: end', $user_info['uid']); |
---|
1055 | return $return; |
---|
1056 | } |
---|
1057 | |
---|
1058 | |
---|
1059 | function rename($params) |
---|
1060 | { |
---|
1061 | $return['status'] = true; |
---|
1062 | |
---|
1063 | // Verifica acesso do gerente (OU) ao tentar renomear um usuário. |
---|
1064 | if ( ! $this->ldap_functions->check_access_to_renamed($params['uid']) ) |
---|
1065 | { |
---|
1066 | $return['status'] = false; |
---|
1067 | $return['msg'] .= $this->functions->lang('You do not have access to delete user') . '.'; |
---|
1068 | return $return; |
---|
1069 | } |
---|
1070 | |
---|
1071 | // Check if the new_uid is in use. |
---|
1072 | if ( ! $this->ldap_functions->check_rename_new_uid($params['new_uid']) ) |
---|
1073 | { |
---|
1074 | $return['status'] = false; |
---|
1075 | $return['msg'] = $this->functions->lang('New login already in use') . '.'; |
---|
1076 | return $return; |
---|
1077 | } |
---|
1078 | |
---|
1079 | // Verifica o acesso do gerente |
---|
1080 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'rename_users')) |
---|
1081 | { |
---|
1082 | $uid = $params['uid']; |
---|
1083 | $new_uid = $params['new_uid']; |
---|
1084 | $defaultUserPassword = '{md5}'.base64_encode(pack("H*",md5($this->current_config['expressoAdmin_defaultUserPassword']))); |
---|
1085 | $defaultUserPassword_plain = $this->current_config['expressoAdmin_defaultUserPassword']; |
---|
1086 | |
---|
1087 | $emailadmin_profiles = $this->db_functions->get_sieve_info(); |
---|
1088 | $sieve_enable = $emailadmin_profiles[0]['imapenablesieve']; |
---|
1089 | $sieve_server = $emailadmin_profiles[0]['imapsieveserver']; |
---|
1090 | $sieve_port = $emailadmin_profiles[0]['imapsieveport']; |
---|
1091 | |
---|
1092 | $imap_admin = $_SESSION['phpgw_info']['expresso']['email_server']['imapAdminUsername']; |
---|
1093 | $imap_passwd = $_SESSION['phpgw_info']['expresso']['email_server']['imapAdminPW']; |
---|
1094 | $imap_server = $_SESSION['phpgw_info']['expresso']['email_server']['imapServer']; |
---|
1095 | $imap_port = $_SESSION['phpgw_info']['expresso']['email_server']['imapPort']; |
---|
1096 | $imapDelimiter = $_SESSION['phpgw_info']['expresso']['email_server']['imapDelimiter']; |
---|
1097 | |
---|
1098 | //Verifica se está sendo usuado cyrus 2.2 ou superior |
---|
1099 | $sk = fsockopen ($imap_server,$imap_port); |
---|
1100 | $server_resp = fread($sk, 100); |
---|
1101 | $tmp = split('v2.', $server_resp); |
---|
1102 | $cyrus_version = '2' . $tmp[1][0]; |
---|
1103 | |
---|
1104 | if ($cyrus_version < '22') |
---|
1105 | { |
---|
1106 | $return['status'] = false; |
---|
1107 | $return['msg'] = "The rename user is only permitted with cyrus 2.2 or higher,"; |
---|
1108 | $return['msg'] .= "\nand with the option 'allowusermoves: yes' set in imapd.conf."; |
---|
1109 | |
---|
1110 | |
---|
1111 | return $return; |
---|
1112 | } |
---|
1113 | |
---|
1114 | // Renomeia UID no openldap |
---|
1115 | $result = $this->ldap_functions->rename_uid($uid, $new_uid); |
---|
1116 | if (!$result['status']) |
---|
1117 | { |
---|
1118 | $return['status'] = false; |
---|
1119 | $return['msg'] = $this->functions->lang("Error rename user in LDAP") . '.'; |
---|
1120 | return $return; |
---|
1121 | } |
---|
1122 | |
---|
1123 | //Renomeia mailbox |
---|
1124 | $imap_rename_result = $this->imap_functions->rename_mailbox($uid, $new_uid); |
---|
1125 | if (!$imap_rename_result['status']) |
---|
1126 | { |
---|
1127 | // Back user uid. |
---|
1128 | $result = $this->ldap_functions->rename_uid($new_uid, $uid); |
---|
1129 | |
---|
1130 | $return['status'] = false; |
---|
1131 | $return['msg'] = $this->functions->lang("Error renaming user mailboxes") . ".\n"; |
---|
1132 | $return['msg'] .= $imap_rename_result['msg']; |
---|
1133 | return $return; |
---|
1134 | } |
---|
1135 | |
---|
1136 | |
---|
1137 | // Renomeia sieve script |
---|
1138 | include_once('sieve-php.lib.php'); |
---|
1139 | //function sieve($host, $port, $user, $pass, $auth="", $auth_types) |
---|
1140 | $sieve=new sieve($sieve_server, $sieve_port, $new_uid, $imap_passwd, $imap_admin, 'PLAIN'); |
---|
1141 | |
---|
1142 | if ($sieve->sieve_login()) |
---|
1143 | { |
---|
1144 | $sieve->sieve_listscripts(); |
---|
1145 | $myactivescript=$sieve->response["ACTIVE"]; |
---|
1146 | $sieve->sieve_getscript($myactivescript); |
---|
1147 | |
---|
1148 | $script = ''; |
---|
1149 | if (!empty($sieve->response)) |
---|
1150 | { |
---|
1151 | foreach($sieve->response as $result) |
---|
1152 | { |
---|
1153 | $script .= $result; |
---|
1154 | } |
---|
1155 | } |
---|
1156 | |
---|
1157 | if (!empty($script)) |
---|
1158 | { |
---|
1159 | $scriptname = $new_uid; |
---|
1160 | if($sieve->sieve_sendscript($new_uid,$script)) |
---|
1161 | { |
---|
1162 | if ($sieve->sieve_setactivescript($new_uid)) |
---|
1163 | { |
---|
1164 | if (!$sieve->sieve_deletescript($myactivescript)) |
---|
1165 | { |
---|
1166 | $return['msg'] .= $result['msg'] . $this->functions->lang("Error renaming sieve script") . ".\\n"; |
---|
1167 | $return['msg'] .= $result['msg'] . $this->functions->lang("Problem deleting old script") . '.'; |
---|
1168 | } |
---|
1169 | } |
---|
1170 | else |
---|
1171 | { |
---|
1172 | $return['msg'] .= $result['msg'] . $this->functions->lang("Error renaming sieve script") . ".\\n"; |
---|
1173 | $return['msg'] .= $result['msg'] . $this->functions->lang("Problem activating sieve script") . '.'; |
---|
1174 | } |
---|
1175 | } |
---|
1176 | else |
---|
1177 | { |
---|
1178 | $return['msg'] .= $result['msg'] . $this->functions->lang("Error renaming sieve script") . ".\\n"; |
---|
1179 | $return['msg'] .= $result['msg'] . $this->functions->lang("Problem saving sieve script") . '.'; |
---|
1180 | } |
---|
1181 | } |
---|
1182 | $sieve->sieve_logout(); |
---|
1183 | } |
---|
1184 | else |
---|
1185 | { |
---|
1186 | $return['status'] = false; |
---|
1187 | $return['msg'] .= $result['msg'] . $this->functions->lang("Error renaming sieve script") . ".\\n"; |
---|
1188 | $return['msg'] .= $result['msg'] . $this->functions->lang("Can not login sieve") . '.'; |
---|
1189 | } |
---|
1190 | |
---|
1191 | $this->db_functions->write_log("renamed user", "$uid -> $new_uid"); |
---|
1192 | |
---|
1193 | $return['exec_return'] = ""; |
---|
1194 | |
---|
1195 | return $return; |
---|
1196 | } |
---|
1197 | } |
---|
1198 | |
---|
1199 | function write_log_from_ajax($params) |
---|
1200 | { |
---|
1201 | $this->db_functions->write_log($params['_action'],'',$params['userinfo'],'',''); |
---|
1202 | return true; |
---|
1203 | } |
---|
1204 | } |
---|
1205 | ?> |
---|