[update]添加命令执行功能

This commit is contained in:
OrangeM21
2020-06-05 17:13:54 +08:00
parent 78c86f5a7e
commit 501c9991cb
3 changed files with 61 additions and 68 deletions

View File

@@ -31,6 +31,10 @@
"assets": { "assets": {
"Action": "动作", "Action": "动作",
"AutoGenerateKey": "自动生成密钥", "AutoGenerateKey": "自动生成密钥",
"UnselectedAssets":"未选择资产",
"Pending": "等待",
"NoSystemUserWasSelected":"未选择系统用户",
"NoInputCommand": "未输入命令",
"LoginModeHelpMessage": "如果选择手动登录模式,用户名和密码可以不填写", "LoginModeHelpMessage": "如果选择手动登录模式,用户名和密码可以不填写",
"UsernameHelpMessage": "用户名是动态的,登录资产时使用当前用户的用户名登录", "UsernameHelpMessage": "用户名是动态的,登录资产时使用当前用户的用户名登录",
"PriorityHelpMessage": "1-100, 1最低优先级100最高优先级。授权多个用户时高优先级的系统用户将会作为默认登录用户", "PriorityHelpMessage": "1-100, 1最低优先级100最高优先级。授权多个用户时高优先级的系统用户将会作为默认登录用户",
@@ -49,7 +53,6 @@
"AssetDetail": "资产详情", "AssetDetail": "资产详情",
"AssetList": "资产列表", "AssetList": "资产列表",
"AssetNumber": "资产编号", "AssetNumber": "资产编号",
"AssetUserList": "资产用户列表",
"Assets": "资产", "Assets": "资产",
"Auth": "认证", "Auth": "认证",
"AutoPush": "自动推送", "AutoPush": "自动推送",
@@ -147,8 +150,6 @@
"DateLastWeek": "最近一周", "DateLastWeek": "最近一周",
"DateLastMonth": "最近一月", "DateLastMonth": "最近一月",
"DateLast3Months": "最近三月", "DateLast3Months": "最近三月",
"View": "查看",
"Remove": "移除",
"Yes": "是", "Yes": "是",
"No": "否", "No": "否",
"Action": "动作", "Action": "动作",
@@ -399,9 +400,9 @@
"DatabaseAppPermissionUpdate": "更新数据库应用授权规则", "DatabaseAppPermissionUpdate": "更新数据库应用授权规则",
"DatabaseAppUpdate": "", "DatabaseAppUpdate": "",
"DomainCreate": "创建网关", "DomainCreate": "创建网关",
"DomainDetail": "域详情", "DomainDetail": "域详情",
"DomainList": "网列表", "DomainList": "网列表",
"DomainUpdate": "更新网", "DomainUpdate": "更新网",
"FileManager": "文件管理", "FileManager": "文件管理",
"FtpLog": "FTP日志", "FtpLog": "FTP日志",
"GatewayCreate": "创建网关", "GatewayCreate": "创建网关",
@@ -455,7 +456,7 @@
"WebFTP": "文件管理", "WebFTP": "文件管理",
"WebTerminal": "Web终端", "WebTerminal": "Web终端",
"BatchCommandLog": "批量命令", "BatchCommandLog": "批量命令",
"TaskMonitor": "任务监控" "": ""
}, },
"sessions": { "sessions": {
"StorageConfiguration": "存储配置", "StorageConfiguration": "存储配置",
@@ -625,9 +626,7 @@
"consult": "咨询", "consult": "咨询",
"ImportLicense": "导入许可证", "ImportLicense": "导入许可证",
"AssetCount": "资产数量", "AssetCount": "资产数量",
"ImportLicenseTip": "请导入许可证", "ImportLicenseTip": "请导入许可证"
"all": "全部",
"auto": "自动"
}, },
"settings": { "settings": {
"setting": "" "setting": ""
@@ -653,10 +652,6 @@
"DeleteNode": "删除节点", "DeleteNode": "删除节点",
"RenameNode": "重命名节点" "RenameNode": "重命名节点"
}, },
"audits": {
"View": "查看",
"Hosts": "主机"
},
"users": { "users": {
"SSHKey": "SSH公钥", "SSHKey": "SSH公钥",
"TermsAndConditions": "条款和条件", "TermsAndConditions": "条款和条件",
@@ -735,10 +730,6 @@
"dateLastLogin": "" "dateLastLogin": ""
}, },
"xpack": { "xpack": {
"Vault": {
"Vault": "密码匣子",
"Create": "创建"
},
"Basic": "基本", "Basic": "基本",
"Other": "其他", "Other": "其他",
"Admin": "管理员", "Admin": "管理员",
@@ -778,8 +769,8 @@
"DateJoined": "创建日期", "DateJoined": "创建日期",
"DateUpdated": "更新日期", "DateUpdated": "更新日期",
"ManualExecutePlan": "手动执行计划", "ManualExecutePlan": "手动执行计划",
"AddAsset": "添加资产", "addAsset": "添加资产",
"AddNode": "添加节点", "addNode": "添加节点",
"Result": "结果", "Result": "结果",
"TimeDelta": "运行时间", "TimeDelta": "运行时间",
"DateStart": "开始日期", "DateStart": "开始日期",
@@ -795,20 +786,11 @@
"Corporation": "公司", "Corporation": "公司",
"Edition": "版本", "Edition": "版本",
"Expired": "过期时间", "Expired": "过期时间",
"GatherUser": { "GatherUserTask": "收集用户任务",
"GatherUser": "收集用户", "GatherUserList": "收集用户",
"GatherUserTask": "收集用户任务", "GatherUserTaskCreate": "创建任务",
"GatherUserList": "收集资产用户列表", "GatherUserTaskList": "任务列表",
"GatherUserTaskCreate": "创建任务", "GatherUserTaskUpdate": "更新任务",
"GatherUserTaskList": "收集资产任务列表",
"GatherUserTaskUpdate": "更新任务"
},
"Organization": {
"OrganizationCreate": "创建组织",
"OrganizationDetail": "组织详情",
"OrganizationList": "组织管理",
"OrganizationUpdate": "更新组织"
},
"ImportLicense": "导入许可证", "ImportLicense": "导入许可证",
"ImportLicenseTip": "请导入许可证", "ImportLicenseTip": "请导入许可证",
"InterfaceSettings": "界面设置", "InterfaceSettings": "界面设置",
@@ -816,6 +798,10 @@
"LicenseDetail": "许可证详情", "LicenseDetail": "许可证详情",
"LicenseFile": "许可证文件", "LicenseFile": "许可证文件",
"NoLicense": "暂无许可证", "NoLicense": "暂无许可证",
"OrganizationCreate": "创建组织",
"OrganizationDetail": "组织详情",
"OrganizationList": "组织管理",
"OrganizationUpdate": "更新组织",
"RestoreButton": "恢复默认", "RestoreButton": "恢复默认",
"SubscriptionID": "订阅授权ID", "SubscriptionID": "订阅授权ID",
"Timer": "定时执行", "Timer": "定时执行",
@@ -835,7 +821,7 @@
"restoreDialogTitle": "你确认吗", "restoreDialogTitle": "你确认吗",
"technologyConsult": "技术咨询", "technologyConsult": "技术咨询",
"Cloud": { "Cloud": {
"CloudCenter": "云管中心", "Cloud": "云管中心",
"AccountList": "账户列表", "AccountList": "账户列表",
"AccountCreate": "创建账户", "AccountCreate": "创建账户",
"AccountUpdate": "更新账户", "AccountUpdate": "更新账户",

View File

@@ -30,6 +30,10 @@
}, },
"assets": { "assets": {
"Action": "Action", "Action": "Action",
"NoInputCommand": "No input command",
"UnselectedAssets":"Unselected assets",
"Pending": "Pending",
"NoSystemUserWasSelected":"No system user was selected",
"LoginModeHelpMessage": "If you choose manual login mode, you do not need to fill in the username and password.", "LoginModeHelpMessage": "If you choose manual login mode, you do not need to fill in the username and password.",
"UsernameHelpMessage": "Username is dynamic, When connect asset, using current user's username", "UsernameHelpMessage": "Username is dynamic, When connect asset, using current user's username",
"PriorityHelpMessage": "1-100, High level will be using login asset as default, if user was granted more than 2 system user", "PriorityHelpMessage": "1-100, High level will be using login asset as default, if user was granted more than 2 system user",
@@ -51,7 +55,6 @@
"AssetList": "Asset list", "AssetList": "Asset list",
"AssetNumber": "Asset number", "AssetNumber": "Asset number",
"Assets": "Assets", "Assets": "Assets",
"AssetUserList": "Asset user",
"Auth": "Auth", "Auth": "Auth",
"AutoPush": "Auto push", "AutoPush": "Auto push",
"BasePlatform": "Base platform", "BasePlatform": "Base platform",
@@ -146,8 +149,6 @@
"DateLastWeek": "Last week", "DateLastWeek": "Last week",
"DateLastMonth": "Last month", "DateLastMonth": "Last month",
"DateLast3Months": "Last 3 months", "DateLast3Months": "Last 3 months",
"Remove": "Remove",
"View": "View",
"Yes": "Yes", "Yes": "Yes",
"No": "No", "No": "No",
"Action": "Action", "Action": "Action",
@@ -275,10 +276,6 @@
"Weekly": "Weekly", "Weekly": "Weekly",
"TimesWeekUnit": "times/week" "TimesWeekUnit": "times/week"
}, },
"audits": {
"View": "View",
"Hosts": "Hosts"
},
"ops": { "ops": {
"ID": "ID", "ID": "ID",
"No": "No", "No": "No",
@@ -455,8 +452,7 @@
"Users": "Users", "Users": "Users",
"WebFTP": "WebFTP", "WebFTP": "WebFTP",
"WebTerminal": "Web terminal", "WebTerminal": "Web terminal",
"BatchCommandLog": "Batch command log", "BatchCommandLog": "Batch command log"
"TaskMonitor": "Task monitor"
}, },
"sessions": { "sessions": {
"StorageConfiguration": "Storage configuration", "StorageConfiguration": "Storage configuration",
@@ -622,8 +618,8 @@
"AssetCount": "Asset count", "AssetCount": "Asset count",
"ImportLicenseTip": "Please Import License", "ImportLicenseTip": "Please Import License",
"ApiKeyList": "Api key list", "ApiKeyList": "Api key list",
"all": "All", "DateCreated": "",
"auto": "Auto" "Create": ""
}, },
"settings": { "settings": {
"setting": "" "setting": ""
@@ -728,10 +724,6 @@
"ResetAndDownloadSSHKey": "Reset and download SSH Key" "ResetAndDownloadSSHKey": "Reset and download SSH Key"
}, },
"xpack": { "xpack": {
"Vault": {
"Vault": "Vault",
"Create": "Create"
},
"Admin": "Admin", "Admin": "Admin",
"AssetCount": "Asset count", "AssetCount": "Asset count",
"Auditor": "Auditor", "Auditor": "Auditor",

View File

@@ -5,6 +5,7 @@
<div v-show="iShowTree" :style="iShowTree?('width:250px;'):('width:0;')" class="transition-box"> <div v-show="iShowTree" :style="iShowTree?('width:250px;'):('width:0;')" class="transition-box">
<AutoDataZTree <AutoDataZTree
ref="AutoDataZTree" ref="AutoDataZTree"
:key="DataZTree"
:setting="treeSetting" :setting="treeSetting"
class="auto-data-ztree" class="auto-data-ztree"
/> />
@@ -58,6 +59,7 @@ export default {
}, },
data() { data() {
return { return {
DataZTree: 0,
codeMirrorOptions: { codeMirrorOptions: {
lineNumbers: true, lineNumbers: true,
lineWrapping: true, lineWrapping: true,
@@ -135,7 +137,7 @@ export default {
}, },
handleSystemUserChange(id) { handleSystemUserChange(id) {
this.treeSetting.treeUrl = `${this.basicUrl}&system_user=${id}` this.treeSetting.treeUrl = `${this.basicUrl}&system_user=${id}`
this.$refs.AutoDataZTree.$refs.dataztree.$refs.ztree.initTree() this.DataZTree++
}, },
getSelectedAssetsNode() { getSelectedAssetsNode() {
const nodes = this.zTree.getCheckedNodes(true) const nodes = this.zTree.getCheckedNodes(true)
@@ -169,15 +171,11 @@ export default {
const port = document.location.port ? ':' + document.location.port : '' const port = document.location.port ? ':' + document.location.port : ''
const url = '/ws/ops/tasks/log/' const url = '/ws/ops/tasks/log/'
const wsURL = scheme + '://' + document.location.hostname + port + url const wsURL = scheme + '://' + document.location.hostname + port + url
const failOverPort = '8070' // const failOverPort = '8070'
const failOverWsURL = scheme + '://' + document.location.hostname + ':' + failOverPort + url // const failOverWsURL = scheme + '://' + document.location.hostname + ':' + failOverPort + url
this.ws = new WebSocket(wsURL) this.ws = new WebSocket(wsURL)
this.ws.onerror = (e) => { this.ws.onerror = (e) => {
this.ws = new WebSocket(failOverWsURL) this.xterm.write(this.wrapperError('Connect websocket server error'))
this.setWsCallback()
this.ws.onerror = (e) => {
this.xterm.write(this.wrapperError('Connect websocket server error'))
}
} }
this.setWsCallback() this.setWsCallback()
}, },
@@ -188,28 +186,45 @@ export default {
} }
}, },
wrapperError(msg) { wrapperError(msg) {
return '\\033[31m' + msg + '\\033[0m\r\n' return `\r\n${msg}\r\n`
},
writeExecutionOutput(taskId) {
let msg = this.$t('assets.Pending')
this.xterm.write(msg)
msg = JSON.stringify({ task: taskId })
this.ws.send(msg)
}, },
execute() { execute() {
// const size = 'rows=' + this.xterm.rows + '&cols=' + this.xterm.cols const size = 'rows=' + this.xterm.rows + '&cols=' + this.xterm.cols
// const url = '{% url "api-ops:command-execution-list" %}?' + size const url = '/api/v1/ops/command-executions/?' + size
const runAs = this.selectedSystemUser const runAs = this.selectedSystemUser
// const command = editor.getValue() const command = this.actions
const hosts = this.getSelectedAssetsNode().map(function(node) { const hosts = this.getSelectedAssetsNode().map(function(node) {
return node.id return node.id
}) })
if (hosts.length === 0) { if (hosts.length === 0) {
this.xterm.write(this.wrapperError("{% trans 'Unselected assets' %}")) this.xterm.write(this.wrapperError(this.$t('assets.UnselectedAssets')))
return
}
if (!command) {
this.xterm.write(this.wrapperError(this.$t('assets.NoInputCommand')))
return return
} }
// if (!command) {
// this.xterm.write(this.wrapperError("{% trans 'No input command' %}"))
// return
// }
if (!runAs) { if (!runAs) {
this.xterm.write(this.wrapperError("{% trans 'No system user was selected' %}")) this.xterm.write(this.wrapperError(this.$t('assets.NoSystemUserWasSelected')))
return return
} }
const data = {
hosts: hosts,
run_as: runAs,
command: command
}
this.$axios.post(
url, data
).then(res => {
this.writeExecutionOutput(res.id)
console.log('success')
})
} }
} }
} }