Skip to content

Commit 3cebc3a

Browse files
committed
Fixed: FS#776 - Client's limits do not apply for it's own client
Improved client and reseller limit checks
1 parent 9518803 commit 3cebc3a

24 files changed

+174
-232
lines changed

interface/lib/app.inc.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ public function load_language_file($filename) {
186186
public function tpl_defaults()
187187
{
188188
$this->tpl->setVar('app_title', $this->_conf['app_title']);
189-
$this->tpl->setVar('app_version', $this->_conf['app_version']);
189+
if(isset($_SESSION['s']['user'])) {
190+
$this->tpl->setVar('app_version', $this->_conf['app_version']);
191+
} else {
192+
$this->tpl->setVar('app_version', '');
193+
}
190194
$this->tpl->setVar('app_link', $this->_conf['app_link']);
191195
if(isset($this->_conf['app_logo']) && $this->_conf['app_logo'] != '' && @is_file($this->_conf['app_logo'])){
192196
$this->tpl->setVar('app_logo', '<img src="'.$this->_conf['app_logo'].'">');

interface/lib/classes/tform.inc.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,63 @@ function lng($msg) {
11481148
}
11491149

11501150
}
1151+
1152+
function checkClientLimit($limit_name,$sql_where = '') {
1153+
global $app;
1154+
1155+
$check_passed = true;
1156+
$limit_name = $app->db->quote($limit_name);
1157+
if($limit_name == '') $app->error('Limit name missing in function checkClientLimit.');
1158+
1159+
// Get the limits of the client that is currently logged in
1160+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
1161+
$client = $app->db->queryOneRecord("SELECT $limit_name as number, parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
1162+
1163+
// Check if the user may add another item
1164+
if($client["number"] >= 0) {
1165+
$sql = "SELECT count(".$this->formDef['db_table_idx'].") as number FROM ".$this->formDef['db_table']." WHERE ".$this->getAuthSQL('u');
1166+
if($sql_where != '') $sql .= ' and '.$sql_where;
1167+
$tmp = $app->db->queryOneRecord($sql);
1168+
if($tmp["number"] >= $client["number"]) $check_passed = false;
1169+
}
1170+
1171+
return $check_passed;
1172+
}
1173+
1174+
function checkResellerLimit($limit_name,$sql_where = '') {
1175+
global $app;
1176+
1177+
$check_passed = true;
1178+
$limit_name = $app->db->quote($limit_name);
1179+
if($limit_name == '') $app->error('Limit name missing in function checkClientLimit.');
1180+
1181+
// Get the limits of the client that is currently logged in
1182+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
1183+
$client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
1184+
1185+
//* If the client belongs to a reseller, we will check against the reseller Limit too
1186+
if($client['parent_client_id'] != 0) {
1187+
1188+
//* first we need to know the groups of this reseller
1189+
$tmp = $app->db->queryOneRecord("SELECT userid, groups FROM sys_user WHERE client_id = ".$client['parent_client_id']);
1190+
$reseller_groups = $tmp["groups"];
1191+
$reseller_userid = $tmp["userid"];
1192+
1193+
// Get the limits of the reseller of the logged in client
1194+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
1195+
$reseller = $app->db->queryOneRecord("SELECT $limit_name as number FROM client WHERE client_id = ".$client['parent_client_id']);
1196+
1197+
// Check if the user may add another item
1198+
if($reseller["number"] >= 0) {
1199+
$sql = "SELECT count(".$this->formDef['db_table_idx'].") as number FROM ".$this->formDef['db_table']." WHERE (sys_groupid IN (".$reseller_groups.") or sys_userid = ".$reseller_userid.")";
1200+
if($sql_where != '') $sql .= ' and '.$sql_where;
1201+
$tmp = $app->db->queryOneRecord($sql);
1202+
if($tmp["number"] >= $reseller["number"]) $check_passed = false;
1203+
}
1204+
}
1205+
1206+
return $check_passed;
1207+
}
11511208

11521209
}
11531210

interface/web/dns/dns_soa_edit.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,11 @@ function onShowNew() {
5555

5656
// we will check only users, not admins
5757
if($_SESSION["s"]["user"]["typ"] == 'user') {
58-
59-
// Get the limits of the client
60-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
61-
$client = $app->db->queryOneRecord("SELECT limit_dns_zone FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
62-
63-
// Check if the user may add another maildomain.
64-
if($client["limit_dns_zone"] >= 0) {
65-
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_soa WHERE sys_groupid = $client_group_id");
66-
if($tmp["number"] >= $client["limit_dns_zone"]) {
67-
$app->error($app->tform->wordbook["limit_dns_zone_txt"]);
68-
}
58+
if(!$app->tform->checkClientLimit('limit_dns_zone')) {
59+
$app->error($app->tform->wordbook["limit_dns_zone_txt"]);
60+
}
61+
if(!$app->tform->checkResellerLimit('limit_dns_zone')) {
62+
$app->error('Reseller: '.$app->tform->wordbook["limit_dns_zone_txt"]);
6963
}
7064
}
7165

interface/web/dns/dns_wizard.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@
137137
if(isset($_POST['ns2']) && $_POST['ns2'] == '') $error .= $app->lng('error_ns2_empty').'<br />';
138138
if(isset($_POST['email']) && $_POST['email'] == '') $error .= $app->lng('error_email_empty').'<br />';
139139

140+
if(!$app->tform->checkClientLimit('limit_dns_zone')) {
141+
$error .= $app->tform->wordbook["limit_dns_zone_txt"];
142+
}
143+
if(!$app->tform->checkResellerLimit('limit_dns_zone')) {
144+
$error .= $app->tform->wordbook["limit_dns_zone_txt"];
145+
}
146+
140147

141148
// replace template placeholders
142149
$tpl_content = $template_record['template'];

interface/web/mail/mail_alias_edit.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,11 @@ function onShowNew() {
5555

5656
// we will check only users, not admins
5757
if($_SESSION["s"]["user"]["typ"] == 'user') {
58-
59-
// Get the limits of the client
60-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
61-
$client = $app->db->queryOneRecord("SELECT limit_mailalias FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
62-
63-
// Check if the user may add another mailbox.
64-
if($client["limit_mailalias"] >= 0) {
65-
$tmp = $app->db->queryOneRecord("SELECT count(forwarding_id) as number FROM mail_forwarding WHERE sys_groupid = $client_group_id and type = 'alias'");
66-
if($tmp["number"] >= $client["limit_mailalias"]) {
67-
$app->error($app->tform->wordbook["limit_mailalias_txt"]);
68-
}
58+
if(!$app->tform->checkClientLimit('limit_mailalias',"type = 'alias'")) {
59+
$app->error($app->tform->wordbook["limit_mailalias_txt"]);
60+
}
61+
if(!$app->tform->checkResellerLimit('limit_mailalias',"type = 'alias'")) {
62+
$app->error('Reseller: '.$app->tform->wordbook["limit_mailalias_txt"]);
6963
}
7064
}
7165

interface/web/mail/mail_blacklist_edit.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,11 @@ function onShowNew() {
5555

5656
// we will check only users, not admins
5757
if($_SESSION["s"]["user"]["typ"] == 'user') {
58-
59-
// Get the limits of the client
60-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
61-
$client = $app->db->queryOneRecord("SELECT limit_mailfilter FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
62-
63-
// Check if the user may add another mailbox.
64-
if($client["limit_mailfilter"] >= 0) {
65-
$tmp = $app->db->queryOneRecord("SELECT count(access_id) as number FROM mail_access WHERE sys_groupid = $client_group_id");
66-
if($tmp["number"] >= $client["limit_mailfilter"]) {
67-
$app->error($app->tform->wordbook["limit_mailfilter_txt"]);
68-
}
58+
if(!$app->tform->checkClientLimit('limit_mailfilter')) {
59+
$app->error($app->tform->wordbook["limit_mailfilter_txt"]);
60+
}
61+
if(!$app->tform->checkResellerLimit('limit_mailfilter')) {
62+
$app->error('Reseller: '.$app->tform->wordbook["limit_mailfilter_txt"]);
6963
}
7064
}
7165

interface/web/mail/mail_domain_catchall_edit.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,11 @@ function onShowNew() {
5555

5656
// we will check only users, not admins
5757
if($_SESSION["s"]["user"]["typ"] == 'user') {
58-
59-
// Get the limits of the client
60-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
61-
$client = $app->db->queryOneRecord("SELECT limit_mailcatchall FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
62-
63-
// Check if the user may add another mailbox.
64-
if($client["limit_mailcatchall"] >= 0) {
65-
$tmp = $app->db->queryOneRecord("SELECT count(forwarding_id) as number FROM mail_forwarding WHERE sys_groupid = $client_group_id and type = 'catchall'");
66-
if($tmp["number"] >= $client["limit_mailcatchall"]) {
67-
$app->error($app->tform->wordbook["limit_mailcatchall_txt"]);
68-
}
58+
if(!$app->tform->checkClientLimit('limit_mailcatchall',"type = 'catchall'")) {
59+
$app->error($app->tform->wordbook["limit_mailcatchall_txt"]);
60+
}
61+
if(!$app->tform->checkResellerLimit('limit_mailcatchall',"type = 'catchall'")) {
62+
$app->error('Reseller: '.$app->tform->wordbook["limit_mailcatchall_txt"]);
6963
}
7064
}
7165

interface/web/mail/mail_domain_edit.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,11 @@ function onShowNew() {
5555

5656
// we will check only users, not admins
5757
if($_SESSION["s"]["user"]["typ"] == 'user') {
58-
59-
// Get the limits of the client
60-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
61-
$client = $app->db->queryOneRecord("SELECT limit_maildomain FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
62-
63-
// Check if the user may add another maildomain.
64-
if($client["limit_maildomain"] >= 0) {
65-
$tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM mail_domain WHERE sys_groupid = $client_group_id");
66-
if($tmp["number"] >= $client["limit_maildomain"]) {
67-
$app->error($app->tform->wordbook["limit_maildomain_txt"]);
68-
}
58+
if(!$app->tform->checkClientLimit('limit_maildomain')) {
59+
$app->error($app->tform->wordbook["limit_maildomain_txt"]);
60+
}
61+
if(!$app->tform->checkResellerLimit('limit_maildomain')) {
62+
$app->error('Reseller: '.$app->tform->wordbook["limit_maildomain_txt"]);
6963
}
7064
}
7165

interface/web/mail/mail_forward_edit.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,11 @@ function onShowNew() {
5555

5656
// we will check only users, not admins
5757
if($_SESSION["s"]["user"]["typ"] == 'user') {
58-
59-
// Get the limits of the client
60-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
61-
$client = $app->db->queryOneRecord("SELECT limit_mailforward FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
62-
63-
// Check if the user may add another mailbox.
64-
if($client["limit_mailforward"] >= 0) {
65-
$tmp = $app->db->queryOneRecord("SELECT count(forwarding_id) as number FROM mail_forwarding WHERE sys_groupid = $client_group_id and type = 'forward'");
66-
if($tmp["number"] >= $client["limit_mailforward"]) {
67-
$app->error($app->tform->wordbook["limit_mailforward_txt"]);
68-
}
58+
if(!$app->tform->checkClientLimit('limit_mailforward',"type = 'forward'")) {
59+
$app->error($app->tform->wordbook["limit_mailforward_txt"]);
60+
}
61+
if(!$app->tform->checkResellerLimit('limit_mailforward',"type = 'forward'")) {
62+
$app->error('Reseller: '.$app->tform->wordbook["limit_mailforward_txt"]);
6963
}
7064
}
7165

interface/web/mail/mail_get_edit.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,11 @@ function onShowNew() {
5555

5656
// we will check only users, not admins
5757
if($_SESSION["s"]["user"]["typ"] == 'user') {
58-
59-
// Get the limits of the client
60-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
61-
$client = $app->db->queryOneRecord("SELECT limit_fetchmail FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
62-
63-
// Check if the user may add another transport.
64-
if($client["limit_fetchmail"] >= 0) {
65-
$tmp = $app->db->queryOneRecord("SELECT count(mailget_id) as number FROM mail_get WHERE sys_groupid = $client_group_id");
66-
if($tmp["number"] >= $client["limit_fetchmail"]) {
67-
$app->error($app->tform->wordbook["limit_fetchmail_txt"]);
68-
}
58+
if(!$app->tform->checkClientLimit('limit_fetchmail')) {
59+
$app->error($app->tform->wordbook["limit_fetchmail_txt"]);
60+
}
61+
if(!$app->tform->checkResellerLimit('limit_fetchmail')) {
62+
$app->error('Reseller: '.$app->tform->wordbook["limit_fetchmail_txt"]);
6963
}
7064
}
7165

0 commit comments

Comments
 (0)