Skip to content

Commit 6778ac7

Browse files
committed
fix ssh bug
1 parent b0a3a36 commit 6778ac7

File tree

5 files changed

+109
-110
lines changed

5 files changed

+109
-110
lines changed
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
package sshopt
2-
3-
type SshOption struct {
4-
Node string
5-
SSHHost string
6-
SSHUser string
7-
SSHPwd string
8-
}
9-
10-
var MySsh SshOption
11-
12-
func InitSshOption() {
13-
MySsh = SshOption{
14-
Node: "Server",
15-
SSHHost: "",
16-
SSHUser: "",
17-
SSHPwd: "",
18-
}
19-
}
20-
21-
func SshSet(node, sshHost, sshUser, sshPwd string) {
22-
MySsh = SshOption{
23-
Node: node,
24-
SSHHost: sshHost,
25-
SSHUser: sshUser,
26-
SSHPwd: sshPwd,
27-
}
28-
}
1+
package sshopt
2+
3+
type SshOption struct {
4+
Node string
5+
SSHHost string
6+
SSHUser string
7+
SSHPwd string
8+
}
9+
10+
var MySsh SshOption
11+
12+
func InitSshOption(node string) {
13+
MySsh = SshOption{
14+
Node: node,
15+
SSHHost: "",
16+
SSHUser: "",
17+
SSHPwd: "",
18+
}
19+
}
20+
21+
func SshSet(node, sshHost, sshUser, sshPwd string) {
22+
MySsh = SshOption{
23+
Node: node,
24+
SSHHost: sshHost,
25+
SSHUser: sshUser,
26+
SSHPwd: sshPwd,
27+
}
28+
}
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
package controller
2-
3-
import (
4-
"Orca_Master/cli/cmdopt/sshopt"
5-
"github.com/desertbit/grumble"
6-
)
7-
8-
var backCmd = &grumble.Command{
9-
Name: "back",
10-
Help: "back to the main menu",
11-
Usage: "back [-h | --help]",
12-
Run: func(c *grumble.Context) error {
13-
BackMainMenu()
14-
return nil
15-
},
16-
}
17-
18-
func BackMainMenu() {
19-
App.SetPrompt(InitPrompt)
20-
SelectClientId = ""
21-
SelectId = -1
22-
SelectIp = ""
23-
SelectVer = ""
24-
sshopt.MySsh.Node = SelectClientId
25-
RemoveCommand()
26-
sshopt.InitSshOption()
27-
}
1+
package controller
2+
3+
import (
4+
"Orca_Master/cli/cmdopt/sshopt"
5+
"github.com/desertbit/grumble"
6+
)
7+
8+
var backCmd = &grumble.Command{
9+
Name: "back",
10+
Help: "back to the main menu",
11+
Usage: "back [-h | --help]",
12+
Run: func(c *grumble.Context) error {
13+
BackMainMenu()
14+
return nil
15+
},
16+
}
17+
18+
func BackMainMenu() {
19+
App.SetPrompt(InitPrompt)
20+
SelectClientId = ""
21+
SelectId = -1
22+
SelectIp = ""
23+
SelectVer = ""
24+
sshopt.MySsh.Node = SelectClientId
25+
RemoveCommand()
26+
sshopt.InitSshOption("Server")
27+
}

