diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 925a2ba8486393bce73efc1354466166334dbed9..87c07515198f7a0aee2c13c15cd2c4a36aaee7f6 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -711,6 +711,10 @@ class installer_base { //* make sure that the server config file (not the interface one) is only readable by the root user exec("chmod 600 $install_dir/server/lib/$configfile"); exec("chown root:root $install_dir/server/lib/$configfile"); + if(@is_file("$install_dir/server/lib/mysql_clientdb.conf") { + exec("chmod 600 $install_dir/server/lib/mysql_clientdb.conf"); + exec("chown root:root $install_dir/server/lib/mysql_clientdb.conf"); + } // TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing // and must be fixed as this will allow the apache user to read the ispconfig files. diff --git a/server/mods-available/database_module.inc.php b/server/mods-available/database_module.inc.php index 40ff6803f16eb23ec9c230d680b1fb4f24bddefa..740e8f8cfdf701a9c1c953a86ed0a8f569ec6326 100644 --- a/server/mods-available/database_module.inc.php +++ b/server/mods-available/database_module.inc.php @@ -61,7 +61,7 @@ class database_module { class that contains the function functionname. */ - $app->modules->registerTableHook('web_database','server_module','process'); + $app->modules->registerTableHook('web_database','database_module','process'); // Register service //$app->services->registerService('httpd','web_module','restartHttpd'); diff --git a/server/plugins-available/mysql_clientdb_plugin.inc.php b/server/plugins-available/mysql_clientdb_plugin.inc.php index bf535995f0b7e2aca8bcd495e29f7721489c7fb4..77112361431d7ef2de231b0c94a6a1ea9235fb6f 100644 --- a/server/plugins-available/mysql_clientdb_plugin.inc.php +++ b/server/plugins-available/mysql_clientdb_plugin.inc.php @@ -28,10 +28,10 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -class mysql_clientdb { +class mysql_clientdb_plugin { - var $plugin_name = 'mysql_clientdb'; - var $class_name = 'mysql_clientdb'; + var $plugin_name = 'mysql_clientdb_plugin'; + var $class_name = 'mysql_clientdb_plugin'; /* @@ -66,10 +66,11 @@ class mysql_clientdb { $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; } //* Create the new database - if (mysql_create_db($data["new"]["database_name"]),$link) { + if (mysql_query('CREATE DATABASE '.addslashes($data["new"]["database_name"]),$link)) { $app->log('Created MySQL database: '.$data["new"]["database_name"],LOGLEVEL_DEBUG); } else { $app->log('Unable to connect to the database'.mysql_error($link),LOGLEVEL_ERROR); @@ -82,7 +83,8 @@ class mysql_clientdb { $db_host = 'localhost'; } - mysql_query("GRANT ALL ON ".addslashes($data["new"]["database_name"])." TO '".addslashes($data["new"]["database_user"])."'@'$db_host' IDENTIFIED BY '".addslashes($data["new"]["database_password"])."';",$link); + mysql_query("GRANT ALL ON ".addslashes($data["new"]["database_name"]).".* TO '".addslashes($data["new"]["database_user"])."'@'$db_host' IDENTIFIED BY '".addslashes($data["new"]["database_password"])."';",$link); + //echo "GRANT ALL ON ".addslashes($data["new"]["database_name"]).".* TO '".addslashes($data["new"]["database_user"])."'@'$db_host' IDENTIFIED BY '".addslashes($data["new"]["database_password"])."';"; mysql_query("FLUSH PRIVILEGES;",$link); mysql_close($link); @@ -95,6 +97,7 @@ class mysql_clientdb { if($data["new"]["type"] == 'mysql') { if(!include_once(ISPC_LIB_PATH.'/mysql_clientdb.conf')) { $app->log('Unable to open'.ISPC_LIB_PATH.'/mysql_clientdb.conf',LOGLEVEL_ERROR); + return; } //* Connect to the database @@ -113,8 +116,10 @@ class mysql_clientdb { if($data["new"]["remote_access"] != $data["old"]["remote_access"]) { if($data["new"]["remote_access"] == 'y') { mysql_query("UPDATE mysql.user SET Host = '%' WHERE User = '".addslashes($data["new"]["database_user"])."' and Host = 'localhost';",$link); + mysql_query("UPDATE mysql.db SET Host = '%' WHERE User = '".addslashes($data["new"]["database_user"])."' and Host = 'localhost';",$link); } else { mysql_query("UPDATE mysql.user SET Host = 'localhost' WHERE User = '".addslashes($data["new"]["database_user"])."' and Host = '%';",$link); + mysql_query("UPDATE mysql.db SET Host = 'localhost' WHERE User = '".addslashes($data["new"]["database_user"])."' and Host = '%';",$link); } $app->log('Changing mysql remote access priveliges for database: '.$data["new"]["database_name"],LOGLEVEL_DEBUG); } @@ -148,9 +153,10 @@ class mysql_clientdb { function db_delete($event_name,$data) { global $app, $conf; - if($data["new"]["type"] == 'mysql') { + if($data["old"]["type"] == 'mysql') { if(!include_once(ISPC_LIB_PATH.'/mysql_clientdb.conf')) { $app->log('Unable to open'.ISPC_LIB_PATH.'/mysql_clientdb.conf',LOGLEVEL_ERROR); + return; } //* Connect to the database @@ -159,10 +165,17 @@ class mysql_clientdb { $app->log('Unable to connect to the database'.mysql_error($link),LOGLEVEL_ERROR); } - mysql_query("DROP USER '".addslashes($data["old"]["database_user"])."';",$link); + //* Get the db host setting for the access priveliges + if($data["old"]["remote_access"] == 'y') { + $db_host = '%'; + } else { + $db_host = 'localhost'; + } + + mysql_query("DROP USER '".addslashes($data["old"]["database_user"])."'@'$db_host';",$link); $app->log('Dropping mysql user: '.$data["old"]["database_user"],LOGLEVEL_DEBUG); - mysql_drop_db($data["old"]["database_name"],$link); + mysql_query('DROP DATABASE '.addslashes($data["old"]["database_name"]),$link); $app->log('Dropping mysql database: '.$data["old"]["database_name"],LOGLEVEL_DEBUG);