mirror of https://github.com/jumpserver/jumpserver
[Update] 抽象Inventory,更新翻译 (#2530)
* [Update] 抽象Inventory, 支持自定义用户名密码构建Inventory * [Update] 更新翻译pull/2541/head
parent
7ea03801d0
commit
612d5efd1b
|
@ -82,7 +82,7 @@
|
||||||
<div id="actions" class="" style="margin-top: -20px">
|
<div id="actions" class="" style="margin-top: -20px">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<select class="form-control m-b" style="width: auto" id="slct_bulk_update">
|
<select class="form-control m-b" style="width: auto" id="slct_bulk_update">
|
||||||
<option value="export">{% trans 'Export login log' %}</option>
|
<option value="export">{% trans 'Export' %}</option>
|
||||||
</select>
|
</select>
|
||||||
<div class="input-group-btn pull-left" style="padding-left: 5px;">
|
<div class="input-group-btn pull-left" style="padding-left: 5px;">
|
||||||
<button id='btn_bulk_update' style="height: 32px;" class="btn btn-sm btn-primary btn_export">
|
<button id='btn_bulk_update' style="height: 32px;" class="btn btn-sm btn-primary btn_export">
|
||||||
|
|
Binary file not shown.
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: Jumpserver 0.3.3\n"
|
"Project-Id-Version: Jumpserver 0.3.3\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2019-03-22 15:57+0800\n"
|
"POT-Creation-Date: 2019-03-22 16:48+0800\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: ibuler <ibuler@qq.com>\n"
|
"Last-Translator: ibuler <ibuler@qq.com>\n"
|
||||||
"Language-Team: Jumpserver team<ibuler@qq.com>\n"
|
"Language-Team: Jumpserver team<ibuler@qq.com>\n"
|
||||||
|
@ -1337,6 +1337,7 @@ msgid "Import"
|
||||||
msgstr "导入"
|
msgstr "导入"
|
||||||
|
|
||||||
#: assets/templates/assets/asset_list.html:76
|
#: assets/templates/assets/asset_list.html:76
|
||||||
|
#: audits/templates/audits/login_log_list.html:85
|
||||||
#: users/templates/users/user_list.html:10
|
#: users/templates/users/user_list.html:10
|
||||||
msgid "Export"
|
msgid "Export"
|
||||||
msgstr "导出"
|
msgstr "导出"
|
||||||
|
@ -1947,12 +1948,6 @@ msgstr "城市"
|
||||||
msgid "Date"
|
msgid "Date"
|
||||||
msgstr "日期"
|
msgstr "日期"
|
||||||
|
|
||||||
#: audits/templates/audits/login_log_list.html:85
|
|
||||||
#, fuzzy
|
|
||||||
#| msgid "Login log"
|
|
||||||
msgid "Export login log"
|
|
||||||
msgstr "登录日志"
|
|
||||||
|
|
||||||
#: audits/templates/audits/operate_log_list.html:71
|
#: audits/templates/audits/operate_log_list.html:71
|
||||||
#: audits/templates/audits/password_change_log_list.html:53
|
#: audits/templates/audits/password_change_log_list.html:53
|
||||||
#: ops/templates/ops/task_adhoc.html:63
|
#: ops/templates/ops/task_adhoc.html:63
|
||||||
|
@ -1983,8 +1978,6 @@ msgid "Login log"
|
||||||
msgstr "登录日志"
|
msgstr "登录日志"
|
||||||
|
|
||||||
#: audits/views.py:242
|
#: audits/views.py:242
|
||||||
#, fuzzy
|
|
||||||
#| msgid "Command execution"
|
|
||||||
msgid "Command execution log"
|
msgid "Command execution log"
|
||||||
msgstr "命令执行"
|
msgstr "命令执行"
|
||||||
|
|
||||||
|
@ -4709,7 +4702,7 @@ msgstr "选择管理员"
|
||||||
#: xpack/plugins/cloud/views.py:41 xpack/plugins/cloud/views.py:57
|
#: xpack/plugins/cloud/views.py:41 xpack/plugins/cloud/views.py:57
|
||||||
#: xpack/plugins/cloud/views.py:71 xpack/plugins/cloud/views.py:84
|
#: xpack/plugins/cloud/views.py:71 xpack/plugins/cloud/views.py:84
|
||||||
#: xpack/plugins/cloud/views.py:100 xpack/plugins/cloud/views.py:121
|
#: xpack/plugins/cloud/views.py:100 xpack/plugins/cloud/views.py:121
|
||||||
#: xpack/plugins/cloud/views.py:136 xpack/plugins/cloud/views.py:187
|
#: xpack/plugins/cloud/views.py:136 xpack/plugins/cloud/views.py:179
|
||||||
msgid "Cloud center"
|
msgid "Cloud center"
|
||||||
msgstr "云管中心"
|
msgstr "云管中心"
|
||||||
|
|
||||||
|
@ -4840,7 +4833,7 @@ msgstr "同步历史列表"
|
||||||
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_detail.html:28
|
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_detail.html:28
|
||||||
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_history.html:31
|
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_history.html:31
|
||||||
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_instance.html:29
|
#: xpack/plugins/cloud/templates/cloud/sync_instance_task_instance.html:29
|
||||||
#: xpack/plugins/cloud/views.py:188
|
#: xpack/plugins/cloud/views.py:180
|
||||||
msgid "Sync instance list"
|
msgid "Sync instance list"
|
||||||
msgstr "同步实例列表"
|
msgstr "同步实例列表"
|
||||||
|
|
||||||
|
@ -4903,14 +4896,10 @@ msgid "Image of login page"
|
||||||
msgstr "登录页面图片"
|
msgstr "登录页面图片"
|
||||||
|
|
||||||
#: xpack/plugins/interface/forms.py:27
|
#: xpack/plugins/interface/forms.py:27
|
||||||
#, fuzzy
|
|
||||||
#| msgid ""
|
|
||||||
#| "Tips: This will be displayed on the enterprise user login page. (suggest "
|
|
||||||
#| "image size: 492px*472px)"
|
|
||||||
msgid ""
|
msgid ""
|
||||||
"Tips: This will be displayed on the enterprise user login page. (suggest "
|
"Tips: This will be displayed on the enterprise user login page. (suggest "
|
||||||
"image size: 635px*472px)"
|
"image size: 492px*472px)"
|
||||||
msgstr "提示:将会显示在企业版用户登录页面(建议图片大小为: 492px*472px)"
|
msgstr "提示:将会显示在企业版用户登录页面(建议图片大小为: 492*472px)"
|
||||||
|
|
||||||
#: xpack/plugins/interface/forms.py:33 xpack/plugins/interface/models.py:23
|
#: xpack/plugins/interface/forms.py:33 xpack/plugins/interface/models.py:23
|
||||||
msgid "Website icon"
|
msgid "Website icon"
|
||||||
|
@ -5084,12 +5073,6 @@ msgstr "创建组织"
|
||||||
msgid "Update org"
|
msgid "Update org"
|
||||||
msgstr "更新组织"
|
msgstr "更新组织"
|
||||||
|
|
||||||
#~ msgid "Cycle perform"
|
|
||||||
#~ msgstr "周期执行"
|
|
||||||
|
|
||||||
#~ msgid "Tips: (Units: hour)"
|
|
||||||
#~ msgstr "提示:(单位: 时)"
|
|
||||||
|
|
||||||
#~ msgid "Password length"
|
#~ msgid "Password length"
|
||||||
#~ msgstr "密码长度"
|
#~ msgstr "密码长度"
|
||||||
|
|
||||||
|
@ -5099,9 +5082,15 @@ msgstr "更新组织"
|
||||||
#~ msgid "* Please enter a valid crontab expression"
|
#~ msgid "* Please enter a valid crontab expression"
|
||||||
#~ msgstr "* 请输入有效的 crontab 表达式"
|
#~ msgstr "* 请输入有效的 crontab 表达式"
|
||||||
|
|
||||||
#~ msgid "Timing perform"
|
#~ msgid "Asset username"
|
||||||
|
#~ msgstr "资产用户名"
|
||||||
|
|
||||||
|
#~ msgid "Periodic perform"
|
||||||
#~ msgstr "定时执行"
|
#~ msgstr "定时执行"
|
||||||
|
|
||||||
|
#~ msgid "Tips: (Units: hour)"
|
||||||
|
#~ msgstr "提示:(单位: 时)"
|
||||||
|
|
||||||
#~ msgid ""
|
#~ msgid ""
|
||||||
#~ "eg: Every Sunday 03:05 run (5 3 * * 0) <br> Tips: Using 5 digits linux "
|
#~ "eg: Every Sunday 03:05 run (5 3 * * 0) <br> Tips: Using 5 digits linux "
|
||||||
#~ "crontab expressions (<a href='https://tool.lu/crontab/' "
|
#~ "crontab expressions (<a href='https://tool.lu/crontab/' "
|
||||||
|
@ -5124,8 +5113,8 @@ msgstr "更新组织"
|
||||||
#~ msgid "All assets use different random password"
|
#~ msgid "All assets use different random password"
|
||||||
#~ msgstr "所有资产使用不同的随机密码"
|
#~ msgstr "所有资产使用不同的随机密码"
|
||||||
|
|
||||||
#~ msgid "Asset username"
|
#~ msgid "Cycle perform"
|
||||||
#~ msgstr "资产用户名"
|
#~ msgstr "周期执行"
|
||||||
|
|
||||||
#~ msgid "Regularly perform"
|
#~ msgid "Regularly perform"
|
||||||
#~ msgstr "定期执行"
|
#~ msgstr "定期执行"
|
||||||
|
@ -5139,11 +5128,11 @@ msgstr "更新组织"
|
||||||
#~ msgid "Change auth plan snapshot"
|
#~ msgid "Change auth plan snapshot"
|
||||||
#~ msgstr "改密计划快照"
|
#~ msgstr "改密计划快照"
|
||||||
|
|
||||||
#~ msgid "Change auth plan history"
|
#~ msgid "Change auth plan execution"
|
||||||
#~ msgstr "改密计划历史"
|
#~ msgstr "改密计划执行"
|
||||||
|
|
||||||
#~ msgid "Change auth plan task"
|
#~ msgid "Change auth plan execution subtask"
|
||||||
#~ msgstr "改密计划任务"
|
#~ msgstr "改密计划执行子任务"
|
||||||
|
|
||||||
#~ msgid "Authentication failed"
|
#~ msgid "Authentication failed"
|
||||||
#~ msgstr "认证失败"
|
#~ msgstr "认证失败"
|
||||||
|
@ -5154,8 +5143,8 @@ msgstr "更新组织"
|
||||||
#~ msgid "Plan detail"
|
#~ msgid "Plan detail"
|
||||||
#~ msgstr "计划详情"
|
#~ msgstr "计划详情"
|
||||||
|
|
||||||
#~ msgid "Run history list"
|
#~ msgid "Plan execution list"
|
||||||
#~ msgstr "执行历史列表"
|
#~ msgstr "执行列表"
|
||||||
|
|
||||||
#~ msgid "Add asset to this plan"
|
#~ msgid "Add asset to this plan"
|
||||||
#~ msgstr "添加资产"
|
#~ msgstr "添加资产"
|
||||||
|
@ -5166,8 +5155,14 @@ msgstr "更新组织"
|
||||||
#~ msgid "Length"
|
#~ msgid "Length"
|
||||||
#~ msgstr "长度"
|
#~ msgstr "长度"
|
||||||
|
|
||||||
#~ msgid "History of plan"
|
#~ msgid "Execute plan"
|
||||||
#~ msgstr "执行历史"
|
#~ msgstr "执行计划"
|
||||||
|
|
||||||
|
#~ msgid "Execute failed"
|
||||||
|
#~ msgstr "执行失败"
|
||||||
|
|
||||||
|
#~ msgid "Execution list of plan"
|
||||||
|
#~ msgstr "执行列表"
|
||||||
|
|
||||||
#~ msgid "Log"
|
#~ msgid "Log"
|
||||||
#~ msgstr "日志"
|
#~ msgstr "日志"
|
||||||
|
@ -5190,12 +5185,8 @@ msgstr "更新组织"
|
||||||
#~ msgid "plan asset list"
|
#~ msgid "plan asset list"
|
||||||
#~ msgstr "计划资产列表"
|
#~ msgstr "计划资产列表"
|
||||||
|
|
||||||
#~ msgid "Run history task list"
|
#~ msgid "Plan execution task list"
|
||||||
#~ msgstr "执行历史任务列表"
|
#~ msgstr "执行任务列表"
|
||||||
|
|
||||||
#~ msgid ""
|
|
||||||
#~ "* When selecting a custom password strategy, please enter the password"
|
|
||||||
#~ msgstr "* 选择自定义密码策略时,请输入密码"
|
|
||||||
|
|
||||||
#~ msgid "Monitor"
|
#~ msgid "Monitor"
|
||||||
#~ msgstr "监控"
|
#~ msgstr "监控"
|
||||||
|
|
|
@ -7,17 +7,70 @@ from assets.utils import get_assets_by_id_list, get_system_user_by_id
|
||||||
from common.utils import get_logger
|
from common.utils import get_logger
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'JMSInventory'
|
'JMSInventory', 'JMSCustomInventory',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
logger = get_logger(__file__)
|
logger = get_logger(__file__)
|
||||||
|
|
||||||
|
|
||||||
class JMSInventory(BaseInventory):
|
class JMSBaseInventory(BaseInventory):
|
||||||
|
|
||||||
|
def convert_to_ansible(self, asset, run_as_admin=False):
|
||||||
|
info = {
|
||||||
|
'id': asset.id,
|
||||||
|
'hostname': asset.hostname,
|
||||||
|
'ip': asset.ip,
|
||||||
|
'port': asset.port,
|
||||||
|
'vars': dict(),
|
||||||
|
'groups': [],
|
||||||
|
}
|
||||||
|
if asset.domain and asset.domain.has_gateway():
|
||||||
|
info["vars"].update(self.make_proxy_command(asset))
|
||||||
|
if run_as_admin:
|
||||||
|
info.update(asset.get_auth_info())
|
||||||
|
for node in asset.nodes.all():
|
||||||
|
info["groups"].append(node.value)
|
||||||
|
for label in asset.labels.all():
|
||||||
|
info["vars"].update({
|
||||||
|
label.name: label.value
|
||||||
|
})
|
||||||
|
info["groups"].append("{}:{}".format(label.name, label.value))
|
||||||
|
if asset.domain:
|
||||||
|
info["vars"].update({
|
||||||
|
"domain": asset.domain.name,
|
||||||
|
})
|
||||||
|
info["groups"].append("domain_"+asset.domain.name)
|
||||||
|
return info
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def make_proxy_command(asset):
|
||||||
|
gateway = asset.domain.random_gateway()
|
||||||
|
proxy_command_list = [
|
||||||
|
"ssh", "-p", str(gateway.port),
|
||||||
|
"-o", "StrictHostKeyChecking=no",
|
||||||
|
"{}@{}".format(gateway.username, gateway.ip),
|
||||||
|
"-W", "%h:%p", "-q",
|
||||||
|
]
|
||||||
|
|
||||||
|
if gateway.password:
|
||||||
|
proxy_command_list.insert(
|
||||||
|
0, "sshpass -p '{}'".format(gateway.password)
|
||||||
|
)
|
||||||
|
if gateway.private_key:
|
||||||
|
proxy_command_list.append("-i {}".format(gateway.private_key_file))
|
||||||
|
|
||||||
|
proxy_command = "'-o ProxyCommand={}'".format(
|
||||||
|
" ".join(proxy_command_list)
|
||||||
|
)
|
||||||
|
return {"ansible_ssh_common_args": proxy_command}
|
||||||
|
|
||||||
|
|
||||||
|
class JMSInventory(JMSBaseInventory):
|
||||||
"""
|
"""
|
||||||
JMS Inventory is the manager with jumpserver assets, so you can
|
JMS Inventory is the manager with jumpserver assets, so you can
|
||||||
write you own manager, construct you inventory
|
write you own manager, construct you inventory,
|
||||||
|
user_info is obtained from admin_user or asset_user
|
||||||
"""
|
"""
|
||||||
def __init__(self, assets, run_as_admin=False, run_as=None, become_info=None):
|
def __init__(self, assets, run_as_admin=False, run_as=None, become_info=None):
|
||||||
"""
|
"""
|
||||||
|
@ -47,33 +100,6 @@ class JMSInventory(BaseInventory):
|
||||||
host.update(become_info)
|
host.update(become_info)
|
||||||
super().__init__(host_list=host_list)
|
super().__init__(host_list=host_list)
|
||||||
|
|
||||||
def convert_to_ansible(self, asset, run_as_admin=False):
|
|
||||||
info = {
|
|
||||||
'id': asset.id,
|
|
||||||
'hostname': asset.hostname,
|
|
||||||
'ip': asset.ip,
|
|
||||||
'port': asset.port,
|
|
||||||
'vars': dict(),
|
|
||||||
'groups': [],
|
|
||||||
}
|
|
||||||
if asset.domain and asset.domain.has_gateway():
|
|
||||||
info["vars"].update(self.make_proxy_command(asset))
|
|
||||||
if run_as_admin:
|
|
||||||
info.update(asset.get_auth_info())
|
|
||||||
for node in asset.nodes.all():
|
|
||||||
info["groups"].append(node.value)
|
|
||||||
for label in asset.labels.all():
|
|
||||||
info["vars"].update({
|
|
||||||
label.name: label.value
|
|
||||||
})
|
|
||||||
info["groups"].append("{}:{}".format(label.name, label.value))
|
|
||||||
if asset.domain:
|
|
||||||
info["vars"].update({
|
|
||||||
"domain": asset.domain.name,
|
|
||||||
})
|
|
||||||
info["groups"].append("domain_"+asset.domain.name)
|
|
||||||
return info
|
|
||||||
|
|
||||||
def get_run_user_info(self, host):
|
def get_run_user_info(self, host):
|
||||||
from assets.backends.multi import AssetUserManager
|
from assets.backends.multi import AssetUserManager
|
||||||
|
|
||||||
|
@ -89,24 +115,38 @@ class JMSInventory(BaseInventory):
|
||||||
else:
|
else:
|
||||||
return run_user._to_secret_json()
|
return run_user._to_secret_json()
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def make_proxy_command(asset):
|
|
||||||
gateway = asset.domain.random_gateway()
|
|
||||||
proxy_command_list = [
|
|
||||||
"ssh", "-p", str(gateway.port),
|
|
||||||
"-o", "StrictHostKeyChecking=no",
|
|
||||||
"{}@{}".format(gateway.username, gateway.ip),
|
|
||||||
"-W", "%h:%p", "-q",
|
|
||||||
]
|
|
||||||
|
|
||||||
if gateway.password:
|
class JMSCustomInventory(JMSBaseInventory):
|
||||||
proxy_command_list.insert(
|
"""
|
||||||
0, "sshpass -p '{}'".format(gateway.password)
|
JMS Custom Inventory is the manager with jumpserver assets,
|
||||||
)
|
user_info is obtained from custom parameter
|
||||||
if gateway.private_key:
|
"""
|
||||||
proxy_command_list.append("-i {}".format(gateway.private_key_file))
|
|
||||||
|
|
||||||
proxy_command = "'-o ProxyCommand={}'".format(
|
def __init__(self, assets, username, password=None, public_key=None, private_key=None):
|
||||||
" ".join(proxy_command_list)
|
"""
|
||||||
)
|
"""
|
||||||
return {"ansible_ssh_common_args": proxy_command}
|
self.assets = assets
|
||||||
|
self.username = username
|
||||||
|
self.password = password
|
||||||
|
self.public_key = public_key
|
||||||
|
self.private_key = private_key
|
||||||
|
|
||||||
|
host_list = []
|
||||||
|
|
||||||
|
for asset in assets:
|
||||||
|
info = self.convert_to_ansible(asset)
|
||||||
|
host_list.append(info)
|
||||||
|
|
||||||
|
for host in host_list:
|
||||||
|
run_user_info = self.get_run_user_info()
|
||||||
|
host.update(run_user_info)
|
||||||
|
|
||||||
|
super().__init__(host_list=host_list)
|
||||||
|
|
||||||
|
def get_run_user_info(self):
|
||||||
|
return {
|
||||||
|
'username': self.username,
|
||||||
|
'password': self.password,
|
||||||
|
'public_key': self.public_key,
|
||||||
|
'private_key': self.private_key
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue