From 09416286bf17f37354c73c5891f70478604818a3 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 29 Dec 2015 13:09:05 +0800 Subject: [PATCH 01/15] fix install port bug --- install/install.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/install.py b/install/install.py index 725eca728..0ada544b1 100755 --- a/install/install.py +++ b/install/install.py @@ -109,7 +109,7 @@ class PreSetup(object): def _test_db_conn(self): try: - MySQLdb.connect(host=self.db_host, port=self.db_port, + MySQLdb.connect(host=self.db_host, port=int(self.db_port), user=self.db_user, passwd=self.db_pass, db=self.db) color_print('连接数据库成功', 'green') return True @@ -157,7 +157,7 @@ class PreSetup(object): self._setup_mysql() else: db_host = raw_input('请输入数据库服务器IP [127.0.0.1]: ') - db_port = int(raw_input('请输入数据库服务器端口 [3306]: ')) + db_port = raw_input('请输入数据库服务器端口 [3306]: ') db_user = raw_input('请输入数据库服务器用户 [root]: ') db_pass = raw_input('请输入数据库服务器密码: ') db = raw_input('请输入使用的数据库 [jumpserver]: ') From e776c3c5f9db378e3e6b9a68c4f493eb2bc695f9 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 29 Dec 2015 22:54:55 +0800 Subject: [PATCH 02/15] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3cca1b740..448ce6711 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,10 @@ Web批量执行命令 ### 文档 * [访问wiki](https://github.com/ibuler/jumpserver/wiki) -* [快速安装](https://github.com/ibuler/jumpserver/wiki/快速安装) -* [名词解释](https://github.com/ibuler/jumpserver/wiki/名称解释) -* [快速开始](https://github.com/ibuler/jumpserver/wiki/快速开始) +* [快速安装](https://github.com/ibuler/jumpserver/wiki/Quickinstall) +* [名词解释](https://github.com/ibuler/jumpserver/wiki/Termexplain) +* [快速开始](https://github.com/ibuler/jumpserver/wiki/Quickstart) +* [FAQ](https://github.com/ibuler/jumpserver/wiki/FAQs) ### 特点 From 86cc963673b54fd433889db1456d3c049bf0146a Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 30 Dec 2015 12:11:39 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E6=9B=B4=E6=8D=A2alert=E6=88=91layer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/juser/change_info.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/juser/change_info.html b/templates/juser/change_info.html index 376ae54b8..7c55b674a 100644 --- a/templates/juser/change_info.html +++ b/templates/juser/change_info.html @@ -113,12 +113,12 @@ $('#userForm').validator({ $("document").ready(function() { $("#regen_ssh_key").click(function () { - alert('申请已提交,请等待,请勿重复提交'); + layer.alert('申请已提交,请等待,请勿重复提交'); $.get( $(this).attr('value'), {}, function(data){ - alert(data) + layer.alert(data) } ) }) From 2fa1d7a95b083c24d3903cea1ed6e3bc3f8b974d Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 30 Dec 2015 12:36:34 +0800 Subject: [PATCH 04/15] =?UTF-8?q?fix=20connect.py=20=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- connect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connect.py b/connect.py index e38dfa751..18c84dee7 100755 --- a/connect.py +++ b/connect.py @@ -527,7 +527,7 @@ class Nav(object): user_asset_search = user_asset_all self.search_result = dict(zip(range(len(user_asset_search)), user_asset_search)) - color_print('[%-3s] %-12s %-15s %-5s %-10s %s' % ('ID', u'主机名', 'IP', u'端口', u'系统用户', u'备注'), 'title') + color_print('[%-3s] %-12s %-15s %-5s %-10s %s' % ('ID', '主机名', 'IP', '端口', '系统用户', '备注'), 'title') for index, asset in self.search_result.items(): # 获取该资产信息 asset_info = get_asset_info(asset) @@ -734,7 +734,7 @@ def main(): 主程序 """ if not login_user: # 判断用户是否存在 - color_print(u'没有该用户,或许你是以root运行的 No that user.', exits=True) + color_print('没有该用户,或许你是以root运行的 No that user.', exits=True) gid_pattern = re.compile(r'^g\d+$') nav = Nav(login_user) From 7be7772af6ac16ee0ac7c89a9f7faffcef3d760a Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 30 Dec 2015 15:38:28 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=98=BE=E7=A4=BAip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jperm/views.py | 2 +- templates/jperm/perm_rule_edit.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jperm/views.py b/jperm/views.py index 33dce420b..db05783bd 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -539,7 +539,7 @@ def perm_role_push(request): if not failed_asset: msg = u'系统用户 %s 推送成功[ %s ]' % (role.name, ','.join(success_asset.keys())) else: - error = u'系统用户 %s 推送失败 [ %s ], 推送成功 [ %s ]' % (role.name, + error = u'系统用户 %s 推送失败 [ %s ], 推送成功 [ %s ] 进入系统用户详情,查看失败原因' % (role.name, ','.join(failed_asset.keys()), ','.join(success_asset.keys())) return my_render('jperm/perm_role_push.html', locals(), request) diff --git a/templates/jperm/perm_rule_edit.html b/templates/jperm/perm_rule_edit.html index 334692e04..0c5f27d5b 100644 --- a/templates/jperm/perm_rule_edit.html +++ b/templates/jperm/perm_rule_edit.html @@ -67,7 +67,7 @@
资产和资产组必选一个 From 90b875adae98eeaf7e276414f5f8059650f643fb Mon Sep 17 00:00:00 2001 From: ParInshOvGotQuep Date: Wed, 30 Dec 2015 19:15:33 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=99=AE=E9=80=9A?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E9=BB=98=E8=AE=A4shell=E4=B8=BAconnect.py?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8Djailbreak?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- connect.py | 1 + install/next.py | 8 ++++---- install/zzjumpserver.sh | 13 ------------- juser/user_api.py | 2 +- 4 files changed, 6 insertions(+), 18 deletions(-) delete mode 100755 install/zzjumpserver.sh diff --git a/connect.py b/connect.py index 18c84dee7..95444cba6 100755 --- a/connect.py +++ b/connect.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # coding: utf-8 import sys diff --git a/install/next.py b/install/next.py index 62814ee67..a68eb66bc 100755 --- a/install/next.py +++ b/install/next.py @@ -81,9 +81,9 @@ class Setup(object): os.system('id %s &> /dev/null || useradd %s' % (self.admin_user, self.admin_user)) @staticmethod - def _cp_zzsh(): - os.chdir(os.path.join(jms_dir, 'install')) - shutil.copy('zzjumpserver.sh', '/etc/profile.d/') + def _ensure_sh(): + jshell = os.path.join(jms_dir, 'connect.py') + os.chmod(jshell, 0755) @staticmethod def _run_service(): @@ -97,7 +97,7 @@ class Setup(object): self._sync_db() self._input_admin() self._create_admin() - self._cp_zzsh() + self._ensure_sh() self._run_service() diff --git a/install/zzjumpserver.sh b/install/zzjumpserver.sh deleted file mode 100755 index 98598ff18..000000000 --- a/install/zzjumpserver.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -if [ "$USER" == "admin" ] || [ "$USER" == "root" ] || [ "$USER" == "" ];then - echo "" -else - python /opt/jumpserver/connect.py - if [ $USER == 'guanghongwei' ];then - echo - else - exit 3 - echo - fi -fi diff --git a/juser/user_api.py b/juser/user_api.py index 312068907..d336d6162 100644 --- a/juser/user_api.py +++ b/juser/user_api.py @@ -151,7 +151,7 @@ def server_add_user(username, password, ssh_key_pwd='', ssh_key_login_need=True) add a system user in jumpserver 在jumpserver服务器上添加一个用户 """ - bash("useradd '%s'; echo '%s'; echo '%s' | passwd --stdin '%s'" % (username, password, password, username)) + bash("useradd -s /opt/jumpserver/connect.py '%s'; echo '%s'; echo '%s' | passwd --stdin '%s'" % (username, password, password, username)) if ssh_key_login_need: gen_ssh_key(username, ssh_key_pwd) From 49f2f92a9c06816929969e4380a4b37ae297aeaf Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 31 Dec 2015 11:20:41 +0800 Subject: [PATCH 07/15] =?UTF-8?q?fix=E8=BE=93=E5=85=A5=E6=8D=A2=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install/install.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/install/install.py b/install/install.py index 0ada544b1..34f771284 100755 --- a/install/install.py +++ b/install/install.py @@ -147,7 +147,7 @@ class PreSetup(object): bash('pip install -r requirements.txt') def _input_ip(self): - ip = raw_input('\n请输入您服务器的IP地址,用户浏览器可以访问 [%s]: ' % get_ip_addr()) + ip = raw_input('\n请输入您服务器的IP地址,用户浏览器可以访问 [%s]: ' % get_ip_addr()).strip() self.ip = ip if ip else get_ip_addr() def _input_mysql(self): @@ -156,11 +156,11 @@ class PreSetup(object): if mysql != 'n': self._setup_mysql() else: - db_host = raw_input('请输入数据库服务器IP [127.0.0.1]: ') - db_port = raw_input('请输入数据库服务器端口 [3306]: ') - db_user = raw_input('请输入数据库服务器用户 [root]: ') - db_pass = raw_input('请输入数据库服务器密码: ') - db = raw_input('请输入使用的数据库 [jumpserver]: ') + db_host = raw_input('请输入数据库服务器IP [127.0.0.1]: ').strip() + db_port = raw_input('请输入数据库服务器端口 [3306]: ').strip() + db_user = raw_input('请输入数据库服务器用户 [root]: ').strip() + db_pass = raw_input('请输入数据库服务器密码: ').strip() + db = raw_input('请输入使用的数据库 [jumpserver]: ').strip() if db_host: self.db_host = db_host if db_port: self.db_port = db_port From a12e401f15322a0e6b7b04a187eefcd43dccc083 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 31 Dec 2015 12:54:15 +0800 Subject: [PATCH 08/15] fix comment --- connect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connect.py b/connect.py index 18c84dee7..4627fc461 100755 --- a/connect.py +++ b/connect.py @@ -684,7 +684,7 @@ class Nav(object): res = gen_resource({'user': self.user, 'asset': assets}, perm=self.user_perm) runner = MyRunner(res) asset_name_str = '' - print "匹配用户:\n" + print "匹配主机:\n" for inv in runner.inventory.get_hosts(pattern=pattern): asset_name_str += '%s ' % inv.name print ' %s' % inv.name From ac40098ac53c45e26ddfc174d36f65698514ef41 Mon Sep 17 00:00:00 2001 From: ParInshOvGotQuep Date: Thu, 31 Dec 2015 16:24:46 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A1=AC=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E7=9A=84shell=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- juser/user_api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/juser/user_api.py b/juser/user_api.py index d336d6162..2c16c3dc7 100644 --- a/juser/user_api.py +++ b/juser/user_api.py @@ -151,7 +151,8 @@ def server_add_user(username, password, ssh_key_pwd='', ssh_key_login_need=True) add a system user in jumpserver 在jumpserver服务器上添加一个用户 """ - bash("useradd -s /opt/jumpserver/connect.py '%s'; echo '%s'; echo '%s' | passwd --stdin '%s'" % (username, password, password, username)) + bash("useradd -s %s/connect.py '%s'; echo '%s'; echo '%s' | passwd --stdin '%s'" % + (BASE_DIR, username, password, password, username)) if ssh_key_login_need: gen_ssh_key(username, ssh_key_pwd) From b1a36bbb11327023f7a5ba3e4b7ed61b50e9b0ae Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 31 Dec 2015 16:35:17 +0800 Subject: [PATCH 10/15] fix --- install/install.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/install/install.py b/install/install.py index 34f771284..5552d3c20 100755 --- a/install/install.py +++ b/install/install.py @@ -127,8 +127,11 @@ class PreSetup(object): smtp.quit() return True - except (SMTPAuthenticationError, socket.timeout, socket.gaierror, SMTPSenderRefused, SMTPConnectError), e: + except Exception, e: color_print(e, 'red') + skip = raw_input('是否跳过(y/n) [n]? : ') + if skip == 'y': + return True return False @staticmethod From 5e86b06db863806cf2cb74416b682069694f119a Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 31 Dec 2015 16:41:52 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- connect.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/connect.py b/connect.py index cec2ea05c..69050ea67 100755 --- a/connect.py +++ b/connect.py @@ -800,7 +800,9 @@ def main(): color_print('请输入正确ID', 'red') except ServerError, e: color_print(e, 'red') - except IndexError: + except Exception, e: + color_print(e) + time.sleep(5) pass if __name__ == '__main__': From b673fec532c5f5f8046e0d5410a6918c64d147a9 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 31 Dec 2015 19:12:17 +0800 Subject: [PATCH 12/15] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/jperm/perm_role_detail.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/templates/jperm/perm_role_detail.html b/templates/jperm/perm_role_detail.html index 6aa91d0ff..aefbde307 100644 --- a/templates/jperm/perm_role_detail.html +++ b/templates/jperm/perm_role_detail.html @@ -204,7 +204,7 @@ {% if info.success %} {{ info.success | yesno:"成功,失败,未知" }} {% else %} - {{ info.success | yesno:"成功,失败,未知" }} + {{ info.success | yesno:"成功,失败,未知" }} {% endif %} @@ -321,7 +321,13 @@ }); var url = '/jperm/role/push/?id={{ role.id }}&asset_id=' + check_array.join(','); $(this).attr('href', url) - }) + }); + + $('.push_failed').click(function() { + var fail_reason = $(this).attr('title'); + layer.alert(fail_reason) + }); + }) From ea973bbb525ef1a42cd408c4c30e0aac90d3cc98 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 31 Dec 2015 22:37:01 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=A4=E6=8D=A2?= =?UTF-8?q?=E6=9C=BA=E5=B0=8Fbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- connect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connect.py b/connect.py index 69050ea67..37c9a126c 100755 --- a/connect.py +++ b/connect.py @@ -291,7 +291,7 @@ class Tty(object): # 发起ssh连接请求 Make a ssh connection ssh = paramiko.SSHClient() - ssh.load_system_host_keys() + #ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: role_key = connect_info.get('role_key') From 7bef517518aaeef76f955d64cb38a9ed7fc8e48a Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 1 Jan 2016 22:38:50 +0800 Subject: [PATCH 14/15] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jumpserver/views.py | 4 ++++ run_websocket.py | 10 ++++++++- templates/jasset/asset_list.html | 15 +++++++++++-- templates/jlog/web_terminal.html | 31 +++++++++++++++++++++++++-- templates/jperm/perm_role_detail.html | 5 ++++- 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/jumpserver/views.py b/jumpserver/views.py index bd00aed99..766ae021f 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -352,6 +352,10 @@ def exec_cmd(request): def web_terminal(request): asset_id = request.GET.get('id') 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) return render_to_response('jlog/web_terminal.html', locals()) diff --git a/run_websocket.py b/run_websocket.py index 757923a0a..4a1a185dc 100755 --- a/run_websocket.py +++ b/run_websocket.py @@ -333,7 +333,13 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler): data = json.loads(message) if not data: 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 if str(data['data']) in ['\r', '\n', '\r\n']: if self.term.vim_flag: @@ -350,6 +356,8 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler): self.term.data = '' self.term.input_mode = False self.channel.send(data['data']) + else: + pass def on_close(self): logger.debug('Websocket: Close request') diff --git a/templates/jasset/asset_list.html b/templates/jasset/asset_list.html index 56d64ce9b..1da808c3c 100644 --- a/templates/jasset/asset_list.html +++ b/templates/jasset/asset_list.html @@ -233,6 +233,7 @@ layer.alert('没有授权系统用户') } else if (dataArray.length == 1 && data != 'error' && navigator.platform == 'Win32'){ + /* var title = 'Jumpserver Web Terminal' + ' '+ hostname +''; layer.open({ type: 2, @@ -242,8 +243,10 @@ area: ['628px', '420px'], content: new_url+data }); + */ + window.open(new_url+data, '', 'width=628px, height=420px') } else if (dataArray.length == 1 && data != 'error'){ - layer.open({ + /*layer.open({ type: 2, title: title, maxmin: true, @@ -251,6 +254,9 @@ area: ['628px', '452px'], content: new_url+data }); + */ + window.open(new_url+data, '', 'width=628px, height=440px') + } else { aUrl = ''; @@ -276,6 +282,7 @@ var hostname = $(a).attr('value'); var title = 'Jumpserver Web Terminal - ' + ' '+ hostname +''; if (navigator.platform == 'Win32'){ + /* layer.open({ type: 2, title: title, @@ -284,8 +291,11 @@ shade: false, content: new_url }); + */ + window.open(new_url, '', 'height=628px, width=420px') } else { + /* layer.open({ type: 2, title: title, @@ -294,6 +304,8 @@ shade: false, content: new_url }); + */ + window.open(new_url, '', 'height=628px, width=452px') } return false @@ -310,7 +322,6 @@ shade: false, content: new_url }); - console.log(new_url); return false } diff --git a/templates/jlog/web_terminal.html b/templates/jlog/web_terminal.html index 514fe6850..e5b864a79 100644 --- a/templates/jlog/web_terminal.html +++ b/templates/jlog/web_terminal.html @@ -2,7 +2,7 @@ - Jumpserver web terminal + Jumpserver Web Terminal: {{ hostname }}