index.php 21 KB

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