index.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. }
  18. if (!empty($_POST['cancel'])) {
  19. header("Location: /list/mail/");
  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. if ($return_var != 0) {
  26. $error = implode('<br>', $output);
  27. if (empty($error)) $error = 'Error: vesta did not return any output.';
  28. $_SESSION['error_msg'] = $error;
  29. } else {
  30. $data = json_decode(implode('', $output), true);
  31. unset($output);
  32. $v_username = $user;
  33. $v_domain = $_GET['domain'];
  34. $v_antispam = $data[$v_domain]['ANTISPAM'];
  35. $v_antivirus = $data[$v_domain]['ANTIVIRUS'];
  36. $v_dkim = $data[$v_domain]['DKIM'];
  37. $v_catchall = $data[$v_domain]['CATCHALL'];
  38. $v_date = $data[$v_domain]['DATE'];
  39. $v_time = $data[$v_domain]['TIME'];
  40. $v_suspended = $data[$v_domain]['SUSPENDED'];
  41. if ( $v_suspended == 'yes' ) {
  42. $v_status = 'suspended';
  43. } else {
  44. $v_status = 'active';
  45. }
  46. }
  47. // Action
  48. if (!empty($_POST['save'])) {
  49. $v_domain = escapeshellarg($_POST['v_domain']);
  50. // Antispam
  51. if (($v_antispam == 'yes') && (empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
  52. exec (VESTA_CMD."v_delete_mail_domain_antispam ".$v_username." ".$v_domain, $output, $return_var);
  53. if ($return_var != 0) {
  54. $error = implode('<br>', $output);
  55. if (empty($error)) $error = 'Error: vesta did not return any output.';
  56. $_SESSION['error_msg'] = $error;
  57. }
  58. $v_antispam = 'no';
  59. unset($output);
  60. }
  61. if (($v_antispam == 'no') && (!empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
  62. exec (VESTA_CMD."v_add_mail_domain_antispam ".$v_username." ".$v_domain, $output, $return_var);
  63. if ($return_var != 0) {
  64. $error = implode('<br>', $output);
  65. if (empty($error)) $error = 'Error: vesta did not return any output.';
  66. $_SESSION['error_msg'] = $error;
  67. }
  68. $v_antispam = 'yes';
  69. unset($output);
  70. }
  71. // Antivirus
  72. if (($v_antivirus == 'yes') && (empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
  73. exec (VESTA_CMD."v_delete_mail_domain_antivirus ".$v_username." ".$v_domain, $output, $return_var);
  74. if ($return_var != 0) {
  75. $error = implode('<br>', $output);
  76. if (empty($error)) $error = 'Error: vesta did not return any output.';
  77. $_SESSION['error_msg'] = $error;
  78. }
  79. $v_antivirus = 'no';
  80. unset($output);
  81. }
  82. if (($v_antivirus == 'no') && (!empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
  83. exec (VESTA_CMD."v_add_mail_domain_antivirus ".$v_username." ".$v_domain, $output, $return_var);
  84. if ($return_var != 0) {
  85. $error = implode('<br>', $output);
  86. if (empty($error)) $error = 'Error: vesta did not return any output.';
  87. $_SESSION['error_msg'] = $error;
  88. }
  89. $v_antivirus = 'yes';
  90. unset($output);
  91. }
  92. if (empty($_SESSION['error_msg'])) {
  93. $_SESSION['ok_msg'] = "OK: changes has been saved.";
  94. }
  95. // DKIM
  96. if (($v_dkim == 'yes') && (empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
  97. exec (VESTA_CMD."v_delete_mail_domain_dkim ".$v_username." ".$v_domain, $output, $return_var);
  98. if ($return_var != 0) {
  99. $error = implode('<br>', $output);
  100. if (empty($error)) $error = 'Error: vesta did not return any output.';
  101. $_SESSION['error_msg'] = $error;
  102. }
  103. $v_dkim = 'no';
  104. unset($output);
  105. }
  106. if (($v_dkim == 'no') && (!empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
  107. exec (VESTA_CMD."v_add_mail_domain_dkim ".$v_username." ".$v_domain, $output, $return_var);
  108. if ($return_var != 0) {
  109. $error = implode('<br>', $output);
  110. if (empty($error)) $error = 'Error: vesta did not return any output.';
  111. $_SESSION['error_msg'] = $error;
  112. }
  113. $v_dkim = 'yes';
  114. unset($output);
  115. }
  116. // Catchall
  117. if ((!empty($v_catchall)) && (empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  118. exec (VESTA_CMD."v_delete_mail_domain_catchall ".$v_username." ".$v_domain, $output, $return_var);
  119. if ($return_var != 0) {
  120. $error = implode('<br>', $output);
  121. if (empty($error)) $error = 'Error: vesta did not return any output.';
  122. $_SESSION['error_msg'] = $error;
  123. }
  124. $v_catchall = '';
  125. unset($output);
  126. }
  127. if ((!empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  128. if ($v_catchall != $_POST['v_catchall']) {
  129. $v_catchall = escapeshellarg($_POST['v_catchall']);
  130. exec (VESTA_CMD."v_change_mail_domain_catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var);
  131. if ($return_var != 0) {
  132. $error = implode('<br>', $output);
  133. if (empty($error)) $error = 'Error: vesta did not return any output.';
  134. $_SESSION['error_msg'] = $error;
  135. }
  136. unset($output);
  137. }
  138. }
  139. if ((empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
  140. $v_catchall = escapeshellarg($_POST['v_catchall']);
  141. exec (VESTA_CMD."v_add_mail_domain_catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var);
  142. if ($return_var != 0) {
  143. $error = implode('<br>', $output);
  144. if (empty($error)) $error = 'Error: vesta did not return any output.';
  145. $_SESSION['error_msg'] = $error;
  146. }
  147. unset($output);
  148. }
  149. if (empty($_SESSION['error_msg'])) {
  150. $_SESSION['ok_msg'] = "OK: changes has been saved.";
  151. }
  152. }
  153. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_mail.html');
  154. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_mail.html');
  155. unset($_SESSION['error_msg']);
  156. unset($_SESSION['ok_msg']);
  157. } else {
  158. $v_domain = escapeshellarg($_GET['domain']);
  159. $v_record_id = escapeshellarg($_GET['record_id']);
  160. exec (VESTA_CMD."v_list_dns_domain_records ".$user." ".$v_domain." 'json'", $output, $return_var);
  161. if ($return_var != 0) {
  162. $error = implode('<br>', $output);
  163. if (empty($error)) $error = 'Error: vesta did not return any output.';
  164. $_SESSION['error_msg'] = $error;
  165. } else {
  166. $data = json_decode(implode('', $output), true);
  167. unset($output);
  168. $v_username = $user;
  169. $v_domain = $_GET['domain'];
  170. $v_d = $_GET['record_id'];
  171. $v_rec = $data[$v_record_id]['RECORD'];
  172. $v_type = $data[$v_record_id]['TYPE'];
  173. $v_val = $data[$v_record_id]['VALUE'];
  174. $v_priority = $data[$v_record_id]['PRIORITY'];
  175. $v_suspended = $data[$v_record_id]['SUSPENDED'];
  176. if ( $v_suspended == 'yes' ) {
  177. $v_status = 'suspended';
  178. } else {
  179. $v_status = 'active';
  180. }
  181. $v_date = $data[$v_record_id]['DATE'];
  182. $v_time = $data[$v_record_id]['TIME'];
  183. }
  184. // Action
  185. if (!empty($_POST['save'])) {
  186. $v_domain = escapeshellarg($_POST['v_domain']);
  187. $v_record_id = escapeshellarg($_POST['v_record_id']);
  188. if (($v_val != $_POST['v_val']) || ($v_priority != $_POST['v_priority']) && (empty($_SESSION['error_msg']))) {
  189. $v_val = escapeshellarg($_POST['v_val']);
  190. $v_priority = escapeshellarg($_POST['v_priority']);
  191. exec (VESTA_CMD."v_change_dns_domain_record ".$v_username." ".$v_domain." ".$v_record_id." ".$v_val." ".$v_priority, $output, $return_var);
  192. if ($return_var != 0) {
  193. $error = implode('<br>', $output);
  194. if (empty($error)) $error = 'Error: vesta did not return any output.';
  195. $_SESSION['error_msg'] = $error;
  196. }
  197. $restart_dns = 'yes';
  198. unset($output);
  199. }
  200. if (empty($_SESSION['error_msg'])) {
  201. $_SESSION['ok_msg'] = "OK: changes has been saved.";
  202. }
  203. }
  204. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_dns_rec.html');
  205. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_dns_rec.html');
  206. unset($_SESSION['error_msg']);
  207. unset($_SESSION['ok_msg']);
  208. }
  209. }
  210. // Footer
  211. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');