diff --git a/spug_web/src/libs/functools.js b/spug_web/src/libs/functools.js index 1d31655..75214d4 100644 --- a/spug_web/src/libs/functools.js +++ b/spug_web/src/libs/functools.js @@ -26,6 +26,11 @@ export function hasPermission(strCode) { return false } +// 清理输入的命令中包含的\r符号 +export function cleanCommand(text) { + return text ? text.replace(/\r\n/g, '\n') : '' +} + // 数组包含关系判断 export function isSubArray(parent, child) { for (let item of child) { diff --git a/spug_web/src/pages/deploy/app/Ext1Setup3.js b/spug_web/src/pages/deploy/app/Ext1Setup3.js index f16103c..f3e0329 100644 --- a/spug_web/src/pages/deploy/app/Ext1Setup3.js +++ b/spug_web/src/pages/deploy/app/Ext1Setup3.js @@ -14,6 +14,7 @@ import 'ace-builds/src-noconflict/theme-tomorrow'; import store from './store'; import http from 'libs/http'; import styles from './index.module.css'; +import { cleanCommand } from "../../../libs"; @observer class Ext1Setup3 extends React.Component { @@ -86,7 +87,7 @@ class Ext1Setup3 extends React.Component { height={full === '1' ? '100vh' : '100px'} placeholder="每行一条规则" value={info['filter_rule']['data']} - onChange={v => info['filter_rule']['data'] = v} + onChange={v => info['filter_rule']['data'] = cleanCommand(v)} style={{border: '1px solid #e8e8e8'}}/> info['hook_pre_server'] = v} + onChange={v => info['hook_pre_server'] = cleanCommand(v)} style={{border: '1px solid #e8e8e8'}}/> info['hook_pre_host'] = v} + onChange={v => info['hook_pre_host'] = cleanCommand(v)} style={{border: '1px solid #e8e8e8'}}/> @@ -144,7 +145,7 @@ class Ext1Setup3 extends React.Component { height={full === '2' ? '100vh' : '100px'} placeholder="每行一个,例如:HOME=/data/spug" value={info['custom_envs']} - onChange={v => info['custom_envs'] = v} + onChange={v => info['custom_envs'] = cleanCommand(v)} style={{border: '1px solid #e8e8e8'}}/> info['hook_post_server'] = v} + onChange={v => info['hook_post_server'] = cleanCommand(v)} style={{border: '1px solid #e8e8e8'}}/> info['hook_post_host'] = v} + onChange={v => info['hook_post_host'] = cleanCommand(v)} style={{border: '1px solid #e8e8e8'}}/> diff --git a/spug_web/src/pages/deploy/app/Ext2Setup3.js b/spug_web/src/pages/deploy/app/Ext2Setup3.js index c80bf1f..37b82ce 100644 --- a/spug_web/src/pages/deploy/app/Ext2Setup3.js +++ b/spug_web/src/pages/deploy/app/Ext2Setup3.js @@ -10,7 +10,7 @@ import Editor from 'react-ace'; import 'ace-builds/src-noconflict/mode-sh'; import 'ace-builds/src-noconflict/theme-tomorrow'; import styles from './index.module.css'; -import http from 'libs/http'; +import { http, cleanCommand } from 'libs'; import store from './store'; @observer @@ -51,7 +51,8 @@ class Ext2Setup3 extends React.Component { style={{margin: '0 80px 20px'}} description={[

Spug 将遵循先本地后目标主机的原则,按照顺序依次执行添加的动作,例如:本地动作1 -> 本地动作2 -> 目标主机动作1 -> 目标主机动作2 ...

, -

执行的命令内可以使用发布申请中设置的环境变量 SPUG_RELEASE,一般可用于标记一次发布的版本号或提交ID等,在执行的脚本内通过使用 $SPUG_RELEASE 获取其值来执行相应操作。

+

