root/trunk/gui/client/mail_catchall_add.php

Revision 1327, 13.1 kB (checked in by rats, 4 months ago)

* Fixed: --scan-knownbad-files and --check-deleted are no longer supported by rkhunter
* Fixed #1471: chkrootkit should be in lenny / hardy
* Updated Chinese (simplified)
* Updated German
* Fixed #1475: typo on installation (ispcp-setup)
* Fixed: default user for rkhunter.log

Line 
1 <?php
2 /**
3  * ispCP ω (OMEGA) a Virtual Hosting Control System
4  *
5  * @copyright     2001-2006 by moleSoftware GmbH
6  * @copyright     2006-2008 by ispCP | http://isp-control.net
7  * @version     SVN: $Id$
8  * @link         http://isp-control.net
9  * @author         ispCP Team
10  *
11  * @license
12  *   This program is free software; you can redistribute it and/or modify it under
13  *   the terms of the MPL General Public License as published by the Free Software
14  *   Foundation; either version 1.1 of the License, or (at your option) any later
15  *   version.
16  *   You should have received a copy of the MPL Mozilla Public License along with
17  *   this program; if not, write to the Open Source Initiative (OSI)
18  *   http://opensource.org | osi@opensource.org
19  */
20
21 require '../include/ispcp-lib.php';
22
23 check_login(__FILE__);
24
25 $tpl = new pTemplate();
26 $tpl->define_dynamic('page', Config::get('CLIENT_TEMPLATE_PATH') . '/mail_catchall_add.tpl');
27 $tpl->define_dynamic('page_message', 'page');
28 $tpl->define_dynamic('logged_from', 'page');
29 $tpl->define_dynamic('mail_list', 'page');
30
31 if (isset($_GET['id'])) {
32     $item_id = $_GET['id'];
33 } else if (isset($_POST['id'])) {
34     $item_id = $_POST['id'];
35 } else {
36     user_goto('mail_catchall.php');
37 }
38
39 // page functions.
40
41 function gen_dynamic_page_data(&$tpl, &$sql, $id) {
42     global $domain_id;
43
44     list($dmn_id,
45         $dmn_name,
46         $dmn_gid,
47         $dmn_uid,
48         $dmn_created_id,
49         $dmn_created,
50         $dmn_last_modified,
51         $dmn_mailacc_limit,
52         $dmn_ftpacc_limit,
53         $dmn_traff_limit,
54         $dmn_sqld_limit,
55         $dmn_sqlu_limit,
56         $dmn_status,
57         $dmn_als_limit,
58         $dmn_subd_limit,
59         $dmn_ip_id,
60         $dmn_disk_limit,
61         $dmn_disk_usage,
62         $dmn_php,
63         $dmn_cgi) = get_domain_default_props($sql, $_SESSION['user_id']);
64
65     $domain_id = $dmn_id;
66
67     list($mail_acc_cnt,
68         $dmn_mail_acc_cnt,
69         $sub_mail_acc_cnt,
70         $als_mail_acc_cnt) = get_domain_running_mail_acc_cnt($sql, $dmn_id);
71
72     if ($dmn_mailacc_limit != 0 && $mail_acc_cnt >= $dmn_mailacc_limit) {
73         set_page_message(tr('Mail accounts limit reached!'));
74         header("Location: mail_catchall.php");
75         die();
76     }
77
78     $ok_status = Config::get('ITEM_OK_STATUS');
79     $match = array();
80     if (preg_match("/(\d+);(dmn|als|sub)/", $id, $match) == 1) {
81         $item_id = $match[1];
82         $item_type = $match[2];
83
84         if ($item_type === 'dmn') {
85             $query = <<<SQL_QUERY
86                 SELECT
87                     t1.mail_id, t1.mail_type, t2.domain_name, t1.mail_acc
88                 FROM
89                     mail_users AS t1,
90                     domain AS t2
91                 WHERE
92                     t1.domain_id = ?
93                   AND
94                     t2.domain_id = ?
95                   AND
96                     t1.sub_id = '0'
97                   AND
98                     t1.status = ?
99                 ORDER BY
100                     t1.mail_type DESC, t1.mail_acc
101 SQL_QUERY;
102
103             $rs = exec_query($sql, $query, array($item_id, $item_id, $ok_status));
104             if ($rs->RecordCount() == 0) {
105                 $tpl->assign(array('FORWARD_MAIL' => 'checked', 'MAIL_LIST' => '', 'DEFAULT' => 'forward'));
106             } else {
107                 $tpl->assign(array('NORMAL_MAIL' => 'checked', 'FORWARD_MAIL' => '', 'DEFAULT' => 'normal'));
108
109                 while (!$rs->EOF) {
110                     $show_mail_acc = decode_idna($rs->fields['mail_acc']);
111                     $show_domain_name = decode_idna($rs->fields['domain_name']);
112                     $mail_acc = $rs->fields['mail_acc'];
113                     $domain_name = $rs->fields['domain_name'];
114                     $tpl->assign(array('MAIL_ID' => $rs->fields['mail_id'],
115                             'MAIL_ACCOUNT' => $show_mail_acc . "@" . $show_domain_name, // this will be show in the templates
116                             'MAIL_ACCOUNT_PUNNY' => $mail_acc . "@" . $domain_name // this will be updated wenn we crate cach all
117                             )
118                         );
119
120                     $tpl->parse('MAIL_LIST', '.mail_list');
121                     $rs->MoveNext();
122                 }
123             }
124         } else if ($item_type === 'als') {
125             $query = <<<SQL_QUERY
126                 SELECT
127                     t1.mail_id, t1.mail_type, t2.alias_name, t1.mail_acc
128                 FROM
129                     mail_users AS t1,
130                     domain_aliasses AS t2
131                 WHERE
132                     t1.sub_id = t2.alias_id
133                   AND
134                     t1.status = ?
135                   AND
136                     t2.alias_id = ?
137                 ORDER BY
138                   t1.mail_type DESC, t1.mail_acc
139 SQL_QUERY;
140
141             $rs = exec_query($sql, $query, array($ok_status, $item_id));
142
143             if ($rs->RecordCount() == 0) {
144                 $tpl->assign(array('FORWARD_MAIL' => 'checked', 'MAIL_LIST' => '', 'DEFAULT' => 'forward'));
145             } else {
146                 $tpl->assign(array('NORMAL_MAIL' => 'checked', 'FORWARD_MAIL' => '', 'DEFAULT' => 'normal'));
147
148                 while (!$rs->EOF) {
149                     $show_mail_acc = decode_idna($rs->fields['mail_acc']);
150                     $show_alias_name = decode_idna($rs->fields['alias_name']);
151                     $mail_acc = $rs->fields['mail_acc'];
152                     $alias_name = $rs->fields['alias_name'];
153                     $tpl->assign(array('MAIL_ID' => $rs->fields['mail_id'],
154                             'MAIL_ACCOUNT' => $show_mail_acc . "@" . $show_alias_name, // this will be show in the templates
155                             'MAIL_ACCOUNT_PUNNY' => $mail_acc . "@" . $alias_name // this will be updated wenn we crate cach all
156                             )
157                         );
158
159                     $tpl->parse('MAIL_LIST', '.mail_list');
160                     $rs->MoveNext();
161                 }
162             }
163         } else if ($item_type === 'sub') {
164             $query = <<<SQL_QUERY
165                 SELECT
166                     t1.mail_id, t1.mail_type, CONCAT( t2.subdomain_name, '.', t3.domain_name ) AS subdomain_name, t1.mail_acc
167                 FROM
168                     mail_users AS t1,
169                       subdomain AS t2,
170                       domain AS t3
171                 WHERE
172                     t1.sub_id = t2.subdomain_id
173                   AND
174                       t2.domain_id = t3.domain_id
175                   AND
176                     t1.status = ?
177                   AND
178                       (t1.mail_type = 'subdom_mail'
179                     or
180                     t1.mail_type = 'subdom_forward')
181                   AND
182                     t2.subdomain_id = ?
183                 ORDER BY
184                   t1.mail_type DESC, t1.mail_acc
185 SQL_QUERY;
186
187             $rs = exec_query($sql, $query, array($ok_status, $item_id));
188
189             if ($rs->RecordCount() == 0) {
190                 $tpl->assign(array('FORWARD_MAIL' => 'checked', 'MAIL_LIST' => '', 'DEFAULT' => 'forward'));
191             } else {
192                 $tpl->assign(array('NORMAL_MAIL' => 'checked', 'FORWARD_MAIL' => '', 'DEFAULT' => 'normal'));
193
194                 while (!$rs->EOF) {
195                     $show_mail_acc = decode_idna($rs->fields['mail_acc']);
196                     $show_alias_name = decode_idna($rs->fields['subdomain_name']);
197                     $mail_acc = $rs->fields['mail_acc'];
198                     $alias_name = $rs->fields['subdomain_name'];
199                     $tpl->assign(array('MAIL_ID' => $rs->fields['mail_id'],
200                             'MAIL_ACCOUNT' => $show_mail_acc . "@" . $show_alias_name, // this will be show in the templates
201                             'MAIL_ACCOUNT_PUNNY' => $mail_acc . "@" . $alias_name // this will be updated wenn we create catch all
202                             )
203                         );
204
205                     $tpl->parse('MAIL_LIST', '.mail_list');
206                     $rs->MoveNext();
207                 }
208             }
209         }
210     } else {
211         user_goto('mail_catchall.php');
212     }
213 }
214
215 function create_catchall_mail_account(&$sql, $id) {
216     list($realId, $type) = explode(';', $id);
217     // Check if user is owner of the domain
218     if (!preg_match('(dmn|als|sub)', $type) || who_owns_this($realId, $type) != $_SESSION['user_id']) {
219         set_page_message(tr('User does not exist or you do not have permission to access this interface!'));
220         user_goto('mail_catchall.php');
221     }
222
223     $match = array();
224     if (isset($_POST['uaction']) && $_POST['uaction'] === 'create_catchall' && $_POST['mail_type'] === 'normal') {
225         if (preg_match("/(\d+);(dmn|als|sub)/", $id, $match) == 1) {
226             $item_id = $match[1];
227             $item_type = $match[2];
228             $post_mail_id = $_POST['mail_id'];
229
230             if (preg_match("/(\d+);([^;]+);/", $post_mail_id, $match) == 1) {
231                 $mail_id = $match[1];
232                 $mail_acc = $match[2];
233
234                 if ($item_type === 'dmn') {
235                     $mail_type = 'normal_catchall';
236                 } elseif ($item_type === 'als') {
237                     $mail_type = 'alias_catchall';
238                 } elseif ($item_type === 'sub') {
239                     $mail_type = 'subdom_catchall';
240                 }
241
242                 $query = <<<SQL_QUERY
243                     SELECT
244                         domain_id, sub_id
245                     FROM
246                         mail_users
247                     WHERE
248                         mail_id = ?
249 SQL_QUERY;
250
251                 $rs = exec_query($sql, $query, array($mail_id));
252                 $domain_id = $rs->fields['domain_id'];
253                 $sub_id = $rs->fields['sub_id'];
254                 $status = Config::get('ITEM_ADD_STATUS');
255
256                 // find the mail_addr (catchall -> "@(sub/alias)domain.tld", should be domain part of mail_acc
257                 $match = explode('@', $mail_acc);
258                 $mail_addr = '@' . $match[1];
259
260                 check_for_lock_file();
261
262                 $query = <<<SQL_QUERY
263                     INSERT INTO `mail_users`
264                         (mail_acc,
265                          mail_pass,
266                          mail_forward,
267                          domain_id,
268                          mail_type,
269                          sub_id,
270                          status,
271                          mail_auto_respond,
272              quota,
273              mail_addr)
274                     VALUES
275                         (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
276 SQL_QUERY;
277
278                 $rs = exec_query($sql, $query, array($mail_acc, '_no_', '_no_', $domain_id, $mail_type, $sub_id, $status, '_no_', NULL, $mail_addr));
279
280                 send_request();
281                 write_log($_SESSION['user_logged'] . ": adds new email catch all");
282                 set_page_message(tr('Catch all account scheduled for creation!'));
283                 user_goto('mail_catchall.php');
284             } else {
285                 user_goto('mail_catchall.php');
286             }
287         }
288     } else if (isset($_POST['uaction']) && $_POST['uaction'] === 'create_catchall' && $_POST['mail_type'] === 'forward' && isset($_POST['forward_list'])) {
289         if (preg_match("/(\d+);(dmn|als|sub)/", $id, $match) == 1) {
290             $item_id = $match[1];
291             $item_type = $match[2];
292
293             if ($item_type === 'dmn') {
294                 $mail_type = 'normal_catchall';
295                 $sub_id = '0';
296                 $domain_id = $item_id;
297                 $query = "SELECT `domain_name` FROM `domain`
298                     WHERE `domain_id` = ?";
299                 $rs = exec_query($sql, $query, $domain_id);
300                 $mail_addr = '@' . $rs->fields['domain_name'];
301             } elseif ($item_type === 'als') {
302                 $mail_type = 'alias_catchall';
303                 $sub_id = $item_id;
304                 $query = "SELECT `domain_aliasses`.`domain_id`, `alias_name` FROM `domain_aliasses`
305                     WHERE `alias_id` = ?";
306                 $rs = exec_query($sql, $query, $item_id);
307                 $domain_id = $rs->fields['domain_id'];
308                 $mail_addr = '@' . $rs->fields['alias_name'];
309
310             } elseif ($item_type === 'sub') {
311                 $mail_type = 'subdom_catchall';
312                 $sub_id = $item_id;
313                 $query = "SELECT `subdomain`.`domain_id`, `subdomain_name`, `domain_name` FROM `subdomain`, `domain`
314                     WHERE `subdomain_id` = ? AND `domain`.`domain_id` = `subdomain`.`domain_id`";
315                 $rs = exec_query($sql, $query, $item_id);
316                 $domain_id = $rs->fields['domain_id'];
317                 $mail_addr = '@' . $rs->fields['subdomain_name'] . '.' . $rs->fields['domain_name'];
318             }
319             $mail_forward = clean_input($_POST['forward_list']);
320             $mail_acc = array();
321             $faray = preg_split ("/[\n,]+/", $mail_forward);
322
323             foreach ($faray as $value) {
324                 $value = trim($value);
325                 if (!chk_email($value) && $value !== '') {
326                     /* ERR .. strange :) not email in this line - warning */
327                     set_page_message(tr("Mail forward list error!"));
328                     return;
329                 } else if ($value === '') {
330                     set_page_message(tr("Mail forward list error!"));
331                     return;
332                 }
333                 $mail_acc[] = $value;
334             }
335
336             $status = Config::get('ITEM_ADD_STATUS');
337             check_for_lock_file();
338
339             $query = <<<SQL_QUERY
340                     INSERT INTO `mail_users`
341                         (mail_acc,
342                          mail_pass,
343                          mail_forward,
344                          domain_id,
345                          mail_type,
346                          sub_id,
347                          status,
348                          mail_auto_respond,
349              quota,
350              mail_addr)
351                     VALUES
352                         (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
353 SQL_QUERY;
354
355             $rs = exec_query($sql, $query, array(implode(',', $mail_acc), '_no_', '_no_', $domain_id, $mail_type, $sub_id, $status, '_no_', NULL, $mail_addr));
356
357             send_request();
358             write_log($_SESSION['user_logged'] . ": adds new email catch all ");
359             set_page_message(tr('Catch all account scheduled for creation!'));
360             user_goto('mail_catchall.php');
361         } else {
362             user_goto('mail_catchall.php');
363         }
364     }
365 }
366
367 // common page data.
368
369 $theme_color = Config::get('USER_INITIAL_THEME');
370
371 $tpl->assign(array('TR_CLIENT_CREATE_CATCHALL_PAGE_TITLE' => tr('ispCP - Client/Create CatchAll Mail Account'),
372         'THEME_COLOR_PATH' => "../themes/$theme_color",
373         'THEME_CHARSET' => tr('encoding'),
374         'ISP_LOGO' => get_logo($_SESSION['user_id'])));
375
376 // dynamic page data.
377
378 gen_dynamic_page_data($tpl, $sql, $item_id);
379 create_catchall_mail_account($sql, $item_id);
380 $tpl->assign('ID', $item_id);
381
382 // static page messages.
383
384 gen_client_mainmenu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/main_menu_email_accounts.tpl');
385 gen_client_menu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/menu_email_accounts.tpl');
386
387 gen_logged_from($tpl);
388
389 check_permissions($tpl);
390
391 $tpl->assign(array('TR_CREATE_CATCHALL_MAIL_ACCOUNT' => tr('Create catch all mail account'),
392         'TR_MAIL_LIST' => tr('Mail accounts list'),
393         'TR_CREATE_CATCHALL' => tr('Create catch all'),
394         'TR_FORWARD_MAIL' => tr('Forward mail'),
395         'TR_FORWARD_TO' => tr('Forward to')));
396
397 gen_page_message($tpl);
398
399 $tpl->parse('PAGE', 'page');
400 $tpl->prnt();
401
402 if (Config::get('DUMP_GUI_DEBUG'))
403     dump_gui_debug();
404
405 unset_messages();
406
407 ?>
Note: See TracBrowser for help on using the browser.