支持修改窗口大小

pull/71/head
ibuler 2016-01-01 22:38:50 +08:00
parent ea973bbb52
commit 7bef517518
5 changed files with 59 additions and 6 deletions

View File

@ -352,6 +352,10 @@ def exec_cmd(request):
def web_terminal(request): def web_terminal(request):
asset_id = request.GET.get('id') asset_id = request.GET.get('id')
role_name = request.GET.get('role') role_name = request.GET.get('role')
asset = get_object(Asset, id=asset_id)
if asset:
print asset
hostname = asset.hostname
web_terminal_uri = 'ws://%s/terminal?id=%s&role=%s' % (WEB_SOCKET_HOST, asset_id, role_name) web_terminal_uri = 'ws://%s/terminal?id=%s&role=%s' % (WEB_SOCKET_HOST, asset_id, role_name)
return render_to_response('jlog/web_terminal.html', locals()) return render_to_response('jlog/web_terminal.html', locals())

View File

@ -333,7 +333,13 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
data = json.loads(message) data = json.loads(message)
if not data: if not data:
return return
if data.get('data'):
if 'resize' in data.get('data'):
self.channel.resize_pty(
data.get('data').get('resize').get('cols', 80),
data.get('data').get('resize').get('rows', 24)
)
elif data.get('data'):
self.term.input_mode = True self.term.input_mode = True
if str(data['data']) in ['\r', '\n', '\r\n']: if str(data['data']) in ['\r', '\n', '\r\n']:
if self.term.vim_flag: if self.term.vim_flag:
@ -350,6 +356,8 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
self.term.data = '' self.term.data = ''
self.term.input_mode = False self.term.input_mode = False
self.channel.send(data['data']) self.channel.send(data['data'])
else:
pass
def on_close(self): def on_close(self):
logger.debug('Websocket: Close request') logger.debug('Websocket: Close request')

View File

@ -233,6 +233,7 @@
layer.alert('没有授权系统用户') layer.alert('没有授权系统用户')
} }
else if (dataArray.length == 1 && data != 'error' && navigator.platform == 'Win32'){ else if (dataArray.length == 1 && data != 'error' && navigator.platform == 'Win32'){
/*
var title = 'Jumpserver Web Terminal' + '<span class="text-info"> '+ hostname +'</span>'; var title = 'Jumpserver Web Terminal' + '<span class="text-info"> '+ hostname +'</span>';
layer.open({ layer.open({
type: 2, type: 2,
@ -242,8 +243,10 @@
area: ['628px', '420px'], area: ['628px', '420px'],
content: new_url+data content: new_url+data
}); });
*/
window.open(new_url+data, '', 'width=628px, height=420px')
} else if (dataArray.length == 1 && data != 'error'){ } else if (dataArray.length == 1 && data != 'error'){
layer.open({ /*layer.open({
type: 2, type: 2,
title: title, title: title,
maxmin: true, maxmin: true,
@ -251,6 +254,9 @@
area: ['628px', '452px'], area: ['628px', '452px'],
content: new_url+data content: new_url+data
}); });
*/
window.open(new_url+data, '', 'width=628px, height=440px')
} }
else { else {
aUrl = ''; aUrl = '';
@ -276,6 +282,7 @@
var hostname = $(a).attr('value'); var hostname = $(a).attr('value');
var title = 'Jumpserver Web Terminal - ' + '<span class="text-info"> '+ hostname +'</span>'; var title = 'Jumpserver Web Terminal - ' + '<span class="text-info"> '+ hostname +'</span>';
if (navigator.platform == 'Win32'){ if (navigator.platform == 'Win32'){
/*
layer.open({ layer.open({
type: 2, type: 2,
title: title, title: title,
@ -284,8 +291,11 @@
shade: false, shade: false,
content: new_url content: new_url
}); });
*/
window.open(new_url, '', 'height=628px, width=420px')
} else { } else {
/*
layer.open({ layer.open({
type: 2, type: 2,
title: title, title: title,
@ -294,6 +304,8 @@
shade: false, shade: false,
content: new_url content: new_url
}); });
*/
window.open(new_url, '', 'height=628px, width=452px')
} }
return false return false
@ -310,7 +322,6 @@
shade: false, shade: false,
content: new_url content: new_url
}); });
console.log(new_url);
return false return false
} }

View File

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Jumpserver web terminal</title> <title>Jumpserver Web Terminal: {{ hostname }}</title>
<style> <style>
body { body {
@ -37,6 +37,8 @@
<script type="application/javascript" src="/static/js/term.js"> <script type="application/javascript" src="/static/js/term.js">
</script> </script>
<script type="application/javascript"> <script type="application/javascript">
var rowHeight = 1;
var colWidth = 1;
function WSSHClient() { function WSSHClient() {
} }
@ -101,7 +103,22 @@
term.write(data); term.write(data);
} }
})); }));
rowHeight = 0.0 + 1.00 * $('.terminal').height() / 24 ;
colWidth = 0.0 + 1.00 * $('.terminal').width() / 80;
return {'term': term, 'client': client};
} }
function resize(){
$('.terminal').css('width', window.innerWidth-25);
console.log(window.innerWidth);
console.log(window.innerWidth-10);
var rows = Math.floor(window.innerHeight/rowHeight) - 1;
var cols = Math.floor(window.innerWidth/colWidth) - 1;
return {rows: rows, cols: cols};
}
</script> </script>
<script type='application/javascript'> <script type='application/javascript'>
@ -110,7 +127,17 @@
}; };
$('#ssh').show(); $('#ssh').show();
openTerminal(options); var term_client = openTerminal(options);
console.log(rowHeight);
window.onresize = function(){
var geom = resize();
console.log(geom);
term_client.term.resize(geom.cols, geom.rows);
term_client.client.send({'resize': {'roles': geom.rows, 'cols': geom.cols}});
$('#ssh').show();
}
}); });
</script> </script>
</body> </body>

View File

@ -325,7 +325,10 @@
$('.push_failed').click(function() { $('.push_failed').click(function() {
var fail_reason = $(this).attr('title'); var fail_reason = $(this).attr('title');
layer.alert(fail_reason) layer.alert(fail_reason, {
skin: 'layui-layer-molv',
area: '500px'
})
}); });