index.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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. if (empty($_SESSION['error_msg'])) {
  192. if (!empty($_POST['v_webmail'])) {
  193. $v_webmail = escapeshellarg($_POST['v_webmail']);
  194. exec (HESTIA_CMD."v-add-sys-webmail ".$user." ".$v_domain." ".$v_webmail." yes", $output, $return_var);
  195. check_return_code($return_var,$output);
  196. unset($output);
  197. }
  198. }
  199. }
  200. if (empty($_POST['v_webmail'])) {
  201. if (empty($_SESSION['error_msg'])) {
  202. exec (HESTIA_CMD."v-delete-sys-webmail ".$user." ".$v_domain." yes", $output, $return_var);
  203. check_return_code($return_var,$output);
  204. $v_webmail = "";
  205. unset($output);
  206. }
  207. }
  208. // Change SSL certificate
  209. if (( $v_letsencrypt == 'no' ) && (empty($_POST['v_letsencrypt'])) && ( $v_ssl == 'yes' ) && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
  210. 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']))) {
  211. exec ('mktemp -d', $mktemp_output, $return_var);
  212. $tmpdir = $mktemp_output[0];
  213. // Certificate
  214. if (!empty($_POST['v_ssl_crt'])) {
  215. $fp = fopen($tmpdir."/".$v_domain.".crt", 'w');
  216. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt']));
  217. fwrite($fp, "\n");
  218. fclose($fp);
  219. }
  220. // Key
  221. if (!empty($_POST['v_ssl_key'])) {
  222. $fp = fopen($tmpdir."/".$v_domain.".key", 'w');
  223. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key']));
  224. fwrite($fp, "\n");
  225. fclose($fp);
  226. }
  227. // CA
  228. if (!empty($_POST['v_ssl_ca'])) {
  229. $fp = fopen($tmpdir."/".$v_domain.".ca", 'w');
  230. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca']));
  231. fwrite($fp, "\n");
  232. fclose($fp);
  233. }
  234. exec (HESTIA_CMD."v-change-mail-domain-sslcert ".$user." ".escapeshellarg($v_domain)." ".$tmpdir." 'no'", $output, $return_var);
  235. check_return_code($return_var,$output);
  236. unset($output);
  237. $restart_web = 'yes';
  238. $restart_proxy = 'yes';
  239. exec (HESTIA_CMD."v-list-mail-domain-ssl ".$user." ".escapeshellarg($v_domain)." json", $output, $return_var);
  240. $ssl_str = json_decode(implode('', $output), true);
  241. unset($output);
  242. $v_ssl_crt = $ssl_str[$v_domain]['CRT'];
  243. $v_ssl_key = $ssl_str[$v_domain]['KEY'];
  244. $v_ssl_ca = $ssl_str[$v_domain]['CA'];
  245. $v_ssl_subject = $ssl_str[$v_domain]['SUBJECT'];
  246. $v_ssl_aliases = $ssl_str[$v_domain]['ALIASES'];
  247. $v_ssl_not_before = $ssl_str[$v_domain]['NOT_BEFORE'];
  248. $v_ssl_not_after = $ssl_str[$v_domain]['NOT_AFTER'];
  249. $v_ssl_signature = $ssl_str[$v_domain]['SIGNATURE'];
  250. $v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY'];
  251. $v_ssl_issuer = $ssl_str[$v_domain]['ISSUER'];
  252. // Cleanup certificate tempfiles
  253. if (!empty($_POST['v_ssl_crt'])) unlink($tmpdir."/".$v_domain.".crt");
  254. if (!empty($_POST['v_ssl_key'])) unlink($tmpdir."/".$v_domain.".key");
  255. if (!empty($_POST['v_ssl_ca'])) unlink($tmpdir."/".$v_domain.".ca");
  256. rmdir($tmpdir);
  257. }
  258. }
  259. // Delete Lets Encrypt support
  260. if (( $v_letsencrypt == 'yes' ) && (empty($_POST['v_letsencrypt']) || empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
  261. exec (HESTIA_CMD."v-delete-letsencrypt-domain ".$user." ".escapeshellarg($v_domain)." ' ' 'yes'", $output, $return_var);
  262. check_return_code($return_var,$output);
  263. unset($output);
  264. $v_ssl_crt = '';
  265. $v_ssl_key = '';
  266. $v_ssl_ca = '';
  267. $v_letsencrypt = 'no';
  268. $v_letsencrypt_deleted = 'yes';
  269. $v_ssl = 'no';
  270. $restart_mail = 'yes';
  271. }
  272. // Delete SSL certificate
  273. if (( $v_ssl == 'yes' ) && (empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
  274. exec (HESTIA_CMD."v-delete-mail-domain-ssl ".$v_username." ".escapeshellarg($v_domain), $output, $return_var);
  275. check_return_code($return_var,$output);
  276. unset($output);
  277. $v_ssl_crt = '';
  278. $v_ssl_key = '';
  279. $v_ssl_ca = '';
  280. $v_ssl = 'no';
  281. $restart_mail = 'yes';
  282. }
  283. // Add Lets Encrypt support
  284. if ((!empty($_POST['v_ssl'])) && ( $v_letsencrypt == 'no' ) && (!empty($_POST['v_letsencrypt'])) && empty($_SESSION['error_msg'])) {
  285. exec (HESTIA_CMD."v-add-letsencrypt-domain ".$user." ".escapeshellarg($v_domain)." ' ' 'yes'", $output, $return_var);
  286. check_return_code($return_var,$output);
  287. unset($output);
  288. $v_letsencrypt = 'yes';
  289. $v_ssl = 'yes';
  290. $restart_mail = 'yes';
  291. }
  292. // Add SSL certificate
  293. if (( $v_ssl == 'no' ) && (!empty($_POST['v_ssl'])) && (empty($v_letsencrypt_deleted)) && (empty($_SESSION['error_msg']))) {
  294. if (empty($_POST['v_ssl_crt'])) $errors[] = 'ssl certificate';
  295. if (empty($_POST['v_ssl_key'])) $errors[] = 'ssl key';
  296. if (!empty($errors[0])) {
  297. foreach ($errors as $i => $error) {
  298. if ( $i == 0 ) {
  299. $error_msg = $error;
  300. } else {
  301. $error_msg = $error_msg.", ".$error;
  302. }
  303. }
  304. $_SESSION['error_msg'] = _('Field "%s" can not be blank.',$error_msg);
  305. } else {
  306. exec ('mktemp -d', $mktemp_output, $return_var);
  307. $tmpdir = $mktemp_output[0];
  308. // Certificate
  309. if (!empty($_POST['v_ssl_crt'])) {
  310. $fp = fopen($tmpdir."/".$v_domain.".crt", 'w');
  311. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt']));
  312. fclose($fp);
  313. }
  314. // Key
  315. if (!empty($_POST['v_ssl_key'])) {
  316. $fp = fopen($tmpdir."/".$v_domain.".key", 'w');
  317. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key']));
  318. fclose($fp);
  319. }
  320. // CA
  321. if (!empty($_POST['v_ssl_ca'])) {
  322. $fp = fopen($tmpdir."/".$v_domain.".ca", 'w');
  323. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca']));
  324. fclose($fp);
  325. }
  326. exec (HESTIA_CMD."v-add-mail-domain-ssl ".$user." ".escapeshellarg($v_domain)." ".$tmpdir." 'no'", $output, $return_var);
  327. check_return_code($return_var,$output);
  328. unset($output);
  329. $v_ssl = 'yes';
  330. $restart_web = 'yes';
  331. $restart_proxy = 'yes';
  332. exec (HESTIA_CMD."v-list-mail-domain-ssl ".$user." ".escapeshellarg($v_domain)." json", $output, $return_var);
  333. $ssl_str = json_decode(implode('', $output), true);
  334. unset($output);
  335. $v_ssl_crt = $ssl_str[$v_domain]['CRT'];
  336. $v_ssl_key = $ssl_str[$v_domain]['KEY'];
  337. $v_ssl_ca = $ssl_str[$v_domain]['CA'];
  338. $v_ssl_subject = $ssl_str[$v_domain]['SUBJECT'];
  339. $v_ssl_aliases = $ssl_str[$v_domain]['ALIASES'];
  340. $v_ssl_not_before = $ssl_str[$v_domain]['NOT_BEFORE'];
  341. $v_ssl_not_after = $ssl_str[$v_domain]['NOT_AFTER'];
  342. $v_ssl_signature = $ssl_str[$v_domain]['SIGNATURE'];
  343. $v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY'];
  344. $v_ssl_issuer = $ssl_str[$v_domain]['ISSUER'];
  345. // Cleanup certificate tempfiles
  346. if (!empty($_POST['v_ssl_crt'])) unlink($tmpdir."/".$v_domain.".crt");
  347. if (!empty($_POST['v_ssl_key'])) unlink($tmpdir."/".$v_domain.".key");
  348. if (!empty($_POST['v_ssl_ca'])) unlink($tmpdir."/".$v_domain.".ca");
  349. rmdir($tmpdir);
  350. }
  351. }
  352. // Set success message
  353. if (empty($_SESSION['error_msg'])) {
  354. $_SESSION['ok_msg'] = _('Changes has been saved.');
  355. }
  356. }
  357. // Check POST request for mail account
  358. if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (!empty($_GET['account']))) {
  359. // Check token
  360. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  361. header('location: /login/');
  362. exit();
  363. }
  364. // Validate email
  365. if ((!empty($_POST['v_send_email'])) && (empty($_SESSION['error_msg']))) {
  366. if (!filter_var($_POST['v_send_email'], FILTER_VALIDATE_EMAIL)) {
  367. $_SESSION['error_msg'] = _('Please enter valid email address.');
  368. }
  369. }
  370. $v_domain = $_POST['v_domain'];
  371. if(!in_array($v_domain, $user_domains)) {
  372. check_return_code(3, ["Unknown domain"]);
  373. }
  374. $v_account = $_POST['v_account'];
  375. $v_send_email = $_POST['v_send_email'];
  376. $v_credentials = $_POST['v_credentials'];
  377. // Change password
  378. if ((!empty($_POST['v_password'])) && (empty($_SESSION['error_msg']))) {
  379. if (!validate_password($_POST['v_password'])) {
  380. $_SESSION['error_msg'] = _('Password does not match the minimum requirements');
  381. }else{
  382. $v_password = tempnam("/tmp","vst");
  383. $fp = fopen($v_password, "w");
  384. fwrite($fp, $_POST['v_password']."\n");
  385. fclose($fp);
  386. exec (HESTIA_CMD."v-change-mail-account-password ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_password, $output, $return_var);
  387. check_return_code($return_var,$output);
  388. unset($output);
  389. unlink($v_password);
  390. $v_password = escapeshellarg($_POST['v_password']);
  391. }
  392. }
  393. // Change quota
  394. if (($v_quota != $_POST['v_quota']) && (empty($_SESSION['error_msg']))) {
  395. if (empty($_POST['v_quota'])) {
  396. $v_quota = 0;
  397. } else {
  398. $v_quota = escapeshellarg($_POST['v_quota']);
  399. }
  400. exec (HESTIA_CMD."v-change-mail-account-quota ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_quota, $output, $return_var);
  401. check_return_code($return_var,$output);
  402. unset($output);
  403. }
  404. // Change account aliases
  405. if (empty($_SESSION['error_msg'])) {
  406. $waliases = preg_replace("/\n/", " ", $_POST['v_aliases']);
  407. $waliases = preg_replace("/,/", " ", $waliases);
  408. $waliases = preg_replace('/\s+/', ' ',$waliases);
  409. $waliases = trim($waliases);
  410. $aliases = explode(" ", $waliases);
  411. $v_aliases = str_replace(' ', "\n", $waliases);
  412. $result = array_diff($valiases, $aliases);
  413. foreach ($result as $alias) {
  414. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  415. exec (HESTIA_CMD."v-delete-mail-account-alias ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($alias), $output, $return_var);
  416. check_return_code($return_var,$output);
  417. unset($output);
  418. }
  419. }
  420. $result = array_diff($aliases, $valiases);
  421. foreach ($result as $alias) {
  422. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  423. exec (HESTIA_CMD."v-add-mail-account-alias ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($alias), $output, $return_var);
  424. check_return_code($return_var,$output);
  425. unset($output);
  426. }
  427. }
  428. }
  429. // Change forwarders to :blackhole:
  430. if (empty($_SESSION['error_msg']) && !empty($_POST['v_blackhole'])) {
  431. foreach ($vfwd 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. exec (HESTIA_CMD."v-add-mail-account-forward ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." :blackhole:", $output, $return_var);
  438. check_return_code($return_var,$output);
  439. unset($output);
  440. $v_fwd = '';
  441. $v_blackhole = "yes";
  442. }
  443. }
  444. // Change forwarders
  445. if (empty($_SESSION['error_msg']) && empty($_POST['v_blackhole'])) {
  446. $wfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
  447. $wfwd = preg_replace("/,/", " ", $wfwd);
  448. $wfwd = preg_replace('/\s+/', ' ',$wfwd);
  449. $wfwd = trim($wfwd);
  450. $fwd = explode(" ", $wfwd);
  451. $v_fwd = str_replace(' ', "\n", $wfwd);
  452. $result = array_diff($vfwd, $fwd);
  453. foreach ($result as $forward) {
  454. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  455. exec (HESTIA_CMD."v-delete-mail-account-forward ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($forward), $output, $return_var);
  456. check_return_code($return_var,$output);
  457. unset($output);
  458. }
  459. }
  460. $result = array_diff($fwd, $vfwd);
  461. foreach ($result as $forward) {
  462. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  463. exec (HESTIA_CMD."v-add-mail-account-forward ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($forward), $output, $return_var);
  464. check_return_code($return_var,$output);
  465. unset($output);
  466. }
  467. }
  468. $v_blackhole = "no";
  469. }
  470. // Delete FWD_ONLY flag
  471. if (($v_fwd_only == 'yes') && (empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  472. exec (HESTIA_CMD."v-delete-mail-account-fwd-only ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var);
  473. check_return_code($return_var,$output);
  474. unset($output);
  475. $v_fwd_only = '';
  476. }
  477. // Add FWD_ONLY flag
  478. if (($v_fwd_only != 'yes') && (!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  479. exec (HESTIA_CMD."v-add-mail-account-fwd-only ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var);
  480. check_return_code($return_var,$output);
  481. unset($output);
  482. $v_fwd_only = 'yes';
  483. }
  484. // Delete autoreply
  485. if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  486. exec (HESTIA_CMD."v-delete-mail-account-autoreply ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var);
  487. check_return_code($return_var,$output);
  488. unset($output);
  489. $v_autoreply = 'no';
  490. $v_autoreply_message = '';
  491. }
  492. // Add autoreply
  493. if ((!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  494. if ( $v_autoreply_message != str_replace("\r\n", "\n", $_POST['v_autoreply_message'])) {
  495. $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
  496. $v_autoreply_message = escapeshellarg($v_autoreply_message);
  497. exec (HESTIA_CMD."v-add-mail-account-autoreply ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_autoreply_message, $output, $return_var);
  498. check_return_code($return_var,$output);
  499. unset($output);
  500. $v_autoreply = 'yes';
  501. $v_autoreply_message = $_POST['v_autoreply_message'];
  502. }
  503. }
  504. // Email login credentials
  505. if ((!empty($v_send_email)) && (empty($_SESSION['error_msg']))) {
  506. $to = $v_send_email;
  507. $subject = _("Email Credentials");
  508. $hostname = exec('hostname');
  509. $from = sprintf(_('MAIL_FROM'), $hostname);
  510. $mailtext = $v_credentials;
  511. send_email($to, $subject, $mailtext, $from);
  512. }
  513. // Set success message
  514. if (empty($_SESSION['error_msg'])) {
  515. $_SESSION['ok_msg'] = _('Changes has been saved.');
  516. }
  517. }
  518. // Render page
  519. if (empty($_GET['account'])) {
  520. // Display body for mail domain
  521. render_page($user, $TAB, 'edit_mail');
  522. } else {
  523. // Display body for mail account
  524. render_page($user, $TAB, 'edit_mail_acc');
  525. }
  526. // Flush session messages
  527. unset($_SESSION['error_msg']);
  528. unset($_SESSION['ok_msg']);