jump hosts

This commit is contained in:
Eugene
2024-08-03 23:28:46 +02:00
parent 8928fa1737
commit a3cc85627d
4 changed files with 26 additions and 21 deletions

View File

@@ -1,3 +1,4 @@
import * as russh from 'russh'
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'
import colors from 'ansi-colors'
import { Component, Injector, HostListener } from '@angular/core'
@@ -94,17 +95,21 @@ export class SSHTabComponent extends ConnectableTerminalTabComponent<SSHProfile>
}
})
// session.jumpStream = await new Promise((resolve, reject) => jumpSession.ssh.forwardOut(
// '127.0.0.1', 0, profile.options.host, profile.options.port ?? 22,
// (err, stream) => {
// if (err) {
// jumpSession.emitServiceMessage(colors.bgRed.black(' X ') + ` Could not set up port forward on ${jumpConnection.name}`)
// reject(err)
// return
// }
// resolve(stream)
// },
// ))
if (!(jumpSession.ssh instanceof russh.AuthenticatedSSHClient)) {
throw new Error('Jump session is not authenticated yet somehow')
}
try {
session.jumpChannel = await jumpSession.ssh.openTCPForwardChannel({
addressToConnectTo: profile.options.host,
portToConnectTo: profile.options.port ?? 22,
originatorAddress: '127.0.0.1',
originatorPort: 0,
})
} catch (err) {
jumpSession.emitServiceMessage(colors.bgRed.black(' X ') + ` Could not set up port forward on ${jumpConnection.name}`)
throw err
}
}
}

View File

@@ -9,7 +9,7 @@ import { ConfigService, FileProvidersService, HostAppService, NotificationsServi
import { Socket } from 'net'
import { Subject, Observable } from 'rxjs'
import { HostKeyPromptModalComponent } from '../components/hostKeyPromptModal.component'
// import { HTTPProxyStream, ProxyCommandStream, SocksProxyStream } from '../services/ssh.service'
// import { HTTPProxyStream, SocksProxyStream } from '../services/ssh.service'
import { PasswordStorageService } from '../services/passwordStorage.service'
import { SSHKnownHostsService } from '../services/sshKnownHosts.service'
import { SFTPSession } from './sftp'
@@ -64,7 +64,7 @@ export class SSHSession {
ssh: russh.SSHClient|russh.AuthenticatedSSHClient
sftp?: russh.SFTP
forwardedPorts: ForwardedPort[] = []
jumpStream: any
jumpChannel: russh.Channel|null = null
proxyCommandStream: SSHProxyStream|null = null
savedPassword?: string
get serviceMessage$ (): Observable<string> { return this.serviceMessage }
@@ -225,6 +225,9 @@ export class SSHSession {
// this.proxyCommandStream.message$.subscribe(message => {
// this.emitServiceMessage(colors.bgBlue.black(' Proxy ') + ' ' + message.trim())
// })
} else if (this.jumpChannel) {
transport = await russh.SshTransport.newSshChannel(await this.jumpChannel.take())
this.jumpChannel = null
} else {
transport = await russh.SshTransport.newSocket(`${this.profile.options.host.trim()}:${this.profile.options.port ?? 22}`)
}
@@ -314,9 +317,6 @@ export class SSHSession {
// ssh.connect({
// host: this.profile.options.host.trim(),
// port: this.profile.options.port ?? 22,
// sock: this.proxyCommandStream?.socket ?? this.jumpStream,
// agent: this.agentPath,
// agentForward: this.profile.options.agentForward && !!this.agentPath,
// keepaliveInterval: this.profile.options.keepaliveInterval ?? 15000,