package sshtun import ( "bufio" "io" "github.com/Neur0toxine/sshpoke/pkg/proto/ssh" "github.com/jonstacks/iomerge" "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 } 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() } } func StdoutPrinterBannerCallback(log *zap.SugaredLogger) ssh.BannerCallback { return func(msg string) error { log.Debug(msg) return nil } }