Skip to content

Commit

Permalink
U 自动移除命令中换行包含的\r
Browse files Browse the repository at this point in the history
  • Loading branch information
vapao committed Mar 12, 2020
1 parent e285faf commit 17dfe26
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
5 changes: 5 additions & 0 deletions spug_web/src/libs/functools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 7 additions & 6 deletions spug_web/src/pages/deploy/app/Ext1Setup3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'}}/>
</Form.Item>
<Form.Item
Expand All @@ -100,7 +101,7 @@ class Ext1Setup3 extends React.Component {
height={full === '3' ? '100vh' : '100px'}
placeholder="输入要执行的命令"
value={info['hook_pre_server']}
onChange={v => info['hook_pre_server'] = v}
onChange={v => info['hook_pre_server'] = cleanCommand(v)}
style={{border: '1px solid #e8e8e8'}}/>
</Form.Item>
<Form.Item
Expand All @@ -114,7 +115,7 @@ class Ext1Setup3 extends React.Component {
height={full === '5' ? '100vh' : '100px'}
placeholder="输入要执行的命令"
value={info['hook_pre_host']}
onChange={v => info['hook_pre_host'] = v}
onChange={v => info['hook_pre_host'] = cleanCommand(v)}
style={{border: '1px solid #e8e8e8'}}/>
</Form.Item>
</Col>
Expand Down Expand Up @@ -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'}}/>
</Form.Item>
<Form.Item
Expand All @@ -158,7 +159,7 @@ class Ext1Setup3 extends React.Component {
height={full === '4' ? '100vh' : '100px'}
placeholder="输入要执行的命令"
value={info['hook_post_server']}
onChange={v => info['hook_post_server'] = v}
onChange={v => info['hook_post_server'] = cleanCommand(v)}
style={{border: '1px solid #e8e8e8'}}/>
</Form.Item>
<Form.Item
Expand All @@ -172,7 +173,7 @@ class Ext1Setup3 extends React.Component {
height={full === '6' ? '100vh' : '100px'}
placeholder="输入要执行的命令"
value={info['hook_post_host']}
onChange={v => info['hook_post_host'] = v}
onChange={v => info['hook_post_host'] = cleanCommand(v)}
style={{border: '1px solid #e8e8e8'}}/>
</Form.Item>
</Col>
Expand Down
9 changes: 5 additions & 4 deletions spug_web/src/pages/deploy/app/Ext2Setup3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,7 +51,8 @@ class Ext2Setup3 extends React.Component {
style={{margin: '0 80px 20px'}}
description={[
<p key={1}>Spug 将遵循先本地后目标主机的原则,按照顺序依次执行添加的动作,例如:本地动作1 -> 本地动作2 -> 目标主机动作1 -> 目标主机动作2 ...</p>,
<p key={2}>执行的命令内可以使用发布申请中设置的环境变量 SPUG_RELEASE,一般可用于标记一次发布的版本号或提交ID等,在执行的脚本内通过使用 $SPUG_RELEASE 获取其值来执行相应操作。</p>
<p key={2}>执行的命令内可以使用发布申请中设置的环境变量 SPUG_RELEASE,一般可用于标记一次发布的版本号或提交ID等,在执行的脚本内通过使用 $SPUG_RELEASE
获取其值来执行相应操作。</p>
]}/>
)}
{server_actions.map((item, index) => (
Expand All @@ -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="请输入要执行的动作"/>
</Form.Item>
<div className={styles.delAction} onClick={() => server_actions.splice(index, 1)}>
Expand All @@ -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="请输入要执行的动作"/>
</Form.Item>
<div className={styles.delAction} onClick={() => host_actions.splice(index, 1)}>
Expand Down
4 changes: 2 additions & 2 deletions spug_web/src/pages/exec/task/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}))
};
Expand Down
4 changes: 2 additions & 2 deletions spug_web/src/pages/exec/template/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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('操作成功');
Expand Down
4 changes: 2 additions & 2 deletions spug_web/src/pages/monitor/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -158,7 +158,7 @@ class ComForm extends React.Component {
</Form.Item>
<Form.Item required label="脚本内容" style={this.getStyle('4')}
extra={<LinkButton onClick={() => this.setState({showTmp: true})}>从模板添加</LinkButton>}>
<ACEditor mode="sh" value={extra['4']} height="200px" onChange={e => this.handleExtra('4', e)}/>
<ACEditor mode="sh" value={extra['4']} height="200px" onChange={e => this.handleExtra('4', cleanCommand(e))}/>
</Form.Item>
<Form.Item label="备注信息">
{getFieldDecorator('desc', {initialValue: info['desc']})(
Expand Down
4 changes: 2 additions & 2 deletions spug_web/src/pages/schedule/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 17dfe26

Please sign in to comment.