From 31c5fd72977417d82791425ded580b1c87fca682 Mon Sep 17 00:00:00 2001 From: lwch Date: Tue, 28 Sep 2021 18:58:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0env=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/client/connect.go | 1 + code/client/global/conf.go | 17 ++++++++-------- code/client/shell/exec_xx.go | 2 +- code/network/shell.pb.go | 39 ++++++++++++++++++++++-------------- code/network/shell.proto | 5 +++-- conf/client.yaml | 4 +++- 6 files changed, 41 insertions(+), 27 deletions(-) diff --git a/code/client/connect.go b/code/client/connect.go index c3623a5..af6acd4 100644 --- a/code/client/connect.go +++ b/code/client/connect.go @@ -50,6 +50,7 @@ func shellCreate(conn *pool.Conn, msg *network.Msg) { Target: msg.GetFrom(), Type: "shell", Exec: create.GetExec(), + Env: create.GetEnv(), }) lk := shell.NewLink(sh, msg.GetLinkId(), msg.GetFrom(), conn) lk.SetTargetIdx(msg.GetFromIdx()) diff --git a/code/client/global/conf.go b/code/client/global/conf.go index 57fa6a8..f5ebb6e 100644 --- a/code/client/global/conf.go +++ b/code/client/global/conf.go @@ -12,14 +12,15 @@ import ( // Tunnel tunnel config type Tunnel struct { - Name string `yaml:"name"` - Target string `yaml:"target"` - Type string `yaml:"type"` - LocalAddr string `yaml:"local_addr"` - LocalPort uint16 `yaml:"local_port"` - RemoteAddr string `yaml:"remote_addr"` - RemotePort uint16 `yaml:"remote_port"` - Exec string `yaml:"exec"` + Name string `yaml:"name"` + Target string `yaml:"target"` + Type string `yaml:"type"` + LocalAddr string `yaml:"local_addr"` + LocalPort uint16 `yaml:"local_port"` + RemoteAddr string `yaml:"remote_addr"` + RemotePort uint16 `yaml:"remote_port"` + Exec string `yaml:"exec"` + Env []string `yaml:"env"` } // Configure client configure diff --git a/code/client/shell/exec_xx.go b/code/client/shell/exec_xx.go index b9410e9..452a188 100644 --- a/code/client/shell/exec_xx.go +++ b/code/client/shell/exec_xx.go @@ -30,7 +30,7 @@ func (link *Link) Exec() error { if cmd == nil { return errors.New("no shell command supported") } - cmd.Env = os.Environ() + cmd.Env = append(os.Environ(), link.parent.cfg.Env...) f, err := pty.Start(cmd) if err != nil { return err diff --git a/code/network/shell.pb.go b/code/network/shell.pb.go index 4054e9c..6dd6647 100644 --- a/code/network/shell.pb.go +++ b/code/network/shell.pb.go @@ -25,8 +25,9 @@ type ShellCreate struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Exec string `protobuf:"bytes,2,opt,name=exec,proto3" json:"exec,omitempty"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Exec string `protobuf:"bytes,2,opt,name=exec,proto3" json:"exec,omitempty"` + Env []string `protobuf:"bytes,3,rep,name=env,proto3" json:"env,omitempty"` } func (x *ShellCreate) Reset() { @@ -75,6 +76,13 @@ func (x *ShellCreate) GetExec() string { return "" } +func (x *ShellCreate) GetEnv() []string { + if x != nil { + return x.Env + } + return nil +} + type ShellCreated struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -236,21 +244,22 @@ var File_shell_proto protoreflect.FileDescriptor var file_shell_proto_rawDesc = []byte{ 0x0a, 0x0b, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x6e, - 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x22, 0x36, 0x0a, 0x0c, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, + 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x22, 0x48, 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, 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, + 0x65, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x65, 0x78, 0x65, 0x63, 0x12, 0x10, + 0x0a, 0x03, 0x65, 0x6e, 0x76, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x03, 0x65, 0x6e, 0x76, + 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 ( diff --git a/code/network/shell.proto b/code/network/shell.proto index 9702499..232f6fd 100644 --- a/code/network/shell.proto +++ b/code/network/shell.proto @@ -4,8 +4,9 @@ package network; option go_package="./;network"; message shell_create { - string name = 1; - string exec = 2; + string name = 1; + string exec = 2; + repeated string env = 3; } message shell_created { diff --git a/conf/client.yaml b/conf/client.yaml index fc8a144..e6db24f 100644 --- a/conf/client.yaml +++ b/conf/client.yaml @@ -24,4 +24,6 @@ tunnel: # 远端tunnel列表可为空 local_port: 8080 # 本地监听端口号 #exec: /bin/bash # 运行命令 # windows默认powershell或cmd - # 其他系统bash或sh \ No newline at end of file + # 其他系统bash或sh + env: # 环境变量设置 + - TERM=xterm \ No newline at end of file