From a88d8ca410c398f5c9c498c00af394a00dde11ef Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 26 Feb 2016 23:51:21 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix(upload,=20download,=20exec,=20gn)=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=BC=A0=E4=B8=8B=E8=BD=BD=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D=EF=BC=8C=E4=B8=8A=E4=BC=A0=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E5=B1=82=E6=AC=A1=EF=BC=8C=E6=89=A7=E8=A1=8C=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E5=9B=9E=E8=BD=A6=E6=8A=A5=E9=94=99=EF=BC=8Cg+=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8id=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 上传下载文件名 改为 时间+随机4位字母数字 2. 命令回车判断,为空返回 3. g+1判断,不过不存在该组,则返回 close #52 close #93 ref https://github.com/jumpserver/jumpserver/issues/53 ref https://github.com/jumpserver/jumpserver/issues/93 --- connect.py | 13 +++++++++++-- jumpserver/api.py | 3 ++- jumpserver/views.py | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/connect.py b/connect.py index 531c608a9..c742e6293 100755 --- a/connect.py +++ b/connect.py @@ -523,7 +523,13 @@ class Nav(object): if gid_pattern.match(str_r): gid = int(str_r.lstrip('g')) # 获取资产组包含的资产 - user_asset_search = get_object(AssetGroup, id=gid).asset_set.all() + asset_group = get_object(AssetGroup, id=gid) + if asset_group: + user_asset_search = asset_group.asset_set.all() + else: + color_print('没有该资产组或没有权限') + return + else: # 匹配 ip, hostname, 备注 for asset in user_asset_all: @@ -609,6 +615,9 @@ class Nav(object): command = raw_input("\033[1;32mCmds>:\033[0m ").strip() if command == 'q': break + elif not command: + color_print('命令不能为空...') + continue runner.run('shell', command, pattern=pattern) ExecLog(host=asset_name_str, user=self.user.username, cmd=command, remote_ip=remote_ip, result=runner.results).save() @@ -661,7 +670,7 @@ class Nav(object): runner = MyRunner(res) runner.run('copy', module_args='src=%s dest=%s directory_mode' - % (tmp_dir, tmp_dir), pattern=pattern) + % (tmp_dir, '/tmp'), pattern=pattern) ret = runner.results FileLog(user=self.user.name, host=asset_name_str, filename=filename_str, remote_ip=remote_ip, type='upload', result=ret).save() diff --git a/jumpserver/api.py b/jumpserver/api.py index 691aafb11..a4840f206 100644 --- a/jumpserver/api.py +++ b/jumpserver/api.py @@ -484,7 +484,8 @@ def my_render(template, data, request): def get_tmp_dir(): - dir_name = os.path.join('/tmp', uuid.uuid4().hex) + seed = uuid.uuid4().hex[:4] + dir_name = os.path.join('/tmp', '%s-%s' % (datetime.datetime.now().strftime('%Y%m%d-%H%M%S'), seed)) mkdir(dir_name, mode=0777) return dir_name diff --git a/jumpserver/views.py b/jumpserver/views.py index 7aa51dcac..5768c656e 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -286,7 +286,7 @@ def upload(request): res = gen_resource({'user': user, 'asset': asset_select}) runner = MyRunner(res) runner.run('copy', module_args='src=%s dest=%s directory_mode' - % (upload_dir, upload_dir), pattern='*') + % (upload_dir, '/tmp'), pattern='*') ret = runner.results logger.debug(ret) FileLog(user=request.user.username, host=' '.join([asset.hostname for asset in asset_select]), From a8eb9f3e79f85d9e3f063762e7019a4d2dbf72eb Mon Sep 17 00:00:00 2001 From: ibuler Date: Sat, 27 Feb 2016 00:19:04 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix(jlog,=20websocket=20url)=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dws=E4=BD=BF=E7=94=A8=20ws=E5=8D=8F=E8=AE=AE=E8=BF=98?= =?UTF-8?q?=E6=98=AFwss=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 不再需要浏览器判断什么协议,需要在jumpserver.conf注明 ref #63 --- connect.py | 1 - jlog/views.py | 6 +++--- jumpserver.conf | 6 ++---- jumpserver/settings.py | 2 +- jumpserver/views.py | 3 +-- templates/jlog/log_online.html | 9 ++------- templates/jlog/web_terminal.html | 7 +------ 7 files changed, 10 insertions(+), 24 deletions(-) diff --git a/connect.py b/connect.py index c742e6293..603f57f60 100755 --- a/connect.py +++ b/connect.py @@ -824,7 +824,6 @@ def main(): except IndexError, e: color_print(e) time.sleep(5) - pass if __name__ == '__main__': main() diff --git a/jlog/views.py b/jlog/views.py index 61ab19ddc..0d49269b6 100644 --- a/jlog/views.py +++ b/jlog/views.py @@ -9,7 +9,7 @@ from django.http import HttpResponseNotFound from jlog.log_api import renderTemplate from jlog.models import Log, ExecLog, FileLog -from jumpserver.settings import WEB_SOCKET_HOST +from jumpserver.settings import WEB_SOCKET_URL @require_role('admin') @@ -66,8 +66,8 @@ def log_list(request, offset): contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) - web_monitor_uri = '%s/monitor' % WEB_SOCKET_HOST - web_kill_uri = '/kill' + web_monitor_url = '%s/monitor' % WEB_SOCKET_URL + web_kill_url = '/kill' session_id = request.session.session_key return render_to_response('jlog/log_%s.html' % offset, locals(), context_instance=RequestContext(request)) diff --git a/jumpserver.conf b/jumpserver.conf index f184a246f..2e1668a6d 100644 --- a/jumpserver.conf +++ b/jumpserver.conf @@ -1,5 +1,6 @@ [base] url = http://192.168.244.129 +websocket_url = ws://192.168.244.129 key = 88aaaf7ffe3c6c04 log = debug @@ -10,14 +11,11 @@ user = jumpserver password = mysql234 database = jumpserver -[websocket] -web_socket_host = 192.168.244.129:3000 - [mail] mail_enable = 1 email_host = smtp.qq.com email_port = 25 email_host_user = xxxxxxxx@qq.com email_host_password = xxxxxx -email_use_tls = False +email_use_tls = True diff --git a/jumpserver/settings.py b/jumpserver/settings.py index d1c8a8f40..a8c0d4dc3 100644 --- a/jumpserver/settings.py +++ b/jumpserver/settings.py @@ -41,7 +41,7 @@ SSH_KEY_DIR = os.path.join(BASE_DIR, 'keys/role_keys') KEY = config.get('base', 'key') URL = config.get('base', 'url') LOG_LEVEL = config.get('base', 'log') -WEB_SOCKET_HOST = config.get('websocket', 'web_socket_host') +WEB_SOCKET_URL = config.get('base', 'websocket_url') # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ diff --git a/jumpserver/views.py b/jumpserver/views.py index 5768c656e..ab97a66e8 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -356,8 +356,7 @@ def web_terminal(request): if asset: print asset hostname = asset.hostname - # web_terminal_uri = '%s/ws/terminal?id=%s&role=%s' % (WEB_SOCKET_HOST, asset_id, role_name) - web_terminal_uri = '/ws/terminal?id=%s&role=%s' % (asset_id, role_name) + web_terminal_url = '%s/ws/terminal?id=%s&role=%s' % (WEB_SOCKET_URL, asset_id, role_name) return render_to_response('jlog/web_terminal.html', locals()) diff --git a/templates/jlog/log_online.html b/templates/jlog/log_online.html index 9d52ecfe8..c17c92129 100644 --- a/templates/jlog/log_online.html +++ b/templates/jlog/log_online.html @@ -136,13 +136,8 @@ {# })#} {# });#} function init(obj){ - var protocol = "ws://"; - if (window.location.protocol == 'https:') { - protocol = 'wss://'; - } - var file_path = obj.attr('file_path'); - var wsUri = protocol + '{{ web_monitor_uri }}'; + var wsUri = '{{ web_monitor_url }}'; var socket = new WebSocket(wsUri + '?file_path=' + file_path); var term = new Terminal({ @@ -211,7 +206,7 @@ function cut(num, login_type){ console.log(login_type); if (login_type=='web'){ - var g_url = '{{ web_kill_uri }}' + '?id=' + num; + var g_url = '{{ web_kill_url }}' + '?id=' + num; } else { var g_url = "{% url 'log_kill' %}?id=" + num; } diff --git a/templates/jlog/web_terminal.html b/templates/jlog/web_terminal.html index 547002f19..3f4683399 100644 --- a/templates/jlog/web_terminal.html +++ b/templates/jlog/web_terminal.html @@ -43,12 +43,7 @@ } WSSHClient.prototype.connect = function(options) { - var protocol = "ws://"; - if (window.location.protocol == 'https:') { - protocol = 'wss://'; - } - - var endpoint = protocol + document.URL.match(RegExp('//(.*?)/'))[1] + '{{ web_terminal_uri }}'; + var endpoint = '{{ web_terminal_url }}'; if (window.WebSocket) { this._connection = new WebSocket(endpoint); From 725405e4fd5dd7983f82bb3a6a8079e71f2aa597 Mon Sep 17 00:00:00 2001 From: ibuler Date: Sun, 28 Feb 2016 16:41:44 +0800 Subject: [PATCH 3/4] =?UTF-8?q?change(install)=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=EF=BC=8C=E6=9B=B4=E6=94=B9=E5=8F=98=E5=8C=96?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6=E5=90=8D=20run=5Fserver.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit websocket -> websocket_url --- install/install.py | 4 ++-- install/next.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/install/install.py b/install/install.py index 007c10503..d7c25660a 100755 --- a/install/install.py +++ b/install/install.py @@ -97,13 +97,13 @@ class PreSetup(object): conf = ConfigParser.ConfigParser() conf.read(conf_file) conf.set('base', 'url', 'http://%s' % self.ip) + conf.set('base', 'websocket_url', 'ws://%s' % self.ip) conf.set('base', 'key', self.key) conf.set('db', 'host', self.db_host) conf.set('db', 'port', self.db_port) conf.set('db', 'user', self.db_user) conf.set('db', 'password', self.db_pass) conf.set('db', 'database', self.db) - conf.set('websocket', 'web_socket_host', '%s:3000' % self.ip) conf.set('mail', 'email_host', self.mail_host) conf.set('mail', 'email_port', self.mail_port) conf.set('mail', 'email_host_user', self.mail_addr) @@ -237,7 +237,7 @@ class PreSetup(object): print def start(self): - color_print('请务必先查看wiki https://github.com/ibuler/jumpserver/wiki/Quickinstall') + color_print('请务必先查看wiki https://github.com/jumpserver/jumpserver/wiki') time.sleep(3) self._rpm_repo() self._depend_rpm() diff --git a/install/next.py b/install/next.py index 49d62db25..e11d4151b 100755 --- a/install/next.py +++ b/install/next.py @@ -86,7 +86,7 @@ class Setup(object): os.chmod('init.sh', 0755) os.chmod('connect.py', 0755) os.chmod('manage.py', 0755) - os.chmod('run_websocket.py', 0755) + os.chmod('run_server.py', 0755) os.chmod('service.sh', 0755) os.chmod('logs', 0777) os.chmod('keys', 0777) @@ -95,7 +95,7 @@ class Setup(object): def _run_service(): os.system('sh %s start' % os.path.join(jms_dir, 'service.sh')) print - color_print('安装成功,请访问web, 祝你使用愉快。\n请访问 https://github.com/jumpserver/jumpserver 查看文档', 'green') + color_print('安装成功,请访问web, 祝你使用愉快。\n请访问 https://github.com/jumpserver/jumpserver/wiki 查看文档', 'green') def start(self): print "开始安装Jumpserver, 要求环境为 CentOS 6.5 x86_64" From cba53bba553d1e0585421c2e9ae89c43883361aa Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 29 Feb 2016 10:25:59 +0800 Subject: [PATCH 4/4] =?UTF-8?q?modify(jumpserver.conf)=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9jumpserver.conf=E9=BB=98=E8=AE=A4=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit django和tornado统一入口后,配置默认启动端口80 websocket和web都使用该端口 --- jumpserver.conf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jumpserver.conf b/jumpserver.conf index f1a166c09..a24203220 100644 --- a/jumpserver.conf +++ b/jumpserver.conf @@ -1,9 +1,9 @@ [base] url = http://192.168.244.129 websocket_url = ws://192.168.244.129 -key = 88aaaf7ffe3c6c04 -ip = 127.0.0.1 -port = 8080 +key = i6k2zeu8x6mncl76 +ip = 0.0.0.0 +port = 80 log = debug [db] @@ -15,9 +15,9 @@ database = jumpserver [mail] mail_enable = 1 -email_host = smtp.qq.com +email_host = smtp.exmail.qq.com email_port = 25 -email_host_user = xxxxxxxx@qq.com -email_host_password = xxxxxx +email_host_user = noreply@jumpserver.org +email_host_password = xxxxxxxxxx email_use_tls = True