Skip to content

Commit e111778

Browse files
committed
Added support for username replacement (and password too) for remote SFTP proxy configuration.
1 parent 4e3123e commit e111778

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

functions.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,32 @@ function createResponseObject($connectionName, $username, $groups = []) {
160160
$output['username'] = $username;
161161
$output['home_dir'] = $userHomeDirectory;
162162

163+
// Allow for username-specific folders in Remote SFTP Proxy:
164+
if (isset($output['filesystem']['sftpconfig'])) {
165+
logMessage('Reviewing Remote SFTP Config for user to see if username replacement is needed');
166+
167+
// Home Directory doesn't seem needed when using Remote SFTP Proxy option:
168+
$output['home_dir'] = '';
169+
170+
$output['filesystem']['sftpconfig']['endpoint'] = str_replace('#USERNAME#', $username, $output['filesystem']['sftpconfig']['endpoint']);
171+
$output['filesystem']['sftpconfig']['username'] = str_replace('#USERNAME#', $username, $output['filesystem']['sftpconfig']['username']);
172+
173+
if ($output['filesystem']['sftpconfig']['password']['status'] === 'Plain') {
174+
if (strpos($output['filesystem']['sftpconfig']['password']['payload'], '#PASSWORD#') === 0) {
175+
logMessage('Retrieving User Password from Request for Dynamic Replacement');
176+
$data = getData();
177+
$password = $data['password'];
178+
unset($data);
179+
logMessage('Retrieved User Password from Request for Dynamic Replacement');
180+
181+
$output['filesystem']['sftpconfig']['password']['payload'] = str_replace('#PASSWORD#', $password, $output['filesystem']['sftpconfig']['password']['payload']);
182+
}
183+
}
184+
185+
$output['filesystem']['sftpconfig']['password']['additional_data'] = str_replace('#USERNAME#', $username, $output['filesystem']['sftpconfig']['password']['additional_data']);
186+
$output['filesystem']['sftpconfig']['prefix'] = str_replace('#USERNAME#', $username, $output['filesystem']['sftpconfig']['prefix']);
187+
}
188+
163189
if (isset($virtual_folders[$connectionName])) {
164190
$output['virtual_folders'] = $virtual_folders[$connectionName];
165191

0 commit comments

Comments
 (0)