[Update] 支持收集资产上的用户

pull/3243/head
ibuler 2019-09-19 14:48:25 +08:00
parent 5464c884db
commit b7021b5ecb
13 changed files with 236 additions and 168 deletions

View File

@ -36,6 +36,7 @@ class AssetViewSet(OrgBulkModelViewSet):
serializer_class = serializers.AssetSerializer
permission_classes = (IsOrgAdminOrAppUser,)
extra_filter_backends = [AssetByNodeFilterBackend, LabelFilterBackend]
custom_filter_fields = ['admin_user_id']
def set_assets_node(self, assets):
if not isinstance(assets, list):

View File

@ -6,6 +6,7 @@ from assets.models import GatheredUser
from common.permissions import IsOrgAdmin
from ..serializers import GatheredUserSerializer
from ..filters import AssetRelatedByNodeFilterBackend
__all__ = ['GatheredUserViewSet']
@ -15,6 +16,7 @@ class GatheredUserViewSet(OrgModelViewSet):
queryset = GatheredUser.objects.all()
serializer_class = GatheredUserSerializer
permission_classes = [IsOrgAdmin]
extra_filter_backends = [AssetRelatedByNodeFilterBackend]
filter_fields = ['asset', 'username', 'present']
search_fields = ['username', 'asset__ip', 'asset__hostname']

View File

@ -12,63 +12,54 @@ from .models import Node, Label
class AssetByNodeFilterBackend(filters.BaseFilterBackend):
fields = ['node', 'all']
# def filter_node(self, queryset):
# node_id = self.request.query_params.get("node_id")
# if not node_id:
# return queryset
#
# node = get_object_or_404(Node, id=node_id)
# show_current_asset = self.request.query_params.get("show_current_asset") in ('1', 'true')
#
# # 当前节点是顶层节点, 并且仅显示直接资产
# if node.is_org_root() and show_current_asset:
# queryset = queryset.filter(
# Q(nodes=node_id) | Q(nodes__isnull=True)
# ).distinct()
# # 当前节点是顶层节点,显示所有资产
# elif node.is_org_root() and not show_current_asset:
# return queryset
# # 当前节点不是鼎城节点,只显示直接资产
# elif not node.is_org_root() and show_current_asset:
# queryset = queryset.filter(nodes=node)
# else:
# children = node.get_all_children(with_self=True)
# queryset = queryset.filter(nodes__in=children).distinct()
# return queryset
def get_schema_fields(self, view):
return [
coreapi.Field(
name=field, location='query', required=False,
type='string', example='', description=''
type='string', example='', description='', schema=None,
)
for field in self.fields
]
def filter_queryset(self, request, queryset, view):
node_id = dict_get_any(request.query_params, ['node', 'node_id'])
if not node_id:
return queryset
@staticmethod
def is_query_all(request):
query_all_arg = request.query_params.get('all')
show_current_asset_arg = request.query_params.get('show_current_asset')
query_all = query_all_arg == '1'
if show_current_asset_arg is not None:
query_all = show_current_asset_arg != '1'
return query_all
@staticmethod
def get_query_node(request):
node_id = dict_get_any(request.query_params, ['node', 'node_id'])
if not node_id:
return None, False
if is_uuid(node_id):
node = get_object_or_none(Node, id=node_id)
else:
node = get_object_or_none(Node, key=node_id)
return node, True
if not node:
@staticmethod
def perform_query(pattern, queryset):
return queryset.filter(nodes__key__regex=pattern)
def filter_queryset(self, request, queryset, view):
node, has_query_arg = self.get_query_node(request)
if not has_query_arg:
return queryset
if node is None:
return queryset.none()
query_all = self.is_query_all(request)
if query_all:
pattern = node.get_all_children_pattern(with_self=True)
else:
pattern = node.get_children_key_pattern(with_self=True)
return queryset.filter(nodes__key__regex=pattern)
return self.perform_query(pattern, queryset)
class LabelFilterBackend(filters.BaseFilterBackend):
@ -117,3 +108,8 @@ class LabelFilterBackend(filters.BaseFilterBackend):
return queryset
class AssetRelatedByNodeFilterBackend(AssetByNodeFilterBackend):
@staticmethod
def perform_query(pattern, queryset):
return queryset.filter(asset__nodes__key__regex=pattern).distinct()

View File

@ -18,10 +18,10 @@ class Migration(migrations.Migration):
('org_id', models.CharField(blank=True, db_index=True, default='', max_length=36, verbose_name='Organization')),
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
('username', models.CharField(blank=True, db_index=True, max_length=32, verbose_name='Username')),
('present', models.BooleanField(default=True)),
('present', models.BooleanField(default=True, verbose_name='Present')),
('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date created')),
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
('asset', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assets.Asset')),
('asset', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assets.Asset', verbose_name='Asset')),
],
options={'ordering': ['asset'], 'verbose_name': 'GatherUser'},
),

View File

