From 0499a7265a4a407227a8cfd857504ecb59807886 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Tue, 5 Apr 2016 10:53:35 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E5=A4=A7=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run_server.py | 1 + static/js/record.js | 7 ++- static/js/webterminal.js | 52 +++++++++++++++----- templates/jlog/log_online.html | 10 +++- templates/jlog/web_terminal.html | 84 +++++++++++++++++++------------- 5 files changed, 103 insertions(+), 51 deletions(-) diff --git a/run_server.py b/run_server.py index 41f70fe25..4a4047c62 100755 --- a/run_server.py +++ b/run_server.py @@ -362,6 +362,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler): return if 'resize' in jsondata.get('data'): + self.termlog.write(jsondata) self.channel.resize_pty( jsondata.get('data').get('resize').get('cols', 80), jsondata.get('data').get('resize').get('rows', 24) diff --git a/static/js/record.js b/static/js/record.js index 910ebbc22..ddcb15755 100644 --- a/static/js/record.js +++ b/static/js/record.js @@ -56,7 +56,12 @@ NgApp.controller('TerminalRecordCtrl', function ($scope, $http) { document.getElementById("beforeScrubberText").innerHTML = buildTimeString(time); for (; pos < timelist.length; pos++) { if (timelist[pos] * 1000 <= time) { - term.write(data[timelist[pos]]); + try{ + var findResize = JSON.parse(data[timelist[pos]])['reszie']; + term.resize(findResize['cols'], findResize['rows']) + } catch (err) { + term.write(data[timelist[pos]]); + } } else { break; } diff --git a/static/js/webterminal.js b/static/js/webterminal.js index 50e21276f..4205e04b2 100644 --- a/static/js/webterminal.js +++ b/static/js/webterminal.js @@ -36,7 +36,7 @@ WSSHClient.prototype.connect = function (options) { }; this._connection.onmessage = function (evt) { - try{ + try { options.onData(evt.data); } catch (e) { var data = JSON.parse(evt.data.toString()); @@ -55,6 +55,15 @@ WSSHClient.prototype.send = function (data) { function openTerminal(options) { var client = new WSSHClient(); + var rowHeight, colWidth; + try { + rowHeight = localStorage.getItem('term-row'); + colWidth = localStorage.getItem('term-col'); + } catch (err) { + rowHeight = 24; + colWidth = 80 + } + var term = new Terminal({ rows: rowHeight, cols: colWidth, @@ -66,7 +75,7 @@ function openTerminal(options) { client.send(data) }); $('.terminal').detach().appendTo('#term'); - term.resize(80, 24); + //term.resize(colWidth, rowHeight); term.write('Connecting...'); client.connect($.extend(options, { onError: function (error) { @@ -74,6 +83,7 @@ function openTerminal(options) { }, onConnect: function () { // Erase our connecting message + client.send({'resize': {'rows': rowHeight, 'cols': colWidth}}); term.write('\r'); }, onClose: function () { @@ -83,20 +93,20 @@ function openTerminal(options) { term.write(data); } })); - rowHeight = 0.0 + 1.00 * $('.terminal').height() / 24; - colWidth = 0.0 + 1.00 * $('.terminal').width() / 80; + //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) - 2; - var cols = Math.floor(window.innerWidth / colWidth) - 1; - - return {rows: rows, cols: cols}; -} +//function resize() { +// $('.terminal').css('width', window.innerWidth - 25); +// console.log(window.innerWidth); +// console.log(window.innerWidth - 10); +// var rows = Math.floor(window.innerHeight / rowHeight) - 2; +// var cols = Math.floor(window.innerWidth / colWidth) - 1; +// +// return {rows: rows, cols: cols}; +//} $(document).ready(function () { var options = {}; @@ -112,5 +122,21 @@ $(document).ready(function () { // term_client.client.send({'resize': {'rows': geom.rows, 'cols': geom.cols}}); // $('#ssh').show(); //} + try { + $('#term-row')[0].value = localStorage.getItem('term-row'); + $('#term-col')[0].value = localStorage.getItem('term-col'); + } catch (err) { + $('#term-row')[0].value = 24; + $('#term-col')[0].value = 80; + } + $('#col-row').click(function () { + var col = $('#term-col').val(); + var row = $('#term-row').val(); + localStorage.setItem('term-col', col); + localStorage.setItem('term-row', row); + term_client.term.resize(col, row); + term_client.client.send({'resize': {'rows': row, 'cols': col}}); + $('#ssh').show(); + }) }); \ No newline at end of file diff --git a/templates/jlog/log_online.html b/templates/jlog/log_online.html index 4f2e60213..e40098685 100644 --- a/templates/jlog/log_online.html +++ b/templates/jlog/log_online.html @@ -173,8 +173,14 @@ $('.terminal').detach().appendTo('#term'); $('.terminal').show(); socket.onmessage = function(evt){ - term.write(evt.data); - }}, 1000); + try { + var findResize = JSON.parse(evt.data)['resize']; + term.resize(findResize['cols'], findResize['rows']) + } catch (err) { + term.write(evt.data); + } + } + }, 1000); return tag[0]; } , diff --git a/templates/jlog/web_terminal.html b/templates/jlog/web_terminal.html index b5aae590d..af27e1127 100644 --- a/templates/jlog/web_terminal.html +++ b/templates/jlog/web_terminal.html @@ -1,43 +1,57 @@ - - - Jumpserver Web Terminal: {{ hostname }} + + + Jumpserver Web Terminal: {{ hostname }} - - + .reverse-video { + color: #000; + background: #f0f0f0; + } - -
-
-
-
+ .clock { + line-height: 1; + margin: 0 auto; + border: 1px solid #ffffff; + color: #fff; + background-color: #ffffff; + position: fixed; + right: 0; + top: 0; + } + + - - - - + +
+
+
+
+
+ + + +
+ + + + From ef59cff44b40bba38530a8e262b6fef955db1b94 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Tue, 5 Apr 2016 12:42:44 +0800 Subject: [PATCH 02/13] bug_fix --- run_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_server.py b/run_server.py index 633950cdb..6c4f42cad 100755 --- a/run_server.py +++ b/run_server.py @@ -364,7 +364,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler): return if 'resize' in jsondata.get('data'): - self.termlog.write(jsondata) + self.termlog.write(message) self.channel.resize_pty( jsondata.get('data').get('resize').get('cols', 80), jsondata.get('data').get('resize').get('rows', 24) From b908fdafc6c89feee9511e01250be1a0dcda0ee3 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Tue, 5 Apr 2016 12:50:09 +0800 Subject: [PATCH 03/13] udpate --- run_server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run_server.py b/run_server.py index 6c4f42cad..48b6be17e 100755 --- a/run_server.py +++ b/run_server.py @@ -366,8 +366,8 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler): if 'resize' in jsondata.get('data'): self.termlog.write(message) self.channel.resize_pty( - jsondata.get('data').get('resize').get('cols', 80), - jsondata.get('data').get('resize').get('rows', 24) + width=jsondata.get('data').get('resize').get('cols', 80), + height=jsondata.get('data').get('resize').get('rows', 24) ) elif jsondata.get('data'): self.termlog.recoder = True From 7f4d3ffdbc747f8fef7252e370aa6f382574efb4 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Tue, 5 Apr 2016 12:54:37 +0800 Subject: [PATCH 04/13] bug_fix --- static/js/webterminal.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/static/js/webterminal.js b/static/js/webterminal.js index 4205e04b2..6f96ab284 100644 --- a/static/js/webterminal.js +++ b/static/js/webterminal.js @@ -63,6 +63,8 @@ function openTerminal(options) { rowHeight = 24; colWidth = 80 } + if(rowHeight){}else{rowHeight=24}; + if(colWidth){}else{colWidth=80}; var term = new Terminal({ rows: rowHeight, From c76d9ebd8840d69eb5d03ca0f42e837b39fb7130 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Tue, 5 Apr 2016 12:56:37 +0800 Subject: [PATCH 05/13] bugfix --- run_server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run_server.py b/run_server.py index 48b6be17e..246ecc560 100755 --- a/run_server.py +++ b/run_server.py @@ -366,8 +366,8 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler): if 'resize' in jsondata.get('data'): self.termlog.write(message) self.channel.resize_pty( - width=jsondata.get('data').get('resize').get('cols', 80), - height=jsondata.get('data').get('resize').get('rows', 24) + width=int(jsondata.get('data').get('resize').get('cols', 80)), + height=int(jsondata.get('data').get('resize').get('rows', 24)) ) elif jsondata.get('data'): self.termlog.recoder = True From 6518aa36708073b2f7a99e1b88a576b314f1192c Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Tue, 5 Apr 2016 13:05:07 +0800 Subject: [PATCH 06/13] bugfix --- static/js/record.js | 4 ++-- templates/jlog/log_online.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/static/js/record.js b/static/js/record.js index ddcb15755..8d73dde3d 100644 --- a/static/js/record.js +++ b/static/js/record.js @@ -57,8 +57,8 @@ NgApp.controller('TerminalRecordCtrl', function ($scope, $http) { for (; pos < timelist.length; pos++) { if (timelist[pos] * 1000 <= time) { try{ - var findResize = JSON.parse(data[timelist[pos]])['reszie']; - term.resize(findResize['cols'], findResize['rows']) + var findResize = JSON.parse(data[timelist[pos]])['data']; + term.resize(findResize['resize']['cols'], findResize['resize']['rows']) } catch (err) { term.write(data[timelist[pos]]); } diff --git a/templates/jlog/log_online.html b/templates/jlog/log_online.html index e40098685..290612c43 100644 --- a/templates/jlog/log_online.html +++ b/templates/jlog/log_online.html @@ -174,8 +174,8 @@ $('.terminal').show(); socket.onmessage = function(evt){ try { - var findResize = JSON.parse(evt.data)['resize']; - term.resize(findResize['cols'], findResize['rows']) + var findResize = JSON.parse(evt.data)['data']; + term.resize(findResize['resize']['cols'], findResize['resize']['rows']) } catch (err) { term.write(evt.data); } From aabab653d30d1ea90d95876883f51f90f454ffdf Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Wed, 6 Apr 2016 10:24:18 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E9=BB=98=E8=AE=A4terminal=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F100x35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run_server.py | 4 ++-- static/js/record.js | 4 ++-- static/js/webterminal.js | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/run_server.py b/run_server.py index 246ecc560..416c86f70 100755 --- a/run_server.py +++ b/run_server.py @@ -366,8 +366,8 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler): if 'resize' in jsondata.get('data'): self.termlog.write(message) self.channel.resize_pty( - width=int(jsondata.get('data').get('resize').get('cols', 80)), - height=int(jsondata.get('data').get('resize').get('rows', 24)) + width=int(jsondata.get('data').get('resize').get('cols', 100)), + height=int(jsondata.get('data').get('resize').get('rows', 35)) ) elif jsondata.get('data'): self.termlog.recoder = True diff --git a/static/js/record.js b/static/js/record.js index 8d73dde3d..ba334e0c2 100644 --- a/static/js/record.js +++ b/static/js/record.js @@ -108,8 +108,8 @@ NgApp.controller('TerminalRecordCtrl', function ($scope, $http) { }; var term = new Terminal({ - rows: 24, - cols: 80, + rows: 35, + cols: 100, useStyle: true, screenKeys: true }); diff --git a/static/js/webterminal.js b/static/js/webterminal.js index 6f96ab284..d21500499 100644 --- a/static/js/webterminal.js +++ b/static/js/webterminal.js @@ -60,11 +60,11 @@ function openTerminal(options) { rowHeight = localStorage.getItem('term-row'); colWidth = localStorage.getItem('term-col'); } catch (err) { - rowHeight = 24; - colWidth = 80 + rowHeight = 35; + colWidth = 100 } - if(rowHeight){}else{rowHeight=24}; - if(colWidth){}else{colWidth=80}; + if(rowHeight){}else{rowHeight=35}; + if(colWidth){}else{colWidth=100}; var term = new Terminal({ rows: rowHeight, @@ -128,8 +128,8 @@ $(document).ready(function () { $('#term-row')[0].value = localStorage.getItem('term-row'); $('#term-col')[0].value = localStorage.getItem('term-col'); } catch (err) { - $('#term-row')[0].value = 24; - $('#term-col')[0].value = 80; + $('#term-row')[0].value = 35; + $('#term-col')[0].value = 100; } $('#col-row').click(function () { var col = $('#term-col').val(); From ff8b5bd6c0af2d268faf05b8eaafbcf6ce50a222 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Wed, 6 Apr 2016 10:26:30 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E9=BB=98=E8=AE=A4terminal100x35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlog/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jlog/views.py b/jlog/views.py index 09c79a9d8..ff1239e8e 100644 --- a/jlog/views.py +++ b/jlog/views.py @@ -224,7 +224,7 @@ class TermLogRecorder(object): Initializing the virtual screen and the character stream """ self._stream = pyte.ByteStream() - self._screen = pyte.Screen(80, 24) + self._screen = pyte.Screen(100, 35) self._stream.attach(self._screen) def _command(self): From 2e49f51093d8f22671c6aba761e9521c248bd388 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Wed, 6 Apr 2016 12:58:00 +0800 Subject: [PATCH 09/13] update --- templates/jlog/web_terminal.html | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/templates/jlog/web_terminal.html b/templates/jlog/web_terminal.html index af27e1127..44a58ba50 100644 --- a/templates/jlog/web_terminal.html +++ b/templates/jlog/web_terminal.html @@ -25,7 +25,7 @@ background: #f0f0f0; } - .clock { + .termChangBar { line-height: 1; margin: 0 auto; border: 1px solid #ffffff; @@ -43,15 +43,13 @@
-
- - +
+ +
- - + + From 288a42663a233791756ad7bd54ebc3722fab89d3 Mon Sep 17 00:00:00 2001 From: Astraeux Date: Tue, 12 Apr 2016 11:11:19 +0800 Subject: [PATCH 10/13] TTY nav sort by ip / hostname / none (#198) * TTY nav sort by ip / hostname / none * add newline at end of file --- connect.py | 16 +++++++++++++--- jumpserver.conf | 3 +++ jumpserver/settings.py | 6 ++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/connect.py b/connect.py index e9bcee094..41d7e89bd 100755 --- a/connect.py +++ b/connect.py @@ -29,7 +29,7 @@ from django.contrib.sessions.models import Session from jumpserver.api import ServerError, User, Asset, PermRole, AssetGroup, get_object, mkdir, get_asset_info from jumpserver.api import logger, Log, TtyLog, get_role_key, CRYPTOR, bash, get_tmp_dir from jperm.perm_api import gen_resource, get_group_asset_perm, get_group_user_perm, user_have_perm, PermRole -from jumpserver.settings import LOG_DIR +from jumpserver.settings import LOG_DIR, NAV_SORT_BY from jperm.ansible_api import MyRunner # from jlog.log_api import escapeString from jlog.models import ExecLog, FileLog @@ -437,11 +437,21 @@ class Nav(object): def __init__(self, user): self.user = user self.user_perm = get_group_user_perm(self.user) - self.perm_assets = sorted(self.user_perm.get('asset', []).keys(), - key=lambda x: [int(num) for num in x.ip.split('.') if num.isdigit()]) + if NAV_SORT_BY == 'ip': + self.perm_assets = sorted(self.user_perm.get('asset', []).keys(), + key=lambda x: [int(num) for num in x.ip.split('.') if num.isdigit()]) + elif NAV_SORT_BY == 'hostname': + self.perm_assets = self.natural_sort_hostname(self.user_perm.get('asset', []).keys()) + else: + self.perm_assets = tuple(self.user_perm.get('asset', [])) self.search_result = self.perm_assets self.perm_asset_groups = self.user_perm.get('asset_group', []) + def natural_sort_hostname(self, list): + convert = lambda text: int(text) if text.isdigit() else text.lower() + alphanum_key = lambda x: [ convert(c) for c in re.split('([0-9]+)', x.hostname) ] + return sorted(list, key = alphanum_key) + @staticmethod def print_nav(): """ diff --git a/jumpserver.conf b/jumpserver.conf index a2b4132d1..28c359c3a 100644 --- a/jumpserver.conf +++ b/jumpserver.conf @@ -20,3 +20,6 @@ email_host_user = email_host_password = email_use_tls = True email_use_ssl = False + +[connect] +nav_sort_by = ip diff --git a/jumpserver/settings.py b/jumpserver/settings.py index d01dcc96a..6f9dc2dc4 100644 --- a/jumpserver/settings.py +++ b/jumpserver/settings.py @@ -49,6 +49,12 @@ LOG_LEVEL = config.get('base', 'log') IP = config.get('base', 'ip') PORT = config.get('base', 'port') +# ======== Connect ========== +try: + NAV_SORT_BY = config.get('connect', 'nav_sort_by') +except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): + NAV_SORT_BY = 'ip' + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ From c9ff2350893a3451df754a240195f77c88bfb382 Mon Sep 17 00:00:00 2001 From: ibuler Date: Sat, 16 Apr 2016 16:27:15 +0800 Subject: [PATCH 11/13] fix(connect) input exact ip for connect modify search strategy if some ip match pass --- connect.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/connect.py b/connect.py index 41d7e89bd..bb7af929c 100755 --- a/connect.py +++ b/connect.py @@ -500,8 +500,9 @@ class Nav(object): except (ValueError, TypeError): # 匹配 ip, hostname, 备注 str_r = str_r.lower() - self.search_result = [asset for asset in self.perm_assets if str_r in str(asset.ip).lower() - or str_r in str(asset.hostname).lower() + self.search_result = [asset for asset in self.perm_assets if str_r == str(asset.ip).lower()] or \ + [asset for asset in self.perm_assets if str_r in str(asset.ip).lower() \ + or str_r in str(asset.hostname).lower() \ or str_r in str(asset.comment).lower()] else: # 如果没有输入就展现所有 From eb4ec47f7a49f5db397973ad1dee3d026cae5f6c Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 20 Apr 2016 14:29:11 +0800 Subject: [PATCH 12/13] bugfix(upload web) When download file, static file will unreachable. Didn't change dir fixed --- jumpserver/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jumpserver/views.py b/jumpserver/views.py index 70476d1a1..f19885e22 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -326,9 +326,9 @@ def download(request): FileLog(user=request.user.username, host=' '.join([asset.hostname for asset in asset_select]), filename=file_path, type='download', remote_ip=remote_ip, result=runner.results).save() logger.debug(runner.results) - os.chdir('/tmp') + #os.chdir('/tmp') tmp_dir_name = os.path.basename(upload_dir) - tar_file = '%s.tar.gz' % upload_dir + tar_file = '/tmp/%s.tar.gz' % upload_dir bash('tar czf %s %s' % (tar_file, tmp_dir_name)) f = open(tar_file) data = f.read() From 9be13cf08f269dd80aae5b4233ac995cb4d1a07c Mon Sep 17 00:00:00 2001 From: yumaojun03 <719118794@qq.com> Date: Wed, 20 Apr 2016 14:31:52 +0800 Subject: [PATCH 13/13] =?UTF-8?q?fix=20(jperm):=20=20=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E6=B7=BB=E5=8A=A0=E5=92=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20role=E6=97=B6=20=E5=AF=86=E7=A0=81=E8=BF=87=E9=95=BF?= =?UTF-8?q?=E5=BC=95=E8=B5=B7=E7=9A=84bug=20(#202)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 修改password字段的长度,对称加密过后的字符串会变长,所有设置得比较大(512) 2. 修改后端检查密码长度,并触发异常。 --- jperm/models.py | 2 +- jperm/views.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/jperm/models.py b/jperm/models.py index 0ba12354a..a3451c447 100644 --- a/jperm/models.py +++ b/jperm/models.py @@ -26,7 +26,7 @@ class PermSudo(models.Model): class PermRole(models.Model): name = models.CharField(max_length=100, unique=True) comment = models.CharField(max_length=100, null=True, blank=True, default='') - password = models.CharField(max_length=128) + password = models.CharField(max_length=512) key_path = models.CharField(max_length=100) date_added = models.DateTimeField(auto_now=True) sudo = models.ManyToManyField(PermSudo, related_name='perm_role') diff --git a/jperm/views.py b/jperm/views.py index 7ff572bcf..6e7036098 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -290,6 +290,8 @@ def perm_role_add(request): if name == "root": raise ServerError(u'禁止使用root用户作为系统用户,这样非常危险!') default = get_object(Setting, name='default') + if len(password) > 64: + raise ServerError(u'密码长度不能超过64位!') if password: encrypt_pass = CRYPTOR.encrypt(password) @@ -446,6 +448,8 @@ def perm_role_edit(request): role_sudo_names = request.POST.getlist("sudo_name") role_sudos = [PermSudo.objects.get(id=sudo_id) for sudo_id in role_sudo_names] key_content = request.POST.get("role_key", "") + if len(role_password) > 64: + raise ServerError(u'密码长度不能超过64位!') try: if not role: