index.php 6.6 KB

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