@ -11,10 +11,10 @@ __all__ = ['GatheredUser']
class GatheredUser(OrgModelMixin):
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
asset = models.ForeignKey('assets.Asset', on_delete=models.CASCADE)
asset = models.ForeignKey('assets.Asset', on_delete=models.CASCADE, verbose_name=_("Asset"))
username = models.CharField(max_length=32, blank=True, db_index=True,
verbose_name=_('Username'))
present = models.BooleanField(default=True)
present = models.BooleanField(default=True, verbose_name=_("Present"))
date_created = models.DateTimeField(auto_now_add=True,
verbose_name=_("Date created"))
date_updated = models.DateTimeField(auto_now=True,

View File

@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
#
from ..models import GatheredUser
from django.utils.translation import ugettext_lazy as _
from orgs.mixins.serializers import OrgResourceModelSerializerMixin
from ..models import GatheredUser
class GatheredUserSerializer(OrgResourceModelSerializerMixin):
@ -14,3 +15,7 @@ class GatheredUserSerializer(OrgResourceModelSerializerMixin):
'present', 'date_created', 'date_updated'
]
read_only_fields = fields
labels = {
'hostname': _("Hostname"),
'ip': "IP"
}

View File

@ -116,8 +116,9 @@ def gather_asset_users(assets, task_name=None):
for k, value in hosts_category.items():
if not value['hosts']:
continue
_task_name = '{}: {}'.format(task_name, k)
task, created = update_or_create_ansible_task(
task_name=task_name, hosts=value['hosts'], tasks=value['tasks'],
task_name=_task_name, hosts=value['hosts'], tasks=value['tasks'],
pattern='all', options=const.TASK_OPTIONS,
run_as_admin=True, created_by=value['hosts'][0].org_id,
)

View File

@ -70,7 +70,6 @@ class IDSpmFilter(filters.BaseFilterBackend):
class CustomFilter(filters.BaseFilterBackend):
custom_filter_fields = [] # ["node", "asset"]
def get_schema_fields(self, view):
fields = []
@ -79,7 +78,10 @@ class CustomFilter(filters.BaseFilterBackend):
type='string', example='',
description=''
)
for field in self.custom_filter_fields:
if not hasattr(view, 'custom_filter_fields'):
return []
for field in view.custom_filter_fields:
if isinstance(field, str):
defaults['name'] = field
elif isinstance(field, dict):

