mirror of
https://github.com/Rayzggz/server_torii.git
synced 2025-06-22 23:11:30 +08:00
feat: Verify Bot
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user