root/trunk/gui/admin/hosting_plan_add.php

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