Skip to content

Commit e348bfc

Browse files
committed
perf: adaptation v3
1 parent 507902b commit e348bfc

File tree

4 files changed

+40
-33
lines changed

4 files changed

+40
-33
lines changed

go-client/cmd/awaken/awaken.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"go.uber.org/zap"
1010
"net/url"
1111
"os"
12-
"runtime"
1312
)
1413

1514
func main() {
@@ -23,7 +22,7 @@ func main() {
2322
infoJson := string(decoded)
2423
json.Unmarshal([]byte(infoJson), p)
2524
r := awaken.Rouse{
26-
SysType: runtime.GOOS,
25+
//SysType: runtime.GOOS,
2726
Info: *p,
2827
}
2928
r.Run()

go-client/pkg/awaken/awaken.go

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package awaken
22

33
import (
4-
"encoding/json"
54
"fmt"
65
"go-client/global"
76
"io/ioutil"
@@ -12,27 +11,27 @@ import (
1211
)
1312

1413
/*{
15-
"filename": "{}-{}-jumpserver".format(username, name),
14+
"id": "f",
15+
"value": "q",
1616
"protocol": "ssh",
17-
"username": "laoguang",
18-
"token": "xxx",
19-
"config": "full address:s:rdjumpserver.fit2cloud.com:33390"
17+
"command": "xxx"
18+
"file": {
19+
"name": "name",
20+
"content": "content",
21+
}
2022
}*/
2123

22-
type Token struct {
23-
Ip string `json:"ip"`
24-
Port string `json:"port"`
25-
UserName string `json:"username"`
26-
Password string `json:"password"`
24+
type File struct {
25+
Name string `json:"name"`
26+
Content string `json:"content"`
2727
}
2828

2929
type Info struct {
30-
FileName string `json:"filename"`
30+
ID string `json:"id"`
31+
Value string `json:"value"`
3132
Protocol string `json:"protocol"`
32-
UserName string `json:"username"`
33-
Token string `json:"token"`
3433
Command string `json:"command"`
35-
Config string `json:"config"`
34+
File `json:"file"`
3635
}
3736

3837
type DBCommand struct {
@@ -44,7 +43,6 @@ type DBCommand struct {
4443
}
4544

4645
type Rouse struct {
47-
SysType string
4846
Info
4947
}
5048

@@ -61,8 +59,8 @@ func removeCurRdpFile() {
6159

6260
func (r *Rouse) HandleRDP() {
6361
removeCurRdpFile()
64-
filePath := filepath.Join(filepath.Dir(os.Args[0]), r.Info.FileName+".rdp")
65-
err := ioutil.WriteFile(filePath, []byte(r.Info.Config), os.ModePerm)
62+
filePath := filepath.Join(filepath.Dir(os.Args[0]), r.Name+".rdp")
63+
err := ioutil.WriteFile(filePath, []byte(r.Content), os.ModePerm)
6664
if err != nil {
6765
global.LOG.Error(err.Error())
6866
return
@@ -72,10 +70,8 @@ func (r *Rouse) HandleRDP() {
7270
}
7371

7472
func (r *Rouse) HandleSSH() {
75-
t := &Token{}
76-
json.Unmarshal([]byte(r.Token), t)
7773
currentPath := filepath.Dir(os.Args[0])
78-
cmd := handleSSH(t, currentPath)
74+
cmd := handleSSH(r.Command, r.Value, currentPath)
7975
cmd.Run()
8076
}
8177

@@ -140,7 +136,7 @@ func (r *Rouse) HandleDB() {
140136
cmd.Run()
141137
}
142138
func (r *Rouse) Run() {
143-
protocol := r.Info.Protocol
139+
protocol := r.Protocol
144140
switch protocol {
145141
case "rdp":
146142
r.HandleRDP()

go-client/pkg/awaken/awaken_unix.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ func handleRDP(filePath string) *exec.Cmd {
1515
return cmd
1616
}
1717

18-
func handleSSH(t *Token, currentPath string) *exec.Cmd {
18+
func handleSSH(c string, secret string, currentPath string) *exec.Cmd {
1919
clientPath := filepath.Join(currentPath, "client")
20-
command := fmt.Sprintf(
21-
"%s ssh %s@%s -p %s -P %s", clientPath, t.UserName, t.Ip, t.Port, t.Password,
22-
)
20+
command := fmt.Sprintf("%s %s -P %s", clientPath, c, secret)
2321
cmd := awakenCommand(command)
2422
return cmd
2523
}

go-client/pkg/awaken/awaken_windows.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package awaken
22

33
import (
44
"fmt"
5+
"go-client/global"
56
"os/exec"
67
"path/filepath"
78
"strings"
@@ -13,16 +14,29 @@ func handleRDP(filePath string) *exec.Cmd {
1314
return cmd
1415
}
1516

16-
func handleSSH(t *Token, currentPath string) *exec.Cmd {
17+
func handleSSH(c string, secret string, currentPath string) *exec.Cmd {
18+
command := ""
19+
if strings.HasPrefix(c, "putty.exe") {
20+
command = puttySSH(c, secret, currentPath)
21+
} else if strings.HasPrefix(c, "xshell.exe") {
22+
command = xshellSSH(c)
23+
} else {
24+
global.LOG.Error("Type not supported")
25+
}
26+
return exec.Command(command)
27+
}
28+
29+
func puttySSH(c string, secret string, currentPath string) string {
30+
c = strings.TrimPrefix(c, "putty.exe ")
1731
puttyPath := "putty.exe"
1832
if _, err := exec.LookPath("putty.exe"); err != nil {
1933
puttyPath = filepath.Join(currentPath, "putty.exe")
2034
}
21-
cmd := exec.Command(
22-
puttyPath, "-ssh",
23-
fmt.Sprintf("%s@%s", t.UserName, t.Ip), "-P", t.Port, "-pw", t.Password,
24-
)
25-
return cmd
35+
return fmt.Sprintf("%s %s -pw %s", puttyPath, c, secret)
36+
}
37+
38+
func xshellSSH(c string) string {
39+
return c
2640
}
2741

2842
func structurePostgreSQLCommand(command string) string {

0 commit comments

Comments
 (0)