diff --git a/class/core/ssh_terminal.py b/class/core/ssh_terminal.py index 362d278f0..3589a6630 100644 --- a/class/core/ssh_terminal.py +++ b/class/core/ssh_terminal.py @@ -421,7 +421,7 @@ class ssh_terminal: if type(info) == str: time.sleep(0.1) if self.__ssh_list[sid].exit_status_ready(): - self.wsSend("已关闭!\r\n") + self.wsSend("logout\r\n") del(self.__ssh_list[sid]) return self.__ssh_list[sid].send(info) diff --git a/plugins/webssh/js/webssh.js b/plugins/webssh/js/webssh.js index 3774609b4..4c1e05872 100755 --- a/plugins/webssh/js/webssh.js +++ b/plugins/webssh/js/webssh.js @@ -263,11 +263,21 @@ function webShell_getCmdList(){ }); } +function Terms_WebSocketIO_Create(ip,random){ + var n = new Terms_WebSocketIO('#'+random, { ssh_info: { host: ip, ps: "22", id: random } }); + n.registerCloseCallBack(function(){ + webShell_removeTermView(random); + layer.msg('已经关闭【'+ip+'】', { icon: 1, time: 3000 }); + }); + return n; +} + function webShell_Menu(){ var random = 'localhost'; // host_ssh_list[random] = new Terms_WebSocketIO('#'+random, { ssh_info: { host: "38.6.224.67", ps: "22", id: random } }); - host_ssh_list[random] = new Terms_WebSocketIO('#'+random, { ssh_info: { host: "127.0.0.1", ps: "22", id: random } }); + host_ssh_list[random] = Terms_WebSocketIO_Create('127.0.0.1',random); + } function webShell_openTermView(info) { @@ -285,12 +295,14 @@ function webShell_openTermView(info) { info.ps = info.host; } item_list.append('
' + info.ps + '
'); - host_ssh_list[random] = new Terms_WebSocketIO('#' + random, { ssh_info: { host: info.host, ps: info.ps, id: random } }); + host_ssh_list[random] = Terms_WebSocketIO_Create(info.host, random); } function webShell_removeTermView(id){ - var item = $('[data-id="' + id + '"]'), next = item.next(), prev = item.prev(); + var item = $('[data-id="' + id + '"]'); + var next = item.next(); + var prev = item.prev(); $('#' + id).remove(); item.remove(); try { diff --git a/route/static/js/term-websocketio.js b/route/static/js/term-websocketio.js index b9831b6bf..cd2d6372f 100644 --- a/route/static/js/term-websocketio.js +++ b/route/static/js/term-websocketio.js @@ -12,6 +12,8 @@ function Terms_WebSocketIO (el, config) { this.fontSize = 14; //终端字体大小 this.ssh_info = config.ssh_info; this.term_timer = null; + + this.callback_close = null; this.run(); } @@ -44,28 +46,14 @@ Terms_WebSocketIO.prototype = { clearInterval(this.term_timer); this.ws.disconnect(); this.ws.close(); + + console.log('message',this.callback_close,typeof(this.callback_close)); if (this.callback_close){ this.callback_close(); } } }, - on_close: function (ws_event) { - this.ws = null; - }, - - on_error: function (ws_event) { - }, - - send: function (data, num) { - - }, - - //关闭连接 - close: function () { - this.ws.close(); - this.set_term_icon(0); - }, resize: function (size) { if (this.ws) { size['resize'] = 1;