index.php 24 KB

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