configuration.php 5.5 KB

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