index.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. // Init
  3. error_reporting(NULL);
  4. ob_start();
  5. session_start();
  6. $TAB = 'MAIL';
  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. // Cancel
  15. if (!empty($_POST['cancel'])) {
  16. header("Location: /list/mail/");
  17. }
  18. // Mail Domain
  19. if (!empty($_POST['ok'])) {
  20. if (empty($_POST['v_domain'])) $errors[] = 'domain';
  21. if (!empty($_POST['v_antispam'])) {
  22. $v_antispam = 'yes';
  23. } else {
  24. $v_antispam = 'no';
  25. }
  26. if (!empty($_POST['v_antivirus'])) {
  27. $v_antivirus = 'yes';
  28. } else {
  29. $v_antivirus = 'no';
  30. }
  31. if (!empty($_POST['v_dkim'])) {
  32. $v_dkim = 'yes';
  33. } else {
  34. $v_dkim = 'no';
  35. }
  36. // Protect input
  37. $v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
  38. $v_domain = escapeshellarg($v_domain);
  39. // Check for errors
  40. if (!empty($errors[0])) {
  41. foreach ($errors as $i => $error) {
  42. if ( $i == 0 ) {
  43. $error_msg = $error;
  44. } else {
  45. $error_msg = $error_msg.", ".$error;
  46. }
  47. }
  48. $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
  49. } else {
  50. // Add mail domain
  51. exec (VESTA_CMD."v_add_mail_domain ".$user." ".$v_domain." ".$v_antispam." ".$v_antivirus." ".$v_dkim, $output, $return_var);
  52. if ($return_var != 0) {
  53. $error = implode('<br>', $output);
  54. if (empty($error)) $error = 'Error: vesta did not return any output.';
  55. $_SESSION['error_msg'] = $error;
  56. }
  57. unset($output);
  58. if (empty($_SESSION['error_msg'])) {
  59. $_SESSION['ok_msg'] = "OK: domain <b>".$_POST[v_domain]."</b> has been created successfully.";
  60. unset($v_domain);
  61. }
  62. }
  63. }
  64. // Mail Account
  65. if (!empty($_POST['ok_acc'])) {
  66. // Check input
  67. if (empty($_POST['v_domain'])) $errors[] = 'domain';
  68. if (empty($_POST['v_account'])) $errors[] = 'account';
  69. if (empty($_POST['v_password'])) $errors[] = 'password';
  70. // Protect input
  71. $v_domain = escapeshellarg($_POST['v_domain']);
  72. $v_account = escapeshellarg($_POST['v_account']);
  73. $v_password = escapeshellarg($_POST['v_password']);
  74. $v_quota = escapeshellarg($_POST['v_quota']);
  75. if (empty($_POST['v_quota'])) $v_quota = 0;
  76. // Check for errors
  77. if (!empty($errors[0])) {
  78. foreach ($errors as $i => $error) {
  79. if ( $i == 0 ) {
  80. $error_msg = $error;
  81. } else {
  82. $error_msg = $error_msg.", ".$error;
  83. }
  84. }
  85. $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
  86. } else {
  87. // Add Mail Account
  88. exec (VESTA_CMD."v_add_mail_account ".$user." ".$v_domain." ".$v_account." ".$v_password." ".$v_quota, $output, $return_var);
  89. if ($return_var != 0) {
  90. $error = implode('<br>', $output);
  91. if (empty($error)) $error = 'Error: vesta did not return any output.';
  92. $_SESSION['error_msg'] = $error;
  93. }
  94. unset($output);
  95. if (empty($_SESSION['error_msg'])) {
  96. $_SESSION['ok_msg'] = "OK: account <b>".$_POST['v_account']."</b> has been created successfully.";
  97. unset($v_account);
  98. unset($v_password);
  99. }
  100. }
  101. }
  102. if ((empty($_GET['domain'])) && (empty($_POST['domain']))) {
  103. $v_domain = $_GET['domain'];
  104. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_mail.html');
  105. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail.html');
  106. unset($_SESSION['error_msg']);
  107. unset($_SESSION['ok_msg']);
  108. } else {
  109. $v_domain = $_GET['domain'];
  110. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_mail_acc.html');
  111. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail_acc.html');
  112. unset($_SESSION['error_msg']);
  113. unset($_SESSION['ok_msg']);
  114. }
  115. }
  116. // Footer
  117. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');