index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <?php
  2. error_reporting(NULL);
  3. ob_start();
  4. $TAB = 'MAIL';
  5. // Main include
  6. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  7. // Check domain argument
  8. if (empty($_GET['domain'])) {
  9. header("Location: /list/mail/");
  10. exit;
  11. }
  12. // Edit as someone else?
  13. if (($_SESSION['user'] == 'admin') && (!empty($_GET['user']))) {
  14. $user=escapeshellarg($_GET['user']);
  15. }
  16. $v_username = $user;
  17. // List mail domain
  18. if ((!empty($_GET['domain'])) && (empty($_GET['account']))) {
  19. $v_domain = escapeshellarg($_GET['domain']);
  20. exec (VESTA_CMD."v-list-mail-domain ".$user." ".$v_domain." json", $output, $return_var);
  21. $data = json_decode(implode('', $output), true);
  22. unset($output);
  23. // Parse domain
  24. $v_domain = $_GET['domain'];
  25. $v_antispam = $data[$v_domain]['ANTISPAM'];
  26. $v_antivirus = $data[$v_domain]['ANTIVIRUS'];
  27. $v_dkim = $data[$v_domain]['DKIM'];
  28. $v_catchall = $data[$v_domain]['CATCHALL'];
  29. $v_date = $data[$v_domain]['DATE'];
  30. $v_time = $data[$v_domain]['TIME'];
  31. $v_suspended = $data[$v_domain]['SUSPENDED'];
  32. if ( $v_suspended == 'yes' ) {
  33. $v_status = 'suspended';
  34. } else {
  35. $v_status = 'active';
  36. }
  37. }
  38. // List mail account
  39. if ((!empty($_GET['domain'])) && (!empty($_GET['account']))) {
  40. $v_domain = escapeshellarg($_GET['domain']);
  41. $v_account = escapeshellarg($_GET['account']);
  42. exec (VESTA_CMD."v-list-mail-account ".$user." ".$v_domain." ".$v_account." 'json'", $output, $return_var);
  43. $data = json_decode(implode('', $output), true);
  44. unset($output);
  45. // Parse mail account
  46. $v_username = $user;
  47. $v_domain = $_GET['domain'];
  48. $v_account = $_GET['account'];
  49. $v_password = "";
  50. $v_aliases = str_replace(',', "\n", $data[$v_account]['ALIAS']);
  51. $valiases = explode(",", $data[$v_account]['ALIAS']);
  52. $v_fwd = str_replace(',', "\n", $data[$v_account]['FWD']);
  53. $vfwd = explode(",", $data[$v_account]['FWD']);
  54. $v_fwd_only = $data[$v_account]['FWD_ONLY'];
  55. $v_quota = $data[$v_account]['QUOTA'];
  56. $v_autoreply = $data[$v_account]['AUTOREPLY'];
  57. $v_suspended = $data[$v_account]['SUSPENDED'];
  58. if ( $v_suspended == 'yes' ) {
  59. $v_status = 'suspended';
  60. } else {
  61. $v_status = 'active';
  62. }
  63. $v_date = $data[$v_account]['DATE'];
  64. $v_time = $data[$v_account]['TIME'];
  65. // Parse autoreply
  66. if ( $v_autoreply == 'yes' ) {
  67. exec (VESTA_CMD."v-list-mail-account-autoreply ".$user." '".$v_domain."' '".$v_account."' json", $output, $return_var);
  68. $autoreply_str = json_decode(implode('', $output), true);
  69. unset($output);
  70. $v_autoreply_message = $autoreply_str[$v_account]['MSG'];
  71. }
  72. }
  73. // Check POST request for mail domain
  74. if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (empty($_GET['account']))) {
  75. $v_domain = escapeshellarg($_POST['v_domain']);
  76. // Check token
  77. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  78. header('location: /login/');
  79. exit();
  80. }
  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. // Check token
  154. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  155. header('location: /login/');
  156. exit();
  157. }
  158. $v_domain = escapeshellarg($_POST['v_domain']);
  159. $v_account = escapeshellarg($_POST['v_account']);
  160. // Change password
  161. if ((!empty($_POST['v_password'])) && (empty($_SESSION['error_msg']))) {
  162. $v_password = tempnam("/tmp","vst");
  163. $fp = fopen($v_password, "w");
  164. fwrite($fp, $_POST['v_password']."\n");
  165. fclose($fp);
  166. exec (VESTA_CMD."v-change-mail-account-password ".$v_username." ".$v_domain." ".$v_account." ".$v_password, $output, $return_var);
  167. check_return_code($return_var,$output);
  168. unset($output);
  169. unlink($v_password);
  170. $v_password = escapeshellarg($_POST['v_password']);;
  171. }
  172. // Change quota
  173. if (($v_quota != $_POST['v_quota']) && (empty($_SESSION['error_msg']))) {
  174. if (empty($_POST['v_quota'])) {
  175. $v_quota = 0;
  176. } else {
  177. $v_quota = escapeshellarg($_POST['v_quota']);
  178. }
  179. exec (VESTA_CMD."v-change-mail-account-quota ".$v_username." ".$v_domain." ".$v_account." ".$v_quota, $output, $return_var);
  180. check_return_code($return_var,$output);
  181. unset($output);
  182. }
  183. // Change account aliases
  184. if (empty($_SESSION['error_msg'])) {
  185. $waliases = preg_replace("/\n/", " ", $_POST['v_aliases']);
  186. $waliases = preg_replace("/,/", " ", $waliases);
  187. $waliases = preg_replace('/\s+/', ' ',$waliases);
  188. $waliases = trim($waliases);
  189. $aliases = explode(" ", $waliases);
  190. $v_aliases = str_replace(' ', "\n", $waliases);
  191. $result = array_diff($valiases, $aliases);
  192. foreach ($result as $alias) {
  193. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  194. exec (VESTA_CMD."v-delete-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." '".$alias."'", $output, $return_var);
  195. check_return_code($return_var,$output);
  196. unset($output);
  197. }
  198. }
  199. $result = array_diff($aliases, $valiases);
  200. foreach ($result as $alias) {
  201. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  202. exec (VESTA_CMD."v-add-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." ".escapeshellarg($alias), $output, $return_var);
  203. check_return_code($return_var,$output);
  204. unset($output);
  205. }
  206. }
  207. }
  208. // Change forwarders
  209. if (empty($_SESSION['error_msg'])) {
  210. $wfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
  211. $wfwd = preg_replace("/,/", " ", $wfwd);
  212. $wfwd = preg_replace('/\s+/', ' ',$wfwd);
  213. $wfwd = trim($wfwd);
  214. $fwd = explode(" ", $wfwd);
  215. $v_fwd = str_replace(' ', "\n", $wfwd);
  216. $result = array_diff($vfwd, $fwd);
  217. foreach ($result as $forward) {
  218. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  219. exec (VESTA_CMD."v-delete-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var);
  220. check_return_code($return_var,$output);
  221. unset($output);
  222. }
  223. }
  224. $result = array_diff($fwd, $vfwd);
  225. foreach ($result as $forward) {
  226. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  227. exec (VESTA_CMD."v-add-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." ".escapeshellarg($forward), $output, $return_var);
  228. check_return_code($return_var,$output);
  229. unset($output);
  230. }
  231. }
  232. }
  233. // Delete FWD_ONLY flag
  234. if (($v_fwd_only == 'yes') && (empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  235. exec (VESTA_CMD."v-delete-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
  236. check_return_code($return_var,$output);
  237. unset($output);
  238. $v_fwd_only = '';
  239. }
  240. // Add FWD_ONLY flag
  241. if (($v_fwd_only != 'yes') && (!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  242. exec (VESTA_CMD."v-add-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
  243. check_return_code($return_var,$output);
  244. unset($output);
  245. $v_fwd_only = 'yes';
  246. }
  247. // Delete autoreply
  248. if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  249. exec (VESTA_CMD."v-delete-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
  250. check_return_code($return_var,$output);
  251. unset($output);
  252. $v_autoreply = 'no';
  253. $v_autoreply_message = '';
  254. }
  255. // Add autoreply
  256. if ((!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  257. if ( $v_autoreply_message != str_replace("\r\n", "\n", $_POST['v_autoreply_message'])) {
  258. $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
  259. $v_autoreply_message = escapeshellarg($v_autoreply_message);
  260. exec (VESTA_CMD."v-add-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account." ".$v_autoreply_message, $output, $return_var);
  261. check_return_code($return_var,$output);
  262. unset($output);
  263. $v_autoreply = 'yes';
  264. $v_autoreply_message = $_POST['v_autoreply_message'];
  265. }
  266. }
  267. // Set success message
  268. if (empty($_SESSION['error_msg'])) {
  269. $_SESSION['ok_msg'] = __('Changes has been saved.');
  270. }
  271. }
  272. // Render page
  273. if (empty($_GET['account'])) {
  274. // Display body for mail domain
  275. render_page($user, $TAB, 'edit_mail');
  276. } else {
  277. // Display body for mail account
  278. render_page($user, $TAB, 'edit_mail_acc');
  279. }
  280. // Flush session messages
  281. unset($_SESSION['error_msg']);
  282. unset($_SESSION['ok_msg']);