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 | /* |
---|
104 | foreach($params['members'] as $index=>$uidnumber) |
---|
105 | { |
---|
106 | $mail = $this->ldap_functions->uidnumber2mail($uidnumber); |
---|
107 | $maillist_info['mailForwardingAddress'][] = $mail; |
---|
108 | $this->db_functions->write_log("Adicionado usuario $mail a lista ".$params['cn']." no momento da criação",$dn,$uidnumber,'',''); |
---|
109 | } |
---|
110 | */ |
---|
111 | |
---|
112 | $maillist_info['mailForwardingAddress'] = $params['mailForwardingAddress']; |
---|
113 | |
---|
114 | $result = $this->ldap_functions->ldap_add_entry($dn, $maillist_info); |
---|
115 | if (!$result['status']) |
---|
116 | { |
---|
117 | $return['status'] = false; |
---|
118 | $return['msg'] .= $result['msg']; |
---|
119 | } |
---|
120 | |
---|
121 | /* log */ |
---|
122 | if ($return['status'] == true) |
---|
123 | { |
---|
124 | $this->db_functions->write_log('Criado lista de email','',$dn,'',''); |
---|
125 | |
---|
126 | foreach($params['mailForwardingAddress'] as $index=>$mail) |
---|
127 | { |
---|
128 | $this->db_functions->write_log("Adicionado email $mail a lista ".$params['cn']." no momento da criação",$dn,'','',''); |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | return $return; |
---|
133 | } |
---|
134 | |
---|
135 | function save($new_values) |
---|
136 | { |
---|
137 | // Verifica o acesso do gerente |
---|
138 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_maillists')) |
---|
139 | { |
---|
140 | $return['status'] = false; |
---|
141 | $return['msg'] = 'Você não tem acesso para editar listas de email.'; |
---|
142 | return $return; |
---|
143 | } |
---|
144 | |
---|
145 | $return['status'] = true; |
---|
146 | |
---|
147 | $old_values = $this->get_info($new_values['uidnumber'], $new_values['manager_context']); |
---|
148 | $diff = array_diff($new_values, $old_values); |
---|
149 | |
---|
150 | $dn = 'uid=' . $old_values['uid'] . ',' . $old_values['context']; |
---|
151 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
152 | // RENAME |
---|
153 | if ($diff['context'] || $diff['uid']) |
---|
154 | { |
---|
155 | $newrdn = 'uid=' . $new_values['uid']; |
---|
156 | $newparent = $new_values['context']; |
---|
157 | $result = $this->ldap_functions->change_user_context($dn, $newrdn, $newparent); |
---|
158 | if (!$result['status']) |
---|
159 | { |
---|
160 | $return['status'] = false; |
---|
161 | $return['msg'] .= $result['msg']; |
---|
162 | } |
---|
163 | else |
---|
164 | { |
---|
165 | $dn = $newrdn . ',' . $newparent; |
---|
166 | $old_dn = $old_values['uid']; |
---|
167 | $this->db_functions->write_log("Renomeado login da lista de $old_dn para $dn",'',$dn,$old_values['uid'],''); |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
172 | // REPLACE MAIL || CN || SN |
---|
173 | if ($new_values['mail'] != $old_values['mail']) |
---|
174 | { |
---|
175 | $ldap_mod_replace['mail'] = $new_values['mail']; |
---|
176 | $this->db_functions->write_log('Modificado email da lista para ' . $new_values['mail'],'',$dn,'',''); |
---|
177 | } |
---|
178 | if ($new_values['cn'] != $old_values['cn']) |
---|
179 | { |
---|
180 | $ldap_mod_replace['cn'] = $new_values['cn']; |
---|
181 | $this->db_functions->write_log("Modificado common name da lista $dn",'',$dn,'',''); |
---|
182 | } |
---|
183 | if ($diff['uid']) |
---|
184 | { |
---|
185 | $ldap_mod_replace['sn'] = $new_values['uid']; |
---|
186 | } |
---|
187 | |
---|
188 | if (count($ldap_mod_replace)) |
---|
189 | { |
---|
190 | $result = $this->ldap_functions->replace_user_attributes($dn, $ldap_mod_replace); |
---|
191 | if (!$result['status']) |
---|
192 | { |
---|
193 | $return['status'] = false; |
---|
194 | $return['msg'] .= $result['msg']; |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|
198 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
199 | // REMOVE ATTRS |
---|
200 | if (($old_values['accountStatus'] == 'active') && ($new_values['accountStatus'] != 'on')) |
---|
201 | $ldap_remove['accountStatus'] = array(); |
---|
202 | |
---|
203 | if (($old_values['phpgwAccountVisible'] == '-1') && ($new_values['phpgwAccountVisible'] != 'on')) |
---|
204 | $ldap_remove['phpgwAccountVisible'] = array(); |
---|
205 | |
---|
206 | if (count($ldap_remove)) |
---|
207 | { |
---|
208 | $result = $this->ldap_functions->remove_user_attributes($dn, $ldap_remove); |
---|
209 | if (!$result['status']) |
---|
210 | { |
---|
211 | $return['status'] = false; |
---|
212 | $return['msg'] .= $result['msg']; |
---|
213 | } |
---|
214 | } |
---|
215 | |
---|
216 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
217 | // ADD ATTRS |
---|
218 | if (($old_values['accountStatus'] != 'active') && ($new_values['accountStatus'] == 'on')) |
---|
219 | $ldap_add['accountStatus'] = 'active'; |
---|
220 | |
---|
221 | if (($old_values['phpgwAccountVisible'] != '-1') && ($new_values['phpgwAccountVisible'] == 'on')) |
---|
222 | $ldap_add['phpgwAccountVisible'] = '-1'; |
---|
223 | |
---|
224 | if (count($ldap_add)) |
---|
225 | { |
---|
226 | $result = $this->ldap_functions->add_user_attributes($dn, $ldap_add); |
---|
227 | if (!$result['status']) |
---|
228 | { |
---|
229 | $return['status'] = false; |
---|
230 | $return['msg'] .= $result['msg']; |
---|
231 | } |
---|
232 | } |
---|
233 | |
---|
234 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
235 | // USERS |
---|
236 | if (!$new_values['mailForwardingAddress']) |
---|
237 | $new_values['mailForwardingAddress'] = array(); |
---|
238 | if (!$old_values['mailForwardingAddress']) |
---|
239 | $old_values['mailForwardingAddress'] = array(); |
---|
240 | |
---|
241 | $add_users = array_diff($new_values['mailForwardingAddress'], $old_values['mailForwardingAddress']); |
---|
242 | $remove_users = array_diff($old_values['mailForwardingAddress'], $new_values['mailForwardingAddress']); |
---|
243 | |
---|
244 | /* echo '<pre>'; |
---|
245 | print_r($new_values);*/ |
---|
246 | |
---|
247 | if (count($add_users)>0) |
---|
248 | { |
---|
249 | sort($add_users); |
---|
250 | $result = $this->ldap_functions->add_user2maillist($new_values['uidnumber'], $add_users); |
---|
251 | |
---|
252 | /* log */ |
---|
253 | if (!$result['status']) |
---|
254 | { |
---|
255 | $return['status'] = false; |
---|
256 | $return['msg'] .= $result['msg']; |
---|
257 | } |
---|
258 | else |
---|
259 | { |
---|
260 | foreach($add_users['mailForwardingAddress'] as $index=>$mail) |
---|
261 | { |
---|
262 | $this->db_functions->write_log("Adicionado usuario $mail a lista de email $dn",$dn,'','',''); |
---|
263 | } |
---|
264 | } |
---|
265 | } |
---|
266 | |
---|
267 | if (count($remove_users)>0) |
---|
268 | { |
---|
269 | sort($remove_users); |
---|
270 | $result = $this->ldap_functions->remove_user2maillist($new_values['uidnumber'], $remove_users); |
---|
271 | |
---|
272 | /* log */ |
---|
273 | if (!$result['status']) |
---|
274 | { |
---|
275 | $return['status'] = false; |
---|
276 | $return['msg'] .= $result['msg']; |
---|
277 | } |
---|
278 | else |
---|
279 | { |
---|
280 | foreach($remove_users as $index=>$mail) |
---|
281 | { |
---|
282 | $this->db_functions->write_log("Removido usuario $mail da lista de email $dn",$dn,'','',''); |
---|
283 | } |
---|
284 | } |
---|
285 | } |
---|
286 | |
---|
287 | return $return; |
---|
288 | } |
---|
289 | |
---|
290 | function save_scl($new_values) |
---|
291 | { |
---|
292 | // Verifica o acesso do gerente |
---|
293 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_maillists')) |
---|
294 | { |
---|
295 | $return['status'] = false; |
---|
296 | $return['msg'] = 'Você não tem acesso para editar listas de email.'; |
---|
297 | return $return; |
---|
298 | } |
---|
299 | |
---|
300 | $return['status'] = true; |
---|
301 | |
---|
302 | //Retira os uids duplicados se existir |
---|
303 | $array_tmp = array(); |
---|
304 | $array_tmp = array_unique($new_values['members']); |
---|
305 | $new_values['members'] = $array_tmp; |
---|
306 | |
---|
307 | $old_values = $this->get_scl_info($new_values['uidnumber'], $new_values['manager_context']); |
---|
308 | $diff = array_diff($new_values, $old_values); |
---|
309 | $dn = $old_values['dn']; |
---|
310 | |
---|
311 | //echo '<pre>'; |
---|
312 | //print_r($new_values['participantCanSendMail']); |
---|
313 | //print_r($old_values['participantCanSendMail']); |
---|
314 | |
---|
315 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
316 | // ADD ATTRS |
---|
317 | if (($new_values['participantCanSendMail'] == 'on') && ($old_values['participantCanSendMail'] == '')) |
---|
318 | { |
---|
319 | $ldap_add['participantCanSendMail'] = "TRUE"; |
---|
320 | $this->db_functions->write_log("Ativado participantCanSendMail da SCL da lista de email " . $new_values['mail'],'','','',''); |
---|
321 | } |
---|
322 | if (($new_values['accountRestrictive'] == 'on') && ($old_values['accountRestrictive'] == '')) |
---|
323 | { |
---|
324 | $ldap_add['accountRestrictive'] = "mailListRestriction"; |
---|
325 | $ldap_add['accountDeliveryMessage'] = 'OK'; |
---|
326 | $this->db_functions->write_log("Ativado mailListRestriction da SCL da lista de email " . $new_values['mail'],'','','',''); |
---|
327 | } |
---|
328 | if (count($ldap_add)) |
---|
329 | { |
---|
330 | $result = $this->ldap_functions->add_user_attributes($dn, $ldap_add); |
---|
331 | if (!$result['status']) |
---|
332 | { |
---|
333 | $return['status'] = false; |
---|
334 | $return['msg'] .= $result['msg']; |
---|
335 | } |
---|
336 | } |
---|
337 | |
---|
338 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
339 | // REMOVE ATTRS |
---|
340 | if (($new_values['participantCanSendMail'] != 'on') && ($old_values['participantCanSendMail'] == 'TRUE')) |
---|
341 | { |
---|
342 | $ldap_remove['participantCanSendMail'] = array(); |
---|
343 | $this->db_functions->write_log("Desativado participantCanSendMail da SCL da lista de email " . $new_values['mail'],'','','',''); |
---|
344 | } |
---|
345 | if (($new_values['accountRestrictive'] != 'on') && ($old_values['accountRestrictive'] == 'mailListRestriction')) |
---|
346 | { |
---|
347 | $ldap_remove['accountRestrictive'] = array(); |
---|
348 | $ldap_remove['accountDeliveryMessage'] = array(); |
---|
349 | $this->db_functions->write_log("Desativado restrição (mailListRestriction) da SCL da lista de email " . $new_values['mail'],'','','',''); |
---|
350 | } |
---|
351 | if (count($ldap_remove)) |
---|
352 | { |
---|
353 | $result = $this->ldap_functions->remove_user_attributes($dn, $ldap_remove); |
---|
354 | if (!$result['status']) |
---|
355 | { |
---|
356 | $return['status'] = false; |
---|
357 | $return['msg'] .= $result['msg']; |
---|
358 | } |
---|
359 | } |
---|
360 | |
---|
361 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
362 | // USERS |
---|
363 | |
---|
364 | if (!$new_values['members']) |
---|
365 | $new_values['members'] = array(); |
---|
366 | if (!$old_values['members']) |
---|
367 | $old_values['members'] = array(); |
---|
368 | |
---|
369 | $add_users = array_diff($new_values['members'], $old_values['members']); |
---|
370 | $remove_users = array_diff($old_values['members'], $new_values['members']); |
---|
371 | |
---|
372 | if (count($add_users)>0) |
---|
373 | { |
---|
374 | $array_emails_add = array(); |
---|
375 | foreach($add_users as $uidnumber) |
---|
376 | { |
---|
377 | if ($uidnumber != -1) |
---|
378 | { |
---|
379 | $mail = $this->ldap_functions->uidnumber2mail($uidnumber); |
---|
380 | $array_emails_add[] = $mail; |
---|
381 | $this->db_functions->write_log("Adicionado usuario $mail a SCL da lista $dn",'',$uidnumber,'',''); |
---|
382 | } |
---|
383 | } |
---|
384 | $result = $this->ldap_functions->add_user2maillist_scl($dn, $array_emails_add); |
---|
385 | if (!$result['status']) |
---|
386 | { |
---|
387 | $return['status'] = false; |
---|
388 | $return['msg'] .= $result['msg']; |
---|
389 | } |
---|
390 | |
---|
391 | } |
---|
392 | |
---|
393 | if (count($remove_users)>0) |
---|
394 | { |
---|
395 | $array_emails_remove = array(); |
---|
396 | foreach($remove_users as $uidnumber) |
---|
397 | { |
---|
398 | if ($uidnumber != -1) |
---|
399 | { |
---|
400 | $mail = $this->ldap_functions->uidnumber2mail($uidnumber); |
---|
401 | $array_emails_remove[] = $mail; |
---|
402 | $this->db_functions->write_log("Removido usuario $mail da SCP da lista $dn",'',$uidnumber,'',''); |
---|
403 | } |
---|
404 | } |
---|
405 | $result = $this->ldap_functions->remove_user2maillist_scl($dn, $array_emails_remove); |
---|
406 | if (!$result['status']) |
---|
407 | { |
---|
408 | $return['status'] = false; |
---|
409 | $return['msg'] .= $result['msg']; |
---|
410 | } |
---|
411 | } |
---|
412 | |
---|
413 | return $return; |
---|
414 | } |
---|
415 | |
---|
416 | function get_info($uidnumber) |
---|
417 | { |
---|
418 | $maillist_info_ldap = $this->ldap_functions->get_maillist_info($uidnumber); |
---|
419 | return $maillist_info_ldap; |
---|
420 | } |
---|
421 | |
---|
422 | function get_scl_info($uidnumber) |
---|
423 | { |
---|
424 | $maillist_info_ldap = $this->ldap_functions->get_maillist_scl_info($uidnumber); |
---|
425 | return $maillist_info_ldap; |
---|
426 | } |
---|
427 | |
---|
428 | function delete($params) |
---|
429 | { |
---|
430 | // Verifica o acesso do gerente |
---|
431 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'delete_maillists')) |
---|
432 | { |
---|
433 | $return['status'] = false; |
---|
434 | $return['msg'] = 'Você não tem acesso para excluir listas de email.'; |
---|
435 | return $return; |
---|
436 | } |
---|
437 | |
---|
438 | $return['status'] = true; |
---|
439 | |
---|
440 | $uidnumber = $params['uidnumber']; |
---|
441 | $uid = $this->ldap_functions->uidnumber2uid($uidnumber); |
---|
442 | $mail = $this->ldap_functions->uidnumber2mail($uidnumber); |
---|
443 | |
---|
444 | //LDAP |
---|
445 | $result_ldap = $this->ldap_functions->delete_maillist($uidnumber, $mail); |
---|
446 | if (!$result_ldap['status']) |
---|
447 | { |
---|
448 | $return['status'] = false; |
---|
449 | $return['msg'] .= $result_ldap['msg']; |
---|
450 | } |
---|
451 | |
---|
452 | if ($return['status'] == true) |
---|
453 | { |
---|
454 | $this->db_functions->write_log('Deletado lista de email','',$uid,'',''); |
---|
455 | } |
---|
456 | |
---|
457 | return $return; |
---|
458 | } |
---|
459 | |
---|
460 | } |
---|
461 | ?> |
---|