You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package obfssh
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
_ = iota
|
|
|
|
// DEBUG log level debug
|
|
|
|
DEBUG
|
|
|
|
// INFO log level info
|
|
|
|
INFO
|
|
|
|
// ERROR log level error
|
|
|
|
ERROR
|
|
|
|
)
|
|
|
|
|
|
|
|
// SSHLogLevel global value for log level
|
|
|
|
var SSHLogLevel = ERROR
|
|
|
|
|
|
|
|
// PipeAndClose pipe the data between c and s, close both when done
|
|
|
|
func PipeAndClose(c io.ReadWriteCloser, s io.ReadWriteCloser) {
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
log.Printf("recovered: %+v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer c.Close()
|
|
|
|
defer s.Close()
|
|
|
|
cc := make(chan struct{}, 2)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
io.Copy(c, s)
|
|
|
|
cc <- struct{}{}
|
|
|
|
}()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
io.Copy(s, c)
|
|
|
|
cc <- struct{}{}
|
|
|
|
}()
|
|
|
|
|
|
|
|
<-cc
|
|
|
|
}
|
|
|
|
|
|
|
|
// Log log the message by level
|
|
|
|
func Log(level int, s string, args ...interface{}) {
|
|
|
|
if level >= SSHLogLevel {
|
|
|
|
log.Printf(s, args...)
|
|
|
|
}
|
|
|
|
}
|