index.php 3.4 KB

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