diff --git a/agent/app/dto/firewall.go b/agent/app/dto/firewall.go
index a5150b521..f926ed9d2 100644
--- a/agent/app/dto/firewall.go
+++ b/agent/app/dto/firewall.go
@@ -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"`
}
diff --git a/agent/app/repo/host.go b/agent/app/repo/host.go
index 0d399229b..374dbcddf 100644
--- a/agent/app/repo/host.go
+++ b/agent/app/repo/host.go
@@ -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
}
diff --git a/agent/app/service/firewall.go b/agent/app/service/firewall.go
index b6b566988..a00c44216 100644
--- a/agent/app/service/firewall.go
+++ b/agent/app/service/firewall.go
@@ -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,
diff --git a/agent/app/service/iptables.go b/agent/app/service/iptables.go
index 0df6d62ee..56f3e952e 100644
--- a/agent/app/service/iptables.go
+++ b/agent/app/service/iptables.go
@@ -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,
}
diff --git a/frontend/src/api/interface/host.ts b/frontend/src/api/interface/host.ts
index e35937c30..98d3285e8 100644
--- a/frontend/src/api/interface/host.ts
+++ b/frontend/src/api/interface/host.ts
@@ -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;
diff --git a/frontend/src/views/host/firewall/advance/index.vue b/frontend/src/views/host/firewall/advance/index.vue
index f9c2dd2ac..ec7c3fa21 100644
--- a/frontend/src/views/host/firewall/advance/index.vue
+++ b/frontend/src/views/host/firewall/advance/index.vue
@@ -96,11 +96,13 @@
- {{ row.strategy }}
-
- {{ row.strategy }}
+
+ {{ $t('firewall.accept') }}
-
+
+ {{ $t('firewall.drop') }}
+
+
{{ row.strategy }}
{{ row.strategy }}
@@ -111,7 +113,11 @@
:label="$t('commons.table.description')"
prop="description"
show-overflow-tooltip
- />
+ >
+
+
+
+
{
});
};
+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'),
diff --git a/frontend/src/views/host/firewall/advance/operate/index.vue b/frontend/src/views/host/firewall/advance/operate/index.vue
index 5896f4e24..d34dc3f95 100644
--- a/frontend/src/views/host/firewall/advance/operate/index.vue
+++ b/frontend/src/views/host/firewall/advance/operate/index.vue
@@ -44,8 +44,8 @@
- {{ $t('firewall.accept') }}
- {{ $t('firewall.drop') }}
+ {{ $t('firewall.accept') }}
+ {{ $t('firewall.drop') }}
diff --git a/frontend/src/views/host/firewall/ip/index.vue b/frontend/src/views/host/firewall/ip/index.vue
index bd8d9fdb4..735c2ba22 100644
--- a/frontend/src/views/host/firewall/ip/index.vue
+++ b/frontend/src/views/host/firewall/ip/index.vue
@@ -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'));
};
diff --git a/frontend/src/views/host/firewall/port/index.vue b/frontend/src/views/host/firewall/port/index.vue
index 1feb41c00..ed9151ec3 100644
--- a/frontend/src/views/host/firewall/port/index.vue
+++ b/frontend/src/views/host/firewall/port/index.vue
@@ -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'));
};