index.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. error_reporting(null);
  3. $TAB = 'SERVER';
  4. // Main include
  5. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  6. // Check user
  7. if ($_SESSION['userContext'] != 'admin') {
  8. header("Location: /list/user");
  9. exit;
  10. }
  11. // Check POST request
  12. if (!empty($_POST['save'])) {
  13. // Check token
  14. verify_csrf($_POST);
  15. // Set restart flag
  16. $v_restart = 'yes';
  17. if (empty($_POST['v_restart'])) {
  18. $v_restart = 'no';
  19. }
  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(HESTIA_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(HESTIA_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(HESTIA_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(HESTIA_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(HESTIA_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(HESTIA_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(HESTIA_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(HESTIA_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(HESTIA_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(HESTIA_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(HESTIA_CMD."v-open-fs-config ".$v_config_path);
  149. if (!empty($v_config_path1)) {
  150. $v_config1 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path1);
  151. }
  152. if (!empty($v_config_path2)) {
  153. $v_config2 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path2);
  154. }
  155. if (!empty($v_config_path3)) {
  156. $v_config3 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path3);
  157. }
  158. if (!empty($v_config_path4)) {
  159. $v_config4 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path4);
  160. }
  161. if (!empty($v_config_path5)) {
  162. $v_config5 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path5);
  163. }
  164. if (!empty($v_config_path6)) {
  165. $v_config6 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path6);
  166. }
  167. if (!empty($v_config_path7)) {
  168. $v_config7 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path7);
  169. }
  170. if (!empty($v_config_path8)) {
  171. $v_config8 = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path8);
  172. }
  173. // Render page
  174. render_page($user, $TAB, 'edit_server_dovecot');
  175. // Flush session messages
  176. unset($_SESSION['error_msg']);
  177. unset($_SESSION['ok_msg']);