index.php 6.5 KB

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