Make `REMOTE_COMMANDS` flag support multiple users

feature/forwarding
Kelvin Schoofs 3 years ago
parent d68bed01cf
commit 7dc40bd285

@ -4,7 +4,7 @@ import type { Client, ClientChannel, SFTPWrapper } from 'ssh2';
import * as vscode from 'vscode';
import { configMatches, getFlagBoolean, loadConfigs } from './config';
import type { EnvironmentVariable, FileSystemConfig } from './fileSystemConfig';
import { Logging } from './logging';
import { Logging, LOGGING_NO_STACKTRACE } from './logging';
import { ActivePortForwarding } from './portForwarding';
import type { SSHPseudoTerminal } from './pseudoTerminal';
import type { SSHFileSystem } from './sshFileSystem';
@ -162,7 +162,13 @@ export class ConnectionManager {
const cmdPath = await this._createCommandTerminal(client, name);
environment.push({ key: 'KELVIN_SSHFS_CMD_PATH', value: cmdPath });
const sftp = await toPromise<SFTPWrapper>(cb => client.sftp(cb));
await toPromise(cb => sftp.writeFile('/tmp/.Kelvin_sshfs', TMP_PROFILE_SCRIPT, { mode: 0o666 }, cb));
const tmpPath = `/tmp/.Kelvin_sshfs.${actualConfig.username || 'root'}`;
await toPromise(cb => sftp.writeFile(tmpPath, TMP_PROFILE_SCRIPT, { mode: 0o644 }, cb)).catch(e => {
const msg = `Could not write profile script to: ${tmpPath}`;
logging.error(msg, LOGGING_NO_STACKTRACE);
logging.error(e);
throw new Error(msg);
});
}
// Set up the Connection object
let timeoutCounter = 0;

@ -172,12 +172,13 @@ export async function createTerminal(options: TerminalOptions): Promise<SSHPseud
commands.push(environmentToExportString(env));
// Beta feature to add a "code <file>" command in terminals to open the file locally
if (getFlagBoolean('REMOTE_COMMANDS', false, actualConfig.flags)[0]) {
const tmpPath = `/tmp/.Kelvin_sshfs.${actualConfig.username || 'root'}`;
// For bash
commands.push(`export ORIG_PROMPT_COMMAND="$PROMPT_COMMAND"`);
commands.push(`export PROMPT_COMMAND='source /tmp/.Kelvin_sshfs PC; $ORIG_PROMPT_COMMAND'`);
commands.push(`export PROMPT_COMMAND='source ${tmpPath} PC; $ORIG_PROMPT_COMMAND'`);
// For sh
commands.push(`export OLD_ENV="$ENV"`); // not actually used (yet?)
commands.push(`export ENV=/tmp/.Kelvin_sshfs`);
commands.push(`export ENV=${tmpPath}`);
}
// Push the actual command or (default) shell command with replaced variables
if (options.command) {

Loading…
Cancel
Save