index.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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'] = __('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. // Check password length
  45. if (empty($_SESSION['error_msg'])) {
  46. $pw_len = strlen($_POST['v_password']);
  47. if ($pw_len < 6 ) $_SESSION['error_msg'] = __('Password is too short.',$error_msg);
  48. }
  49. if (empty($_SESSION['error_msg'])) {
  50. // Add Database
  51. $v_type = escapeshellarg($_POST['v_type']);
  52. $v_charset = escapeshellarg($_POST['v_charset']);
  53. exec (VESTA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." 'default' ".$v_charset, $output, $return_var);
  54. $v_type = $_POST['v_type'];
  55. $v_charset = $_POST['v_charset'];
  56. if ($return_var != 0) {
  57. $error = implode('<br>', $output);
  58. if (empty($error)) $error = __('Error code:',$return_var);
  59. $_SESSION['error_msg'] = $error;
  60. unset($v_password);
  61. unset($output);
  62. }
  63. if ((!empty($v_db_email)) && ($return_var == 0)) {
  64. list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"]);
  65. if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpMyAdmin/";
  66. if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phpPgAdmin/";
  67. $to = $v_db_email;
  68. $subject = __("Database Credentials");
  69. $hostname = exec('hostname');
  70. $from = __('MAIL_FROM',$hostname);
  71. $mailtext = __('DATABASE_READY',$user."_".$_POST['v_database'],$user."_".$_POST['v_dbuser'],$_POST['v_password'],$db_admin_link);
  72. send_email($to, $subject, $mailtext, $from);
  73. }
  74. $_SESSION['ok_msg'] = __('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']);
  75. unset($v_database);
  76. unset($v_dbuser);
  77. unset($v_password);
  78. unset($v_type);
  79. unset($v_charset);
  80. unset($output);
  81. }
  82. }
  83. exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
  84. $db_types = json_decode(implode('', $output), true);
  85. unset($output);
  86. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
  87. unset($_SESSION['error_msg']);
  88. unset($_SESSION['ok_msg']);
  89. // Footer
  90. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');
  91. ?>