From db5aa62b7faa2685f29215d4d08e13d28fd481a1 Mon Sep 17 00:00:00 2001 From: tbrehm <t.brehm@ispconfig.org> Date: Mon, 15 Dec 2008 04:22:20 -0500 Subject: [PATCH] - Added a global system settings storage in ini format. - Updated the user and database prefixes to use this storage. --- server/lib/classes/getconf.inc.php | 11 install/lib/installer_base.lib.php | 5 install/sql/ispconfig3.sql | 18 ++ install/tpl/system.ini.master | 19 ++ interface/web/sites/shell_user_edit.php | 131 +++++--------- interface/web/sites/tools.inc.php | 2 install/update.php | 22 ++ interface/web/sites/database_edit.php | 150 ++++++---------- interface/lib/classes/getconf.inc.php | 10 interface/web/sites/ftp_user_edit.php | 142 +++++---------- 10 files changed, 232 insertions(+), 278 deletions(-) diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 4101356..d33b304 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -159,6 +159,11 @@ if(count($db_tables) == 0) { $this->error('Unable to load SQL-Dump into database table.'); } + + //* Load system.ini into the sys_ini table + $system_ini = $this->db->quote(rf('tpl/system.ini.master')); + $this->db->query("UPDATE sys_ini SET config = '$system_ini' WHERE sysini_id = 1"); + } } diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql index fbb2539..cc5b893 100644 --- a/install/sql/ispconfig3.sql +++ b/install/sql/ispconfig3.sql @@ -998,6 +998,24 @@ -- -------------------------------------------------------- -- +-- Tabellenstruktur f�r Tabelle `sys_ini` +-- + +CREATE TABLE `sys_ini` ( + `sysini_id` int(11) NOT NULL auto_increment, + `config` longtext NOT NULL, + PRIMARY KEY (`sysini_id`) +) ENGINE=MyISAM AUTO_INCREMENT=1 ; + +-- +-- Daten f�r Tabelle `sys_ini` +-- + +INSERT INTO `sys_ini` (`sysini_id`, `config`) VALUES (1, ''); + +-- -------------------------------------------------------- + +-- -- Tabellenstruktur f�r Tabelle `sys_log` -- diff --git a/install/tpl/system.ini.master b/install/tpl/system.ini.master new file mode 100644 index 0000000..2ef756e --- /dev/null +++ b/install/tpl/system.ini.master @@ -0,0 +1,19 @@ +[global] + +[admin] + +[client] + +[dns] + +[mail] + +[monitor] + +[sites] +dbname_prefix=[CLIENTNAME]_ +dbuser_prefix=[CLIENTNAME] +ftpuser_prefix=[CLIENTNAME] +shelluser_prefix=[CLIENTNAME] + +[tools] \ No newline at end of file diff --git a/install/update.php b/install/update.php index 0bfaf3d..8af1097 100644 --- a/install/update.php +++ b/install/update.php @@ -199,6 +199,28 @@ unset($new_ini); +//** Update system ini +$tmp_server_rec = $inst->db->queryOneRecord("SELECT config FROM sys_ini WHERE sysini_id = 1"); +$old_ini_array = ini_to_array(stripslashes($tmp_server_rec['config'])); +unset($tmp_server_rec); +$tpl_ini_array = ini_to_array(rf('tpl/system.ini.master')); + +// update the new template with the old values +if(is_array($old_ini_array)) { + foreach($old_ini_array as $tmp_section_name => $tmp_section_content) { + foreach($tmp_section_content as $tmp_var_name => $tmp_var_content) { + $tpl_ini_array[$tmp_section_name][$tmp_var_name] = $tmp_var_content; + } + } +} + +$new_ini = array_to_ini($tpl_ini_array); +$inst->db->query("UPDATE sys_ini SET config = '".mysql_real_escape_string($new_ini)."' WHERE sysini_id = 1"); +unset($old_ini_array); +unset($tpl_ini_array); +unset($new_ini); + + //** Shall the services be reconfigured during update $reconfigure_services_answer = $inst->simple_query('Reconfigure Services?', array('yes','no'),'yes'); diff --git a/interface/lib/classes/getconf.inc.php b/interface/lib/classes/getconf.inc.php index 097342c..2a9dcc1 100644 --- a/interface/lib/classes/getconf.inc.php +++ b/interface/lib/classes/getconf.inc.php @@ -44,9 +44,15 @@ return ($section == '') ? $this->config[$server_id] : $this->config[$server_id][$section]; } - public function get_global_config() { + public function get_global_config($section = '') { + global $app; - die("not yet implemented"); + if(!is_array($this->config['global'])) { + $app->uses('ini_parser'); + $tmp = $app->db->queryOneRecord("SELECT config FROM sys_ini WHERE sysini_id = 1"); + $this->config['global'] = $app->ini_parser->parse_ini_string(stripslashes($tmp["config"])); + } + return ($section == '') ? $this->config['global'] : $this->config['global'][$section]; } } diff --git a/interface/web/sites/database_edit.php b/interface/web/sites/database_edit.php index 5147265..5ed2dc8 100644 --- a/interface/web/sites/database_edit.php +++ b/interface/web/sites/database_edit.php @@ -153,39 +153,25 @@ * If the names are restricted -> remove the restriction, so that the * data can be edited */ - if ($interfaceConf['restrict_names'] == true){ - /* get the restriction */ - $restriction = '[CLIENTNAME]_'; - if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname']; - $tmpRestriction = $restriction; - /* Get the group-id */ - if($_SESSION["s"]["user"]["typ"] != 'admin') { - // Get the group-id of the user - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } - else { - // Get the group-id from the data itself - $client_group_id = $this->dataRecord['sys_groupid']; - } - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); - $clientName = $tmp['name']; - if ($clientName == "") $clientName = 'default'; - $clientName = convertClientName($clientName); - $restriction = str_replace('[CLIENTNAME]', $clientName, $restriction); - if ($this->dataRecord['database_name'] != ""){ - /* REMOVE the restriction */ - $app->tpl->setVar("database_name", str_replace($restriction , '', $this->dataRecord['database_name'])); - $app->tpl->setVar("database_user", str_replace($restriction , '', $this->dataRecord['database_user'])); - } - if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { - $app->tpl->setVar("database_name_prefix", $tmpRestriction); - $app->tpl->setVar("database_user_prefix", $tmpRestriction); - } - else { - $app->tpl->setVar("database_name_prefix", $restriction); - $app->tpl->setVar("database_user_prefix", $restriction); - } + + //* Get the database name and database user prefix + $app->uses('getconf'); + $global_config = $app->getconf->get_global_config('sites'); + $dbname_prefix = ($global_config['dbname_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbname_prefix']); + $dbuser_prefix = ($global_config['dbuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbuser_prefix']); + + if ($this->dataRecord['database_name'] != ""){ + /* REMOVE the restriction */ + $app->tpl->setVar("database_name", str_replace($dbname_prefix , '', $this->dataRecord['database_name'])); + $app->tpl->setVar("database_user", str_replace($dbuser_prefix , '', $this->dataRecord['database_user'])); + } + + if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { + $app->tpl->setVar("database_name_prefix", $global_config['dbname_prefix']); + $app->tpl->setVar("database_user_prefix", $global_config['dbuser_prefix']); + } else { + $app->tpl->setVar("database_name_prefix", $dbname_prefix); + $app->tpl->setVar("database_user_prefix", $dbuser_prefix); } parent::onShowEnd(); @@ -233,44 +219,23 @@ global $app, $conf, $interfaceConf; /* - * If the names should be restricted -> do it! - */ - if ($interfaceConf['restrict_names'] == true){ - /* get the restriction */ - $restriction = '[CLIENTNAME]_'; - if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname']; - - /* Get the group-id */ - if($_SESSION["s"]["user"]["typ"] != 'admin') { - // Get the group-id of the user - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } - else { - // Get the group-id from the data itself - $client_group_id = $this->dataRecord['client_group_id']; - } - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); - $clientName = $tmp['name']; - if ($clientName == "") $clientName = 'default'; - $clientName = convertClientName($clientName); - $restriction = str_replace('[CLIENTNAME]', $clientName, $restriction); - } - else { - $restriction = ''; - } - - $error = false; + * If the names should be restricted -> do it! + */ + + + //* Get the database name and database user prefix + $app->uses('getconf'); + $global_config = $app->getconf->get_global_config('sites'); + $dbname_prefix = ($global_config['dbname_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbname_prefix']); + $dbuser_prefix = ($global_config['dbuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbuser_prefix']); //* Prevent that the database name and charset is changed $old_record = $app->tform->getDataRecord($this->id); if($old_record["database_name"] != $restriction . $this->dataRecord["database_name"]) { $app->tform->errorMessage .= $app->tform->wordbook["database_name_change_txt"].'<br />'; - $error = true; } if($old_record["database_charset"] != $this->dataRecord["database_charset"]) { $app->tform->errorMessage .= $app->tform->wordbook["database_charset_change_txt"].'<br />'; - $error = true; } //* Check if the server has been changed @@ -280,15 +245,14 @@ //* Add a error message and switch back to old server $app->tform->errorMessage .= $app->lng('The Server can not be changed.'); $this->dataRecord["server_id"] = $rec['server_id']; - $error = true; } } unset($old_record); - if ($error == false){ + if ($app->tform->errorMessage == ''){ /* restrict the names if there is no error */ - $this->dataRecord['database_name'] = $restriction . $this->dataRecord['database_name']; - $this->dataRecord['database_user'] = $restriction . $this->dataRecord['database_user']; + $this->dataRecord['database_name'] = $dbname_prefix . $this->dataRecord['database_name']; + $this->dataRecord['database_user'] = $dbuser_prefix . $this->dataRecord['database_user']; } parent::onBeforeUpdate(); @@ -297,34 +261,16 @@ function onBeforeInsert() { global $app, $conf, $interfaceConf; - /* - * If the names should be restricted -> do it! - */ - if ($interfaceConf['restrict_names'] == true){ - /* get the restriction */ - $restriction = '[CLIENTNAME]_'; - if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname']; + //* Get the database name and database user prefix + $app->uses('getconf'); + $global_config = $app->getconf->get_global_config('sites'); + $dbname_prefix = ($global_config['dbname_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbname_prefix']); + $dbuser_prefix = ($global_config['dbuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbuser_prefix']); - /* Get the group-id */ - if($_SESSION["s"]["user"]["typ"] != 'admin') { - // Get the group-id of the user - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } - else { - // Get the group-id from the data itself - $client_group_id = $this->dataRecord['client_group_id']; - } - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); - $clientName = $tmp['name']; - if ($clientName == "") $clientName = 'default'; - $clientName = convertClientName($clientName); - $restriction = str_replace('[CLIENTNAME]', $clientName, $restriction); + /* restrict the names */ + $this->dataRecord['database_name'] = $dbname_prefix . $this->dataRecord['database_name']; + $this->dataRecord['database_user'] = $dbuser_prefix . $this->dataRecord['database_user']; - /* restrict the names */ - $this->dataRecord['database_name'] = $restriction . $this->dataRecord['database_name']; - $this->dataRecord['database_user'] = $restriction . $this->dataRecord['database_user']; - } parent::onBeforeInsert(); } @@ -358,6 +304,24 @@ } } + + function getClientName() { + global $app, $conf; + + if($_SESSION["s"]["user"]["typ"] != 'admin') { + // Get the group-id of the user + $client_group_id = $_SESSION["s"]["user"]["default_group"]; + } else { + // Get the group-id from the data itself + $client_group_id = $this->dataRecord['client_group_id']; + } + /* get the name of the client */ + $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); + $clientName = $tmp['name']; + if ($clientName == "") $clientName = 'default'; + $clientName = convertClientName($clientName); + + } } diff --git a/interface/web/sites/ftp_user_edit.php b/interface/web/sites/ftp_user_edit.php index 980e00f..2ceff9c 100644 --- a/interface/web/sites/ftp_user_edit.php +++ b/interface/web/sites/ftp_user_edit.php @@ -79,38 +79,20 @@ * If the names are restricted -> remove the restriction, so that the * data can be edited */ - if ($interfaceConf['restrict_names'] == true){ - /* get the restriction */ - $restriction = '[CLIENTNAME]_'; - if (isset($interfaceConf['restrict_ftpuser'])) $restriction = $interfaceConf['restrict_ftpuser']; - $tmplRestriction = $restriction; - /* Get the group-id */ - if($_SESSION["s"]["user"]["typ"] != 'admin') { - // Get the group-id of the user - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } - else { - // Get the group-id from the data itself - $web = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"])); - $client_group_id = $web['sys_groupid']; - } - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); - $clientName = $tmp['name']; - if ($clientName == "") $clientName = 'default'; - $clientName = convertClientName($clientName); - $restriction = str_replace('[CLIENTNAME]', $clientName, $restriction); - if ($this->dataRecord['username'] != ""){ - /* REMOVE the restriction */ - $app->tpl->setVar("username", str_replace($restriction , '', $this->dataRecord['username'])); - $app->tpl->setVar("username", str_replace($restriction , '', $this->dataRecord['username'])); - } - if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { - $app->tpl->setVar("username_prefix", $tmplRestriction); - } - else { - $app->tpl->setVar("username_prefix", $restriction); - } + + $app->uses('getconf'); + $global_config = $app->getconf->get_global_config('sites'); + $ftpuser_prefix = ($global_config['ftpuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['ftpuser_prefix']); + + if ($this->dataRecord['username'] != ""){ + /* REMOVE the restriction */ + $app->tpl->setVar("username", str_replace($ftpuser_prefix , '', $this->dataRecord['username'])); + } + if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { + $app->tpl->setVar("username_prefix", $global_config['ftpuser_prefix']); + } + else { + $app->tpl->setVar("username_prefix", $ftpuser_prefix); } parent::onShowEnd(); @@ -130,39 +112,15 @@ function onBeforeInsert() { global $app, $conf, $interfaceConf; - - $error = false; - - /* - * If the names should be restricted -> do it! - */ - if ($error == false){ - if ($interfaceConf['restrict_names'] == true){ - /* get the restriction */ - $restriction = '[CLIENTNAME]_'; - if (isset($interfaceConf['restrict_ftpuser'])) $restriction = $interfaceConf['restrict_ftpuser']; - - /* Get the group-id */ - if($_SESSION["s"]["user"]["typ"] != 'admin') { - // Get the group-id of the user - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } - else { - // Get the group-id from the data itself - $web = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"])); - $client_group_id = $web['sys_groupid']; - } - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); - $clientName = $tmp['name']; - if ($clientName == "") $clientName = 'default'; - $clientName = convertClientName($clientName); - $restriction = str_replace('[CLIENTNAME]', $clientName, $restriction); - - /* restrict the names */ - $this->dataRecord['username'] = $restriction . $this->dataRecord['username']; - } + + $app->uses('getconf'); + $global_config = $app->getconf->get_global_config('sites'); + $ftpuser_prefix = ($global_config['ftpuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['ftpuser_prefix']); + + if ($app->tform->errorMessage == '') { + $this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username']; } + parent::onBeforeInsert(); } @@ -187,39 +145,17 @@ function onBeforeUpdate() { global $app, $conf, $interfaceConf; - $error = false; - /* * If the names should be restricted -> do it! */ - if ($error == false){ - /* - * If the names should be restricted -> do it! - */ - if ($interfaceConf['restrict_names'] == true){ - /* get the restriction */ - $restriction = '[CLIENTNAME]_'; - if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname']; - - /* Get the group-id */ - if($_SESSION["s"]["user"]["typ"] != 'admin') { - // Get the group-id of the user - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } - else { - // Get the group-id from the data itself - $web = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"])); - $client_group_id = $web['sys_groupid']; - } - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); - $clientName = $tmp['name']; - if ($clientName == "") $clientName = 'default'; - $clientName = convertClientName($clientName); - $restriction = str_replace('[CLIENTNAME]', $clientName, $restriction); - /* restrict the names */ - $this->dataRecord['username'] = $restriction . $this->dataRecord['username']; - } + + $app->uses('getconf'); + $global_config = $app->getconf->get_global_config('sites'); + $ftpuser_prefix = ($global_config['ftpuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['ftpuser_prefix']); + + /* restrict the names */ + if ($app->tform->errorMessage == '') { + $this->dataRecord['username'] = $restriction . $this->dataRecord['username']; } } @@ -229,6 +165,24 @@ } + function getClientName() { + global $app, $conf; + + if($_SESSION["s"]["user"]["typ"] != 'admin') { + // Get the group-id of the user + $client_group_id = $_SESSION["s"]["user"]["default_group"]; + } else { + // Get the group-id from the data itself + $client_group_id = $this->dataRecord['client_group_id']; + } + /* get the name of the client */ + $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); + $clientName = $tmp['name']; + if ($clientName == "") $clientName = 'default'; + $clientName = convertClientName($clientName); + + } + } $page = new page_action; diff --git a/interface/web/sites/shell_user_edit.php b/interface/web/sites/shell_user_edit.php index d45413a..0ce0404 100644 --- a/interface/web/sites/shell_user_edit.php +++ b/interface/web/sites/shell_user_edit.php @@ -79,38 +79,19 @@ * If the names are restricted -> remove the restriction, so that the * data can be edited */ - if ($interfaceConf['restrict_names'] == true){ - /* get the restriction */ - $restriction = '[CLIENTNAME]_'; - if (isset($interfaceConf['restrict_shelluser'])) $restriction = $interfaceConf['restrict_shelluser']; - $tmplRestriction = $restriction; - /* Get the group-id */ - if($_SESSION["s"]["user"]["typ"] != 'admin') { - // Get the group-id of the user - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } - else { - // Get the group-id from the data itself - $web = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"])); - $client_group_id = $web['sys_groupid']; - } - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); - $clientName = $tmp['name']; - if ($clientName == "") $clientName = 'default'; - $clientName = convertClientName($clientName); - $restriction = str_replace('[CLIENTNAME]', $clientName, $restriction); - if ($this->dataRecord['username'] != ""){ - /* REMOVE the restriction */ - $app->tpl->setVar("username", str_replace($restriction , '', $this->dataRecord['username'])); - $app->tpl->setVar("username", str_replace($restriction , '', $this->dataRecord['username'])); - } - if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { - $app->tpl->setVar("username_prefix", $tmplRestriction); - } - else { - $app->tpl->setVar("username_prefix", $restriction); - } + + $app->uses('getconf'); + $global_config = $app->getconf->get_global_config('sites'); + $shelluser_prefix = ($global_config['shelluser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['shelluser_prefix']); + + if ($this->dataRecord['username'] != ""){ + /* REMOVE the restriction */ + $app->tpl->setVar("username", str_replace($shelluser_prefix , '', $this->dataRecord['username'])); + } + if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { + $app->tpl->setVar("username_prefix", $global_config['shelluser_prefix']); + } else { + $app->tpl->setVar("username_prefix", $shelluser_prefix); } parent::onShowEnd(); @@ -131,13 +112,11 @@ function onBeforeInsert() { global $app, $conf, $interfaceConf; - $error = false; // check if the username is not blacklisted $blacklist = file(ISPC_LIB_PATH.'/shelluser_blacklist'); foreach($blacklist as $line) { if(strtolower(trim($line)) == strtolower(trim($this->dataRecord['username']))){ $app->tform->errorMessage .= 'The username is not allowed.'; - $error = true; } } unset($blacklist); @@ -145,32 +124,14 @@ /* * If the names should be restricted -> do it! */ - if ($error == false){ - if ($interfaceConf['restrict_names'] == true){ - /* get the restriction */ - $restriction = '[CLIENTNAME]_'; - if (isset($interfaceConf['restrict_shelluser'])) $restriction = $interfaceConf['restrict_shelluser']; + if ($app->tform->errorMessage == ''){ + + $app->uses('getconf'); + $global_config = $app->getconf->get_global_config('sites'); + $shelluser_prefix = ($global_config['shelluser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['shelluser_prefix']); - /* Get the group-id */ - if($_SESSION["s"]["user"]["typ"] != 'admin') { - // Get the group-id of the user - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } - else { - // Get the group-id from the data itself - $web = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"])); - $client_group_id = $web['sys_groupid']; - } - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); - $clientName = $tmp['name']; - if ($clientName == "") $clientName = 'default'; - $clientName = convertClientName($clientName); - $restriction = str_replace('[CLIENTNAME]', $clientName, $restriction); - - /* restrict the names */ - $this->dataRecord['username'] = $restriction . $this->dataRecord['username']; - } + /* restrict the names */ + $this->dataRecord['username'] = $shelluser_prefix . $this->dataRecord['username']; } parent::onBeforeInsert(); } @@ -195,13 +156,11 @@ function onBeforeUpdate() { global $app, $conf, $interfaceConf; - $error = false; // check if the username is not blacklisted $blacklist = file(ISPC_LIB_PATH.'/shelluser_blacklist'); foreach($blacklist as $line) { if(strtolower(trim($line)) == strtolower(trim($this->dataRecord['username']))){ $app->tform->errorMessage .= 'The username is not allowed.'; - $error = true; } } unset($blacklist); @@ -209,34 +168,16 @@ /* * If the names should be restricted -> do it! */ - if ($error == false){ + if ($app->tform->errorMessage == '') { /* * If the names should be restricted -> do it! */ - if ($interfaceConf['restrict_names'] == true){ - /* get the restriction */ - $restriction = '[CLIENTNAME]_'; - if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname']; - - /* Get the group-id */ - if($_SESSION["s"]["user"]["typ"] != 'admin') { - // Get the group-id of the user - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - } - else { - // Get the group-id from the data itself - $web = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"])); - $client_group_id = $web['sys_groupid']; - } - /* get the name of the client */ - $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); - $clientName = $tmp['name']; - if ($clientName == "") $clientName = 'default'; - $clientName = convertClientName($clientName); - $restriction = str_replace('[CLIENTNAME]', $clientName, $restriction); - /* restrict the names */ - $this->dataRecord['username'] = $restriction . $this->dataRecord['username']; - } + $app->uses('getconf'); + $global_config = $app->getconf->get_global_config('sites'); + $shelluser_prefix = ($global_config['shelluser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['shelluser_prefix']); + + /* restrict the names */ + $this->dataRecord['username'] = $shelluser_prefix . $this->dataRecord['username']; } } @@ -246,6 +187,24 @@ } + function getClientName() { + global $app, $conf; + + if($_SESSION["s"]["user"]["typ"] != 'admin') { + // Get the group-id of the user + $client_group_id = $_SESSION["s"]["user"]["default_group"]; + } else { + // Get the group-id from the data itself + $client_group_id = $this->dataRecord['client_group_id']; + } + /* get the name of the client */ + $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); + $clientName = $tmp['name']; + if ($clientName == "") $clientName = 'default'; + $clientName = convertClientName($clientName); + + } + } $page = new page_action; diff --git a/interface/web/sites/tools.inc.php b/interface/web/sites/tools.inc.php index 400c05f..c2b8297 100644 --- a/interface/web/sites/tools.inc.php +++ b/interface/web/sites/tools.inc.php @@ -17,4 +17,6 @@ } return $res; } + + ?> diff --git a/server/lib/classes/getconf.inc.php b/server/lib/classes/getconf.inc.php index 7bff61f..a4bc832 100644 --- a/server/lib/classes/getconf.inc.php +++ b/server/lib/classes/getconf.inc.php @@ -49,10 +49,15 @@ } } - function get_global_config() { + public function get_global_config($section = '') { + global $app; - die("not yet implemented"); - + if(!is_array($this->config['global'])) { + $app->uses('ini_parser'); + $tmp = $app->db->queryOneRecord("SELECT config FROM sys_ini WHERE sysini_id = 1"); + $this->config['global'] = $app->ini_parser->parse_ini_string(stripslashes($tmp["config"])); + } + return ($section == '') ? $this->config['global'] : $this->config['global'][$section]; } } -- Gitblit v1.9.1