configuration.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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'];
  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 (isset($_SESSION['user'])) {
  12. $v_user = $_SESSION['user'];
  13. }
  14. if (!empty($_SESSION['look'])) {
  15. if (isset($_SESSION['look']) && ($_SESSION['userContext'] === 'admin')) {
  16. $v_user = $_SESSION['look'];
  17. }
  18. if ((isset($_SESSION['look']) && ($_SESSION['look'] == 'admin') && ($_SESSION['POLICY_SYSTEM_PROTECTED_ADMIN'] == 'yes'))) {
  19. header('Location: /');
  20. }
  21. }
  22. # Create filemanager sftp key if missing and trash it after 30 min
  23. if (! file_exists('/home/'.basename($v_user).'/.ssh/hst-filemanager-key')) {
  24. exec("sudo /usr/local/hestia/bin/v-add-user-sftp-key " . escapeshellarg(basename($v_user)) . " 30", $output, $return_var);
  25. }
  26. if (!isset($_SESSION['SFTP_PORT'])) {
  27. exec("sudo /usr/local/hestia/bin/v-list-sys-sshd-port json", $output, $result);
  28. $port=json_decode(implode('', $output));
  29. if (is_numeric($port[0]) && $port[0] > 0) {
  30. $_SESSION['SFTP_PORT'] = $port[0];
  31. } elseif (preg_match('/^\s*Port\s+(\d+)$/im', file_get_contents('/etc/ssh/sshd_config'), $matches)) {
  32. $_SESSION['SFTP_PORT'] = $matches[1] ?? 22;
  33. } else {
  34. $_SESSION['SFTP_PORT'] = 22;
  35. }
  36. }
  37. preg_match('/(Hestia SFTP Chroot\nMatch User)(.*)/i', file_get_contents('/etc/ssh/sshd_config'), $matches);
  38. $user_list = explode(',', $matches[2]);
  39. if (in_array($v_user, $user_list)) {
  40. $root = '/';
  41. } else {
  42. $root = '/home/'.$v_user;
  43. }
  44. return new \League\Flysystem\Sftp\SftpAdapter([
  45. 'host' => '127.0.0.1',
  46. 'port' => intval($_SESSION['SFTP_PORT']),
  47. 'username' => basename($v_user),
  48. 'privateKey' => '/home/'.basename($v_user).'/.ssh/hst-filemanager-key',
  49. 'root' => $root,
  50. 'timeout' => 10,
  51. 'directoryPerm' => 0755,
  52. ]);
  53. };
  54. $dist_config['services']['Filegator\Services\Archiver\ArchiverInterface'] = [
  55. 'handler' => '\Filegator\Services\Archiver\Adapters\HestiaZipArchiver',
  56. 'config' => [],
  57. ];
  58. $dist_config['services']['Filegator\Services\Auth\AuthInterface'] = [
  59. 'handler' => '\Filegator\Services\Auth\Adapters\HestiaAuth',
  60. 'config' => [
  61. 'permissions' => ['read', 'write', 'upload', 'download', 'batchdownload', 'zip'],
  62. 'private_repos' => false,
  63. ],
  64. ];
  65. $dist_config['services']['Filegator\Services\View\ViewInterface']['config'] = [
  66. 'add_to_head' => '
  67. <style>
  68. .logo {
  69. width: 46px;
  70. }
  71. </style>
  72. ',
  73. 'add_to_body' => '
  74. <script>
  75. var checkVueLoaded = setInterval(function() {
  76. if (document.getElementsByClassName("container").length) {
  77. clearInterval(checkVueLoaded);
  78. var navProfile = document.getElementsByClassName("navbar-item profile")[0]; navProfile.replaceWith(navProfile.cloneNode(true))
  79. document.getElementsByClassName("navbar-item logout")[0].text="Exit to Control Panel \u00BB";
  80. div = document.getElementsByClassName("container")[0];
  81. callback = function(){
  82. if (document.getElementsByClassName("navbar-item logout")[0]){
  83. if ( document.getElementsByClassName("navbar-item logout")[0].text != "Exit to Control Panel \u00BB" ){
  84. var navProfile = document.getElementsByClassName("navbar-item profile")[0]; navProfile.replaceWith(navProfile.cloneNode(true))
  85. document.getElementsByClassName("navbar-item logout")[0].text="Exit to Control Panel \u00BB";
  86. }
  87. }
  88. }
  89. config = {
  90. childList:true,
  91. subtree:true
  92. }
  93. observer = new MutationObserver(callback);
  94. observer.observe(div,config);
  95. }
  96. }, 200);
  97. </script>',
  98. ];
  99. return $dist_config;