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 maillist |
---|
18 | { |
---|
19 | var $ldap_functions; |
---|
20 | var $db_functions; |
---|
21 | var $imap_functions; |
---|
22 | var $functions; |
---|
23 | var $current_config; |
---|
24 | |
---|
25 | |
---|
26 | function maillist() |
---|
27 | { |
---|
28 | $this->ldap_functions = new ldap_functions; |
---|
29 | $this->db_functions = new db_functions; |
---|
30 | $this->imap_functions = new imap_functions; |
---|
31 | $this->functions = new functions; |
---|
32 | $this->current_config = $_SESSION['phpgw_info']['expresso']['expressoAdmin']; |
---|
33 | } |
---|
34 | |
---|
35 | function validate_fields($params) |
---|
36 | { |
---|
37 | return $this->ldap_functions->validate_fields_maillist($params); |
---|
38 | } |
---|
39 | |
---|
40 | function create($params) |
---|
41 | { |
---|
42 | // Verifica o acesso do gerente |
---|
43 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'add_maillists')) |
---|
44 | { |
---|
45 | $return['status'] = false; |
---|
46 | $return['msg'] = 'Você não tem acesso para adicionar listas de email.'; |
---|
47 | return $return; |
---|
48 | } |
---|
49 | |
---|
50 | $return['status'] = true; |
---|
51 | |
---|
52 | //Retira os mailForwardingAddress duplicados, se existir algum. |
---|
53 | $array_tmp = array(); |
---|
54 | $array_tmp = array_unique($params['mailForwardingAddress']); |
---|
55 | $params['mailForwardingAddress'] = $array_tmp; |
---|
56 | |
---|
57 | // Leio o ID a ser usado na criação do objecto. |
---|
58 | $next_id = ($this->db_functions->get_next_id('accounts')); |
---|
59 | if ((!is_numeric($next_id['id'])) || (!$next_id['status'])) |
---|
60 | { |
---|
61 | $return['status'] = false; |
---|
62 | $return['msg'] = "Problemas obtendo ID do usuário.\n" . $id['msg']; |
---|
63 | return $return; |
---|
64 | } |
---|
65 | else |
---|
66 | { |
---|
67 | $id = $next_id['id']; |
---|
68 | } |
---|
69 | |
---|
70 | // Cria array para incluir no LDAP |
---|
71 | $dn = 'uid=' . $params['uid'] . ',' . $params['context']; |
---|
72 | |
---|
73 | $maillist_info = array(); |
---|
74 | $maillist_info['uid'] = $params['uid']; |
---|
75 | $maillist_info['givenName'] = 'MailList'; |
---|
76 | $maillist_info['sn'] = $params['uid']; |
---|
77 | $maillist_info['cn'] = $params['cn']; |
---|
78 | |
---|
79 | $maillist_info['homeDirectory'] = '/home/false'; |
---|
80 | $maillist_info['loginShell'] = '/bin/false'; |
---|
81 | $maillist_info['mail'] = $params['mail']; |
---|
82 | $maillist_info['objectClass'][0] = 'posixAccount'; |
---|
83 | $maillist_info['objectClass'][1] = 'inetOrgPerson'; |
---|
84 | $maillist_info['objectClass'][2] = 'shadowAccount'; |
---|
85 | $maillist_info['objectClass'][3] = 'qmailuser'; |
---|
86 | $maillist_info['objectClass'][4] = 'phpgwAccount'; |
---|
87 | $maillist_info['objectClass'][5] = 'top'; |
---|
88 | $maillist_info['objectClass'][6] = 'person'; |
---|
89 | $maillist_info['objectClass'][7] = 'organizationalPerson'; |
---|
90 | $maillist_info['phpgwAccountExpires'] = '-1'; |
---|
91 | $maillist_info['phpgwAccountType'] = 'l'; |
---|
92 | $maillist_info['uidnumber'] = $id; |
---|
93 | $maillist_info['gidnumber'] = '0'; |
---|
94 | $maillist_info['userPassword'] = ''; |
---|
95 | $maillist_info['deliveryMode'] = 'forwardOnly'; |
---|
96 | |
---|
97 | if ($params['accountStatus'] == 'on') |
---|
98 | $maillist_info['accountStatus'] = 'active'; |
---|
99 | |
---|
100 | if ($params['phpgwAccountVisible'] == 'on') |
---|
101 | $maillist_info['phpgwAccountVisible'] = '-1'; |
---|
102 | |
---|
103 | $maillist_info['mailForwardingAddress'] = $params['mailForwardingAddress']; |
---|
104 | |
---|
105 | $result = $this->ldap_functions->ldap_add_entry($dn, $maillist_info); |
---|
106 | if (!$result['status']) |
---|
107 | { |
---|
108 | $return['status'] = false; |
---|
109 | $return['msg'] .= $result['msg']; |
---|
110 | } |
---|
111 | |
---|
112 | /* log */ |
---|
113 | if ($return['status'] == true) |
---|
114 | { |
---|
115 | $this->db_functions->write_log('Criado lista de email','',$dn,'',''); |
---|
116 | |
---|
117 | foreach($params['mailForwardingAddress'] as $index=>$mail) |
---|
118 | { |
---|
119 | $this->db_functions->write_log("Adicionado email $mail a lista ".$params['cn']." no momento da criação",$dn,'','',''); |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | return $return; |
---|
124 | } |
---|
125 | |
---|
126 | function save($new_values) |
---|
127 | { |
---|
128 | // Verifica o acesso do gerente |
---|
129 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_maillists')) |
---|
130 | { |
---|
131 | $return['status'] = false; |
---|
132 | $return['msg'] = 'Você não tem acesso para editar listas de email.'; |
---|
133 | return $return; |
---|
134 | } |
---|
135 | |
---|
136 | $return['status'] = true; |
---|
137 | |
---|
138 | $old_values = $this->get_info($new_values['uidnumber'], $new_values['manager_context']); |
---|
139 | $diff = array_diff($new_values, $old_values); |
---|
140 | |
---|
141 | $dn = 'uid=' . $old_values['uid'] . ',' . $old_values['context']; |
---|
142 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
143 | // RENAME |
---|
144 | if ($diff['context'] || $diff['uid']) |
---|
145 | { |
---|
146 | $newrdn = 'uid=' . $new_values['uid']; |
---|
147 | $newparent = $new_values['context']; |
---|
148 | $result = $this->ldap_functions->change_user_context($dn, $newrdn, $newparent); |
---|
149 | if (!$result['status']) |
---|
150 | { |
---|
151 | $return['status'] = false; |
---|
152 | $return['msg'] .= $result['msg']; |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | $dn = $newrdn . ',' . $newparent; |
---|
157 | $old_dn = $old_values['uid']; |
---|
158 | $this->db_functions->write_log("Renomeado login da lista de $old_dn para $dn",'',$dn,$old_values['uid'],''); |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
163 | // REPLACE MAIL || CN || SN |
---|
164 | if ($new_values['mail'] != $old_values['mail']) |
---|
165 | { |
---|
166 | $ldap_mod_replace['mail'] = $new_values['mail']; |
---|
167 | $this->db_functions->write_log('Modificado email da lista para ' . $new_values['mail'],'',$dn,'',''); |
---|
168 | } |
---|
169 | if ($new_values['cn'] != $old_values['cn']) |
---|
170 | { |
---|
171 | $ldap_mod_replace['cn'] = $new_values['cn']; |
---|
172 | $this->db_functions->write_log("Modificado common name da lista $dn",'',$dn,'',''); |
---|
173 | } |
---|
174 | if ($diff['uid']) |
---|
175 | { |
---|
176 | $ldap_mod_replace['sn'] = $new_values['uid']; |
---|
177 | } |
---|
178 | |
---|
179 | if (count($ldap_mod_replace)) |
---|
180 | { |
---|
181 | $result = $this->ldap_functions->replace_user_attributes($dn, $ldap_mod_replace); |
---|
182 | if (!$result['status']) |
---|
183 | { |
---|
184 | $return['status'] = false; |
---|
185 | $return['msg'] .= $result['msg']; |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
190 | // REMOVE ATTRS |
---|
191 | if (($old_values['accountStatus'] == 'active') && ($new_values['accountStatus'] != 'on')) |
---|
192 | $ldap_remove['accountStatus'] = array(); |
---|
193 | |
---|
194 | if (($old_values['phpgwAccountVisible'] == '-1') && ($new_values['phpgwAccountVisible'] != 'on')) |
---|
195 | $ldap_remove['phpgwAccountVisible'] = array(); |
---|
196 | |
---|
197 | if (count($ldap_remove)) |
---|
198 | { |
---|
199 | $result = $this->ldap_functions->remove_user_attributes($dn, $ldap_remove); |
---|
200 | if (!$result['status']) |
---|
201 | { |
---|
202 | $return['status'] = false; |
---|
203 | $return['msg'] .= $result['msg']; |
---|
204 | } |
---|
205 | } |
---|
206 | |
---|
207 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
208 | // ADD ATTRS |
---|
209 | if (($old_values['accountStatus'] != 'active') && ($new_values['accountStatus'] == 'on')) |
---|
210 | $ldap_add['accountStatus'] = 'active'; |
---|
211 | |
---|
212 | if (($old_values['phpgwAccountVisible'] != '-1') && ($new_values['phpgwAccountVisible'] == 'on')) |
---|
213 | $ldap_add['phpgwAccountVisible'] = '-1'; |
---|
214 | |
---|
215 | if (count($ldap_add)) |
---|
216 | { |
---|
217 | $result = $this->ldap_functions->add_user_attributes($dn, $ldap_add); |
---|
218 | if (!$result['status']) |
---|
219 | { |
---|
220 | $return['status'] = false; |
---|
221 | $return['msg'] .= $result['msg']; |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
226 | // USERS |
---|
227 | /* |
---|
228 | echo '<pre>'; |
---|
229 | print_r($new_values['mailForwardingAddress']); |
---|
230 | */ |
---|
231 | if (!$new_values['mailForwardingAddress']) |
---|
232 | $new_values['mailForwardingAddress'] = array(); |
---|
233 | if (!$old_values['mailForwardingAddress']) |
---|
234 | $old_values['mailForwardingAddress'] = array(); |
---|
235 | |
---|
236 | $add_users = array_diff($new_values['mailForwardingAddress'], $old_values['mailForwardingAddress']); |
---|
237 | $remove_users = array_diff($old_values['mailForwardingAddress'], $new_values['mailForwardingAddress']); |
---|
238 | |
---|
239 | if (count($add_users)>0) |
---|
240 | { |
---|
241 | sort($add_users); |
---|
242 | $result = $this->ldap_functions->add_user2maillist($new_values['uid'], $add_users); |
---|
243 | |
---|
244 | /* log */ |
---|
245 | if (!$result['status']) |
---|
246 | { |
---|
247 | $return['status'] = false; |
---|
248 | $return['msg'] .= $result['msg']; |
---|
249 | } |
---|
250 | else |
---|
251 | { |
---|
252 | foreach($add_users as $index=>$mail) |
---|
253 | { |
---|
254 | $this->db_functions->write_log("Adicionado usuario $mail a lista de email $dn",$dn,'','',''); |
---|
255 | } |
---|
256 | } |
---|
257 | } |
---|
258 | |
---|
259 | if (count($remove_users)>0) |
---|
260 | { |
---|
261 | sort($remove_users); |
---|
262 | $result = $this->ldap_functions->remove_user2maillist($new_values['uid'], $remove_users); |
---|
263 | |
---|
264 | /* log */ |
---|
265 | if (!$result['status']) |
---|
266 | { |
---|
267 | $return['status'] = false; |
---|
268 | $return['msg'] .= $result['msg']; |
---|
269 | } |
---|
270 | else |
---|
271 | { |
---|
272 | foreach($remove_users as $index=>$mail) |
---|
273 | { |
---|
274 | $this->db_functions->write_log("Removido usuario $mail da lista de email $dn",$dn,'','',''); |
---|
275 | } |
---|
276 | } |
---|
277 | } |
---|
278 | |
---|
279 | return $return; |
---|
280 | } |
---|
281 | |
---|
282 | function save_scl($new_values) |
---|
283 | { |
---|
284 | // Verifica o acesso do gerente |
---|
285 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_scl_email_lists')) |
---|
286 | { |
---|
287 | $return['status'] = false; |
---|
288 | $return['msg'] = 'Você não tem acesso para editar SCL de listas de email.'; |
---|
289 | return $return; |
---|
290 | } |
---|
291 | |
---|
292 | $return['status'] = true; |
---|
293 | |
---|
294 | //Retira os uids duplicados se existir |
---|
295 | $array_tmp = array(); |
---|
296 | $array_tmp = @array_unique($new_values['members']); |
---|
297 | $new_values['members'] = $array_tmp; |
---|
298 | |
---|
299 | $old_values = $this->get_scl_info($new_values['uidnumber'], $new_values['manager_context']); |
---|
300 | |
---|
301 | $diff = array_diff($new_values, $old_values); |
---|
302 | $dn = $old_values['dn']; |
---|
303 | |
---|
304 | //echo '<pre>'; |
---|
305 | //print_r($new_values['participantCanSendMail']); |
---|
306 | //print_r($old_values['participantCanSendMail']); |
---|
307 | |
---|
308 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
309 | // ADD ATTRS |
---|
310 | if (($new_values['participantCanSendMail'] == 'on') && ($old_values['participantCanSendMail'] == '')) |
---|
311 | { |
---|
312 | $ldap_add['participantCanSendMail'] = "TRUE"; |
---|
313 | $this->db_functions->write_log("Ativado participantCanSendMail da SCL da lista de email " . $new_values['mail'],'','','',''); |
---|
314 | } |
---|
315 | if (($new_values['accountRestrictive'] == 'on') && ($old_values['accountRestrictive'] == '')) |
---|
316 | { |
---|
317 | $ldap_add['accountRestrictive'] = "mailListRestriction"; |
---|
318 | $ldap_add['accountDeliveryMessage'] = 'OK'; |
---|
319 | $this->db_functions->write_log("Ativado mailListRestriction da SCL da lista de email " . $new_values['mail'],'','','',''); |
---|
320 | } |
---|
321 | if (count($ldap_add)) |
---|
322 | { |
---|
323 | $result = $this->ldap_functions->add_user_attributes($dn, $ldap_add); |
---|
324 | if (!$result['status']) |
---|
325 | { |
---|
326 | $return['status'] = false; |
---|
327 | $return['msg'] .= $result['msg']; |
---|
328 | } |
---|
329 | } |
---|
330 | |
---|
331 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
332 | // REMOVE ATTRS |
---|
333 | if (($new_values['participantCanSendMail'] != 'on') && ($old_values['participantCanSendMail'] == 'TRUE')) |
---|
334 | { |
---|
335 | $ldap_remove['participantCanSendMail'] = array(); |
---|
336 | $this->db_functions->write_log("Desativado participantCanSendMail da SCL da lista de email " . $new_values['mail'],'','','',''); |
---|
337 | } |
---|
338 | if (($new_values['accountRestrictive'] != 'on') && ($old_values['accountRestrictive'] == 'mailListRestriction')) |
---|
339 | { |
---|
340 | $ldap_remove['accountRestrictive'] = array(); |
---|
341 | $ldap_remove['accountDeliveryMessage'] = array(); |
---|
342 | $this->db_functions->write_log("Desativado restrição (mailListRestriction) da SCL da lista de email " . $new_values['mail'],'','','',''); |
---|
343 | } |
---|
344 | if (count($ldap_remove)) |
---|
345 | { |
---|
346 | $result = $this->ldap_functions->remove_user_attributes($dn, $ldap_remove); |
---|
347 | if (!$result['status']) |
---|
348 | { |
---|
349 | $return['status'] = false; |
---|
350 | $return['msg'] .= $result['msg']; |
---|
351 | } |
---|
352 | } |
---|
353 | |
---|
354 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
355 | // USERS |
---|
356 | |
---|
357 | if (!$new_values['members']) |
---|
358 | $new_values['members'] = array(); |
---|
359 | if (!$old_values['members']) |
---|
360 | $old_values['members'] = array(); |
---|
361 | |
---|
362 | $add_users = array_diff($new_values['members'], $old_values['members']); |
---|
363 | $remove_users = array_diff($old_values['members'], $new_values['members']); |
---|
364 | |
---|
365 | if (count($add_users)>0) |
---|
366 | { |
---|
367 | sort($add_users); |
---|
368 | $result = $this->ldap_functions->add_user2maillist_scl($dn, $add_users); |
---|
369 | |
---|
370 | /* log */ |
---|
371 | if (!$result['status']) |
---|
372 | { |
---|
373 | $return['status'] = false; |
---|
374 | $return['msg'] .= $result['msg']; |
---|
375 | } |
---|
376 | else |
---|
377 | { |
---|
378 | foreach($add_users as $index=>$mail) |
---|
379 | { |
---|
380 | $this->db_functions->write_log("Adicionado usuario $mail da SCP da lista de email $dn",$dn,'','',''); |
---|
381 | } |
---|
382 | } |
---|
383 | } |
---|
384 | |
---|
385 | if (count($remove_users)>0) |
---|
386 | { |
---|
387 | sort($remove_users); |
---|
388 | $result = $this->ldap_functions->remove_user2maillist_scl($dn, $remove_users); |
---|
389 | |
---|
390 | /* log */ |
---|
391 | if (!$result['status']) |
---|
392 | { |
---|
393 | $return['status'] = false; |
---|
394 | $return['msg'] .= $result['msg']; |
---|
395 | } |
---|
396 | else |
---|
397 | { |
---|
398 | foreach($add_users as $index=>$mail) |
---|
399 | { |
---|
400 | $this->db_functions->write_log("Removido usuario $mail da SCP da lista de email $dn",$dn,'','',''); |
---|
401 | } |
---|
402 | } |
---|
403 | } |
---|
404 | |
---|
405 | return $return; |
---|
406 | } |
---|
407 | |
---|
408 | function get_info($uidnumber) |
---|
409 | { |
---|
410 | $maillist_info_ldap = $this->ldap_functions->get_maillist_info($uidnumber); |
---|
411 | return $maillist_info_ldap; |
---|
412 | } |
---|
413 | |
---|
414 | function get_scl_info($uidnumber) |
---|
415 | { |
---|
416 | $maillist_info_ldap = $this->ldap_functions->get_maillist_scl_info($uidnumber); |
---|
417 | return $maillist_info_ldap; |
---|
418 | } |
---|
419 | |
---|
420 | function delete($params) |
---|
421 | { |
---|
422 | // Verifica o acesso do gerente |
---|
423 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'delete_maillists')) |
---|
424 | { |
---|
425 | $return['status'] = false; |
---|
426 | $return['msg'] = 'Você não tem acesso para excluir listas de email.'; |
---|
427 | return $return; |
---|
428 | } |
---|
429 | |
---|
430 | $return['status'] = true; |
---|
431 | |
---|
432 | $uidnumber = $params['uidnumber']; |
---|
433 | $uid = $this->ldap_functions->uidnumber2uid($uidnumber); |
---|
434 | $mail = $this->ldap_functions->uidnumber2mail($uidnumber); |
---|
435 | |
---|
436 | //LDAP |
---|
437 | $result_ldap = $this->ldap_functions->delete_maillist($uidnumber, $mail); |
---|
438 | if (!$result_ldap['status']) |
---|
439 | { |
---|
440 | $return['status'] = false; |
---|
441 | $return['msg'] .= $result_ldap['msg']; |
---|
442 | } |
---|
443 | |
---|
444 | if ($return['status'] == true) |
---|
445 | { |
---|
446 | $this->db_functions->write_log('Deletado lista de email','',$uid,'',''); |
---|
447 | } |
---|
448 | |
---|
449 | return $return; |
---|
450 | } |
---|
451 | |
---|
452 | } |
---|
453 | ?> |
---|