root/trunk/gui/reseller/hosting_plan_add.php

Revision 1327, 9.5 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 (Config::exists('HOSTING_PLANS_LEVEL') && strtolower(Config::get('HOSTING_PLANS_LEVEL')) == 'admin') {
26     Header("Location: hosting_plan.php");
27     die();
28 }
29
30 $tpl = new pTemplate();
31 $tpl->define_dynamic('page', Config::get('RESELLER_TEMPLATE_PATH') . '/hosting_plan_add.tpl');
32 $tpl->define_dynamic('page_message', 'page');
33 $tpl->define_dynamic('logged_from', 'page');
34
35 $theme_color = Config::get('USER_INITIAL_THEME');
36
37 $tpl->assign(
38         array(
39             'TR_RESELLER_MAIN_INDEX_PAGE_TITLE' => tr('ispCP - Reseller/Add hosting plan'),
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
52 gen_reseller_mainmenu($tpl, Config::get('RESELLER_TEMPLATE_PATH') . '/main_menu_hosting_plan.tpl');
53 gen_reseller_menu($tpl, Config::get('RESELLER_TEMPLATE_PATH') . '/menu_hosting_plan.tpl');
54
55 gen_logged_from($tpl);
56
57 $tpl->assign(
58         array(
59             'TR_ADD_HOSTING_PLAN' => tr('Add hosting plan'),
60             'TR_HOSTING PLAN PROPS' => tr('Hosting plan properties'),
61             'TR_TEMPLATE_NAME' => tr('Template name'),
62             'TR_MAX_SUBDOMAINS' => tr('Max subdomains<br><i>(-1 disabled, 0 unlimited)</i>'),
63             'TR_MAX_ALIASES' => tr('Max aliases<br><i>(-1 disabled, 0 unlimited)</i>'),
64             'TR_MAX_MAILACCOUNTS' => tr('Mail accounts limit<br><i>(-1 disabled, 0 unlimited)</i>'),
65             'TR_MAX_FTP' => tr('FTP accounts limit<br><i>(-1 disabled, 0 unlimited)</i>'),
66             'TR_MAX_SQL' => tr('SQL databases limit<br><i>(-1 disabled, 0 unlimited)</i>'),
67             'TR_MAX_SQL_USERS' => tr('SQL users limit<br><i>(-1 disabled, 0 unlimited)</i>'),
68             'TR_MAX_TRAFFIC' => tr('Traffic limit [MB]<br><i>(0 unlimited)</i>'),
69             'TR_DISK_LIMIT' => tr('Disk limit [MB]<br><i>(0 unlimited)</i>'),
70             'TR_PHP' => tr('PHP'),
71             'TR_CGI' => tr('CGI / Perl'),
72             'TR_BACKUP_RESTORE' => tr('Backup and restore'),
73             'TR_APACHE_LOGS' => tr('Apache logfiles'),
74             'TR_AWSTATS' => tr('AwStats'),
75             'TR_YES' => tr('yes'),
76             'TR_NO' => tr('no'),
77             'TR_BILLING_PROPS' => tr('Billing Settings'),
78             'TR_PRICE' => tr('Price'),
79             'TR_SETUP_FEE' => tr('Setup fee'),
80             'TR_VALUE' => tr('Currency'),
81             'TR_PAYMENT' => tr('Payment period'),
82             'TR_STATUS' => tr('Available for purchasing'),
83             'TR_TEMPLATE_DESCRIPTON' => tr('Description'),
84             'TR_EXAMPLE' => tr('(e.g. EUR)'),
85             'TR_ADD_PLAN' => tr('Add plan')
86             )
87         );
88
89 if (isset($_POST['uaction']) && ('add_plan' === $_POST['uaction'])) {
90     // Process data
91     if (check_data_correction($tpl))
92         save_data_to_db($tpl, $_SESSION['user_id']);
93
94     gen_data_ahp_page($tpl);
95 } else {
96     gen_empty_ahp_page($tpl);
97 }
98
99 gen_page_message($tpl);
100
101 $tpl->parse('PAGE', 'page');
102 $tpl->prnt();
103
104 if (Config::get('DUMP_GUI_DEBUG')) dump_gui_debug();
105
106 // Function definitions
107
108 // Generate empty form
109 function gen_empty_ahp_page(&$tpl) {
110     $tpl->assign(
111             array(
112                 'HP_NAME_VALUE' => '',
113                 'TR_MAX_SUB_LIMITS' => '',
114                 'TR_MAX_ALS_VALUES' => '',
115                 'HP_MAIL_VALUE' => '',
116                 'HP_FTP_VALUE' => '',
117                 'HP_SQL_DB_VALUE' => '',
118                 'HP_SQL_USER_VALUE' => '',
119                 'HP_TRAFF_VALUE' => '',
120                 'HP_PRICE' => '',
121                 'HP_SETUPFEE' => '',
122                 'HP_VELUE' => '',
123                 'HP_PAYMENT' => '',
124                 'HP_DESCRIPTION_VALUE' => '',
125         'TR_STATUS_YES'            => '',
126         'TR_STATUS_NO'            => 'checked',
127         'TR_PHP_YES'            => '',
128         'TR_PHP_NO'                => 'checked',
129         'TR_CGI_YES'            => '',
130         'TR_CGI_NO'                => 'checked',
131         'HP_DISK_VALUE'            => ''
132     ));
133     $tpl->assign('MESSAGE', '');
134 } // End of gen_empty_hp_page()
135
136 // Show last entered data for new hp
137 function gen_data_ahp_page(&$tpl) {
138     global $hp_name, $description, $hp_php, $hp_cgi;
139     global $hp_sub, $hp_als, $hp_mail;
140     global $hp_ftp, $hp_sql_db, $hp_sql_user;
141     global $hp_traff, $hp_disk;
142     global $price, $setup_fee, $value, $payment, $status;
143
144     $tpl->assign(
145             array(
146                 'HP_NAME_VALUE' => $hp_name,
147                 'TR_MAX_SUB_LIMITS' => $hp_sub,
148                 'TR_MAX_ALS_VALUES' => $hp_als,
149                 'HP_MAIL_VALUE' => $hp_mail,
150                 'HP_FTP_VALUE' => $hp_ftp,
151                 'HP_SQL_DB_VALUE' => $hp_sql_db,
152                 'HP_SQL_USER_VALUE' => $hp_sql_user,
153                 'HP_TRAFF_VALUE' => $hp_traff,
154                 'HP_DISK_VALUE' => $hp_disk,
155                 'HP_DESCRIPTION_VALUE' => $description,
156                 'HP_PRICE' => $price,
157                 'HP_SETUPFEE' => $setup_fee,
158                 'HP_VELUE' => $value,
159                 'HP_PAYMENT' => $payment
160                 )
161             );
162
163     if ('_yes_' === $hp_php) {
164         $tpl->assign(array('TR_PHP_YES' => 'checked'));
165     } else {
166         $tpl->assign(array('TR_PHP_NO' => 'checked'));
167     }
168     if ('_yes_' === $hp_cgi) {
169         $tpl->assign(
170             array('TR_CGI_YES' => 'checked'));
171     } else {
172         $tpl->assign(array('TR_CGI_NO' => 'checked'));
173     }
174     if ($status == 1) {
175         $tpl->assign(array('TR_STATUS_YES' => 'checked'));
176     } else
177         $tpl->assign(array('TR_STATUS_NO' => 'checked'));
178 } // End of gen_data_ahp_page()
179
180 // Check correction of input data
181 function check_data_correction(&$tpl) {
182     global $hp_name, $description, $hp_php, $hp_cgi;
183     global $hp_sub, $hp_als, $hp_mail;
184     global $hp_ftp, $hp_sql_db, $hp_sql_user;
185     global $hp_traff, $hp_disk;
186     global $price, $setup_fee, $value, $payment, $status;
187
188     $ahp_error = "_off_";
189
190     $hp_name = clean_input($_POST['hp_name']);
191     $hp_sub = clean_input($_POST['hp_sub']);
192     $hp_als = clean_input($_POST['hp_als']);
193     $hp_mail = clean_input($_POST['hp_mail']);
194     $hp_ftp = clean_input($_POST['hp_ftp']);
195     $hp_sql_db = clean_input($_POST['hp_sql_db']);
196     $hp_sql_user = clean_input($_POST['hp_sql_user']);
197     $hp_traff = clean_input($_POST['hp_traff']);
198     $hp_disk = clean_input($_POST['hp_disk']);
199     $description = clean_input($_POST['hp_description']);
200
201     if (empty($_POST['hp_price'])) {
202         $price = 0;
203     } else {
204         $price = clean_input($_POST['hp_price']);
205     }
206     if (empty($_POST['hp_setupfee'])) {
207         $setup_fee = 0;
208     } else {
209         $setup_fee = clean_input($_POST['hp_setupfee']);
210     }
211
212     $value = clean_input($_POST['hp_value']);
213     $payment = clean_input($_POST['hp_payment']);
214     $status = $_POST['status'];
215
216     if (isset($_POST['php']))
217         $hp_php = $_POST['php'];
218
219     if (isset($_POST['cgi']))
220         $hp_cgi = $_POST['cgi'];;
221
222     if ($hp_name == '') {
223         $ahp_error = tr('Incorrect template name length!');
224     }
225
226     if ($description == '') {
227         $ahp_error = tr('Incorrect template description length!');
228     }
229     if (!is_numeric($price)) {
230         $ahp_error = tr('Price must be a number!');
231     }
232
233     if (!is_numeric($setup_fee)) {
234         $ahp_error = tr('Setup fee must be a number!');
235     }
236
237     if (!ispcp_limit_check($hp_sub, -1)) {
238         $ahp_error = tr('Incorrect subdomains limit!');
239     } else if (!ispcp_limit_check($hp_als, -1)) {
240         $ahp_error = tr('Incorrect aliases limit!');
241     } else if (!ispcp_limit_check($hp_mail, -1)) {
242         $ahp_error = tr('Incorrect mail accounts limit!');
243     } else if (!ispcp_limit_check($hp_ftp, -1)) {
244         $ahp_error = tr('Incorrect FTP accounts limit!');
245     } else if (!ispcp_limit_check($hp_sql_user, -1)) {
246         $ahp_error = tr('Incorrect SQL databases limit!');
247     } else if (!ispcp_limit_check($hp_sql_db, -1)) {
248         $ahp_error = tr('Incorrect SQL users limit!');
249     } else if (!ispcp_limit_check($hp_traff, null)) {
250         $ahp_error = tr('Incorrect traffic limit!');
251     } else if (!ispcp_limit_check($hp_disk, null)) {
252         $ahp_error = tr('Incorrect disk quota limit!');
253     }
254
255     if ($ahp_error == '_off_') {
256         $tpl->assign('MESSAGE', '');
257         return true;
258     } else {
259         set_page_message($ahp_error);
260         // $tpl -> assign('MESSAGE', $ahp_error);
261         return false;
262     }
263 } // End of check_data_correction()
264
265 // Add new host plan to DB
266 function save_data_to_db(&$tpl, $admin_id){
267     $sql = Database::getInstance();
268     global $hp_name, $description, $hp_php, $hp_cgi;
269     global $hp_sub, $hp_als, $hp_mail;
270     global $hp_ftp, $hp_sql_db, $hp_sql_user;
271     global $hp_traff, $hp_disk;
272     global $price, $setup_fee, $value, $payment, $status;
273
274     $err_msg = "";
275     $query = "select id from hosting_plans where name = ? and reseller_id = ?";
276     $res = exec_query($sql, $query, array($hp_name, $admin_id));
277
278     if ($res->RowCount() == 1) {
279         $tpl->assign('MESSAGE', tr('Hosting plan with entered name already exists!'));
280         // $tpl -> parse('AHP_MESSAGE', 'ahp_message');
281     } else {
282         $hp_props = "$hp_php;$hp_cgi;$hp_sub;$hp_als;$hp_mail;$hp_ftp;$hp_sql_db;$hp_sql_user;$hp_traff;$hp_disk;";
283         // this id is just for fake and is not used in reseller_limits_check.
284         $hpid = 0;
285
286         if (reseller_limits_check($sql, $err_msg, $admin_id, $hpid, $hp_props)) {
287             if (!empty($err_msg)) {
288                 set_page_message($err_msg);
289                 return false;
290             } else {
291                 $query = <<<SQL_QUERY
292         insert into
293             hosting_plans(reseller_id,
294                             name,
295                             description,
296                             props,
297                             price,
298                             setup_fee,
299                             value,
300                             payment,
301                             status)
302         values (?, ?, ?, ?, ?, ?, ?, ?, ?)
303 SQL_QUERY;
304                 $res = exec_query($sql, $query, array($admin_id, $hp_name, $description, $hp_props, $price, $setup_fee, $value, $payment, $status));
305
306                 $_SESSION['hp_added'] = '_yes_';
307                 header("Location: hosting_plan.php");
308                 die();
309             }
310         }
311         else {
312             set_page_message(tr("Hosting plan values exceed reseller maximum values!"));
313             return false;
314         }
315     }
316 } //End of save_data_to_db()
317
318 ?>
Note: See TracBrowser for help on using the browser.