index.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. $v_aliases = $_POST['v_aliases'];
  76. $v_fwd = $_POST['v_fwd'];
  77. if (empty($_POST['v_quota'])) $v_quota = 0;
  78. if ((!empty($_POST['v_quota'])) || (!empty($_POST['v_aliases'])) || (!empty($_POST['v_fwd'])) ) $v_adv = 'yes';
  79. // Check for errors
  80. if (!empty($errors[0])) {
  81. foreach ($errors as $i => $error) {
  82. if ( $i == 0 ) {
  83. $error_msg = $error;
  84. } else {
  85. $error_msg = $error_msg.", ".$error;
  86. }
  87. }
  88. $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
  89. } else {
  90. // Add Mail Account
  91. exec (VESTA_CMD."v_add_mail_account ".$user." ".$v_domain." ".$v_account." ".$v_password." ".$v_quota, $output, $return_var);
  92. if ($return_var != 0) {
  93. $error = implode('<br>', $output);
  94. if (empty($error)) $error = 'Error: vesta did not return any output.';
  95. $_SESSION['error_msg'] = $error;
  96. }
  97. // Add Aliases
  98. if ((!empty($_POST['v_aliases'])) && (empty($_SESSION['error_msg']))) {
  99. $valiases = preg_replace("/\n/", " ", $_POST['v_aliases']);
  100. $valiases = preg_replace("/,/", " ", $valiases);
  101. $valiases = preg_replace('/\s+/', ' ',$valiases);
  102. $valiases = trim($valiases);
  103. $aliases = explode(" ", $valiases);
  104. foreach ($aliases as $alias) {
  105. $alias = escapeshellarg($alias);
  106. if (empty($_SESSION['error_msg'])) {
  107. exec (VESTA_CMD."v_add_mail_account_alias ".$user." ".$v_domain." ".$v_account." ".$alias, $output, $return_var);
  108. if ($return_var != 0) {
  109. $error = implode('<br>', $output);
  110. if (empty($error)) $error = 'Error: vesta did not return any output.';
  111. $_SESSION['error_msg'] = $error;
  112. }
  113. }
  114. unset($output);
  115. }
  116. }
  117. // Add Forwads
  118. if ((!empty($_POST['v_fwd'])) && (empty($_SESSION['error_msg']))) {
  119. $vfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
  120. $vfwd = preg_replace("/,/", " ", $vfwd);
  121. $vfwd = preg_replace('/\s+/', ' ',$vfwd);
  122. $vfwd = trim($vfwd);
  123. $fwd = explode(" ", $vfwd);
  124. foreach ($fwd as $forward) {
  125. $forward = escapeshellarg($forward);
  126. if (empty($_SESSION['error_msg'])) {
  127. exec (VESTA_CMD."v_add_mail_account_forward ".$user." ".$v_domain." ".$v_account." ".$forward, $output, $return_var);
  128. if ($return_var != 0) {
  129. $error = implode('<br>', $output);
  130. if (empty($error)) $error = 'Error: vesta did not return any output.';
  131. $_SESSION['error_msg'] = $error;
  132. }
  133. }
  134. unset($output);
  135. }
  136. }
  137. unset($output);
  138. if (empty($_SESSION['error_msg'])) {
  139. $_SESSION['ok_msg'] = "OK: account <b>".$_POST['v_account']."</b> has been created successfully.";
  140. unset($v_account);
  141. unset($v_password);
  142. unset($v_password);
  143. unset($v_aliases);
  144. unset($v_fwd);
  145. unset($v_quota);
  146. }
  147. }
  148. }
  149. if ((empty($_GET['domain'])) && (empty($_POST['domain']))) {
  150. $v_domain = $_GET['domain'];
  151. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_mail.html');
  152. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail.html');
  153. unset($_SESSION['error_msg']);
  154. unset($_SESSION['ok_msg']);
  155. } else {
  156. $v_domain = $_GET['domain'];
  157. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_mail_acc.html');
  158. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail_acc.html');
  159. unset($_SESSION['error_msg']);
  160. unset($_SESSION['ok_msg']);
  161. }
  162. }
  163. // Footer
  164. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');