ssh update 90%

pull/350/head
midoks 2 years ago
parent c952be4e45
commit d5fc464603
  1. 6
      class/core/ssh_terminal.py
  2. 17
      plugins/webssh/js/webssh.js
  3. 30
      route/static/js/term-websocketio.js

@ -383,6 +383,9 @@ class ssh_terminal:
def wsSendConnect(self): def wsSendConnect(self):
return emit('connect', {'data': 'ok'}) return emit('connect', {'data': 'ok'})
def wsSendReConnect(self):
return emit('reconnect', {'data': 'ok'})
def heartbeat(self): def heartbeat(self):
# limit_cos = 10 # limit_cos = 10
while True: while True:
@ -393,7 +396,6 @@ class ssh_terminal:
sid_off_cos = cur_time - ssh_last_time sid_off_cos = cur_time - ssh_last_time
# print("heartbeat off cos :", x, sid_off_cos) # print("heartbeat off cos :", x, sid_off_cos)
if sid_off_cos > 3: if sid_off_cos > 3:
cur_ssh = self.__ssh_list[x] cur_ssh = self.__ssh_list[x]
if not cur_ssh: if not cur_ssh:
@ -423,6 +425,8 @@ class ssh_terminal:
return self.wsSendConnect() return self.wsSendConnect()
else: else:
return self.wsSend(result['msg']) return self.wsSend(result['msg'])
else:
return self.wsSendReConnect()
result = self.returnMsg(False, '') result = self.returnMsg(False, '')
if sid in self.__ssh_list: if sid in self.__ssh_list:

@ -293,8 +293,25 @@ function Terms_WebSocketIO_Create(ip, random){
}); });
n.registerConnectedCallBack(function(){ n.registerConnectedCallBack(function(){
var that = this;
$('.term_item_tab .item').each(function(){
var id = $(this).data('id');
if (id == that.id){
$(this).find('.icon').removeClass('icon-warning').addClass('icon-sucess');
}
});
webShell_Resize(); webShell_Resize();
}); });
n.registerExitCallBack(function(){
var that = this;
$('.term_item_tab .item').each(function(){
var id = $(this).data('id');
if (id == that.id){
$(this).find('.icon').removeClass('icon-sucess').addClass('icon-warning');
}
});
});
return n; return n;
} }

@ -30,6 +30,10 @@ Terms_WebSocketIO.prototype = {
this.callback_connected = callback; this.callback_connected = callback;
}, },
registerExitCallBack:function(callback){
this.callback_exit = callback;
},
connectWs: function (callback) { connectWs: function (callback) {
this.ws = io.connect(); this.ws = io.connect();
// console.log(this.ws); // console.log(this.ws);
@ -61,18 +65,24 @@ Terms_WebSocketIO.prototype = {
} }
}, },
on_connect:function(ws_event){ on_connect:function(ws_event){
// console.log(ws_event);
this.is_connected = true; this.is_connected = true;
if (this.callback_connected){ if (this.callback_connected){
this.callback_connected(); this.callback_connected();
} }
}, },
on_exit:function(ws_event){ on_reconnect:function(ws_event){
this.is_connected = false;
// if (this.callback_connected){
// this.callback_connected();
// }
},
on_exit:function(){
if (this.callback_exit){
this.callback_exit();
}
}, },
send:function(data){ send:function(data){
@ -97,29 +107,29 @@ Terms_WebSocketIO.prototype = {
this.term.setOption('cursorBlink', true); this.term.setOption('cursorBlink', true);
this.ws.on('server_response', function (ev) { that.on_message(ev)}); this.ws.on('server_response', function (ev) { that.on_message(ev)});
this.ws.on('connect', function (ev) { that.on_connect(ev)}); this.ws.on('connect', function (ev) { that.on_connect(ev)});
this.ws.on('reconnect', function (ev) { that.on_reconnect(ev)});
this.ws.on('exit', function (ev) { that.on_exit(ev)}); this.ws.on('exit', function (ev) { that.on_exit(ev)});
if (this.ws) { if (this.ws) {
that.send('');
this.term_timer = setInterval(function () { this.term_timer = setInterval(function () {
if (that.is_connected){ if (that.is_connected){
that.send(''); that.send('');
} else{
that.on_exit();
} }
}, 600); }, 600);
} }
this.term.on('data', function (data) { this.term.on('data', function (data) {
if (that.is_connected){ if (that.is_connected){
try { that.send(data);
that.send(data) } else{
} catch (e) {
that.term.write('\r\n连接丢失,正在尝试重新连接!\r\n'); that.term.write('\r\n连接丢失,正在尝试重新连接!\r\n');
that.connectSsh(); that.connectSsh();
} }
}
}); });
that.term.write('\r\n请稍等,正在链接中...\r\n');
this.term.write('\r\n请稍等,正在链接中...\r\n');
this.connectSsh(); this.connectSsh();
this.term.focus(); this.term.focus();
} }

Loading…
Cancel
Save