diff --git a/interface/lib/plugins/vm_openvz_plugin.inc.php b/interface/lib/plugins/vm_openvz_plugin.inc.php index 73cc9cda86fd3e2be17a351ccda7fff974e4cf08..9d54b6b1a92f4546dd0eb90e490f34d797718aaf 100644 --- a/interface/lib/plugins/vm_openvz_plugin.inc.php +++ b/interface/lib/plugins/vm_openvz_plugin.inc.php @@ -94,7 +94,10 @@ class vm_openvz_plugin { } // Set the IP address - if(isset($this->dataRecord['ip_address'])) $app->db->query("UPDATE openvz_ip SET vm_id = ? WHERE ip_address = ?", $this->id, $this->dataRecord['ip_address']); + if(isset($this->dataRecord['ip_address'])) { + $app->db->query("UPDATE openvz_ip SET vm_id = 0 WHERE vm_id = ?", $this->id); + $app->db->query("UPDATE openvz_ip SET vm_id = ? WHERE ip_address = ?", $this->id, $this->dataRecord['ip_address']); + } // Create the OpenVZ config file and store it in config field $this->makeOpenVZConfig(); diff --git a/interface/web/sites/database_edit.php b/interface/web/sites/database_edit.php index 2d051d118f445263f6dd7c805fe4b093124ffe50..e64a03f05aab34c393b73a244d1c9927e4c7f3fc 100644 --- a/interface/web/sites/database_edit.php +++ b/interface/web/sites/database_edit.php @@ -154,7 +154,8 @@ class page_action extends tform_actions { if($this->id > 0) { //* we are editing a existing record - $app->tpl->setVar("edit_disabled", 1); + $edit_disabled = @($_SESSION["s"]["user"]["typ"] == 'admin')? 0 : 1; //* admin can change the database-name + $app->tpl->setVar("edit_disabled", $edit_disabled); $app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]); $app->tpl->setVar("database_charset_value", $this->dataRecord["database_charset"]); $app->tpl->setVar("limit_database_quota", $this->dataRecord["database_quota"]); @@ -300,8 +301,11 @@ class page_action extends tform_actions { $dbname_prefix = $app->tools_sites->getPrefix($old_record['database_name_prefix'], $dbname_prefix); $this->dataRecord['database_name_prefix'] = $dbname_prefix; - if($old_record["database_name"] != $dbname_prefix . $this->dataRecord["database_name"]) { - $app->tform->errorMessage .= $app->tform->wordbook["database_name_change_txt"].'
'; + //* Only admin can change the database name + if ($_SESSION["s"]["user"]["typ"] != 'admin') { + if($old_record["database_name"] != $dbname_prefix . $this->dataRecord["database_name"]) { + $app->tform->errorMessage .= $app->tform->wordbook["database_name_change_txt"].'
'; + } } if($old_record["database_charset"] != $this->dataRecord["database_charset"]) { $app->tform->errorMessage .= $app->tform->wordbook["database_charset_change_txt"].'
'; diff --git a/server/lib/classes/modules.inc.php b/server/lib/classes/modules.inc.php index b909fbfe47c170cdd933a4c4a91b89f52ca6087a..aa95d473b23fd612cc2e4fe0b991e98f86fb305b 100644 --- a/server/lib/classes/modules.inc.php +++ b/server/lib/classes/modules.inc.php @@ -152,12 +152,14 @@ class modules { $app->db->errorNumber = 0; $app->db->errorMessage = ''; $app->db->query($sql, true, $params); - unset($params); if($app->db->errorNumber > 0) { $replication_error = true; $app->log("Replication failed. Error: (" . $d['dbtable'] . ") in MySQL server: (".$app->db->dbHost.") " . $app->db->errorMessage . " # SQL: " . $sql, LOGLEVEL_ERROR); } - $app->log('Replicated from master: '.$sql, LOGLEVEL_DEBUG); + $log = $app->db->_build_query_string($sql, true, $params); + $app->log('Replicated from master: '.$log, LOGLEVEL_DEBUG); + unset($params); + unset($log); } if($d['action'] == 'd') { @@ -169,7 +171,9 @@ class modules { $replication_error = true; $app->log("Replication failed. Error: (" . $d[dbtable] . ") " . $app->db->errorMessage . " # SQL: " . $sql, LOGLEVEL_ERROR); } - $app->log('Replicated from master: '.$sql, LOGLEVEL_DEBUG); + $log = $app->db->_build_query_string($sql, $d['dbtable'], $idx[0], $idx[1]); + $app->log('Replicated from master: '.$log, LOGLEVEL_DEBUG); + unset($log); } diff --git a/server/plugins-available/mysql_clientdb_plugin.inc.php b/server/plugins-available/mysql_clientdb_plugin.inc.php index bce409d1b443d37c1cbfa631e50a4ff17f86d393..2f2171f19b11294df77bf47d8b36f653c1495577 100644 --- a/server/plugins-available/mysql_clientdb_plugin.inc.php +++ b/server/plugins-available/mysql_clientdb_plugin.inc.php @@ -275,6 +275,123 @@ class mysql_clientdb_plugin { if($old_host_list != '') $old_host_list .= ','; $old_host_list .= 'localhost'; + //* rename database + if ( $data['new']['database_name'] != $data['old']['database_name'] ) { + $old_name = $link->escape_string($data['old']['database_name']); + $new_name = $link->escape_string($data['new']['database_name']); + $timestamp = time(); + + $tables = $link->query("SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema='".$old_name."' AND TABLE_TYPE='BASE TABLE'"); + if ($tables->num_rows > 0) { + while ($row = $tables->fetch_assoc()) { + $tables_array[] = $row['TABLE_NAME']; + } + + //* save triggers, routines and events + $triggers = $link->query("SHOW TRIGGERS FROM ".$old_name); + if ($triggers->num_rows > 0) { + while ($row = $triggers->fetch_assoc()) { + $triggers_array[] = $row; + } + $app->log('Dumping triggers from '.$old_name, LOGLEVEL_DEBUG); + $command = "mysqldump -h ".escapeshellarg($clientdb_host)." -u ".escapeshellarg($clientdb_user)." -p".escapeshellarg($clientdb_password)." ".$old_name." -d -t -R -E > ".$timestamp.$old_name.'.triggers'; + exec($command, $out, $ret); + $app->system->chmod($timestamp.$old_name.'.triggers', 0600); + if ($ret != 0) { + unset($triggers_array); + $app->system->unlink($timestamp.$old_name.'.triggers'); + $app->log('Unable to dump triggers from '.$old_name, LOGLEVEL_ERROR); + } + unset($out); + } + + //* save views + $views = $link->query("SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema='".$old_name."' and TABLE_TYPE='VIEW'"); + if ($views->num_rows > 0) { + while ($row = $views->fetch_assoc()) { + $views_array[] = $row; + } + foreach ($views_array as $_views) { + $temp[] = $_views['TABLE_NAME']; + } + $app->log('Dumping views from '.$old_name, LOGLEVEL_DEBUG); + $temp_views = implode(' ', $temp); + $command = "mysqldump -h ".escapeshellarg($clientdb_host)." -u ".escapeshellarg($clientdb_user)." -p".escapeshellarg($clientdb_password)." ".$old_name." ".$temp_views." > ".$timestamp.$old_name.'.views'; + exec($command, $out, $ret); + $app->system->chmod($timestamp.$old_name.'.views', 0600); + if ($ret != 0) { + unset($views_array); + $app->system->unlink($timestamp.$old_name.'.views'); + $app->log('Unable to dump views from '.$old_name, LOGLEVEL_ERROR); + } + unset($out); + unset($temp); + unset($temp_views); + } + + //* create new database + $this->db_insert($event_name, $data); + + $link->query("show databases like '".$new_name."'"); + if ($link) { + //* rename tables + foreach ($tables_array as $table) { + $table = $link->escape_string($table); + $sql = "RENAME TABLE ".$old_name.".".$table." TO ".$new_name.".".$table; + $link->query($sql); + $app->log($sql, LOGLEVEL_DEBUG); + if(!$link) { + $app->log($sql." failed", LOGLEVEL_ERROR); + } + } + + //* drop old triggers + if (@is_array($triggers_array)) { + foreach($triggers_array as $trigger) { + $_trigger = $link->escape_string($trigger['Trigger']); + $sql = "DROP TRIGGER ".$old_name.".".$_trigger; + $link->query($sql); + $app->log($sql, LOGLEVEL_DEBUG); + unset($_trigger); + } + //* update triggers, routines and events + $command = "mysql -h ".escapeshellarg($clientdb_host)." -u ".escapeshellarg($clientdb_user)." -p".escapeshellarg($clientdb_password)." ".$new_name." < ".$timestamp.$old_name.'.triggers'; + exec($command, $out, $ret); + if ($ret != 0) { + $app->log('Unable to import triggers for '.$new_name, LOGLEVEL_ERROR); + } else { + $app->system->unlink($timestamp.$old_name.'.triggers'); + } + } + + //* loading views + if (@is_array($views_array)) { + $command = "mysql -h ".escapeshellarg($clientdb_host)." -u ".escapeshellarg($clientdb_user)." -p".escapeshellarg($clientdb_password)." ".$new_name." < ".$timestamp.$old_name.'.views'; + exec($command, $out, $ret); + if ($ret != 0) { + $app->log('Unable to import views for '.$new_name, LOGLEVEL_ERROR); + } else { + $app->system->unlink($timestamp.$old_name.'.views'); + } + } + + //* drop old database + $this->db_delete($event_name, $data); + } else { + $app->log('Connection to new databse '.$new_name.' failed', LOGLEVEL_ERROR); + if (@is_array($triggers_array)) { + $app->system->unlink($timestamp.$old_name.'.triggers'); + } + if (@is_array($views_array)) { + $app->system->unlink($timestamp.$old_name.'.views'); + } + } + + } else { //* SELECT TABLE_NAME error + $app->log('Unable to rename database '.$old_name.' to '.$new_name, LOGLEVEL_ERROR); + } + } + // Create the database user if database was disabled before if($data['new']['active'] == 'y') { if($db_user) { @@ -299,6 +416,7 @@ class mysql_clientdb_plugin { //$this->process_host_list('DROP', $data['new']['database_name'], $db_user['database_user'], $db_user['database_password'], $old_host_list, $link); //$this->process_host_list('REVOKE', $data['new']['database_name'], $db_user['database_user'], $db_user['database_password'], $old_host_list, $link); } + } if($old_db_ro_user && $data['old']['database_user_id'] != $data['old']['database_ro_user_id']) { if($old_db_ro_user['database_user'] == 'root'){