Skip to content

Commit db5aa62

Browse files
committed
- Added a global system settings storage in ini format.
- Updated the user and database prefixes to use this storage.
1 parent d062c99 commit db5aa62

File tree

10 files changed

+235
-281
lines changed

10 files changed

+235
-281
lines changed

install/lib/installer_base.lib.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ public function configure_database() {
159159
if(count($db_tables) == 0) {
160160
$this->error('Unable to load SQL-Dump into database table.');
161161
}
162+
163+
//* Load system.ini into the sys_ini table
164+
$system_ini = $this->db->quote(rf('tpl/system.ini.master'));
165+
$this->db->query("UPDATE sys_ini SET config = '$system_ini' WHERE sysini_id = 1");
166+
162167
}
163168
}
164169

install/sql/ispconfig3.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,24 @@ INSERT INTO `sys_group` (`groupid`, `name`, `description`, `client_id`) VALUES (
997997

998998
-- --------------------------------------------------------
999999

1000+
--
1001+
-- Tabellenstruktur für Tabelle `sys_ini`
1002+
--
1003+
1004+
CREATE TABLE `sys_ini` (
1005+
`sysini_id` int(11) NOT NULL auto_increment,
1006+
`config` longtext NOT NULL,
1007+
PRIMARY KEY (`sysini_id`)
1008+
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
1009+
1010+
--
1011+
-- Daten für Tabelle `sys_ini`
1012+
--
1013+
1014+
INSERT INTO `sys_ini` (`sysini_id`, `config`) VALUES (1, '');
1015+
1016+
-- --------------------------------------------------------
1017+
10001018
--
10011019
-- Tabellenstruktur für Tabelle `sys_log`
10021020
--

install/tpl/system.ini.master

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[global]
2+
3+
[admin]
4+
5+
[client]
6+
7+
[dns]
8+
9+
[mail]
10+
11+
[monitor]
12+
13+
[sites]
14+
dbname_prefix=[CLIENTNAME]_
15+
dbuser_prefix=[CLIENTNAME]
16+
ftpuser_prefix=[CLIENTNAME]
17+
shelluser_prefix=[CLIENTNAME]
18+
19+
[tools]

install/update.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,28 @@
199199
unset($new_ini);
200200

201201

202+
//** Update system ini
203+
$tmp_server_rec = $inst->db->queryOneRecord("SELECT config FROM sys_ini WHERE sysini_id = 1");
204+
$old_ini_array = ini_to_array(stripslashes($tmp_server_rec['config']));
205+
unset($tmp_server_rec);
206+
$tpl_ini_array = ini_to_array(rf('tpl/system.ini.master'));
207+
208+
// update the new template with the old values
209+
if(is_array($old_ini_array)) {
210+
foreach($old_ini_array as $tmp_section_name => $tmp_section_content) {
211+
foreach($tmp_section_content as $tmp_var_name => $tmp_var_content) {
212+
$tpl_ini_array[$tmp_section_name][$tmp_var_name] = $tmp_var_content;
213+
}
214+
}
215+
}
216+
217+
$new_ini = array_to_ini($tpl_ini_array);
218+
$inst->db->query("UPDATE sys_ini SET config = '".mysql_real_escape_string($new_ini)."' WHERE sysini_id = 1");
219+
unset($old_ini_array);
220+
unset($tpl_ini_array);
221+
unset($new_ini);
222+
223+
202224
//** Shall the services be reconfigured during update
203225
$reconfigure_services_answer = $inst->simple_query('Reconfigure Services?', array('yes','no'),'yes');
204226

interface/lib/classes/getconf.inc.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,15 @@ public function get_server_config($server_id, $section = '') {
4444
return ($section == '') ? $this->config[$server_id] : $this->config[$server_id][$section];
4545
}
4646

47-
public function get_global_config() {
47+
public function get_global_config($section = '') {
48+
global $app;
4849

49-
die("not yet implemented");
50+
if(!is_array($this->config['global'])) {
51+
$app->uses('ini_parser');
52+
$tmp = $app->db->queryOneRecord("SELECT config FROM sys_ini WHERE sysini_id = 1");
53+
$this->config['global'] = $app->ini_parser->parse_ini_string(stripslashes($tmp["config"]));
54+
}
55+
return ($section == '') ? $this->config['global'] : $this->config['global'][$section];
5056
}
5157
}
5258

interface/web/sites/database_edit.php

Lines changed: 59 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -153,39 +153,25 @@ function onShowEnd() {
153153
* If the names are restricted -> remove the restriction, so that the
154154
* data can be edited
155155
*/
156-
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;
161-
/* Get the group-id */
162-
if($_SESSION["s"]["user"]["typ"] != 'admin') {
163-
// Get the group-id of the user
164-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
165-
}
166-
else {
167-
// Get the group-id from the data itself
168-
$client_group_id = $this->dataRecord['sys_groupid'];
169-
}
170-
/* get the name of the client */
171-
$tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id);
172-
$clientName = $tmp['name'];
173-
if ($clientName == "") $clientName = 'default';
174-
$clientName = convertClientName($clientName);
175-
$restriction = str_replace('[CLIENTNAME]', $clientName, $restriction);
176-
if ($this->dataRecord['database_name'] != ""){
177-
/* REMOVE the restriction */
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']));
180-
}
181-
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
182-
$app->tpl->setVar("database_name_prefix", $tmpRestriction);
183-
$app->tpl->setVar("database_user_prefix", $tmpRestriction);
184-
}
185-
else {
186-
$app->tpl->setVar("database_name_prefix", $restriction);
187-
$app->tpl->setVar("database_user_prefix", $restriction);
188-
}
156+
157+
//* Get the database name and database user prefix
158+
$app->uses('getconf');
159+
$global_config = $app->getconf->get_global_config('sites');
160+
$dbname_prefix = ($global_config['dbname_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbname_prefix']);
161+
$dbuser_prefix = ($global_config['dbuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbuser_prefix']);
162+
163+
if ($this->dataRecord['database_name'] != ""){
164+
/* REMOVE the restriction */
165+
$app->tpl->setVar("database_name", str_replace($dbname_prefix , '', $this->dataRecord['database_name']));
166+
$app->tpl->setVar("database_user", str_replace($dbuser_prefix , '', $this->dataRecord['database_user']));
167+
}
168+
169+
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
170+
$app->tpl->setVar("database_name_prefix", $global_config['dbname_prefix']);
171+
$app->tpl->setVar("database_user_prefix", $global_config['dbuser_prefix']);
172+
} else {
173+
$app->tpl->setVar("database_name_prefix", $dbname_prefix);
174+
$app->tpl->setVar("database_user_prefix", $dbuser_prefix);
189175
}
190176

