feat: Verify Bot

This commit is contained in:
Roi Feng
2025-03-09 22:08:06 -04:00
parent a1f15f37c6
commit dfce050dd9
5 changed files with 108 additions and 10 deletions

View File

@ -50,21 +50,23 @@ func LoadMainConfig(basePath string) (*MainConfig, error) {
// RuleSet stores all rules
type RuleSet struct {
IPAllowTrie *dataType.TrieNode
IPBlockTrie *dataType.TrieNode
URLAllowList *dataType.URLRuleList
URLBlockList *dataType.URLRuleList
CAPTCHARule *dataType.CaptchaRule
IPAllowTrie *dataType.TrieNode
IPBlockTrie *dataType.TrieNode
URLAllowList *dataType.URLRuleList
URLBlockList *dataType.URLRuleList
CAPTCHARule *dataType.CaptchaRule
VerifyBotRule *dataType.VerifyBotRule
}
// LoadRules Load all rules from the specified path
func LoadRules(rulePath string) (*RuleSet, error) {
rs := RuleSet{
IPAllowTrie: &dataType.TrieNode{},
IPBlockTrie: &dataType.TrieNode{},
URLAllowList: &dataType.URLRuleList{},
URLBlockList: &dataType.URLRuleList{},
CAPTCHARule: &dataType.CaptchaRule{},
IPAllowTrie: &dataType.TrieNode{},
IPBlockTrie: &dataType.TrieNode{},
URLAllowList: &dataType.URLRuleList{},
URLBlockList: &dataType.URLRuleList{},
CAPTCHARule: &dataType.CaptchaRule{},
VerifyBotRule: &dataType.VerifyBotRule{},
}
// Load IP Allow List
@ -97,6 +99,12 @@ func LoadRules(rulePath string) (*RuleSet, error) {
return nil, err
}
// Load Verify Bot Rule
verifyBotFile := rulePath + "/VerifyBot.yml"
if err := loadVerifyBotRule(verifyBotFile, rs.VerifyBotRule); err != nil {
return nil, err
}
return &rs, nil
}
@ -114,6 +122,17 @@ func loadCAPTCHARule(file string, rule *dataType.CaptchaRule) error {
}
func loadVerifyBotRule(file string, rule *dataType.VerifyBotRule) error {
data, err := os.ReadFile(file)
if err != nil {
return err
}
if err := yaml.Unmarshal(data, &rule); err != nil {
return err
}
return nil
}
// loadIPRules read the IP rule file and insert the rules into the trie
func loadIPRules(filePath string, trie *dataType.TrieNode) error {
file, err := os.Open(filePath)