From a88d8ca410c398f5c9c498c00af394a00dde11ef Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 26 Feb 2016 23:51:21 +0800 Subject: [PATCH] =?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]),