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]),