index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. $v_db_email = $panel[$user]['CONTACT'];
  13. if (!empty($_POST['ok'])) {
  14. // Check input
  15. if (empty($_POST['v_database'])) $errors[] = _('database');
  16. if (empty($_POST['v_dbuser'])) $errors[] = _('username');
  17. if (empty($_POST['v_password'])) $errors[] = _('password');
  18. if (empty($_POST['v_type'])) $errors[] = _('type');
  19. if (empty($_POST['v_charset'])) $errors[] = _('charset');
  20. // Check for errors
  21. if (empty($errors[0])) {
  22. foreach ($errors as $i => $error) {
  23. if ( $i == 0 ) {
  24. $error_msg = $error;
  25. } else {
  26. $error_msg = $error_msg.", ".$error;
  27. }
  28. }
  29. $_SESSION['error_msg'] = _('Error: field "%s" can not be blank.',$error_msg);
  30. }
  31. // Validate email
  32. if (!empty($_POST['v_db_email'])) {
  33. if (!filter_var($_POST['v_db_email'], FILTER_VALIDATE_EMAIL)) {
  34. $_SESSION['error_msg'] = _('Please enter valid email address.');
  35. }
  36. }
  37. // Protect input
  38. $v_database = escapeshellarg($_POST['v_database']);
  39. $v_dbuser = escapeshellarg($_POST['v_dbuser']);
  40. $v_password = escapeshellarg($_POST['v_password']);
  41. $v_type = $_POST['v_type'];
  42. $v_charset = $_POST['v_charset'];
  43. $v_db_email = $_POST['v_db_email'];
  44. if (empty($_SESSION['error_msg'])) {
  45. // Add Database
  46. $v_type = escapeshellarg($_POST['v_type']);
  47. $v_charset = escapeshellarg($_POST['v_charset']);
  48. exec (VESTA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." 'default' ".$v_charset, $output, $return_var);
  49. $v_type = $_POST['v_type'];
  50. $v_charset = $_POST['v_charset'];
  51. if ($return_var != 0) {
  52. $error = implode('<br>', $output);
  53. if (empty($error)) $error = _('Error: vesta did not return any output.');
  54. $_SESSION['error_msg'] = $error;
  55. unset($v_password);
  56. unset($output);
  57. }
  58. if (!empty($v_db_email)) {
  59. list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"]);
  60. if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpMyAdmin/";
  61. if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phpPgAdmin/";
  62. $to = $v_db_email;
  63. $subject = _("Database Credentials");
  64. $hostname = exec('hostname');
  65. $from = _('MAIL_FROM',$hostname);
  66. $mailtext = _('DATABASE_READY',$user,$_POST['v_database'],$user,$_POST['v_dbuser'],$_POST['v_password']);
  67. $mailtext .= $db_admin_link."\n\n";
  68. $mailtext .= "--\n"._('Vesta Control Panel')."\n";
  69. send_email($to, $subject, $mailtext, $from);
  70. }
  71. $_SESSION['ok_msg'] = _('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']);
  72. unset($v_database);
  73. unset($v_dbuser);
  74. unset($v_password);
  75. unset($v_type);
  76. unset($v_charset);
  77. unset($output);
  78. }
  79. }
  80. exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
  81. $db_types = json_decode(implode('', $output), true);
  82. unset($output);
  83. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
  84. unset($_SESSION['error_msg']);
  85. unset($_SESSION['ok_msg']);
  86. // Footer
  87. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');
  88. ?>