forked from moul/sshportal
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(deps): internalize deleted dependency
github.com/sabban/bastion no longer exists The code has been replaced by https://github.com/moul/bastion/blob/master/pkg/logchannel/logchannel.go
- Loading branch information
Showing
4 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/binary" | ||
"io" | ||
"syscall" | ||
"time" | ||
|
||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
type logChannel struct { | ||
channel ssh.Channel | ||
writer io.WriteCloser | ||
} | ||
|
||
func writeTTYRecHeader(fd io.Writer, length int) { | ||
t := time.Now() | ||
|
||
tv := syscall.NsecToTimeval(t.UnixNano()) | ||
|
||
binary.Write(fd, binary.LittleEndian, int32(tv.Sec)) | ||
binary.Write(fd, binary.LittleEndian, int32(tv.Usec)) | ||
binary.Write(fd, binary.LittleEndian, int32(length)) | ||
} | ||
|
||
func New(channel ssh.Channel, writer io.WriteCloser) *logChannel { | ||
return &logChannel{ | ||
channel: channel, | ||
writer: writer, | ||
} | ||
} | ||
|
||
func (l *logChannel) Read(data []byte) (int, error) { | ||
return l.Read(data) | ||
} | ||
|
||
func (l *logChannel) Write(data []byte) (int, error) { | ||
writeTTYRecHeader(l.writer, len(data)) | ||
l.writer.Write(data) | ||
|
||
return l.channel.Write(data) | ||
} | ||
|
||
func (l *logChannel) LogWrite(data []byte) (int, error) { | ||
writeTTYRecHeader(l.writer, len(data)) | ||
return l.writer.Write(data) | ||
} | ||
|
||
func (l *logChannel) Close() error { | ||
l.writer.Close() | ||
|
||
return l.channel.Close() | ||
} | ||