configuration.php 4.3 KB

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