Binary file not shown.

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Jumpserver 0.3.3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-09-18 12:53+0800\n"
"POT-Creation-Date: 2019-09-19 14:43+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: ibuler <ibuler@qq.com>\n"
"Language-Team: Jumpserver team<ibuler@qq.com>\n"
@ -77,8 +77,8 @@ msgstr "运行参数"
#: applications/templates/applications/user_remote_app_list.html:18
#: assets/forms/domain.py:15 assets/forms/label.py:13
#: assets/models/asset.py:295 assets/models/authbook.py:24
#: assets/serializers/admin_user.py:32 assets/serializers/asset_user.py:82
#: assets/serializers/system_user.py:31
#: assets/models/gathered_user.py:14 assets/serializers/admin_user.py:32
#: assets/serializers/asset_user.py:82 assets/serializers/system_user.py:31
#: assets/templates/assets/admin_user_list.html:46
#: assets/templates/assets/domain_detail.html:60
#: assets/templates/assets/domain_list.html:26
@ -96,15 +96,13 @@ msgstr "运行参数"
#: terminal/templates/terminal/session_list.html:28
#: terminal/templates/terminal/session_list.html:72
#: xpack/plugins/change_auth_plan/forms.py:121
#: xpack/plugins/change_auth_plan/models.py:412
#: xpack/plugins/change_auth_plan/models.py:409
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_create_update.html:46
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_execution_list.html:54
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_execution_subtask_list.html:13
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_list.html:14
#: xpack/plugins/cloud/models.py:310
#: xpack/plugins/cloud/models.py:307
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_instance.html:63
#: xpack/plugins/gathered_user/forms.py:13
#: xpack/plugins/gathered_user/forms.py:15
#: xpack/plugins/orgs/templates/orgs/org_list.html:16
#: xpack/plugins/vault/forms.py:13 xpack/plugins/vault/forms.py:15
msgid "Asset"
@ -162,6 +160,8 @@ msgstr "资产"
#: xpack/plugins/cloud/templates/cloud/account_list.html:12
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_detail.html:56
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_list.html:12
#: xpack/plugins/gathered_user/models.py:28
#: xpack/plugins/gathered_user/templates/gathered_user/task_list.html:16
#: xpack/plugins/orgs/templates/orgs/org_detail.html:52
#: xpack/plugins/orgs/templates/orgs/org_list.html:12
msgid "Name"
@ -202,6 +202,7 @@ msgstr "参数"
#: xpack/plugins/change_auth_plan/models.py:105
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_detail.html:113
#: xpack/plugins/cloud/models.py:80 xpack/plugins/cloud/models.py:179
#: xpack/plugins/gathered_user/models.py:46
msgid "Created by"
msgstr "创建者"
@ -268,6 +269,7 @@ msgstr "创建日期"
#: xpack/plugins/cloud/templates/cloud/account_list.html:15
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_detail.html:105
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_list.html:18
#: xpack/plugins/gathered_user/models.py:42
#: xpack/plugins/orgs/templates/orgs/org_detail.html:64
#: xpack/plugins/orgs/templates/orgs/org_list.html:22
msgid "Comment"
@ -316,7 +318,7 @@ msgstr "远程应用"
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_create_update.html:71
#: xpack/plugins/cloud/templates/cloud/account_create_update.html:33
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_create_update.html:53
#: xpack/plugins/gathered_user/templates/gathered_user/vault_create.html:45
#: xpack/plugins/gathered_user/templates/gathered_user/task_create_update.html:44
#: xpack/plugins/interface/templates/interface/interface.html:72
#: xpack/plugins/vault/templates/vault/vault_create.html:45
msgid "Reset"
@ -355,7 +357,6 @@ msgstr "重置"
#: users/templates/users/user_profile_update.html:68
#: users/templates/users/user_pubkey_update.html:81
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_create_update.html:72
#: xpack/plugins/gathered_user/templates/gathered_user/vault_create.html:46
#: xpack/plugins/interface/templates/interface/interface.html:74
#: xpack/plugins/vault/templates/vault/vault_create.html:46
msgid "Submit"
@ -429,6 +430,7 @@ msgstr "详情"
#: xpack/plugins/cloud/templates/cloud/account_list.html:40
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_detail.html:29
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_list.html:57
#: xpack/plugins/gathered_user/templates/gathered_user/task_list.html:51
#: xpack/plugins/orgs/templates/orgs/org_detail.html:25
#: xpack/plugins/orgs/templates/orgs/org_list.html:88
msgid "Update"
@ -470,6 +472,7 @@ msgstr "更新"
#: xpack/plugins/cloud/templates/cloud/account_list.html:42
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_detail.html:33
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_list.html:58
#: xpack/plugins/gathered_user/templates/gathered_user/task_list.html:52
#: xpack/plugins/orgs/templates/orgs/org_detail.html:29
#: xpack/plugins/orgs/templates/orgs/org_list.html:90
msgid "Delete"
@ -528,6 +531,7 @@ msgstr "创建远程应用"
#: xpack/plugins/cloud/templates/cloud/account_list.html:16
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_history.html:72
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_list.html:19
#: xpack/plugins/gathered_user/templates/gathered_user/task_list.html:20
#: xpack/plugins/orgs/templates/orgs/org_list.html:23
msgid "Action"
msgstr "动作"
@ -560,11 +564,6 @@ msgstr "远程应用详情"
msgid "My RemoteApp"
msgstr "我的远程应用"
#: assets/api/asset.py:40
#, python-format
msgid "%(hostname)s was %(action)s successfully"
msgstr "%(hostname)s %(action)s成功"
#: assets/api/node.py:58
msgid "You can't update the root node name"
msgstr "不能修改根节点名称"
@ -590,6 +589,8 @@ msgstr "端口"
#: assets/templates/assets/system_user_assets.html:83
#: perms/models/asset_permission.py:79
#: xpack/plugins/change_auth_plan/models.py:71
#: xpack/plugins/gathered_user/models.py:31
#: xpack/plugins/gathered_user/templates/gathered_user/task_list.html:17
msgid "Nodes"
msgstr "节点"
@ -619,7 +620,7 @@ msgid "Domain"
msgstr "网域"
#: assets/forms/asset.py:68 assets/forms/asset.py:101 assets/forms/asset.py:114
#: assets/forms/asset.py:149 assets/models/node.py:393
#: assets/forms/asset.py:149 assets/models/node.py:401
#: assets/templates/assets/asset_create.html:42
#: perms/forms/asset_permission.py:82 perms/forms/asset_permission.py:89
#: perms/templates/perms/asset_permission_list.html:53
@ -694,7 +695,7 @@ msgstr "SSH网关支持代理SSH,RDP和VNC"
#: users/templates/users/user_profile.html:47
#: xpack/plugins/change_auth_plan/forms.py:106
#: xpack/plugins/change_auth_plan/models.py:62
#: xpack/plugins/change_auth_plan/models.py:408
#: xpack/plugins/change_auth_plan/models.py:405
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_detail.html:65
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_execution_list.html:53
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_execution_subtask_list.html:12
@ -722,7 +723,7 @@ msgstr "密码或密钥密码"
#: users/templates/users/user_pubkey_update.html:41
#: users/templates/users/user_update.html:20
#: xpack/plugins/change_auth_plan/models.py:92
#: xpack/plugins/change_auth_plan/models.py:263
#: xpack/plugins/change_auth_plan/models.py:260
msgid "Password"
msgstr "密码"
@ -785,6 +786,7 @@ msgid "IP"
msgstr "IP"
#: assets/models/asset.py:136 assets/serializers/asset_user.py:27
#: assets/serializers/gathered_user.py:19
#: assets/templates/assets/_asset_list_modal.html:46
#: assets/templates/assets/_asset_user_auth_update_modal.html:9
#: assets/templates/assets/_asset_user_auth_view_modal.html:15
@ -914,12 +916,12 @@ msgid "AuthBook"
msgstr ""
#: assets/models/base.py:31 xpack/plugins/change_auth_plan/models.py:96
#: xpack/plugins/change_auth_plan/models.py:270
#: xpack/plugins/change_auth_plan/models.py:267
msgid "SSH private key"
msgstr "ssh密钥"
#: assets/models/base.py:32 xpack/plugins/change_auth_plan/models.py:99
#: xpack/plugins/change_auth_plan/models.py:266
#: xpack/plugins/change_auth_plan/models.py:263
msgid "SSH public key"
msgstr "ssh公钥"
@ -1054,6 +1056,11 @@ msgstr "命令过滤规则"
msgid "Gateway"
msgstr "网关"
#: assets/models/gathered_user.py:17
#: xpack/plugins/gathered_user/templates/gathered_user/gathered_user_list.html:75
msgid "Present"
msgstr "存在"
#: assets/models/gathered_user.py:32
msgid "GatherUser"
msgstr "收集用户"
@ -1096,7 +1103,7 @@ msgstr "默认资产组"
msgid "User"
msgstr "用户"
#: assets/models/label.py:19 assets/models/node.py:384
#: assets/models/label.py:19 assets/models/node.py:392
#: assets/templates/assets/label_list.html:15 settings/models.py:30
msgid "Value"
msgstr "值"
@ -1105,19 +1112,19 @@ msgstr "值"
msgid "Category"
msgstr "分类"
#: assets/models/node.py:222
#: assets/models/node.py:230
msgid "New node"
msgstr "新节点"
#: assets/models/node.py:308
#: assets/models/node.py:316
msgid "ungrouped"
msgstr "未分组"
#: assets/models/node.py:310
#: assets/models/node.py:318
msgid "empty"
msgstr "空"
#: assets/models/node.py:383
#: assets/models/node.py:391
msgid "Key"
msgstr "键"
@ -1291,7 +1298,7 @@ msgstr "测试资产可连接性: {}"
#: assets/tasks/asset_user_connectivity.py:27
#: assets/tasks/push_system_user.py:130
#: xpack/plugins/change_auth_plan/models.py:521
#: xpack/plugins/change_auth_plan/models.py:518
msgid "The asset {} system platform {} does not support run Ansible tasks"
msgstr "资产 {} 系统平台 {} 不支持运行 Ansible 任务"
@ -1311,7 +1318,7 @@ msgstr "更新资产硬件信息"
msgid "Update asset hardware info: {}"
msgstr "更新资产硬件信息: {}"
#: assets/tasks/gather_asset_users.py:95
#: assets/tasks/gather_asset_users.py:96
msgid "Gather assets users"
msgstr "收集资产上的用户"
@ -1536,6 +1543,7 @@ msgstr "重命名成功"
#: perms/templates/perms/remote_app_permission_create_update.html:39
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_create_update.html:43
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_create_update.html:27
#: xpack/plugins/gathered_user/templates/gathered_user/task_create_update.html:27
msgid "Basic"
msgstr "基本"
@ -1558,6 +1566,7 @@ msgstr "自动生成密钥"
#: terminal/templates/terminal/terminal_update.html:40
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_create_update.html:67
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_create_update.html:48
#: xpack/plugins/gathered_user/templates/gathered_user/task_create_update.html:39
msgid "Other"
msgstr "其它"
@ -1609,12 +1618,13 @@ msgstr "替换资产的管理员"
#: perms/templates/perms/asset_permission_asset.html:103
#: xpack/plugins/change_auth_plan/forms.py:116
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_asset_list.html:109
#: xpack/plugins/gathered_user/forms.py:36
msgid "Select nodes"
msgstr "选择节点"
#: assets/templates/assets/admin_user_detail.html:100
#: assets/templates/assets/asset_detail.html:204
#: assets/templates/assets/asset_list.html:418
#: assets/templates/assets/asset_list.html:422
#: assets/templates/assets/cmd_filter_detail.html:106
#: assets/templates/assets/system_user_assets.html:97
#: assets/templates/assets/system_user_detail.html:182
@ -1631,6 +1641,7 @@ msgstr "选择节点"
#: users/templates/users/user_list.html:256
#: xpack/plugins/cloud/templates/cloud/account_create_update.html:34
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_create_update.html:54
#: xpack/plugins/gathered_user/templates/gathered_user/task_create_update.html:45
#: xpack/plugins/interface/templates/interface/interface.html:103
#: xpack/plugins/orgs/templates/orgs/org_create_update.html:33
msgid "Confirm"
@ -1678,8 +1689,8 @@ msgstr "创建管理用户"
#: assets/templates/assets/admin_user_list.html:162
#: assets/templates/assets/admin_user_list.html:193
#: assets/templates/assets/asset_list.html:299
#: assets/templates/assets/asset_list.html:336
#: assets/templates/assets/asset_list.html:303
#: assets/templates/assets/asset_list.html:340
#: assets/templates/assets/system_user_list.html:192
#: assets/templates/assets/system_user_list.html:223
#: users/templates/users/user_group_list.html:164
@ -1797,31 +1808,31 @@ msgstr "禁用所选"
msgid "Active selected"
msgstr "激活所选"
#: assets/templates/assets/asset_list.html:189
#: assets/templates/assets/asset_list.html:193
msgid "Add assets to node"
msgstr "添加资产到节点"
#: assets/templates/assets/asset_list.html:190
#: assets/templates/assets/asset_list.html:194
msgid "Move assets to node"
msgstr "移动资产到节点"
#: assets/templates/assets/asset_list.html:192
#: assets/templates/assets/asset_list.html:196
msgid "Refresh node hardware info"
msgstr "更新节点资产硬件信息"
#: assets/templates/assets/asset_list.html:193
#: assets/templates/assets/asset_list.html:197
msgid "Test node connective"
msgstr "测试节点资产可连接性"
#: assets/templates/assets/asset_list.html:195
#: assets/templates/assets/asset_list.html:199
msgid "Display only current node assets"
msgstr "仅显示当前节点资产"
#: assets/templates/assets/asset_list.html:196
#: assets/templates/assets/asset_list.html:200
msgid "Displays all child node assets"
msgstr "显示所有子节点资产"
#: assets/templates/assets/asset_list.html:412
#: assets/templates/assets/asset_list.html:416
#: assets/templates/assets/system_user_list.html:133
#: users/templates/users/user_detail.html:388
#: users/templates/users/user_detail.html:414
@ -1832,11 +1843,11 @@ msgstr "显示所有子节点资产"
msgid "Are you sure?"
msgstr "你确认吗?"
#: assets/templates/assets/asset_list.html:413
#: assets/templates/assets/asset_list.html:417
msgid "This will delete the selected assets !!!"
msgstr "删除选择资产"
#: assets/templates/assets/asset_list.html:416
#: assets/templates/assets/asset_list.html:420
#: assets/templates/assets/system_user_list.html:137
#: settings/templates/settings/terminal_setting.html:166
#: users/templates/users/user_detail.html:392
@ -1850,16 +1861,16 @@ msgstr "删除选择资产"
msgid "Cancel"
msgstr "取消"
#: assets/templates/assets/asset_list.html:429
#: assets/templates/assets/asset_list.html:433
msgid "Asset Deleted."
msgstr "已被删除"
#: assets/templates/assets/asset_list.html:430
#: assets/templates/assets/asset_list.html:434
#: assets/templates/assets/asset_list.html:438
msgid "Asset Delete"
msgstr "删除"
#: assets/templates/assets/asset_list.html:433
#: assets/templates/assets/asset_list.html:437
msgid "Asset Deleting failed."
msgstr "删除失败"
@ -2179,7 +2190,6 @@ msgstr "成功"
#: audits/models.py:32
#: authentication/templates/authentication/_access_key_modal.html:38
#: xpack/plugins/gathered_user/templates/gathered_user/gathered_user_list.html:48
#: xpack/plugins/vault/templates/vault/vault.html:46
msgid "Create"
msgstr "创建"
@ -2210,8 +2220,8 @@ msgstr "启用"
msgid "-"
msgstr ""
#: audits/models.py:77 xpack/plugins/cloud/models.py:267
#: xpack/plugins/cloud/models.py:290
#: audits/models.py:77 xpack/plugins/cloud/models.py:264
#: xpack/plugins/cloud/models.py:287
msgid "Failed"
msgstr "失败"
@ -2239,15 +2249,15 @@ msgid "MFA"
msgstr "MFA"
#: audits/models.py:86 audits/templates/audits/login_log_list.html:63
#: xpack/plugins/change_auth_plan/models.py:416
#: xpack/plugins/change_auth_plan/models.py:413
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_execution_subtask_list.html:15
#: xpack/plugins/cloud/models.py:281
#: xpack/plugins/cloud/models.py:278
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_history.html:69
msgid "Reason"
msgstr "原因"
#: audits/models.py:87 audits/templates/audits/login_log_list.html:64
#: xpack/plugins/cloud/models.py:278 xpack/plugins/cloud/models.py:313
#: xpack/plugins/cloud/models.py:275 xpack/plugins/cloud/models.py:310
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_history.html:70
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_instance.html:65
msgid "Status"
@ -2265,10 +2275,11 @@ msgstr "登录日期"
#: perms/templates/perms/asset_permission_detail.html:86
#: perms/templates/perms/remote_app_permission_detail.html:78
#: terminal/models.py:165 terminal/templates/terminal/session_list.html:34
#: xpack/plugins/change_auth_plan/models.py:249
#: xpack/plugins/change_auth_plan/models.py:419
#: xpack/plugins/change_auth_plan/models.py:246
#: xpack/plugins/change_auth_plan/models.py:416
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_execution_list.html:59
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_execution_subtask_list.html:17
#: xpack/plugins/gathered_user/models.py:143
msgid "Date start"
msgstr "开始日期"
@ -2688,19 +2699,6 @@ msgstr ""
msgid "Encrypt field using Secret Key"
msgstr ""
#: common/mixins/api.py:64
#, python-format
msgid "%(name)s was %(action)s successfully"
msgstr "%(name)s %(action)s成功"
#: common/mixins/api.py:65
msgid "create"
msgstr "创建"
#: common/mixins/api.py:65
msgid "update"
msgstr "更新"
#: common/mixins/models.py:31
msgid "is discard"
msgstr ""
@ -2800,54 +2798,55 @@ msgstr "Become"
msgid "Create by"
msgstr "创建者"
#: ops/models/adhoc.py:224
#: ops/models/adhoc.py:226
msgid "{} Start task: {}"
msgstr "{} 任务开始: {}"
#: ops/models/adhoc.py:227
#: ops/models/adhoc.py:238
msgid "{} Task finish"
msgstr "{} 任务结束"
#: ops/models/adhoc.py:325
#: ops/models/adhoc.py:329
msgid "Start time"
msgstr "开始时间"
#: ops/models/adhoc.py:326
#: ops/models/adhoc.py:330
msgid "End time"
msgstr "完成时间"
#: ops/models/adhoc.py:327 ops/templates/ops/adhoc_history.html:57
#: ops/models/adhoc.py:331 ops/templates/ops/adhoc_history.html:57
#: ops/templates/ops/task_history.html:63 ops/templates/ops/task_list.html:33
#: xpack/plugins/change_auth_plan/models.py:252
#: xpack/plugins/change_auth_plan/models.py:422
#: xpack/plugins/change_auth_plan/models.py:249
#: xpack/plugins/change_auth_plan/models.py:419
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_execution_list.html:58
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_execution_subtask_list.html:16
#: xpack/plugins/gathered_user/models.py:146
msgid "Time"
msgstr "时间"
#: ops/models/adhoc.py:328 ops/templates/ops/adhoc_detail.html:106
#: ops/models/adhoc.py:332 ops/templates/ops/adhoc_detail.html:106
#: ops/templates/ops/adhoc_history.html:55
#: ops/templates/ops/adhoc_history_detail.html:69
#: ops/templates/ops/task_detail.html:84 ops/templates/ops/task_history.html:61
msgid "Is finished"
msgstr "是否完成"
#: ops/models/adhoc.py:329 ops/templates/ops/adhoc_history.html:56
#: ops/models/adhoc.py:333 ops/templates/ops/adhoc_history.html:56
#: ops/templates/ops/task_history.html:62
msgid "Is success"
msgstr "是否成功"
#: ops/models/adhoc.py:330
#: ops/models/adhoc.py:334
msgid "Adhoc raw result"
msgstr "结果"
#: ops/models/adhoc.py:331
#: ops/models/adhoc.py:335
msgid "Adhoc result summary"
msgstr "汇总"
#: ops/models/command.py:22
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_execution_list.html:56
#: xpack/plugins/cloud/models.py:276
#: xpack/plugins/cloud/models.py:273
msgid "Result"
msgstr "结果"
@ -2882,6 +2881,7 @@ msgstr "运行用户"
#: ops/templates/ops/adhoc_detail.html:94 ops/templates/ops/task_list.html:28
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_list.html:18
#: xpack/plugins/gathered_user/templates/gathered_user/task_list.html:19
msgid "Run times"
msgstr "执行次数"
@ -3049,6 +3049,7 @@ msgstr "版本"
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_list.html:54
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_detail.html:141
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_list.html:55
#: xpack/plugins/gathered_user/templates/gathered_user/task_list.html:49
msgid "Run"
msgstr "执行"
@ -3067,6 +3068,7 @@ msgid "Ops"
msgstr "作业中心"
#: ops/views/adhoc.py:46 templates/_nav.html:115
#: xpack/plugins/gathered_user/views.py:35
msgid "Task list"
msgstr "任务列表"
@ -3377,21 +3379,21 @@ msgstr "连接LDAP成功"
msgid "Match {} s users"
msgstr "匹配 {} 个用户"
#: settings/api.py:159
#: settings/api.py:161
msgid "succeed: {} failed: {} total: {}"
msgstr "成功:{} 失败:{} 总数:{}"
#: settings/api.py:181 settings/api.py:217
#: settings/api.py:183 settings/api.py:219
msgid ""
"Error: Account invalid (Please make sure the information such as Access key "
"or Secret key is correct)"
msgstr "错误:账户无效 (请确保 Access key 或 Secret key 等信息正确)"
#: settings/api.py:187 settings/api.py:223
#: settings/api.py:189 settings/api.py:225
msgid "Create succeed"
msgstr "创建成功"
#: settings/api.py:205 settings/api.py:243
#: settings/api.py:207 settings/api.py:245
#: settings/templates/settings/terminal_setting.html:154
msgid "Delete succeed"
msgstr "删除成功"
@ -3850,7 +3852,7 @@ msgid "Endpoint suffix"
msgstr "端点后缀"
#: settings/templates/settings/replay_storage_create.html:136
#: xpack/plugins/cloud/models.py:307
#: xpack/plugins/cloud/models.py:304
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_detail.html:109
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_instance.html:62
msgid "Region"
@ -5444,7 +5446,7 @@ msgid "Password length"
msgstr "密码长度"
#: xpack/plugins/change_auth_plan/forms.py:51
#: xpack/plugins/change_auth_plan/models.py:212
#: xpack/plugins/change_auth_plan/models.py:209
msgid "* For security, do not change {} user's password"
msgstr "* 为了安全,禁止更改 {} 用户的密码"
@ -5465,6 +5467,9 @@ msgstr "* 请输入有效的 crontab 表达式"
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_create_update.html:41
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_detail.html:72
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_list.html:16
#: xpack/plugins/gathered_user/forms.py:13
#: xpack/plugins/gathered_user/forms.py:41
#: xpack/plugins/gathered_user/templates/gathered_user/task_create_update.html:32
msgid "Periodic perform"
msgstr "定时执行"
@ -5477,10 +5482,12 @@ msgstr ""
"用户不存在,则创建用户。"
#: xpack/plugins/change_auth_plan/forms.py:131 xpack/plugins/cloud/forms.py:90
#: xpack/plugins/gathered_user/forms.py:44
msgid "Tips: (Units: hour)"
msgstr "提示:(单位: 时)"
#: xpack/plugins/change_auth_plan/forms.py:132 xpack/plugins/cloud/forms.py:91
#: xpack/plugins/gathered_user/forms.py:45
msgid ""
"eg: Every Sunday 03:05 run <5 3 * * 0> <br> Tips: Using 5 digits linux "
"crontab expressions <min hour day month week> (<a href='https://tool.lu/"
@ -5493,7 +5500,7 @@ msgstr ""
#: xpack/plugins/change_auth_plan/meta.py:9
#: xpack/plugins/change_auth_plan/models.py:113
#: xpack/plugins/change_auth_plan/models.py:256
#: xpack/plugins/change_auth_plan/models.py:253
#: xpack/plugins/change_auth_plan/views.py:33
#: xpack/plugins/change_auth_plan/views.py:50
#: xpack/plugins/change_auth_plan/views.py:72
@ -5521,6 +5528,8 @@ msgstr "所有资产使用不同的随机密码"
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_detail.html:100
#: xpack/plugins/cloud/models.py:165 xpack/plugins/cloud/models.py:219
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_detail.html:91
#: xpack/plugins/gathered_user/models.py:35
#: xpack/plugins/gathered_user/models.py:72
msgid "Cycle perform"
msgstr "周期执行"
@ -5529,6 +5538,8 @@ msgstr "周期执行"
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_detail.html:92
#: xpack/plugins/cloud/models.py:170 xpack/plugins/cloud/models.py:217
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_detail.html:83
#: xpack/plugins/gathered_user/models.py:40
#: xpack/plugins/gathered_user/models.py:70
msgid "Regularly perform"
msgstr "定期执行"
@ -5537,28 +5548,28 @@ msgstr "定期执行"
msgid "Password rules"
msgstr "密码规则"
#: xpack/plugins/change_auth_plan/models.py:216
#: xpack/plugins/change_auth_plan/models.py:213
msgid "Assets is empty, please add the asset"
msgstr "资产为空,请添加资产"
#: xpack/plugins/change_auth_plan/models.py:260
#: xpack/plugins/change_auth_plan/models.py:257
msgid "Change auth plan snapshot"
msgstr "改密计划快照"
#: xpack/plugins/change_auth_plan/models.py:275
#: xpack/plugins/change_auth_plan/models.py:426
#: xpack/plugins/change_auth_plan/models.py:272
#: xpack/plugins/change_auth_plan/models.py:423
msgid "Change auth plan execution"
msgstr "改密计划执行"
#: xpack/plugins/change_auth_plan/models.py:435
#: xpack/plugins/change_auth_plan/models.py:432
msgid "Change auth plan execution subtask"
msgstr "改密计划执行子任务"
#: xpack/plugins/change_auth_plan/models.py:453
#: xpack/plugins/change_auth_plan/models.py:450
msgid "Authentication failed"
msgstr "认证失败"
#: xpack/plugins/change_auth_plan/models.py:455
#: xpack/plugins/change_auth_plan/models.py:452
msgid "Connection timeout"
msgstr "连接超时"
@ -5603,6 +5614,7 @@ msgstr "手动执行计划"
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_detail.html:179
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_list.html:103
#: xpack/plugins/gathered_user/templates/gathered_user/task_list.html:96
msgid "Execute failed"
msgstr "执行失败"
@ -5722,37 +5734,37 @@ msgstr "实例"
msgid "Date last sync"
msgstr "最后同步日期"
#: xpack/plugins/cloud/models.py:187 xpack/plugins/cloud/models.py:274
#: xpack/plugins/cloud/models.py:187 xpack/plugins/cloud/models.py:271
msgid "Sync instance task"
msgstr "同步实例任务"
#: xpack/plugins/cloud/models.py:268 xpack/plugins/cloud/models.py:291
#: xpack/plugins/cloud/models.py:265 xpack/plugins/cloud/models.py:288
msgid "Succeed"
msgstr "成功"
#: xpack/plugins/cloud/models.py:269
#: xpack/plugins/cloud/models.py:266
msgid "Partial succeed"
msgstr ""
#: xpack/plugins/cloud/models.py:284 xpack/plugins/cloud/models.py:316
#: xpack/plugins/cloud/models.py:281 xpack/plugins/cloud/models.py:313
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_history.html:71
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_instance.html:66
msgid "Date sync"
msgstr "同步日期"
#: xpack/plugins/cloud/models.py:292
#: xpack/plugins/cloud/models.py:289
msgid "Exist"
msgstr "存在"
#: xpack/plugins/cloud/models.py:297
#: xpack/plugins/cloud/models.py:294
msgid "Sync task"
msgstr "同步任务"
#: xpack/plugins/cloud/models.py:301
#: xpack/plugins/cloud/models.py:298
msgid "Sync instance task history"
msgstr "同步实例任务历史"
#: xpack/plugins/cloud/models.py:304
#: xpack/plugins/cloud/models.py:301
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_detail.html:117
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_instance.html:61
msgid "Instance"
@ -5873,26 +5885,51 @@ msgid "Update sync Instance task"
msgstr "更新同步实例任务"
#: xpack/plugins/gathered_user/meta.py:11
#: xpack/plugins/gathered_user/views.py:22
#: xpack/plugins/gathered_user/views.py:21
#: xpack/plugins/gathered_user/views.py:34
msgid "Gathered user"
msgstr "收集用户"
#: xpack/plugins/gathered_user/templates/gathered_user/gathered_user_list.html:75
msgid "Present"
msgstr "存在"
#: xpack/plugins/gathered_user/models.py:33
#: xpack/plugins/gathered_user/templates/gathered_user/task_list.html:18
msgid "Periodic"
msgstr "定时执行"
#: xpack/plugins/gathered_user/views.py:23
#: xpack/plugins/gathered_user/models.py:57
#: xpack/plugins/gathered_user/templates/gathered_user/gathered_user_list.html:48
msgid "Gather user task"
msgstr "收集用户任务"
#: xpack/plugins/gathered_user/models.py:140
msgid "Task"
msgstr "任务"
#: xpack/plugins/gathered_user/models.py:152
msgid "gather user task execution"
msgstr "收集用户执行"
#: xpack/plugins/gathered_user/models.py:158
msgid "Assets is empty, please change nodes"
msgstr "资产为空,请更改节点"
#: xpack/plugins/gathered_user/templates/gathered_user/task_list.html:7
#: xpack/plugins/gathered_user/views.py:50
msgid "Create task"
msgstr "创建任务"
#: xpack/plugins/gathered_user/views.py:22
msgid "Gathered user list"
msgstr "收集用户列表"
#: xpack/plugins/gathered_user/views.py:37 xpack/plugins/vault/meta.py:11
#: xpack/plugins/gathered_user/views.py:49
#: xpack/plugins/gathered_user/views.py:66 xpack/plugins/vault/meta.py:11
#: xpack/plugins/vault/views.py:23 xpack/plugins/vault/views.py:38
msgid "Vault"
msgstr "密码匣子"
#: xpack/plugins/gathered_user/views.py:38 xpack/plugins/vault/views.py:39
msgid "vault create"
msgstr "创建"
#: xpack/plugins/gathered_user/views.py:67
msgid "Update task"
msgstr "更新任务"
#: xpack/plugins/interface/forms.py:17 xpack/plugins/interface/models.py:15
msgid "Title of login page"
@ -6112,6 +6149,25 @@ msgstr "导入密码"
msgid "vault list"
msgstr "密码匣子"
#: xpack/plugins/vault/views.py:39
msgid "vault create"
msgstr "创建"
#~ msgid "Gather user plan"
#~ msgstr "收集用户计划"
#~ msgid "Task update"
#~ msgstr "更新"
#~ msgid "Task create"
#~ msgstr "创建"
#~ msgid "%(hostname)s was %(action)s successfully"
#~ msgstr "%(hostname)s %(action)s成功"
#~ msgid "%(name)s was %(action)s successfully"
#~ msgstr "%(name)s %(action)s成功"
#~ msgid "* For security, do not change {}'s password"
#~ msgstr "* 为了安全,禁止更改 {} 的密码"

