|
11 | 11 | $dist_config['frontend_config']['upload_max_size'] = 1024 * 1024 * 1024; |
12 | 12 |
|
13 | 13 | $dist_config['services']['Filegator\Services\Storage\Filesystem']['config']['adapter'] = function () { |
| 14 | + if (isset($_SESSION['user'])) { |
| 15 | + $v_user = $_SESSION['user']; |
| 16 | + } |
| 17 | + if (isset($_SESSION['look']) && ($_SESSION['userContext'] === 'admin')) { |
| 18 | + $v_user = $_SESSION['look']; |
| 19 | + } |
| 20 | + if ((isset($_SESSION['look']) && ($_SESSION['look'] == 'admin') && ($_SESSION['POLICY_SYSTEM_PROTECTED_ADMIN'] == 'yes'))) { |
| 21 | + header('Location: /'); |
| 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 " . escapeshellarg(basename($v_user)) . " 30", $output, $return_var); |
| 26 | + } |
14 | 27 |
|
15 | | - if (isset($_SESSION['user'])) { |
16 | | - $v_user = $_SESSION['user']; |
17 | | - } |
18 | | - if (isset($_SESSION['look']) && ($_SESSION['userContext'] === 'admin')) { |
19 | | - $v_user = $_SESSION['look']; |
20 | | - } |
21 | | - if ((isset($_SESSION['look']) && ($_SESSION['look'] == 'admin') && ($_SESSION['POLICY_SYSTEM_PROTECTED_ADMIN'] == 'yes') )) { |
22 | | - header('Location: /'); |
23 | | - } |
24 | | - # Create filemanager sftp key if missing and trash it after 30 min |
25 | | - if (! file_exists('/home/'.basename($v_user).'/.ssh/hst-filemanager-key')) { |
26 | | - exec ("sudo /usr/local/hestia/bin/v-add-user-sftp-key " . escapeshellarg(basename($v_user)) . " 30", $output, $return_var); |
| 28 | + if (!isset($_SESSION['SFTP_PORT'])) { |
| 29 | + exec("sudo /usr/local/hestia/bin/v-list-sys-sshd-port json", $output, $result); |
| 30 | + if ($output) { |
| 31 | + $port=json_decode(implode('', $output)); |
| 32 | + $_SESSION['SFTP_PORT'] = $port[0]; |
| 33 | + } else { |
| 34 | + $_SESSION['SFTP_PORT'] = 22; |
27 | 35 | } |
| 36 | + } |
28 | 37 |
|
29 | | - if ( !isset($_SESSION['SFTP_PORT']) ) { |
30 | | - if( preg_match('/^\s*Port\s+(\d+)$/im', file_get_contents('/etc/ssh/sshd_config'), $matches) ) { |
31 | | - $_SESSION['SFTP_PORT'] = $matches[1] ?? 22; |
32 | | - } else { |
33 | | - $_SESSION['SFTP_PORT'] = 22; |
34 | | - } |
35 | | - } |
| 38 | + preg_match('/(Hestia SFTP Chroot\nMatch User)(.*)/i', file_get_contents('/etc/ssh/sshd_config'), $matches); |
| 39 | + $user_list = explode(',', $matches[2]); |
| 40 | + if (in_array($v_user, $user_list)) { |
| 41 | + $root = '/'; |
| 42 | + } else { |
| 43 | + $root = '/home/'.$v_user; |
| 44 | + } |
36 | 45 |
|
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 | | - |
45 | | - return new \League\Flysystem\Sftp\SftpAdapter([ |
| 46 | + return new \League\Flysystem\Sftp\SftpAdapter([ |
46 | 47 | 'host' => '127.0.0.1', |
47 | 48 | 'port' => intval($_SESSION['SFTP_PORT']), |
48 | 49 | 'username' => basename($v_user), |
|
51 | 52 | 'timeout' => 10, |
52 | 53 | 'directoryPerm' => 0755, |
53 | 54 | ]); |
54 | | - }; |
| 55 | +}; |
55 | 56 |
|
56 | 57 | $dist_config['services']['Filegator\Services\Archiver\ArchiverInterface'] = [ |
57 | 58 | 'handler' => '\Filegator\Services\Archiver\Adapters\HestiaZipArchiver', |
|
0 commit comments