configuration.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. use function Hestiacp\quoteshellarg\quoteshellarg;
  3. $dist_config = require __DIR__ . "/configuration_sample.php";
  4. $dist_config["public_path"] = "/fm/";
  5. $dist_config["frontend_config"]["app_name"] = "File Manager - Hestia Control Panel";
  6. $dist_config["frontend_config"]["logo"] = "../images/logo.svg";
  7. $dist_config["frontend_config"]["editable"] = [
  8. ".txt",
  9. ".css",
  10. ".js",
  11. ".ts",
  12. ".html",
  13. ".php",
  14. ".py",
  15. ".yml",
  16. ".xml",
  17. ".md",
  18. ".log",
  19. ".csv",
  20. ".conf",
  21. ".config",
  22. ".ini",
  23. ".scss",
  24. ".sh",
  25. ".env",
  26. ".example",
  27. ".htaccess",
  28. ".twig",
  29. ".tpl",
  30. ".yaml",
  31. ];
  32. $dist_config["frontend_config"]["date_format"] = "YY/MM/DD H:mm:ss";
  33. $dist_config["frontend_config"]["guest_redirection"] = "/login/";
  34. $dist_config["frontend_config"]["upload_max_size"] = 1024 * 1024 * 1024;
  35. $dist_config["services"]["Filegator\Services\Storage\Filesystem"]["config"][
  36. "adapter"
  37. ] = function () {
  38. if (!empty($_SESSION["INACTIVE_SESSION_TIMEOUT"])) {
  39. if ($_SESSION["INACTIVE_SESSION_TIMEOUT"] * 60 + $_SESSION["LAST_ACTIVITY"] < time()) {
  40. $v_user = quoteshellarg($_SESSION["user"]);
  41. $v_session_id = quoteshellarg($_SESSION["token"]);
  42. exec(
  43. "/usr/local/hestia/bin/v-log-user-logout " . $v_user . " " . $v_session_id,
  44. $output,
  45. $return_var,
  46. );
  47. unset($_SESSION);
  48. session_unset();
  49. session_destroy();
  50. session_start();
  51. echo '<meta http-equiv="refresh" content="0; url=/">';
  52. exit();
  53. } else {
  54. $_SESSION["LAST_ACTIVITY"] = time();
  55. }
  56. } else {
  57. echo '<meta http-equiv="refresh" content="0; url=/">';
  58. }
  59. if (isset($_SESSION["user"])) {
  60. $v_user = $_SESSION["user"];
  61. }
  62. if (!empty($_SESSION["look"])) {
  63. if (isset($_SESSION["look"]) && $_SESSION["userContext"] === "admin") {
  64. $v_user = $_SESSION["look"];
  65. }
  66. if (
  67. isset($_SESSION["look"]) &&
  68. $_SESSION["look"] == "admin" &&
  69. $_SESSION["POLICY_SYSTEM_PROTECTED_ADMIN"] == "yes"
  70. ) {
  71. header("Location: /");
  72. }
  73. }
  74. # Create filemanager sftp key if missing and trash it after 30 min
  75. if (!file_exists("/home/" . basename($v_user) . "/.ssh/hst-filemanager-key")) {
  76. exec(
  77. "sudo /usr/local/hestia/bin/v-add-user-sftp-key " .
  78. quoteshellarg(basename($v_user)) .
  79. " 30",
  80. $output,
  81. $return_var,
  82. );
  83. // filemanager also requires .ssh chmod o+x ... hopefully we can improve it to g+x or u+x someday
  84. // current minimum for filemanager: chmod 0701 .ssh
  85. shell_exec("sudo chmod o+x " . quoteshellarg("/home/" . basename($v_user) . "/.ssh"));
  86. }
  87. if (!isset($_SESSION["SFTP_PORT"])) {
  88. exec("sudo /usr/local/hestia/bin/v-list-sys-sshd-port json", $output, $result);
  89. $port = json_decode(implode("", $output));
  90. if (is_numeric($port[0]) && $port[0] > 0) {
  91. $_SESSION["SFTP_PORT"] = $port[0];
  92. } elseif (
  93. preg_match('/^\s*Port\s+(\d+)$/im', file_get_contents("/etc/ssh/sshd_config"), $matches)
  94. ) {
  95. $_SESSION["SFTP_PORT"] = $matches[1] ?? 22;
  96. } else {
  97. $_SESSION["SFTP_PORT"] = 22;
  98. }
  99. }
  100. preg_match(
  101. '/(Hestia SFTP Chroot\nMatch User)(.*)/i',
  102. file_get_contents("/etc/ssh/sshd_config"),
  103. $matches,
  104. );
  105. $user_list = explode(",", $matches[2]);
  106. if (in_array($v_user, $user_list)) {
  107. $root = "/";
  108. } else {
  109. $root = "/home/" . $v_user;
  110. }
  111. return new \League\Flysystem\Sftp\SftpAdapter([
  112. "host" => "127.0.0.1",
  113. "port" => intval($_SESSION["SFTP_PORT"]),
  114. "username" => basename($v_user),
  115. "privateKey" => "/home/" . basename($v_user) . "/.ssh/hst-filemanager-key",
  116. "root" => $root,
  117. "timeout" => 10,
  118. "directoryPerm" => 0755,
  119. ]);
  120. };
  121. $dist_config["services"]["Filegator\Services\Archiver\ArchiverInterface"] = [
  122. "handler" => "\Filegator\Services\Archiver\Adapters\HestiaZipArchiver",
  123. "config" => [],
  124. ];
  125. $dist_config["services"]["Filegator\Services\Auth\AuthInterface"] = [
  126. "handler" => "\Filegator\Services\Auth\Adapters\HestiaAuth",
  127. "config" => [
  128. "permissions" => ["read", "write", "upload", "download", "batchdownload", "zip"],
  129. "private_repos" => false,
  130. ],
  131. ];
  132. $dist_config["services"]["Filegator\Services\View\ViewInterface"]["config"] = [
  133. "add_to_head" => '
  134. <style>
  135. .logo {
  136. width: 46px;
  137. }
  138. </style>
  139. ',
  140. "add_to_body" => '
  141. <script>
  142. var checkVueLoaded = setInterval(function() {
  143. if (document.getElementsByClassName("container").length) {
  144. clearInterval(checkVueLoaded);
  145. var navProfile = document.getElementsByClassName("navbar-item profile")[0]; navProfile.replaceWith(navProfile.cloneNode(true))
  146. document.getElementsByClassName("navbar-item logout")[0].text="Exit to Control Panel \u00BB";
  147. div = document.getElementsByClassName("container")[0];
  148. callback = function(){
  149. if (document.getElementsByClassName("navbar-item logout")[0]){
  150. if ( document.getElementsByClassName("navbar-item logout")[0].text != "Exit to Control Panel \u00BB" ){
  151. var navProfile = document.getElementsByClassName("navbar-item profile")[0]; navProfile.replaceWith(navProfile.cloneNode(true))
  152. document.getElementsByClassName("navbar-item logout")[0].text="Exit to Control Panel \u00BB";
  153. }
  154. }
  155. }
  156. config = {
  157. childList:true,
  158. subtree:true
  159. }
  160. observer = new MutationObserver(callback);
  161. observer.observe(div,config);
  162. }
  163. }, 200);
  164. </script>',
  165. ];
  166. return $dist_config;