191177
parent::onShowEnd();
@@ -233,44 +219,23 @@ function onBeforeUpdate() {
233219
global $app, $conf, $interfaceConf;
234220

235221
/*
236-
* If the names should be restricted -> do it!
237-
*/
238-
if ($interfaceConf['restrict_names'] == true){
239-
/* get the restriction */
240-
$restriction = '[CLIENTNAME]_';
241-
if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname'];
242-
243-
/* Get the group-id */
244-
if($_SESSION["s"]["user"]["typ"] != 'admin') {
245-
// Get the group-id of the user
246-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
247-
}
248-
else {
249-
// Get the group-id from the data itself
250-
$client_group_id = $this->dataRecord['client_group_id'];
251-
}
252-
/* get the name of the client */
253-
$tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id);
254-
$clientName = $tmp['name'];
255-
if ($clientName == "") $clientName = 'default';
256-
$clientName = convertClientName($clientName);
257-
$restriction = str_replace('[CLIENTNAME]', $clientName, $restriction);
258-
}
259-
else {
260-
$restriction = '';
261-
}
262-
263-
$error = false;
222+
* If the names should be restricted -> do it!
223+
*/
224+
225+
226+
//* Get the database name and database user prefix
227+
$app->uses('getconf');
228+
$global_config = $app->getconf->get_global_config('sites');
229+
$dbname_prefix = ($global_config['dbname_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbname_prefix']);
230+
$dbuser_prefix = ($global_config['dbuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbuser_prefix']);
264231

