root/trunk/gui/reseller/domain_edit.php

Revision 1327, 16.6 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('RESELLER_TEMPLATE_PATH') . '/domain_edit.tpl');
27 $tpl->define_dynamic('page_message', 'page');
28 $tpl->define_dynamic('ip_entry', 'page');
29 $tpl->define_dynamic('logged_from', 'page');
30
31 $theme_color = Config::get('USER_INITIAL_THEME');
32
33 if (Config::exists('HOSTING_PLANS_LEVEL') && Config::get('HOSTING_PLANS_LEVEL') === 'admin') {
34     header("Location: users.php");
35     die();
36 }
37
38 $tpl->assign(
39             array(
40                 'TR_EDIT_DOMAIN_PAGE_TITLE' => tr('ispCP - Domain/Edit'),
41                 'THEME_COLOR_PATH' => "../themes/$theme_color",
42                 'THEME_CHARSET' => tr('encoding'),
43                 'ISP_LOGO' => get_logo($_SESSION['user_id'])
44             )
45         );
46
47 /*
48  *
49  * static page messages.
50  *
51  */
52 $tpl->assign(
53             array(
54                 'TR_EDIT_DOMAIN' => tr('Edit Domain'),
55                 'TR_DOMAIN_PROPERTIES' => tr('Domain properties'),
56                 'TR_DOMAIN_NAME' => tr('Domain name'),
57                 'TR_DOMAIN_IP' => tr('Domain IP'),
58                 'TR_PHP_SUPP' => tr('PHP support'),
59                 'TR_CGI_SUPP' => tr('CGI support'),
60                 'TR_SUBDOMAINS' => tr('Max subdomains<br /><i>(-1 disabled, 0 unlimited)</i>'),
61                 'TR_ALIAS' => tr('Max aliases<br /><i>(-1 disabled, 0 unlimited)</i>'),
62                 'TR_MAIL_ACCOUNT' => tr('Mail accounts limit <br /><i>(-1 disabled, 0 unlimited)</i>'),
63                 'TR_FTP_ACCOUNTS' => tr('FTP accounts limit <br /><i>(-1 disabled, 0 unlimited)</i>'),
64                 'TR_SQL_DB' => tr('SQL databases limit <br /><i>(-1 disabled, 0 unlimited)</i>'),
65                 'TR_SQL_USERS' => tr('SQL users limit <br /><i>(-1 disabled, 0 unlimited)</i>'),
66                 'TR_TRAFFIC' => tr('Traffic limit [MB] <br /><i>(0 unlimited)</i>'),
67                 'TR_DISK' => tr('Disk limit [MB] <br /><i>(0 unlimited)</i>'),
68                 'TR_USER_NAME' => tr('Username'),
69                 'TR_UPDATE_DATA' => tr('Submit changes'),
70                 'TR_CANCEL' => tr('Cancel'),
71                 'TR_YES' => tr('Yes'),
72                 'TR_NO' => tr('No')
73             )
74         );
75
76 gen_reseller_mainmenu($tpl, Config::get('RESELLER_TEMPLATE_PATH') . '/main_menu_users_manage.tpl');
77 gen_reseller_menu($tpl, Config::get('RESELLER_TEMPLATE_PATH') . '/menu_users_manage.tpl');
78
79 gen_logged_from($tpl);
80
81 gen_page_message($tpl);
82
83 if (isset($_POST['uaction']) && ('sub_data' === $_POST['uaction'])) {
84     // Process data
85     if (isset($_SESSION['edit_id'])) {
86         $editid = $_SESSION['edit_id'];
87     } else {
88         unset($_SESSION['edit_id']);
89         $_SESSION['edit'] = '_no_';
90
91         header('Location: users.php');
92         die();
93     }
94
95     if (check_user_data($tpl, $sql, $_SESSION['user_id'], $editid)) { // Save data to db
96         $_SESSION['dedit'] = "_yes_";
97         header("Location: users.php");
98         die();
99     }
100     load_additional_data($_SESSION['user_id'], $editid);
101 } else {
102     // Get user id that come for edit
103     if (isset($_GET['edit_id'])) {
104         $editid = $_GET['edit_id'];
105     }
106
107     load_user_data($_SESSION['user_id'], $editid);
108     // $_SESSION['edit_ID'] = $editid;
109     $_SESSION['edit_id'] = $editid;
110     $tpl->assign('MESSAGE', "");
111 }
112
113 gen_editdomain_page($tpl);
114
115 // Begin function block
116
117 // Load data from sql
118 function load_user_data($user_id, $domain_id) {
119     $sql = Database::getInstance();
120
121     global $domain_name, $domain_ip, $php_sup;
122     global $cgi_supp , $sub, $als;
123     global $mail, $ftp, $sql_db;
124     global $sql_user, $traff, $disk;
125     global $username;
126
127     $query = <<<SQL_QUERY
128         SELECT
129             domain_id
130         FROM
131             domain
132         WHERE
133             domain_id = ?
134         AND
135             domain_created_id = ?
136 SQL_QUERY;
137
138     $rs = exec_query($sql, $query, array($domain_id, $user_id));
139
140     if ($rs->RecordCount() == 0) {
141         set_page_message(tr('User does not exist or you do not have permission to access this interface!'));
142
143         header('Location: users.php');
144         die();
145     }
146
147     list ($a, $sub,
148         $b, $als,
149         $c, $mail,
150         $d, $ftp,
151         $e, $sql_db,
152         $f, $sql_user,
153         $traff, $disk
154         ) = generate_user_props($domain_id);;
155
156     load_additional_data($user_id, $domain_id);
157 } //End of load_user_data()
158
159 // Load additional data
160 function load_additional_data($user_id, $domain_id) {
161     $sql = Database::getInstance();
162     global $domain_name, $domain_ip, $php_sup;
163     global $cgi_supp, $username;
164     // Get domain data
165     $query = <<<SQL_QUERY
166         SELECT
167             domain_name,
168             domain_ip_id,
169             domain_php,
170             domain_cgi,
171             domain_admin_id
172         FROM
173             domain
174         WHERE
175             domain_id = ?
176 SQL_QUERY;
177
178     $res = exec_query($sql, $query, array($domain_id));
179     $data = $res->FetchRow();
180
181     $domain_name = $data['domain_name'];
182     $domain_ip_id = $data['domain_ip_id'];
183     $php_sup = $data['domain_php'];
184     $cgi_supp = $data['domain_cgi'];
185     $domain_admin_id = $data['domain_admin_id'];
186     // Get IP of domain
187     $query = <<<SQL_QUERY
188         SELECT
189             ip_number,
190             ip_domain
191         FROM
192             server_ips
193         WHERE
194             ip_id = ?
195 SQL_QUERY;
196
197     $res = exec_query($sql, $query, array($domain_ip_id));
198     $data = $res->FetchRow();
199
200     $domain_ip = $data['ip_number'] . '&nbsp;(' . $data['ip_domain'] . ')';
201     // Get username of domain
202     $query = <<<SQL_QUERY
203         SELECT
204             admin_name
205         FROM
206             admin
207         WHERE
208             admin_id = ?
209         AND
210             admin_type = 'user'
211         AND
212             created_by = ?
213 SQL_QUERY;
214
215     $res = exec_query($sql, $query, array($domain_admin_id, $user_id));
216     $data = $res->FetchRow();
217
218     $username = $data['admin_name'];
219 } //End of load_additional_data()
220
221 // Show user data
222 function gen_editdomain_page(&$tpl) {
223     global $domain_name, $domain_ip, $php_sup;
224     global $cgi_supp , $sub, $als;
225     global $mail, $ftp, $sql_db;
226     global $sql_user, $traff, $disk;
227     global $username;
228     // Fill in the fileds
229     $domain_name = decode_idna($domain_name);
230
231     $username = decode_idna($username);
232
233     generate_ip_list($tpl, $_SESSION['user_id']);
234
235     if ($php_sup === 'yes') {
236         $tpl->assign(
237                 array(
238                     'PHP_YES' => 'selected',
239                     'PHP_NO' => '',
240                 )
241             );
242     } else {
243         $tpl->assign(
244                 array(
245                     'PHP_YES' => '',
246                     'PHP_NO' => 'selected',
247                 )
248             );
249     }
250
251     if ($cgi_supp === 'yes') {
252         $tpl->assign(
253                 array(
254                     'CGI_YES' => 'selected',
255                     'CGI_NO' => '',
256                 )
257             );
258     } else {
259         $tpl->assign(
260                 array(
261                     'CGI_YES' => '',
262                     'CGI_NO' => 'selected',
263                 )
264             );
265     }
266
267     $tpl->assign(
268             array(
269                 'VL_DOMAIN_NAME' => $domain_name,
270                 'VL_DOMAIN_IP' => $domain_ip,
271                 'VL_DOM_SUB' => $sub,
272                 'VL_DOM_ALIAS' => $als,
273                 'VL_DOM_MAIL_ACCOUNT' => $mail,
274                 'VL_FTP_ACCOUNTS' => $ftp,
275                 'VL_SQL_DB' => $sql_db,
276                 'VL_SQL_USERS' => $sql_user,
277                 'VL_TRAFFIC' => $traff,
278                 'VL_DOM_DISK' => $disk,
279                 'VL_USER_NAME' => $username
280             )
281         );
282 } // End of gen_editdomain_page()
283
284 // Check input data
285 function check_user_data(&$tpl, &$sql, $reseller_id, $user_id) {
286     global $sub, $als, $mail, $ftp, $sql_db, $sql_user, $traff, $disk, $sql, $domain_ip, $domain_php, $domain_cgi;
287
288     $sub = clean_input($_POST['dom_sub']);
289     $als = clean_input($_POST['dom_alias']);
290     $mail = clean_input($_POST['dom_mail_acCount']);
291     $ftp = clean_input($_POST['dom_ftp_acCounts']);
292     $sql_db = clean_input($_POST['dom_sqldb']);
293     $sql_user = clean_input($_POST['dom_sql_users']);
294     $traff = clean_input($_POST['dom_traffic']);
295     $disk = clean_input($_POST['dom_disk']);
296     // $domain_ip = $_POST['domain_ip'];
297     $domain_php = $_POST['domain_php'];
298     $domain_cgi = $_POST['domain_cgi'];
299
300     $ed_error = '';
301
302     if (!ispcp_limit_check($sub, -1)) {
303         $ed_error .= tr('Incorrect subdomains limit!');
304     }
305     if (!ispcp_limit_check($als, -1)) {
306         $ed_error .= tr('Incorrect aliases limit!');
307     }
308     if (!ispcp_limit_check($mail, -1)) {
309         $ed_error .= tr('Incorrect mail accounts limit!');
310     }
311     if (!ispcp_limit_check($ftp, -1)) {
312         $ed_error .= tr('Incorrect FTP accounts limit!');
313     }
314     if (!ispcp_limit_check($sql_db, -1)) {
315         $ed_error .= tr('Incorrect SQL users limit!');
316     }
317     else if ($sql_db == -1 && $sql_user != -1) {
318         $ed_error .= tr('SQL databases limit is <i>disabled</i>!');
319     }
320     if (!ispcp_limit_check($sql_user, -1)) {
321         $ed_error .= tr('Incorrect SQL databases limit!');
322     }
323     else if ($sql_user == -1 && $sql_db != -1) {
324         $ed_error .= tr('SQL users limit is <i>disabled</i>!');
325     }
326     if (!ispcp_limit_check($traff, null)) {
327         $ed_error .= tr('Incorrect traffic limit!');
328     }
329     if (!ispcp_limit_check($disk, null)) {
330         $ed_error .= tr('Incorrect disk quota limit!');
331     }
332
333     // $user_props = generate_user_props($user_id);
334     // $reseller_props = generate_reseller_props($reseller_id);
335     list ($usub_current, $usub_max,
336         $uals_current, $uals_max,
337         $umail_current, $umail_max,
338         $uftp_current, $uftp_max,
339         $usql_db_current, $usql_db_max,
340         $usql_user_current, $usql_user_max,
341         $utraff_max, $udisk_max) = generate_user_props($user_id);
342
343     $previous_utraff_max = $utraff_max;
344
345     list ($rdmn_current, $rdmn_max,
346         $rsub_current, $rsub_max,
347         $rals_current, $rals_max,
348         $rmail_current, $rmail_max,
349         $rftp_current, $rftp_max,
350         $rsql_db_current, $rsql_db_max,
351         $rsql_user_current, $rsql_user_max,
352         $rtraff_current, $rtraff_max,
353         $rdisk_current, $rdisk_max
354         ) = get_reseller_default_props($sql, $reseller_id); //generate_reseller_props($reseller_id);
355     list ($a, $b, $c, $d, $e, $f, $utraff_current, $udisk_current, $i, $h) = generate_user_traffic($user_id);
356
357     if (empty($ed_error)) {
358         calculate_user_dvals($sub, $usub_current, $usub_max, $rsub_current, $rsub_max, $ed_error, tr('Subdomain'));
359         calculate_user_dvals($als, $uals_current, $uals_max, $rals_current, $rals_max, $ed_error, tr('Alias'));
360         calculate_user_dvals($mail, $umail_current, $umail_max, $rmail_current, $rmail_max, $ed_error, tr('Mail'));
361         calculate_user_dvals($ftp, $uftp_current, $uftp_max, $rftp_current, $rftp_max, $ed_error, tr('FTP'));
362         calculate_user_dvals($sql_db, $usql_db_current, $usql_db_max, $rsql_db_current, $rsql_db_max, $ed_error, tr('SQL Database'));
363     }
364
365     if (empty($ed_error)) {
366         $query = <<<SQL_QUERY
367             SELECT
368                 COUNT(su.sqlu_id) AS cnt
369             FROM
370                 sql_user AS su,
371                 sql_database AS sd
372             WHERE
373                 su.sqld_id = sd.sqld_id
374             AND
375                 sd.domain_id = ?
376 SQL_QUERY;
377
378         $rs = exec_query($sql, $query, array($_SESSION['edit_id']));
379         calculate_user_dvals($sql_user, $rs->fields['cnt'], $usql_user_max, $rsql_user_current, $rsql_user_max, $ed_error, tr('SQL User'));
380     }
381
382     if (empty($ed_error)) {
383         calculate_user_dvals($traff, $utraff_current / 1024 / 1024 , $utraff_max, $rtraff_current, $rtraff_max, $ed_error, tr('Traffic'));
384         calculate_user_dvals($disk, $udisk_current / 1024 / 1024, $udisk_max, $rdisk_current, $rdisk_max, $ed_error, tr('Disk'));
385     }
386
387     if (empty($ed_error)) {
388         // Set domain's status to 'change' to update mod_cband's limit
389         if ($previous_utraff_max != $utraff_max) {
390             $query = "UPDATE domain SET domain_status = 'change' WHERE domain_id = ?";
391             exec_query($sql, $query, array($user_id));
392             check_for_lock_file();
393             send_request();
394         }
395
396         $user_props = "$usub_current;$usub_max;";
397         $user_props .= "$uals_current;$uals_max;";
398         $user_props .= "$umail_current;$umail_max;";
399         $user_props .= "$uftp_current;$uftp_max;";
400         $user_props .= "$usql_db_current;$usql_db_max;";
401         $user_props .= "$usql_user_current;$usql_user_max;";
402         $user_props .= "$utraff_max;";
403         $user_props .= "$udisk_max;";
404         // $user_props .= "$domain_ip;";
405         $user_props .= "$domain_php;";
406         $user_props .= "$domain_cgi";
407         update_user_props($user_id, $user_props);
408
409         $reseller_props = "$rdmn_current;$rdmn_max;";
410         $reseller_props .= "$rsub_current;$rsub_max;";
411         $reseller_props .= "$rals_current;$rals_max;";
412         $reseller_props .= "$rmail_current;$rmail_max;";
413         $reseller_props .= "$rftp_current;$rftp_max;";
414         $reseller_props .= "$rsql_db_current;$rsql_db_max;";
415         $reseller_props .= "$rsql_user_current;$rsql_user_max;";
416         $reseller_props .= "$rtraff_current;$rtraff_max;";
417         $reseller_props .= "$rdisk_current;$rdisk_max";
418
419         if (!update_reseller_props($reseller_id, $reseller_props)) {
420
421             set_page_message(tr('Domain properties could not be updated!'));
422
423             return false;
424         }
425
426         // update the sql quotas too
427         $query = "SELECT domain_name FROM domain WHERE domain_id=?";
428         $rs = exec_query($sql, $query, array($user_id));
429         $temp_dmn_name = $rs->fields['domain_name'];
430
431         $query = "SELECT COUNT(name) AS cnt FROM quotalimits WHERE name=?";
432         $rs = exec_query($sql, $query, array($temp_dmn_name));
433         if ($rs->fields['cnt'] > 0) {
434             // we need to update it
435             if ($disk == 0) {
436                 $dlim = 0;
437             } else {
438                 $dlim = $disk * 1024 * 1024;
439             }
440
441             $query = "UPDATE quotalimits SET bytes_in_avail = ? WHERE name=?";
442             $rs = exec_query($sql, $query, array($dlim, $temp_dmn_name));
443         }
444
445         set_page_message(tr('Domain properties updated successfully!'));
446
447         return true;
448     } else {
449         $tpl->assign('MESSAGE', $ed_error);
450         $tpl->parse('PAGE_MESSAGE', 'page_message');
451
452         return false;
453     }
454 } //End of check_user_data()
455
456 function calculate_user_dvals($data, $u, &$umax, &$r, $rmax, &$err, $obj) {
457     if ($rmax == 0 && $umax == -1) {
458         if ($data == -1) {
459             return;
460         } else if ($data == 0) {
461             $umax = $data;
462             return;
463         } else if ($data > 0) {
464             $umax = $data;
465             $r += $umax;
466             return;
467         }
468     } else if ($rmax == 0 && $umax == 0) {
469         if ($data == -1) {
470             if ($u > 0) {
471                 $err .= tr('The <em>%s</em> service can not be disabled! ', $obj) . tr('There are <em>%s</em> records on system!', $obj);
472             } else {
473                 $umax = $data;
474             }
475
476             return;
477         } else if ($data == 0) {
478             return;
479         } else if ($data > 0) {
480             if ($u > $data) {
481                 $err .= tr('The <em>%s</em> service can not be limited! ', $obj) . tr