index.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. // Mail Domain
  13. if (!empty($_POST['ok'])) {
  14. if (empty($_POST['v_domain'])) $errors[] = __('domain');
  15. if (!empty($_POST['v_antispam'])) {
  16. $v_antispam = 'yes';
  17. } else {
  18. $v_antispam = 'no';
  19. }
  20. if (!empty($_POST['v_antivirus'])) {
  21. $v_antivirus = 'yes';
  22. } else {
  23. $v_antivirus = 'no';
  24. }
  25. if (!empty($_POST['v_dkim'])) {
  26. $v_dkim = 'yes';
  27. } else {
  28. $v_dkim = 'no';
  29. }
  30. // Protect input
  31. $v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
  32. $v_domain = escapeshellarg($v_domain);
  33. $v_domain = strtolower($v_domain);
  34. // Check for errors
  35. if (!empty($errors[0])) {
  36. foreach ($errors as $i => $error) {
  37. if ( $i == 0 ) {
  38. $error_msg = $error;
  39. } else {
  40. $error_msg = $error_msg.", ".$error;
  41. }
  42. }
  43. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  44. } else {
  45. // Add mail domain
  46. exec (VESTA_CMD."v-add-mail-domain ".$user." ".$v_domain." ".$v_antispam." ".$v_antivirus." ".$v_dkim, $output, $return_var);
  47. check_return_code($return_var,$output);
  48. unset($output);
  49. if (empty($_SESSION['error_msg'])) {
  50. $_SESSION['ok_msg'] = __('MAIL_DOMAIN_CREATED_OK',$_POST['v_domain'],$_POST['v_domain']);
  51. unset($v_domain);
  52. }
  53. }
  54. }
  55. // Mail Account
  56. if (!empty($_POST['ok_acc'])) {
  57. // Check input
  58. if (empty($_POST['v_domain'])) $errors[] = __('domain');
  59. if (empty($_POST['v_account'])) $errors[] = __('account');
  60. if (empty($_POST['v_password'])) $errors[] = __('password');
  61. // Protect input
  62. $v_domain = escapeshellarg($_POST['v_domain']);
  63. $v_domain = strtolower($v_domain);
  64. $v_account = escapeshellarg($_POST['v_account']);
  65. $v_password = escapeshellarg($_POST['v_password']);
  66. $v_quota = escapeshellarg($_POST['v_quota']);
  67. $v_aliases = $_POST['v_aliases'];
  68. $v_fwd = $_POST['v_fwd'];
  69. if (empty($_POST['v_quota'])) $v_quota = 0;
  70. if ((!empty($_POST['v_quota'])) || (!empty($_POST['v_aliases'])) || (!empty($_POST['v_fwd'])) ) $v_adv = 'yes';
  71. // Check for errors
  72. if (!empty($errors[0])) {
  73. foreach ($errors as $i => $error) {
  74. if ( $i == 0 ) {
  75. $error_msg = $error;
  76. } else {
  77. $error_msg = $error_msg.", ".$error;
  78. }
  79. }
  80. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  81. } else {
  82. // Add Mail Account
  83. exec (VESTA_CMD."v-add-mail-account ".$user." ".$v_domain." ".$v_account." ".$v_password." ".$v_quota, $output, $return_var);
  84. check_return_code($return_var,$output);
  85. unset($output);
  86. // Add Aliases
  87. if ((!empty($_POST['v_aliases'])) && (empty($_SESSION['error_msg']))) {
  88. $valiases = preg_replace("/\n/", " ", $_POST['v_aliases']);
  89. $valiases = preg_replace("/,/", " ", $valiases);
  90. $valiases = preg_replace('/\s+/', ' ',$valiases);
  91. $valiases = trim($valiases);
  92. $aliases = explode(" ", $valiases);
  93. foreach ($aliases as $alias) {
  94. $alias = escapeshellarg($alias);
  95. if (empty($_SESSION['error_msg'])) {
  96. exec (VESTA_CMD."v-add-mail-account-alias ".$user." ".$v_domain." ".$v_account." ".$alias, $output, $return_var);
  97. check_return_code($return_var,$output);
  98. }
  99. unset($output);
  100. }
  101. }
  102. // Add Forwads
  103. if ((!empty($_POST['v_fwd'])) && (empty($_SESSION['error_msg']))) {
  104. $vfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
  105. $vfwd = preg_replace("/,/", " ", $vfwd);
  106. $vfwd = preg_replace('/\s+/', ' ',$vfwd);
  107. $vfwd = trim($vfwd);
  108. $fwd = explode(" ", $vfwd);
  109. foreach ($fwd as $forward) {
  110. $forward = escapeshellarg($forward);
  111. if (empty($_SESSION['error_msg'])) {
  112. exec (VESTA_CMD."v-add-mail-account-forward ".$user." ".$v_domain." ".$v_account." ".$forward, $output, $return_var);
  113. check_return_code($return_var,$output);
  114. }
  115. unset($output);
  116. }
  117. // Add fwd_only flag
  118. if ((!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  119. exec (VESTA_CMD."v-add-mail-account-fwd-only ".$user." ".$v_domain." ".$v_account, $output, $return_var);
  120. check_return_code($return_var,$output);
  121. unset($output);
  122. }
  123. }
  124. if (empty($_SESSION['error_msg'])) {
  125. exec (VESTA_CMD."v-list-sys-config json", $output, $return_var);
  126. $sys = json_decode(implode('', $output), true);
  127. unset($output);
  128. list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
  129. $webmail = "http://".$http_host."/webmail/";
  130. if (!empty($sys['config']['MAIL_URL'])) $webmail = $sys['config']['MAIL_URL'];
  131. $_SESSION['ok_msg'] = __('MAIL_ACCOUNT_CREATED_OK',strtolower($_POST['v_account']),$_POST[v_domain],strtolower($_POST['v_account']),$_POST[v_domain]);
  132. $_SESSION['ok_msg'] .= " / <a href=".$webmail." target='_blank'>" . __('open webmail') . "</a>";
  133. unset($v_account);
  134. unset($v_password);
  135. unset($v_password);
  136. unset($v_aliases);
  137. unset($v_fwd);
  138. unset($v_quota);
  139. }
  140. }
  141. }
  142. if ((empty($_GET['domain'])) && (empty($_POST['domain']))) {
  143. $v_domain = (isset($_GET['domain'])?$_GET['domain']:'');
  144. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail.html');
  145. unset($_SESSION['error_msg']);
  146. unset($_SESSION['ok_msg']);
  147. } else {
  148. $v_domain = $_GET['domain'];
  149. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail_acc.html');
  150. unset($_SESSION['error_msg']);
  151. unset($_SESSION['ok_msg']);
  152. }
  153. // Footer
  154. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');