index.php 7.0 KB

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