forked from jumpserver/koko
/
client.go
61 lines (49 loc) · 1 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package httpd
import (
"io"
"github.com/gliderlabs/ssh"
"github.com/kataras/neffos"
)
type Client struct {
Uuid string
WinChan chan ssh.Window
UserRead io.Reader
UserWrite io.WriteCloser
Conn *UserWebsocketConn
pty ssh.Pty
}
func (c *Client) WinCh() <-chan ssh.Window {
return c.WinChan
}
func (c *Client) LoginFrom() string {
return "WT"
}
func (c *Client) RemoteAddr() string {
return c.Conn.Addr
}
func (c *Client) Read(p []byte) (n int, err error) {
return c.UserRead.Read(p)
}
func (c *Client) Write(p []byte) (n int, err error) {
if _, ok := c.Conn.GetClient(c.Uuid); ok {
data := DataMsg{Data: string(p), Room: c.Uuid}
c.Conn.SendDataEvent(neffos.Marshal(data))
return len(p), nil
}
return 0, io.EOF
}
func (c *Client) Pty() ssh.Pty {
return c.pty
}
func (c *Client) Close() (err error) {
return c.UserWrite.Close()
}
func (c *Client) SetWinSize(size ssh.Window) {
select {
case c.WinChan <- size:
default:
}
}
func (c *Client) ID() string {
return c.Uuid
}