增加env支持

This commit is contained in:
lwch
2021-09-28 18:58:26 +08:00
parent 1ffd1b31c9
commit 31c5fd7297
6 changed files with 41 additions and 27 deletions
+1
View File
@@ -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())
+9 -8
View File
@@ -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
+1 -1
View File
@@ -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
+24 -15
View File
@@ -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 (
+3 -2
View File
@@ -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 {
+3 -1
View File
@@ -24,4 +24,6 @@ tunnel: # 远端tunnel列表可为空
local_port: 8080 # 本地监听端口号
#exec: /bin/bash # 运行命令
# windows默认powershell或cmd
# 其他系统bash或sh
# 其他系统bash或sh
env: # 环境变量设置
- TERM=xterm