github.com/TeaOSLab/EdgeNode@v1.3.8/internal/iplibrary/action_html.go (about)

     1  package iplibrary
     2  
     3  import (
     4  	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
     5  	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
     6  	"net/http"
     7  )
     8  
     9  // HTMLAction HTML动作
    10  type HTMLAction struct {
    11  	BaseAction
    12  
    13  	config *firewallconfigs.FirewallActionHTMLConfig
    14  }
    15  
    16  // NewHTMLAction 获取新对象
    17  func NewHTMLAction() *HTMLAction {
    18  	return &HTMLAction{}
    19  }
    20  
    21  // Init 初始化
    22  func (this *HTMLAction) Init(config *firewallconfigs.FirewallActionConfig) error {
    23  	this.config = &firewallconfigs.FirewallActionHTMLConfig{}
    24  	err := this.convertParams(config.Params, this.config)
    25  	if err != nil {
    26  		return err
    27  	}
    28  	return nil
    29  }
    30  
    31  // AddItem 添加
    32  func (this *HTMLAction) AddItem(listType IPListType, item *pb.IPItem) error {
    33  	return nil
    34  }
    35  
    36  // DeleteItem 删除
    37  func (this *HTMLAction) DeleteItem(listType IPListType, item *pb.IPItem) error {
    38  	return nil
    39  }
    40  
    41  // Close 关闭
    42  func (this *HTMLAction) Close() error {
    43  	return nil
    44  }
    45  
    46  // DoHTTP 处理HTTP请求
    47  func (this *HTMLAction) DoHTTP(req *http.Request, resp http.ResponseWriter) (goNext bool, err error) {
    48  	if this.config == nil {
    49  		goNext = true
    50  		return
    51  	}
    52  	resp.WriteHeader(http.StatusForbidden) // TODO改成可以配置
    53  	_, _ = resp.Write([]byte(this.config.Content))
    54  	return false, nil
    55  }