265232
//* Prevent that the database name and charset is changed
266233
$old_record = $app->tform->getDataRecord($this->id);
267234
if($old_record["database_name"] != $restriction . $this->dataRecord["database_name"]) {
268235
$app->tform->errorMessage .= $app->tform->wordbook["database_name_change_txt"].'<br />';
269-
$error = true;
270236
}
271237
if($old_record["database_charset"] != $this->dataRecord["database_charset"]) {
272238
$app->tform->errorMessage .= $app->tform->wordbook["database_charset_change_txt"].'<br />';
273-
$error = true;
274239
}
275240

276241
//* Check if the server has been changed
@@ -280,15 +245,14 @@ function onBeforeUpdate() {
280245
//* Add a error message and switch back to old server
281246
$app->tform->errorMessage .= $app->lng('The Server can not be changed.');
282247
$this->dataRecord["server_id"] = $rec['server_id'];
283-
$error = true;
284248
}
285249
}
286250
unset($old_record);
287251

288-
if ($error == false){
252+
if ($app->tform->errorMessage == ''){
289253
/* restrict the names if there is no error */
290-
$this->dataRecord['database_name'] = $restriction . $this->dataRecord['database_name'];
291-
$this->dataRecord['database_user'] = $restriction . $this->dataRecord['database_user'];
254+
$this->dataRecord['database_name'] = $dbname_prefix . $this->dataRecord['database_name'];
255+
$this->dataRecord['database_user'] = $dbuser_prefix . $this->dataRecord['database_user'];
292256
}
293257

294258
parent::onBeforeUpdate();
@@ -297,34 +261,16 @@ function onBeforeUpdate() {
297261
function onBeforeInsert() {
298262
global $app, $conf, $interfaceConf;
299263

300-
/*
301-
* If the names should be restricted -> do it!
302-
*/
303-
if ($interfaceConf['restrict_names'] == true){
304-
/* get the restriction */
305-
$restriction = '[CLIENTNAME]_';
306-
if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname'];
307-
308-
/* Get the group-id */
309-
if($_SESSION["s"]["user"]["typ"] != 'admin') {
310-
// Get the group-id of the user
311-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
312-
}
313-
else {
314-
// Get the group-id from the data itself
315-
$client_group_id = $this->dataRecord['client_group_id'];
316-
}
317-
/* get the name of the client */
318-
$tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id);
319-
$clientName = $tmp['name'];
320-
if ($clientName == "") $clientName = 'default';
321-
$clientName = convertClientName($clientName);
322-
$restriction = str_replace('[CLIENTNAME]', $clientName, $restriction);
323-
324-
/* restrict the names */
325-
$this->dataRecord['database_name'] = $restriction . $this->dataRecord['database_name'];
326-
$this->dataRecord['database_user'] = $restriction . $this->dataRecord['database_user'];
327-
}
264+
//* Get the database name and database user prefix
265+
$app->uses('getconf');
266+
$global_config = $app->getconf->get_global_config('sites');
267+
$dbname_prefix = ($global_config['dbname_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbname_prefix']);
268+
$dbuser_prefix = ($global_config['dbuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbuser_prefix']);
269+
270+
/* restrict the names */
271+
$this->dataRecord['database_name'] = $dbname_prefix . $this->dataRecord['database_name'];
272+
$this->dataRecord['database_user'] = $dbuser_prefix . $this->dataRecord['database_user'];
273+
328274
parent::onBeforeInsert();
329275
}
330276

@@ -358,6 +304,24 @@ function onAfterUpdate() {
358304
}
359305

360306
}
307+
308+
function getClientName() {
309+
global $app, $conf;
310+
311+
if($_SESSION["s"]["user"]["typ"] != 'admin') {
312+
// Get the group-id of the user
313+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
314+
} else {
315+
// Get the group-id from the data itself
316+
$client_group_id = $this->dataRecord['client_group_id'];
317+
}
318+
/* get the name of the client */
319+
$tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id);
320+
$clientName = $tmp['name'];
321+
if ($clientName == "") $clientName = 'default';
322+
$clientName = convertClientName($clientName);
323+
324+
}
361325

362326
}
363327

0 commit comments

Comments
 (0)