index.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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. // Get all user domains
  18. exec (HESTIA_CMD."v-list-mail-domains ".escapeshellarg($user)." json", $output, $return_var);
  19. $user_domains = json_decode(implode('', $output), true);
  20. $user_domains = array_keys($user_domains);
  21. unset($output);
  22. // List mail domain
  23. if ((!empty($_GET['domain'])) && (empty($_GET['account']))) {
  24. $v_domain = $_GET['domain'];
  25. if(!in_array($v_domain, $user_domains)) {
  26. header("Location: /list/mail/");
  27. exit;
  28. }
  29. exec (HESTIA_CMD."v-list-mail-domain ".$user." ".escapeshellarg($v_domain)." json", $output, $return_var);
  30. $data = json_decode(implode('', $output), true);
  31. unset($output);
  32. // Parse domain
  33. $v_antispam = $data[$v_domain]['ANTISPAM'];
  34. $v_antivirus = $data[$v_domain]['ANTIVIRUS'];
  35. $v_dkim = $data[$v_domain]['DKIM'];
  36. $v_catchall = $data[$v_domain]['CATCHALL'];
  37. $v_date = $data[$v_domain]['DATE'];
  38. $v_time = $data[$v_domain]['TIME'];
  39. $v_suspended = $data[$v_domain]['SUSPENDED'];
  40. $v_webmail_alias = $data[$v_domain]['WEBMAIL_ALIAS'];
  41. if ( $v_suspended == 'yes' ) {
  42. $v_status = 'suspended';
  43. } else {
  44. $v_status = 'active';
  45. }
  46. $v_ssl = $data[$v_domain]['SSL'];
  47. if (!empty($v_ssl)) {
  48. exec (HESTIA_CMD."v-list-mail-domain-ssl ".$user." ".escapeshellarg($v_domain)." json", $output, $return_var);
  49. $ssl_str = json_decode(implode('', $output), true);
  50. unset($output);
  51. $v_ssl_crt = $ssl_str[$v_domain]['CRT'];
  52. $v_ssl_key = $ssl_str[$v_domain]['KEY'];
  53. $v_ssl_ca = $ssl_str[$v_domain]['CA'];
  54. $v_ssl_subject = $ssl_str[$v_domain]['SUBJECT'];
  55. $v_ssl_aliases = $ssl_str[$v_domain]['ALIASES'];
  56. $v_ssl_not_before = $ssl_str[$v_domain]['NOT_BEFORE'];
  57. $v_ssl_not_after = $ssl_str[$v_domain]['NOT_AFTER'];
  58. $v_ssl_signature = $ssl_str[$v_domain]['SIGNATURE'];
  59. $v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY'];
  60. $v_ssl_issuer = $ssl_str[$v_domain]['ISSUER'];
  61. }
  62. $v_letsencrypt = $data[$v_domain]['LETSENCRYPT'];
  63. if (empty($v_letsencrypt)) $v_letsencrypt = 'no';
  64. }
  65. // List mail account
  66. if ((!empty($_GET['domain'])) && (!empty($_GET['account']))) {
  67. $v_domain = $_GET['domain'];
  68. if(!in_array($v_domain, $user_domains)) {
  69. header("Location: /list/mail/");
  70. exit;
  71. }
  72. $v_account = $_GET['account'];
  73. exec (HESTIA_CMD."v-list-mail-account ".$user." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." 'json'", $output, $return_var);
  74. $data = json_decode(implode('', $output), true);
  75. unset($output);
  76. // Parse mail account
  77. $v_username = $user;
  78. $v_password = "";
  79. $v_aliases = str_replace(',', "\n", $data[$v_account]['ALIAS']);
  80. $valiases = explode(",", $data[$v_account]['ALIAS']);
  81. $v_fwd = str_replace(',', "\n", $data[$v_account]['FWD']);
  82. $vfwd = explode(",", $data[$v_account]['FWD']);
  83. $v_fwd_only = $data[$v_account]['FWD_ONLY'];
  84. $v_quota = $data[$v_account]['QUOTA'];
  85. $v_autoreply = $data[$v_account]['AUTOREPLY'];
  86. $v_suspended = $data[$v_account]['SUSPENDED'];
  87. $v_webmail_alias = $data[$v_account]['WEBMAIL_ALIAS'];
  88. if ( $v_suspended == 'yes' ) {
  89. $v_status = 'suspended';
  90. } else {
  91. $v_status = 'active';
  92. }
  93. $v_date = $data[$v_account]['DATE'];
  94. $v_time = $data[$v_account]['TIME'];
  95. // Parse autoreply
  96. if ( $v_autoreply == 'yes' ) {
  97. exec (HESTIA_CMD."v-list-mail-account-autoreply ".$user." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." json", $output, $return_var);
  98. $autoreply_str = json_decode(implode('', $output), true);
  99. unset($output);
  100. $v_autoreply_message = $autoreply_str[$v_account]['MSG'];
  101. $v_autoreply_message=str_replace("\\n", "\n", $v_autoreply_message);
  102. }
  103. }
  104. // Check POST request for mail domain
  105. if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (empty($_GET['account']))) {
  106. $v_domain = $_POST['v_domain'];
  107. if(!in_array($v_domain, $user_domains)) {
  108. check_return_code(3, ["Unknown domain"]);
  109. }
  110. // Check token
  111. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  112. header('location: /login/');
  113. exit();
  114. }
  115. // Delete antispam
  116. if (($v_antispam == 'yes') && (empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
  117. exec (HESTIA_CMD."v-delete-mail-domain-antispam ".$v_username." ".escapeshellarg($v_domain), $output, $return_var);
  118. check_return_code($return_var,$output);
  119. $v_antispam = 'no';
  120. unset($output);
  121. }
  122. // Add antispam
  123. if (($v_antispam == 'no') && (!empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
  124. exec (HESTIA_CMD."v-add-mail-domain-antispam ".$v_username." ".escapeshellarg($v_domain), $output, $return_var);
  125. check_return_code($return_var,$output);
  126. $v_antispam = 'yes';
  127. unset($output);
  128. }
  129. // Delete antivirus
  130. if (($v_antivirus == 'yes') && (empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
  131. exec (HESTIA_CMD."v-delete-mail-domain-antivirus ".$v_username." ".escapeshellarg($v_domain), $output, $return_var);
  132. check_return_code($return_var,$output);
  133. $v_antivirus = 'no';
  134. unset($output);
  135. }
  136. // Add antivirs
  137. if (($v_antivirus == 'no') && (!empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
  138. exec (HESTIA_CMD."v-add-mail-domain-antivirus ".$v_username." ".escapeshellarg($v_domain), $output, $return_var);
  139. check_return_code($return_var,$output);
  140. $v_antivirus = 'yes';
  141. unset($output);
  142. }
  143. // Delete DKIM
  144. if (($v_dkim == 'yes') && (empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
  145. exec (HESTIA_CMD."v-delete-mail-domain-dkim ".$v_username." ".escapeshellarg($v_domain), $output, $return_var);
  146. check_return_code($return_var,$output);
  147. $v_dkim = 'no';
  148. unset($output);
  149. }
  150. // Add DKIM
  151. if (($v_dkim == 'no') && (!empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
  152. exec (HESTIA_CMD."v-add-mail-domain-dkim ".$v_username." ".escapeshellarg($v_domain), $output, $return_var);
  153. check_return_code($return_var,$output);
  154. $v_dkim = 'yes';
  155. unset($output);
  156. }
  157. // Delete catchall
  158. if ((!empty($v_catchall)) && (empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  159. exec (HESTIA_CMD."v-delete-mail-domain-catchall ".$v_username." ".escapeshellarg($v_domain), $output, $return_var);
  160. check_return_code($return_var,$output);
  161. $v_catchall = '';
  162. unset($output);
  163. }
  164. // Change catchall address
  165. if ((!empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  166. if ($v_catchall != $_POST['v_catchall']) {
  167. $v_catchall = escapeshellarg($_POST['v_catchall']);
  168. exec (HESTIA_CMD."v-change-mail-domain-catchall ".$v_username." ".escapeshellarg($v_domain)." ".$v_catchall, $output, $return_var);
  169. check_return_code($return_var,$output);
  170. unset($output);
  171. }
  172. }
  173. // Add catchall
  174. if ((empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  175. $v_catchall = escapeshellarg($_POST['v_catchall']);
  176. exec (HESTIA_CMD."v-add-mail-domain-catchall ".$v_username." ".escapeshellarg($v_domain)." ".$v_catchall, $output, $return_var);
  177. check_return_code($return_var,$output);
  178. unset($output);
  179. }
  180. // Change SSL certificate
  181. if (( $v_letsencrypt == 'no' ) && (empty($_POST['v_letsencrypt'])) && ( $v_ssl == 'yes' ) && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
  182. if (( $v_ssl_crt != str_replace("\r\n", "\n", $_POST['v_ssl_crt'])) || ( $v_ssl_key != str_replace("\r\n", "\n", $_POST['v_ssl_key'])) || ( $v_ssl_ca != str_replace("\r\n", "\n", $_POST['v_ssl_ca']))) {
  183. exec ('mktemp -d', $mktemp_output, $return_var);
  184. $tmpdir = $mktemp_output[0];
  185. // Certificate
  186. if (!empty($_POST['v_ssl_crt'])) {
  187. $fp = fopen($tmpdir."/".$v_domain.".crt", 'w');
  188. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt']));
  189. fwrite($fp, "\n");
  190. fclose($fp);
  191. }
  192. // Key
  193. if (!empty($_POST['v_ssl_key'])) {
  194. $fp = fopen($tmpdir."/".$v_domain.".key", 'w');
  195. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key']));
  196. fwrite($fp, "\n");
  197. fclose($fp);
  198. }
  199. // CA
  200. if (!empty($_POST['v_ssl_ca'])) {
  201. $fp = fopen($tmpdir."/".$v_domain.".ca", 'w');
  202. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca']));
  203. fwrite($fp, "\n");
  204. fclose($fp);
  205. }
  206. exec (HESTIA_CMD."v-change-mail-domain-sslcert ".$user." ".escapeshellarg($v_domain)." ".$tmpdir." 'no'", $output, $return_var);
  207. check_return_code($return_var,$output);
  208. unset($output);
  209. $restart_web = 'yes';
  210. $restart_proxy = 'yes';
  211. exec (HESTIA_CMD."v-list-mail-domain-ssl ".$user." ".escapeshellarg($v_domain)." json", $output, $return_var);
  212. $ssl_str = json_decode(implode('', $output), true);
  213. unset($output);
  214. $v_ssl_crt = $ssl_str[$v_domain]['CRT'];
  215. $v_ssl_key = $ssl_str[$v_domain]['KEY'];
  216. $v_ssl_ca = $ssl_str[$v_domain]['CA'];
  217. $v_ssl_subject = $ssl_str[$v_domain]['SUBJECT'];
  218. $v_ssl_aliases = $ssl_str[$v_domain]['ALIASES'];
  219. $v_ssl_not_before = $ssl_str[$v_domain]['NOT_BEFORE'];
  220. $v_ssl_not_after = $ssl_str[$v_domain]['NOT_AFTER'];
  221. $v_ssl_signature = $ssl_str[$v_domain]['SIGNATURE'];
  222. $v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY'];
  223. $v_ssl_issuer = $ssl_str[$v_domain]['ISSUER'];
  224. // Cleanup certificate tempfiles
  225. if (!empty($_POST['v_ssl_crt'])) unlink($tmpdir."/".$v_domain.".crt");
  226. if (!empty($_POST['v_ssl_key'])) unlink($tmpdir."/".$v_domain.".key");
  227. if (!empty($_POST['v_ssl_ca'])) unlink($tmpdir."/".$v_domain.".ca");
  228. rmdir($tmpdir);
  229. }
  230. }
  231. // Delete Lets Encrypt support
  232. if (( $v_letsencrypt == 'yes' ) && (empty($_POST['v_letsencrypt'])) && (empty($_SESSION['error_msg']))) {
  233. exec (HESTIA_CMD."v-delete-letsencrypt-domain ".$user." ".escapeshellarg($v_domain)." ' ' 'yes'", $output, $return_var);
  234. check_return_code($return_var,$output);
  235. unset($output);
  236. $v_ssl_crt = '';
  237. $v_ssl_key = '';
  238. $v_ssl_ca = '';
  239. $v_letsencrypt = 'no';
  240. $v_letsencrypt_deleted = 'yes';
  241. $v_ssl = 'no';
  242. $restart_mail = 'yes';
  243. }
  244. // Delete SSL certificate
  245. if (( $v_ssl == 'yes' ) && (empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
  246. exec (HESTIA_CMD."v-delete-mail-domain-ssl ".$v_username." ".escapeshellarg($v_domain), $output, $return_var);
  247. check_return_code($return_var,$output);
  248. unset($output);
  249. $v_ssl_crt = '';
  250. $v_ssl_key = '';
  251. $v_ssl_ca = '';
  252. $v_ssl = 'no';
  253. $restart_mail = 'yes';
  254. }
  255. // Add Lets Encrypt support
  256. if ((!empty($_POST['v_ssl'])) && ( $v_letsencrypt == 'no' ) && (!empty($_POST['v_letsencrypt'])) && empty($_SESSION['error_msg'])) {
  257. exec (HESTIA_CMD."v-add-letsencrypt-domain ".$user." ".escapeshellarg($v_domain)." ' ' 'yes'", $output, $return_var);
  258. check_return_code($return_var,$output);
  259. unset($output);
  260. $v_letsencrypt = 'yes';
  261. $v_ssl = 'yes';
  262. $restart_mail = 'yes';
  263. }
  264. // Add SSL certificate
  265. if (( $v_ssl == 'no' ) && (!empty($_POST['v_ssl'])) && (empty($v_letsencrypt_deleted)) && (empty($_SESSION['error_msg']))) {
  266. if (empty($_POST['v_ssl_crt'])) $errors[] = 'ssl certificate';
  267. if (empty($_POST['v_ssl_key'])) $errors[] = 'ssl key';
  268. if (!empty($errors[0])) {
  269. foreach ($errors as $i => $error) {
  270. if ( $i == 0 ) {
  271. $error_msg = $error;
  272. } else {
  273. $error_msg = $error_msg.", ".$error;
  274. }
  275. }
  276. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  277. } else {
  278. exec ('mktemp -d', $mktemp_output, $return_var);
  279. $tmpdir = $mktemp_output[0];
  280. // Certificate
  281. if (!empty($_POST['v_ssl_crt'])) {
  282. $fp = fopen($tmpdir."/".$v_domain.".crt", 'w');
  283. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt']));
  284. fclose($fp);
  285. }
  286. // Key
  287. if (!empty($_POST['v_ssl_key'])) {
  288. $fp = fopen($tmpdir."/".$v_domain.".key", 'w');
  289. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key']));
  290. fclose($fp);
  291. }
  292. // CA
  293. if (!empty($_POST['v_ssl_ca'])) {
  294. $fp = fopen($tmpdir."/".$v_domain.".ca", 'w');
  295. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca']));
  296. fclose($fp);
  297. }
  298. exec (HESTIA_CMD."v-add-mail-domain-ssl ".$user." ".escapeshellarg($v_domain)." ".$tmpdir." 'no'", $output, $return_var);
  299. check_return_code($return_var,$output);
  300. unset($output);
  301. $v_ssl = 'yes';
  302. $restart_web = 'yes';
  303. $restart_proxy = 'yes';
  304. exec (HESTIA_CMD."v-list-mail-domain-ssl ".$user." ".escapeshellarg($v_domain)." json", $output, $return_var);
  305. $ssl_str = json_decode(implode('', $output), true);
  306. unset($output);
  307. $v_ssl_crt = $ssl_str[$v_domain]['CRT'];
  308. $v_ssl_key = $ssl_str[$v_domain]['KEY'];
  309. $v_ssl_ca = $ssl_str[$v_domain]['CA'];
  310. $v_ssl_subject = $ssl_str[$v_domain]['SUBJECT'];
  311. $v_ssl_aliases = $ssl_str[$v_domain]['ALIASES'];
  312. $v_ssl_not_before = $ssl_str[$v_domain]['NOT_BEFORE'];
  313. $v_ssl_not_after = $ssl_str[$v_domain]['NOT_AFTER'];
  314. $v_ssl_signature = $ssl_str[$v_domain]['SIGNATURE'];
  315. $v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY'];
  316. $v_ssl_issuer = $ssl_str[$v_domain]['ISSUER'];
  317. // Cleanup certificate tempfiles
  318. if (!empty($_POST['v_ssl_crt'])) unlink($tmpdir."/".$v_domain.".crt");
  319. if (!empty($_POST['v_ssl_key'])) unlink($tmpdir."/".$v_domain.".key");
  320. if (!empty($_POST['v_ssl_ca'])) unlink($tmpdir."/".$v_domain.".ca");
  321. rmdir($tmpdir);
  322. }
  323. }
  324. // Set success message
  325. if (empty($_SESSION['error_msg'])) {
  326. $_SESSION['ok_msg'] = __('Changes has been saved.');
  327. }
  328. }
  329. // Check POST request for mail account
  330. if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (!empty($_GET['account']))) {
  331. // Check token
  332. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  333. header('location: /login/');
  334. exit();
  335. }
  336. // Validate email
  337. if ((!empty($_POST['v_send_email'])) && (empty($_SESSION['error_msg']))) {
  338. if (!filter_var($_POST['v_send_email'], FILTER_VALIDATE_EMAIL)) {
  339. $_SESSION['error_msg'] = __('Please enter valid email address.');
  340. }
  341. }
  342. $v_domain = $_POST['v_domain'];
  343. if(!in_array($v_domain, $user_domains)) {
  344. check_return_code(3, ["Unknown domain"]);
  345. }
  346. $v_account = $_POST['v_account'];
  347. $v_send_email = $_POST['v_send_email'];
  348. $v_credentials = $_POST['v_credentials'];
  349. // Change password
  350. if ((!empty($_POST['v_password'])) && (empty($_SESSION['error_msg']))) {
  351. $v_password = tempnam("/tmp","vst");
  352. $fp = fopen($v_password, "w");
  353. fwrite($fp, $_POST['v_password']."\n");
  354. fclose($fp);
  355. exec (HESTIA_CMD."v-change-mail-account-password ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_password, $output, $return_var);
  356. check_return_code($return_var,$output);
  357. unset($output);
  358. unlink($v_password);
  359. $v_password = escapeshellarg($_POST['v_password']);;
  360. }
  361. // Change quota
  362. if (($v_quota != $_POST['v_quota']) && (empty($_SESSION['error_msg']))) {
  363. if (empty($_POST['v_quota'])) {
  364. $v_quota = 0;
  365. } else {
  366. $v_quota = escapeshellarg($_POST['v_quota']);
  367. }
  368. exec (HESTIA_CMD."v-change-mail-account-quota ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_quota, $output, $return_var);
  369. check_return_code($return_var,$output);
  370. unset($output);
  371. }
  372. // Change account aliases
  373. if (empty($_SESSION['error_msg'])) {
  374. $waliases = preg_replace("/\n/", " ", $_POST['v_aliases']);
  375. $waliases = preg_replace("/,/", " ", $waliases);
  376. $waliases = preg_replace('/\s+/', ' ',$waliases);
  377. $waliases = trim($waliases);
  378. $aliases = explode(" ", $waliases);
  379. $v_aliases = str_replace(' ', "\n", $waliases);
  380. $result = array_diff($valiases, $aliases);
  381. foreach ($result as $alias) {
  382. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  383. exec (HESTIA_CMD."v-delete-mail-account-alias ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($alias), $output, $return_var);
  384. check_return_code($return_var,$output);
  385. unset($output);
  386. }
  387. }
  388. $result = array_diff($aliases, $valiases);
  389. foreach ($result as $alias) {
  390. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  391. exec (HESTIA_CMD."v-add-mail-account-alias ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($alias), $output, $return_var);
  392. check_return_code($return_var,$output);
  393. unset($output);
  394. }
  395. }
  396. }
  397. // Change forwarders
  398. if (empty($_SESSION['error_msg'])) {
  399. $wfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
  400. $wfwd = preg_replace("/,/", " ", $wfwd);
  401. $wfwd = preg_replace('/\s+/', ' ',$wfwd);
  402. $wfwd = trim($wfwd);
  403. $fwd = explode(" ", $wfwd);
  404. $v_fwd = str_replace(' ', "\n", $wfwd);
  405. $result = array_diff($vfwd, $fwd);
  406. foreach ($result as $forward) {
  407. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  408. exec (HESTIA_CMD."v-delete-mail-account-forward ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($forward), $output, $return_var);
  409. check_return_code($return_var,$output);
  410. unset($output);
  411. }
  412. }
  413. $result = array_diff($fwd, $vfwd);
  414. foreach ($result as $forward) {
  415. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  416. exec (HESTIA_CMD."v-add-mail-account-forward ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($forward), $output, $return_var);
  417. check_return_code($return_var,$output);
  418. unset($output);
  419. }
  420. }
  421. }
  422. // Delete FWD_ONLY flag
  423. if (($v_fwd_only == 'yes') && (empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  424. exec (HESTIA_CMD."v-delete-mail-account-fwd-only ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var);
  425. check_return_code($return_var,$output);
  426. unset($output);
  427. $v_fwd_only = '';
  428. }
  429. // Add FWD_ONLY flag
  430. if (($v_fwd_only != 'yes') && (!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  431. exec (HESTIA_CMD."v-add-mail-account-fwd-only ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var);
  432. check_return_code($return_var,$output);
  433. unset($output);
  434. $v_fwd_only = 'yes';
  435. }
  436. // Delete autoreply
  437. if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  438. exec (HESTIA_CMD."v-delete-mail-account-autoreply ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var);
  439. check_return_code($return_var,$output);
  440. unset($output);
  441. $v_autoreply = 'no';
  442. $v_autoreply_message = '';
  443. }
  444. // Add autoreply
  445. if ((!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  446. if ( $v_autoreply_message != str_replace("\r\n", "\n", $_POST['v_autoreply_message'])) {
  447. $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
  448. $v_autoreply_message = escapeshellarg($v_autoreply_message);
  449. exec (HESTIA_CMD."v-add-mail-account-autoreply ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_autoreply_message, $output, $return_var);
  450. check_return_code($return_var,$output);
  451. unset($output);
  452. $v_autoreply = 'yes';
  453. $v_autoreply_message = $_POST['v_autoreply_message'];
  454. }
  455. }
  456. // Email login credentials
  457. if ((!empty($v_send_email)) && (empty($_SESSION['error_msg']))) {
  458. $to = $v_send_email;
  459. $subject = __("Email Credentials");
  460. $hostname = exec('hostname');
  461. $from = __('MAIL_FROM', $hostname);
  462. $mailtext = $v_credentials;
  463. send_email($to, $subject, $mailtext, $from);
  464. }
  465. // Set success message
  466. if (empty($_SESSION['error_msg'])) {
  467. $_SESSION['ok_msg'] = __('Changes has been saved.');
  468. }
  469. }
  470. // Render page
  471. if (empty($_GET['account'])) {
  472. // Display body for mail domain
  473. render_page($user, $TAB, 'edit_mail');
  474. } else {
  475. // Display body for mail account
  476. render_page($user, $TAB, 'edit_mail_acc');
  477. }
  478. // Flush session messages
  479. unset($_SESSION['error_msg']);
  480. unset($_SESSION['ok_msg']);