mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-23 00:00:52 +00:00
fix: Fix the issue where iptables description does not take effect (#10947)
This commit is contained in:
@@ -50,8 +50,11 @@ type ForwardRuleOperate struct {
|
||||
|
||||
type UpdateFirewallDescription struct {
|
||||
Type string `json:"type"`
|
||||
Address string `json:"address"`
|
||||
Port string `json:"port"`
|
||||
Chain string `json:"chain"`
|
||||
SrcIP string `json:"srcIP"`
|
||||
DstIP string `json:"dstIP"`
|
||||
SrcPort string `json:"srcPort"`
|
||||
DstPort string `json:"dstPort"`
|
||||
Protocol string `json:"protocol"`
|
||||
Strategy string `json:"strategy" validate:"required,oneof=accept drop"`
|
||||
|
||||
@@ -96,7 +99,7 @@ type IptablesRuleOp struct {
|
||||
SrcPort uint `json:"srcPort"`
|
||||
DstIP string `json:"dstIP"`
|
||||
DstPort uint `json:"dstPort"`
|
||||
Strategy string `json:"strategy" validate:"required,oneof=ACCEPT DROP REJECT"`
|
||||
Strategy string `json:"strategy" validate:"required,oneof=accept drop reject"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
|
||||
+20
-9
@@ -57,16 +57,27 @@ func (h *HostRepo) SaveFirewallRecord(firewall *model.Firewall) error {
|
||||
return global.DB.Save(firewall).Error
|
||||
}
|
||||
var data model.Firewall
|
||||
if firewall.Type == "port" {
|
||||
_ = global.DB.Where("type = ? AND dst_port = ? AND protocol = ? AND src_ip = ? AND strategy = ?", "port", firewall.DstPort, firewall.Protocol, firewall.SrcIP, firewall.Strategy).First(&data)
|
||||
if data.ID != 0 {
|
||||
firewall.ID = data.ID
|
||||
}
|
||||
} else {
|
||||
switch firewall.Type {
|
||||
case "port":
|
||||
_ = global.DB.Where("type = ? AND dst_port = ? AND protocol = ? AND src_ip = ? AND strategy = ?", "port",
|
||||
firewall.DstPort,
|
||||
firewall.Protocol,
|
||||
firewall.SrcIP,
|
||||
firewall.Strategy,
|
||||
).First(&data).Error
|
||||
case "ip":
|
||||
_ = global.DB.Where("type = ? AND src_ip = ? AND strategy = ?", "address", firewall.SrcIP, firewall.Strategy).First(&data)
|
||||
if data.ID != 0 {
|
||||
firewall.ID = data.ID
|
||||
}
|
||||
default:
|
||||
_ = global.DB.Where("type = ? AND chain = ? AND src_port = ? AND dst_port = ? AND protocol = ? AND src_ip = ? AND dst_ip = ? AND strategy = ?",
|
||||
firewall.Type,
|
||||
firewall.Chain,
|
||||
firewall.SrcPort,
|
||||
firewall.DstPort,
|
||||
firewall.Protocol,
|
||||
firewall.SrcIP,
|
||||
firewall.DstIP,
|
||||
firewall.Strategy,
|
||||
).First(&data).Error
|
||||
}
|
||||
return global.DB.Save(firewall).Error
|
||||
}
|
||||
|
||||
@@ -475,9 +475,11 @@ func (u *FirewallService) UpdateAddrRule(req dto.AddrRuleUpdate) error {
|
||||
func (u *FirewallService) UpdateDescription(req dto.UpdateFirewallDescription) error {
|
||||
firewall := model.Firewall{
|
||||
Type: req.Type,
|
||||
Chain: iptables.Chain1PanelBasic,
|
||||
SrcIP: req.Address,
|
||||
DstPort: req.Port,
|
||||
Chain: req.Chain,
|
||||
SrcIP: req.SrcIP,
|
||||
DstIP: req.DstIP,
|
||||
SrcPort: req.SrcPort,
|
||||
DstPort: req.DstPort,
|
||||
Protocol: req.Protocol,
|
||||
Strategy: req.Strategy,
|
||||
Description: req.Description,
|
||||
|
||||
@@ -100,9 +100,9 @@ func (s *IptablesService) OperateRule(req dto.IptablesRuleOp) error {
|
||||
Chain: req.Chain,
|
||||
Protocol: req.Protocol,
|
||||
SrcIP: req.SrcIP,
|
||||
SrcPort: fmt.Sprintf("%v", req.SrcPort),
|
||||
SrcPort: policy.SrcPort,
|
||||
DstIP: req.DstIP,
|
||||
DstPort: fmt.Sprintf("%v", req.DstPort),
|
||||
DstPort: policy.DstPort,
|
||||
Strategy: req.Strategy,
|
||||
Description: req.Description,
|
||||
}
|
||||
|
||||
@@ -95,8 +95,12 @@ export namespace Host {
|
||||
[key: string]: any;
|
||||
}
|
||||
export interface UpdateDescription {
|
||||
address: string;
|
||||
port: string;
|
||||
type: string;
|
||||
chain: string;
|
||||
srcIP: string;
|
||||
dstIP: string;
|
||||
srcPort: string;
|
||||
dstPort: string;
|
||||
protocol: string;
|
||||
strategy: string;
|
||||
description: string;
|
||||
|
||||
@@ -96,11 +96,13 @@
|
||||
</el-table-column>
|
||||
<el-table-column :min-width="100" :label="$t('firewall.action')" prop="strategy">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.strategy === 'ACCEPT'" type="success">{{ row.strategy }}</el-tag>
|
||||
<el-tag v-else-if="row.strategy === 'DROP'" type="danger">
|
||||
{{ row.strategy }}
|
||||
<el-tag v-if="row.strategy === 'accept'" type="success">
|
||||
{{ $t('firewall.accept') }}
|
||||
</el-tag>
|
||||
<el-tag v-else-if="row.strategy === 'REJECT'" type="warning">
|
||||
<el-tag v-else-if="row.strategy === 'drop'" type="danger">
|
||||
{{ $t('firewall.drop') }}
|
||||
</el-tag>
|
||||
<el-tag v-else-if="row.strategy === 'reject'" type="warning">
|
||||
{{ row.strategy }}
|
||||
</el-tag>
|
||||
<el-tag v-else type="info">{{ row.strategy }}</el-tag>
|
||||
@@ -111,7 +113,11 @@
|
||||
:label="$t('commons.table.description')"
|
||||
prop="description"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<fu-input-rw-switch v-model="row.description" @blur="onChange(row)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<fu-table-operations
|
||||
width="120px"
|
||||
:buttons="buttons"
|
||||
@@ -135,7 +141,13 @@ import FireRouter from '@/views/host/firewall/index.vue';
|
||||
import FireStatus from '@/views/host/firewall/status/index.vue';
|
||||
import OperateDialog from '@/views/host/firewall/advance/operate/index.vue';
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import { searchFilterRules, batchOperateFilterRule, loadChainStatus, operateFilterChain } from '@/api/modules/host';
|
||||
import {
|
||||
searchFilterRules,
|
||||
batchOperateFilterRule,
|
||||
loadChainStatus,
|
||||
operateFilterChain,
|
||||
updateFirewallDescription,
|
||||
} from '@/api/modules/host';
|
||||
import { Host } from '@/api/interface/host';
|
||||
import i18n from '@/lang';
|
||||
import { MsgSuccess } from '@/utils/message';
|
||||
@@ -247,7 +259,7 @@ const onOpenDialog = async (title: string, rowData?: Host.IptablesFilterRuleOp)
|
||||
rowData: rowData || {
|
||||
chain: selectedChain.value,
|
||||
protocol: 'tcp',
|
||||
strategy: 'ACCEPT',
|
||||
strategy: 'accept',
|
||||
srcPort: 0,
|
||||
dstPort: 0,
|
||||
},
|
||||
@@ -302,6 +314,23 @@ const onDelete = async (row: Host.IptablesRules | null) => {
|
||||
});
|
||||
};
|
||||
|
||||
const onChange = async (row: any) => {
|
||||
let params = {
|
||||
type: 'advance',
|
||||
chain: selectedChain.value,
|
||||
srcIP: row.srcIP,
|
||||
dstIP: row.dstIP,
|
||||
srcPort: row.srcPort,
|
||||
dstPort: row.dstPort,
|
||||
protocol: row.protocol,
|
||||
strategy: row.strategy,
|
||||
|
||||
description: row.description,
|
||||
};
|
||||
await updateFirewallDescription(params);
|
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||
};
|
||||
|
||||
const buttons = [
|
||||
{
|
||||
label: i18n.global.t('commons.button.delete'),
|
||||
|
||||
@@ -44,8 +44,8 @@
|
||||
|
||||
<el-form-item :label="$t('firewall.action')" prop="strategy">
|
||||
<el-radio-group v-model="dialogData.rowData!.strategy">
|
||||
<el-radio value="ACCEPT">{{ $t('firewall.accept') }}</el-radio>
|
||||
<el-radio value="DROP">{{ $t('firewall.drop') }}</el-radio>
|
||||
<el-radio value="accept">{{ $t('firewall.accept') }}</el-radio>
|
||||
<el-radio value="drop">{{ $t('firewall.drop') }}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
|
||||
@@ -192,9 +192,20 @@ const onOpenDialog = async (
|
||||
dialogRef.value!.acceptParams(params);
|
||||
};
|
||||
|
||||
const onChange = async (info: any) => {
|
||||
info.type = 'address';
|
||||
await updateFirewallDescription(info);
|
||||
const onChange = async (row: any) => {
|
||||
let params = {
|
||||
type: 'address',
|
||||
chain: fireName.value === 'iptables' ? '1PANEL_BASIC' : '',
|
||||
srcIP: row.address,
|
||||
dstIP: '',
|
||||
srcPort: '',
|
||||
dstPort: '',
|
||||
protocol: '',
|
||||
strategy: row.strategy,
|
||||
|
||||
description: row.description,
|
||||
};
|
||||
await updateFirewallDescription(params);
|
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||
};
|
||||
|
||||
|
||||
@@ -293,9 +293,20 @@ const onChangeStatus = async (row: Host.RuleInfo, status: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
const onChange = async (info: any) => {
|
||||
info.type = 'port';
|
||||
await updateFirewallDescription(info);
|
||||
const onChange = async (row: any) => {
|
||||
let params = {
|
||||
type: 'port',
|
||||
chain: fireName.value === 'iptables' ? '1PANEL_BASIC' : '',
|
||||
srcIP: row.address,
|
||||
dstIP: '',
|
||||
srcPort: '',
|
||||
dstPort: row.port,
|
||||
protocol: row.protocol,
|
||||
strategy: row.strategy,
|
||||
|
||||
description: row.description,
|
||||
};
|
||||
await updateFirewallDescription(params);
|
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user