Skip to content

Commit 1e0af88

Browse files
authored
fix mysql username rename (hestiacp#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.
1 parent 254007e commit 1e0af88

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

web/edit/db/index.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,16 @@
5050

5151
// Change database user
5252
if (($v_dbuser != $_POST['v_dbuser']) && (empty($_SESSION['error_msg']))) {
53-
$v_dbuser = escapeshellarg($v_dbuser);
54-
exec(HESTIA_CMD."v-change-database-user ".$user." ".escapeshellarg($v_database)." ".$v_dbuser, $output, $return_var);
53+
$cmd = implode(" ", array(
54+
HESTIA_CMD . "v-change-database-user",
55+
// $user is already shell-quoted
56+
$user,
57+
escapeshellarg($v_database),
58+
escapeshellarg($_POST['v_dbuser']),
59+
));
60+
exec($cmd, $output, $return_var);
5561
check_return_code($return_var, $output);
5662
unset($output);
57-
$v_dbuser = $_POST['v_dbuser'];
5863
}
5964

6065
// Change database password
@@ -78,6 +83,11 @@
7883
if (empty($_SESSION['error_msg'])) {
7984
$_SESSION['ok_msg'] = _('Changes has been saved.');
8085
}
86+
// if the mysql username was changed, render_page() below will render with the OLD mysql username,
87+
// to prvent that, make the browser refresh the page.
88+
http_response_code(303);
89+
header("Location: " . $_SERVER['REQUEST_URI']);
90+
die();
8191
}
8292

8393
// Render page

0 commit comments

Comments
 (0)