index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. check_return_code($return_var,$output);
  57. unset($output);
  58. if ((!empty($v_db_email)) && (empty($_SESSION['error_msg']))) {
  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'],$db_admin_link);
  67. send_email($to, $subject, $mailtext, $from);
  68. }
  69. if (empty($_SESSION['error_msg'])) {
  70. $_SESSION['ok_msg'] = __('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']);
  71. unset($v_database);
  72. unset($v_dbuser);
  73. unset($v_password);
  74. unset($v_type);
  75. unset($v_charset);
  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. // Footer
  86. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');
  87. ?>