configuration.php 5.2 KB

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