执行的命令内可以使用发布申请中设置的环境变量 SPUG_RELEASE,一般可用于标记一次发布的版本号或提交ID等,在执行的脚本内通过使用 $SPUG_RELEASE + 获取其值来执行相应操作。

]}/> )} {server_actions.map((item, index) => ( @@ -67,7 +68,7 @@ class Ext2Setup3 extends React.Component { width="100%" height="100px" value={item['data']} - onChange={v => item['data'] = v} + onChange={v => item['data'] = cleanCommand(v)} placeholder="请输入要执行的动作"/>
server_actions.splice(index, 1)}> @@ -94,7 +95,7 @@ class Ext2Setup3 extends React.Component { width="100%" height="100px" value={item['data']} - onChange={v => item['data'] = v} + onChange={v => item['data'] = cleanCommand(v)} placeholder="请输入要执行的动作"/>
host_actions.splice(index, 1)}> diff --git a/spug_web/src/pages/exec/task/index.js b/spug_web/src/pages/exec/task/index.js index a11a3a2..6672c6c 100644 --- a/spug_web/src/pages/exec/task/index.js +++ b/spug_web/src/pages/exec/task/index.js @@ -10,8 +10,8 @@ import { ACEditor, AuthCard } from 'components'; import HostSelector from './HostSelector'; import TemplateSelector from './TemplateSelector'; import ExecConsole from './ExecConsole'; +import { http, cleanCommand } from 'libs'; import store from './store'; -import http from 'libs/http'; @observer class TaskIndex extends React.Component { @@ -26,7 +26,7 @@ class TaskIndex extends React.Component { handleSubmit = () => { this.setState({loading: true}); const host_ids = store.hosts.map(item => item.id); - http.post('/api/exec/do/', {host_ids, command: this.state.body}) + http.post('/api/exec/do/', {host_ids, command: cleanCommand(this.state.body)}) .then(store.switchConsole) .finally(() => this.setState({loading: false})) }; diff --git a/spug_web/src/pages/exec/template/Form.js b/spug_web/src/pages/exec/template/Form.js index 413d51f..60925a7 100644 --- a/spug_web/src/pages/exec/template/Form.js +++ b/spug_web/src/pages/exec/template/Form.js @@ -7,7 +7,7 @@ import React from 'react'; import { observer } from 'mobx-react'; import { Modal, Form, Input, Select, Col, Button, message } from 'antd'; import { ACEditor } from 'components'; -import http from 'libs/http'; +import { http, cleanCommand } from 'libs'; import store from './store'; @observer @@ -25,7 +25,7 @@ class ComForm extends React.Component { this.setState({loading: true}); const formData = this.props.form.getFieldsValue(); formData['id'] = store.record.id; - formData['body'] = this.state.body; + formData['body'] = cleanCommand(this.state.body); http.post('/api/exec/template/', formData) .then(res => { message.success('操作成功'); diff --git a/spug_web/src/pages/monitor/Form.js b/spug_web/src/pages/monitor/Form.js index 05a4d17..9c1609e 100644 --- a/spug_web/src/pages/monitor/Form.js +++ b/spug_web/src/pages/monitor/Form.js @@ -8,7 +8,7 @@ import { observer } from 'mobx-react'; import { Modal, Form, Input, Select, Radio, message, Steps, Button, Transfer, Checkbox } from 'antd'; import TemplateSelector from '../exec/task/TemplateSelector'; import { LinkButton, ACEditor } from 'components'; -import http from 'libs/http'; +import { http, cleanCommand } from 'libs'; import store from './store'; import hostStore from '../host/store'; import groupStore from '../alarm/group/store'; @@ -158,7 +158,7 @@ class ComForm extends React.Component { this.setState({showTmp: true})}>从模板添加}> - this.handleExtra('4', e)}/> + this.handleExtra('4', cleanCommand(e))}/> {getFieldDecorator('desc', {initialValue: info['desc']})( diff --git a/spug_web/src/pages/schedule/Form.js b/spug_web/src/pages/schedule/Form.js index a8149f1..37a4780 100644 --- a/spug_web/src/pages/schedule/Form.js +++ b/spug_web/src/pages/schedule/Form.js @@ -8,7 +8,7 @@ import { observer } from 'mobx-react'; import { Modal, Form, Input, Select, Col, Button, Steps, Tabs, InputNumber, DatePicker, Icon, message } from 'antd'; import { LinkButton, ACEditor } from 'components'; import TemplateSelector from '../exec/task/TemplateSelector'; -import http from 'libs/http'; +import { http, cleanCommand } from 'libs'; import store from './store'; import hostStore from '../host/store'; import styles from './index.module.css'; @@ -51,7 +51,7 @@ class ComForm extends React.Component { } this.setState({loading: true}); formData['id'] = store.record.id; - formData['command'] = this.state.command; + formData['command'] = cleanCommand(this.state.command); formData['targets'] = store.targets.filter(x => x); formData['trigger_args'] = this._parse_args(formData['trigger']); http.post('/api/schedule/', formData)