Files
EdgeNode/internal/iplibrary/action_html.go

57 lines
1.2 KiB
Go
Raw Permalink Normal View History

2021-02-26 16:33:58 +08:00
package iplibrary
import (
2024-07-27 15:42:50 +08:00
"net/http"
2021-02-26 16:33:58 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
)
2021-11-14 20:46:08 +08:00
// HTMLAction HTML动作
2021-02-26 16:33:58 +08:00
type HTMLAction struct {
BaseAction
config *firewallconfigs.FirewallActionHTMLConfig
}
2021-11-14 20:46:08 +08:00
// NewHTMLAction 获取新对象
2021-02-26 16:33:58 +08:00
func NewHTMLAction() *HTMLAction {
return &HTMLAction{}
}
2021-11-14 20:46:08 +08:00
// Init 初始化
2021-02-26 16:33:58 +08:00
func (this *HTMLAction) Init(config *firewallconfigs.FirewallActionConfig) error {
this.config = &firewallconfigs.FirewallActionHTMLConfig{}
err := this.convertParams(config.Params, this.config)
if err != nil {
return err
}
return nil
}
2021-11-14 20:46:08 +08:00
// AddItem 添加
2021-02-26 16:33:58 +08:00
func (this *HTMLAction) AddItem(listType IPListType, item *pb.IPItem) error {
return nil
}
2021-11-14 20:46:08 +08:00
// DeleteItem 删除
2021-02-26 16:33:58 +08:00
func (this *HTMLAction) DeleteItem(listType IPListType, item *pb.IPItem) error {
return nil
}
2021-11-14 20:46:08 +08:00
// Close 关闭
2021-02-26 16:33:58 +08:00
func (this *HTMLAction) Close() error {
return nil
}
2021-11-14 20:46:08 +08:00
// DoHTTP 处理HTTP请求
2021-02-26 16:33:58 +08:00
func (this *HTMLAction) DoHTTP(req *http.Request, resp http.ResponseWriter) (goNext bool, err error) {
if this.config == nil {
goNext = true
return
}
resp.WriteHeader(http.StatusForbidden) // TODO改成可以配置
_, _ = resp.Write([]byte(this.config.Content))
return false, nil
}