mirror of
https://github.com/VaalaCat/frp-panel.git
synced 2025-12-24 11:51:06 +08:00
fix: special term char
This commit is contained in:
@@ -31,7 +31,7 @@ func initStreamLog(h *common.HookMgr) {
|
||||
|
||||
h.AddStream(func(msg string) {
|
||||
handler.Send(&pb.PushClientStreamLogReq{
|
||||
Log: utils.EncodeBase64(msg),
|
||||
Log: []byte(utils.EncodeBase64(msg)),
|
||||
Base: &pb.ClientBase{
|
||||
ClientId: clientID,
|
||||
ClientSecret: clientSecret,
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/VaalaCat/frp-panel/services/rpcclient"
|
||||
"github.com/VaalaCat/frp-panel/utils/pty"
|
||||
"github.com/google/uuid"
|
||||
"github.com/samber/lo"
|
||||
"github.com/sourcegraph/conc"
|
||||
)
|
||||
|
||||
@@ -34,7 +33,7 @@ func StartPTYConnect(c context.Context, req *pb.CommonRequest, initMsg *pb.PTYCl
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if ack.GetData() != "ok" {
|
||||
if string(ack.GetData()) != "ok" {
|
||||
logger.Logger(c).Infof("ack error")
|
||||
return nil, fmt.Errorf("ack error")
|
||||
}
|
||||
@@ -54,7 +53,7 @@ func HandlePTY(c context.Context, conn pb.Master_PTYConnectClient, sessionID str
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("failed to start tty: %s", err)
|
||||
logger.Logger(c).WithError(err).Warn(msg)
|
||||
conn.Send(&pb.PTYClientMessage{Data: &msg, SessionId: sessionID})
|
||||
conn.Send(&pb.PTYClientMessage{Data: []byte(msg), SessionId: sessionID})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -82,7 +81,7 @@ func HandlePTY(c context.Context, conn pb.Master_PTYConnectClient, sessionID str
|
||||
readLength, err := ptyInstace.Read(buffer)
|
||||
if err != nil {
|
||||
logger.Logger(c).Warnf("failed to read from tty: %s", err)
|
||||
if err := conn.Send(&pb.PTYClientMessage{Data: lo.ToPtr("bye!"), SessionId: sessionID}); err != nil {
|
||||
if err := conn.Send(&pb.PTYClientMessage{Data: []byte("bye!"), SessionId: sessionID}); err != nil {
|
||||
logger.Logger(c).Warnf("failed to send termination message from tty to master: %s", err)
|
||||
}
|
||||
if err := conn.CloseSend(); err != nil {
|
||||
@@ -90,8 +89,8 @@ func HandlePTY(c context.Context, conn pb.Master_PTYConnectClient, sessionID str
|
||||
}
|
||||
return
|
||||
}
|
||||
str := string(buffer[:readLength])
|
||||
if err := conn.Send(&pb.PTYClientMessage{Data: lo.ToPtr(str), SessionId: sessionID}); err != nil {
|
||||
str := buffer[:readLength]
|
||||
if err := conn.Send(&pb.PTYClientMessage{Data: str, SessionId: sessionID}); err != nil {
|
||||
logger.Logger(c).Warnf("failed to send %v bytes from tty to master", readLength)
|
||||
errorCounter++
|
||||
continue
|
||||
|
||||
@@ -93,7 +93,7 @@ func PTYHandler(c *gin.Context) {
|
||||
|
||||
defer func() {
|
||||
logger.Logger(c).Info("gracefully stopping spawned tty...")
|
||||
if err := cliConn.Send(&pb.PTYServerMessage{Data: lo.ToPtr("bye!"), Done: true}); err != nil {
|
||||
if err := cliConn.Send(&pb.PTYServerMessage{Data: []byte("bye!"), Done: true}); err != nil {
|
||||
logger.Logger(c).Warnf("failed to send close message: %s", err)
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func PTYHandler(c *gin.Context) {
|
||||
|
||||
wg.Go(func() {
|
||||
defer func() {
|
||||
if err := cliConn.Send(&pb.PTYServerMessage{Data: lo.ToPtr("bye!"), Done: true}); err != nil {
|
||||
if err := cliConn.Send(&pb.PTYServerMessage{Data: []byte("bye!"), Done: true}); err != nil {
|
||||
logger.Logger(c).Warnf("failed to send close message: %s", err)
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ func PTYHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
time.Sleep(keepalivePingTimeout / 2)
|
||||
if time.Now().Sub(lastPongTime) > keepalivePingTimeout {
|
||||
if time.Since(lastPongTime) > keepalivePingTimeout {
|
||||
logger.Logger(c).Warn("failed to get response from ping, triggering disconnect now...")
|
||||
return
|
||||
}
|
||||
@@ -151,10 +151,10 @@ func PTYHandler(c *gin.Context) {
|
||||
cliMsg, err := cliConn.Recv()
|
||||
if err != nil {
|
||||
logger.Logger(c).Warnf("failed to read from client sender: %s", err)
|
||||
if err := webConn.WriteMessage(websocket.TextMessage, []byte("bye!")); err != nil {
|
||||
if err := webConn.WriteMessage(websocket.BinaryMessage, []byte("bye!")); err != nil {
|
||||
logger.Logger(c).Warnf("failed to send termination message from client sender to xterm.js: %s", err)
|
||||
}
|
||||
if err := cliConn.Send(&pb.PTYServerMessage{Data: lo.ToPtr("bye!"), Done: true}); err != nil {
|
||||
if err := cliConn.Send(&pb.PTYServerMessage{Data: []byte("bye!"), Done: true}); err != nil {
|
||||
logger.Logger(c).Warnf("failed to send termination message from client sender to client: %s", err)
|
||||
}
|
||||
if err := webConn.Close(); err != nil {
|
||||
@@ -184,7 +184,7 @@ func PTYHandler(c *gin.Context) {
|
||||
if !connectionClosed {
|
||||
logger.Logger(c).Warnf("failed to get next reader: %s", err)
|
||||
}
|
||||
if err := cliConn.Send(&pb.PTYServerMessage{Data: lo.ToPtr("bye!"), Done: true}); err != nil {
|
||||
if err := cliConn.Send(&pb.PTYServerMessage{Data: []byte("bye!"), Done: true}); err != nil {
|
||||
logger.Logger(c).Warnf("failed to send termination message from xterm.js to client: %s", err)
|
||||
}
|
||||
if err := webConn.Close(); err != nil {
|
||||
@@ -201,7 +201,7 @@ func PTYHandler(c *gin.Context) {
|
||||
|
||||
msg := &pb.PTYServerMessage{}
|
||||
if payload.Data != nil {
|
||||
msg.Data = lo.ToPtr(*payload.Data)
|
||||
msg.Data = []byte(*payload.Data)
|
||||
}
|
||||
if payload.Height != nil {
|
||||
msg.Height = lo.ToPtr(int32(*payload.Height))
|
||||
@@ -212,10 +212,10 @@ func PTYHandler(c *gin.Context) {
|
||||
|
||||
err = cliConn.Send(msg)
|
||||
if err != nil {
|
||||
logger.Logger(c).Warn(fmt.Sprintf("failed to write bytes to tty: %s", err))
|
||||
logger.Logger(c).Warn(fmt.Sprintf("failed to write bytes to client: %s", err))
|
||||
continue
|
||||
}
|
||||
logger.Logger(c).Tracef("messageType [%v] bytes written to tty...", messageType)
|
||||
logger.Logger(c).Tracef("messageType [%v] bytes written to client...", messageType)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/VaalaCat/frp-panel/biz/master/server"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func PTYConnect(sender pb.Master_PTYConnectServer) error {
|
||||
@@ -42,7 +41,7 @@ func PTYConnect(sender pb.Master_PTYConnectServer) error {
|
||||
|
||||
Mgr().Add(msg.GetSessionId(), sender)
|
||||
|
||||
if err := sender.Send(&pb.PTYServerMessage{Data: lo.ToPtr("ok")}); err != nil {
|
||||
if err := sender.Send(&pb.PTYServerMessage{Data: []byte("ok")}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ func PushClientStreamLog(sender pb.Master_PushClientStreamLogServer) error {
|
||||
return fmt.Errorf("push client stream log cannot find client, id: [%s]", req.GetBase().GetClientId())
|
||||
}
|
||||
|
||||
ch <- req.GetLog()
|
||||
ch <- string(req.GetLog())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func PushServerStreamLog(sender pb.Master_PushServerStreamLogServer) error {
|
||||
if !ok {
|
||||
return fmt.Errorf("push server stream log cannot find server, id: [%s]", req.GetBase().GetServerId())
|
||||
}
|
||||
ch <- req.GetLog()
|
||||
ch <- string(req.GetLog())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func initStreamLog(h *common.HookMgr) {
|
||||
|
||||
h.AddStream(func(msg string) {
|
||||
handler.Send(&pb.PushServerStreamLogReq{
|
||||
Log: utils.EncodeBase64(msg),
|
||||
Log: []byte(utils.EncodeBase64(msg)),
|
||||
Base: &pb.ServerBase{
|
||||
ServerId: clientID,
|
||||
ServerSecret: clientSecret,
|
||||
|
||||
@@ -90,12 +90,12 @@ message PushProxyInfoResp {
|
||||
}
|
||||
|
||||
message PushServerStreamLogReq {
|
||||
string log = 1;
|
||||
bytes log = 1;
|
||||
ServerBase base = 255;
|
||||
}
|
||||
|
||||
message PushClientStreamLogReq {
|
||||
string log = 1;
|
||||
bytes log = 1;
|
||||
ClientBase base = 255;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ message PushStreamLogResp {
|
||||
}
|
||||
|
||||
message PTYClientMessage {
|
||||
optional string data = 1;
|
||||
optional bytes data = 1;
|
||||
string session_id = 2;
|
||||
bool done = 3;
|
||||
oneof Base {
|
||||
@@ -115,7 +115,7 @@ message PTYClientMessage {
|
||||
}
|
||||
|
||||
message PTYServerMessage {
|
||||
optional string data = 1;
|
||||
optional bytes data = 1;
|
||||
optional int32 height = 2;
|
||||
optional int32 width = 3;
|
||||
bool done = 4;
|
||||
|
||||
@@ -779,7 +779,7 @@ type PushServerStreamLogReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Log string `protobuf:"bytes,1,opt,name=log,proto3" json:"log,omitempty"`
|
||||
Log []byte `protobuf:"bytes,1,opt,name=log,proto3" json:"log,omitempty"`
|
||||
Base *ServerBase `protobuf:"bytes,255,opt,name=base,proto3" json:"base,omitempty"`
|
||||
}
|
||||
|
||||
@@ -813,11 +813,11 @@ func (*PushServerStreamLogReq) Descriptor() ([]byte, []int) {
|
||||
return file_rpc_master_proto_rawDescGZIP(), []int{12}
|
||||
}
|
||||
|
||||
func (x *PushServerStreamLogReq) GetLog() string {
|
||||
func (x *PushServerStreamLogReq) GetLog() []byte {
|
||||
if x != nil {
|
||||
return x.Log
|
||||
}
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *PushServerStreamLogReq) GetBase() *ServerBase {
|
||||
@@ -832,7 +832,7 @@ type PushClientStreamLogReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Log string `protobuf:"bytes,1,opt,name=log,proto3" json:"log,omitempty"`
|
||||
Log []byte `protobuf:"bytes,1,opt,name=log,proto3" json:"log,omitempty"`
|
||||
Base *ClientBase `protobuf:"bytes,255,opt,name=base,proto3" json:"base,omitempty"`
|
||||
}
|
||||
|
||||
@@ -866,11 +866,11 @@ func (*PushClientStreamLogReq) Descriptor() ([]byte, []int) {
|
||||
return file_rpc_master_proto_rawDescGZIP(), []int{13}
|
||||
}
|
||||
|
||||
func (x *PushClientStreamLogReq) GetLog() string {
|
||||
func (x *PushClientStreamLogReq) GetLog() []byte {
|
||||
if x != nil {
|
||||
return x.Log
|
||||
}
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *PushClientStreamLogReq) GetBase() *ClientBase {
|
||||
@@ -938,9 +938,9 @@ type PTYClientMessage struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Data *string `protobuf:"bytes,1,opt,name=data,proto3,oneof" json:"data,omitempty"`
|
||||
SessionId string `protobuf:"bytes,2,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
|
||||
Done bool `protobuf:"varint,3,opt,name=done,proto3" json:"done,omitempty"`
|
||||
Data []byte `protobuf:"bytes,1,opt,name=data,proto3,oneof" json:"data,omitempty"`
|
||||
SessionId string `protobuf:"bytes,2,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
|
||||
Done bool `protobuf:"varint,3,opt,name=done,proto3" json:"done,omitempty"`
|
||||
// Types that are assignable to Base:
|
||||
//
|
||||
// *PTYClientMessage_ServerBase
|
||||
@@ -978,11 +978,11 @@ func (*PTYClientMessage) Descriptor() ([]byte, []int) {
|
||||
return file_rpc_master_proto_rawDescGZIP(), []int{15}
|
||||
}
|
||||
|
||||
func (x *PTYClientMessage) GetData() string {
|
||||
if x != nil && x.Data != nil {
|
||||
return *x.Data
|
||||
func (x *PTYClientMessage) GetData() []byte {
|
||||
if x != nil {
|
||||
return x.Data
|
||||
}
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *PTYClientMessage) GetSessionId() string {
|
||||
@@ -1041,10 +1041,10 @@ type PTYServerMessage struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Data *string `protobuf:"bytes,1,opt,name=data,proto3,oneof" json:"data,omitempty"`
|
||||
Height *int32 `protobuf:"varint,2,opt,name=height,proto3,oneof" json:"height,omitempty"`
|
||||
Width *int32 `protobuf:"varint,3,opt,name=width,proto3,oneof" json:"width,omitempty"`
|
||||
Done bool `protobuf:"varint,4,opt,name=done,proto3" json:"done,omitempty"`
|
||||
Data []byte `protobuf:"bytes,1,opt,name=data,proto3,oneof" json:"data,omitempty"`
|
||||
Height *int32 `protobuf:"varint,2,opt,name=height,proto3,oneof" json:"height,omitempty"`
|
||||
Width *int32 `protobuf:"varint,3,opt,name=width,proto3,oneof" json:"width,omitempty"`
|
||||
Done bool `protobuf:"varint,4,opt,name=done,proto3" json:"done,omitempty"`
|
||||
}
|
||||
|
||||
func (x *PTYServerMessage) Reset() {
|
||||
@@ -1077,11 +1077,11 @@ func (*PTYServerMessage) Descriptor() ([]byte, []int) {
|
||||
return file_rpc_master_proto_rawDescGZIP(), []int{16}
|
||||
}
|
||||
|
||||
func (x *PTYServerMessage) GetData() string {
|
||||
if x != nil && x.Data != nil {
|
||||
return *x.Data
|
||||
func (x *PTYServerMessage) GetData() []byte {
|
||||
if x != nil {
|
||||
return x.Data
|
||||
}
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *PTYServerMessage) GetHeight() int32 {
|
||||
@@ -1184,12 +1184,12 @@ var file_rpc_master_proto_rawDesc = []byte{
|
||||
0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x53, 0x0a, 0x16,
|
||||
0x50, 0x75, 0x73, 0x68, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d,
|
||||
0x4c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x6c, 0x6f, 0x67, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x03, 0x6c, 0x6f, 0x67, 0x12, 0x27, 0x0a, 0x04, 0x62, 0x61, 0x73, 0x65,
|
||||
0x01, 0x28, 0x0c, 0x52, 0x03, 0x6c, 0x6f, 0x67, 0x12, 0x27, 0x0a, 0x04, 0x62, 0x61, 0x73, 0x65,
|
||||
0x18, 0xff, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72,
|
||||
0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x42, 0x61, 0x73, 0x65, 0x52, 0x04, 0x62, 0x61, 0x73,
|
||||
0x65, 0x22, 0x53, 0x0a, 0x16, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x53,
|
||||
0x74, 0x72, 0x65, 0x61, 0x6d, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x6c,
|
||||
0x6f, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6c, 0x6f, 0x67, 0x12, 0x27, 0x0a,
|
||||
0x6f, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6c, 0x6f, 0x67, 0x12, 0x27, 0x0a,
|
||||
0x04, 0x62, 0x61, 0x73, 0x65, 0x18, 0xff, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x6d,
|
||||
0x61, 0x73, 0x74, 0x65, 0x72, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x42, 0x61, 0x73, 0x65,
|
||||
0x52, 0x04, 0x62, 0x61, 0x73, 0x65, 0x22, 0x4b, 0x0a, 0x11, 0x50, 0x75, 0x73, 0x68, 0x53, 0x74,
|
||||
@@ -1199,7 +1199,7 @@ var file_rpc_master_proto_rawDesc = []byte{
|
||||
0x74, 0x75, 0x73, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52,
|
||||
0x02, 0x6f, 0x6b, 0x22, 0xdf, 0x01, 0x0a, 0x10, 0x50, 0x54, 0x59, 0x43, 0x6c, 0x69, 0x65, 0x6e,
|
||||
0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x17, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x88, 0x01,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x01, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x88, 0x01,
|
||||
0x01, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64,
|
||||
0x12, 0x12, 0x0a, 0x04, 0x64, 0x6f, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04,
|
||||
@@ -1213,7 +1213,7 @@ var file_rpc_master_proto_rawDesc = []byte{
|
||||
0x42, 0x61, 0x73, 0x65, 0x42, 0x06, 0x0a, 0x04, 0x42, 0x61, 0x73, 0x65, 0x42, 0x07, 0x0a, 0x05,
|
||||
0x5f, 0x64, 0x61, 0x74, 0x61, 0x22, 0x95, 0x01, 0x0a, 0x10, 0x50, 0x54, 0x59, 0x53, 0x65, 0x72,
|
||||
0x76, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x17, 0x0a, 0x04, 0x64, 0x61,
|
||||
0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61,
|
||||
0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61,
|
||||
0x88, 0x01, 0x01, 0x12, 0x1b, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x05, 0x48, 0x01, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x88, 0x01, 0x01,
|
||||
0x12, 0x19, 0x0a, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x48,
|
||||
|
||||
Reference in New Issue
Block a user