Orca_Master/cli/controller/mainapp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func init() {
3131
f.String("u", "username", "", "enter username to login to the TeamServer")
3232
f.String("p", "password", "", "enter password to login to the TeamServer")
3333
f.String("c", "color", "green", "theme color (green|blue|red|black|magenta|yellow|cyan|white)")
34-
sshopt.InitSshOption()
34+
sshopt.InitSshOption("Server")
3535
},
3636
})
3737

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,52 @@
1-
package controller
2-
3-
import (
4-
"Orca_Master/cli/cmdopt/listopt"
5-
"Orca_Master/cli/cmdopt/sshopt"
6-
"Orca_Master/cli/common"
7-
"Orca_Master/define/colorcode"
8-
"github.com/desertbit/grumble"
9-
"time"
10-
)
11-
12-
// 选择id对应的主机命令
13-
var selectCmd = &grumble.Command{
14-
Name: "select",
15-
Help: "select the host id waiting to be operated",
16-
Usage: "select [-h | --help] <id>",
17-
Args: func(a *grumble.Args) {
18-
a.Int("id", "set host id")
19-
},
20-
Run: func(c *grumble.Context) error {
21-
SelectId = c.Args.Int("id")
22-
// 发送命令获取HostList
23-
common.SendSuccessMsg("Server", common.ClientId, "listHosts", "")
24-
// 从管道中接收消息
25-
select {
26-
case msg := <-common.DefaultMsgChan:
27-
HostLists = listopt.GetHostLists(msg)
28-
case <-time.After(10 * time.Second):
29-
colorcode.PrintMessage(colorcode.SIGN_FAIL, "request timed out")
30-
return nil
31-
}
32-
// 判断设置id是否合法
33-
if SelectId > len(HostLists) {
34-
SelectId = -1
35-
colorcode.PrintMessage(colorcode.SIGN_ERROR, "there is no corresponding host in the list")
36-
return nil
37-
}
38-
// 更改终端提示符
39-
host := HostLists[SelectId-1]
40-
SelectClientId = host.ClientId
41-
SelectIp = host.Ip
42-
SelectVer = host.Version
43-
sshopt.MySsh.Node = SelectClientId
44-
if SelectId <= 0 {
45-
sshopt.MySsh.Node = "Server"
46-
}
47-
App.SetPrompt("Orca[" + Uname + "] → " + SelectIp + " » ")
48-
RemoveCommand()
49-
AddCommand()
50-
sshopt.InitSshOption()
51-
return nil
52-
},
53-
}
1+
package controller
2+
3+
import (
4+
"Orca_Master/cli/cmdopt/listopt"
5+
"Orca_Master/cli/cmdopt/sshopt"
6+
"Orca_Master/cli/common"
7+
"Orca_Master/define/colorcode"
8+
"github.com/desertbit/grumble"
9+
"time"
10+
)
11+
12+
// 选择id对应的主机命令
13+
var selectCmd = &grumble.Command{
14+
Name: "select",
15+
Help: "select the host id waiting to be operated",
16+
Usage: "select [-h | --help] <id>",
17+
Args: func(a *grumble.Args) {
18+
a.Int("id", "set host id")
19+
},
20+
Run: func(c *grumble.Context) error {
21+
SelectId = c.Args.Int("id")
22+
// 发送命令获取HostList
23+
common.SendSuccessMsg("Server", common.ClientId, "listHosts", "")
24+
// 从管道中接收消息
25+
select {
26+
case msg := <-common.DefaultMsgChan:
27+
HostLists = listopt.GetHostLists(msg)
28+
case <-time.After(10 * time.Second):
29+
colorcode.PrintMessage(colorcode.SIGN_FAIL, "request timed out")
30+
return nil
31+
}
32+
// 判断设置id是否合法
33+
if SelectId > len(HostLists) {
34+
SelectId = -1
35+
colorcode.PrintMessage(colorcode.SIGN_ERROR, "there is no corresponding host in the list")
36+
return nil
37+
}
38+
// 更改终端提示符
39+
host := HostLists[SelectId-1]
40+
SelectClientId = host.ClientId
41+
SelectIp = host.Ip
42+
SelectVer = host.Version
43+
sshopt.MySsh.Node = SelectClientId
44+
if SelectId <= 0 {
45+
sshopt.MySsh.Node = "Server"
46+
}
47+
App.SetPrompt("Orca[" + Uname + "] → " + SelectIp + " » ")
48+
RemoveCommand()
49+
AddCommand()
50+
return nil
51+
},
52+
}

Orca_Master/cli/controller/sshcmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ var sshSetCmd = &grumble.Command{
7575
_, _, retData := common.SettleRetDataEx(msg)
7676
_, _, decData := common.SettleRetData(msg)
7777
if retData.Code != retcode.SUCCESS {
78-
sshopt.InitSshOption()
78+
sshopt.InitSshOption(SelectClientId)
7979
}
8080
fmt.Println(decData)
8181
case <-time.After(30 * time.Second):

0 commit comments

Comments
 (0)