1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

fix: 解决 ufw 防火墙创建多端口时无法删除的问题

This commit is contained in:
ssongliu 2023-08-17 10:21:14 +08:00
parent b7dada93da
commit 280e74e01b

View File

@ -166,59 +166,51 @@ func (u *FirewallService) OperatePortRule(req dto.PortRuleOperate, reload bool)
if err != nil { if err != nil {
return err return err
} }
protos := strings.Split(req.Protocol, "/")
if client.Name() == "ufw" { if client.Name() == "ufw" {
req.Port = strings.ReplaceAll(req.Port, "-", ":") if len(req.Address) == 0 {
if req.Operation == "remove" && req.Protocol == "tcp/udp" { req.Address = "Anywhere"
req.Protocol = ""
return u.operatePort(client, req)
} }
if strings.Contains(req.Port, ",") || strings.Contains(req.Port, "-") {
for _, proto := range protos {
req.Port = strings.ReplaceAll(req.Port, "-", ":")
req.Protocol = proto
if err := u.operatePort(client, req); err != nil {
return err
}
}
return nil
}
if req.Protocol == "tcp/udp" {
req.Protocol = ""
}
if err := u.operatePort(client, req); err != nil {
return err
}
return nil
} }
if req.Protocol == "tcp/udp" {
if client.Name() == "firewalld" && strings.Contains(req.Port, ",") { for _, proto := range protos {
if strings.Contains(req.Port, "-") {
req.Protocol = proto
if err := u.operatePort(client, req); err != nil {
return err
}
} else {
ports := strings.Split(req.Port, ",") ports := strings.Split(req.Port, ",")
for _, port := range ports { for _, port := range ports {
if len(port) == 0 { if len(port) == 0 {
continue continue
} }
req.Port = port req.Port = port
req.Protocol = "tcp" req.Protocol = proto
if err := u.operatePort(client, req); err != nil { if err := u.operatePort(client, req); err != nil {
return err return err
} }
req.Protocol = "udp"
if err := u.operatePort(client, req); err != nil {
return err
}
}
} else {
req.Protocol = "tcp"
if err := u.operatePort(client, req); err != nil {
return err
}
req.Protocol = "udp"
if err := u.operatePort(client, req); err != nil {
return err
}
}
} else {
if strings.Contains(req.Port, ",") {
ports := strings.Split(req.Port, ",")
for _, port := range ports {
req.Port = port
if err := u.operatePort(client, req); err != nil {
return err
}
}
} else {
if err := u.operatePort(client, req); err != nil {
return err
} }
} }
} }
if reload { return client.Reload()
return client.Reload()
}
return nil
} }
func (u *FirewallService) OperateAddressRule(req dto.AddrRuleOperate, reload bool) error { func (u *FirewallService) OperateAddressRule(req dto.AddrRuleOperate, reload bool) error {