Files
EdgeCommon/pkg/serverconfigs/firewallconfigs/firewall_actions.go

113 lines
3.6 KiB
Go
Raw Normal View History

package firewallconfigs
type FirewallActionType = string
const (
FirewallActionTypeIPSet FirewallActionType = "ipset"
FirewallActionTypeFirewalld FirewallActionType = "firewalld"
FirewallActionTypeIPTables FirewallActionType = "iptables"
FirewallActionTypeScript FirewallActionType = "script"
FirewallActionTypeHTTPAPI FirewallActionType = "httpAPI"
2021-02-26 16:32:16 +08:00
FirewallActionTypeHTML FirewallActionType = "html"
)
type FirewallActionTypeDefinition struct {
Name string `json:"name"`
Code FirewallActionType `json:"code"`
Description string `json:"description"`
}
func FindAllFirewallActionTypes() []*FirewallActionTypeDefinition {
return []*FirewallActionTypeDefinition{
{
Name: "ipset",
Code: FirewallActionTypeIPSet,
Description: "使用特定的ipset管理IP可以结合iptables和firewalld等工具一起工作。",
},
{
Name: "firewalld",
Code: FirewallActionTypeFirewalld,
Description: "使用Firewalld管理IP非持久保存reload之后重置规则。",
},
{
Name: "iptables",
Code: FirewallActionTypeIPTables,
Description: "使用IPTables管理IP不支持超时时间设定非持久保存reload之后重置规则。",
},
{
Name: "自定义脚本",
Code: FirewallActionTypeScript,
Description: "使用自定义的脚本执行IP操作。",
},
{
Name: "自定义HTTP API",
Code: FirewallActionTypeHTTPAPI,
Description: "使用自定义的HTTP API执行IP操作。",
},
2021-02-26 16:32:16 +08:00
{
Name: "显示HTML内容",
Code: FirewallActionTypeHTML,
Description: "显示一段自定义的HTML网页内容",
},
}
}
func FindFirewallActionTypeName(actionType FirewallActionType) string {
for _, a := range FindAllFirewallActionTypes() {
if a.Code == actionType {
return a.Name
}
}
return ""
}
type FirewallActionIPSetConfig struct {
2022-03-16 20:48:00 +08:00
Path string `json:"path"` // 命令路径 TODO 暂时不实现
WhiteName string `json:"whiteName"` // IPSet白名单名称
BlackName string `json:"blackName"` // IPSet黑名单名称
WhiteNameIPv6 string `json:"whiteNameIPv6"` // IPv6白名单名称
BlackNameIPv6 string `json:"blackNameIPv6"` // IPv6黑名单名称
MaxElements int `json:"maxElements"` // 最多IP数量 TODO 暂时不实现
AutoAddToIPTables bool `json:"autoAddToIPTables"` // 是否自动创建IPTables规则
AutoAddToFirewalld bool `json:"autoAddToFirewalld"` // 是否自动加入到Firewalld
// TODO 添加需要阻止的端口列表
}
type FirewallActionFirewalldConfig struct {
Path string `json:"path"` // 命令路径 TODO 暂时不实现
// TODO 添加需要阻止的端口列表
}
type FirewallActionIPTablesConfig struct {
Path string `json:"path"` // 命令路径 TODO 暂时不实现
// TODO 添加需要阻止的端口列表
}
type FirewallActionScriptConfig struct {
Path string `json:"path"` // 脚本路径
Cwd string `json:"cwd"` // 工作目录 TODO 暂时不实现
Args []string `json:"args"` // 附加参数 TODO 暂时不实现
// TODO 添加需要阻止的端口列表
}
2022-03-16 20:48:00 +08:00
// FirewallActionHTTPAPIConfig HTTP API配置
type FirewallActionHTTPAPIConfig struct {
URL string `json:"url"` // URL路径
TimeoutSeconds int `json:"timeoutSeconds"` // 超时时间 TODO 暂时不实现
Secret string `json:"secret"` // 认证密钥 TODO 暂时不实现
// TODO 添加需要阻止的端口列表
}
2021-02-26 16:32:16 +08:00
2022-03-16 20:48:00 +08:00
// FirewallActionHTMLConfig HTML配置
2021-02-26 16:32:16 +08:00
type FirewallActionHTMLConfig struct {
Content string `json:"content"` // 完整的HTML内容
}