index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. // Init
  3. error_reporting(NULL);
  4. ob_start();
  5. session_start();
  6. $TAB = 'MAIL';
  7. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  8. // Header
  9. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  10. // Panel
  11. top_panel($user,$TAB);
  12. // Check user argument?
  13. if (empty($_GET['domain'])) {
  14. header("Location: /list/mail/");
  15. exit;
  16. }
  17. // Edit as someone else?
  18. if (($_SESSION['user'] == 'admin') && (!empty($_GET['user']))) {
  19. $user=escapeshellarg($_GET['user']);
  20. }
  21. // Check domain
  22. if ((!empty($_GET['domain'])) && (empty($_GET['account']))) {
  23. $v_domain = escapeshellarg($_GET['domain']);
  24. exec (VESTA_CMD."v-list-mail-domain ".$user." ".$v_domain." json", $output, $return_var);
  25. check_return_code($return_var,$output);
  26. if (empty($_SESSION['error_msg'])) {
  27. $data = json_decode(implode('', $output), true);
  28. unset($output);
  29. $v_username = $user;
  30. $v_domain = $_GET['domain'];
  31. $v_antispam = $data[$v_domain]['ANTISPAM'];
  32. $v_antivirus = $data[$v_domain]['ANTIVIRUS'];
  33. $v_dkim = $data[$v_domain]['DKIM'];
  34. $v_catchall = $data[$v_domain]['CATCHALL'];
  35. $v_date = $data[$v_domain]['DATE'];
  36. $v_time = $data[$v_domain]['TIME'];
  37. $v_suspended = $data[$v_domain]['SUSPENDED'];
  38. if ( $v_suspended == 'yes' ) {
  39. $v_status = 'suspended';
  40. } else {
  41. $v_status = 'active';
  42. }
  43. }
  44. // Action
  45. if (!empty($_POST['save'])) {
  46. $v_domain = escapeshellarg($_POST['v_domain']);
  47. // Antispam
  48. if (($v_antispam == 'yes') && (empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
  49. exec (VESTA_CMD."v-delete-mail-domain-antispam ".$v_username." ".$v_domain, $output, $return_var);
  50. check_return_code($return_var,$output);
  51. $v_antispam = 'no';
  52. unset($output);
  53. }
  54. if (($v_antispam == 'no') && (!empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
  55. exec (VESTA_CMD."v-add-mail-domain-antispam ".$v_username." ".$v_domain, $output, $return_var);
  56. check_return_code($return_var,$output);
  57. $v_antispam = 'yes';
  58. unset($output);
  59. }
  60. // Antivirus
  61. if (($v_antivirus == 'yes') && (empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
  62. exec (VESTA_CMD."v-delete-mail-domain-antivirus ".$v_username." ".$v_domain, $output, $return_var);
  63. check_return_code($return_var,$output);
  64. $v_antivirus = 'no';
  65. unset($output);
  66. }
  67. if (($v_antivirus == 'no') && (!empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
  68. exec (VESTA_CMD."v-add-mail-domain-antivirus ".$v_username." ".$v_domain, $output, $return_var);
  69. check_return_code($return_var,$output);
  70. $v_antivirus = 'yes';
  71. unset($output);
  72. }
  73. if (empty($_SESSION['error_msg'])) {
  74. $_SESSION['ok_msg'] = __('Changes has been saved.');
  75. }
  76. // DKIM
  77. if (($v_dkim == 'yes') && (empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
  78. exec (VESTA_CMD."v-delete-mail-domain-dkim ".$v_username." ".$v_domain, $output, $return_var);
  79. check_return_code($return_var,$output);
  80. $v_dkim = 'no';
  81. unset($output);
  82. }
  83. if (($v_dkim == 'no') && (!empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
  84. exec (VESTA_CMD."v-add-mail-domain-dkim ".$v_username." ".$v_domain, $output, $return_var);
  85. check_return_code($return_var,$output);
  86. $v_dkim = 'yes';
  87. unset($output);
  88. }
  89. // Catchall
  90. if ((!empty($v_catchall)) && (empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  91. exec (VESTA_CMD."v-delete-mail-domain-catchall ".$v_username." ".$v_domain, $output, $return_var);
  92. check_return_code($return_var,$output);
  93. $v_catchall = '';
  94. unset($output);
  95. }
  96. if ((!empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  97. if ($v_catchall != $_POST['v_catchall']) {
  98. $v_catchall = escapeshellarg($_POST['v_catchall']);
  99. exec (VESTA_CMD."v-change-mail-domain-catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var);
  100. check_return_code($return_var,$output);
  101. unset($output);
  102. }
  103. }
  104. if ((empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  105. $v_catchall = escapeshellarg($_POST['v_catchall']);
  106. exec (VESTA_CMD."v-add-mail-domain-catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var);
  107. check_return_code($return_var,$output);
  108. unset($output);
  109. }
  110. if (empty($_SESSION['error_msg'])) {
  111. $_SESSION['ok_msg'] = __('Changes has been saved.');
  112. }
  113. }
  114. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_mail.html');
  115. unset($_SESSION['error_msg']);
  116. unset($_SESSION['ok_msg']);
  117. } else {
  118. $v_username = $user;
  119. $v_domain = escapeshellarg($_GET['domain']);
  120. $v_account = escapeshellarg($_GET['account']);
  121. exec (VESTA_CMD."v-list-mail-account ".$user." ".$v_domain." ".$v_account." 'json'", $output, $return_var);
  122. check_return_code($return_var,$output);
  123. if (empty($_SESSION['error_msg'])) {
  124. $data = json_decode(implode('', $output), true);
  125. unset($output);
  126. $v_username = $user;
  127. $v_domain = $_GET['domain'];
  128. $v_account = $_GET['account'];
  129. $v_password = "••••••••";
  130. $v_aliases = str_replace(',', "\n", $data[$v_account]['ALIAS']);
  131. $valiases = explode(",", $data[$v_account]['ALIAS']);
  132. $v_fwd = str_replace(',', "\n", $data[$v_account]['FWD']);
  133. $vfwd = explode(",", $data[$v_account]['FWD']);
  134. $v_fwd_only = $data[$v_account]['FWD_ONLY'];
  135. $v_quota = $data[$v_account]['QUOTA'];
  136. $v_autoreply = $data[$v_account]['AUTOREPLY'];
  137. if ( $v_autoreply == 'yes' ) {
  138. exec (VESTA_CMD."v-list-mail-account-autoreply ".$user." '".$v_domain."' '".$v_account."' json", $output, $return_var);
  139. $autoreply_str = json_decode(implode('', $output), true);
  140. unset($output);
  141. $v_autoreply_message = $autoreply_str[$v_account]['MSG'];
  142. }
  143. $v_suspended = $data[$v_account]['SUSPENDED'];
  144. if ( $v_suspended == 'yes' ) {
  145. $v_status = 'suspended';
  146. } else {
  147. $v_status = 'active';
  148. }
  149. $v_date = $data[$v_account]['DATE'];
  150. $v_time = $data[$v_account]['TIME'];
  151. }
  152. // Action
  153. if (!empty($_POST['save'])) {
  154. $v_domain = escapeshellarg($_POST['v_domain']);
  155. $v_account = escapeshellarg($_POST['v_account']);
  156. // Password
  157. if (($v_password != $_POST['v_password']) && (empty($_SESSION['error_msg']))) {
  158. $v_password = escapeshellarg($_POST['v_password']);
  159. exec (VESTA_CMD."v-change-mail-account-password ".$v_username." ".$v_domain." ".$v_account." ".$v_password, $output, $return_var);
  160. check_return_code($return_var,$output);
  161. $v_password = "••••••••";
  162. unset($output);
  163. }
  164. // Quota
  165. if (($v_quota != $_POST['v_quota']) && (empty($_SESSION['error_msg']))) {
  166. if (empty($_POST['v_quota'])) {
  167. $v_quota = 0;
  168. } else {
  169. $v_quota = escapeshellarg($_POST['v_quota']);
  170. }
  171. exec (VESTA_CMD."v-change-mail-account-quota ".$v_username." ".$v_domain." ".$v_account." ".$v_quota, $output, $return_var);
  172. check_return_code($return_var,$output);
  173. unset($output);
  174. }
  175. // Aliases
  176. if (empty($_SESSION['error_msg'])) {
  177. $waliases = preg_replace("/\n/", " ", $_POST['v_aliases']);
  178. $waliases = preg_replace("/,/", " ", $waliases);
  179. $waliases = preg_replace('/\s+/', ' ',$waliases);
  180. $waliases = trim($waliases);
  181. $aliases = explode(" ", $waliases);
  182. $v_aliases = str_replace(' ', "\n", $waliases);
  183. $result = array_diff($valiases, $aliases);
  184. foreach ($result as $alias) {
  185. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  186. exec (VESTA_CMD."v-delete-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." '".$alias."'", $output, $return_var);
  187. check_return_code($return_var,$output);
  188. unset($output);
  189. }
  190. }
  191. $result = array_diff($aliases, $valiases);
  192. foreach ($result as $alias) {
  193. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  194. exec (VESTA_CMD."v-add-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." '".$alias."'", $output, $return_var);
  195. check_return_code($return_var,$output);
  196. unset($output);
  197. }
  198. }
  199. }
  200. // Forwarders
  201. if (empty($_SESSION['error_msg'])) {
  202. $wfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
  203. $wfwd = preg_replace("/,/", " ", $wfwd);
  204. $wfwd = preg_replace('/\s+/', ' ',$wfwd);
  205. $wfwd = trim($wfwd);
  206. $fwd = explode(" ", $wfwd);
  207. $v_fwd = str_replace(' ', "\n", $wfwd);
  208. $result = array_diff($vfwd, $fwd);
  209. foreach ($result as $forward) {
  210. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  211. exec (VESTA_CMD."v-delete-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var);
  212. check_return_code($return_var,$output);
  213. unset($output);
  214. }
  215. }
  216. $result = array_diff($fwd, $vfwd);
  217. foreach ($result as $forward) {
  218. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  219. exec (VESTA_CMD."v-add-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var);
  220. check_return_code($return_var,$output);
  221. unset($output);
  222. }
  223. }
  224. }
  225. // FWD_ONLY flag
  226. if (($v_fwd_only == 'yes') && (empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  227. exec (VESTA_CMD."v-delete-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
  228. check_return_code($return_var,$output);
  229. unset($output);
  230. $v_fwd_only = '';
  231. }
  232. if (($v_fwd_only != 'yes') && (!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
  233. exec (VESTA_CMD."v-add-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
  234. check_return_code($return_var,$output);
  235. unset($output);
  236. $v_fwd_only = 'yes';
  237. }
  238. // Autoreply
  239. if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  240. exec (VESTA_CMD."v-delete-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
  241. check_return_code($return_var,$output);
  242. unset($output);
  243. $v_autoreply = 'no';
  244. $v_autoreply_message = '';
  245. }
  246. if (($v_autoreply == 'yes') && (!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  247. if ( $v_autoreply_message != str_replace("\r\n", "\n", $_POST['v_autoreply_message'])) {
  248. $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
  249. $v_autoreply_message = escapeshellarg($v_autoreply_message);
  250. exec (VESTA_CMD."v-add-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account." ".$v_autoreply_message, $output, $return_var);
  251. check_return_code($return_var,$output);
  252. unset($output);
  253. $v_autoreply_message = $_POST['v_autoreply_message'];
  254. }
  255. }
  256. if (($v_autoreply == 'no') && (!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  257. if (empty($_POST['v_autoreply_message'])) $_SESSION['error_msg'] = $_SESSION['error_msg'] = __('Field "%s" can not be blank.','atoreply');
  258. if (empty($_SESSION['error_msg'])) {
  259. $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
  260. $v_autoreply_message = escapeshellarg($v_autoreply_message);
  261. exec (VESTA_CMD."v-add-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account." ".$v_autoreply_message, $output, $return_var);
  262. check_return_code($return_var,$output);
  263. unset($output);
  264. $v_autoreply = 'yes';
  265. $v_autoreply_message = $_POST['v_autoreply_message'];
  266. }
  267. }
  268. if (empty($_SESSION['error_msg'])) {
  269. $_SESSION['ok_msg'] = __('Changes has been saved.');
  270. }
  271. }
  272. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_mail_acc.html');
  273. unset($_SESSION['error_msg']);
  274. unset($_SESSION['ok_msg']);
  275. }
  276. // Footer
  277. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');