Commit 1390c8b7 authored by tbrehm's avatar tbrehm

Implemented: FS#1251 - Add option to software installer to create databases

Implemented: FS#1252 - Add permission system based on user / password to app installer 
parent dfd031ab
......@@ -745,6 +745,10 @@ CREATE TABLE `software_package` (
`package_description` text,
`package_version` varchar(8) default NULL,
`package_type` enum('ispconfig','app','web') NOT NULL default 'app',
`package_installable` enum('yes','no','key') NOT NULL default 'yes',
`package_requires_db` enum('no','mysql') NOT NULL default 'no',
`package_key` varchar(255) NOT NULL,
`package_config` text,
PRIMARY KEY (`package_id`),
UNIQUE KEY `package_name` (`package_name`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
......
<?php
$wb["repo_name_txt"] = 'Repository';
$wb["repo_url_txt"] = 'URL';
$wb["repo_username_txt"] = 'User (optional)';
$wb["repo_password_txt"] = 'Password (optional)';
$wb["active_txt"] = 'Active';
?>
\ No newline at end of file
<?php
$wb["head_txt"] = 'Install software package';
$wb["install_key_txt"] = 'Enter install key';
$wb["btn_save_txt"] = 'Start Installation';
$wb["btn_cancel_txt"] = 'Cancel';
?>
\ No newline at end of file
......@@ -4,4 +4,6 @@ $wb['installed_txt'] = 'Status';
$wb['package_title_txt'] = 'Package';
$wb['package_description_txt'] = 'Description';
$wb['action_txt'] = 'Action';
$wb['toolsarea_head_txt'] = 'Packages';
$wb['repoupdate_txt'] = 'Update package list';
?>
<?php
/*
Copyright (c) 2010, Till Brehm, projektfarm Gmbh
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of ISPConfig nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
require_once('../../lib/config.inc.php');
require_once('../../lib/app.inc.php');
//* Check permissions for module
$app->auth->check_module_permissions('admin');
//* This is only allowed for administrators
if(!$app->auth->is_admin()) die('only allowed for administrators.');
$package_name = $app->db->quote($_REQUEST['package']);
$install_server_id = intval($_REQUEST['server_id']);
$install_key = $app->db->quote(trim($_REQUEST['install_key']));
$package = $app->db->queryOneRecord("SELECT * FROM software_package WHERE package_name = '$package_name'");
$install_key_verified = false;
$message_err = '';
$message_ok = '';
//* verify the key
if($package['package_installable'] == 'key' && $install_key != '') {
$repo = $app->db->queryOneRecord("SELECT * FROM software_repo WHERE software_repo_id = ".$package['software_repo_id']);
$client = new SoapClient(null, array('location' => $repo['repo_url'],
'uri' => $repo['repo_url']));
$install_key_verified = $client->check_installable($package_name, $install_key, $repo['repo_username'], $repo['repo_password']);
if($install_key_verified == false) {
//$install_key = '';
$message_err = 'Verification of the key failed.';
} else {
// Store the verified key into the database
$app->db->datalogUpdate('software_package', "package_key = '$install_key'", 'package_id',$package['package_id']);
}
} else {
$message_ok = 'Please enter the software key for the package.';
}
//* Install packages, if all requirements are fullfilled.
if($install_server_id > 0 && $package_name != '' && ($package['package_installable'] == 'yes' || $install_key_verified == true)) {
$sql = "SELECT software_update_id, package_name, update_title FROM software_update WHERE type = 'full' AND package_name = '$package_name' ORDER BY v1 DESC, v2 DESC, v3 DESC, v4 DESC LIMIT 0,1";
$tmp = $app->db->queryOneRecord($sql);
$software_update_id = $tmp['software_update_id'];
//* if package requires a DB and there is no data for a db in config, then we create this data now
if($package['package_requires_db'] == 'mysql') {
$app->uses('ini_parser,getconf');
$package_config_array = array();
if(trim($package['package_config']) != '') {
$package_config_array = $app->ini_parser->parse_ini_string(stripslashes($package['package_config']));
}
if(!isset($package_config_array['mysql'])) {
$package_config_array['mysql'] = array( 'database_name' => 'ispapp'.$package['package_id'],
'database_user' => 'ispapp'.$package['package_id'],
'database_password' => md5(mt_rand()),
'database_host' => 'localhost');
$package_config_str = $app->ini_parser->get_ini_string($package_config_array);
$app->db->datalogUpdate('software_package', "package_config = '".$app->db->quote($package_config_str)."'", 'package_id',$package['package_id']);
}
}
//* Add the record to start the install process
$insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$install_server_id', '$software_update_id','installing')";
$app->db->datalogInsert('software_update_inst', $insert_data, 'software_update_inst_id');
$message_ok = 'Starting package installation '."<a href=\"#\" onClick=\"submitForm('pageForm','admin/software_package_list.php');\">".$app->lng('next')."</a>";
}
if(count($_POST) > 2 && $install_key == '') {
$message_ok = 'Please enter the software key.';
}
//* Show key input form
if($package['package_installable'] == 'key' && !$install_key_verified) {
$insert_key = true;
} else {
$insert_key = false;
}
// Loading the template
$app->uses('tpl');
$app->tpl->newTemplate("form.tpl.htm");
$app->tpl->setInclude('content_tpl','templates/software_package_install.htm');
$app->tpl->setVar('message_ok',$message_ok);
$app->tpl->setVar('message_err',$message_err);
$app->tpl->setVar('insert_key',$insert_key);
$app->tpl->setVar('install_key',$install_key);
$app->tpl->setVar('package_name',$package_name);
$app->tpl->setVar('server_id',$install_server_id);
include_once('lib/lang/en_software_package_install.lng');
$app->tpl->setVar($wb);
$app->tpl_defaults();
$app->tpl->pparse();
?>
......@@ -40,7 +40,7 @@ if(!$app->auth->is_admin()) die('only allowed for administrators.');
//* Get the latest packages from the repositorys and insert them in the local database
$packages_added = 0;
$repos = $app->db->queryAllRecords("SELECT software_repo_id, repo_url, repo_username, repo_password FROM software_repo WHERE active = 'y'");
if(is_array($repos)) {
if(is_array($repos) && isset($_GET['action']) && $_GET['action'] == 'repoupdate' ) {
foreach($repos as $repo) {
$client = new SoapClient(null, array('location' => $repo['repo_url'],
'uri' => $repo['repo_url']));
......@@ -50,16 +50,26 @@ if(is_array($repos)) {
foreach($packages as $p) {
$package_name = $app->db->quote($p['name']);
$tmp = $app->db->queryOneRecord("SELECT package_id FROM software_package WHERE package_name = '$package_name'");
$package_title = $app->db->quote($p['title']);
$package_description = $app->db->quote($p['description']);
$software_repo_id = intval($repo['software_repo_id']);
$package_type = $app->db->quote($p['type']);
$package_installable = $app->db->quote($p['installable']);
$package_requires_db = $app->db->quote($p['requires_db']);
if(empty($tmp['package_id'])) {
$package_title = $app->db->quote($p['title']);
$package_description = $app->db->quote($p['description']);
$software_repo_id = intval($repo['software_repo_id']);
$package_type = $app->db->quote($p['type']);
$sql = "INSERT INTO software_package (software_repo_id, package_name, package_title, package_description,package_type) VALUES ($software_repo_id, '$package_name', '$package_title', '$package_description','$package_type')";
$app->db->query($sql);
//$sql = "INSERT INTO software_package (software_repo_id, package_name, package_title, package_description,package_type,package_installable,package_requires_db) VALUES ($software_repo_id, '$package_name', '$package_title', '$package_description','$package_type','$package_installable','$package_requires_db')";
//$app->db->query($sql);
$insert_data = "(software_repo_id, package_name, package_title, package_description,package_type,package_installable,package_requires_db) VALUES ($software_repo_id, '$package_name', '$package_title', '$package_description','$package_type','$package_installable','$package_requires_db')";
$app->db->datalogInsert('software_package', $insert_data, 'package_id');
$packages_added++;
} else {
//$sql = "UPDATE software_package SET software_repo_id = $software_repo_id, package_title = '$package_title', package_description = '$package_description', package_type = '$package_type', package_installable = '$package_installable', package_requires_db = '$package_requires_db' WHERE package_name = '$package_name'";
//$app->db->query($sql);
$update_data = "software_repo_id = $software_repo_id, package_title = '$package_title', package_description = '$package_description', package_type = '$package_type', package_installable = '$package_installable', package_requires_db = '$package_requires_db'";
//echo $update_data;
$app->db->datalogUpdate('software_package', $update_data, 'package_id',$tmp['package_id']);
}
}
}
......@@ -93,10 +103,13 @@ if(is_array($repos)) {
$tmp = $app->db->queryOneRecord($sql);
if(!isset($tmp['software_update_id'])) {
// Insert the update in the datbase
$sql = "INSERT INTO software_update (software_repo_id, package_name, update_url, update_md5, update_dependencies, update_title, v1, v2, v3, v4, type)
VALUES ($software_repo_id, '$package_name', '$update_url', '$update_md5', '$update_dependencies', '$update_title', '$v1', '$v2', '$v3', '$v4', '$type')";
//$sql = "INSERT INTO software_update (software_repo_id, package_name, update_url, update_md5, update_dependencies, update_title, v1, v2, v3, v4, type)
//VALUES ($software_repo_id, '$package_name', '$update_url', '$update_md5', '$update_dependencies', '$update_title', '$v1', '$v2', '$v3', '$v4', '$type')";
//die($sql);
$app->db->query($sql);
//$app->db->query($sql);
$insert_data = "(software_repo_id, package_name, update_url, update_md5, update_dependencies, update_title, v1, v2, v3, v4, type)
VALUES ($software_repo_id, '$package_name', '$update_url', '$update_md5', '$update_dependencies', '$update_title', '$v1', '$v2', '$v3', '$v4', '$type')";
$app->db->datalogInsert('software_update', $insert_data, 'software_update_id');
}
}
......@@ -107,6 +120,7 @@ if(is_array($repos)) {
}
//* Install packages, if GET Request
/*
if(isset($_GET['action']) && $_GET['action'] == 'install' && $_GET['package'] != '' && $_GET['server_id'] > 0) {
$package_name = $app->db->quote($_GET['package']);
$server_id = intval($_GET['server_id']);
......@@ -117,8 +131,8 @@ if(isset($_GET['action']) && $_GET['action'] == 'install' && $_GET['package'] !=
$insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$server_id', '$software_update_id','installing')";
// $insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$server_id', '$software_update_id','installed')";
$app->db->datalogInsert('software_update_inst', $insert_data, 'software_update_inst_id');
}
*/
......@@ -139,15 +153,19 @@ if(is_array($packages)) {
$version = $inst['v1'].'.'.$inst['v2'].'.'.$inst['v3'].'.'.$inst['v4'];
if($inst['status'] == 'installed') {
$installed_txt .= $s['server_name'].": Installed version $version<br />";
$installed_txt .= $s['server_name'].": ".$app->lng("Installed version $version")."<br />";
} elseif ($inst['status'] == 'installing') {
$installed_txt .= $s['server_name'].": Installation in progress<br />";
$installed_txt .= $s['server_name'].": ".$app->lng("Installation in progress")."<br />";
} elseif ($inst['status'] == 'failed') {
$installed_txt .= $s['server_name'].": Installation failed<br />";
$installed_txt .= $s['server_name'].": ".$app->lng("Installation failed")."<br />";
} elseif ($inst['status'] == 'deleting') {
$installed_txt .= $s['server_name'].": Deletion in progress<br />";
$installed_txt .= $s['server_name'].": ".$app->lng("Deletion in progress")."<br />";
} else {
$installed_txt .= $s['server_name'].": <a href=\"#\" onClick=\"loadContent('admin/software_package_list.php?action=install&package=".$p["package_name"]."&server_id=".$s["server_id"]."');\">Install now</a><br />";
if($p['package_installable'] == 'no') {
$installed_txt .= $s['server_name'].": ".$app->lng("Package can not be installed.")."<br />";
} else {
$installed_txt .= $s['server_name'].": <a href=\"#\" onClick=\"loadContent('admin/software_package_install.php?package=".$p["package_name"]."&server_id=".$s["server_id"]."');\">Install now</a><br />";
}
}
}
$packages[$key]['installed'] = $installed_txt;
......
......@@ -16,7 +16,7 @@
<input name="lng_new" id="lng_new" value="" size="30" maxlength="255" type="text" class="textInput formLengthHalf" />
<p class="formHint">{tmpl_var name='language_new_hint_txt'}</p>
</div>
</fieldset>
<input type="hidden" name="id" value="{tmpl_var name='id'}">
......@@ -24,6 +24,9 @@
<button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/language_add.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
<button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/language_list.php');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
</div>
</fieldset>
</div>
</div>
......@@ -18,12 +18,15 @@
{tmpl_var name='language_option'}
</select>
</div>
</fieldset>
<div class="buttonHolder buttons" style="margin-top: -100px;">
<div class="buttonHolder buttons">
<button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/language_complete.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
<button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/language_list.php');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
</div>
</fieldset>
</div>
</div>
......@@ -24,6 +24,9 @@
<button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/language_edit.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
<button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/language_list.php?lng_select={tmpl_var name='lang'}');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
</div>
</div>
</div>
......@@ -11,7 +11,7 @@
{tmpl_var name='language_option'}
</select>
</div>
</fieldset>
<tmpl_if name="msg">
<div id="OKMsg"><p><tmpl_var name="msg"></p></div>
......@@ -23,6 +23,9 @@
<button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/language_export.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
<button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/language_list.php');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
</div>
</fieldset>
</div>
</div>
......@@ -21,7 +21,7 @@
<input id="ignore_version" type="checkbox" value="1" name="ignore_version"/>
</div>
</div>
</fieldset>
<tmpl_if name="msg">
<div id="OKMsg"><p><tmpl_var name="msg"></p></div>
......@@ -36,6 +36,9 @@
<button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitUploadForm('pageForm','admin/language_import.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
<button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/language_list.php');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
</div>
</fieldset>
</div>
</div>
<h2><tmpl_var name="head_txt"></h2>
<p><tmpl_var name="desc_txt"></p>
<div class="panel panel_software_repo">
<tmpl_if name="message_err">
<div id="errorMsg"><tmpl_var name="message_err"></div>
</tmpl_if>
<tmpl_if name="message_ok">
<div id="OKMsg"><tmpl_var name="message_ok"></div>
</tmpl_if>
<tmpl_if name="insert_key">
<div class="pnl_formsarea">
<fieldset class="inlineLabels">
<p>&nbsp;</p>
<div class="ctrlHolder">
<label for="install_key">{tmpl_var name='install_key_txt'}</label>
<input name="install_key" id="install_key" value="{tmpl_var name='install_key'}" size="40" maxlength="40" type="text" class="textInput" />
</div>
<input type="hidden" name="package" value="{tmpl_var name='package_name'}">
<input type="hidden" name="server_id" value="{tmpl_var name='server_id'}">
<p>&nbsp;</p>
<div class="buttonHolder buttons">
<button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/software_package_install.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
<button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/software_package_list.php');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
</div>
</fieldset>
</div>
</tmpl_if>
</div>
\ No newline at end of file
......@@ -3,6 +3,16 @@
<div class="panel panel_list_package">
<div class="pnl_toolsarea">
<fieldset><legend>{tmpl_var name="toolsarea_head_txt"}</legend>
<div class="buttons">
<button class="iconstxt icoAdd" type="button" onClick="loadContent('admin/software_package_list.php?action=repoupdate');">
<span>{tmpl_var name="repoupdate_txt"}</span>
</button>
</div>
</fieldset>
</div>
<div class="pnl_listarea">
<fieldset><legend><tmpl_var name="list_head_txt"></legend>
<table class="list">
......
......@@ -7,7 +7,7 @@
<fieldset class="inlineLabels"><legend>Tools</legend>
<div class="buttons">
<div class="ctrlHolder">
<label for="server_id">{tmpl_var name='server_select_txt'}</label>
<label for="server_id">{tmpl_var name='server_select_txt'}</label>
<select name="server_id" id="server_id" class="selectInput" onChange="submitForm('pageForm','admin/software_update_list.php');">
<tmpl_loop name="servers">
<option value="{tmpl_var name='server_id'}" {tmpl_var name='selected'}>{tmpl_var name='server_name'}</option>
......
......@@ -105,6 +105,10 @@ class software_update_plugin {
return false;
}
//* Replace placeholders in download URL
$software_update["update_url"] = str_replace('{key}',$software_package['package_key'],$software_update["update_url"]);
//* Download the update package
$cmd = "cd $temp_dir && wget ".$software_update["update_url"];
if($installuser == '') {
exec($cmd);
......@@ -113,8 +117,28 @@ class software_update_plugin {
}
$app->log("Downloading the update file from: ".$software_update["update_url"],LOGLEVEL_DEBUG);
$url_parts = parse_url($software_update["update_url"]);
$update_filename = basename($url_parts["path"]);
//$url_parts = parse_url($software_update["update_url"]);
//$update_filename = basename($url_parts["path"]);
//* Find the name of the zip file which contains the app.
$tmp_dir_handle = dir($temp_dir);
$update_filename = '';
while (false !== ($t = $tmp_dir_handle->read())) {
if($t != '.' && $t != '..' && is_file($temp_dir.'/'.$t) && substr($t,-4) == '.zip') {
$update_filename = $t;
}
}
$tmp_dir_handle->close();
unset($tmp_dir_handle);
unset($t);
if($update_filename == '') {
$app->log("No package file found. Download failed? Installation aborted.",LOGLEVEL_WARN);
exec("rm -rf $temp_dir");
$app->log("Deleting the temp directory $temp_dir",LOGLEVEL_DEBUG);
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
return false;
}
$app->log("The update filename is $update_filename",LOGLEVEL_DEBUG);
if(is_file($temp_dir.'/'.$update_filename)) {
......@@ -139,6 +163,35 @@ class software_update_plugin {
exec("su -c ".escapeshellarg($cmd)." $installuser");
}
//* Create a database, if the package requires one
if($software_package['package_type'] == 'app' && $software_package['package_requires_db'] == 'mysql') {
$app->uses('ini_parser');
$package_config = $app->ini_parser->parse_ini_string(stripslashes($software_package['package_config']));
$this->create_app_db($package_config['mysql']);
$app->log("Creating the app DB.",LOGLEVEL_DEBUG);
//* Load the sql dump into the database
if(is_file($temp_dir.'/setup.sql')) {
$db_config = $package_config['mysql'];
if( $db_config['database_user'] != '' &&
$db_config['database_password'] != '' &&
$db_config['database_name'] != '' &&
$db_config['database_host'] != '') {
system("mysql --default-character-set=utf8 --force -h '".$db_config['database_host']."' -u '".$db_config['database_user']."' ".$db_config['database_name']." < ".escapeshellcmd($temp_dir.'/setup.sql'));
$app->log("Loading setup.sql dump into the app db.",LOGLEVEL_DEBUG);
}
}
}
//* Save the package config file as app.ini
if($software_package['package_config'] != '') {
file_put_contents($temp_dir.'/app.ini',$software_package['package_config']);
$app->log("Writing ".$temp_dir.'/app.ini',LOGLEVEL_DEBUG);
}
if(is_file($temp_dir.'/setup.sh')) {
// Execute the setup script
exec('chmod +x '.$temp_dir.'/setup.sh');
......@@ -168,10 +221,56 @@ class software_update_plugin {
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
}
exec("rm -rf $temp_dir");
if($temp_dir != '' && $temp_dir != '/') exec("rm -rf $temp_dir");
$app->log("Deleting the temp directory $temp_dir",LOGLEVEL_DEBUG);
}
private function create_app_db($db_config) {
global $app, $conf;
if( $db_config['database_user'] != '' &&
$db_config['database_password'] != '' &&
$db_config['database_name'] != '' &&
$db_config['database_host'] != '') {
if(!include(ISPC_LIB_PATH.'/mysql_clientdb.conf')) {
$app->log('Unable to open'.ISPC_LIB_PATH.'/mysql_clientdb.conf',LOGLEVEL_ERROR);
return;
}
if($db_config['database_user'] == 'root') {
$app->log('User root not allowed for App databases',LOGLEVEL_WARNING);
return;
}
//* Connect to the database
$link = mysql_connect($clientdb_host, $clientdb_user, $clientdb_password);
if (!$link) {
$app->log('Unable to connect to the database'.mysql_error($link),LOGLEVEL_ERROR);
return;
}
$query_charset_table = '';
//* Create the new database
if (mysql_query('CREATE DATABASE '.mysql_real_escape_string($db_config['database_name']).$query_charset_table,$link)) {
$app->log('Created MySQL database: '.$db_config['database_name'],LOGLEVEL_DEBUG);
} else {
$app->log('Unable to connect to the database'.mysql_error($link),LOGLEVEL_ERROR);
}
if(mysql_query("GRANT ALL ON ".mysql_real_escape_string($db_config['database_name'],$link).".* TO '".mysql_real_escape_string($db_config['database_user'],$link)."'@'".$db_config['database_host']."' IDENTIFIED BY '".mysql_real_escape_string($db_config['database_password'],$link)."';",$link)) {
$app->log('Created MySQL user: '.$db_config['database_user'],LOGLEVEL_DEBUG);
} else {
$app->log('Unable to create database user'.$db_config['database_user'].' '.mysql_error($link),LOGLEVEL_ERROR);
}
mysql_query("FLUSH PRIVILEGES;",$link);
mysql_close($link);
}
}
} // end class
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment