Merge pull request #955 from ioito/hotfix/qx-webconsole-connections

避免webconsole频繁连接server,导致IP被封禁
This commit is contained in:
yunion-ci-robot
2019-05-30 15:03:19 +08:00
committed by GitHub
3 changed files with 19 additions and 19 deletions
-5
View File
@@ -30,7 +30,6 @@ type ICommand interface {
GetCommand() *exec.Cmd
Cleanup() error
GetData(string) (isShow bool, ouput string, command string)
Connect() error
ShowInfo() string
}
@@ -57,10 +56,6 @@ 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, "", ""
}
+7 -9
View File
@@ -87,12 +87,15 @@ 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)
err := p.Stop()
//之前有cmd命令运行,并且正常退出,认为程序是正常退出的
if err == nil && p.Cmd != nil {
so.Disconnect()
return
}
p.Stop()
if err != nil {
log.Warningf("stop tty error: %v", err)
}
if info := p.Session.ShowInfo(); len(info) > 0 {
so.Emit(OUTPUT_EVENT, info)
}
@@ -109,11 +112,6 @@ 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")
+12 -5
View File
@@ -84,18 +84,25 @@ func (p *Pty) Resize(size *pty.Winsize) {
p.sizeCh <- syscall.SIGWINCH
}
func (p *Pty) Stop() {
func (p *Pty) Stop() error {
if p.Pty != nil {
if err := p.Pty.Close(); err != nil {
err := p.Pty.Close()
if err != nil {
log.Errorf("Close PTY error: %v", err)
return err
}
}
if p.Cmd != nil && p.Cmd.Process != nil {
if err := p.Cmd.Process.Signal(os.Kill); err != nil {
err := p.Cmd.Process.Signal(os.Kill)
if err != nil {
log.Errorf("Kill command process error: %v", err)
} else if err := p.Cmd.Wait(); err != nil {
return err
}
err = p.Cmd.Wait()
if err != nil {
log.Errorf("Wait command error: %v", err)
return err
}
}
p.Session.Close()
return p.Session.Close()
}