Skip to content

Commit a613451

Browse files
committed
- Various bugfixes in client database files.
1 parent d83fcfe commit a613451

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

install/lib/installer_base.lib.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,10 @@ public function install_ispconfig()
711711
//* make sure that the server config file (not the interface one) is only readable by the root user
712712
exec("chmod 600 $install_dir/server/lib/$configfile");
713713
exec("chown root:root $install_dir/server/lib/$configfile");
714+
if(@is_file("$install_dir/server/lib/mysql_clientdb.conf") {
715+
exec("chmod 600 $install_dir/server/lib/mysql_clientdb.conf");
716+
exec("chown root:root $install_dir/server/lib/mysql_clientdb.conf");
717+
}
714718

715719
// TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing
716720
// and must be fixed as this will allow the apache user to read the ispconfig files.

server/mods-available/database_module.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function onLoad() {
6161
class that contains the function functionname.
6262
*/
6363

64-
$app->modules->registerTableHook('web_database','server_module','process');
64+
$app->modules->registerTableHook('web_database','database_module','process');
6565

6666
// Register service
6767
//$app->services->registerService('httpd','web_module','restartHttpd');

server/plugins-available/mysql_clientdb_plugin.inc.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*/
3030

31-
class mysql_clientdb {
31+
class mysql_clientdb_plugin {
3232

33-
var $plugin_name = 'mysql_clientdb';
34-
var $class_name = 'mysql_clientdb';
33+
var $plugin_name = 'mysql_clientdb_plugin';
34+
var $class_name = 'mysql_clientdb_plugin';
3535

3636

3737
/*
@@ -66,10 +66,11 @@ function db_insert($event_name,$data) {
6666
$link = mysql_connect($clientdb_host, $clientdb_user, $clientdb_password);
6767
if (!$link) {
6868
$app->log('Unable to connect to the database'.mysql_error($link),LOGLEVEL_ERROR);
69+
return;
6970
}
7071

7172
//* Create the new database
72-
if (mysql_create_db($data["new"]["database_name"]),$link) {
73+
if (mysql_query('CREATE DATABASE '.addslashes($data["new"]["database_name"]),$link)) {
7374
$app->log('Created MySQL database: '.$data["new"]["database_name"],LOGLEVEL_DEBUG);
7475
} else {
7576
$app->log('Unable to connect to the database'.mysql_error($link),LOGLEVEL_ERROR);
@@ -82,7 +83,8 @@ function db_insert($event_name,$data) {
8283
$db_host = 'localhost';
8384
}
8485

85-
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);
86+
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);
87+
//echo "GRANT ALL ON ".addslashes($data["new"]["database_name"]).".* TO '".addslashes($data["new"]["database_user"])."'@'$db_host' IDENTIFIED BY '".addslashes($data["new"]["database_password"])."';";
8688

8789
mysql_query("FLUSH PRIVILEGES;",$link);
8890
mysql_close($link);
@@ -95,6 +97,7 @@ function db_update($event_name,$data) {
9597
if($data["new"]["type"] == 'mysql') {
9698
if(!include_once(ISPC_LIB_PATH.'/mysql_clientdb.conf')) {
9799
$app->log('Unable to open'.ISPC_LIB_PATH.'/mysql_clientdb.conf',LOGLEVEL_ERROR);
100+
return;
98101
}
99102

100103
//* Connect to the database
@@ -113,8 +116,10 @@ function db_update($event_name,$data) {
113116
if($data["new"]["remote_access"] != $data["old"]["remote_access"]) {
114117
if($data["new"]["remote_access"] == 'y') {
115118
mysql_query("UPDATE mysql.user SET Host = '%' WHERE User = '".addslashes($data["new"]["database_user"])."' and Host = 'localhost';",$link);
119+
mysql_query("UPDATE mysql.db SET Host = '%' WHERE User = '".addslashes($data["new"]["database_user"])."' and Host = 'localhost';",$link);
116120
} else {
117121
mysql_query("UPDATE mysql.user SET Host = 'localhost' WHERE User = '".addslashes($data["new"]["database_user"])."' and Host = '%';",$link);
122+
mysql_query("UPDATE mysql.db SET Host = 'localhost' WHERE User = '".addslashes($data["new"]["database_user"])."' and Host = '%';",$link);
118123
}
119124
$app->log('Changing mysql remote access priveliges for database: '.$data["new"]["database_name"],LOGLEVEL_DEBUG);
120125
}
@@ -148,9 +153,10 @@ function db_update($event_name,$data) {
148153
function db_delete($event_name,$data) {
149154
global $app, $conf;
150155

151-
if($data["new"]["type"] == 'mysql') {
156+
if($data["old"]["type"] == 'mysql') {
152157
if(!include_once(ISPC_LIB_PATH.'/mysql_clientdb.conf')) {
153158
$app->log('Unable to open'.ISPC_LIB_PATH.'/mysql_clientdb.conf',LOGLEVEL_ERROR);
159+
return;
154160
}
155161

156162
//* Connect to the database
@@ -159,10 +165,17 @@ function db_delete($event_name,$data) {
159165
$app->log('Unable to connect to the database'.mysql_error($link),LOGLEVEL_ERROR);
160166
}
161167

162-
mysql_query("DROP USER '".addslashes($data["old"]["database_user"])."';",$link);
168+
//* Get the db host setting for the access priveliges
169+
if($data["old"]["remote_access"] == 'y') {
170+
$db_host = '%';
171+
} else {
172+
$db_host = 'localhost';
173+
}
174+
175+
mysql_query("DROP USER '".addslashes($data["old"]["database_user"])."'@'$db_host';",$link);
163176
$app->log('Dropping mysql user: '.$data["old"]["database_user"],LOGLEVEL_DEBUG);
164177

165-
mysql_drop_db($data["old"]["database_name"],$link);
178+
mysql_query('DROP DATABASE '.addslashes($data["old"]["database_name"]),$link);
166179
$app->log('Dropping mysql database: '.$data["old"]["database_name"],LOGLEVEL_DEBUG);
167180

168181

0 commit comments

Comments
 (0)