index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. // Check domain argument
  13. if (empty($_GET['domain'])) {
  14. header("Location: /list/mail/");
  15. exit;
  16. }
  17. // Edit as someone else?
  18. if (($_SESSION['user'] == 'admin') && (!empty($_GET['user']))) {
  19. $user=escapeshellarg($_GET['user']);
  20. }
  21. $v_username = $user;
  22. // List mail domain
  23. if ((!empty($_GET['domain'])) && (empty($_GET['account']))) {
  24. $v_domain = escapeshellarg($_GET['domain']);
  25. exec (VESTA_CMD."v-list-mail-domain ".$user." ".$v_domain." json", $output, $return_var);
  26. $data = json_decode(implode('', $output), true);
  27. unset($output);
  28. // Parse domain
  29. $v_domain = $_GET['domain'];
  30. $v_antispam = $data[$v_domain]['ANTISPAM'];
  31. $v_antivirus = $data[$v_domain]['ANTIVIRUS'];
  32. $v_dkim = $data[$v_domain]['DKIM'];
  33. $v_catchall = $data[$v_domain]['CATCHALL'];
  34. $v_date = $data[$v_domain]['DATE'];
  35. $v_time = $data[$v_domain]['TIME'];
  36. $v_suspended = $data[$v_domain]['SUSPENDED'];
  37. if ( $v_suspended == 'yes' ) {
  38. $v_status = 'suspended';
  39. } else {
  40. $v_status = 'active';
  41. }
  42. }
  43. // List mail account
  44. if ((!empty($_GET['domain'])) && (!empty($_GET['account']))) {
  45. $v_domain = escapeshellarg($_GET['domain']);
  46. $v_account = escapeshellarg($_GET['account']);
  47. exec (VESTA_CMD."v-list-mail-account ".$user." ".$v_domain." ".$v_account." 'json'", $output, $return_var);
  48. $data = json_decode(implode('', $output), true);
  49. unset($output);
  50. // Parse mail account
  51. $v_username = $user;
  52. $v_domain = $_GET['domain'];
  53. $v_account = $_GET['account'];
  54. $v_password = "••••••••";
  55. $v_aliases = str_replace(',', "\n", $data[$v_account]['ALIAS']);
  56. $valiases = explode(",", $data[$v_account]['ALIAS']);
  57. $v_fwd = str_replace(',', "\n", $data[$v_account]['FWD']);
  58. $vfwd = explode(",", $data[$v_account]['FWD']);
  59. $v_fwd_only = $data[$v_account]['FWD_ONLY'];
  60. $v_quota = $data[$v_account]['QUOTA'];
  61. $v_autoreply = $data[$v_account]['AUTOREPLY'];
  62. $v_suspended = $data[$v_account]['SUSPENDED'];
  63. if ( $v_suspended == 'yes' ) {
  64. $v_status = 'suspended';
  65. } else {
  66. $v_status = 'active';
  67. }
  68. $v_date = $data[$v_account]['DATE'];
  69. $v_time = $data[$v_account]['TIME'];
  70. // Parse autoreply
  71. if ( $v_autoreply == 'yes' ) {
  72. exec (VESTA_CMD."v-list-mail-account-autoreply ".$user." '".$v_domain."' '".$v_account."' json", $output, $return_var);
  73. $autoreply_str = json_decode(implode('', $output), true);
  74. unset($output);
  75. $v_autoreply_message = $autoreply_str[$v_account]['MSG'];
  76. }
  77. }
  78. // Check POST request for mail domain
  79. if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (empty($_GET['account']))) {
  80. $v_domain = escapeshellarg($_POST['v_domain']);
  81. // Delete antispam
  82. if (($v_antispam == 'yes') && (empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
  83. exec (VESTA_CMD."v-delete-mail-domain-antispam ".$v_username." ".$v_domain, $output, $return_var);
  84. check_return_code($return_var,$output);
  85. $v_antispam = 'no';
  86. unset($output);
  87. }
  88. // Add antispam
  89. if (($v_antispam == 'no') && (!empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
  90. exec (VESTA_CMD."v-add-mail-domain-antispam ".$v_username." ".$v_domain, $output, $return_var);
  91. check_return_code($return_var,$output);
  92. $v_antispam = 'yes';
  93. unset($output);
  94. }
  95. // Delete antivirus
  96. if (($v_antivirus == 'yes') && (empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
  97. exec (VESTA_CMD."v-delete-mail-domain-antivirus ".$v_username." ".$v_domain, $output, $return_var);
  98. check_return_code($return_var,$output);
  99. $v_antivirus = 'no';
  100. unset($output);
  101. }
  102. // Add antivirs
  103. if (($v_antivirus == 'no') && (!empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
  104. exec (VESTA_CMD."v-add-mail-domain-antivirus ".$v_username." ".$v_domain, $output, $return_var);
  105. check_return_code($return_var,$output);
  106. $v_antivirus = 'yes';
  107. unset($output);
  108. }
  109. // Delete DKIM
  110. if (($v_dkim == 'yes') && (empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
  111. exec (VESTA_CMD."v-delete-mail-domain-dkim ".$v_username." ".$v_domain, $output, $return_var);
  112. check_return_code($return_var,$output);
  113. $v_dkim = 'no';
  114. unset($output);
  115. }
  116. // Add DKIM
  117. if (($v_dkim == 'no') && (!empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
  118. exec (VESTA_CMD."v-add-mail-domain-dkim ".$v_username." ".$v_domain, $output, $return_var);
  119. check_return_code($return_var,$output);
  120. $v_dkim = 'yes';
  121. unset($output);
  122. }
  123. // Delete catchall
  124. if ((!empty($v_catchall)) && (empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  125. exec (VESTA_CMD."v-delete-mail-domain-catchall ".$v_username." ".$v_domain, $output, $return_var);
  126. check_return_code($return_var,$output);
  127. $v_catchall = '';
  128. unset($output);
  129. }
  130. // Change catchall address
  131. if ((!empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  132. if ($v_catchall != $_POST['v_catchall']) {
  133. $v_catchall = escapeshellarg($_POST['v_catchall']);
  134. exec (VESTA_CMD."v-change-mail-domain-catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var);
  135. check_return_code($return_var,$output);
  136. unset($output);
  137. }
  138. }
  139. // Add catchall
  140. if ((empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  141. $v_catchall = escapeshellarg($_POST['v_catchall']);
  142. exec (VESTA_CMD."v-add-mail-domain-catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var);
  143. check_return_code($return_var,$output);
  144. unset($output);
  145. }
  146. // Set success message
  147. if (empty($_SESSION['error_msg'])) {
  148. $_SESSION['ok_msg'] = __('Changes has been saved.');
  149. }
  150. }
  151. // Check POST request for mail account
  152. if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (!empty($_GET['account']))) {
  153. $v_domain = escapeshellarg($_POST['v_domain']);
  154. $v_account = escapeshellarg($_POST['v_account']);
  155. // Change password
  156. if (($v_password != $_POST['v_password']) && (empty($_SESSION['error_msg']))) {
  157. $v_password = escapeshellarg($_POST['v_password']);
  158. exec (VESTA_CMD."v-change-mail-account-password ".$v_username." ".$v_domain." ".$v_account." ".$v_password, $output, $return_var);
  159. check_return_code($return_var,$output);
  160. $v_password = "••••••••";
  161. unset($output);
  162. }
  163. // Change quota
  164. if (($v_quota != $_POST['v_quota']) && (empty($_SESSION['error_msg']))) {
  165. if (empty($_POST['v_quota'])) {
  166. $v_quota = 0;
  167. } else {
  168. $v_quota = escapeshellarg($_POST['v_quota']);
  169. }
  170. exec (VESTA_CMD."v-change-mail-account-quota ".$v_username." ".$v_domain." ".$v_account." ".$v_quota, $output, $return_var);
  171. check_return_code($return_var,$output);
  172. unset($output);
  173. }
  174. // Change account aliases
  175. if (empty($_SESSION['error_msg'])) {
  176. $waliases = preg_replace("/\n/", " ", $_POST['v_aliases']);
  177. $waliases = preg_replace("/,/", " ", $waliases);
  178. $waliases = preg_replace('/\s+/', ' ',$waliases);
  179. $waliases = trim($waliases);
  180. $aliases = explode(" ", $waliases);
  181. $v_aliases = str_replace(' ', "\n", $waliases);
  182. $result = array_diff($valiases, $aliases);
  183. foreach ($result as $alias) {
  184. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  185. exec (VESTA_CMD."v-delete-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." '".$alias."'", $output, $return_var);
  186. check_return_code($return_var,$output);
  187. unset($output);
  188. }
  189. }
  190. $result = array_diff($aliases, $valiases);
  191. foreach ($result as $alias) {
  192. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  193. exec (VESTA_CMD."v-add-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." '".$alias."'", $output, $return_var);
  194. check_return_code($return_var,$output);
  195. unset($output);
  196. }
  197. }
  198. }
  199. // Change forwarders
  200. if (empty($_SESSION['error_msg'])) {
  201. $wfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
  202. $wfwd = preg_replace("/,/", " ", $wfwd);
  203. $wfwd = preg_replace('/\s+/', ' ',$wfwd);
  204. $wfwd = trim($wfwd);
  205. $fwd = explode(" ", $wfwd);
  206. $v_fwd = str_replace(' ', "\n", $wfwd);
  207. $result = array_diff($vfwd, $fwd);
  208. foreach ($result as $forward) {
  209. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  210. exec (VESTA_CMD."v-delete-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var);
  211. check_return_code($return_var,$output);
  212. unset($output);
  213. }
  214. }
  215. $result = array_diff($fwd, $vfwd);
  216. foreach ($result as $forward) {
  217. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  218. exec (VESTA_CMD."v-add-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var);
  219. check_return_code($return_var,$output);
  220. unset($output);
  221. }
  222. }
  223. }
  224. // Delete FWD_ONLY flag
  225. if (($v_fwd_only == 'yes') && (empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  226. exec (VESTA_CMD."v-delete-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
  227. check_return_code($return_var,$output);
  228. unset($output);
  229. $v_fwd_only = '';
  230. }
  231. // Add FWD_ONLY flag
  232. if (($v_fwd_only != 'yes') && (!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  233. exec (VESTA_CMD."v-add-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
  234. check_return_code($return_var,$output);
  235. unset($output);
  236. $v_fwd_only = 'yes';
  237. }
  238. // Delete autoreply
  239. if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  240. exec (VESTA_CMD."v-delete-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
  241. check_return_code($return_var,$output);
  242. unset($output);
  243. $v_autoreply = 'no';
  244. $v_autoreply_message = '';
  245. }
  246. // Add autoreply
  247. if ((!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  248. if ( $v_autoreply_message != str_replace("\r\n", "\n", $_POST['v_autoreply_message'])) {
  249. $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
  250. $v_autoreply_message = escapeshellarg($v_autoreply_message);
  251. exec (VESTA_CMD."v-add-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account." ".$v_autoreply_message, $output, $return_var);
  252. check_return_code($return_var,$output);
  253. unset($output);
  254. $v_autoreply = 'yes';
  255. $v_autoreply_message = $_POST['v_autoreply_message'];
  256. }
  257. }
  258. // Set success message
  259. if (empty($_SESSION['error_msg'])) {
  260. $_SESSION['ok_msg'] = __('Changes has been saved.');
  261. }
  262. }
  263. // Display body for mail domain
  264. if ((!empty($_GET['domain'])) && (empty($_GET['account']))) {
  265. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_mail.html');
  266. }
  267. // Display body for mail account
  268. if ((!empty($_GET['domain'])) && (!empty($_GET['account']))) {
  269. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_mail_acc.html');
  270. }
  271. // Flush session messages
  272. unset($_SESSION['error_msg']);
  273. unset($_SESSION['ok_msg']);
  274. // Footer
  275. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');