From dd7fc5ff075681398bbe3af12b29d14dc441eaff Mon Sep 17 00:00:00 2001 From: lwch Date: Tue, 28 Sep 2021 11:43:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=97=A0=E6=B3=95=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E8=AE=BE=E7=BD=AEto=5Fidx=E5=AD=97=E6=AE=B5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/client/connect.go | 4 ++ code/client/pool/send.go | 41 ----------- code/client/pool/send_shell.go | 85 ++++++++++++++++++++++ code/client/shell/forward.go | 10 +++ code/client/shell/h_ws.go | 2 + code/client/shell/link.go | 2 + code/network/msg.pb.go | 125 ++++++++++++++++++++------------- code/network/msg.proto | 14 ++-- code/network/shell.pb.go | 112 +++++++++++++++++++++++------ code/network/shell.proto | 5 ++ go.mod | 4 +- 11 files changed, 285 insertions(+), 119 deletions(-) create mode 100644 code/client/pool/send_shell.go diff --git a/code/client/connect.go b/code/client/connect.go index b7cab9a..51f1cc0 100644 --- a/code/client/connect.go +++ b/code/client/connect.go @@ -21,6 +21,7 @@ func connect(conn *pool.Conn, msg *network.Msg) { } link, err := net.Dial(dial, fmt.Sprintf("%s:%d", req.GetAddr(), req.GetPort())) if err != nil { + logging.Error("connect to %s:%d failed, err=%v", req.GetAddr(), req.GetPort(), err) conn.SendConnectError(msg.GetFrom(), msg.GetFromIdx(), msg.GetLinkId(), err.Error()) return } @@ -55,7 +56,10 @@ func shellCreate(conn *pool.Conn, msg *network.Msg) { err := lk.Exec() if err != nil { logging.Error("create shell failed: %v", err) + conn.SendShellCreatedError(msg.GetFrom(), msg.GetFromIdx(), msg.GetLinkId(), err.Error()) return } + conn.SendShellCreatedOK(msg.GetFrom(), msg.GetFromIdx(), msg.GetLinkId()) lk.Forward() + lk.OnWork <- struct{}{} } diff --git a/code/client/pool/send.go b/code/client/pool/send.go index 6870679..9a72b2c 100644 --- a/code/client/pool/send.go +++ b/code/client/pool/send.go @@ -113,44 +113,3 @@ func (conn *Conn) SendKeepalive() { case <-time.After(conn.parent.cfg.WriteTimeout): } } - -// SendShellCreate send shell create message -func (conn *Conn) SendShellCreate(id string, cfg global.Tunnel) { - var msg network.Msg - msg.To = cfg.Target - msg.XType = network.Msg_shell_create - msg.LinkId = id - msg.Payload = &network.Msg_Screate{ - Screate: &network.ShellCreate{ - Name: cfg.Name, - Exec: cfg.Exec, - }, - } - select { - case conn.write <- &msg: - case <-time.After(conn.parent.cfg.WriteTimeout): - } -} - -// SendData send shell data -func (conn *Conn) SendShellData(to string, toIdx uint32, id string, data []byte) { - dup := func(data []byte) []byte { - ret := make([]byte, len(data)) - copy(ret, data) - return ret - } - var msg network.Msg - msg.To = to - msg.ToIdx = toIdx - msg.XType = network.Msg_shell_data - msg.LinkId = id - msg.Payload = &network.Msg_Sdata{ - Sdata: &network.ShellData{ - Data: dup(data), - }, - } - select { - case conn.write <- &msg: - case <-time.After(conn.parent.cfg.WriteTimeout): - } -} diff --git a/code/client/pool/send_shell.go b/code/client/pool/send_shell.go new file mode 100644 index 0000000..5353d29 --- /dev/null +++ b/code/client/pool/send_shell.go @@ -0,0 +1,85 @@ +package pool + +import ( + "natpass/code/client/global" + "natpass/code/network" + "time" +) + +// SendShellCreate send shell create message +func (conn *Conn) SendShellCreate(id string, cfg global.Tunnel) { + var msg network.Msg + msg.To = cfg.Target + msg.XType = network.Msg_shell_create + msg.LinkId = id + msg.Payload = &network.Msg_Screate{ + Screate: &network.ShellCreate{ + Name: cfg.Name, + Exec: cfg.Exec, + }, + } + select { + case conn.write <- &msg: + case <-time.After(conn.parent.cfg.WriteTimeout): + } +} + +// SendShellCreatedError send shell create error response message +func (conn *Conn) SendShellCreatedError(to string, toIdx uint32, id, info string) { + var msg network.Msg + msg.To = to + msg.ToIdx = toIdx + msg.XType = network.Msg_shell_created + msg.LinkId = id + msg.Payload = &network.Msg_Screated{ + Screated: &network.ShellCreated{ + Ok: false, + Msg: info, + }, + } + select { + case conn.write <- &msg: + case <-time.After(conn.parent.cfg.WriteTimeout): + } +} + +// SendShellCreatedOK send shell create success response message +func (conn *Conn) SendShellCreatedOK(to string, toIdx uint32, id string) { + var msg network.Msg + msg.To = to + msg.ToIdx = toIdx + msg.XType = network.Msg_shell_created + msg.LinkId = id + msg.Payload = &network.Msg_Screated{ + Screated: &network.ShellCreated{ + Ok: true, + }, + } + select { + case conn.write <- &msg: + case <-time.After(conn.parent.cfg.WriteTimeout): + } +} + +// SendData send shell data +func (conn *Conn) SendShellData(to string, toIdx uint32, id string, data []byte) { + dup := func(data []byte) []byte { + ret := make([]byte, len(data)) + copy(ret, data) + return ret + } + var msg network.Msg + msg.To = to + msg.ToIdx = toIdx + msg.XType = network.Msg_shell_data + msg.LinkId = id + msg.Payload = &network.Msg_Sdata{ + Sdata: &network.ShellData{ + Data: dup(data), + }, + } + select { + case conn.write <- &msg: + case <-time.After(conn.parent.cfg.WriteTimeout): + } +} diff --git a/code/client/shell/forward.go b/code/client/shell/forward.go index c8d160b..76342a6 100644 --- a/code/client/shell/forward.go +++ b/code/client/shell/forward.go @@ -21,7 +21,16 @@ func (link *Link) remoteRead() { if msg == nil { return } + link.targetIdx = msg.GetFromIdx() switch msg.GetXType() { + case network.Msg_shell_created: + if msg.GetCrep().GetOk() { + link.OnWork <- struct{}{} + continue + } + logging.Error("create shell %s on tunnel %s failed, err=%s", + link.id, link.parent.Name, msg.GetCrep().GetMsg()) + return case network.Msg_shell_resize: // TODO case network.Msg_shell_data: @@ -41,6 +50,7 @@ func (link *Link) remoteRead() { func (link *Link) localRead() { defer utils.Recover("localRead") defer link.Close() + <-link.OnWork buf := make([]byte, 16*1024) for { n, err := link.stdout.Read(buf) diff --git a/code/client/shell/h_ws.go b/code/client/shell/h_ws.go index 11611ea..65ca0f3 100644 --- a/code/client/shell/h_ws.go +++ b/code/client/shell/h_ws.go @@ -19,6 +19,7 @@ func (shell *Shell) WS(pool *pool.Pool, w http.ResponseWriter, r *http.Request) id := strings.TrimPrefix(r.URL.Path, "/ws/") conn := pool.Get(id) + logging.Info("ws: %d", conn.Idx) local, err := upgrader.Upgrade(w, r, nil) if err != nil { logging.Error("upgrade websocket failed: %s, err=%v", shell.Name, err) @@ -44,6 +45,7 @@ func (shell *Shell) WS(pool *pool.Pool, w http.ResponseWriter, r *http.Request) func (shell *Shell) localForward(id string, local *websocket.Conn, remote *pool.Conn) { defer utils.Recover("localForward") defer local.Close() + logging.Info("localForward: %d", remote.Idx) for { _, data, err := local.ReadMessage() if err != nil { diff --git a/code/client/shell/link.go b/code/client/shell/link.go index 4001283..89b1196 100644 --- a/code/client/shell/link.go +++ b/code/client/shell/link.go @@ -14,6 +14,7 @@ type Link struct { target string // target id targetIdx uint32 // target idx remote *pool.Conn + OnWork chan struct{} // in remote pid int stdin io.WriteCloser @@ -30,6 +31,7 @@ func NewLink(parent *Shell, id, target string, remote *pool.Conn) *Link { id: id, target: target, remote: remote, + OnWork: make(chan struct{}), } } diff --git a/code/network/msg.pb.go b/code/network/msg.pb.go index 76a0f4e..85abcc1 100644 --- a/code/network/msg.pb.go +++ b/code/network/msg.pb.go @@ -31,10 +31,11 @@ const ( Msg_disconnect MsgType = 5 Msg_forward MsgType = 6 // shell - Msg_shell_create MsgType = 10 - Msg_shell_resize MsgType = 11 - Msg_shell_data MsgType = 12 - Msg_shell_close MsgType = 13 + Msg_shell_create MsgType = 10 + Msg_shell_created MsgType = 11 + Msg_shell_resize MsgType = 12 + Msg_shell_data MsgType = 13 + Msg_shell_close MsgType = 14 ) // Enum value maps for MsgType. @@ -48,22 +49,24 @@ var ( 5: "disconnect", 6: "forward", 10: "shell_create", - 11: "shell_resize", - 12: "shell_data", - 13: "shell_close", + 11: "shell_created", + 12: "shell_resize", + 13: "shell_data", + 14: "shell_close", } MsgType_value = map[string]int32{ - "unknown": 0, - "handshake": 1, - "keepalive": 2, - "connect_req": 3, - "connect_rep": 4, - "disconnect": 5, - "forward": 6, - "shell_create": 10, - "shell_resize": 11, - "shell_data": 12, - "shell_close": 13, + "unknown": 0, + "handshake": 1, + "keepalive": 2, + "connect_req": 3, + "connect_rep": 4, + "disconnect": 5, + "forward": 6, + "shell_create": 10, + "shell_created": 11, + "shell_resize": 12, + "shell_data": 13, + "shell_close": 14, } ) @@ -158,6 +161,7 @@ type Msg struct { // *Msg_Crep // *Msg_XData // *Msg_Screate + // *Msg_Screated // *Msg_Sresize // *Msg_Sdata Payload isMsg_Payload `protobuf_oneof:"payload"` @@ -279,6 +283,13 @@ func (x *Msg) GetScreate() *ShellCreate { return nil } +func (x *Msg) GetScreated() *ShellCreated { + if x, ok := x.GetPayload().(*Msg_Screated); ok { + return x.Screated + } + return nil +} + func (x *Msg) GetSresize() *ShellResize { if x, ok := x.GetPayload().(*Msg_Sresize); ok { return x.Sresize @@ -318,12 +329,16 @@ type Msg_Screate struct { Screate *ShellCreate `protobuf:"bytes,20,opt,name=screate,proto3,oneof"` } +type Msg_Screated struct { + Screated *ShellCreated `protobuf:"bytes,21,opt,name=screated,proto3,oneof"` +} + type Msg_Sresize struct { - Sresize *ShellResize `protobuf:"bytes,21,opt,name=sresize,proto3,oneof"` + Sresize *ShellResize `protobuf:"bytes,22,opt,name=sresize,proto3,oneof"` } type Msg_Sdata struct { - Sdata *ShellData `protobuf:"bytes,22,opt,name=sdata,proto3,oneof"` + Sdata *ShellData `protobuf:"bytes,23,opt,name=sdata,proto3,oneof"` } func (*Msg_Hsp) isMsg_Payload() {} @@ -336,6 +351,8 @@ func (*Msg_XData) isMsg_Payload() {} func (*Msg_Screate) isMsg_Payload() {} +func (*Msg_Screated) isMsg_Payload() {} + func (*Msg_Sresize) isMsg_Payload() {} func (*Msg_Sdata) isMsg_Payload() {} @@ -349,7 +366,7 @@ var file_msg_proto_rawDesc = []byte{ 0x74, 0x6f, 0x1a, 0x0b, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x25, 0x0a, 0x11, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, 0x6b, 0x65, 0x5f, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x03, 0x65, 0x6e, 0x63, 0x22, 0xa9, 0x05, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x26, + 0x0c, 0x52, 0x03, 0x65, 0x6e, 0x63, 0x22, 0xf2, 0x05, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x26, 0x0a, 0x05, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x11, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x6d, 0x73, 0x67, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x52, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x02, @@ -374,26 +391,31 @@ var file_msg_proto_rawDesc = []byte{ 0x73, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x48, 0x00, 0x52, 0x07, 0x73, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, - 0x31, 0x0a, 0x07, 0x73, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x15, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x15, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x73, 0x68, 0x65, 0x6c, 0x6c, - 0x5f, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x48, 0x00, 0x52, 0x07, 0x73, 0x72, 0x65, 0x73, 0x69, - 0x7a, 0x65, 0x12, 0x2b, 0x0a, 0x05, 0x73, 0x64, 0x61, 0x74, 0x61, 0x18, 0x16, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x13, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x73, 0x68, 0x65, 0x6c, - 0x6c, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x48, 0x00, 0x52, 0x05, 0x73, 0x64, 0x61, 0x74, 0x61, 0x22, - 0xb5, 0x01, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x75, 0x6e, 0x6b, 0x6e, - 0x6f, 0x77, 0x6e, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, - 0x6b, 0x65, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x6b, 0x65, 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76, - 0x65, 0x10, 0x02, 0x12, 0x0f, 0x0a, 0x0b, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x5f, 0x72, - 0x65, 0x71, 0x10, 0x03, 0x12, 0x0f, 0x0a, 0x0b, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x5f, - 0x72, 0x65, 0x70, 0x10, 0x04, 0x12, 0x0e, 0x0a, 0x0a, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x6e, 0x6e, - 0x65, 0x63, 0x74, 0x10, 0x05, 0x12, 0x0b, 0x0a, 0x07, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, - 0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x63, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x10, 0x0a, 0x12, 0x10, 0x0a, 0x0c, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x72, 0x65, - 0x73, 0x69, 0x7a, 0x65, 0x10, 0x0b, 0x12, 0x0e, 0x0a, 0x0a, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, - 0x64, 0x61, 0x74, 0x61, 0x10, 0x0c, 0x12, 0x0f, 0x0a, 0x0b, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, - 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x10, 0x0d, 0x42, 0x09, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, - 0x61, 0x64, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x2f, 0x3b, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x34, 0x0a, 0x08, 0x73, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x15, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x16, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x73, 0x68, 0x65, 0x6c, + 0x6c, 0x5f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x48, 0x00, 0x52, 0x08, 0x73, 0x63, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x31, 0x0a, 0x07, 0x73, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x65, + 0x18, 0x16, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, + 0x2e, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x48, 0x00, 0x52, + 0x07, 0x73, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x2b, 0x0a, 0x05, 0x73, 0x64, 0x61, 0x74, + 0x61, 0x18, 0x17, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, + 0x6b, 0x2e, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x48, 0x00, 0x52, 0x05, + 0x73, 0x64, 0x61, 0x74, 0x61, 0x22, 0xc8, 0x01, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x0b, + 0x0a, 0x07, 0x75, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x68, + 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, 0x6b, 0x65, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x6b, 0x65, + 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x10, 0x02, 0x12, 0x0f, 0x0a, 0x0b, 0x63, 0x6f, 0x6e, + 0x6e, 0x65, 0x63, 0x74, 0x5f, 0x72, 0x65, 0x71, 0x10, 0x03, 0x12, 0x0f, 0x0a, 0x0b, 0x63, 0x6f, + 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x5f, 0x72, 0x65, 0x70, 0x10, 0x04, 0x12, 0x0e, 0x0a, 0x0a, 0x64, + 0x69, 0x73, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x10, 0x05, 0x12, 0x0b, 0x0a, 0x07, 0x66, + 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x73, 0x68, 0x65, 0x6c, + 0x6c, 0x5f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x10, 0x0a, 0x12, 0x11, 0x0a, 0x0d, 0x73, 0x68, + 0x65, 0x6c, 0x6c, 0x5f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x10, 0x0b, 0x12, 0x10, 0x0a, + 0x0c, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x10, 0x0c, 0x12, + 0x0e, 0x0a, 0x0a, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x10, 0x0d, 0x12, + 0x0f, 0x0a, 0x0b, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x10, 0x0e, + 0x42, 0x09, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, + 0x2f, 0x3b, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -418,8 +440,9 @@ var file_msg_proto_goTypes = []interface{}{ (*ConnectResponse)(nil), // 4: network.connect_response (*Data)(nil), // 5: network.data (*ShellCreate)(nil), // 6: network.shell_create - (*ShellResize)(nil), // 7: network.shell_resize - (*ShellData)(nil), // 8: network.shell_data + (*ShellCreated)(nil), // 7: network.shell_created + (*ShellResize)(nil), // 8: network.shell_resize + (*ShellData)(nil), // 9: network.shell_data } var file_msg_proto_depIdxs = []int32{ 0, // 0: network.msg._type:type_name -> network.msg.type @@ -428,13 +451,14 @@ var file_msg_proto_depIdxs = []int32{ 4, // 3: network.msg.crep:type_name -> network.connect_response 5, // 4: network.msg._data:type_name -> network.data 6, // 5: network.msg.screate:type_name -> network.shell_create - 7, // 6: network.msg.sresize:type_name -> network.shell_resize - 8, // 7: network.msg.sdata:type_name -> network.shell_data - 8, // [8:8] is the sub-list for method output_type - 8, // [8:8] is the sub-list for method input_type - 8, // [8:8] is the sub-list for extension type_name - 8, // [8:8] is the sub-list for extension extendee - 0, // [0:8] is the sub-list for field type_name + 7, // 6: network.msg.screated:type_name -> network.shell_created + 8, // 7: network.msg.sresize:type_name -> network.shell_resize + 9, // 8: network.msg.sdata:type_name -> network.shell_data + 9, // [9:9] is the sub-list for method output_type + 9, // [9:9] is the sub-list for method input_type + 9, // [9:9] is the sub-list for extension type_name + 9, // [9:9] is the sub-list for extension extendee + 0, // [0:9] is the sub-list for field type_name } func init() { file_msg_proto_init() } @@ -477,6 +501,7 @@ func file_msg_proto_init() { (*Msg_Crep)(nil), (*Msg_XData)(nil), (*Msg_Screate)(nil), + (*Msg_Screated)(nil), (*Msg_Sresize)(nil), (*Msg_Sdata)(nil), } diff --git a/code/network/msg.proto b/code/network/msg.proto index 59f6797..841444c 100644 --- a/code/network/msg.proto +++ b/code/network/msg.proto @@ -21,10 +21,11 @@ message msg { disconnect = 5; forward = 6; // shell - shell_create = 10; - shell_resize = 11; - shell_data = 12; - shell_close = 13; + shell_create = 10; + shell_created = 11; + shell_resize = 12; + shell_data = 13; + shell_close = 14; } type _type = 1; string from = 2; @@ -39,7 +40,8 @@ message msg { data _data = 13; // shell shell_create screate = 20; - shell_resize sresize = 21; - shell_data sdata = 22; + shell_created screated = 21; + shell_resize sresize = 22; + shell_data sdata = 23; } } \ No newline at end of file diff --git a/code/network/shell.pb.go b/code/network/shell.pb.go index 401adc0..4054e9c 100644 --- a/code/network/shell.pb.go +++ b/code/network/shell.pb.go @@ -75,6 +75,61 @@ func (x *ShellCreate) GetExec() string { return "" } +type ShellCreated struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Ok bool `protobuf:"varint,1,opt,name=ok,proto3" json:"ok,omitempty"` + Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` +} + +func (x *ShellCreated) Reset() { + *x = ShellCreated{} + if protoimpl.UnsafeEnabled { + mi := &file_shell_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShellCreated) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShellCreated) ProtoMessage() {} + +func (x *ShellCreated) ProtoReflect() protoreflect.Message { + mi := &file_shell_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShellCreated.ProtoReflect.Descriptor instead. +func (*ShellCreated) Descriptor() ([]byte, []int) { + return file_shell_proto_rawDescGZIP(), []int{1} +} + +func (x *ShellCreated) GetOk() bool { + if x != nil { + return x.Ok + } + return false +} + +func (x *ShellCreated) GetMsg() string { + if x != nil { + return x.Msg + } + return "" +} + type ShellResize struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -87,7 +142,7 @@ type ShellResize struct { func (x *ShellResize) Reset() { *x = ShellResize{} if protoimpl.UnsafeEnabled { - mi := &file_shell_proto_msgTypes[1] + mi := &file_shell_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -100,7 +155,7 @@ func (x *ShellResize) String() string { func (*ShellResize) ProtoMessage() {} func (x *ShellResize) ProtoReflect() protoreflect.Message { - mi := &file_shell_proto_msgTypes[1] + mi := &file_shell_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -113,7 +168,7 @@ func (x *ShellResize) ProtoReflect() protoreflect.Message { // Deprecated: Use ShellResize.ProtoReflect.Descriptor instead. func (*ShellResize) Descriptor() ([]byte, []int) { - return file_shell_proto_rawDescGZIP(), []int{1} + return file_shell_proto_rawDescGZIP(), []int{2} } func (x *ShellResize) GetRows() uint32 { @@ -141,7 +196,7 @@ type ShellData struct { func (x *ShellData) Reset() { *x = ShellData{} if protoimpl.UnsafeEnabled { - mi := &file_shell_proto_msgTypes[2] + mi := &file_shell_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -154,7 +209,7 @@ func (x *ShellData) String() string { func (*ShellData) ProtoMessage() {} func (x *ShellData) ProtoReflect() protoreflect.Message { - mi := &file_shell_proto_msgTypes[2] + mi := &file_shell_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -167,7 +222,7 @@ func (x *ShellData) ProtoReflect() protoreflect.Message { // Deprecated: Use ShellData.ProtoReflect.Descriptor instead. func (*ShellData) Descriptor() ([]byte, []int) { - return file_shell_proto_rawDescGZIP(), []int{2} + return file_shell_proto_rawDescGZIP(), []int{3} } func (x *ShellData) GetData() []byte { @@ -184,14 +239,18 @@ var file_shell_proto_rawDesc = []byte{ 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x22, 0x36, 0x0a, 0x0c, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x65, 0x78, - 0x65, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x65, 0x78, 0x65, 0x63, 0x22, 0x36, - 0x0a, 0x0c, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x12, - 0x0a, 0x04, 0x72, 0x6f, 0x77, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x72, 0x6f, - 0x77, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, - 0x52, 0x04, 0x63, 0x6f, 0x6c, 0x73, 0x22, 0x20, 0x0a, 0x0a, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, - 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x2f, 0x3b, 0x6e, - 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x65, 0x78, 0x65, 0x63, 0x22, 0x31, + 0x0a, 0x0d, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, + 0x0e, 0x0a, 0x02, 0x6f, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x02, 0x6f, 0x6b, 0x12, + 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, + 0x67, 0x22, 0x36, 0x0a, 0x0c, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x72, 0x65, 0x73, 0x69, 0x7a, + 0x65, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x6f, 0x77, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x04, 0x72, 0x6f, 0x77, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x6c, 0x73, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x04, 0x63, 0x6f, 0x6c, 0x73, 0x22, 0x20, 0x0a, 0x0a, 0x73, 0x68, 0x65, + 0x6c, 0x6c, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, + 0x2f, 0x3b, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -206,11 +265,12 @@ func file_shell_proto_rawDescGZIP() []byte { return file_shell_proto_rawDescData } -var file_shell_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_shell_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_shell_proto_goTypes = []interface{}{ - (*ShellCreate)(nil), // 0: network.shell_create - (*ShellResize)(nil), // 1: network.shell_resize - (*ShellData)(nil), // 2: network.shell_data + (*ShellCreate)(nil), // 0: network.shell_create + (*ShellCreated)(nil), // 1: network.shell_created + (*ShellResize)(nil), // 2: network.shell_resize + (*ShellData)(nil), // 3: network.shell_data } var file_shell_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type @@ -239,7 +299,7 @@ func file_shell_proto_init() { } } file_shell_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ShellResize); i { + switch v := v.(*ShellCreated); i { case 0: return &v.state case 1: @@ -251,6 +311,18 @@ func file_shell_proto_init() { } } file_shell_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ShellResize); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_shell_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ShellData); i { case 0: return &v.state @@ -269,7 +341,7 @@ func file_shell_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_shell_proto_rawDesc, NumEnums: 0, - NumMessages: 3, + NumMessages: 4, NumExtensions: 0, NumServices: 0, }, diff --git a/code/network/shell.proto b/code/network/shell.proto index 2f4ae1f..9702499 100644 --- a/code/network/shell.proto +++ b/code/network/shell.proto @@ -8,6 +8,11 @@ message shell_create { string exec = 2; } +message shell_created { + bool ok = 1; + string msg = 2; +} + message shell_resize { uint32 rows = 1; uint32 cols = 2; diff --git a/go.mod b/go.mod index 8e72cdb..ae4170c 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module natpass go 1.16 require ( - github.com/creack/pty v1.1.15 // indirect + github.com/creack/pty v1.1.15 github.com/dustin/go-humanize v1.0.0 - github.com/gorilla/websocket v1.4.2 // indirect + github.com/gorilla/websocket v1.4.2 github.com/kardianos/service v1.2.0 github.com/lwch/logging v0.0.0-20210528090125-a154917d90c6 github.com/lwch/runtime v0.0.0-20190520054850-8c97e19e0c6d