| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- <template>
- <base-dialog @cancel="cancelDialog">
- <div slot="header">{{$t('compute.text_991')}}</div>
- <div slot="body">
- <a-form
- :form="form.fc">
- <a-form-item :label="$t('compute.text_990')" v-bind="formItemLayout">
- <a-radio-group v-decorator="decorators.direction" @change="decoratorsChange">
- <a-radio value="in">{{$t('compute.text_993')}}</a-radio>
- <a-radio value="out">{{$t('compute.text_994')}}</a-radio>
- </a-radio-group>
- </a-form-item>
- <a-form-item :label="$t('compute.text_175')" v-bind="formItemLayout">
- <a-select
- v-decorator="decorators.type"
- :disabled="typeDisabled"
- :placeholder="$t('compute.text_219')"
- @change="typeChange">
- <a-select-option v-for="item in typeOptions" :key="item.value" :value="item.value">
- {{item.label}}
- </a-select-option>
- </a-select>
- </a-form-item>
- <a-form-item v-bind="formItemLayout">
- <span slot="label">
- {{decLabel}}
- <a-tooltip :title="$t('compute.text_995')">
- <a-icon type="question-circle-o" />
- </a-tooltip>
- </span>
- <a-input :disabled="IPCheckboxDisabled" v-decorator="decorators.cidr" :placeholder="$t('compute.text_996')" />
- <a-checkbox class="right-checkbox" @change="cidrChange">{{$t('compute.text_997')}}</a-checkbox>
- </a-form-item>
- <a-form-item :label="$t('compute.text_980')" v-bind="formItemLayout">
- <a-select v-decorator="decorators.protocol" @change="protocolChange" :disabled="protocolDisabled">
- <a-select-option v-for="item in protocolOptions" :key="item.value" :value="item.value">
- {{item.label}}
- </a-select-option>
- </a-select>
- </a-form-item>
- <a-form-item v-bind="formItemLayout">
- <span slot="label">{{$t('compute.text_998')}}<a-tooltip :title="$t('compute.text_999')">
- <a-icon type="question-circle-o" />
- </a-tooltip>
- </span>
- <a-input :disabled="portsDisabled" v-decorator="decorators.ports" :placeholder="$t('compute.text_350')" />
- <a-checkbox class="right-checkbox" @change="portsChange" :checked="portsChecked" :disabled="portsCheckboxDisabled">{{$t('compute.text_1000')}}</a-checkbox>
- </a-form-item>
- <a-form-item :label="$t('compute.text_694')" v-bind="formItemLayout">
- <a-select v-decorator="decorators.action">
- <a-select-option v-for="item in actionOptions" :key="item.value" :value="item.value">
- {{item.label}}
- </a-select-option>
- </a-select>
- </a-form-item>
- <a-form-item v-bind="formItemLayout">
- <span slot="label">{{$t('compute.text_1001')}}<a-tooltip :title="$t('compute.text_1002')">
- <a-icon type="question-circle-o" />
- </a-tooltip>
- </span>
- <a-input-number :min="1" :max="100" v-decorator="decorators.priority" />
- </a-form-item>
- </a-form>
- <dialog-selected-tips :name="$t('dictionary.secgroup')" :count="params.data.length" :action="$t('compute.text_991')" />
- <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
- </div>
- <div slot="footer">
- <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
- <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
- </div>
- </base-dialog>
- </template>
- <script>
- import { validate } from '@/utils/validate'
- import DialogMixin from '@/mixins/dialog'
- import WindowsMixin from '@/mixins/windows'
- export default {
- name: 'AddRulesDialog',
- mixins: [DialogMixin, WindowsMixin],
- data () {
- return {
- loading: false,
- form: {
- fc: this.$form.createForm(this),
- },
- decorators: {
- direction: [
- 'direction',
- {
- initialValue: 'in',
- },
- ],
- type: [
- 'type',
- ],
- cidr: [
- 'cidr',
- {
- validateFirst: true,
- rules: [
- { required: true, message: this.$t('compute.text_996') },
- { validator: this.$validate(['cidr', 'IPv4', 'cidr6', 'IPv6'], true, 'some') },
- ],
- },
- ],
- protocol: [
- 'protocol',
- {
- initialValue: 'tcp',
- },
- ],
- ports: [
- 'ports',
- {
- rules: [
- { required: true, message: this.$t('compute.text_347') },
- { validator: this.validatePorts },
- ],
- },
- ],
- action: [
- 'action',
- {
- initialValue: 'allow',
- rules: [
- { required: true },
- ],
- },
- ],
- priority: [
- 'priority',
- {
- initialValue: 1,
- },
- ],
- },
- formItemLayout: {
- wrapperCol: {
- span: 8,
- },
- labelCol: {
- span: 3,
- },
- },
- typeOptions: [
- { label: this.$t('compute.text_144'), value: 'custom', description: '' },
- { label: this.$t('compute.text_1003'), value: 'windows', description: this.$t('compute.text_1004') },
- { label: 'SSH (22)', value: 'linux', description: this.$t('compute.text_1005') },
- { label: 'HTTP(80)', value: 'http', description: this.$t('compute.text_1006') },
- { label: 'HTTPS(443)', value: 'https', description: this.$t('compute.text_1007') },
- { label: 'Ping', value: 'ping', description: this.$t('compute.text_1008') },
- ],
- protocolOptions: [
- { label: 'TCP', value: 'tcp' },
- { label: 'UDP', value: 'udp' },
- { label: 'ICMP', value: 'icmp' },
- { label: this.$t('compute.any_protocol.text'), value: 'any' },
- ],
- actionOptions: [
- { label: this.$t('compute.text_976'), value: 'allow' },
- { label: this.$t('compute.text_977'), value: 'deny' },
- ],
- typeDisabled: false,
- IPCheckboxDisabled: false,
- portsDisabled: false,
- portsCheckboxDisabled: false,
- portsChecked: false,
- protocolDisabled: this.params.title !== 'edit',
- decLabel: this.$t('compute.text_979'),
- }
- },
- methods: {
- validatePorts (rule, value, callback) {
- const ports = value.indexOf(',') !== -1 ? value.split(',') : value.split('-')
- if (ports.length > 1) {
- const pass = ports.every(function (item, index) {
- return +item && item >= 0 && item <= 65535
- })
- if (!pass) {
- if (validate(value, 'ports') === false || validate(value, 'ports').result === false) {
- callback(new Error(validate(value, 'ports').msg))
- }
- callback()
- } else {
- callback()
- }
- } else {
- if (value === 'ALL') {
- callback()
- } else {
- if (validate(value, 'ports') === false || validate(value, 'ports').result === false) {
- callback(new Error(validate(value, 'ports').msg))
- }
- callback()
- }
- }
- },
- typeChange (e) {
- if (e === 'windows') {
- this.form.fc.setFieldsValue({ ports: '3389' })
- this.portsChecked = false
- this.portsDisabled = true
- this.portsCheckboxDisabled = true
- this.protocolDisabled = true
- } else if (e === 'linux') {
- this.form.fc.setFieldsValue({ ports: '22' })
- this.portsChecked = false
- this.portsDisabled = true
- this.portsCheckboxDisabled = true
- this.protocolDisabled = true
- } else if (e === 'http') {
- this.form.fc.setFieldsValue({ ports: '80' })
- this.portsChecked = false
- this.portsDisabled = true
- this.portsCheckboxDisabled = true
- this.protocolDisabled = true
- } else if (e === 'https') {
- this.form.fc.setFieldsValue({ ports: '443' })
- this.portsChecked = false
- this.portsDisabled = true
- this.portsCheckboxDisabled = true
- this.protocolDisabled = true
- } else if (e === 'ping') {
- this.form.fc.setFieldsValue({ ports: 'ALL', protocol: 'icmp' })
- this.portsChecked = true
- this.portsDisabled = true
- this.portsCheckboxDisabled = true
- this.protocolDisabled = true
- } else {
- this.portsChecked = false
- this.portsDisabled = false
- this.form.fc.resetFields(['ports'])
- this.portsCheckboxDisabled = false
- this.protocolDisabled = false
- }
- },
- protocolChange (e) {
- if (e === 'icmp') {
- this.portsChecked = true
- this.portsDisabled = true
- this.form.fc.setFieldsValue({ ports: 'ALL' })
- this.portsCheckboxDisabled = true
- } else {
- this.portsCheckboxDisabled = false
- }
- if (e === 'any') {
- this.portsChecked = true
- this.form.fc.setFieldsValue({ ports: 'ALL' })
- this.form.fc.setFieldsValue({ type: 'custom' })
- this.portsCheckboxDisabled = true
- this.portsDisabled = true
- this.typeDisabled = true
- } else {
- this.portsCheckboxDisabled = false
- this.typeDisabled = false
- }
- },
- decoratorsChange (e) {
- if (e.target.value === 'out') {
- this.decLabel = this.$t('compute.text_978')
- } else {
- this.decLabel = this.$t('compute.text_979')
- }
- this.form.fc.resetFields()
- },
- cidrChange (e) {
- this.IPCheckboxDisabled = !this.IPCheckboxDisabled
- if (e.target.checked) {
- this.form.fc.setFieldsValue({ cidr: '0.0.0.0/0' })
- } else {
- this.form.fc.resetFields(['cidr'])
- }
- },
- portsChange (e) {
- this.portsChecked = !this.portsChecked
- this.portsDisabled = !this.portsDisabled
- if (e.target.checked) {
- this.form.fc.setFieldsValue({ ports: 'ALL' })
- } else {
- this.form.fc.resetFields(['ports'])
- }
- },
- doAdd (data) {
- const ids = this.params.data.map(v => v.id)
- return new this.$Manager('secgroups').batchPerformAction({
- action: 'add-rule',
- ids,
- data,
- })
- },
- async handleConfirm () {
- this.loading = true
- try {
- const values = await this.form.fc.validateFields()
- if (values.ports === 'ALL') {
- values.ports = ''
- }
- let description = ''
- this.typeOptions.forEach((item) => {
- if (item.value === values.type) {
- description = item.description
- }
- })
- values.description = description
- await this.doAdd(values)
- this.loading = false
- this.params.refresh()
- this.cancelDialog()
- } finally {
- this.loading = false
- }
- },
- },
- }
- </script>
- <style lang="less" scoped>
- .right-checkbox {
- width: 100px;
- height: 40px;
- left: 270px;
- font-size: 12px!important;
- color: #ccc;
- position: absolute;
- }
- </style>
|