Skip to content

Commit 5190fe6

Browse files
author
vogelor
committed
The names of the database, the database-user, the shell-user and the ftp-user can now be restricted
1 parent e265dcb commit 5190fe6

File tree

5 files changed

+275
-21
lines changed

5 files changed

+275
-21
lines changed

interface/web/sites/database_edit.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,14 @@ function onShowEnd() {
150150
}
151151

152152
/*
153-
* If the names are restricted -> remove the client, so that the
153+
* If the names are restricted -> remove the restriction, so that the
154154
* data can be edited
155155
*/
156156
if ($interfaceConf['restrict_names'] == true){
157+
/* get the restriction */
158+
$restriction = '[CLIENTNAME]_';
159+
if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname'];
160+
$tmpRestriction = $restriction;
157161
/* Get the group-id */
158162
if($_SESSION["s"]["user"]["typ"] != 'admin') {
159163
// Get the group-id of the user
@@ -168,18 +172,19 @@ function onShowEnd() {
168172
$clientName = $tmp['name'];
169173
if ($clientName == "") $clientName = 'default';
170174
$clientName = convertClientName($clientName);
175+
$restriction = str_replace('[CLIENTNAME]', $clientName, $restriction);
171176
if ($this->dataRecord['database_name'] != ""){
172177
/* REMOVE the restriction */
173-
$app->tpl->setVar("database_name", str_replace($clientName . '_' , '', $this->dataRecord['database_name']));
174-
$app->tpl->setVar("database_user", str_replace($clientName . '_' , '', $this->dataRecord['database_user']));
178+
$app->tpl->setVar("database_name", str_replace($restriction , '', $this->dataRecord['database_name']));
179+
$app->tpl->setVar("database_user", str_replace($restriction , '', $this->dataRecord['database_user']));
175180
}
176181
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
177-
$app->tpl->setVar("database_name_prefix", '{client}_');
178-
$app->tpl->setVar("database_user_prefix", '{client}_');
182+
$app->tpl->setVar("database_name_prefix", $tmpRestriction);
183+
$app->tpl->setVar("database_user_prefix", $tmpRestriction);
179184
}
180185
else {
181-
$app->tpl->setVar("database_name_prefix", $clientName . '_');
182-
$app->tpl->setVar("database_user_prefix", $clientName . '_');
186+
$app->tpl->setVar("database_name_prefix", $restriction);
187+
$app->tpl->setVar("database_user_prefix", $restriction);
183188
}
184189
}
185190

@@ -231,6 +236,10 @@ function onBeforeUpdate() {
231236
* If the names should be restricted -> do it!
232237
*/
233238
if ($interfaceConf['restrict_names'] == true){
239+
/* get the restriction */
240+
$restriction = '[CLIENTNAME]_';
241+
if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname'];
242+
234243
/* Get the group-id */
235244
if($_SESSION["s"]["user"]["typ"] != 'admin') {
236245
// Get the group-id of the user
@@ -245,17 +254,17 @@ function onBeforeUpdate() {
245254
$clientName = $tmp['name'];
246255
if ($clientName == "") $clientName = 'default';
247256
$clientName = convertClientName($clientName);
248-
$nameSuffix = $clientName . '_';
257+
$restriction = str_replace('[CLIENTNAME]', $clientName, $restriction);
249258
}
250259
else {
251-
$nameSuffix = '';
260+
$restriction = '';
252261
}
253262

254263
$error = false;
255264

256265
//* Prevent that the database name and charset is changed
257266
$old_record = $app->tform->getDataRecord($this->id);
258-
if($old_record["database_name"] != $nameSuffix . $this->dataRecord["database_name"]) {
267+
if($old_record["database_name"] != $restriction . $this->dataRecord["database_name"]) {
259268
$app->tform->errorMessage .= $app->tform->wordbook["database_name_change_txt"].'<br />';
260269
$error = true;
261270
}
@@ -278,21 +287,24 @@ function onBeforeUpdate() {
278287

279288
if ($error == false){
280289
/* restrict the names if there is no error */
281-
$this->dataRecord['database_name'] = $nameSuffix . $this->dataRecord['database_name'];
282-
$this->dataRecord['database_user'] = $nameSuffix . $this->dataRecord['database_user'];
290+
$this->dataRecord['database_name'] = $restriction . $this->dataRecord['database_name'];
291+
$this->dataRecord['database_user'] = $restriction . $this->dataRecord['database_user'];
283292
}
284293

285294
parent::onBeforeUpdate();
286295
}
287296

288297
function onBeforeInsert() {
289298
global $app, $conf, $interfaceConf;
290-
global $interfaceConf;
291299

292300
/*
293301
* If the names should be restricted -> do it!
294302
*/
295303
if ($interfaceConf['restrict_names'] == true){
304+
/* get the restriction */
305+
$restriction = '[CLIENTNAME]_';
306+
if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname'];
307+
296308
/* Get the group-id */
297309
if($_SESSION["s"]["user"]["typ"] != 'admin') {
298310
// Get the group-id of the user
@@ -307,9 +319,11 @@ function onBeforeInsert() {
307319
$clientName = $tmp['name'];
308320
if ($clientName == "") $clientName = 'default';
309321
$clientName = convertClientName($clientName);
322+
$restriction = str_replace('[CLIENTNAME]', $clientName, $restriction);
323+
310324
/* restrict the names */
311-
$this->dataRecord['database_name'] = $clientName . '_' . $this->dataRecord['database_name'];
312-
$this->dataRecord['database_user'] = $clientName . '_' . $this->dataRecord['database_user'];
325+
$this->dataRecord['database_name'] = $restriction . $this->dataRecord['database_name'];
326+
$this->dataRecord['database_user'] = $restriction . $this->dataRecord['database_user'];
313327
}
314328
parent::onBeforeInsert();
315329
}

interface/web/sites/ftp_user_edit.php

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
require_once('../../lib/config.inc.php');
4242
require_once('../../lib/app.inc.php');
43+
require_once('tools.inc.php');
4344

4445
//* Check permissions for module
4546
$app->auth->check_module_permissions('sites');
@@ -71,6 +72,49 @@ function onShowNew() {
7172

7273
parent::onShowNew();
7374
}
75+
76+
function onShowEnd() {
77+
global $app, $conf, $interfaceConf;
78+
/*
79+
* If the names are restricted -> remove the restriction, so that the
80+
* data can be edited
81+
*/
82+
if ($interfaceConf['restrict_names'] == true){
83+
/* get the restriction */
84+
$restriction = '[CLIENTNAME]_';
85+
if (isset($interfaceConf['restrict_ftpuser'])) $restriction = $interfaceConf['restrict_ftpuser'];
86+
$tmplRestriction = $restriction;
87+
/* Get the group-id */
88+
if($_SESSION["s"]["user"]["typ"] != 'admin') {
89+
// Get the group-id of the user
90+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
91+
}
92+
else {
93+
// Get the group-id from the data itself
94+
$web = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"]));
95+
$client_group_id = $web['sys_groupid'];
96+
}
97+
/* get the name of the client */
98+
$tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id);
99+
$clientName = $tmp['name'];
100+
if ($clientName == "") $clientName = 'default';
101+
$clientName = convertClientName($clientName);
102+
$restriction = str_replace('[CLIENTNAME]', $clientName, $restriction);
103+
if ($this->dataRecord['username'] != ""){
104+
/* REMOVE the restriction */
105+
$app->tpl->setVar("username", str_replace($restriction , '', $this->dataRecord['username']));
106+
$app->tpl->setVar("username", str_replace($restriction , '', $this->dataRecord['username']));
107+
}
108+
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
109+
$app->tpl->setVar("username_prefix", $tmplRestriction);
110+
}
111+
else {
112+
$app->tpl->setVar("username_prefix", $restriction);
113+
}
114+
}
115+
116+
parent::onShowEnd();
117+
}
74118

75119
function onSubmit() {
76120
global $app, $conf;
@@ -84,7 +128,45 @@ function onSubmit() {
84128
parent::onSubmit();
85129
}
86130

87-
function onAfterInsert() {
131+
function onBeforeInsert() {
132+
global $app, $conf, $interfaceConf;
133+
134+
$error = false;
135+
136+
/*
137+
* If the names should be restricted -> do it!
138+
*/
139+
if ($error == false){
140+
if ($interfaceConf['restrict_names'] == true){
141+
/* get the restriction */
142+
$restriction = '[CLIENTNAME]_';
143+
if (isset($interfaceConf['restrict_ftpuser'])) $restriction = $interfaceConf['restrict_ftpuser'];
144+
145+
/* Get the group-id */
146+
if($_SESSION["s"]["user"]["typ"] != 'admin') {
147+
// Get the group-id of the user
148+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
149+
}
150+
else {
151+
// Get the group-id from the data itself
152+
$web = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"]));
153+
$client_group_id = $web['sys_groupid'];
154+
}
155+
/* get the name of the client */
156+
$tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id);
157+
$clientName = $tmp['name'];
158+
if ($clientName == "") $clientName = 'default';
159+
$clientName = convertClientName($clientName);
160+
$restriction = str_replace('[CLIENTNAME]', $clientName, $restriction);
161+
162+
/* restrict the names */
163+
$this->dataRecord['username'] = $restriction . $this->dataRecord['username'];
164+
}
165+
}
166+
parent::onBeforeInsert();
167+
}
168+
169+
function onAfterInsert() {
88170
global $app, $conf;
89171

90172
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"]));
@@ -101,6 +183,45 @@ function onAfterInsert() {
101183

102184

103185
}
186+
187+
function onBeforeUpdate() {
188+
global $app, $conf, $interfaceConf;
189+
190+
$error = false;
191+
192+
/*
193+
* If the names should be restricted -> do it!
194+
*/
195+
if ($error == false){
196+
/*
197+
* If the names should be restricted -> do it!
198+
*/
199+
if ($interfaceConf['restrict_names'] == true){
200+
/* get the restriction */
201+
$restriction = '[CLIENTNAME]_';
202+
if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname'];
203+
204+
/* Get the group-id */
205+
if($_SESSION["s"]["user"]["typ"] != 'admin') {
206+
// Get the group-id of the user
207+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
208+
}
209+
else {
210+
// Get the group-id from the data itself
211+
$web = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"]));
212+
$client_group_id = $web['sys_groupid'];
213+
}
214+
/* get the name of the client */
215+
$tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id);
216+
$clientName = $tmp['name'];
217+
if ($clientName == "") $clientName = 'default';
218+
$clientName = convertClientName($clientName);
219+
$restriction = str_replace('[CLIENTNAME]', $clientName, $restriction);
220+
/* restrict the names */
221+
$this->dataRecord['username'] = $restriction . $this->dataRecord['username'];
222+
}
223+
}
224+
}
104225

105226
function onAfterUpdate() {
106227
global $app, $conf;

0 commit comments

Comments
 (0)