index.php 6.7 KB

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