mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
sample implementation of connserver w/ regular ssh connections
This commit is contained in:
parent
c874a6e302
commit
6d58478e76
@ -276,7 +276,9 @@ func (bc *BlockController) DoRunShellCommand(rc *RunShellOpts, blockMeta waveobj
|
|||||||
return fmt.Errorf("not connected, cannot start shellproc")
|
return fmt.Errorf("not connected, cannot start shellproc")
|
||||||
}
|
}
|
||||||
if !blockMeta.GetBool(waveobj.MetaKey_CmdNoWsh, false) {
|
if !blockMeta.GetBool(waveobj.MetaKey_CmdNoWsh, false) {
|
||||||
jwtStr, err := wshutil.MakeClientJWTToken(wshrpc.RpcContext{TabId: bc.TabId, BlockId: bc.BlockId, Conn: conn.Opts.String()}, conn.GetDomainSocketName())
|
sockName := conn.GetDomainSocketName()
|
||||||
|
sockName = "~/.waveterm/wave-remote.sock"
|
||||||
|
jwtStr, err := wshutil.MakeClientJWTToken(wshrpc.RpcContext{TabId: bc.TabId, BlockId: bc.BlockId, Conn: conn.Opts.String()}, sockName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error making jwt token: %w", err)
|
return fmt.Errorf("error making jwt token: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -216,8 +216,10 @@ func (conn *SSHConn) StartConnServer() error {
|
|||||||
return fmt.Errorf("unable to create ssh session for conn controller: %w", err)
|
return fmt.Errorf("unable to create ssh session for conn controller: %w", err)
|
||||||
}
|
}
|
||||||
pipeRead, pipeWrite := io.Pipe()
|
pipeRead, pipeWrite := io.Pipe()
|
||||||
|
inputPipeRead, inputPipeWrite := io.Pipe()
|
||||||
sshSession.Stdout = pipeWrite
|
sshSession.Stdout = pipeWrite
|
||||||
sshSession.Stderr = pipeWrite
|
sshSession.Stderr = pipeWrite
|
||||||
|
sshSession.Stdin = inputPipeRead
|
||||||
shellPath, err := remote.DetectShell(client)
|
shellPath, err := remote.DetectShell(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -226,7 +228,7 @@ func (conn *SSHConn) StartConnServer() error {
|
|||||||
if remote.IsPowershell(shellPath) {
|
if remote.IsPowershell(shellPath) {
|
||||||
cmdStr = fmt.Sprintf("$env:%s=\"%s\"; %s connserver", wshutil.WaveJwtTokenVarName, jwtToken, wshPath)
|
cmdStr = fmt.Sprintf("$env:%s=\"%s\"; %s connserver", wshutil.WaveJwtTokenVarName, jwtToken, wshPath)
|
||||||
} else {
|
} else {
|
||||||
cmdStr = fmt.Sprintf("%s=\"%s\" %s connserver", wshutil.WaveJwtTokenVarName, jwtToken, wshPath)
|
cmdStr = fmt.Sprintf("%s=\"%s\" %s connserver --router", wshutil.WaveJwtTokenVarName, jwtToken, wshPath)
|
||||||
}
|
}
|
||||||
log.Printf("starting conn controller: %s\n", cmdStr)
|
log.Printf("starting conn controller: %s\n", cmdStr)
|
||||||
err = sshSession.Start(cmdStr)
|
err = sshSession.Start(cmdStr)
|
||||||
@ -246,6 +248,10 @@ func (conn *SSHConn) StartConnServer() error {
|
|||||||
log.Printf("conn controller (%q) terminated: %v", conn.GetName(), waitErr)
|
log.Printf("conn controller (%q) terminated: %v", conn.GetName(), waitErr)
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
|
logName := fmt.Sprintf("conncontroller:%s", conn.GetName())
|
||||||
|
wshutil.HandleStdIOClient(logName, pipeRead, inputPipeWrite)
|
||||||
|
return
|
||||||
|
|
||||||
readErr := wshutil.StreamToLines(pipeRead, func(line []byte) {
|
readErr := wshutil.StreamToLines(pipeRead, func(line []byte) {
|
||||||
lineStr := string(line)
|
lineStr := string(line)
|
||||||
if !strings.HasSuffix(lineStr, "\n") {
|
if !strings.HasSuffix(lineStr, "\n") {
|
||||||
|
Loading…
Reference in New Issue
Block a user