index.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. // Init
  3. error_reporting(null);
  4. ob_start();
  5. $TAB = 'DB';
  6. // Main include
  7. include($_SERVER['DOCUMENT_ROOT'].'/inc/main.php');
  8. // Check database id
  9. if (empty($_GET['database'])) {
  10. header("Location: /list/db/");
  11. exit;
  12. }
  13. // Edit as someone else?
  14. if (($_SESSION['userContext'] === 'admin') && (!empty($_GET['user']))) {
  15. $user=escapeshellarg($_GET['user']);
  16. }
  17. // List datbase
  18. $v_database = $_GET['database'];
  19. exec(HESTIA_CMD."v-list-database ".$user." ".escapeshellarg($v_database)." 'json'", $output, $return_var);
  20. check_return_code($return_var, $output);
  21. $data = json_decode(implode('', $output), true);
  22. unset($output);
  23. // Parse database
  24. $v_username = $user;
  25. $v_dbuser = preg_replace("/^".$user."_/", "", $data[$v_database]['DBUSER']);
  26. $v_password = "";
  27. $v_host = $data[$v_database]['HOST'];
  28. $v_type = $data[$v_database]['TYPE'];
  29. $v_charset = $data[$v_database]['CHARSET'];
  30. $v_date = $data[$v_database]['DATE'];
  31. $v_time = $data[$v_database]['TIME'];
  32. $v_suspended = $data[$v_database]['SUSPENDED'];
  33. if ($v_suspended == 'yes') {
  34. $v_status = 'suspended';
  35. } else {
  36. $v_status = 'active';
  37. }
  38. // Check POST request
  39. if (!empty($_POST['save'])) {
  40. $v_username = $user;
  41. // Check token
  42. verify_csrf($_POST);
  43. // Change database user
  44. if (($v_dbuser != $_POST['v_dbuser']) && (empty($_SESSION['error_msg']))) {
  45. $v_dbuser = escapeshellarg($v_dbuser);
  46. exec(HESTIA_CMD."v-change-database-user ".$v_username." ".escapeshellarg($v_database)." ".$v_dbuser, $output, $return_var);
  47. check_return_code($return_var, $output);
  48. unset($output);
  49. $v_dbuser = $user."_".preg_replace("/^".$user."_/", "", $_POST['v_dbuser']);
  50. }
  51. // Change database password
  52. if ((!empty($_POST['v_password'])) && (empty($_SESSION['error_msg']))) {
  53. if (!validate_password($_POST['v_password'])) {
  54. $_SESSION['error_msg'] = _('Password does not match the minimum requirements');
  55. } else {
  56. $v_password = tempnam("/tmp", "vst");
  57. $fp = fopen($v_password, "w");
  58. fwrite($fp, $_POST['v_password']."\n");
  59. fclose($fp);
  60. exec(HESTIA_CMD."v-change-database-password ".$v_username." ".escapeshellarg($v_database)." ".$v_password, $output, $return_var);
  61. check_return_code($return_var, $output);
  62. unset($output);
  63. unlink($v_password);
  64. $v_password = escapeshellarg($_POST['v_password']);
  65. }
  66. }
  67. // Set success message
  68. if (empty($_SESSION['error_msg'])) {
  69. $_SESSION['ok_msg'] = _('Changes has been saved.');
  70. }
  71. }
  72. // Render page
  73. render_page($user, $TAB, 'edit_db');
  74. // Flush session messages
  75. unset($_SESSION['error_msg']);
  76. unset($_SESSION['ok_msg']);