index.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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(HESTIA_CMD."v-change-sys-service-config ".$new_conf." dovecot ".$v_restart, $output, $return_var);
  27. check_return_code($return_var, $output);
  28. unset($output);
  29. unlink($new_conf);
  30. }
  31. // Update config1
  32. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config1']))) {
  33. exec('mktemp', $mktemp_output, $return_var);
  34. $new_conf = $mktemp_output[0];
  35. $fp = fopen($new_conf, 'w');
  36. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config1']));
  37. fclose($fp);
  38. exec(HESTIA_CMD."v-change-sys-service-config ".$new_conf." dovecot-1 " .$v_restart, $output, $return_var);
  39. check_return_code($return_var, $output);
  40. unset($output);
  41. unlink($new_conf);
  42. }
  43. // Update config2
  44. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config2']))) {
  45. exec('mktemp', $mktemp_output, $return_var);
  46. $new_conf = $mktemp_output[0];
  47. $fp = fopen($new_conf, 'w');
  48. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config2']));
  49. fclose($fp);
  50. exec(HESTIA_CMD."v-change-sys-service-config ".$new_conf." dovecot-2 " .$v_restart, $output, $return_var);
  51. check_return_code($return_var, $output);
  52. unset($output);
  53. unlink($new_conf);
  54. }
  55. // Update config3
  56. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config3']))) {
  57. exec('mktemp', $mktemp_output, $return_var);
  58. $new_conf = $mktemp_output[0];
  59. $fp = fopen($new_conf, 'w');
  60. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config3']));
  61. fclose($fp);
  62. exec(HESTIA_CMD."v-change-sys-service-config ".$new_conf." dovecot-3 " .$v_restart, $output, $return_var);
  63. check_return_code($return_var, $output);
  64. unset($output);
  65. unlink($new_conf);
  66. }
  67. // Update config4
  68. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config4']))) {
  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_config4']));
  73. fclose($fp);
  74. exec(HESTIA_CMD."v-change-sys-service-config ".$new_conf." dovecot-4 " .$v_restart, $output, $return_var);
  75. check_return_code($return_var, $output);
  76. unset($output);
  77. unlink($new_conf);
  78. }
  79. // Update config5
  80. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config5']))) {
  81. exec('mktemp', $mktemp_output, $return_var);
  82. $new_conf = $mktemp_output[0];
  83. $fp = fopen($new_conf, 'w');
  84. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config5']));
  85. fclose($fp);
  86. exec(HESTIA_CMD."v-change-sys-service-config ".$new_conf." dovecot-5 " .$v_restart, $output, $return_var);
  87. check_return_code($return_var, $output);
  88. unset($output);
  89. unlink($new_conf);
  90. }
  91. // Update config6
  92. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config6']))) {
  93. exec('mktemp', $mktemp_output, $return_var);
  94. $new_conf = $mktemp_output[0];
  95. $fp = fopen($new_conf, 'w');
  96. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config6']));
  97. fclose($fp);
  98. exec(HESTIA_CMD."v-change-sys-service-config ".$new_conf." dovecot-6 " .$v_restart, $output, $return_var);
  99. check_return_code($return_var, $output);
  100. unset($output);
  101. unlink($new_conf);
  102. }
  103. // Update config7
  104. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config7']))) {
  105. exec('mktemp', $mktemp_output, $return_var);
  106. $new_conf = $mktemp_output[0];
  107. $fp = fopen($new_conf, 'w');
  108. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config7']));
  109. fclose($fp);
  110. exec(HESTIA_CMD."v-change-sys-service-config ".$new_conf." dovecot-7 " .$v_restart, $output, $return_var);
  111. check_return_code($return_var, $output);
  112. unset($output);
  113. unlink($new_conf);
  114. }
  115. // Update config8
  116. if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config8']))) {
  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_config8']));
  121. fclose($fp);
  122. exec(HESTIA_CMD."v-change-sys-service-config ".$new_conf." dovecot-8 " .$v_restart, $output, $return_var);
  123. check_return_code($return_var, $output);
  124. unset($output);
  125. unlink($new_conf);
  126. }
  127. // Set success message
  128. if (empty($_SESSION['error_msg'])) {
  129. $_SESSION['ok_msg'] = _('Changes has been saved.');
  130. }
  131. }
  132. // List config
  133. exec(HESTIA_CMD."v-list-sys-dovecot-config json", $output, $return_var);
  134. $data = json_decode(implode('', $output), true);
  135. unset($output);
  136. $v_config_path = $data['CONFIG']['config_path'];
  137. $v_config_path1 = $data['CONFIG']['config_path1'];
  138. $v_config_path2 = $data['CONFIG']['config_path2'];
  139. $v_config_path3 = $data['CONFIG']['config_path3'];
  140. $v_config_path4 = $data['CONFIG']['config_path4'];
  141. $v_config_path5 = $data['CONFIG']['config_path5'];
  142. $v_config_path6 = $data['CONFIG']['config_path6'];
  143. $v_config_path7 = $data['CONFIG']['config_path7'];
  144. $v_config_path8 = $data['CONFIG']['config_path8'];
  145. $v_service_name = strtoupper('dovecot');
  146. // Read config
  147. $v_config = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path);
  148. if (!empty($v_config_path1)) {
  149. $v_config1 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path1);
  150. }
  151. if (!empty($v_config_path2)) {
  152. $v_config2 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path2);
  153. }
  154. if (!empty($v_config_path3)) {
  155. $v_config3 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path3);
  156. }
  157. if (!empty($v_config_path4)) {
  158. $v_config4 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path4);
  159. }
  160. if (!empty($v_config_path5)) {
  161. $v_config5 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path5);
  162. }
  163. if (!empty($v_config_path6)) {
  164. $v_config6 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path6);
  165. }
  166. if (!empty($v_config_path7)) {
  167. $v_config7 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path7);
  168. }
  169. if (!empty($v_config_path8)) {
  170. $v_config8 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path8);
  171. }
  172. // Render page
  173. render_page($user, $TAB, 'edit_server_dovecot');
  174. // Flush session messages
  175. unset($_SESSION['error_msg']);
  176. unset($_SESSION['ok_msg']);