Skip to content

Commit 4e18bd4

Browse files
author
mcramer
committed
Fixed: FS#2421 - Domain module does not check for valid selection
Implemented: FS#2422 - Use domain module when creating subdomains Bugfix: datalog was used in the wrong way on editing aliasdomains Bugfix: missing datalog update for parent domain on editing subdomains
1 parent 864ba9a commit 4e18bd4

File tree

9 files changed

+249
-32
lines changed

9 files changed

+249
-32
lines changed

interface/web/admin/system_config_edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function onUpdateSave($sql) {
134134
$app->db->query($sql);
135135
$sql = "REPLACE INTO domain (sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, domain ) " .
136136
"SELECT sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, domain " .
137-
"FROM web_domain";
137+
"FROM web_domain WHERE type NOT IN ('subdomain','vhostsubdomain')";
138138
$app->db->query($sql);
139139
}
140140

interface/web/client/domain_new_client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
$app->uses('ini_parser,getconf');
4040
$settings = $app->getconf->get_global_config('domains');
4141
if ($settings['use_domain_module'] == 'y') {
42-
echo $settings[new_domain_html];
42+
echo $settings['new_domain_html'];
4343
}
4444

4545
?>

interface/web/mail/mail_domain_edit.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function onShowEnd() {
126126
/*
127127
* The admin can select ALL domains, the user only the domains assigned to him
128128
*/
129-
$sql = "SELECT domain FROM domain ";
129+
$sql = "SELECT domain_id, domain FROM domain ";
130130
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
131131
$sql .= "WHERE sys_groupid =" . $client_group_id;
132132
}
@@ -136,7 +136,7 @@ function onShowEnd() {
136136
if(is_array($domains) && sizeof($domains) > 0) {
137137
/* We have domains in the list, so create the drop-down-list */
138138
foreach( $domains as $domain) {
139-
$domain_select .= "<option value=" . $domain['domain'] ;
139+
$domain_select .= "<option value=" . $domain['domain_id'] ;
140140
if ($domain['domain'] == $this->dataRecord["domain"]) {
141141
$domain_select .= " selected";
142142
}
@@ -184,7 +184,27 @@ function onShowEnd() {
184184

185185
function onSubmit() {
186186
global $app, $conf;
187-
if($_SESSION["s"]["user"]["typ"] != 'admin') {
187+
188+
/* check if the domain module is used - and check if the selected domain can be used! */
189+
$app->uses('ini_parser,getconf');
190+
$settings = $app->getconf->get_global_config('domains');
191+
if ($settings['use_domain_module'] == 'y') {
192+
$client_group_id = intval($_SESSION["s"]["user"]["default_group"]);
193+
194+
$sql = "SELECT domain_id, domain FROM domain WHERE domain_id = " . intval($this->dataRecord['domain']);
195+
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
196+
$sql .= "AND sys_groupid =" . $client_group_id;
197+
}
198+
$domain_check = $app->db->queryOneRecord($sql);
199+
if(!$domain_check) {
200+
// invalid domain selected
201+
$app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />";
202+
} else {
203+
$this->dataRecord['domain'] = $domain_check['domain'];
204+
}
205+
}
206+
207+
if($_SESSION["s"]["user"]["typ"] != 'admin') {
188208

189209
// Get the limits of the client
190210
$client_group_id = $_SESSION["s"]["user"]["default_group"];

interface/web/sites/templates/web_subdomain_edit.htm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,29 @@ <h2><tmpl_var name="list_head_txt"></h2>
55

66
<div class="pnl_formsarea">
77
<fieldset class="inlineLabels">
8+
<tmpl_if name="domain_option">
9+
<div class="ctrlHolder">
10+
<label for="parent_domain_id">{tmpl_var name='parent_domain_id_txt'}</label>
11+
<select id="parent_domain_id" name="parent_domain_id" class="selectInput formLengthHalf">{tmpl_var name='parent_domain_id'}</select>
12+
</div>
13+
</tmpl_if>
814
<div class="ctrlHolder">
915
<label for="domain">{tmpl_var name='host_txt'}</label>
1016
<input name="domain" id="domain" value="{tmpl_var name='domain'}" size="30" maxlength="255" type="text" class="textInput formLengthHalf" />
1117
</div>
18+
<tmpl_if name="domain_option">
19+
<div class="ctrlHolder">
20+
<label for="sel_domain">{tmpl_var name='domain_txt'}</label>
21+
<select name="sel_domain" id="sel_domain" class="selectInput">
22+
{tmpl_var name='domain_option'}
23+
</select>
24+
</div>
25+
<tmpl_else>
1226
<div class="ctrlHolder">
1327
<label for="parent_domain_id">{tmpl_var name='domain_txt'}</label>
1428
<select id="parent_domain_id" name="parent_domain_id" class="selectInput formLengthHalf">{tmpl_var name='parent_domain_id'}</select>
1529
</div>
30+
</tmpl_if>
1631
<div class="ctrlHolder">
1732
<label for="redirect_type">{tmpl_var name='redirect_type_txt'}</label>
1833
<select name="redirect_type" id="redirect_type" class="selectInput formLengthHalf">

interface/web/sites/templates/web_vhost_subdomain_edit.htm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,29 @@ <h2><tmpl_var name="list_head_txt"></h2>
66
<div class="pnl_formsarea">
77
<fieldset class="inlineLabels">
88
<input type="hidden" name="server_id" id="server_id" value="{tmpl_var name='server_id_value'}" />
9+
<tmpl_if name="domain_option">
10+
<div class="ctrlHolder">
11+
<label for="parent_domain_id">{tmpl_var name='parent_domain_id_txt'}</label>
12+
<select id="parent_domain_id" name="parent_domain_id" class="selectInput formLengthHalf">{tmpl_var name='parent_domain_id'}</select>
13+
</div>
14+
</tmpl_if>
915
<div class="ctrlHolder">
1016
<label for="domain">{tmpl_var name='host_txt'}</label>
1117
<input name="domain" id="domain" value="{tmpl_var name='domain'}" size="30" maxlength="255" type="text" class="textInput formLengthHalf" />
1218
</div>
19+
<tmpl_if name="domain_option">
20+
<div class="ctrlHolder">
21+
<label for="sel_domain">{tmpl_var name='domain_txt'}</label>
22+
<select name="sel_domain" id="sel_domain" class="selectInput">
23+
{tmpl_var name='domain_option'}
24+
</select>
25+
</div>
26+
<tmpl_else>
1327
<div class="ctrlHolder">
1428
<label for="parent_domain_id">{tmpl_var name='domain_txt'}</label>
1529
<select id="parent_domain_id" name="parent_domain_id" class="selectInput formLengthHalf">{tmpl_var name='parent_domain_id'}</select>
1630
</div>
31+
</tmpl_if>
1732
<div class="ctrlHolder">
1833
<label for="web_folder">{tmpl_var name='web_folder_txt'}</label>
1934
<input name="web_folder" id="web_folder" value="{tmpl_var name='web_folder'}" size="30" maxlength="100" type="text" class="textInput formLengthHalf"<tmpl_if name='fixed_folder' op='==' value='y'> readonly="readonly"</tmpl_if> />

interface/web/sites/web_aliasdomain_edit.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function onShowEnd() {
8585
/*
8686
* The admin can select ALL domains, the user only the domains assigned to him
8787
*/
88-
$sql = "SELECT domain FROM domain ";
88+
$sql = "SELECT domain_id, domain FROM domain ";
8989
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
9090
$sql .= "WHERE sys_groupid =" . $client_group_id;
9191
}
@@ -95,7 +95,7 @@ function onShowEnd() {
9595
if(is_array($domains) && sizeof($domains) > 0) {
9696
/* We have domains in the list, so create the drop-down-list */
9797
foreach( $domains as $domain) {
98-
$domain_select .= "<option value=" . $domain['domain'] ;
98+
$domain_select .= "<option value=" . $domain['domain_id'] ;
9999
if ($domain['domain'] == $this->dataRecord["domain"]) {
100100
$domain_select .= " selected";
101101
}
@@ -120,6 +120,25 @@ function onShowEnd() {
120120
function onSubmit() {
121121
global $app, $conf;
122122

123+
/* check if the domain module is used - and check if the selected domain can be used! */
124+
$app->uses('ini_parser,getconf');
125+
$settings = $app->getconf->get_global_config('domains');
126+
if ($settings['use_domain_module'] == 'y') {
127+
$client_group_id = intval($_SESSION["s"]["user"]["default_group"]);
128+
129+
$sql = "SELECT domain_id, domain FROM domain WHERE domain_id = " . intval($this->dataRecord['domain']);
130+
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
131+
$sql .= "AND sys_groupid =" . $client_group_id;
132+
}
133+
$domain_check = $app->db->queryOneRecord($sql);
134+
if(!$domain_check) {
135+
// invalid domain selected
136+
$app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />";
137+
} else {
138+
$this->dataRecord['domain'] = $domain_check['domain'];
139+
}
140+
}
141+
123142
// Get the record of the parent domain
124143
$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".intval(@$this->dataRecord["parent_domain_id"]));
125144

@@ -155,15 +174,7 @@ function onAfterUpdate() {
155174
//* Update the old website, so that the vhost alias gets removed
156175
//* We force the update by inserting a transaction record without changes manually.
157176
$old_website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = '.$this->oldDataRecord['domain_id']);
158-
$diffrec_full = array();
159-
$diffrec_full['old'] = $old_website;
160-
$diffrec_full['new'] = $old_website;
161-
$diffstr = $app->db->quote(serialize($diffrec_full));
162-
$username = $app->db->quote($_SESSION['s']['user']['username']);
163-
$dbidx = 'domsin_id:'.$this->id;
164-
$server_id = $this->oldDataRecord['server_id'];
165-
$sql = "INSERT INTO sys_datalog (dbtable,dbidx,server_id,action,tstamp,user,data) VALUES ('web_domain','$dbidx','$server_id','u','".time()."','$username','$diffstr')";
166-
$app->db->query($sql);
177+
$app->db->datalogSave('web_domain', 'UPDATE', 'domain_id', $this->oldDataRecord['parent_domain_id'], $old_website, $old_website, true);
167178
}
168179

169180
}

interface/web/sites/web_domain_edit.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ function onShowEnd() {
418418
/*
419419
* The admin can select ALL domains, the user only the domains assigned to him
420420
*/
421-
$sql = "SELECT domain FROM domain ";
421+
$sql = "SELECT domain_id, domain FROM domain ";
422422
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
423423
$sql .= "WHERE sys_groupid =" . $client_group_id;
424424
}
@@ -428,7 +428,7 @@ function onShowEnd() {
428428
if(is_array($domains) && sizeof($domains) > 0) {
429429
/* We have domains in the list, so create the drop-down-list */
430430
foreach( $domains as $domain) {
431-
$domain_select .= "<option value=" . $domain['domain'] ;
431+
$domain_select .= "<option value=" . $domain['domain_id'] ;
432432
if ($domain['domain'] == $this->dataRecord["domain"]) {
433433
$domain_select .= " selected";
434434
}
@@ -458,6 +458,25 @@ function onShowEdit() {
458458
function onSubmit() {
459459
global $app, $conf;
460460

461+
/* check if the domain module is used - and check if the selected domain can be used! */
462+
$app->uses('ini_parser,getconf');
463+
$settings = $app->getconf->get_global_config('domains');
464+
if ($settings['use_domain_module'] == 'y') {
465+
$client_group_id = intval($_SESSION["s"]["user"]["default_group"]);
466+
467+
$sql = "SELECT domain_id, domain FROM domain WHERE domain_id = " . intval($this->dataRecord['domain']);
468+
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
469+
$sql .= "AND sys_groupid =" . $client_group_id;
470+
}
471+
$domain_check = $app->db->queryOneRecord($sql);
472+
if(!$domain_check) {
473+
// invalid domain selected
474+
$app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />";
475+
} else {
476+
$this->dataRecord['domain'] = $domain_check['domain'];
477+
}
478+
}
479+
461480
// Set a few fixed values
462481
$this->dataRecord["parent_domain_id"] = 0;
463482
$this->dataRecord["type"] = 'vhost';

interface/web/sites/web_subdomain_edit.php

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,54 @@ function onShowNew() {
7171
function onShowEnd() {
7272
global $app, $conf;
7373

74-
// Get the record of the parent domain
75-
$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".intval(@$this->dataRecord["parent_domain_id"]));
76-
77-
// remove the parent domain part of the domain name before we show it in the text field.
78-
$this->dataRecord["domain"] = str_replace('.'.$parent_domain["domain"],'',$this->dataRecord["domain"]);
79-
$app->tpl->setVar("domain",$this->dataRecord["domain"]);
74+
$app->uses('ini_parser,getconf');
75+
$settings = $app->getconf->get_global_config('domains');
76+
if ($settings['use_domain_module'] == 'y') {
77+
/*
78+
* The domain-module is in use.
79+
*/
80+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
81+
/*
82+
* The admin can select ALL domains, the user only the domains assigned to him
83+
*/
84+
$sql = "SELECT domain_id, domain FROM domain ";
85+
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
86+
$sql .= "WHERE sys_groupid =" . $client_group_id;
87+
}
88+
$sql .= " ORDER BY domain";
89+
$domains = $app->db->queryAllRecords($sql);
90+
$domain_select = '';
91+
$selected_domain = '';
92+
if(is_array($domains) && sizeof($domains) > 0) {
93+
/* We have domains in the list, so create the drop-down-list */
94+
foreach( $domains as $domain) {
95+
$domain_select .= "<option value=" . $domain['domain_id'] ;
96+
if ('.' . $domain['domain'] == substr($this->dataRecord["domain"], -strlen($domain['domain']) - 1)) {
97+
$domain_select .= " selected";
98+
$selected_domain = $domain['domain'];
99+
}
100+
$domain_select .= ">" . $domain['domain'] . "</option>\r\n";
101+
}
102+
}
103+
else {
104+
/*
105+
* We have no domains in the domain-list. This means, we can not add ANY new domain.
106+
* To avoid, that the variable "domain_option" is empty and so the user can
107+
* free enter a domain, we have to create a empty option!
108+
*/
109+
$domain_select .= "<option value=''></option>\r\n";
110+
}
111+
$app->tpl->setVar("domain_option",$domain_select);
112+
$this->dataRecord['domain'] = substr($this->dataRecord["domain"], 0, strlen($this->dataRecord['domain']) - strlen($selected_domain) - 1);
113+
} else {
114+
115+
// Get the record of the parent domain
116+
$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".intval(@$this->dataRecord["parent_domain_id"]));
117+
118+
// remove the parent domain part of the domain name before we show it in the text field.
119+
$this->dataRecord["domain"] = str_replace('.'.$parent_domain["domain"],'',$this->dataRecord["domain"]);
120+
}
121+
$app->tpl->setVar("domain",$this->dataRecord["domain"]);
80122

81123
parent::onShowEnd();
82124

@@ -85,17 +127,30 @@ function onShowEnd() {
85127
function onSubmit() {
86128
global $app, $conf;
87129

88-
// Get the record of the parent domain
89-
$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".intval(@$this->dataRecord["parent_domain_id"]));
90-
130+
// Get the record of the parent domain
131+
$parent_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval(@$this->dataRecord["parent_domain_id"]));
132+
133+
$app->uses('ini_parser,getconf');
134+
$settings = $app->getconf->get_global_config('domains');
135+
if ($settings['use_domain_module'] == 'y') {
136+
// get the record of the domain module domain
137+
$domain = $app->db->queryOneRecord("SELECT * FROM domain WHERE domain_id = ".intval($this->dataRecord["sel_domain"]));
138+
if(!$domain) {
139+
$app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />";
140+
} else {
141+
$this->dataRecord['domain'] = $this->dataRecord['domain'] . '.' . $domain['domain'];
142+
}
143+
} else {
144+
$this->dataRecord["domain"] = $this->dataRecord["domain"].'.'.$parent_domain["domain"];
145+
}
146+
91147
// Set a few fixed values
92148
$this->dataRecord["type"] = 'subdomain';
93149
$this->dataRecord["server_id"] = $parent_domain["server_id"];
94-
$this->dataRecord["domain"] = $this->dataRecord["domain"].'.'.$parent_domain["domain"];
95150

96151
$this->parent_domain_record = $parent_domain;
97152

98-
//* make sure that the email domain is lowercase
153+
//* make sure that the domain is lowercase
99154
if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]);
100155

101156
parent::onSubmit();
@@ -108,6 +163,22 @@ function onAfterInsert() {
108163

109164
}
110165

166+
function onAfterUpdate() {
167+
global $app, $conf;
168+
169+
//* Check if parent domain has been changed
170+
if($this->dataRecord['parent_domain_id'] != $this->oldDataRecord['parent_domain_id']) {
171+
172+
//* Update the domain owner
173+
$app->db->query('UPDATE web_domain SET sys_groupid = '.intval($this->parent_domain_record['sys_groupid']).' WHERE domain_id = '.$this->id);
174+
175+
//* Update the old website, so that the vhost alias gets removed
176+
//* We force the update by inserting a transaction record without changes manually.
177+
$old_website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = '.$this->oldDataRecord['domain_id']);
178+
$app->db->datalogSave('web_domain', 'UPDATE', 'domain_id', $this->oldDataRecord['parent_domain_id'], $old_website, $old_website, true);
179+
}
180+
181+
}
111182

112183
}
113184

0 commit comments

Comments
 (0)