index.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. error_reporting(NULL);
  3. $TAB = 'SERVER';
  4. header('Content-Type: application/json');
  5. // Main include
  6. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  7. // Check user
  8. if ($_SESSION['user'] != 'admin') {
  9. exit;
  10. }
  11. // Check POST request
  12. if (!empty($_POST['save'])) {
  13. // Check token
  14. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  15. exit();
  16. }
  17. // Set restart flag
  18. $v_restart = 'yes';
  19. if (empty($_POST['v_restart'])) $v_restart = 'no';
  20. // Update config
  21. if (!empty($_POST['v_config'])) {
  22. exec ('mktemp', $mktemp_output, $return_var);
  23. $new_conf = $mktemp_output[0];
  24. $fp = fopen($new_conf, 'w');
  25. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config']));
  26. fclose($fp);
  27. exec (VESTA_CMD."v-change-sys-service-config ".$new_conf." dovecot ".$v_restart, $output, $return_var);
  28. check_return_code($return_var,$output);
  29. unset($output);
  30. unlink($new_conf);
  31. }
  32. // Update config1
  33. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config1']))) {
  34. exec ('mktemp', $mktemp_output, $return_var);
  35. $new_conf = $mktemp_output[0];
  36. $fp = fopen($new_conf, 'w');
  37. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config1']));
  38. fclose($fp);
  39. exec (VESTA_CMD."v-change-sys-service-config ".$new_conf." dovecot-1 " .$v_restart, $output, $return_var);
  40. check_return_code($return_var,$output);
  41. unset($output);
  42. unlink($new_conf);
  43. }
  44. // Update config2
  45. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config2']))) {
  46. exec ('mktemp', $mktemp_output, $return_var);
  47. $new_conf = $mktemp_output[0];
  48. $fp = fopen($new_conf, 'w');
  49. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config2']));
  50. fclose($fp);
  51. exec (VESTA_CMD."v-change-sys-service-config ".$new_conf." dovecot-2 " .$v_restart, $output, $return_var);
  52. check_return_code($return_var,$output);
  53. unset($output);
  54. unlink($new_conf);
  55. }
  56. // Update config3
  57. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config3']))) {
  58. exec ('mktemp', $mktemp_output, $return_var);
  59. $new_conf = $mktemp_output[0];
  60. $fp = fopen($new_conf, 'w');
  61. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config3']));
  62. fclose($fp);
  63. exec (VESTA_CMD."v-change-sys-service-config ".$new_conf." dovecot-3 " .$v_restart, $output, $return_var);
  64. check_return_code($return_var,$output);
  65. unset($output);
  66. unlink($new_conf);
  67. }
  68. // Update config4
  69. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config4']))) {
  70. exec ('mktemp', $mktemp_output, $return_var);
  71. $new_conf = $mktemp_output[0];
  72. $fp = fopen($new_conf, 'w');
  73. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config4']));
  74. fclose($fp);
  75. exec (VESTA_CMD."v-change-sys-service-config ".$new_conf." dovecot-4 " .$v_restart, $output, $return_var);
  76. check_return_code($return_var,$output);
  77. unset($output);
  78. unlink($new_conf);
  79. }
  80. // Update config5
  81. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config5']))) {
  82. exec ('mktemp', $mktemp_output, $return_var);
  83. $new_conf = $mktemp_output[0];
  84. $fp = fopen($new_conf, 'w');
  85. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config5']));
  86. fclose($fp);
  87. exec (VESTA_CMD."v-change-sys-service-config ".$new_conf." dovecot-5 " .$v_restart, $output, $return_var);
  88. check_return_code($return_var,$output);
  89. unset($output);
  90. unlink($new_conf);
  91. }
  92. // Update config6
  93. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config6']))) {
  94. exec ('mktemp', $mktemp_output, $return_var);
  95. $new_conf = $mktemp_output[0];
  96. $fp = fopen($new_conf, 'w');
  97. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config6']));
  98. fclose($fp);
  99. exec (VESTA_CMD."v-change-sys-service-config ".$new_conf." dovecot-6 " .$v_restart, $output, $return_var);
  100. check_return_code($return_var,$output);
  101. unset($output);
  102. unlink($new_conf);
  103. }
  104. // Update config7
  105. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config7']))) {
  106. exec ('mktemp', $mktemp_output, $return_var);
  107. $new_conf = $mktemp_output[0];
  108. $fp = fopen($new_conf, 'w');
  109. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config7']));
  110. fclose($fp);
  111. exec (VESTA_CMD."v-change-sys-service-config ".$new_conf." dovecot-7 " .$v_restart, $output, $return_var);
  112. check_return_code($return_var,$output);
  113. unset($output);
  114. unlink($new_conf);
  115. }
  116. // Update config8
  117. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config8']))) {
  118. exec ('mktemp', $mktemp_output, $return_var);
  119. $new_conf = $mktemp_output[0];
  120. $fp = fopen($new_conf, 'w');
  121. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config8']));
  122. fclose($fp);
  123. exec (VESTA_CMD."v-change-sys-service-config ".$new_conf." dovecot-8 " .$v_restart, $output, $return_var);
  124. check_return_code($return_var,$output);
  125. unset($output);
  126. unlink($new_conf);
  127. }
  128. // Set success message
  129. if (empty($_SESSION['error_msg'])) {
  130. $_SESSION['ok_msg'] = __('Changes has been saved.');
  131. }
  132. }
  133. // List config
  134. exec (VESTA_CMD."v-list-sys-dovecot-config json", $output, $return_var);
  135. $data = json_decode(implode('', $output), true);
  136. unset($output);
  137. $v_config_path = $data['CONFIG']['config_path'];
  138. $v_config_path1 = $data['CONFIG']['config_path1'];
  139. $v_config_path2 = $data['CONFIG']['config_path2'];
  140. $v_config_path3 = $data['CONFIG']['config_path3'];
  141. $v_config_path4 = $data['CONFIG']['config_path4'];
  142. $v_config_path5 = $data['CONFIG']['config_path5'];
  143. $v_config_path6 = $data['CONFIG']['config_path6'];
  144. $v_config_path7 = $data['CONFIG']['config_path7'];
  145. $v_config_path8 = $data['CONFIG']['config_path8'];
  146. $v_service_name = strtoupper('dovecot');
  147. // Read config
  148. $v_config = shell_exec(VESTA_CMD."v-open-fs-config ".$v_config_path);
  149. if (!empty($v_config_path1)) $v_config1 = shell_exec(VESTA_CMD."v-open-fs-config ".$v_config_path1);
  150. if (!empty($v_config_path2)) $v_config2 = shell_exec(VESTA_CMD."v-open-fs-config ".$v_config_path2);
  151. if (!empty($v_config_path3)) $v_config3 = shell_exec(VESTA_CMD."v-open-fs-config ".$v_config_path3);
  152. if (!empty($v_config_path4)) $v_config4 = shell_exec(VESTA_CMD."v-open-fs-config ".$v_config_path4);
  153. if (!empty($v_config_path5)) $v_config5 = shell_exec(VESTA_CMD."v-open-fs-config ".$v_config_path5);
  154. if (!empty($v_config_path6)) $v_config6 = shell_exec(VESTA_CMD."v-open-fs-config ".$v_config_path6);
  155. if (!empty($v_config_path7)) $v_config7 = shell_exec(VESTA_CMD."v-open-fs-config ".$v_config_path7);
  156. if (!empty($v_config_path8)) $v_config8 = shell_exec(VESTA_CMD."v-open-fs-config ".$v_config_path8);
  157. $result = array(
  158. 'config_path' => $v_config_path,
  159. 'config_path1' => $v_config_path1,
  160. 'config_path2' => $v_config_path2,
  161. 'config_path3' => $v_config_path3,
  162. 'config_path4' => $v_config_path4,
  163. 'config_path5' => $v_config_path5,
  164. 'config_path6' => $v_config_path6,
  165. 'config_path7' => $v_config_path7,
  166. 'config_path8' => $v_config_path8,
  167. 'service_name' => $v_service_name,
  168. 'config' => $config,
  169. 'config1' => $config1,
  170. 'config2' => $config2,
  171. 'config3' => $config3,
  172. 'config4' => $config4,
  173. 'config5' => $config5,
  174. 'config6' => $config6,
  175. 'config7' => $config7,
  176. 'config8' => $config8,
  177. 'error_msg' => $_SESSION['error_msg'],
  178. 'ok_msg' => $_SESSION['ok_msg']
  179. );
  180. echo json_encode($result);
  181. // Flush session messages
  182. unset($_SESSION['error_msg']);
  183. unset($_SESSION['ok_msg']);