index.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. if (empty($_POST['v_notify'])) $v_notify = 'off';
  28. // Check for errors
  29. if (!empty($errors[0])) {
  30. foreach ($errors as $i => $error) {
  31. if ( $i == 0 ) {
  32. $error_msg = $error;
  33. } else {
  34. $error_msg = $error_msg.", ".$error;
  35. }
  36. }
  37. $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
  38. } else {
  39. // Add Database
  40. $v_type = escapeshellarg($_POST['v_type']);
  41. $v_charset = escapeshellarg($_POST['v_charset']);
  42. exec (VESTA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." 'default' ".$v_charset, $output, $return_var);
  43. $v_type = $_POST['v_type'];
  44. $v_charset = $_POST['v_charset'];
  45. if ($return_var != 0) {
  46. $error = implode('<br>', $output);
  47. if (empty($error)) $error = 'Error: vesta did not return any output.';
  48. $_SESSION['error_msg'] = $error;
  49. unset($v_password);
  50. unset($output);
  51. } else {
  52. if (empty($v_notify)) {
  53. list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"]);
  54. if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpMyAdmin/";
  55. if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phpPgAdmin/";
  56. $to = $panel[$user]['CONTACT'];
  57. $subject = "Database Credentials";
  58. $hostname = exec('hostname');
  59. $from = "Vesta Control Panel <noreply@".$hostname.">";
  60. $mailtext = "Hello ".$panel[$user]['FNAME']." ".$panel[$user]['LNAME'].",\n";
  61. $mailtext .= "your ".$_POST['v_type']." database has been created successfully.\n\n";
  62. $mailtext .= "database: ".$user."_".$_POST['v_database']."\n";
  63. $mailtext .= "username: ".$user."_".$_POST['v_dbuser']."\n";
  64. $mailtext .= "password: ".$_POST['v_password']."\n\n";
  65. $mailtext .= $db_admin_link."\n\n";
  66. $mailtext .= "--\nVesta Control Panel\n";
  67. send_email($to, $subject, $mailtext, $from);
  68. }
  69. $_SESSION['ok_msg'] = "OK: database <a href='/edit/db/?database=".$user."_".$_POST['v_database']."'><b>".$user."_".$_POST['v_database']."</b></a> has been created successfully.";
  70. unset($v_database);
  71. unset($v_dbuser);
  72. unset($v_password);
  73. unset($v_type);
  74. unset($v_charset);
  75. unset($output);
  76. }
  77. }
  78. }
  79. exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
  80. $db_types = json_decode(implode('', $output), true);
  81. unset($output);
  82. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
  83. unset($_SESSION['error_msg']);
  84. unset($_SESSION['ok_msg']);
  85. //}
  86. // Footer
  87. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');