Skip to content

Commit 5d1c691

Browse files
author
Marius Cramer
committed
Merge branch 'reseller_template_limits' into 'master'
Reseller quota When a reseller has some quota established, they shouldn't be allowed to create clients without quota or assign more quota to their clients. If they are allowed (as it's done now), total quota used by their clients can be higher than reseller limit, and when reseller try to edit site or mailbox, then quota can be changed to 0.
2 parents 1e121ab + 009b2dc commit 5d1c691

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

interface/web/mail/mail_user_edit.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function onSubmit() {
153153
if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin
154154
// Get the limits of the client
155155
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
156-
$client = $app->db->queryOneRecord("SELECT limit_mailbox, limit_mailquota FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
156+
$client = $app->db->queryOneRecord("SELECT limit_mailbox, limit_mailquota, parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
157157

158158

159159
// Check if the user may add another mailbox.
@@ -179,6 +179,28 @@ function onSubmit() {
179179
unset($tmp);
180180
unset($tmp_quota);
181181
}
182+
183+
if($client['parent_client_id'] > 0) {
184+
// Get the limits of the reseller
185+
$reseller = $app->db->queryOneRecord("SELECT limit_mailquota, limit_maildomain FROM client WHERE client_id = ".$client['parent_client_id']);
186+
187+
//* Check the website quota of the client
188+
if(isset($_POST["quota"]) && $reseller["limit_mailquota"] >= 0 && $app->functions->intval($this->dataRecord["quota"]) * 1024 * 1024 != $this->oldDataRecord['quota']) {
189+
$tmp = $app->db->queryOneRecord("SELECT sum(quota) as mailquota FROM mail_user, sys_group, client WHERE mail_user.sys_groupid=sys_group.groupid AND sys_group.client_id=client.client_id AND ".$client['parent_client_id']." IN (client.parent_client_id, client.client_id) AND mailuser_id != ".$app->functions->intval($this->id));
190+
191+
$mailquota = $tmp["mailquota"] / 1024 / 1024;
192+
$new_mailbox_quota = $app->functions->intval($this->dataRecord["quota"]);
193+
if(($mailquota + $new_mailbox_quota > $reseller["limit_mailquota"]) || ($new_mailbox_quota == 0 && $reseller["limit_mailquota"] != -1)) {
194+
$max_free_quota = $reseller["limit_mailquota"] - $mailquota;
195+
if($max_free_quota < 0) $max_free_quota = 0;
196+
$app->tform->errorMessage .= $app->tform->lng("limit_mailquota_txt").": ".$max_free_quota."<br>";
197+
// Set the quota field to the max free space
198+
$this->dataRecord["quota"] = $max_free_quota;
199+
}
200+
unset($tmp);
201+
unset($tmp_quota);
202+
}
203+
}
182204
} // end if user is not admin
183205

184206

interface/web/sites/database_edit.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function onSubmit() {
170170
if($_SESSION["s"]["user"]["typ"] != 'admin') {
171171
// Get the limits of the client
172172
$client_group_id = $_SESSION["s"]["user"]["default_group"];
173-
$client = $app->db->queryOneRecord("SELECT db_servers, limit_database, limit_database_quota FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.groupid = $client_group_id");
173+
$client = $app->db->queryOneRecord("SELECT db_servers, limit_database, limit_database_quota, parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.groupid = $client_group_id");
174174

175175
// When the record is updated
176176
if($this->id > 0) {
@@ -200,6 +200,33 @@ function onSubmit() {
200200
unset($global_config);
201201
unset($dbname_prefix);
202202
}
203+
204+
if($client['parent_client_id'] > 0) {
205+
// Get the limits of the reseller
206+
$reseller = $app->db->queryOneRecord("SELECT limit_database, limit_database_quota FROM client WHERE client_id = ".$client['parent_client_id']);
207+
208+
//* Check the website quota of the client
209+
if ($reseller['limit_database_quota'] >= 0) {
210+
//* get the database prefix
211+
$app->uses('getconf,tools_sites');
212+
$global_config = $app->getconf->get_global_config('sites');
213+
$dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord);
214+
//* get quota from other databases
215+
$tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database, sys_group, client WHERE web_database.sys_groupid=sys_group.groupid AND sys_group.client_id=client.client_id AND ? IN (client.parent_client_id, client.client_id) AND database_name <> ?", $client['parent_client_id'], $dbname_prefix.$this->dataRecord['database_name']);
216+
217+
$used_quota = $app->functions->intval($tmp['db_quota']);
218+
$new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]);
219+
if(($used_quota + $new_db_quota > $reseller["limit_database_quota"]) || ($new_db_quota < 0 && $reseller["limit_database_quota"] >= 0)) {
220+
$max_free_quota = floor($reseller["limit_database_quota"] - $used_quota);
221+
if($max_free_quota < 0) $max_free_quota = 0;
222+
$app->tform->errorMessage .= $app->tform->lng("limit_database_quota_free_txt").": ".$max_free_quota." MB<br>";
223+
$this->dataRecord["database_quota"] = $max_free_quota;
224+
}
225+
unset($tmp);
226+
unset($global_config);
227+
unset($dbname_prefix);
228+
}
229+
}
203230
// When the record is inserted
204231
} else {
205232
$client['db_servers_ids'] = explode(',', $client['db_servers']);

interface/web/sites/web_vhost_domain_edit.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,8 @@ function onSubmit() {
838838
if($this->_vhostdomain_type == 'domain') {
839839
//* Check the website quota of the client
840840
if(isset($_POST["hd_quota"]) && $reseller["limit_web_quota"] >= 0 && $_POST["hd_quota"] != $old_web_values["hd_quota"]) {
841-
$tmp = $app->db->queryOneRecord("SELECT sum(hd_quota) as webquota FROM web_domain WHERE domain_id != ".$app->functions->intval($this->id)." AND type = 'vhost' AND ".$app->tform->getAuthSQL('u'));
841+
$tmp = $app->db->queryOneRecord("SELECT sum(hd_quota) as webquota FROM web_domain, sys_group, client WHERE web_domain.sys_groupid=sys_group.groupid AND sys_group.client_id=client.client_id AND ".$client['parent_client_id']." IN (client.parent_client_id, client.client_id) AND domain_id != ".$app->functions->intval($this->id)." AND type = 'vhost'");
842+
842843
$webquota = $tmp["webquota"];
843844
$new_web_quota = $app->functions->intval($this->dataRecord["hd_quota"]);
844845
if(($webquota + $new_web_quota > $reseller["limit_web_quota"]) || ($new_web_quota < 0 && $reseller["limit_web_quota"] >= 0)) {
@@ -855,7 +856,7 @@ function onSubmit() {
855856

856857
//* Check the traffic quota of the client
857858
if(isset($_POST["traffic_quota"]) && $reseller["limit_traffic_quota"] > 0 && $_POST["traffic_quota"] != $old_web_values["traffic_quota"]) {
858-
$tmp = $app->db->queryOneRecord("SELECT sum(traffic_quota) as trafficquota FROM web_domain WHERE domain_id != ".$app->functions->intval($this->id)." AND ".$app->tform->getAuthSQL('u'));
859+
$tmp = $app->db->queryOneRecord("SELECT sum(traffic_quota) as trafficquota FROM web_domain, sys_group, client WHERE web_domain.sys_groupid=sys_group.groupid AND sys_group.client_id=client.client_id AND ".$client['parent_client_id']." IN (client.parent_client_id, client.client_id) AND domain_id != ".$app->functions->intval($this->id)." AND type = 'vhost'");
859860
$trafficquota = $tmp["trafficquota"];
860861
$new_traffic_quota = $app->functions->intval($this->dataRecord["traffic_quota"]);
861862
if(($trafficquota + $new_traffic_quota > $reseller["limit_traffic_quota"]) || ($new_traffic_quota < 0 && $reseller["limit_traffic_quota"] >= 0)) {

0 commit comments

Comments
 (0)