|
@ -33,7 +33,7 @@ export default ( |
|
|
? loginOptions(command, remoteAddress) |
|
|
? loginOptions(command, remoteAddress) |
|
|
: sshOptions( |
|
|
: sshOptions( |
|
|
urlArgs(referer, { |
|
|
urlArgs(referer, { |
|
|
ssh: address(referer, user, host), |
|
|
host: address(referer, user, host), |
|
|
port: `${port}`, |
|
|
port: `${port}`, |
|
|
pass, |
|
|
pass, |
|
|
command, |
|
|
command, |
|
@ -48,29 +48,37 @@ export default ( |
|
|
address(referer, user, host).includes('@'), |
|
|
address(referer, user, host).includes('@'), |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
function parseCommand(command: string, path?: string): string { |
|
|
|
|
|
if (command === 'login' && path === undefined) return ''; |
|
|
|
|
|
return path !== undefined |
|
|
|
|
|
? `$SHELL -c "cd ${path};${command === 'login' ? '$SHELL' : command}"` |
|
|
|
|
|
: command; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function sshOptions( |
|
|
function sshOptions( |
|
|
{ pass, path, command, ssh, port, auth }: { [s: string]: string }, |
|
|
{ pass, path, command, host, port, auth }: { [s: string]: string }, |
|
|
key?: string |
|
|
key?: string |
|
|
): string[] { |
|
|
): string[] { |
|
|
|
|
|
const cmd = parseCommand(command, path); |
|
|
const sshRemoteOptsBase = [ |
|
|
const sshRemoteOptsBase = [ |
|
|
'ssh', |
|
|
'ssh', |
|
|
ssh, |
|
|
host, |
|
|
'-t', |
|
|
'-t', |
|
|
'-p', |
|
|
'-p', |
|
|
port, |
|
|
port, |
|
|
'-o', |
|
|
'-o', |
|
|
`PreferredAuthentications=${auth}`, |
|
|
`PreferredAuthentications=${auth}`, |
|
|
path !== undefined |
|
|
|
|
|
? `$SHELL -c "cd ${path};${command === 'login' ? '$SHELL' : command}"` |
|
|
|
|
|
: command, |
|
|
|
|
|
]; |
|
|
]; |
|
|
if (key) { |
|
|
if (key) { |
|
|
return sshRemoteOptsBase.concat(['-i', key]); |
|
|
return sshRemoteOptsBase.concat(['-i', key, cmd]); |
|
|
} |
|
|
} |
|
|
if (pass) { |
|
|
if (pass) { |
|
|
return ['sshpass', '-p', pass].concat(sshRemoteOptsBase); |
|
|
return ['sshpass', '-p', pass].concat(sshRemoteOptsBase, [cmd]); |
|
|
|
|
|
} |
|
|
|
|
|
if (cmd === '') { |
|
|
|
|
|
return sshRemoteOptsBase; |
|
|
} |
|
|
} |
|
|
return sshRemoteOptsBase; |
|
|
return sshRemoteOptsBase.concat([cmd]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function loginOptions(command: string, remoteAddress: string): string[] { |
|
|
function loginOptions(command: string, remoteAddress: string): string[] { |
|
|