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 uids duplicados se existir |
---|
53 | $array_tmp = array(); |
---|
54 | $array_tmp = array_unique($params['members']); |
---|
55 | $params['members'] = $array_tmp; |
---|
56 | |
---|
57 | // Pega ID do BD e incrementa de 1. |
---|
58 | $id = (($this->db_functions->get_next_id()) + 1); |
---|
59 | |
---|
60 | // Incrementa o id no BD. |
---|
61 | $this->db_functions->increment_id($id,'accounts'); |
---|
62 | |
---|
63 | // Cria array para incluir no LDAP |
---|
64 | $dn = 'uid=' . $params['uid'] . ',' . $params['context']; |
---|
65 | |
---|
66 | $maillist_info = array(); |
---|
67 | $maillist_info['uid'] = $params['uid']; |
---|
68 | $maillist_info['givenName'] = 'MailList'; |
---|
69 | $maillist_info['sn'] = $params['uid']; |
---|
70 | $maillist_info['cn'] = $params['cn']; |
---|
71 | |
---|
72 | $maillist_info['homeDirectory'] = '/home/false'; |
---|
73 | $maillist_info['loginShell'] = '/bin/false'; |
---|
74 | $maillist_info['mail'] = $params['mail']; |
---|
75 | $maillist_info['objectClass'][0] = 'posixAccount'; |
---|
76 | $maillist_info['objectClass'][1] = 'inetOrgPerson'; |
---|
77 | $maillist_info['objectClass'][2] = 'shadowAccount'; |
---|
78 | $maillist_info['objectClass'][3] = 'qmailuser'; |
---|
79 | $maillist_info['objectClass'][4] = 'phpgwAccount'; |
---|
80 | $maillist_info['objectClass'][5] = 'top'; |
---|
81 | $maillist_info['objectClass'][6] = 'person'; |
---|
82 | $maillist_info['objectClass'][7] = 'organizationalPerson'; |
---|
83 | $maillist_info['phpgwAccountExpires'] = '-1'; |
---|
84 | $maillist_info['phpgwAccountType'] = 'l'; |
---|
85 | $maillist_info['uidnumber'] = $id; |
---|
86 | $maillist_info['gidnumber'] = '0'; |
---|
87 | $maillist_info['userPassword'] = ''; |
---|
88 | $maillist_info['deliveryMode'] = 'forwardOnly'; |
---|
89 | |
---|
90 | if ($params['accountStatus'] == 'on') |
---|
91 | $maillist_info['accountStatus'] = 'active'; |
---|
92 | |
---|
93 | if ($params['phpgwAccountVisible'] == 'on') |
---|
94 | $maillist_info['phpgwAccountVisible'] = '-1'; |
---|
95 | |
---|
96 | foreach($params['members'] as $index=>$uidnumber) |
---|
97 | { |
---|
98 | $mail = $this->ldap_functions->uidnumber2mail($uidnumber); |
---|
99 | $maillist_info['mailForwardingAddress'][] = $mail; |
---|
100 | $this->db_functions->write_log("Adicionado usuario $mail a lista ".$params['cn']." no momento da criação",$dn,$uidnumber,'',''); |
---|
101 | } |
---|
102 | |
---|
103 | $result = $this->ldap_functions->ldap_add_entry($dn, $maillist_info); |
---|
104 | if (!$result['status']) |
---|
105 | { |
---|
106 | $return['status'] = false; |
---|
107 | $return['msg'] .= $result['msg']; |
---|
108 | } |
---|
109 | |
---|
110 | if ($return['status'] == true) |
---|
111 | { |
---|
112 | $this->db_functions->write_log('Criado lista de email','',$dn,'',''); |
---|
113 | } |
---|
114 | |
---|
115 | return $return; |
---|
116 | } |
---|
117 | |
---|
118 | function save($new_values) |
---|
119 | { |
---|
120 | // Verifica o acesso do gerente |
---|
121 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_maillists')) |
---|
122 | { |
---|
123 | $return['status'] = false; |
---|
124 | $return['msg'] = 'Você não tem acesso para editar listas de email.'; |
---|
125 | return $return; |
---|
126 | } |
---|
127 | |
---|
128 | $return['status'] = true; |
---|
129 | |
---|
130 | //Retira os uids duplicados se existir |
---|
131 | $array_tmp = array(); |
---|
132 | $array_tmp = array_unique($new_values['members']); |
---|
133 | $new_values['members'] = $array_tmp; |
---|
134 | |
---|
135 | $old_values = $this->get_info($new_values['uidnumber'], $new_values['manager_context']); |
---|
136 | $diff = array_diff($new_values, $old_values); |
---|
137 | |
---|
138 | $dn = 'uid=' . $old_values['uid'] . ',' . $old_values['context']; |
---|
139 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
140 | // RENAME |
---|
141 | if ($diff['context'] || $diff['uid']) |
---|
142 | { |
---|
143 | $newrdn = 'uid=' . $new_values['uid']; |
---|
144 | $newparent = $new_values['context']; |
---|
145 | $result = $this->ldap_functions->change_user_context($dn, $newrdn, $newparent); |
---|
146 | if (!$result['status']) |
---|
147 | { |
---|
148 | $return['status'] = false; |
---|
149 | $return['msg'] .= $result['msg']; |
---|
150 | } |
---|
151 | else |
---|
152 | { |
---|
153 | $dn = $newrdn . ',' . $newparent; |
---|
154 | $this->db_functions->write_log('Renomeado login da lista','',$dn,$old_values['uid'],''); |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
159 | // REPLACE MAIL & CN |
---|
160 | if ($new_values['mail'] != $old_values['mail']) |
---|
161 | { |
---|
162 | $ldap_mod_replace['mail'] = $new_values['mail']; |
---|
163 | $this->db_functions->write_log('Modificado email da lista','',$dn,'',''); |
---|
164 | } |
---|
165 | if ($new_values['cn'] != $old_values['cn']) |
---|
166 | { |
---|
167 | $ldap_mod_replace['cn'] = $new_values['cn']; |
---|
168 | $this->db_functions->write_log('Modificado common name da lista','',$dn,'',''); |
---|
169 | } |
---|
170 | |
---|
171 | if (count($ldap_mod_replace)) |
---|
172 | { |
---|
173 | $result = $this->ldap_functions->replace_user_attributes($dn, $ldap_mod_replace); |
---|
174 | if (!$result['status']) |
---|
175 | { |
---|
176 | $return['status'] = false; |
---|
177 | $return['msg'] .= $result['msg']; |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
182 | // REMOVE ATTRS |
---|
183 | if (($old_values['accountStatus'] == 'active') && ($new_values['accountStatus'] != 'on')) |
---|
184 | $ldap_remove['accountStatus'] = array(); |
---|
185 | |
---|
186 | if (($old_values['phpgwAccountVisible'] == '-1') && ($new_values['phpgwAccountVisible'] != 'on')) |
---|
187 | $ldap_remove['phpgwAccountVisible'] = array(); |
---|
188 | |
---|
189 | if (count($ldap_remove)) |
---|
190 | { |
---|
191 | $result = $this->ldap_functions->remove_user_attributes($dn, $ldap_remove); |
---|
192 | if (!$result['status']) |
---|
193 | { |
---|
194 | $return['status'] = false; |
---|
195 | $return['msg'] .= $result['msg']; |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
200 | // ADD ATTRS |
---|
201 | if (($old_values['accountStatus'] != 'active') && ($new_values['accountStatus'] == 'on')) |
---|
202 | $ldap_add['accountStatus'] = 'active'; |
---|
203 | |
---|
204 | if (($old_values['phpgwAccountVisible'] != '-1') && ($new_values['phpgwAccountVisible'] == 'on')) |
---|
205 | $ldap_add['phpgwAccountVisible'] = '-1'; |
---|
206 | |
---|
207 | if (count($ldap_add)) |
---|
208 | { |
---|
209 | $result = $this->ldap_functions->add_user_attributes($dn, $ldap_add); |
---|
210 | if (!$result['status']) |
---|
211 | { |
---|
212 | $return['status'] = false; |
---|
213 | $return['msg'] .= $result['msg']; |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|
217 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
218 | // USERS |
---|
219 | |
---|
220 | if (!$new_values['members']) |
---|
221 | $new_values['members'] = array(); |
---|
222 | if (!$old_values['members']) |
---|
223 | $old_values['members'] = array(); |
---|
224 | |
---|
225 | $add_users = array_diff($new_values['members'], $old_values['members']); |
---|
226 | $remove_users = array_diff($old_values['members'], $new_values['members']); |
---|
227 | |
---|
228 | if (count($add_users)>0) |
---|
229 | { |
---|
230 | $array_emails_add = array(); |
---|
231 | foreach($add_users as $uidnumber) |
---|
232 | { |
---|
233 | $mail = $this->ldap_functions->uidnumber2mail($uidnumber); |
---|
234 | $array_emails_add[] = $mail; |
---|
235 | $this->db_functions->write_log("Adicionado usuario $mail a lista",$dn,$uidnumber,'',''); |
---|
236 | } |
---|
237 | $this->ldap_functions->add_user2maillist($new_values['uidnumber'], $array_emails_add); |
---|
238 | } |
---|
239 | if (count($remove_users)>0) |
---|
240 | { |
---|
241 | $array_emails_remove = array(); |
---|
242 | foreach($remove_users as $uidnumber) |
---|
243 | { |
---|
244 | $mail = $this->ldap_functions->uidnumber2mail($uidnumber); |
---|
245 | $array_emails_remove[] = $mail; |
---|
246 | $this->db_functions->write_log("Removido usuario $mail da lista",$dn,$uidnumber,'',''); |
---|
247 | } |
---|
248 | $this->ldap_functions->remove_user2maillist($new_values['uidnumber'], $array_emails_remove); |
---|
249 | } |
---|
250 | |
---|
251 | return $return; |
---|
252 | } |
---|
253 | |
---|
254 | |
---|
255 | function get_info($uidnumber, $context) |
---|
256 | { |
---|
257 | $maillist_info_ldap = $this->ldap_functions->get_maillist_info($uidnumber, $context); |
---|
258 | return $maillist_info_ldap; |
---|
259 | } |
---|
260 | |
---|
261 | function delete($params) |
---|
262 | { |
---|
263 | // Verifica o acesso do gerente |
---|
264 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'delete_maillists')) |
---|
265 | { |
---|
266 | $return['status'] = false; |
---|
267 | $return['msg'] = 'Você não tem acesso para excluir listas de email.'; |
---|
268 | return $return; |
---|
269 | } |
---|
270 | |
---|
271 | $return['status'] = true; |
---|
272 | |
---|
273 | $uidnumber = $params['uidnumber']; |
---|
274 | $uid = $this->ldap_functions->uidnumber2uid($uidnumber); |
---|
275 | |
---|
276 | //LDAP |
---|
277 | $result_ldap = $this->ldap_functions->delete_maillist($uidnumber); |
---|
278 | if (!$result_ldap['status']) |
---|
279 | { |
---|
280 | $return['status'] = false; |
---|
281 | $return['msg'] .= $result_ldap['msg']; |
---|
282 | } |
---|
283 | |
---|
284 | if ($return['status'] == true) |
---|
285 | { |
---|
286 | $this->db_functions->write_log('Deletado lista de email','',$uid,'',''); |
---|
287 | } |
---|
288 | |
---|
289 | return $return; |
---|
290 | } |
---|
291 | |
---|
292 | } |
---|
293 | ?> |
---|