View File

@ -218,28 +218,32 @@ class AdHoc(models.Model):
hid = str(uuid.uuid4())
history = AdHocRunHistory(id=hid, adhoc=self, task=self.task)
time_start = time.time()
date_start = timezone.now()
is_success = False
try:
date_start = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
history.date_start = timezone.now()
print(_("{} Start task: {}").format(date_start, self.task.name))
date_start_s = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(_("{} Start task: {}").format(date_start_s, self.task.name))
raw, summary = self._run_only()
date_end = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(_("{} Task finish").format(date_end))
history.is_finished = True
if summary.get('dark'):
history.is_success = False
else:
history.is_success = True
history.result = raw
history.summary = summary
is_success = summary.get('success', False)
return raw, summary
except Exception as e:
logger.error(e, exc_info=True)
return {}, {"dark": {"all": str(e)}, "contacted": []}
summary = {}
raw = {"dark": {"all": str(e)}, "contacted": []}
return raw, summary
finally:
history.date_finished = timezone.now()
history.timedelta = time.time() - time_start
history.save()
date_end = timezone.now()
date_end_s = date_end.strftime('%Y-%m-%d %H:%M:%S')
print(_("{} Task finish").format(date_end_s))
print('.\n\n.')
AdHocRunHistory.objects.filter(id=history.id).update(
date_start=date_start,
is_finished=True,
is_success=is_success,
date_finished=timezone.now(),
timedelta=time.time() - time_start
)
def _run_only(self):
runner = AdHocRunner(self.inventory, options=self.options)

View File

@ -20,12 +20,7 @@ class RootOrgViewMixin:
return super().dispatch(request, *args, **kwargs)
class OrgModelViewSet(CommonApiMixin, ModelViewSet):
def get_queryset(self):
return super().get_queryset().all()
class OrgBulkModelViewSet(CommonApiMixin, BulkModelViewSet):
class OrgQuerySetMixin:
def get_queryset(self):
queryset = super().get_queryset().all()
if hasattr(self, 'swagger_fake_view'):
@ -36,6 +31,12 @@ class OrgBulkModelViewSet(CommonApiMixin, BulkModelViewSet):
queryset = self.serializer_class.setup_eager_loading(queryset)
return queryset
class OrgModelViewSet(CommonApiMixin, OrgQuerySetMixin, ModelViewSet):
pass
class OrgBulkModelViewSet(CommonApiMixin, OrgQuerySetMixin, BulkModelViewSet):
def allow_bulk_destroy(self, qs, filtered):
if qs.count() <= filtered.count():
return False

View File

@ -7,7 +7,7 @@ from common.tree import TreeNodeSerializer
class UserAssetPermissionMixin(UserPermissionMixin):
util = AssetPermissionUtilV2(None)
util = None
tree = None
def initial(self, *args, **kwargs):