index.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 "%s" can not be blank.',$error_msg);
  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. // Add Database
  53. $v_type = escapeshellarg($_POST['v_type']);
  54. $v_charset = escapeshellarg($_POST['v_charset']);
  55. exec (VESTA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." 'default' ".$v_charset, $output, $return_var);
  56. $v_type = $_POST['v_type'];
  57. $v_charset = $_POST['v_charset'];
  58. if ($return_var != 0) {
  59. $error = implode('<br>', $output);
  60. if (empty($error)) $error = _('Error: vesta did not return any output.');
  61. $_SESSION['error_msg'] = $error;
  62. unset($v_password);
  63. unset($output);
  64. }
  65. else {
  66. if (empty($v_notify)) {
  67. list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"]);
  68. if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpMyAdmin/";
  69. if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phpPgAdmin/";
  70. $to = $panel[$user]['CONTACT'];
  71. $subject = _("Database Credentials");
  72. $hostname = exec('hostname');
  73. $from = _('MAIL_FROM',$hostname);
  74. $mailtext = _('DATABASE_READY',$panel[$user]['FNAME'],$panel[$user]['LNAME'],$_POST['v_type'],$user,$_POST['v_database'],$user,$_POST['v_dbuser'],$_POST['v_password']);
  75. $mailtext .= $db_admin_link."\n\n";
  76. $mailtext .= "--\n"._('Vesta Control Panel')."\n";
  77. send_email($to, $subject, $mailtext, $from);
  78. }
  79. $_SESSION['ok_msg'] = _('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']);
  80. unset($v_database);
  81. unset($v_dbuser);
  82. unset($v_password);
  83. unset($v_type);
  84. unset($v_charset);
  85. unset($output);
  86. }
  87. }
  88. }
  89. }
  90. exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
  91. $db_types = json_decode(implode('', $output), true);
  92. unset($output);
  93. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
  94. unset($_SESSION['error_msg']);
  95. unset($_SESSION['ok_msg']);
  96. //}
  97. // Footer
  98. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');
  99. ?>