Skip to content

Commit b61dae6

Browse files
authored
fix(forward): Fix the problem of duplicate creation of port forwardin… (#7975)
Refs #7969
1 parent 872a93a commit b61dae6

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

backend/app/dto/firewall.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ type PortRuleOperate struct {
3030
}
3131

3232
type ForwardRuleOperate struct {
33-
Rules []struct {
33+
ForceDelete bool `json:"forceDelete"`
34+
Rules []struct {
3435
Operation string `json:"operation" validate:"required,oneof=add remove"`
3536
Num string `json:"num"`
3637
Protocol string `json:"protocol" validate:"required,oneof=tcp udp tcp/udp"`

backend/app/service/firewall.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ func (u *FirewallService) OperateForwardRule(req dto.ForwardRuleOperate) error {
381381
TargetIP: r.TargetIP,
382382
TargetPort: r.TargetPort,
383383
}, r.Operation); err != nil {
384+
if req.ForceDelete {
385+
global.LOG.Error(err)
386+
continue
387+
}
384388
return err
385389
}
386390
}

frontend/src/api/modules/host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const operateFire = (operation: string) => {
9898
export const operatePortRule = (params: Host.RulePort) => {
9999
return http.post<Host.RulePort>(`/hosts/firewall/port`, params, TimeoutEnum.T_40S);
100100
};
101-
export const operateForwardRule = (params: { rules: Host.RuleForward[] }) => {
101+
export const operateForwardRule = (params: { rules: Host.RuleForward[]; forceDelete: boolean }) => {
102102
return http.post<Host.RulePort>(`/hosts/firewall/forward`, params, TimeoutEnum.T_40S);
103103
};
104104
export const operateIPRule = (params: Host.RuleIP) => {

frontend/src/views/host/firewall/forward/index.vue

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,18 @@
7777
</div>
7878
</div>
7979

80-
<OpDialog ref="opRef" @search="search" />
80+
<OpDialog ref="opRef" @search="search" @submit="onSubmitDelete()">
81+
<template #content>
82+
<el-form class="mt-4 mb-1" ref="deleteForm" label-position="left">
83+
<el-form-item>
84+
<el-checkbox v-model="forceDelete" :label="$t('website.forceDelete')" />
85+
<span class="input-help">
86+
{{ $t('website.forceDeleteHelper') }}
87+
</span>
88+
</el-form-item>
89+
</el-form>
90+
</template>
91+
</OpDialog>
8192
<OperateDialog @search="search" ref="dialogRef" />
8293
</div>
8394
</template>
@@ -91,6 +102,7 @@ import { operateForwardRule, searchFireRule } from '@/api/modules/host';
91102
import { Host } from '@/api/interface/host';
92103
import i18n from '@/lang';
93104
import { GlobalStore } from '@/store';
105+
import { MsgSuccess } from '@/utils/message';
94106
95107
const globalStore = GlobalStore();
96108
@@ -107,6 +119,8 @@ const fireName = ref();
107119
const fireStatusRef = ref();
108120
109121
const opRef = ref();
122+
const forceDelete = ref(false);
123+
const operateRules = ref();
110124
111125
const data = ref();
112126
const paginationConfig = reactive({
@@ -180,18 +194,32 @@ const onDelete = async (row: Host.RuleForward | null) => {
180194
});
181195
}
182196
}
197+
operateRules.value = rules;
183198
opRef.value.acceptParams({
184199
title: i18n.global.t('commons.button.delete'),
185200
names: names,
186201
msg: i18n.global.t('commons.msg.operatorHelper', [
187202
i18n.global.t('firewall.forwardRule'),
188203
i18n.global.t('commons.button.delete'),
189204
]),
190-
api: operateForwardRule,
191-
params: { rules: rules },
205+
api: null,
206+
params: null,
192207
});
193208
};
194209
210+
const onSubmitDelete = async () => {
211+
loading.value = true;
212+
await operateForwardRule({ rules: operateRules.value, forceDelete: forceDelete.value })
213+
.then(() => {
214+
loading.value = false;
215+
MsgSuccess(i18n.global.t('commons.msg.deleteSuccess'));
216+
search();
217+
})
218+
.catch(() => {
219+
loading.value = false;
220+
});
221+
};
222+
195223
const buttons = [
196224
{
197225
label: i18n.global.t('commons.button.edit'),
@@ -208,6 +236,7 @@ const buttons = [
208236
];
209237
210238
onMounted(() => {
239+
forceDelete.value = false;
211240
if (fireName.value !== '-') {
212241
loading.value = true;
213242
fireStatusRef.value.acceptParams();

0 commit comments

Comments
 (0)