index.php 22 KB

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