mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
关机后断开webconsole连接
This commit is contained in:
@@ -16,6 +16,7 @@ type ICommand interface {
|
||||
GetCommand() *exec.Cmd
|
||||
Cleanup() error
|
||||
GetData(string) (isShow bool, ouput string, command string)
|
||||
Connect() error
|
||||
ShowInfo() string
|
||||
}
|
||||
|
||||
@@ -42,6 +43,10 @@ func (c BaseCommand) GetCommand() *exec.Cmd {
|
||||
return exec.Command(c.name, c.args...)
|
||||
}
|
||||
|
||||
func (c BaseCommand) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c BaseCommand) GetData(comand string) (isShow bool, ouput string, command string) {
|
||||
return true, "", ""
|
||||
}
|
||||
|
||||
@@ -105,6 +105,15 @@ func (c *SSHtoolSol) GetProtocol() string {
|
||||
return PROTOCOL_TTY
|
||||
}
|
||||
|
||||
func (c *SSHtoolSol) Connect() error {
|
||||
conn, err := net.DialTimeout("tcp", c.IP+":22", time.Second*2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *SSHtoolSol) GetData(data string) (isShow bool, ouput string, command string) {
|
||||
if len(c.Username) == 0 {
|
||||
if len(data) == 0 {
|
||||
|
||||
@@ -19,9 +19,10 @@ const (
|
||||
ON_DISCONNECTION = "disconnection"
|
||||
ON_ERROR = "error"
|
||||
|
||||
OUTPUT_EVENT = "output"
|
||||
INPUT_EVENT = "input"
|
||||
RESIZE_EVENT = "resize"
|
||||
DISCONNECT_EVENT = "disconnect"
|
||||
OUTPUT_EVENT = "output"
|
||||
INPUT_EVENT = "input"
|
||||
RESIZE_EVENT = "resize"
|
||||
|
||||
COMMAND_QUERY = "command"
|
||||
ARGS_QUERY = "args"
|
||||
@@ -72,6 +73,11 @@ func initSocketHandler(so socketio.Socket, p *session.Pty) {
|
||||
so.Emit(OUTPUT_EVENT, string(buf[0:n]))
|
||||
}
|
||||
if !p.IsOk {
|
||||
if err := p.Session.Connect(); err != nil {
|
||||
so.Emit(DISCONNECT_EVENT, "")
|
||||
cleanUp(so, p)
|
||||
return
|
||||
}
|
||||
p.Stop()
|
||||
if info := p.Session.ShowInfo(); len(info) > 0 {
|
||||
so.Emit(OUTPUT_EVENT, info)
|
||||
@@ -89,6 +95,11 @@ func initSocketHandler(so socketio.Socket, p *session.Pty) {
|
||||
// handle write
|
||||
so.On(INPUT_EVENT, func(data string) {
|
||||
if !p.IsOk {
|
||||
if err := p.Session.Connect(); err != nil {
|
||||
so.Emit(DISCONNECT_EVENT, "")
|
||||
cleanUp(so, p)
|
||||
return
|
||||
}
|
||||
if data == "\r" {
|
||||
p.Show, p.Output, p.Command = p.Session.GetData(p.Buffer)
|
||||
so.Emit(OUTPUT_EVENT, "\r\n")
|
||||
|
||||
@@ -64,6 +64,11 @@ func (info *RemoteConsoleInfo) Cleanup() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetData implements ISessionData interface
|
||||
func (info *RemoteConsoleInfo) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetData implements ISessionData interface
|
||||
func (info *RemoteConsoleInfo) GetData(s string) (bool, string, string) {
|
||||
return false, "", ""
|
||||
|
||||
Reference in New Issue
Block a user