index.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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($_POST['v_ssl'])) && (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. if (!validate_password($_POST['v_password'])) {
  352. $_SESSION['error_msg'] = __('Password does not match the minimum requirements');
  353. }else{
  354. $v_password = tempnam("/tmp","vst");
  355. $fp = fopen($v_password, "w");
  356. fwrite($fp, $_POST['v_password']."\n");
  357. fclose($fp);
  358. exec (HESTIA_CMD."v-change-mail-account-password ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_password, $output, $return_var);
  359. check_return_code($return_var,$output);
  360. unset($output);
  361. unlink($v_password);
  362. $v_password = escapeshellarg($_POST['v_password']);
  363. }
  364. }
  365. // Change quota
  366. if (($v_quota != $_POST['v_quota']) && (empty($_SESSION['error_msg']))) {
  367. if (empty($_POST['v_quota'])) {
  368. $v_quota = 0;
  369. } else {
  370. $v_quota = escapeshellarg($_POST['v_quota']);
  371. }
  372. exec (HESTIA_CMD."v-change-mail-account-quota ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_quota, $output, $return_var);
  373. check_return_code($return_var,$output);
  374. unset($output);
  375. }
  376. // Change account aliases
  377. if (empty($_SESSION['error_msg'])) {
  378. $waliases = preg_replace("/\n/", " ", $_POST['v_aliases']);
  379. $waliases = preg_replace("/,/", " ", $waliases);
  380. $waliases = preg_replace('/\s+/', ' ',$waliases);
  381. $waliases = trim($waliases);
  382. $aliases = explode(" ", $waliases);
  383. $v_aliases = str_replace(' ', "\n", $waliases);
  384. $result = array_diff($valiases, $aliases);
  385. foreach ($result as $alias) {
  386. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  387. exec (HESTIA_CMD."v-delete-mail-account-alias ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($alias), $output, $return_var);
  388. check_return_code($return_var,$output);
  389. unset($output);
  390. }
  391. }
  392. $result = array_diff($aliases, $valiases);
  393. foreach ($result as $alias) {
  394. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  395. exec (HESTIA_CMD."v-add-mail-account-alias ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($alias), $output, $return_var);
  396. check_return_code($return_var,$output);
  397. unset($output);
  398. }
  399. }
  400. }
  401. // Change forwarders
  402. if (empty($_SESSION['error_msg'])) {
  403. $wfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
  404. $wfwd = preg_replace("/,/", " ", $wfwd);
  405. $wfwd = preg_replace('/\s+/', ' ',$wfwd);
  406. $wfwd = trim($wfwd);
  407. $fwd = explode(" ", $wfwd);
  408. $v_fwd = str_replace(' ', "\n", $wfwd);
  409. $result = array_diff($vfwd, $fwd);
  410. foreach ($result as $forward) {
  411. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  412. exec (HESTIA_CMD."v-delete-mail-account-forward ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($forward), $output, $return_var);
  413. check_return_code($return_var,$output);
  414. unset($output);
  415. }
  416. }
  417. $result = array_diff($fwd, $vfwd);
  418. foreach ($result as $forward) {
  419. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  420. exec (HESTIA_CMD."v-add-mail-account-forward ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($forward), $output, $return_var);
  421. check_return_code($return_var,$output);
  422. unset($output);
  423. }
  424. }
  425. }
  426. // Delete FWD_ONLY flag
  427. if (($v_fwd_only == 'yes') && (empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  428. exec (HESTIA_CMD."v-delete-mail-account-fwd-only ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var);
  429. check_return_code($return_var,$output);
  430. unset($output);
  431. $v_fwd_only = '';
  432. }
  433. // Add FWD_ONLY flag
  434. if (($v_fwd_only != 'yes') && (!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  435. exec (HESTIA_CMD."v-add-mail-account-fwd-only ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var);
  436. check_return_code($return_var,$output);
  437. unset($output);
  438. $v_fwd_only = 'yes';
  439. }
  440. // Delete autoreply
  441. if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  442. exec (HESTIA_CMD."v-delete-mail-account-autoreply ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var);
  443. check_return_code($return_var,$output);
  444. unset($output);
  445. $v_autoreply = 'no';
  446. $v_autoreply_message = '';
  447. }
  448. // Add autoreply
  449. if ((!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  450. if ( $v_autoreply_message != str_replace("\r\n", "\n", $_POST['v_autoreply_message'])) {
  451. $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
  452. $v_autoreply_message = escapeshellarg($v_autoreply_message);
  453. exec (HESTIA_CMD."v-add-mail-account-autoreply ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_autoreply_message, $output, $return_var);
  454. check_return_code($return_var,$output);
  455. unset($output);
  456. $v_autoreply = 'yes';
  457. $v_autoreply_message = $_POST['v_autoreply_message'];
  458. }
  459. }
  460. // Email login credentials
  461. if ((!empty($v_send_email)) && (empty($_SESSION['error_msg']))) {
  462. $to = $v_send_email;
  463. $subject = _("Email Credentials");
  464. $hostname = exec('hostname');
  465. $from = sprintf(_('MAIL_FROM'), $hostname);
  466. $mailtext = $v_credentials;
  467. send_email($to, $subject, $mailtext, $from);
  468. }
  469. // Set success message
  470. if (empty($_SESSION['error_msg'])) {
  471. $_SESSION['ok_msg'] = _('Changes has been saved.');
  472. }
  473. }
  474. // Render page
  475. if (empty($_GET['account'])) {
  476. // Display body for mail domain
  477. render_page($user, $TAB, 'edit_mail');
  478. } else {
  479. // Display body for mail account
  480. render_page($user, $TAB, 'edit_mail_acc');
  481. }
  482. // Flush session messages
  483. unset($_SESSION['error_msg']);
  484. unset($_SESSION['ok_msg']);