Skip to content

Commit e467517

Browse files
authored
Merge pull request #206 from jumpserver/pr@dev@perf_rdp_app
perf: code structure for improved readability and maintainability
2 parents 35931ca + 235831e commit e467517

File tree

14 files changed

+103
-97
lines changed

14 files changed

+103
-97
lines changed

go-client/config.json

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"filename": "Jumpserve Clients Config",
3-
"version": 4,
3+
"version": 5,
44
"windowBounds": {
55
"width": 1280,
66
"height": 800
@@ -109,7 +109,7 @@
109109
},
110110
"download_url": "",
111111
"type": "remotedesktop",
112-
"path": "mstsc.exe",
112+
"path": "C:\\WINDOWS\\system32\\mstsc.exe",
113113
"arg_format": "{file}",
114114
"match_first": [
115115
"rdp"
@@ -121,7 +121,9 @@
121121
{
122122
"name": "royalts",
123123
"display_name": "Royal TS",
124-
"protocol": ["rdp"],
124+
"protocol": [
125+
"rdp"
126+
],
125127
"comment": {
126128
"zh": "Royal TS 是一款强大的远程连接管理工具。",
127129
"en": "Royal TS is a powerful remote connection manager."
@@ -130,15 +132,19 @@
130132
"type": "remotedesktop",
131133
"path": "",
132134
"arg_format": "{file}",
133-
"match_first": ["rdp"],
135+
"match_first": [
136+
"rdp"
137+
],
134138
"is_internal": false,
135139
"is_default": false,
136140
"is_set": false
137141
},
138142
{
139143
"name": "windows_rdm",
140144
"display_name": "Remote Desktop Manager",
141-
"protocol": ["rdp"],
145+
"protocol": [
146+
"rdp"
147+
],
142148
"comment": {
143149
"zh": "Remote Desktop Manager (Devolutions) 集中管理所有远程连接。",
144150
"en": "Remote Desktop Manager (Devolutions) centralizes all remote connections."
@@ -147,15 +153,19 @@
147153
"type": "remotedesktop",
148154
"path": "",
149155
"arg_format": "{file}",
150-
"match_first": ["rdp"],
156+
"match_first": [
157+
"rdp"
158+
],
151159
"is_internal": false,
152160
"is_default": false,
153161
"is_set": false
154162
},
155163
{
156-
"name": "moba_rdp",
164+
"name": "mobaxterm",
157165
"display_name": "MobaXterm (RDP)",
158-
"protocol": ["rdp"],
166+
"protocol": [
167+
"rdp"
168+
],
159169
"comment": {
160170
"zh": "MobaXterm 支持 RDP/VNC/SSH 等多种协议。",
161171
"en": "MobaXterm supports RDP/VNC/SSH and more."
@@ -164,45 +174,30 @@
164174
"type": "remotedesktop",
165175
"path": "",
166176
"arg_format": "{file}",
167-
"match_first": ["rdp"],
177+
"match_first": [
178+
"rdp"
179+
],
168180
"is_internal": false,
169181
"is_default": false,
170182
"is_set": false
171183
},
172184
{
173-
"name": "vncviewer",
174-
"display_name": "RealVNC Viewer",
185+
"name": "tigervnc",
186+
"display_name": "TigerVNC",
175187
"protocol": [
176188
"vnc"
177189
],
178190
"comment": {
179-
"zh": "RealVNC Viewer 是一款用于远程控制计算机的软件,它使用VNC(Virtual Network Computing)协议,允许用户从一台计算机(客户端)访问和控制另一台计算机(服务器)的桌面",
180-
"en": "RealVNC Viewer is a software used for remote computer control. It utilizes the VNC (Virtual Network Computing) protocol, allowing users to access and control the desktop of another computer (the server) from their own computer"
191+
"zh": "TigerVNC是一个高效且安全的远程桌面控制工具,适用于跨平台操作,并有强大的安全性能保障",
192+
"en": "TigerVNC is an efficient and secure remote desktop control tool that is suitable for cross platform operations and has strong security performance guarantees."
181193
},
182-
"download_url": "https://www.realvnc.com/en/connect/download/viewer/",
194+
"download_url": "https://sourceforge.net/projects/tigervnc/files/stable/1.15.0/tigervnc-1.15.0.x86_64.tar.gz",
183195
"type": "remotedesktop",
184196
"path": "",
185-
"arg_format": " -WarnUnencrypted=0 -VerifyId=0 -UserName={username} {host}:{port}",
197+
"arg_format": "{host}::{port}",
186198
"match_first": [
187199
"vnc"
188200
],
189-
"autoit": [
190-
{
191-
"cmd": "Wait",
192-
"type": "10",
193-
"element": "[CLASS:os::Window::Dialog]"
194-
},
195-
{
196-
"cmd": "ControlSend",
197-
"type": "{value}",
198-
"element": "[CLASS:Edit; INSTANCE:2]"
199-
},
200-
{
201-
"cmd": "ControlClick",
202-
"type": "25,10",
203-
"element": "[CLASS:Button; INSTANCE:3]"
204-
}
205-
],
206201
"is_internal": false,
207202
"is_default": false,
208203
"is_set": false
@@ -250,7 +245,9 @@
250245
{
251246
"name": "xftp",
252247
"display_name": "Xftp",
253-
"protocol": ["sftp"],
248+
"protocol": [
249+
"sftp"
250+
],
254251
"comment": {
255252
"zh": "Xftp是一个功能强大的SFTP、FTP 文件传输软件。",
256253
"en": "Xftp is a powerful SFTP and FTP file transfer software."
@@ -902,4 +899,4 @@
902899
}
903900
]
904901
}
905-
}
902+
}

go-client/pkg/awaken/awaken_windows.go

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -61,46 +61,36 @@ func getCommandFromArgs(connectInfo map[string]string, argFormat string) string
6161
}
6262

6363
func handleRDP(r *Rouse, filePath string, cfg *config.AppConfig) *exec.Cmd {
64-
if cfg != nil {
65-
appLst := cfg.Windows.RemoteDesktop
66-
for _, app := range appLst {
67-
if !app.IsSet || !app.IsMatchProtocol("rdp") {
68-
continue
69-
}
70-
appPath := app.Path
71-
if app.IsInternal {
72-
currentPath := filepath.Dir(os.Args[0])
73-
candidate := filepath.Join(currentPath, app.Path)
74-
if _, err := os.Stat(candidate); err == nil {
75-
appPath = candidate
76-
}
77-
}
78-
if appPath == "" {
79-
break
80-
}
81-
connectMap := map[string]string{
82-
"file": filePath,
83-
"name": r.getName(),
84-
"protocol": r.Protocol,
85-
"username": r.getUserName(),
86-
"value": r.Value,
87-
"host": r.Host,
88-
"port": strconv.Itoa(r.Port),
89-
}
90-
commands := strings.TrimSpace(getCommandFromArgs(connectMap, app.ArgFormat))
91-
if commands == "" {
92-
return exec.Command(appPath)
93-
}
94-
if strings.Contains(commands, "*") {
95-
parts := strings.Split(commands, "*")
96-
return exec.Command(appPath, parts...)
97-
}
98-
args := strings.Split(commands, " ")
99-
return exec.Command(appPath, args...)
100-
}
101-
}
102-
cmd := exec.Command("C:\\WINDOWS\\system32\\mstsc.exe", filePath)
103-
return cmd
64+
var appItem *config.AppItem
65+
appLst := cfg.Windows.RemoteDesktop
66+
for _, app := range appLst {
67+
if app.IsMatchProtocol("rdp") {
68+
appItem = &app
69+
break
70+
}
71+
}
72+
if appItem == nil {
73+
return nil
74+
}
75+
appPath := appItem.Path
76+
connectMap := map[string]string{
77+
"file": filePath,
78+
"name": r.getName(),
79+
"protocol": r.Protocol,
80+
"username": r.getUserName(),
81+
"value": r.Value,
82+
"host": r.Host,
83+
"port": strconv.Itoa(r.Port),
84+
}
85+
commands := strings.TrimSpace(getCommandFromArgs(connectMap, appItem.ArgFormat))
86+
87+
if strings.Contains(commands, "*") {
88+
commands := strings.Split(commands, "*")
89+
return exec.Command(appPath, commands...)
90+
} else {
91+
commands := strings.Split(commands, " ")
92+
return exec.Command(appPath, commands...)
93+
}
10494
}
10595

10696
func handleVNC(r *Rouse, cfg *config.AppConfig) *exec.Cmd {
@@ -124,7 +114,14 @@ func handleVNC(r *Rouse, cfg *config.AppConfig) *exec.Cmd {
124114
"port": strconv.Itoa(r.Port),
125115
}
126116
if len(appItem.AutoIt) == 0 {
127-
return nil
117+
commands := getCommandFromArgs(connectMap, appItem.ArgFormat)
118+
cmd := exec.Command(appItem.Path, strings.Split(commands, " ")...)
119+
// 设置环境变量(只对这个子进程有效)
120+
cmd.Env = append(os.Environ(),
121+
"VNC_USERNAME="+r.getUserName(),
122+
"VNC_PASSWORD="+r.Value,
123+
)
124+
return cmd
128125
} else {
129126
commands := getCommandFromArgs(connectMap, appItem.ArgFormat)
130127
global.LOG.Error(appItem.Path + " " + commands)

ui/assets/images/mobaxterm.png

1.38 KB
Loading

ui/assets/images/plsql.png

1.39 KB
Loading

ui/assets/images/putty.png

1.66 KB
Loading

ui/assets/images/remmina.png

11.1 KB
Loading

ui/assets/images/ssms17.png

3.96 KB
Loading

ui/assets/images/winscp.png

31.5 KB
Loading

0 commit comments

Comments
 (0)