mirror of
https://github.com/moul/sshportal.git
synced 2025-09-10 14:44:55 +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"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"os"
|
"os"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/gliderlabs/ssh"
|
"github.com/gliderlabs/ssh"
|
||||||
"github.com/sabban/sshportal/pkg/logchannel"
|
"github.com/moul/sshportal/pkg/logchannel"
|
||||||
gossh "golang.org/x/crypto/ssh"
|
gossh "golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -52,18 +53,22 @@ func pipe(lreqs, rreqs <-chan *gossh.Request, lch, rch gossh.Channel, logs_locat
|
||||||
}()
|
}()
|
||||||
|
|
||||||
errch := make(chan error, 1)
|
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)
|
f, err := os.OpenFile(file_name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0640)
|
||||||
if err != nil {
|
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()
|
defer f.Close()
|
||||||
wrappedlch := logchannel.New(lch, f)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
_, _ = io.Copy(wrappedlch, rch)
|
|
||||||
errch <- errors.New("lch closed the connection")
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
_, _ = io.Copy(rch, lch)
|
_, _ = io.Copy(rch, lch)
|
||||||
|
|
Loading…
Add table
Reference in a new issue