index.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. $lang = 'ru_RU.utf8';
  13. setlocale(LC_ALL, $lang);
  14. // Check user argument?
  15. if (empty($_GET['domain'])) {
  16. header("Location: /list/mail/");
  17. exit;
  18. }
  19. // Edit as someone else?
  20. if (($_SESSION['user'] == 'admin') && (!empty($_GET['user']))) {
  21. $user=escapeshellarg($_GET['user']);
  22. }
  23. // Check domain
  24. if ((!empty($_GET['domain'])) && (empty($_GET['account']))) {
  25. $v_domain = escapeshellarg($_GET['domain']);
  26. exec (VESTA_CMD."v-list-mail-domain ".$user." ".$v_domain." json", $output, $return_var);
  27. if ($return_var != 0) {
  28. $error = implode('<br>', $output);
  29. if (empty($error)) $error = _('Error: vesta did not return any output.');
  30. $_SESSION['error_msg'] = $error;
  31. } else {
  32. $data = json_decode(implode('', $output), true);
  33. unset($output);
  34. $v_username = $user;
  35. $v_domain = $_GET['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. if ( $v_suspended == 'yes' ) {
  44. $v_status = 'suspended';
  45. } else {
  46. $v_status = 'active';
  47. }
  48. }
  49. // Action
  50. if (!empty($_POST['save'])) {
  51. $v_domain = escapeshellarg($_POST['v_domain']);
  52. // Antispam
  53. if (($v_antispam == 'yes') && (empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
  54. exec (VESTA_CMD."v-delete-mail-domain-antispam ".$v_username." ".$v_domain, $output, $return_var);
  55. if ($return_var != 0) {
  56. $error = implode('<br>', $output);
  57. if (empty($error)) $error = _('Error: vesta did not return any output.');
  58. $_SESSION['error_msg'] = $error;
  59. }
  60. $v_antispam = 'no';
  61. unset($output);
  62. }
  63. if (($v_antispam == 'no') && (!empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
  64. exec (VESTA_CMD."v-add-mail-domain-antispam ".$v_username." ".$v_domain, $output, $return_var);
  65. if ($return_var != 0) {
  66. $error = implode('<br>', $output);
  67. if (empty($error)) $error = _('Error: vesta did not return any output.');
  68. $_SESSION['error_msg'] = $error;
  69. }
  70. $v_antispam = 'yes';
  71. unset($output);
  72. }
  73. // Antivirus
  74. if (($v_antivirus == 'yes') && (empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
  75. exec (VESTA_CMD."v-delete-mail-domain-antivirus ".$v_username." ".$v_domain, $output, $return_var);
  76. if ($return_var != 0) {
  77. $error = implode('<br>', $output);
  78. if (empty($error)) $error = _('Error: vesta did not return any output.');
  79. $_SESSION['error_msg'] = $error;
  80. }
  81. $v_antivirus = 'no';
  82. unset($output);
  83. }
  84. if (($v_antivirus == 'no') && (!empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
  85. exec (VESTA_CMD."v-add-mail-domain-antivirus ".$v_username." ".$v_domain, $output, $return_var);
  86. if ($return_var != 0) {
  87. $error = implode('<br>', $output);
  88. if (empty($error)) $error = _('Error: vesta did not return any output.');
  89. $_SESSION['error_msg'] = $error;
  90. }
  91. $v_antivirus = 'yes';
  92. unset($output);
  93. }
  94. if (empty($_SESSION['error_msg'])) {
  95. $_SESSION['ok_msg'] = _('OK: changes has been saved.');
  96. }
  97. // DKIM
  98. if (($v_dkim == 'yes') && (empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
  99. exec (VESTA_CMD."v-delete-mail-domain-dkim ".$v_username." ".$v_domain, $output, $return_var);
  100. if ($return_var != 0) {
  101. $error = implode('<br>', $output);
  102. if (empty($error)) $error = _('Error: vesta did not return any output.');
  103. $_SESSION['error_msg'] = $error;
  104. }
  105. $v_dkim = 'no';
  106. unset($output);
  107. }
  108. if (($v_dkim == 'no') && (!empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
  109. exec (VESTA_CMD."v-add-mail-domain-dkim ".$v_username." ".$v_domain, $output, $return_var);
  110. if ($return_var != 0) {
  111. $error = implode('<br>', $output);
  112. if (empty($error)) $error = _('Error: vesta did not return any output.');
  113. $_SESSION['error_msg'] = $error;
  114. }
  115. $v_dkim = 'yes';
  116. unset($output);
  117. }
  118. // Catchall
  119. if ((!empty($v_catchall)) && (empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  120. exec (VESTA_CMD."v-delete-mail-domain-catchall ".$v_username." ".$v_domain, $output, $return_var);
  121. if ($return_var != 0) {
  122. $error = implode('<br>', $output);
  123. if (empty($error)) $error = _('Error: vesta did not return any output.');
  124. $_SESSION['error_msg'] = $error;
  125. }
  126. $v_catchall = '';
  127. unset($output);
  128. }
  129. if ((!empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  130. if ($v_catchall != $_POST['v_catchall']) {
  131. $v_catchall = escapeshellarg($_POST['v_catchall']);
  132. exec (VESTA_CMD."v-change-mail-domain-catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var);
  133. if ($return_var != 0) {
  134. $error = implode('<br>', $output);
  135. if (empty($error)) $error = _('Error: vesta did not return any output.');
  136. $_SESSION['error_msg'] = $error;
  137. }
  138. unset($output);
  139. }
  140. }
  141. if ((empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  142. $v_catchall = escapeshellarg($_POST['v_catchall']);
  143. exec (VESTA_CMD."v-add-mail-domain-catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var);
  144. if ($return_var != 0) {
  145. $error = implode('<br>', $output);
  146. if (empty($error)) $error = _('Error: vesta did not return any output.');
  147. $_SESSION['error_msg'] = $error;
  148. }
  149. unset($output);
  150. }
  151. if (empty($_SESSION['error_msg'])) {
  152. $_SESSION['ok_msg'] = _('OK: changes has been saved.');
  153. }
  154. }
  155. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_mail.html');
  156. unset($_SESSION['error_msg']);
  157. unset($_SESSION['ok_msg']);
  158. } else {
  159. $v_username = $user;
  160. $v_domain = escapeshellarg($_GET['domain']);
  161. $v_account = escapeshellarg($_GET['account']);
  162. exec (VESTA_CMD."v-list-mail-account ".$user." ".$v_domain." ".$v_account." 'json'", $output, $return_var);
  163. if ($return_var != 0) {
  164. $error = implode('<br>', $output);
  165. if (empty($error)) $error = _('Error: vesta did not return any output.');
  166. $_SESSION['error_msg'] = $error;
  167. } else {
  168. $data = json_decode(implode('', $output), true);
  169. unset($output);
  170. $v_username = $user;
  171. $v_domain = $_GET['domain'];
  172. $v_account = $_GET['account'];
  173. $v_password = "••••••••";
  174. $v_aliases = str_replace(',', "\n", $data[$v_account]['ALIAS']);
  175. $valiases = explode(",", $data[$v_account]['ALIAS']);
  176. $v_fwd = str_replace(',', "\n", $data[$v_account]['FWD']);
  177. $vfwd = explode(",", $data[$v_account]['FWD']);
  178. $v_quota = $data[$v_account]['QUOTA'];
  179. $v_autoreply = $data[$v_account]['AUTOREPLY'];
  180. if ( $v_autoreply == 'yes' ) {
  181. exec (VESTA_CMD."v-list-mail-account-autoreply ".$user." '".$v_domain."' '".$v_account."' json", $output, $return_var);
  182. $autoreply_str = json_decode(implode('', $output), true);
  183. unset($output);
  184. $v_autoreply_message = $autoreply_str[$v_account]['MSG'];
  185. }
  186. $v_suspended = $data[$v_account]['SUSPENDED'];
  187. if ( $v_suspended == 'yes' ) {
  188. $v_status = 'suspended';
  189. } else {
  190. $v_status = 'active';
  191. }
  192. $v_date = $data[$v_account]['DATE'];
  193. $v_time = $data[$v_account]['TIME'];
  194. }
  195. // Action
  196. if (!empty($_POST['save'])) {
  197. $v_domain = escapeshellarg($_POST['v_domain']);
  198. $v_account = escapeshellarg($_POST['v_account']);
  199. // Password
  200. if (($v_password != $_POST['v_password']) && (empty($_SESSION['error_msg']))) {
  201. $v_password = escapeshellarg($_POST['v_password']);
  202. exec (VESTA_CMD."v-change-mail-account-password ".$v_username." ".$v_domain." ".$v_account." ".$v_password, $output, $return_var);
  203. if ($return_var != 0) {
  204. $error = implode('<br>', $output);
  205. if (empty($error)) $error = _('Error: vesta did not return any output.');
  206. $_SESSION['error_msg'] = $error;
  207. }
  208. $v_password = "••••••••";
  209. unset($output);
  210. }
  211. // Quota
  212. if (($v_quota != $_POST['v_quota']) && (empty($_SESSION['error_msg']))) {
  213. if (empty($_POST['v_quota'])) {
  214. $v_quota = 0;
  215. } else {
  216. $v_quota = escapeshellarg($_POST['v_quota']);
  217. }
  218. exec (VESTA_CMD."v-change-mail-account-quota ".$v_username." ".$v_domain." ".$v_account." ".$v_quota, $output, $return_var);
  219. if ($return_var != 0) {
  220. $error = implode('<br>', $output);
  221. if (empty($error)) $error = _('Error: vesta did not return any output.');
  222. $_SESSION['error_msg'] = $error;
  223. }
  224. unset($output);
  225. }
  226. // Aliases
  227. if (empty($_SESSION['error_msg'])) {
  228. $waliases = preg_replace("/\n/", " ", $_POST['v_aliases']);
  229. $waliases = preg_replace("/,/", " ", $waliases);
  230. $waliases = preg_replace('/\s+/', ' ',$waliases);
  231. $waliases = trim($waliases);
  232. $aliases = explode(" ", $waliases);
  233. $v_aliases = str_replace(' ', "\n", $waliases);
  234. $result = array_diff($valiases, $aliases);
  235. foreach ($result as $alias) {
  236. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  237. exec (VESTA_CMD."v-delete-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." '".$alias."'", $output, $return_var);
  238. if ($return_var != 0) {
  239. $error = implode('<br>', $output);
  240. if (empty($error)) $error = _('Error: vesta did not return any output.');
  241. $_SESSION['error_msg'] = $error;
  242. }
  243. unset($output);
  244. }
  245. }
  246. $result = array_diff($aliases, $valiases);
  247. foreach ($result as $alias) {
  248. if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
  249. exec (VESTA_CMD."v-add-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." '".$alias."'", $output, $return_var);
  250. if ($return_var != 0) {
  251. $error = implode('<br>', $output);
  252. if (empty($error)) $error = _('Error: vesta did not return any output.');
  253. $_SESSION['error_msg'] = $error;
  254. }
  255. unset($output);
  256. }
  257. }
  258. }
  259. // Forwarders
  260. if (empty($_SESSION['error_msg'])) {
  261. $wfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
  262. $wfwd = preg_replace("/,/", " ", $wfwd);
  263. $wfwd = preg_replace('/\s+/', ' ',$wfwd);
  264. $wfwd = trim($wfwd);
  265. $fwd = explode(" ", $wfwd);
  266. $v_fwd = str_replace(' ', "\n", $wfwd);
  267. $result = array_diff($vfwd, $fwd);
  268. foreach ($result as $forward) {
  269. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  270. exec (VESTA_CMD."v-delete-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var);
  271. if ($return_var != 0) {
  272. $error = implode('<br>', $output);
  273. if (empty($error)) $error = _('Error: vesta did not return any output.');
  274. $_SESSION['error_msg'] = $error;
  275. }
  276. unset($output);
  277. }
  278. }
  279. $result = array_diff($fwd, $vfwd);
  280. foreach ($result as $forward) {
  281. if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
  282. exec (VESTA_CMD."v-add-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var);
  283. if ($return_var != 0) {
  284. $error = implode('<br>', $output);
  285. if (empty($error)) $error = _('Error: vesta did not return any output.');
  286. $_SESSION['error_msg'] = $error;
  287. }
  288. unset($output);
  289. }
  290. }
  291. }
  292. // Autoreply
  293. if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  294. exec (VESTA_CMD."v-delete-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
  295. if ($return_var != 0) {
  296. $error = implode('<br>', $output);
  297. if (empty($error)) $error = _('Error: vesta did not return any output.');
  298. $_SESSION['error_msg'] = $error;
  299. }
  300. unset($output);
  301. $v_autoreply = 'no';
  302. $v_autoreply_message = '';
  303. }
  304. if (($v_autoreply == 'yes') && (!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  305. if ( $v_autoreply_message != str_replace("\r\n", "\n", $_POST['v_autoreply_message'])) {
  306. $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
  307. $v_autoreply_message = escapeshellarg($v_autoreply_message);
  308. exec (VESTA_CMD."v-add-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account." ".$v_autoreply_message, $output, $return_var);
  309. if ($return_var != 0) {
  310. $error = implode('<br>', $output);
  311. if (empty($error)) $error = _('Error: vesta did not return any output.');
  312. $_SESSION['error_msg'] = $error;
  313. }
  314. unset($output);
  315. $v_autoreply_message = $_POST['v_autoreply_message'];
  316. }
  317. }
  318. if (($v_autoreply == 'no') && (!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
  319. if (empty($_POST['v_autoreply_message'])) $_SESSION['error_msg'] = "Error: field atoreply message can not be blank.";
  320. if (empty($_SESSION['error_msg'])) {
  321. $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
  322. $v_autoreply_message = escapeshellarg($v_autoreply_message);
  323. exec (VESTA_CMD."v-add-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account." ".$v_autoreply_message, $output, $return_var);
  324. if ($return_var != 0) {
  325. $error = implode('<br>', $output);
  326. if (empty($error)) $error = _('Error: vesta did not return any output.');
  327. $_SESSION['error_msg'] = $error;
  328. }
  329. unset($output);
  330. $v_autoreply = 'yes';
  331. $v_autoreply_message = $_POST['v_autoreply_message'];
  332. }
  333. }
  334. if (empty($_SESSION['error_msg'])) {
  335. $_SESSION['ok_msg'] = _('OK: changes has been saved.');
  336. }
  337. }
  338. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_mail_acc.html');
  339. unset($_SESSION['error_msg']);
  340. unset($_SESSION['ok_msg']);
  341. }
  342. // Footer
  343. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');