root/trunk/gui/admin/domain_edit.php

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