Skip to content

Commit 8164cdd

Browse files
author
Marius Cramer
committed
Merge branch 'hide_client' into 'master'
Hide client When domain module is enabled in config, every module has a domain selector now, and changing domain's owner on domain list changes owner for every module. This patch removes client selector when domain module is enabled, because I don't see the point in having a client selector on mail, sites and dns, neither create nor update, because setting client to a different one than domain's owner, if that client try to edit, it will break because it's not domain's owner.
2 parents 8537705 + a67681d commit 8164cdd

File tree

11 files changed

+295
-232
lines changed

11 files changed

+295
-232
lines changed

interface/lib/classes/tools_sites.inc.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ function checkDomainModuleDomain($domain_id) {
181181
return $domain['domain'];
182182
}
183183

184+
function getClientIdForDomain($domain_id) {
185+
global $app;
186+
187+
$sql = "SELECT sys_groupid FROM domain WHERE domain_id = " . $app->functions->intval($domain_id);
188+
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
189+
$groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0;
190+
$sql .= " AND sys_groupid IN (".$groups.")";
191+
}
192+
$domain = $app->db->queryOneRecord($sql);
193+
if(!$domain || !$domain['sys_groupid']) return false;
194+
return $domain['sys_groupid'];
195+
}
196+
184197
}
185198

186199
?>

