index.php 23 KB

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