mirror of https://github.com/jumpserver/jumpserver
test
parent
31708c0d24
commit
ade8fb927c
|
@ -338,7 +338,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
|
||||||
if not self.term.remote_ip:
|
if not self.term.remote_ip:
|
||||||
self.term.remote_ip = self.request.remote_ip
|
self.term.remote_ip = self.request.remote_ip
|
||||||
self.ssh = self.term.get_connection()
|
self.ssh = self.term.get_connection()
|
||||||
self.channel = self.ssh.invoke_shell()
|
self.channel = self.ssh.invoke_shell(term='xterm')
|
||||||
WebTerminalHandler.tasks.append(MyThread(target=self.forward_outbound))
|
WebTerminalHandler.tasks.append(MyThread(target=self.forward_outbound))
|
||||||
WebTerminalHandler.clients.append(self)
|
WebTerminalHandler.clients.append(self)
|
||||||
|
|
||||||
|
@ -412,7 +412,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
|
||||||
if self.term.vim_flag:
|
if self.term.vim_flag:
|
||||||
self.term.vim_data += recv
|
self.term.vim_data += recv
|
||||||
try:
|
try:
|
||||||
print chardet.detect(data)
|
# print chardet.detect(data)
|
||||||
if chardet.detect(data)['encoding'] == 'GB2312':
|
if chardet.detect(data)['encoding'] == 'GB2312':
|
||||||
data = data.decode('gb2312').encode('utf8')
|
data = data.decode('gb2312').encode('utf8')
|
||||||
self.write_message(data)
|
self.write_message(data)
|
||||||
|
|
|
@ -1,69 +1,61 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by liuzheng on 3/3/16.
|
* Created by liuzheng on 3/3/16.
|
||||||
*/
|
*/
|
||||||
var rowHeight = 1;
|
var rowHeight = 1;
|
||||||
var colWidth = 1;
|
var colWidth = 1;
|
||||||
//function WSSHClient() {
|
function WSSHClient() {
|
||||||
//}
|
}
|
||||||
//WSSHClient.prototype._generateEndpoint = function (options) {
|
WSSHClient.prototype._generateEndpoint = function (options) {
|
||||||
// console.log(options);
|
console.log(options);
|
||||||
// if (window.location.protocol == 'https:') {
|
|
||||||
// var protocol = 'wss://';
|
|
||||||
// } else {
|
|
||||||
// var protocol = 'ws://';
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// var endpoint = protocol + document.URL.match(RegExp('//(.*?)/'))[1] + '/ws/terminal' + document.URL.match(/(\?.*)/);
|
|
||||||
// return endpoint;
|
|
||||||
//};
|
|
||||||
//WSSHClient.prototype.connect = function (options) {
|
|
||||||
// var endpoint = this._generateEndpoint(options);
|
|
||||||
//
|
|
||||||
// if (window.WebSocket) {
|
|
||||||
// this._connection = new WebSocket(endpoint);
|
|
||||||
// }
|
|
||||||
// else if (window.MozWebSocket) {
|
|
||||||
// this._connection = MozWebSocket(endpoint);
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// options.onError('WebSocket Not Supported');
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// this._connection.onopen = function () {
|
|
||||||
// options.onConnect();
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// this._connection.onmessage = function (evt) {
|
|
||||||
// var data = JSON.parse(evt.data.toString());
|
|
||||||
// if (data.error !== undefined) {
|
|
||||||
// options.onError(data.error);
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// options.onData(data.data);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// this._connection.onclose = function (evt) {
|
|
||||||
// options.onClose();
|
|
||||||
// };
|
|
||||||
//};
|
|
||||||
//
|
|
||||||
//WSSHClient.prototype.send = function (data) {
|
|
||||||
// this._connection.send(JSON.stringify({'data': data}));
|
|
||||||
//};
|
|
||||||
|
|
||||||
|
|
||||||
function openTerminal(options) {
|
|
||||||
if (window.location.protocol == 'https:') {
|
if (window.location.protocol == 'https:') {
|
||||||
var protocol = 'wss://';
|
var protocol = 'wss://';
|
||||||
} else {
|
} else {
|
||||||
var protocol = 'ws://';
|
var protocol = 'ws://';
|
||||||
}
|
}
|
||||||
|
|
||||||
var endpoint = protocol + document.URL.match(RegExp('//(.*?)/'))[1] + '/ws/terminal' + document.URL.match(/(\?.*)/)[1];
|
var endpoint = protocol + document.URL.match(RegExp('//(.*?)/'))[1] + '/ws/terminal' + document.URL.match(/(\?.*)/);
|
||||||
var sock = new WebSocket(endpoint);
|
return endpoint;
|
||||||
//var client = new WSSHClient();
|
};
|
||||||
|
WSSHClient.prototype.connect = function (options) {
|
||||||
|
var endpoint = this._generateEndpoint(options);
|
||||||
|
|
||||||
|
if (window.WebSocket) {
|
||||||
|
this._connection = new WebSocket(endpoint);
|
||||||
|
}
|
||||||
|
else if (window.MozWebSocket) {
|
||||||
|
this._connection = MozWebSocket(endpoint);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
options.onError('WebSocket Not Supported');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._connection.onopen = function () {
|
||||||
|
options.onConnect();
|
||||||
|
};
|
||||||
|
|
||||||
|
this._connection.onmessage = function (evt) {
|
||||||
|
var data = JSON.parse(evt.data.toString());
|
||||||
|
if (data.error !== undefined) {
|
||||||
|
options.onError(data.error);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
options.onData(data.data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this._connection.onclose = function (evt) {
|
||||||
|
options.onClose();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
WSSHClient.prototype.send = function (data) {
|
||||||
|
this._connection.send(JSON.stringify({'data': data}));
|
||||||
|
};
|
||||||
|
|
||||||
|
function openTerminal(options) {
|
||||||
|
var client = new WSSHClient();
|
||||||
var term = new Terminal({
|
var term = new Terminal({
|
||||||
rows: rowHeight,
|
rows: rowHeight,
|
||||||
cols: colWidth,
|
cols: colWidth,
|
||||||
|
@ -72,46 +64,29 @@ function openTerminal(options) {
|
||||||
});
|
});
|
||||||
term.open();
|
term.open();
|
||||||
term.on('data', function (data) {
|
term.on('data', function (data) {
|
||||||
sock.send(JSON.stringify({'data': data}))
|
client.send(data)
|
||||||
});
|
});
|
||||||
$('.terminal').detach().appendTo('#term');
|
$('.terminal').detach().appendTo('#term');
|
||||||
term.resize(80, 24);
|
term.resize(80, 24);
|
||||||
term.write('Connecting...');
|
term.write('Connecting...');
|
||||||
sock.onopen = function () {
|
client.connect($.extend(options, {
|
||||||
// Erase our connecting message
|
onError: function (error) {
|
||||||
term.write('\r');
|
term.write('Error: ' + error + '\r\n');
|
||||||
};
|
},
|
||||||
sock.onclose = function () {
|
onConnect: function () {
|
||||||
term.write('Connection Reset By Peer');
|
// Erase our connecting message
|
||||||
};
|
term.write('\r');
|
||||||
sock.onmessage= function (data) {
|
},
|
||||||
try {
|
onClose: function () {
|
||||||
term.write(data.data)
|
term.write('Connection Reset By Peer');
|
||||||
} catch (e) {
|
},
|
||||||
term.write(JSON.parse(data.data)['data'])
|
onData: function (data) {
|
||||||
|
term.write(data);
|
||||||
}
|
}
|
||||||
};
|
}));
|
||||||
sock.onerror= function () {
|
|
||||||
term.write('Connection Reset By Peer');
|
|
||||||
};
|
|
||||||
//client.connect($.extend(options, {
|
|
||||||
// onError: function (error) {
|
|
||||||
// term.write('Error: ' + error + '\r\n');
|
|
||||||
// },
|
|
||||||
// onConnect: function () {
|
|
||||||
// // Erase our connecting message
|
|
||||||
// term.write('\r');
|
|
||||||
// },
|
|
||||||
// onClose: function () {
|
|
||||||
// term.write('Connection Reset By Peer');
|
|
||||||
// },
|
|
||||||
// onData: function (data) {
|
|
||||||
// term.write(data);
|
|
||||||
// }
|
|
||||||
//}));
|
|
||||||
rowHeight = 0.0 + 1.00 * $('.terminal').height() / 24;
|
rowHeight = 0.0 + 1.00 * $('.terminal').height() / 24;
|
||||||
colWidth = 0.0 + 1.00 * $('.terminal').width() / 80;
|
colWidth = 0.0 + 1.00 * $('.terminal').width() / 80;
|
||||||
return {'term': term, 'client': sock};
|
return {'term': term, 'client': client};
|
||||||
}
|
}
|
||||||
|
|
||||||
function resize() {
|
function resize() {
|
||||||
|
@ -135,7 +110,7 @@ $(document).ready(function () {
|
||||||
var geom = resize();
|
var geom = resize();
|
||||||
console.log(geom);
|
console.log(geom);
|
||||||
term_client.term.resize(geom.cols, geom.rows);
|
term_client.term.resize(geom.cols, geom.rows);
|
||||||
term_client.client.send(JSON.stringify({'data':{'resize': {'rows': geom.rows, 'cols': geom.cols}}}));
|
term_client.client.send({'resize': {'rows': geom.rows, 'cols': geom.cols}});
|
||||||
$('#ssh').show();
|
$('#ssh').show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue