root/trunk/gui/reseller/orders_update.php

Revision 1327, 10.4 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 $reseller_id = $_SESSION['user_id'];
26
27 if (isset($_GET['order_id']) && is_numeric($_GET['order_id'])) {
28     $order_id = $_GET['order_id'];
29 } else {
30     set_page_message(tr('Wrong order ID!'));
31     header("Location: orders.php");
32     die();
33 }
34
35 if (Config::exists('HOSTING_PLANS_LEVEL') && Config::get('HOSTING_PLANS_LEVEL') === 'admin') {
36     $query = <<<SQL_QUERY
37     select
38         *
39     from
40         orders
41     where
42             id = ?
43         and
44             status = 'update'
45 SQL_QUERY;
46
47     $rs = exec_query($sql, $query, array($order_id));
48 } else {
49     $query = <<<SQL_QUERY
50     select
51         *
52     from
53         orders
54     where
55             id = ?
56         and
57             user_id = ?
58         and
59             status = 'update'
60 SQL_QUERY;
61
62     $rs = exec_query($sql, $query, array($order_id, $reseller_id));
63 }
64
65 if ($rs->RecordCount() == 0) {
66     set_page_message(tr('Permission deny!'));
67     header('Location: orders.php');
68     die();
69 }
70
71 $hpid = $rs->fields['plan_id'];
72 $customer_id = $rs->fields['customer_id'];
73 $dmn_id = get_user_domain_id($sql, $customer_id);
74 // lets check the reseller limits
75 $err_msg = '';
76
77 if (Config::exists('HOSTING_PLANS_LEVEL') && Config::get('HOSTING_PLANS_LEVEL') === 'admin') {
78     $query = "select props from hosting_plans where id = ?";
79     $res = exec_query($sql, $query, array($hpid));
80 } else {
81     $query = "select props from hosting_plans where reseller_id = ? and id = ?";
82     $res = exec_query($sql, $query, array($reseller_id, $hpid));
83 }
84 $data = $res->FetchRow();
85 $props = $data['props'];
86
87 $_SESSION["ch_hpprops"] = $props;
88
89 if (!reseller_limits_check($sql, $err_msg, $reseller_id, $hpid)) {
90     set_page_message(tr("Order Canceled: resellers maximum exceeded!"));
91     header('Location: orders.php');
92     die();
93 }
94
95 if (!empty($err_msg)) {
96     set_page_message($err_msg);
97     unset($_SESSION['domain_ip']);
98     header('Location: orders.php');
99     die();
100 }
101 unset($_SESSION["ch_hpprops"]);
102
103 list($domain_php, $domain_cgi, $sub,
104     $als, $mail, $ftp,
105     $sql_db, $sql_user,
106     $traff, $disk) = explode(";", $props);
107
108 $domain_php = preg_replace("/\_/", "", $domain_php);
109 $domain_cgi = preg_replace("/\_/", "", $domain_cgi);
110
111 $ed_error = '';
112
113 if (!ispcp_limit_check($sub, -1)) {
114     $ed_error = tr('Incorrect subdomains limit!');
115 }
116 if (!ispcp_limit_check($als, -1)) {
117     $ed_error .= tr('Incorrect aliases limit!');
118 }
119 if (!ispcp_limit_check($mail, -1)) {
120     $ed_error .= tr('Incorrect mail accounts limit!');
121 }
122 if (!ispcp_limit_check($ftp, -1)) {
123     $ed_error .= tr('Incorrect FTP accounts limit!');
124 }
125 if (!ispcp_limit_check($sql_db, -1)) {
126     $ed_error .= tr('Incorrect SQL users limit!');
127 }
128 if (!ispcp_limit_check($sql_user, -1)) {
129     $ed_error .= tr('Incorrect SQL databases limit!');
130 }
131 if (!ispcp_limit_check($traff, null)) {
132     $ed_error .= tr('Incorrect traffic limit!');
133 }
134 if (!ispcp_limit_check($disk, null)) {
135     $ed_error .= tr('Incorrect disk quota limit!');
136 }
137
138 list ($usub_current, $usub_max,
139     $uals_current, $uals_max,
140     $umail_current, $umail_max,
141     $uftp_current, $uftp_max,
142     $usql_db_current, $usql_db_max,
143     $usql_user_current, $usql_user_max,
144     $utraff_max, $udisk_max) = generate_user_props($dmn_id);
145
146 list ($rdmn_current, $rdmn_max,
147     $rsub_current, $rsub_max,
148     $rals_current, $rals_max,
149     $rmail_current, $rmail_max,
150     $rftp_current, $rftp_max,
151     $rsql_db_current, $rsql_db_max,
152     $rsql_user_current, $rsql_user_max,
153     $rtraff_current, $rtraff_max,
154     $rdisk_current, $rdisk_max
155     ) = get_reseller_default_props($sql, $reseller_id); //generate_reseller_props($reseller_id);
156
157 list ($a, $b, $c, $d, $e, $f, $utraff_current, $udisk_current, $i, $h) = generate_user_traffic($dmn_id);
158
159 if (empty($ed_error)) {
160     calculate_user_dvals($sub, $usub_current, $usub_max, $rsub_current, $rsub_max, $ed_error, tr('Subdomain'));
161     calculate_user_dvals($als, $uals_current, $uals_max, $rals_current, $rals_max, $ed_error, tr('Alias'));
162     calculate_user_dvals($mail, $umail_current, $umail_max, $rmail_current, $rmail_max, $ed_error, tr('Mail'));
163     calculate_user_dvals($ftp, $uftp_current, $uftp_max, $rftp_current, $rftp_max, $ed_error, tr('FTP'));
164     calculate_user_dvals($sql_db, $usql_db_current, $usql_db_max, $rsql_db_current, $rsql_db_max, $ed_error, tr('SQL Database'));
165     calculate_user_dvals($sql_user, $usql_user_current, $usql_user_max, $rsql_user_current, $rsql_user_max, $ed_error, tr('SQL User'));
166     calculate_user_dvals($traff, $utraff_current / 1024 / 1024 , $utraff_max, $rtraff_current, $rtraff_max, $ed_error, tr('Traffic'));
167     calculate_user_dvals($disk, $udisk_current / 1024 / 1024, $udisk_max, $rdisk_current, $rdisk_max, $ed_error, tr('Disk'));
168 }
169
170 if (empty($ed_error)) {
171     $user_props = "$usub_current;$usub_max;";
172     $user_props .= "$uals_current;$uals_max;";
173     $user_props .= "$umail_current;$umail_max;";
174     $user_props .= "$uftp_current;$uftp_max;";
175     $user_props .= "$usql_db_current;$usql_db_max;";
176     $user_props .= "$usql_user_current;$usql_user_max;";
177     $user_props .= "$utraff_max;";
178     $user_props .= "$udisk_max;";
179     // $user_props .= "$domain_ip;";
180     $user_props .= "$domain_php;";
181     $user_props .= "$domain_cgi";
182     update_user_props($dmn_id, $user_props);
183
184     $reseller_props = "$rdmn_current;$rdmn_max;";
185     $reseller_props .= "$rsub_current;$rsub_max;";
186     $reseller_props .= "$rals_current;$rals_max;";
187     $reseller_props .= "$rmail_current;$rmail_max;";
188     $reseller_props .= "$rftp_current;$rftp_max;";
189     $reseller_props .= "$rsql_db_current;$rsql_db_max;";
190     $reseller_props .= "$rsql_user_current;$rsql_user_max;";
191     $reseller_props .= "$rtraff_current;$rtraff_max;";
192     $reseller_props .= "$rdisk_current;$rdisk_max";
193
194     update_reseller_props($reseller_id, $reseller_props);
195     // update the sql quotas too
196     $query = "select domain_name from domain where domain_id=?";
197     $rs = exec_query($sql, $query, array($dmn_id));
198     $temp_dmn_name = $rs->fields['domain_name'];
199
200     $query = "SELECT count(name) as cnt from quotalimits where name=?";
201     $rs = exec_query($sql, $query, array($temp_dmn_name));
202     if ($rs->fields['cnt'] > 0) {
203         // we need to update it
204         if ($disk == 0) {
205             $dlim = 0;
206         } else {
207             $dlim = $disk * 1024 * 1024;
208         }
209
210         $query = "UPDATE quotalimits SET bytes_in_avail=? WHERE name=?";
211         $rs = exec_query($sql, $query, array($dlim, $temp_dmn_name));
212     }
213
214     $query = <<<SQL_QUERY
215             update
216                 orders
217             set
218                 status=?
219             where
220                 id=?
221 SQL_QUERY;
222     exec_query($sql, $query, array('added', $order_id));
223     set_page_message(tr('Domain properties updated successfully!'));
224     header('Location: users.php');
225     die();
226 } else {
227     set_page_message($ed_error);
228     header('Location: orders.php');
229     die();
230 }
231
232 function calculate_user_dvals($data, $u, &$umax, &$r, $rmax, &$err, $obj) {
233     if ($rmax == 0 && $umax == -1) {
234         if ($data == -1) {
235             return;
236         } else if ($data == 0) {
237             $umax = $data;
238
239             return;
240         } else if ($data > 0) {
241             $umax = $data;
242
243             $r += $umax;
244
245             return;
246         }
247     } else if ($rmax == 0 && $umax == 0) {
248         if ($data == -1) {
249             if ($u > 0) {
250                 $err .= tr('The <em>%s</em> service can not be disabled! ', $obj) . tr('There are <em>%s</em> records on the system!', $obj);
251             } else {
252                 $umax = $data;
253             }
254
255             return;
256         } else if ($data == 0) {
257             return;
258         } else if ($data > 0) {
259             if ($u > $data) {
260                 $err .= tr('The <em>%s</em> service can not be limited! ', $obj) . tr('Specified number is smaller than <em>%s</em> records, present on the system!', $obj);
261             } else {
262                 $umax = $data;
263
264                 $r += $umax;
265             }
266
267             return;
268         }
269     } else if ($rmax == 0 && $umax > 0) {
270         if ($data == -1) {
271             if ($u > 0) {
272                 $err .= tr('The <em>%s</em> service can not be disabled! ', $obj) . tr('There are <em>%s</em> records on the system!', $obj);
273             } else {
274                 $r -= $umax;
275
276                 $umax = $data;
277             }
278
279             return;
280         } else if ($data == 0) {
281             $r -= $umax;
282
283             $umax = $data;
284
285             return;
286         } else if ($data > 0) {
287             if ($u > $data) {
288                 $err .= tr('The <em>%s</em> service can not be limited! ', $obj) . tr('Specified number is smaller than <em>%s</em> records, present on the system!', $obj);
289             } else {
290                 if ($umax > $data) {
291                     $data_dec = $umax - $data;
292
293                     $r -= $data_dec;
294                 } else {
295                     $data_inc = $data - $umax;
296
297                     $r += $data_inc;
298                 }
299
300                 $umax = $data;
301             }
302
303             return;
304         }
305     } else if ($rmax > 0 && $umax == -1) {
306         if ($data == -1) {
307             return;
308         } else if ($data == 0) {
309             $err .= tr('The <em>%s</em> service can not be unlimited! ', $obj) . tr('There are reseller limits for the <em>%s</em> service!', $obj);
310
311             return;
312         } else if ($data > 0) {
313             if ($r + $data > $rmax) {
314                 $err .= tr('The <em>%s</em> service can not be limited! ', $obj) . tr('You are exceeding reseller limits for the <em>%s</em> service!', $obj);
315             } else {
316                 $r += $data;
317
318                 $umax = $data;
319             }
320
321             return;
322         }
323     } else if ($rmax > 0 && $umax == 0) {
324         // We Can't Get Here! This clone is present only for
325         // sample purposes;
326         if ($data == -1) {
327         } else if ($data == 0) {
328         } else if ($data > 0) {
329         }
330     } else if ($rmax > 0 && $umax > 0) {
331         if ($data == -1) {
332             if ($u > 0) {
333                 $err .= tr('The <em>%s</em> service can not be disabled! ', $obj) . tr('There are <em>%s</em> records on the system!', $obj);
334             } else {
335                 $r -= $umax;
336
337                 $umax = $data;
338             }
339
340             return;
341         } else if ($data == 0) {
342             $err .= tr('The <em>%s</em> service can not be unlimited! ', $obj) . tr('There are reseller limits for the <em>%s</em> service!', $obj);
343
344             return;
345         } else if ($data > 0) {
346             if ($u > $data) {
347                 $err .= tr('The <em>%s</em> service can not be limited! ', $obj) . tr('Specified number is smaller than <em>%s</em> records, present on the system!', $obj);
348             } else {
349                 if ($umax > $data) {
350                     $data_dec = $umax - $data;
351
352                     $r -= $data_dec;
353                 } else {
354                     $data_inc = $data - $umax;
355
356                     if ($r + $data_inc > $rmax) {
357                         $err .= tr('The <em>%s</em> service can not be limited! ', $obj) . tr('You are exceeding reseller limits for the <em>%s</em> service!', $obj);
358
359                         return;
360                     }
361
362                     $r += $data_inc;
363                 }
364
365                 $umax = $data;
366             }
367
368             return;
369         }
370     }
371 } // End of calculate_user_dvals()
372
373 ?>
Note: See TracBrowser for help on using the browser.