index.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. if (empty($_SESSION['error_msg'])) {
  45. // Add Database
  46. $v_type = escapeshellarg($_POST['v_type']);
  47. $v_charset = escapeshellarg($_POST['v_charset']);
  48. exec (VESTA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." 'default' ".$v_charset, $output, $return_var);
  49. $v_type = $_POST['v_type'];
  50. $v_charset = $_POST['v_charset'];
  51. if ($return_var != 0) {
  52. $error = implode('<br>', $output);
  53. if (empty($error)) $error = _('Error code:',$return_var);
  54. $_SESSION['error_msg'] = $error;
  55. unset($v_password);
  56. unset($output);
  57. }
  58. if ((!empty($v_db_email)) && ($return_var == 0)) {
  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. $_SESSION['ok_msg'] = _('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']);
  70. unset($v_database);
  71. unset($v_dbuser);
  72. unset($v_password);
  73. unset($v_type);
  74. unset($v_charset);
  75. unset($output);
  76. }
  77. }
  78. exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
  79. $db_types = json_decode(implode('', $output), true);
  80. unset($output);
  81. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
  82. unset($_SESSION['error_msg']);
  83. unset($_SESSION['ok_msg']);
  84. // Footer
  85. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');
  86. ?>