Fixed: FS#2066 - Check if problems can occur ins ervices when the default prefix is manually changed
- Notes:
once the entry was created or modified after applying this update the current prefix is stored with the entry and kept even if the global prefix changes
| | |
| | | `server_id` int(11) unsigned NOT NULL default '0', |
| | | `parent_domain_id` int(11) unsigned NOT NULL default '0', |
| | | `username` varchar(64) default NULL, |
| | | `username_prefix` varchar(50) NOT NULL default '', |
| | | `password` varchar(64) default NULL, |
| | | `quota_size` bigint(20) NOT NULL default '-1', |
| | | `active` enum('n','y') NOT NULL default 'y', |
| | |
| | | `server_id` int(11) unsigned NOT NULL default '0', |
| | | `parent_domain_id` int(11) unsigned NOT NULL default '0', |
| | | `username` varchar(64) default NULL, |
| | | `username_prefix` varchar(50) NOT NULL default '', |
| | | `password` varchar(64) default NULL, |
| | | `quota_size` bigint(20) NOT NULL default '-1', |
| | | `active` enum('n','y') NOT NULL default 'y', |
| | |
| | | `server_id` int(11) unsigned NOT NULL DEFAULT '0', |
| | | `parent_domain_id` int(11) unsigned NOT NULL DEFAULT '0', |
| | | `username` varchar(64) DEFAULT NULL, |
| | | `username_prefix` varchar(50) NOT NULL default '', |
| | | `password` varchar(64) DEFAULT NULL, |
| | | `active` enum('n','y') NOT NULL DEFAULT 'y', |
| | | `dir` varchar(255) DEFAULT NULL, |
| | |
| | | `parent_domain_id` int(11) unsigned NOT NULL DEFAULT '0', |
| | | `type` varchar(16) NOT NULL DEFAULT 'y', |
| | | `database_name` varchar(64) DEFAULT NULL, |
| | | `database_name_prefix` varchar(50) NOT NULL default '', |
| | | `database_user_id` int(11) unsigned DEFAULT NULL, |
| | | `database_ro_user_id` int(11) unsigned DEFAULT NULL, |
| | | `database_charset` varchar(64) DEFAULT NULL, |
| | |
| | | `sys_perm_other` varchar(5) DEFAULT NULL, |
| | | `server_id` int(11) UNSIGNED NOT NULL DEFAULT '0', |
| | | `database_user` varchar(64) DEFAULT NULL, |
| | | `database_user_prefix` varchar(50) NOT NULL default '', |
| | | `database_password` varchar(64) DEFAULT NULL, |
| | | PRIMARY KEY (`database_user_id`) |
| | | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; |
| | |
| | | }
|
| | | //* Find a free db username for the app
|
| | | for($n = 1; $n <= 1000; $n++) {
|
| | | $mysql_db_user = ($dbname_prefix != '' ? $dbname_prefix.'aps'.$n : uniqid('aps'));
|
| | | $mysql_db_user = ($dbuser_prefix != '' ? $dbuser_prefix.'aps'.$n : uniqid('aps'));
|
| | | $tmp = $app->db->queryOneRecord("SELECT count(database_user_id) as number FROM web_database_user WHERE database_user = '".$app->db->quote($mysql_db_user)."'");
|
| | | if($tmp['number'] == 0) break;
|
| | | }
|
| | |
| | | $mysql_db_password = $settings['main_database_password'];
|
| | |
|
| | | //* Create the mysql database user
|
| | | $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `database_user`, `database_password`) |
| | | VALUES( ".$websrv['sys_userid'].", ".$websrv['sys_groupid'].", 'riud', '".$websrv['sys_perm_group']."', '', 0, '$mysql_db_user', PASSWORD('$mysql_db_password'))";
|
| | | $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `database_user`, `database_user_prefix`, `database_password`) |
| | | VALUES( ".$websrv['sys_userid'].", ".$websrv['sys_groupid'].", 'riud', '".$websrv['sys_perm_group']."', '', 0, '$mysql_db_user', '".$app->db->quote($dbuser_prefix) . "', PASSWORD('$mysql_db_password'))";
|
| | | $mysql_db_user_id = $app->db->datalogInsert('web_database_user', $insert_data, 'database_user_id');
|
| | |
|
| | | //* Create the mysql database
|
| | | $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `parent_domain_id`, `type`, `database_name`, `database_user_id`, `database_ro_user_id`, `database_charset`, `remote_access`, `remote_ips`, `backup_copies`, `active`, `backup_interval`) |
| | | VALUES( ".$websrv['sys_userid'].", ".$websrv['sys_groupid'].", 'riud', '".$websrv['sys_perm_group']."', '', $mysql_db_server_id, ".$websrv['domain_id'].", 'mysql', '$mysql_db_name', '$mysql_db_user_id', 0, '', '$mysql_db_remote_access', '$mysql_db_remote_ips', ".$websrv['backup_copies'].", 'y', '".$websrv['backup_interval']."')";
|
| | | $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `parent_domain_id`, `type`, `database_name`, `database_name_prefix`, `database_user_id`, `database_ro_user_id`, `database_charset`, `remote_access`, `remote_ips`, `backup_copies`, `active`, `backup_interval`) |
| | | VALUES( ".$websrv['sys_userid'].", ".$websrv['sys_groupid'].", 'riud', '".$websrv['sys_perm_group']."', '', $mysql_db_server_id, ".$websrv['domain_id'].", 'mysql', '$mysql_db_name', '" . $app->db->quote($dbname_prefix) . "', '$mysql_db_user_id', 0, '', '$mysql_db_remote_access', '$mysql_db_remote_ips', ".$websrv['backup_copies'].", 'y', '".$websrv['backup_interval']."')";
|
| | | $app->db->datalogInsert('web_database', $insert_data, 'database_id');
|
| | |
|
| | | //* Add db details to package settings
|
| | |
| | | return $name; |
| | | } |
| | | |
| | | function removePrefix($name, $currentPrefix, $globalPrefix) { |
| | | if($name == "") return ""; |
| | | |
| | | if($currentPrefix == '#') return $name; // # = empty prefix, do not change name |
| | | if($currentPrefix === '') $currentPrefix = $globalPrefix; // entry has no prefix set, maybe it was created before this function was introduced |
| | | |
| | | if($currentPrefix === '') return $name; // no current prefix and global prefix is empty -> nothing to remove here. |
| | | |
| | | return preg_replace('/^' . preg_quote($currentPrefix, '/') . '/', '', $name); // return name without prefix |
| | | } |
| | | |
| | | function getPrefix($currentPrefix, $userPrefix, $adminPrefix = false) { |
| | | global $app; |
| | | |
| | | if($currentPrefix !== '') return ($currentPrefix == '#' ? '' : $currentPrefix); // return the currently set prefix for this entry (# = empty) |
| | | |
| | | if($adminPrefix === false) $adminPrefix = $userPrefix; |
| | | |
| | | if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) return $adminPrefix; |
| | | else return $userPrefix; |
| | | } |
| | | |
| | | function getClientName($dataRecord) { |
| | | global $app, $conf; |
| | | if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
| | |
| | | |
| | | 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_name", $app->tools_sites->removePrefix($this->dataRecord['database_name'], $this->dataRecord['database_name_prefix'], $dbname_prefix)); |
| | | } |
| | | |
| | | if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
| | | $app->tpl->setVar("database_name_prefix", $global_config['dbname_prefix']); |
| | | } else { |
| | | $app->tpl->setVar("database_name_prefix", $dbname_prefix); |
| | | } |
| | | $app->tpl->setVar("database_name_prefix", $app->tools_sites->getPrefix($this->dataRecord['database_name_prefix'], $dbname_prefix, $global_config['dbname_prefix'])); |
| | | |
| | | if($this->id > 0) { |
| | | //* we are editing a existing record |
| | |
| | | |
| | | //* Prevent that the database name and charset is changed |
| | | $old_record = $app->tform->getDataRecord($this->id); |
| | | $dbname_prefix = $app->tools_sites->getPrefix($old_record['database_name_prefix'], $dbname_prefix); |
| | | $this->dataRecord['database_name_prefix'] = ($dbname_prefix === '' ? '#' : $dbname_prefix); |
| | | |
| | | if($old_record["database_name"] != $dbname_prefix . $this->dataRecord["database_name"]) { |
| | | $app->tform->errorMessage .= $app->tform->wordbook["database_name_change_txt"].'<br />'; |
| | | } |
| | |
| | | $app->uses('getconf,tools_sites'); |
| | | $global_config = $app->getconf->get_global_config('sites'); |
| | | $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); |
| | | $this->dataRecord['database_name_prefix'] = ($dbname_prefix === '' ? '#' : $dbname_prefix); |
| | | |
| | | if(strlen($dbname_prefix . $this->dataRecord['database_name']) > 64) $app->tform->errorMessage .= str_replace('{db}',$dbname_prefix . $this->dataRecord['database_name'],$app->tform->wordbook["database_name_error_len"]).'<br />'; |
| | | |
| | |
| | | |
| | | if ($this->dataRecord['database_user'] != ""){ |
| | | /* REMOVE the restriction */ |
| | | $app->tpl->setVar("database_user", str_replace($dbuser_prefix , '', $this->dataRecord['database_user'])); |
| | | $app->tpl->setVar("database_user", $app->tools_sites->removePrefix($this->dataRecord['database_user'], $this->dataRecord['database_user_prefix'], $dbuser_prefix)); |
| | | } |
| | | |
| | | if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
| | | $app->tpl->setVar("database_user_prefix", $global_config['dbuser_prefix']); |
| | | } else { |
| | | $app->tpl->setVar("database_user_prefix", $dbuser_prefix); |
| | | } |
| | | |
| | | $app->tpl->setVar("database_user_prefix", $app->tools_sites->getPrefix($this->dataRecord['database_user_prefix'], $dbuser_prefix, $global_config['dbuser_prefix'])); |
| | | |
| | | parent::onShowEnd(); |
| | | } |
| | |
| | | $global_config = $app->getconf->get_global_config('sites'); |
| | | $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord); |
| | | |
| | | $this->oldDataRecord = $app->db->queryOneRecord("SELECT * FROM web_database_user WHERE database_user_id = '".$this->id."'"); |
| | | |
| | | $dbuser_prefix = $app->tools_sites->getPrefix($this->oldDataRecord['database_user_prefix'], $dbuser_prefix); |
| | | $this->dataRecord['database_user_prefix'] = ($dbuser_prefix === '' ? '#' : $dbuser_prefix); |
| | | |
| | | //* Database username shall not be empty |
| | | if($this->dataRecord['database_user'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_user_error_empty"].'<br />'; |
| | | |
| | |
| | | } |
| | | |
| | | $this->dataRecord['server_id'] = $conf['server_id']; |
| | | $this->oldDataRecord = $app->db->queryOneRecord("SELECT * FROM web_database_user WHERE database_user_id = '".$this->id."'"); |
| | | |
| | | parent::onBeforeUpdate(); |
| | | } |
| | |
| | | $global_config = $app->getconf->get_global_config('sites'); |
| | | $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord); |
| | | |
| | | $this->dataRecord['database_user_prefix'] = ($dbuser_prefix === '' ? '#' : $dbuser_prefix); |
| | | |
| | | if(strlen($dbuser_prefix . $this->dataRecord['database_user']) > 16) $app->tform->errorMessage .= str_replace('{user}',$dbuser_prefix . $this->dataRecord['database_user'],$app->tform->wordbook["database_user_error_len"]).'<br />'; |
| | | |
| | | //* Check database user against blacklist |
| | |
| | | 'maxlength' => '255', |
| | | 'searchable' => 1 |
| | | ), |
| | | 'database_name_prefix' => array ( |
| | | 'datatype' => 'VARCHAR', |
| | | 'formtype' => 'TEXT', |
| | | 'default' => '', |
| | | 'value' => '', |
| | | 'width' => '30', |
| | | 'maxlength' => '25' |
| | | ), |
| | | 'database_user_id' => array ( |
| | | 'datatype' => 'INTEGER', |
| | | 'formtype' => 'SELECT', |
| | |
| | | 'maxlength' => '255', |
| | | 'searchable' => 1 |
| | | ), |
| | | 'database_user_prefix' => array ( |
| | | 'datatype' => 'VARCHAR', |
| | | 'formtype' => 'TEXT', |
| | | 'default' => '', |
| | | 'value' => '', |
| | | 'width' => '30', |
| | | 'maxlength' => '25' |
| | | ), |
| | | 'database_password' => array ( |
| | | 'datatype' => 'VARCHAR', |
| | | 'formtype' => 'PASSWORD', |
| | |
| | | 'maxlength' => '255', |
| | | 'searchable' => 1 |
| | | ), |
| | | 'username_prefix' => array ( |
| | | 'datatype' => 'VARCHAR', |
| | | 'formtype' => 'TEXT', |
| | | 'default' => '', |
| | | 'value' => '', |
| | | 'width' => '30', |
| | | 'maxlength' => '25' |
| | | ), |
| | | 'password' => array ( |
| | | 'datatype' => 'VARCHAR', |
| | | 'formtype' => 'PASSWORD', |
| | |
| | | 'maxlength' => '255', |
| | | 'searchable' => 1 |
| | | ), |
| | | 'username_prefix' => array ( |
| | | 'datatype' => 'VARCHAR', |
| | | 'formtype' => 'TEXT', |
| | | 'default' => '', |
| | | 'value' => '', |
| | | 'width' => '30', |
| | | 'maxlength' => '25' |
| | | ), |
| | | 'password' => array ( |
| | | 'datatype' => 'VARCHAR', |
| | | 'formtype' => 'PASSWORD', |
| | |
| | | 'width' => '30', |
| | | 'maxlength' => '255' |
| | | ), |
| | | 'username_prefix' => array ( |
| | | 'datatype' => 'VARCHAR', |
| | | 'formtype' => 'TEXT', |
| | | 'default' => '', |
| | | 'value' => '', |
| | | 'width' => '30', |
| | | 'maxlength' => '25' |
| | | ), |
| | | 'password' => array ( |
| | | 'datatype' => 'VARCHAR', |
| | | 'encryption' => 'CLEARTEXT', |
| | |
| | | |
| | | if ($this->dataRecord['username'] != ""){ |
| | | /* REMOVE the restriction */ |
| | | $app->tpl->setVar("username", preg_replace('/'.$ftpuser_prefix.'/' , '', $this->dataRecord['username'], 1)); |
| | | $app->tpl->setVar("username", $app->tools_sites->removePrefix($this->dataRecord['username'], $this->dataRecord['username_prefix'], $ftpuser_prefix)); |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | $app->tpl->setVar("username_prefix", $app->tools_sites->getPrefix($this->dataRecord['username_prefix'], $ftpuser_prefix, $global_config['ftpuser_prefix'])); |
| | | |
| | | parent::onShowEnd(); |
| | | } |
| | |
| | | $app->uses('getconf,tools_sites'); |
| | | $global_config = $app->getconf->get_global_config('sites'); |
| | | $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); |
| | | |
| | | $this->dataRecord['username_prefix'] = ($ftpuser_prefix === '' ? '#' : $ftpuser_prefix); |
| | | |
| | | if ($app->tform->errorMessage == '') { |
| | | $this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username']; |
| | |
| | | $global_config = $app->getconf->get_global_config('sites'); |
| | | $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); |
| | | |
| | | $old_record = $app->tform->getDataRecord($this->id); |
| | | $ftpuser_prefix = $app->tools_sites->getPrefix($old_record['username_prefix'], $ftpuser_prefix); |
| | | $this->dataRecord['username_prefix'] = ($ftpuser_prefix === '' ? '#' : $ftpuser_prefix); |
| | | |
| | | /* restrict the names */ |
| | | if ($app->tform->errorMessage == '') { |
| | | $this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username']; |
| | |
| | | |
| | | if ($this->dataRecord['username'] != ""){ |
| | | /* REMOVE the restriction */ |
| | | $app->tpl->setVar("username", preg_replace('/'.$shelluser_prefix.'/', '', $this->dataRecord['username'], 1)); |
| | | $app->tpl->setVar("username", $app->tools_sites->removePrefix($this->dataRecord['username'], $this->dataRecord['username_prefix'], $shelluser_prefix)); |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | $app->tpl->setVar("username_prefix", $app->tools_sites->getPrefix($this->dataRecord['username_prefix'], $shelluser_prefix, $global_config['shelluser_prefix'])); |
| | | |
| | | if($this->id > 0) { |
| | | //* we are editing a existing record |
| | |
| | | $global_config = $app->getconf->get_global_config('sites'); |
| | | $shelluser_prefix = $app->tools_sites->replacePrefix($global_config['shelluser_prefix'], $this->dataRecord); |
| | | |
| | | $this->dataRecord['username_prefix'] = ($shelluser_prefix === '' ? '#' : $shelluser_prefix); |
| | | /* restrict the names */ |
| | | $this->dataRecord['username'] = $shelluser_prefix . $this->dataRecord['username']; |
| | | } |
| | |
| | | $global_config = $app->getconf->get_global_config('sites'); |
| | | $shelluser_prefix = $app->tools_sites->replacePrefix($global_config['shelluser_prefix'], $this->dataRecord); |
| | | |
| | | $old_record = $app->tform->getDataRecord($this->id); |
| | | $shelluser_prefix = $app->tools_sites->getPrefix($old_record['username_prefix'], $shelluser_prefix); |
| | | $this->dataRecord['username_prefix'] = ($shelluser_prefix === '' ? '#' : $shelluser_prefix); |
| | | |
| | | /* restrict the names */ |
| | | $this->dataRecord['username'] = $shelluser_prefix . $this->dataRecord['username']; |
| | | } |
| | |
| | | |
| | | if ($this->dataRecord['username'] != "") { |
| | | /* REMOVE the restriction */ |
| | | $app->tpl->setVar("username", str_replace($webdavuser_prefix , '', $this->dataRecord['username'])); |
| | | $app->tpl->setVar("username", $app->tools_sites->removePrefix($this->dataRecord['username'], $this->dataRecord['username_prefix'], $webdavuser_prefix)); |
| | | } |
| | | if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
| | | $app->tpl->setVar("username_prefix", $global_config['webdavuser_prefix']); |
| | | } else { |
| | | $app->tpl->setVar("username_prefix", $webdavuser_prefix); |
| | | } |
| | | |
| | | $app->tpl->setVar("username_prefix", $app->tools_sites->getPrefix($this->dataRecord['username_prefix'], $webdavuser_prefix, $global_config['webdavuser_prefix'])); |
| | | |
| | | if($this->id > 0) { |
| | | //* we are editing a existing record |
| | |
| | | $global_config = $app->getconf->get_global_config('sites'); |
| | | $webdavuser_prefix = $app->tools_sites->replacePrefix($global_config['webdavuser_prefix'], $this->dataRecord); |
| | | |
| | | $this->dataRecord['username_prefix'] = ($webdavuser_prefix === '' ? '#' : $webdavuser_prefix); |
| | | |
| | | /* restrict the names */ |
| | | $this->dataRecord['username'] = $webdavuser_prefix . $this->dataRecord['username']; |
| | | |
| | |
| | | $data = $app->db->queryOneRecord("SELECT * FROM webdav_user WHERE webdav_user_id = ".$app->functions->intval($this->id)); |
| | | $this->dataRecord["username"] = $data['username']; |
| | | $this->dataRecord["dir"] = $data['dir']; |
| | | $this->dataRecord['username_prefix'] = $data['username_prefix']; |
| | | $passwordOld = $data['password']; |
| | | |
| | | /* |
| | |
| | | $db_id = parent::getXPathValue($sxe, '//db:id');
|
| | | if(empty($db_id)) return; // No database needed
|
| | |
|
| | | /*
|
| | | /* WARNING: if this will ever be uncommented please check the updated prefix handling for user and db names!!!
|
| | | * |
| | | // Set the database owner to the domain owner
|
| | | // ISPConfig identifies the owner by the sys_groupid (not sys_userid!)
|
| | | // so sys_userid can be set to any value
|