Merge pull request #835 in YUNIONIO/onecloud from ~QUXUAN/onecloud:hotfix/qx-webconsole-disconnect to release/2.3.0

* commit '5f9cc3296a4522775cecb78a1d775da0c1927c68':
  关机后断开webconsole连接
This commit is contained in:
邱剑
2018-12-25 15:42:19 +08:00
4 changed files with 33 additions and 3 deletions
+5
View File
@@ -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, "", ""
}
+9
View File
@@ -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 {
+14 -3
View File
@@ -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")
+5
View File
@@ -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, "", ""