import url from 'url' ; import type { Socket } from 'socket.io' ; import type { SSH } from '../shared/interfaces' ; import { address } from './command/address.js' ; import { loginOptions } from './command/login.js' ; import { sshOptions } from './command/ssh.js' ; const localhost = ( host ) : boolean => process . getuid ( ) === 0 && ( host === 'localhost' || host === '0.0.0.0' || host === '127.0.0.1' ) ; const urlArgs = ( referer , def ) : { [ s ] : string ; } => Object . assign ( def , url . parse ( referer , true ) . query ) ; export function getCommand ( { request : { headers } , client : { conn : { remoteAddress } , } , } , { user , host , port , auth , pass , key , knownHosts , config } , command , forcessh ) { const sshAddress = address ( headers , user , host ) ; const localLogin = ! forcessh && localhost ( host ) ; return localLogin ? [ loginOptions ( command , remoteAddress ) , localLogin ] : [ sshOptions ( { ... urlArgs ( headers . referer , { port : `${ port }` , pass : pass || '' , command , auth , knownHosts , config : config || '' , } ) , host : sshAddress , } , key ) , user !== '' || user . includes ( '@' ) || sshAddress . includes ( '@' ) , ] ; }