index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. // Check token
  82. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  83. header('location: /login/');
  84. exit();
  85. }
  86. // Delete antispam
  87. if (($v_antispam == 'yes') && (empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
  88. exec (VESTA_CMD."v-delete-mail-domain-antispam ".$v_username." ".$v_domain, $output, $return_var);
  89. check_return_code($return_var,$output);
  90. $v_antispam = 'no';
  91. unset($output);
  92. }
  93. // Add antispam
  94. if (($v_antispam == 'no') && (!empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
  95. exec (VESTA_CMD."v-add-mail-domain-antispam ".$v_username." ".$v_domain, $output, $return_var);
  96. check_return_code($return_var,$output);
  97. $v_antispam = 'yes';
  98. unset($output);
  99. }
  100. // Delete antivirus
  101. if (($v_antivirus == 'yes') && (empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
  102. exec (VESTA_CMD."v-delete-mail-domain-antivirus ".$v_username." ".$v_domain, $output, $return_var);
  103. check_return_code($return_var,$output);
  104. $v_antivirus = 'no';
  105. unset($output);
  106. }
  107. // Add antivirs
  108. if (($v_antivirus == 'no') && (!empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
  109. exec (VESTA_CMD."v-add-mail-domain-antivirus ".$v_username." ".$v_domain, $output, $return_var);
  110. check_return_code($return_var,$output);
  111. $v_antivirus = 'yes';
  112. unset($output);
  113. }
  114. // Delete DKIM
  115. if (($v_dkim == 'yes') && (empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
  116. exec (VESTA_CMD."v-delete-mail-domain-dkim ".$v_username." ".$v_domain, $output, $return_var);
  117. check_return_code($return_var,$output);
  118. $v_dkim = 'no';
  119. unset($output);
  120. }
  121. // Add DKIM
  122. if (($v_dkim == 'no') && (!empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
  123. exec (VESTA_CMD."v-add-mail-domain-dkim ".$v_username." ".$v_domain, $output, $return_var);
  124. check_return_code($return_var,$output);
  125. $v_dkim = 'yes';
  126. unset($output);
  127. }
  128. // Delete catchall
  129. if ((!empty($v_catchall)) && (empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  130. exec (VESTA_CMD."v-delete-mail-domain-catchall ".$v_username." ".$v_domain, $output, $return_var);
  131. check_return_code($return_var,$output);
  132. $v_catchall = '';
  133. unset($output);
  134. }
  135. // Change catchall address
  136. if ((!empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  137. if ($v_catchall != $_POST['v_catchall']) {
  138. $v_catchall = escapeshellarg($_POST['v_catchall']);
  139. exec (VESTA_CMD."v-change-mail-domain-catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var);
  140. check_return_code($return_var,$output);
  141. unset($output);
  142. }
  143. }
  144. // Add catchall
  145. if ((empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  146. $v_catchall = escapeshellarg($_POST['v_catchall']);
  147. exec (VESTA_CMD."v-add-mail-domain-catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var);
  148. check_return_code($return_var,$output);
  149. unset($output);
  150. }
  151. // Set success message
  152. if (empty($_SESSION['error_msg'])) {
  153. $_SESSION['ok_msg'] = __('Changes has been saved.');
  154. }
  155. }
  156. // Check POST request for mail account
  157. if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (!empty($_GET['account']))) {
  158. // Check token
  159. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  160. header('location: /login/');
  161. exit();
  162. }
  163. $v_domain = escapeshellarg($_POST['v_domain']);
  164. $v_account = escapeshellarg($_POST['v_account']);
  165. // Change password
  166. if ((!empty($_POST['v_password'])) && (empty($_SESSION['error_msg']))) {
  167. $v_password = tempnam("/tmp","vst");
  168. $fp = fopen($v_password, "w");
  169. fwrite($fp, $_POST['v_password']."\n");
  170. fclose($fp);
  171. exec (VESTA_CMD."v-change-mail-account-password ".$v_username." ".$v_domain." ".$v_account." ".$v_password, $output, $return_var);
  172. check_return_code($return_var,$output);
  173. unset($output);
  174. unlink($v_password);
  175. $v_password = escapeshellarg($_POST['v_password']);;
  176. }
  177. // Change quota
  178. if (($v_quota != $_POST['v_quota']) && (empty($_SESSION['error_msg']))) {
  179. if (empty($_POST['v_quota'])) {
  180. $v_quota = 0;
  181. } else {
  182. $v_quota = escapeshellarg($_POST['v_quota']);
  183. }
  184. exec (VESTA_CMD."v-change-mail-account-quota ".$v_username." ".$v_domain." ".$v_account." ".$v_quota, $output, $return_var);
  185. check_return_code($return_var,$output);
  186. unset($output);
  187. }
  188. // Change account aliases
  189. if (empty($_SESSION['error_msg'])) {
  190. $waliases = preg_replace("/\n/", " ", $_POST['v_aliases']);
  191. $waliases = preg_replace("/,/", " ", $waliases);
  192. $waliases = preg_replace('/\s+/', ' ',$waliases);
  193. $waliases = trim($waliases);
  194. $aliases = explode(" ", $waliases);
  195. $v_aliases = str_replace(' ', "\n", $waliases);
  196. $result = array_diff($valiases, $aliases);
  197. foreach ($result as $alias) {
  198. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  199. exec (VESTA_CMD."v-delete-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." '".$alias."'", $output, $return_var);
  200. check_return_code($return_var,$output);
  201. unset($output);
  202. }
  203. }
  204. $result = array_diff($aliases, $valiases);
  205. foreach ($result as $alias) {
  206. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  207. exec (VESTA_CMD."v-add-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." '".$alias."'", $output, $return_var);
  208. check_return_code($return_var,$output);
  209. unset($output);
  210. }
  211. }
  212. }
  213. // Change forwarders
  214. if (empty($_SESSION['error_msg'])) {
  215. $wfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
  216. $wfwd = preg_replace("/,/", " ", $wfwd);
  217. $wfwd = preg_replace('/\s+/', ' ',$wfwd);
  218. $wfwd = trim($wfwd);
  219. $fwd = explode(" ", $wfwd);
  220. $v_fwd = str_replace(' ', "\n", $wfwd);
  221. $result = array_diff($vfwd, $fwd);
  222. foreach ($result as $forward) {
  223. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  224. exec (VESTA_CMD."v-delete-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var);
  225. check_return_code($return_var,$output);
  226. unset($output);
  227. }
  228. }
  229. $result = array_diff($fwd, $vfwd);
  230. foreach ($result as $forward) {
  231. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  232. exec (VESTA_CMD."v-add-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var);
  233. check_return_code($return_var,$output);
  234. unset($output);
  235. }
  236. }
  237. }
  238. // Delete FWD_ONLY flag
  239. if (($v_fwd_only == 'yes') && (empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  240. exec (VESTA_CMD."v-delete-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
  241. check_return_code($return_var,$output);
  242. unset($output);
  243. $v_fwd_only = '';
  244. }
  245. // Add FWD_ONLY flag
  246. if (($v_fwd_only != 'yes') && (!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  247. exec (VESTA_CMD."v-add-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
  248. check_return_code($return_var,$output);
  249. unset($output);
  250. $v_fwd_only = 'yes';
  251. }
  252. // Delete autoreply
  253. if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  254. exec (VESTA_CMD."v-delete-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
  255. check_return_code($return_var,$output);
  256. unset($output);
  257. $v_autoreply = 'no';
  258. $v_autoreply_message = '';
  259. }
  260. // Add autoreply
  261. if ((!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  262. if ( $v_autoreply_message != str_replace("\r\n", "\n", $_POST['v_autoreply_message'])) {
  263. $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
  264. $v_autoreply_message = escapeshellarg($v_autoreply_message);
  265. exec (VESTA_CMD."v-add-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account." ".$v_autoreply_message, $output, $return_var);
  266. check_return_code($return_var,$output);
  267. unset($output);
  268. $v_autoreply = 'yes';
  269. $v_autoreply_message = $_POST['v_autoreply_message'];
  270. }
  271. }
  272. // Set success message
  273. if (empty($_SESSION['error_msg'])) {
  274. $_SESSION['ok_msg'] = __('Changes has been saved.');
  275. }
  276. }
  277. // Display body for mail domain
  278. if ((!empty($_GET['domain'])) && (empty($_GET['account']))) {
  279. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_mail.html');
  280. }
  281. // Display body for mail account
  282. if ((!empty($_GET['domain'])) && (!empty($_GET['account']))) {
  283. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_mail_acc.html');
  284. }
  285. // Flush session messages
  286. unset($_SESSION['error_msg']);
  287. unset($_SESSION['ok_msg']);
  288. // Footer
  289. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');