mirror of
https://github.com/lwch/natpass.git
synced 2024-04-21 12:41:54 +00:00
修正无法正确设置to_idx字段的问题
This commit is contained in:
@@ -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{}{}
|
||||
}
|
||||
|
||||
@@ -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):
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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):
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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{}),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+75
-50
@@ -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),
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+92
-20
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user