Make instant connections try to use PuTTY

feature/ssh-config
Kelvin Schoofs 4 years ago
parent 844b0e1b43
commit 8852d4733b

@ -70,47 +70,55 @@ export async function calculateActualConfig(config: FileSystemConfig): Promise<F
logging.warning(`\tConfigurating uses putty, but platform is ${process.platform}`); logging.warning(`\tConfigurating uses putty, but platform is ${process.platform}`);
} }
let nameOnly = true; let nameOnly = true;
if (config.putty === true) { let mandatory = true;
if (config.putty === true || config.putty === '<TRY>') {
// ^ '<TRY>' is a special case used in parseConnectionString in fileSystemConfig.ts
await promptFields(config, 'host'); await promptFields(config, 'host');
// TODO: `config.putty === true` without config.host should prompt the user with *all* PuTTY sessions // TODO: `config.putty === true` without config.host should prompt the user with *all* PuTTY sessions
if (!config.host) throw new Error(`'putty' was true but 'host' is empty/missing`); if (!config.host) throw new Error(`'putty' was true but 'host' is empty/missing`);
mandatory = config.putty === true;
config.putty = config.host; config.putty = config.host;
nameOnly = false; nameOnly = false;
} else { } else {
config.putty = replaceVariables(config.putty); config.putty = replaceVariables(config.putty);
} }
const session = await (await import('./putty')).getSession(config.putty, config.host, config.username, nameOnly); const session = await (await import('./putty')).getSession(config.putty, config.host, config.username, nameOnly);
if (!session) throw new Error(`Couldn't find the requested PuTTY session`); if (session) {
if (session.protocol !== 'ssh') throw new Error(`The requested PuTTY session isn't a SSH session`); if (session.protocol !== 'ssh') throw new Error(`The requested PuTTY session isn't a SSH session`);
config.username = config.username || session.username; config.username = config.username || session.username;
if (!config.username && session.hostname && session.hostname.indexOf('@') >= 1) { if (!config.username && session.hostname && session.hostname.indexOf('@') >= 1) {
config.username = session.hostname.substr(0, session.hostname.indexOf('@')); config.username = session.hostname.substr(0, session.hostname.indexOf('@'));
} }
config.host = config.host || session.hostname; config.host = config.host || session.hostname;
config.port = session.portnumber || config.port; config.port = session.portnumber || config.port;
config.agent = config.agent || (session.tryagent ? 'pageant' : undefined); config.agent = config.agent || (session.tryagent ? 'pageant' : undefined);
if (session.usernamefromenvironment) { if (session.usernamefromenvironment) {
config.username = process.env.USERNAME || process.env.USER; config.username = process.env.USERNAME || process.env.USER;
if (!config.username) throw new Error(`Trying to use the system username, but process.env.USERNAME or process.env.USER is missing`); if (!config.username) throw new Error(`Trying to use the system username, but process.env.USERNAME or process.env.USER is missing`);
} }
config.privateKeyPath = config.privateKeyPath || (!config.agent && session.publickeyfile) || undefined; config.privateKeyPath = config.privateKeyPath || (!config.agent && session.publickeyfile) || undefined;
switch (session.proxymethod) { switch (session.proxymethod) {
case 0: case 0:
break; break;
case 1: case 1:
case 2: case 2:
case 3: case 3:
if (!session.proxyhost) throw new Error(`Proxymethod is SOCKS 4/5 or HTTP but 'proxyhost' is missing`); if (!session.proxyhost) throw new Error(`Proxymethod is SOCKS 4/5 or HTTP but 'proxyhost' is missing`);
config.proxy = { config.proxy = {
host: session.proxyhost, host: session.proxyhost,
port: session.proxyport, port: session.proxyport,
type: session.proxymethod === 1 ? 'socks4' : (session.proxymethod === 2 ? 'socks5' : 'http'), type: session.proxymethod === 1 ? 'socks4' : (session.proxymethod === 2 ? 'socks5' : 'http'),
}; };
break; break;
default: default:
throw new Error(`The requested PuTTY session uses an unsupported proxy method`); throw new Error(`The requested PuTTY session uses an unsupported proxy method`);
}
logging.debug(`\tReading PuTTY configuration lead to the following configuration:\n${JSON.stringify(config, null, 4)}`);
} else if (mandatory) {
throw new Error(`Couldn't find the requested PuTTY session`);
} else {
logging.debug(`\tConfig suggested finding a PuTTY configuration, did not find one`);
} }
logging.debug(`\tReading PuTTY configuration lead to the following configuration:\n${JSON.stringify(config, null, 4)}`);
} }
if (config.privateKeyPath) { if (config.privateKeyPath) {
try { try {

@ -143,5 +143,6 @@ export function parseConnectionString(input: string): [config: FileSystemConfig,
username: user || '$USERNAME', username: user || '$USERNAME',
_locations: [], _locations: [],
//debug: true as any, //debug: true as any,
putty: process.platform === 'win32' && '<TRY>', // Since this is like a "quick connect", automatically enable PuTTY support
}, path]; }, path];
} }

Loading…
Cancel
Save