interface/web/dns/dns_slave_edit.php

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,30 @@ function onShowNew() {
7272
function onShowEnd() {
7373
global $app, $conf;
7474

75-
// If user is admin, we will allow him to select to whom this record belongs
76-
if($_SESSION["s"]["user"]["typ"] == 'admin') {
77-
// Getting Domains of the user
78-
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
79-
$clients = $app->db->queryAllRecords($sql);
80-
$client_select = '';
81-
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>";
82-
//$tmp_data_record = $app->tform->getDataRecord($this->id);
83-
if(is_array($clients)) {
84-
foreach( $clients as $client) {
85-
$selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
86-
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
75+
$app->uses('ini_parser,getconf');
76+
$settings = $app->getconf->get_global_config('domains');
77+
78+
/*
79+
* Now we have to check, if we should use the domain-module to select the domain
80+
* or not
81+
*/
82+
if ($settings['use_domain_module'] != 'y') {
83+
// If user is admin, we will allow him to select to whom this record belongs
84+
if($_SESSION["s"]["user"]["typ"] == 'admin') {
85+
// Getting Domains of the user
86+
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
87+
$clients = $app->db->queryAllRecords($sql);
88+
$client_select = '';
89+
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>";
90+
//$tmp_data_record = $app->tform->getDataRecord($this->id);
91+
if(is_array($clients)) {
92+
foreach( $clients as $client) {
93+
$selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
94+
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
95+
}
8796
}
88-
}
89-
$app->tpl->setVar("client_group_id", $client_select);
90-
} else if($app->auth->has_clients($_SESSION['s']['user']['userid'])) {
97+
$app->tpl->setVar("client_group_id", $client_select);
98+
} else if($app->auth->has_clients($_SESSION['s']['user']['userid'])) {
9199

92100
// Get the limits of the client
93101
$client_group_id = intval($_SESSION["s"]["user"]["default_group"]);
@@ -108,14 +116,7 @@ function onShowEnd() {
108116
$app->tpl->setVar("client_group_id", $client_select);
109117

110118
}
111-
112-
/*
113-
* Now we have to check, if we should use the domain-module to select the domain
114-
* or not
115-
*/
116-
$app->uses('ini_parser,getconf');
117-
$settings = $app->getconf->get_global_config('domains');
118-
if ($settings['use_domain_module'] == 'y') {
119+
} else {
119120
/*
120121
* The domain-module is in use.
121122
*/
@@ -160,6 +161,9 @@ function onSubmit() {
160161
$app->uses('ini_parser,getconf');
161162
$settings = $app->getconf->get_global_config('domains');
162163
if ($settings['use_domain_module'] == 'y') {
164+
if ($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
165+
$this->dataRecord['client_group_id'] = $app->tools_sites->getClientIdForDomain($this->dataRecord['origin']);
166+
}
163167
$domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['origin']);
164168
if(!$domain_check) {
165169
// invalid domain selected

interface/web/dns/dns_soa_edit.php

Lines changed: 82 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,30 @@ function onShowNew() {
8282
function onShowEnd() {
8383
global $app, $conf;
8484

85-
// If user is admin, we will allow him to select to whom this record belongs
86-
if($_SESSION["s"]["user"]["typ"] == 'admin') {
87-
// Getting Domains of the user
88-
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
89-
$clients = $app->db->queryAllRecords($sql);
90-
$client_select = '';
91-
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>";
92-
//$tmp_data_record = $app->tform->getDataRecord($this->id);
93-
if(is_array($clients)) {
94-
foreach( $clients as $client) {
95-
$selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
96-
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
85+
$app->uses('ini_parser,getconf');
86+
$settings = $app->getconf->get_global_config('domains');
87+
88+
/*
89+
* Now we have to check, if we should use the domain-module to select the domain
90+
* or not
91+
*/
92+
if ($settings['use_domain_module'] != 'y') {
93+
// If user is admin, we will allow him to select to whom this record belongs
94+
if($_SESSION["s"]["user"]["typ"] == 'admin') {
95+
// Getting Domains of the user
96+
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
97+
$clients = $app->db->queryAllRecords($sql);
98+
$client_select = '';
99+
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>";
100+
//$tmp_data_record = $app->tform->getDataRecord($this->id);
101+
if(is_array($clients)) {
102+
foreach( $clients as $client) {
103+
$selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
104+
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
105+
}
97106
}
98-
}
99-
$app->tpl->setVar("client_group_id", $client_select);
100-
} else if($app->auth->has_clients($_SESSION['s']['user']['userid'])) {
107+
$app->tpl->setVar("client_group_id", $client_select);
108+
} else if($app->auth->has_clients($_SESSION['s']['user']['userid'])) {
101109

102110
// Get the limits of the client
103111
$client_group_id = intval($_SESSION["s"]["user"]["default_group"]);
@@ -118,7 +126,7 @@ function onShowEnd() {
118126
$app->tpl->setVar("client_group_id", $client_select);
119127

120128
}
121-
$app->tpl->setVar("client_group_id", $client_select);
129+
}
122130

123131
// }
124132

@@ -150,12 +158,6 @@ function onShowEnd() {
150158

151159
}
152160

153-
/*
154-
* Now we have to check, if we should use the domain-module to select the domain
155-
* or not
156-
*/
157-
$app->uses('ini_parser,getconf');
158-
$settings = $app->getconf->get_global_config('domains');
159161
if ($settings['use_domain_module'] == 'y') {
160162
/*
161163
* The domain-module is in use.
@@ -197,75 +199,79 @@ function onShowEnd() {
197199
function onSubmit() {
198200
global $app, $conf;
199201

200-
/* check if the domain module is used - and check if the selected domain can be used! */
201-
$app->uses('ini_parser,getconf');
202-
$settings = $app->getconf->get_global_config('domains');
203-
if ($settings['use_domain_module'] == 'y') {
204-
$domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['origin']);
205-
if(!$domain_check) {
206-
// invalid domain selected
207-
$app->tform->errorMessage .= $app->tform->lng("origin_error_empty")."<br />";
208-
} else {
209-
$this->dataRecord['origin'] = $domain_check.'.';
202+
if ($app->tform->getCurrentTab() == 'dns_soa') {
203+
/* check if the domain module is used - and check if the selected domain can be used! */
204+
$app->uses('ini_parser,getconf');
205+
$settings = $app->getconf->get_global_config('domains');
206+
if ($settings['use_domain_module'] == 'y') {
207+
if ($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
208+
$this->dataRecord['client_group_id'] = $app->tools_sites->getClientIdForDomain($this->dataRecord['origin']);
209+
}
210+
$domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['origin']);
211+
if(!$domain_check) {
212+
// invalid domain selected
213+
$app->tform->errorMessage .= $app->tform->lng("origin_error_empty")."<br />";
214+
} else {
215+
$this->dataRecord['origin'] = $domain_check.'.';
216+
}
210217
}
211-
}
212218

213-
if($_SESSION["s"]["user"]["typ"] != 'admin') {
214-
// Get the limits of the client
215-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
216-
$client = $app->db->queryOneRecord("SELECT limit_dns_zone, dns_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
219+
if($_SESSION["s"]["user"]["typ"] != 'admin') {
220+
// Get the limits of the client
221+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
222+
$client = $app->db->queryOneRecord("SELECT limit_dns_zone, dns_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
217223

218-
$client['dns_servers_ids'] = explode(',', $client['dns_servers']);
224+
$client['dns_servers_ids'] = explode(',', $client['dns_servers']);
219225

220-
// Check if chosen server is in authorized servers for this client
221-
if (!(is_array($client['dns_servers_ids']) && in_array($this->dataRecord["server_id"], $client['dns_servers_ids'])) && $_SESSION["s"]["user"]["typ"] != 'admin') {
222-
$app->error($app->tform->wordbook['error_not_allowed_server_id']);
223-
}
226+
// Check if chosen server is in authorized servers for this client
227+
if (!(is_array($client['dns_servers_ids']) && in_array($this->dataRecord["server_id"], $client['dns_servers_ids'])) && $_SESSION["s"]["user"]["typ"] != 'admin') {
228+
$app->error($app->tform->wordbook['error_not_allowed_server_id']);
229+
}
224230

225-
// When the record is updated
226-
if($this->id > 0) {
227-
// restore the server ID if the user is not admin and record is edited
228-
$tmp = $app->db->queryOneRecord("SELECT server_id FROM dns_soa WHERE id = ".$app->functions->intval($this->id));
229-
$this->dataRecord["server_id"] = $tmp["server_id"];
230-
unset($tmp);
231-
// When the record is inserted
232-
} else {
233-
// Check if the user may add another maildomain.
234-
if($client["limit_dns_zone"] >= 0) {
235-
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_soa WHERE sys_groupid = $client_group_id");
236-
if($tmp["number"] >= $client["limit_dns_zone"]) {
237-
$app->error($app->tform->wordbook["limit_dns_zone_txt"]);
231+
// When the record is updated
232+
if($this->id > 0) {
233+
// restore the server ID if the user is not admin and record is edited
234+
$tmp = $app->db->queryOneRecord("SELECT server_id FROM dns_soa WHERE id = ".$app->functions->intval($this->id));
235+
$this->dataRecord["server_id"] = $tmp["server_id"];
236+
unset($tmp);
237+
// When the record is inserted
238+
} else {
239+
// Check if the user may add another maildomain.
240+
if($client["limit_dns_zone"] >= 0) {
241+
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_soa WHERE sys_groupid = $client_group_id");
242+
if($tmp["number"] >= $client["limit_dns_zone"]) {
243+
$app->error($app->tform->wordbook["limit_dns_zone_txt"]);
244+
}
238245
}
239246
}
240247
}
241-
}
242248

243-
/*
244-
// Update the serial number of the SOA record
245-
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ".$this->id);
246-
$this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
247-
*/
249+
/*
250+
// Update the serial number of the SOA record
251+
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ".$this->id);
252+
$this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
253+
*/
248254

249255

250-
//* Check if soa, ns and mbox have a dot at the end
251-
if(strlen($this->dataRecord["origin"]) > 0 && substr($this->dataRecord["origin"], -1, 1) != '.') $this->dataRecord["origin"] .= '.';
252-
if(strlen($this->dataRecord["ns"]) > 0 && substr($this->dataRecord["ns"], -1, 1) != '.') $this->dataRecord["ns"] .= '.';
253-
if(strlen($this->dataRecord["mbox"]) > 0 && substr($this->dataRecord["mbox"], -1, 1) != '.') $this->dataRecord["mbox"] .= '.';
256+
//* Check if soa, ns and mbox have a dot at the end
257+
if(strlen($this->dataRecord["origin"]) > 0 && substr($this->dataRecord["origin"], -1, 1) != '.') $this->dataRecord["origin"] .= '.';
258+
if(strlen($this->dataRecord["ns"]) > 0 && substr($this->dataRecord["ns"], -1, 1) != '.') $this->dataRecord["ns"] .= '.';
259+
if(strlen($this->dataRecord["mbox"]) > 0 && substr($this->dataRecord["mbox"], -1, 1) != '.') $this->dataRecord["mbox"] .= '.';
254260

255-
//* Replace @ in mbox
256-
if(stristr($this->dataRecord["mbox"], '@')) {
257-
$this->dataRecord["mbox"] = str_replace('@', '.', $this->dataRecord["mbox"]);
258-
}
261+
//* Replace @ in mbox
262+
if(stristr($this->dataRecord["mbox"], '@')) {
263+
$this->dataRecord["mbox"] = str_replace('@', '.', $this->dataRecord["mbox"]);
264+
}
259265

260-
$this->dataRecord["xfer"] = preg_replace('/\s+/', '', $this->dataRecord["xfer"]);
261-
$this->dataRecord["also_notify"] = preg_replace('/\s+/', '', $this->dataRecord["also_notify"]);
266+
$this->dataRecord["xfer"] = preg_replace('/\s+/', '', $this->dataRecord["xfer"]);
267+
$this->dataRecord["also_notify"] = preg_replace('/\s+/', '', $this->dataRecord["also_notify"]);
262268

263-
//* Check if a secondary zone with the same name already exists
264-
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_slave WHERE origin = ? AND server_id = ?", $this->dataRecord["origin"], $this->dataRecord["server_id"]);
265-
if($tmp["number"] > 0) {
266-
$app->error($app->tform->wordbook["origin_error_unique"]);
269+
//* Check if a secondary zone with the same name already exists
270+
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_slave WHERE origin = ? AND server_id = ?", $this->dataRecord["origin"], $this->dataRecord["server_id"]);
271+
if($tmp["number"] > 0) {
272+
$app->error($app->tform->wordbook["origin_error_unique"]);
273+
}
267274
}
268-
269275
parent::onSubmit();
270276
}
271277

0 commit comments

Comments
 (0)