index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. if (empty($v_notify)) {
  53. list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"]);
  54. if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpMyAdmin/";
  55. if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phpPgAdmin/";
  56. $to = $panel[$user]['CONTACT'];
  57. $subject = _("Database Credentials");
  58. $hostname = exec('hostname');
  59. $from = _('MAIL_FROM',$hostname);
  60. $mailtext = _('DATABASE_READY',$panel[$user]['FNAME'],$panel[$user]['LNAME'],$_POST['v_type'],$user,$_POST['v_database'],$user,$_POST['v_dbuser'],$_POST['v_password']);
  61. $mailtext .= $db_admin_link."\n\n";
  62. $mailtext .= "--\n"._('Vesta Control Panel')."\n";
  63. send_email($to, $subject, $mailtext, $from);
  64. }
  65. $_SESSION['ok_msg'] = _('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']);
  66. unset($v_database);
  67. unset($v_dbuser);
  68. unset($v_password);
  69. unset($v_type);
  70. unset($v_charset);
  71. unset($output);
  72. }
  73. }
  74. }
  75. exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
  76. $db_types = json_decode(implode('', $output), true);
  77. unset($output);
  78. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
  79. unset($_SESSION['error_msg']);
  80. unset($_SESSION['ok_msg']);
  81. //}
  82. // Footer
  83. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');