mirror of
https://github.com/moul/sshportal.git
synced 2025-09-04 11:44:52 +08:00
Fix when error on session file creation.
This commit is contained in:
parent
ed676b0d7e
commit
58e2abca8c
1 changed files with 14 additions and 9 deletions
|
@ -6,9 +6,10 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
"os"
|
||||
"log"
|
||||
|
||||
"github.com/gliderlabs/ssh"
|
||||
"github.com/sabban/sshportal/pkg/logchannel"
|
||||
"github.com/moul/sshportal/pkg/logchannel"
|
||||
gossh "golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
|
@ -52,19 +53,23 @@ func pipe(lreqs, rreqs <-chan *gossh.Request, lch, rch gossh.Channel, logs_locat
|
|||
}()
|
||||
|
||||
errch := make(chan error, 1)
|
||||
file_name := strings.Join([]string{logs_location, "/", user, "-", time.Now().Format("RFC3339")}, "") // get user
|
||||
file_name := strings.Join([]string{logs_location, "/", user, "-", time.Now().Format(time.RFC3339)}, "") // get user
|
||||
f, err := os.OpenFile(file_name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0640)
|
||||
if err != nil {
|
||||
errch <- errors.New("Opening session file" + file_name + "failed.")
|
||||
go func() {
|
||||
_, _ = io.Copy(lch, rch)
|
||||
errch <- errors.New("lch closed the connection")
|
||||
}()
|
||||
} else {
|
||||
log.Printf("Session is recorded in %v", file_name)
|
||||
wrappedlch := logchannel.New(lch, f)
|
||||
go func() {
|
||||
_, _ = io.Copy(wrappedlch, rch)
|
||||
errch <- errors.New("lch closed the connection")
|
||||
}()
|
||||
}
|
||||
defer f.Close()
|
||||
wrappedlch := logchannel.New(lch, f)
|
||||
|
||||
go func() {
|
||||
_, _ = io.Copy(wrappedlch, rch)
|
||||
errch <- errors.New("lch closed the connection")
|
||||
}()
|
||||
|
||||
go func() {
|
||||
_, _ = io.Copy(rch, lch)
|
||||
errch <- errors.New("rch closed the connection")
|
||||
|
|
Loading…
Add table
Reference in a new issue