index.php 17 KB

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