index.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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['user'] == 'admin') && (!empty($_GET['user']))) {
  15. $user=escapeshellarg($_GET['user']);
  16. }
  17. // List datbase
  18. $v_database = escapeshellarg($_GET['database']);
  19. exec (VESTA_CMD."v-list-database ".$user." ".$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_database = $_GET['database'];
  26. $v_dbuser = $data[$v_database]['DBUSER'];
  27. $v_password = "";
  28. $v_host = $data[$v_database]['HOST'];
  29. $v_type = $data[$v_database]['TYPE'];
  30. $v_charset = $data[$v_database]['CHARSET'];
  31. $v_date = $data[$v_database]['DATE'];
  32. $v_time = $data[$v_database]['TIME'];
  33. $v_suspended = $data[$v_database]['SUSPENDED'];
  34. if ( $v_suspended == 'yes' ) {
  35. $v_status = 'suspended';
  36. } else {
  37. $v_status = 'active';
  38. }
  39. $v_database = escapeshellarg($_GET['database']);
  40. // Check POST request
  41. if (!empty($_POST['save'])) {
  42. $v_username = $user;
  43. // Check token
  44. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  45. header('location: /login/');
  46. exit();
  47. }
  48. // Change database user
  49. if (($v_dbuser != $_POST['v_dbuser']) && (empty($_SESSION['error_msg']))) {
  50. $v_dbuser = preg_replace("/^".$user."_/", "", $_POST['v_dbuser']);
  51. $v_dbuser = escapeshellarg($v_dbuser);
  52. exec (VESTA_CMD."v-change-database-user ".$v_username." ".$v_database." ".$v_dbuser, $output, $return_var);
  53. check_return_code($return_var,$output);
  54. unset($output);
  55. $v_dbuser = $user."_".preg_replace("/^".$user."_/", "", $_POST['v_dbuser']);
  56. }
  57. // Change database password
  58. if ((!empty($_POST['v_password'])) && (empty($_SESSION['error_msg']))) {
  59. $v_password = tempnam("/tmp","vst");
  60. $fp = fopen($v_password, "w");
  61. fwrite($fp, $_POST['v_password']."\n");
  62. fclose($fp);
  63. exec (VESTA_CMD."v-change-database-password ".$v_username." ".$v_database." ".$v_password, $output, $return_var);
  64. check_return_code($return_var,$output);
  65. unset($output);
  66. unlink($v_password);
  67. $v_password = escapeshellarg($_POST['v_password']);
  68. }
  69. // Set success message
  70. if (empty($_SESSION['error_msg'])) {
  71. $_SESSION['ok_msg'] = __('Changes has been saved.');
  72. }
  73. }
  74. // Render page
  75. render_page($user, $TAB, 'edit_db');
  76. // Flush session messages
  77. unset($_SESSION['error_msg']);
  78. unset($_SESSION['ok_msg']);