configuration.php 4.8 KB

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