Skip to content

Commit a90f44d

Browse files
committed
Added support for username replacement (and password too) for remote SFTP proxy configuration.
1 parent 50cb361 commit a90f44d

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
@@ -157,6 +157,32 @@ function createResponseObject($connectionName, $username, $groups = []) {
157157
$output['username'] = $username;
158158
$output['home_dir'] = $userHomeDirectory;
159159

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

0 commit comments

Comments
 (0)