sshpoke/internal/server/driver/ssh/sshtun/printer.go

44 lines
853 B
Go
Raw Normal View History

2023-11-18 21:23:29 +03:00
package sshtun
import (
"bufio"
"io"
2023-11-18 21:23:29 +03:00
2023-11-18 21:51:44 +03:00
"github.com/Neur0toxine/sshpoke/pkg/proto/ssh"
"github.com/jonstacks/iomerge"
2023-11-18 21:23:29 +03:00
"go.uber.org/zap"
)
func StdoutPrinterSessionCallback(log *zap.SugaredLogger) SessionCallback {
return func(session *ssh.Session) {
stdout, err := session.StdoutPipe()
if err != nil {
return
}
stderr, err := session.StderrPipe()
if err != nil {
return
2023-11-18 21:23:29 +03:00
}
combined := iomerge.NewStreamMerger(2)
combined.Write(func(readers chan<- io.Reader) {
readers <- stdout
readers <- stderr
})
combined.Read(func(r io.Reader) error {
scan := bufio.NewScanner(r)
for scan.Scan() {
log.Debug(scan.Text())
}
return nil
})
_ = combined.Wait()
2023-11-18 21:23:29 +03:00
}
}
func StdoutPrinterBannerCallback(log *zap.SugaredLogger) ssh.BannerCallback {
return func(msg string) error {
log.Debug(msg)
return nil
}
}