Просмотр исходного кода

fix mysql username rename (#2775)

* fix mysql username rename

there was actually 2 bugs here:

1: the 3rd argument to v-change-database-user mixed the old name with the new name, so the command became "rename old_name to old_name", which broke mysql username rename completely.

2: even if the username rename worked (which it didn't), render_page() would still render with the old mysql username, not the new one. fixed that by forcing a page GET reload after changing username.
divinity76 3 лет назад
Родитель
Сommit
1e0af88361
1 измененных файлов с 13 добавлено и 3 удалено
  1. 13 3
      web/edit/db/index.php

+ 13 - 3
web/edit/db/index.php

@@ -50,11 +50,16 @@ if (!empty($_POST['save'])) {
 
 
     // Change database user
     // Change database user
     if (($v_dbuser != $_POST['v_dbuser']) && (empty($_SESSION['error_msg']))) {
     if (($v_dbuser != $_POST['v_dbuser']) && (empty($_SESSION['error_msg']))) {
-        $v_dbuser = escapeshellarg($v_dbuser);
-        exec(HESTIA_CMD."v-change-database-user ".$user." ".escapeshellarg($v_database)." ".$v_dbuser, $output, $return_var);
+        $cmd = implode(" ", array(
+            HESTIA_CMD . "v-change-database-user",
+            // $user is already shell-quoted
+            $user,
+            escapeshellarg($v_database),
+            escapeshellarg($_POST['v_dbuser']),
+        ));
+        exec($cmd, $output, $return_var);
         check_return_code($return_var, $output);
         check_return_code($return_var, $output);
         unset($output);
         unset($output);
-        $v_dbuser = $_POST['v_dbuser'];
     }
     }
 
 
     // Change database password
     // Change database password
@@ -78,6 +83,11 @@ if (!empty($_POST['save'])) {
     if (empty($_SESSION['error_msg'])) {
     if (empty($_SESSION['error_msg'])) {
         $_SESSION['ok_msg'] = _('Changes has been saved.');
         $_SESSION['ok_msg'] = _('Changes has been saved.');
     }
     }
+    // if the mysql username was changed, render_page() below will render with the OLD mysql username,
+    // to prvent that, make the browser refresh the page.
+    http_response_code(303);
+    header("Location: " . $_SERVER['REQUEST_URI']);
+    die();
 }
 }
 
 
 // Render page
 // Render page