index.php 6.1 KB

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