index.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. // Init
  3. error_reporting(NULL);
  4. ob_start();
  5. session_start();
  6. $TAB = 'DB';
  7. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  8. // Header
  9. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  10. // Panel
  11. top_panel($user,$TAB);
  12. // Are you admin?
  13. //if ($_SESSION['user'] == 'admin') {
  14. if (!empty($_POST['ok'])) {
  15. // Check input
  16. if (empty($_POST['v_database'])) $errors[] = 'database';
  17. if (empty($_POST['v_dbuser'])) $errors[] = 'username';
  18. if (empty($_POST['v_password'])) $errors[] = 'password';
  19. if (empty($_POST['v_type'])) $errors[] = 'type';
  20. if (empty($_POST['v_charset'])) $errors[] = 'charset';
  21. // Protect input
  22. $v_database = escapeshellarg($_POST['v_database']);
  23. $v_dbuser = escapeshellarg($_POST['v_dbuser']);
  24. $v_password = escapeshellarg($_POST['v_password']);
  25. $v_type = $_POST['v_type'];
  26. $v_charset = $_POST['v_charset'];
  27. // Check for errors
  28. if (!empty($errors[0])) {
  29. foreach ($errors as $i => $error) {
  30. if ( $i == 0 ) {
  31. $error_msg = $error;
  32. } else {
  33. $error_msg = $error_msg.", ".$error;
  34. }
  35. }
  36. $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
  37. } else {
  38. // Add Database
  39. $v_type = escapeshellarg($_POST['v_type']);
  40. $v_charset = escapeshellarg($_POST['v_charset']);
  41. exec (VESTA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." 'default' ".$v_charset, $output, $return_var);
  42. $v_type = $_POST['v_type'];
  43. $v_charset = $_POST['v_charset'];
  44. if ($return_var != 0) {
  45. $error = implode('<br>', $output);
  46. if (empty($error)) $error = 'Error: vesta did not return any output.';
  47. $_SESSION['error_msg'] = $error;
  48. unset($v_password);
  49. unset($output);
  50. } else {
  51. $_SESSION['ok_msg'] = "OK: database <b>".$user."_".$_POST['v_database']."</b> has been created successfully.";
  52. unset($v_database);
  53. unset($v_dbuser);
  54. unset($v_password);
  55. unset($v_type);
  56. unset($v_charset);
  57. unset($output);
  58. }
  59. }
  60. }
  61. exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
  62. $db_types = json_decode(implode('', $output), true);
  63. unset($output);
  64. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
  65. unset($_SESSION['error_msg']);
  66. unset($_SESSION['ok_msg']);
  67. //}
  68. // Footer
  69. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');