root/trunk/gui/admin/hosting_plan_edit.php

Revision 1327, 10.3 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 if (strtolower(Config::get('HOSTING_PLANS_LEVEL')) != 'admin') {
26     header('Location: index.php');
27     die();
28 }
29
30 $tpl = new pTemplate();
31 $tpl->define_dynamic('page', Config::get('ADMIN_TEMPLATE_PATH') . '/hosting_plan_edit.tpl');
32 $tpl->define_dynamic('page_message', 'page');
33
34 $theme_color = Config::get('USER_INITIAL_THEME');
35
36 /*
37  *
38  * static page messages.
39  *
40  */
41 global $hpid;
42 // Show main menu
43 gen_admin_mainmenu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/main_menu_hosting_plan.tpl');
44 gen_admin_menu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/menu_hosting_plan.tpl');
45
46 $tpl->assign(
47         array(
48             'TR_RESELLER_MAIN_INDEX_PAGE_TITLE' => tr('ispCP - Administrator/Edit hosting plan'),
49             'THEME_COLOR_PATH' => "../themes/$theme_color",
50             'THEME_CHARSET' => tr('encoding'),
51             'ISP_LOGO' => get_logo($_SESSION['user_id'])));
52
53 $tpl->assign(
54         array(
55             'TR_HOSTING PLAN PROPS' => tr('Hosting plan properties'),
56             'TR_TEMPLATE_NAME' => tr('Template name'),
57             'TR_MAX_SUBDOMAINS' => tr('Max subdomains<br><i>(-1 disabled, 0 unlimited)</i>'),
58             'TR_MAX_ALIASES' => tr('Max aliases<br><i>(-1 disabled, 0 unlimited)</i>'),
59             'TR_MAX_MAILACCOUNTS' => tr('Mail accounts limit<br><i>(-1 disabled, 0 unlimited)</i>'),
60             'TR_MAX_FTP' => tr('FTP accounts limit<br><i>(-1 disabled, 0 unlimited)</i>'),
61             'TR_MAX_SQL' => tr('SQL databases limit<br><i>(-1 disabled, 0 unlimited)</i>'),
62             'TR_MAX_SQL_USERS' => tr('SQL users limit<br><i>(-1 disabled, 0 unlimited)</i>'),
63             'TR_MAX_TRAFFIC' => tr('Traffic limit [MB]<br><i>(0 unlimited)</i>'),
64             'TR_DISK_LIMIT' => tr('Disk limit [MB]<br><i>(0 unlimited)</i>'),
65             'TR_PHP' => tr('PHP'),
66             'TR_CGI' => tr('CGI / Perl'),
67             'TR_BACKUP_RESTORE' => tr('Backup and restore'),
68             'TR_APACHE_LOGS' => tr('Apache logfiles'),
69             'TR_AWSTATS' => tr('AwStats'),
70             'TR_YES' => tr('yes'),
71             'TR_NO' => tr('no'),
72             'TR_BILLING_PROPS' => tr('Billing Settings'),
73             'TR_PRICE_STYLE' => tr('Price Style'),
74             'TR_PRICE' => tr('Price'),
75             'TR_SETUP_FEE' => tr('Setup fee'),
76             'TR_VALUE' => tr('Currency'),
77             'TR_PAYMENT' => tr('Payment period'),
78             'TR_STATUS' => tr('Available for purchasing'),
79             'TR_TEMPLATE_DESCRIPTON' => tr('Description'),
80             'TR_EXAMPLE' => tr('(e.g. EUR)'),
81             'TR_UPDATE_PLAN' => tr('Update plan')));
82
83 /*
84 * Dynamic page process
85 *
86 */
87 if (isset($_POST['uaction']) && ('add_plan' === $_POST['uaction'])) {
88     // Process data
89     if (check_data_iscorrect($tpl)) { // Save data to db
90         save_data_to_db();
91     } else {
92         restore_form($tpl);
93     }
94 } else {
95     // Get hosting plan id tha come for edit
96     if (isset($_GET['hpid'])) {
97         $hpid = $_GET['hpid'];
98     }
99
100     gen_load_ehp_page($tpl, $sql, $hpid, $_SESSION['user_id']);
101     $tpl->assign('MESSAGE', "");
102 }
103
104 gen_page_message($tpl);
105 $tpl->parse('PAGE', 'page');
106 $tpl->prnt();
107
108 if (Config::get('DUMP_GUI_DEBUG')) dump_gui_debug();
109
110 // *******************************************************
111 // * Function definitions
112 // *
113 // Restore form on any error
114 function restore_form(&$tpl) {
115     $tpl->assign(
116             array(
117                 'HP_NAME_VALUE' => clean_input($_POST['hp_name']),
118                 'HP_DESCRIPTION_VALUE' => clean_input($_POST['hp_description']),
119                 'TR_MAX_SUB_LIMITS' => clean_input($_POST['hp_sub']),
120                 'TR_MAX_ALS_VALUES' => clean_input($_POST['hp_als']),
121                 'HP_MAIL_VALUE' => clean_input($_POST['hp_mail']),
122                 'HP_FTP_VALUE' => clean_input($_POST['hp_ftp']),
123                 'HP_SQL_DB_VALUE' => clean_input($_POST['hp_sql_db']),
124                 'HP_SQL_USER_VALUE' => clean_input($_POST['hp_sql_user']),
125                 'HP_TRAFF_VALUE' => clean_input($_POST['hp_traff']),
126                 'HP_TRAFF' => clean_input($_POST['hp_traff']),
127                 'HP_DISK_VALUE' => clean_input($_POST['hp_disk']),
128                 'HP_PRICE_STYLE' => format_price(clean_input($_POST['hp_style'])),
129                 'HP_PRICE' => clean_input($_POST['hp_price']),
130                 'HP_SETUPFEE' => clean_input($_POST['hp_setupfee']),
131                 'HP_CURRENCY' => clean_input($_POST['hp_currency']),
132                 'HP_PAYMENT' => clean_input($_POST['hp_payment'])
133             ));
134
135     if ('_yes_' === $_POST['php']) {
136         $tpl->assign(array('TR_PHP_YES' => 'checked'));
137     } else
138         $tpl->assign(array('TR_PHP_NO' => 'checked'));
139     if ('_yes_' === $_POST['cgi']) {
140         $tpl->assign(array('TR_CGI_YES' => 'checked'));
141     } else
142         $tpl->assign(array('TR_CGI_NO' => 'checked'));
143
144     if ($_POST['status'] == 1) {
145         $tpl->assign(array('TR_STATUS_YES' => 'checked'));
146     } else
147         $tpl->assign(array('TR_STATUS_NO' => 'checked'));
148 }
149
150 // Generate load data from sql for requested hosting plan
151 function gen_load_ehp_page(&$tpl, &$sql, $hpid, $admin_id) {
152     $_SESSION['hpid'] = $hpid;
153
154     $query = <<<SQL_QUERY
155         select
156             *
157         from
158             hosting_plans
159         where
160             id = ?;
161 SQL_QUERY;
162     $res = exec_query($sql, $query, array($hpid));
163
164     $readonly = '';
165     $disabled = '';
166     $edit_hp = tr('Edit hosting plan');
167     // $tpl -> parse('FORM', 'page');
168     if ($res->RowCount() !== 1) { // Error
169         header('Location: hosting_plan.php');
170         die();
171     }
172
173     $data = $res->FetchRow();
174     $props = $data['props'];
175     $description = $data['description'];
176     $price = $data['price'];
177     $setup_fee = $data['setup_fee'];
178     $value = $data['value'];
179     $payment = $data['payment'];
180     $status = $data['status'];
181     list($hp_php, $hp_cgi, $hp_sub, $hp_als, $hp_mail, $hp_ftp, $hp_sql_db, $hp_sql_user, $hp_traff, $hp_disk) = explode(";", $props);
182     $hp_name = $data['name'];
183
184     if ($description == '')
185         $description = '';
186
187     if ($payment == '')
188         $payment = '';
189
190     if ($value == '')
191         $value = '';
192
193     $tpl->assign(array('HP_NAME_VALUE' => $hp_name,
194             'TR_EDIT_HOSTING_PLAN' => $edit_hp,
195             'TR_MAX_SUB_LIMITS' => $hp_sub,
196             'TR_MAX_ALS_VALUES' => $hp_als,
197             'HP_MAIL_VALUE' => $hp_mail,
198             'HP_FTP_VALUE' => $hp_ftp,
199             'HP_SQL_DB_VALUE' => $hp_sql_db,
200             'HP_SQL_USER_VALUE' => $hp_sql_user,
201             'HP_TRAFF_VALUE' => $hp_traff,
202             'HP_DISK_VALUE' => $hp_disk,
203             'HP_DESCRIPTION_VALUE' => $description,
204             'HP_PRICE' => $price,
205             'HP_SETUPFEE' => $setup_fee,
206             'HP_CURRENCY' => $value,
207             'READONLY' => $readonly,
208             'DISBLED' => $disabled,
209             'HP_PAYMENT' => $payment));
210
211     if ('_yes_' === $hp_php) {
212         $tpl->assign(array('TR_PHP_YES' => 'checked'));
213     } else
214         $tpl->assign(array('TR_PHP_NO' => 'checked'));
215     if ('_yes_' === $hp_cgi) {
216         $tpl->assign(array('TR_CGI_YES' => 'checked'));
217     } else
218         $tpl->assign(array('TR_CGI_NO' => 'checked'));
219
220     if ($status == 1) {
221         $tpl->assign(array('TR_STATUS_YES' => 'checked'));
222     } else
223         $tpl->assign(array('TR_STATUS_NO' => 'checked'));
224 } // End of gen_load_ehp_page()
225
226 // Check correction of input data
227 function check_data_iscorrect(&$tpl) {
228     global $hp_name, $hp_php, $hp_cgi;
229     global $hp_sub, $hp_als, $hp_mail;
230     global $hp_ftp, $hp_sql_db, $hp_sql_user;
231     global $hp_traff, $hp_disk;
232     global $hpid;
233
234     $ahp_error = '_off_';
235     $hp_name = clean_input($_POST['hp_name']);
236     $hp_sub = clean_input($_POST['hp_sub']);
237     $hp_als = clean_input($_POST['hp_als']);
238     $hp_mail = clean_input($_POST['hp_mail']);
239     $hp_ftp = clean_input($_POST['hp_ftp']);
240     $hp_sql_db = clean_input($_POST['hp_sql_db']);
241     $hp_sql_user = clean_input($_POST['hp_sql_user']);
242     $hp_traff = clean_input($_POST['hp_traff']);
243     $hp_disk = clean_input($_POST['hp_disk']);
244
245     if (isset($_SESSION['hpid']))
246         $hpid = $_SESSION['hpid'];
247     else
248         $ahp_error = tr('Undefined reference to data!');
249     // put hosting plan id into session value
250     $_SESSION['hpid'] = $hpid;
251     // Get values from previes page and check him correction
252     if (isset($_POST['php']))
253         $hp_php = $_POST['php'];
254
255     if (isset($_POST['cgi']))
256         $hp_cgi = $_POST['cgi'];;
257
258     if (!is_numeric($_POST['hp_price'])) {
259         $ahp_error = tr('Incorrect price. Example: 9.99');
260     }
261
262     if (!is_numeric($_POST['hp_setupfee'])) {
263         $ahp_error = tr('Incorrect setup fee. Example: 19.99');
264     }
265
266     if (!ispcp_limit_check($hp_sub, -1)) {
267         $ahp_error = tr('Incorrect subdomains limit!');
268     } else if (!ispcp_limit_check($hp_als, -1)) {
269         $ahp_error = tr('Incorrect aliases limit!');
270     } else if (!ispcp_limit_check($hp_mail, -1)) {
271         $ahp_error = tr('Incorrect mail accounts limit!');
272     } else if (!ispcp_limit_check($hp_ftp, -1)) {
273         $ahp_error = tr('Incorrect FTP accounts limit!');
274     } else if (!ispcp_limit_check($hp_sql_user, -1)) {
275         $ahp_error = tr('Incorrect SQL databases limit!');
276     } else if (!ispcp_limit_check($hp_sql_db, -1)) {
277         $ahp_error = tr('Incorrect SQL users limit!');
278     } else if (!ispcp_limit_check($hp_traff, null)) {
279         $ahp_error = tr('Incorrect traffic limit!');
280     } else if (!ispcp_limit_check($hp_disk, null)) {
281         $ahp_error = tr('Incorrect disk quota limit!');
282     }
283
284     if ($ahp_error == '_off_') {
285         $tpl->assign('MESSAGE', '');
286         return true;
287     } else {
288         set_page_message($ahp_error);
289         return false;
290     }
291 } // End of check_data_iscorrect()
292
293 // Add new host plan to DB
294 function save_data_to_db() {
295     $sql = Database::getInstance();
296     global $hp_name, $hp_php, $hp_cgi;
297     global $hp_sub, $hp_als, $hp_mail;
298     global $hp_ftp, $hp_sql_db, $hp_sql_user;
299     global $hp_traff, $hp_disk;
300     global $hpid;
301
302     $description = clean_input($_POST['hp_description']);
303     $price = clean_input($_POST['hp_price']);
304     $setup_fee = clean_input($_POST['hp_setupfee']);
305     $value = clean_input($_POST['hp_currency']);
306     $payment = clean_input($_POST['hp_payment']);
307     $status = clean_input($_POST['status']);
308
309     $hp_props = "$hp_php;$hp_cgi;$hp_sub;$hp_als;$hp_mail;$hp_ftp;$hp_sql_db;$hp_sql_user;$hp_traff;$hp_disk;";
310
311     $query = <<<SQL_QUERY
312         update
313             hosting_plans
314         set
315             name = ?,
316             description = ?,
317             props = ?,
318             price = ?,
319             setup_fee = ?,
320             value = ?,
321             payment = ?,
322             status = ?
323         where
324             id = ?
325 SQL_QUERY;
326     $res = exec_query($sql, $query, array($hp_name, $description, $hp_props, $price, $setup_fee, $value, $payment, $status, $hpid));
327     $_SESSION['hp_updated'] = "_yes_";
328     Header("Location: hosting_plan.php");
329     die();
330 } //End of save_data_to_db()
331 die();
332
333 ?>
Note: See TracBrowser for help on using the browser.