mirror of
https://github.com/Rayzggz/server_torii.git
synced 2025-06-25 00:11:31 +08:00
Compare commits
7 Commits
dev
...
feature/wa
Author | SHA1 | Date | |
---|---|---|---|
fff4327007 | |||
6abbb3a323 | |||
50380ebc5c | |||
aa1e760a79 | |||
fcb08478d2 | |||
c203cdf684 | |||
42e9d6502d |
@ -14,4 +14,9 @@ VerifyBot:
|
||||
verify_baidu_bot: true
|
||||
verify_yandex_bot: true
|
||||
verify_sogou_bot: true
|
||||
verify_apple_bot: true
|
||||
verify_apple_bot: true
|
||||
ExternalMigration:
|
||||
enabled: false
|
||||
redirect_url: "https://example.com/migration"
|
||||
secret_key: "0378b0f84c4310279918d71a5647ba5d"
|
||||
session_timeout: 1800
|
21
internal/check/ExternalMigration.go
Normal file
21
internal/check/ExternalMigration.go
Normal file
@ -0,0 +1,21 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"server_torii/internal/action"
|
||||
"server_torii/internal/config"
|
||||
"server_torii/internal/dataType"
|
||||
)
|
||||
|
||||
func ExternalMigration(reqData dataType.UserRequest, ruleSet *config.RuleSet, decision *action.Decision, sharedMem *dataType.SharedMemory) {
|
||||
if !ruleSet.ExternalMigrationRule.Enabled {
|
||||
decision.Set(action.Continue)
|
||||
return
|
||||
}
|
||||
|
||||
if !verifyClearanceCookie(reqData, *ruleSet) {
|
||||
decision.SetResponse(action.Done, []byte("EXTERNAL"), genSessionID(reqData, *ruleSet))
|
||||
return
|
||||
}
|
||||
|
||||
decision.Set(action.Continue)
|
||||
}
|
@ -66,20 +66,22 @@ 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
|
||||
VerifyBotRule *dataType.VerifyBotRule
|
||||
HTTPFloodRule *dataType.HTTPFloodRule
|
||||
IPAllowTrie *dataType.TrieNode
|
||||
IPBlockTrie *dataType.TrieNode
|
||||
URLAllowList *dataType.URLRuleList
|
||||
URLBlockList *dataType.URLRuleList
|
||||
CAPTCHARule *dataType.CaptchaRule
|
||||
VerifyBotRule *dataType.VerifyBotRule
|
||||
HTTPFloodRule *dataType.HTTPFloodRule
|
||||
ExternalMigrationRule *dataType.ExternalMigrationRule
|
||||
}
|
||||
|
||||
// ruleSetWrapper
|
||||
type ruleSetWrapper struct {
|
||||
CAPTCHARule *dataType.CaptchaRule `yaml:"CAPTCHA"`
|
||||
VerifyBotRule *dataType.VerifyBotRule `yaml:"VerifyBot"`
|
||||
HTTPFloodRule httpFloodRuleWrapper `yaml:"HTTPFlood"`
|
||||
CAPTCHARule *dataType.CaptchaRule `yaml:"CAPTCHA"`
|
||||
VerifyBotRule *dataType.VerifyBotRule `yaml:"VerifyBot"`
|
||||
HTTPFloodRule httpFloodRuleWrapper `yaml:"HTTPFlood"`
|
||||
ExternalMigrationRule *dataType.ExternalMigrationRule `yaml:"ExternalMigration"`
|
||||
}
|
||||
|
||||
type httpFloodRuleWrapper struct {
|
||||
@ -90,13 +92,14 @@ type httpFloodRuleWrapper struct {
|
||||
// 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{},
|
||||
VerifyBotRule: &dataType.VerifyBotRule{},
|
||||
HTTPFloodRule: &dataType.HTTPFloodRule{},
|
||||
IPAllowTrie: &dataType.TrieNode{},
|
||||
IPBlockTrie: &dataType.TrieNode{},
|
||||
URLAllowList: &dataType.URLRuleList{},
|
||||
URLBlockList: &dataType.URLRuleList{},
|
||||
CAPTCHARule: &dataType.CaptchaRule{},
|
||||
VerifyBotRule: &dataType.VerifyBotRule{},
|
||||
HTTPFloodRule: &dataType.HTTPFloodRule{},
|
||||
ExternalMigrationRule: &dataType.ExternalMigrationRule{},
|
||||
}
|
||||
|
||||
// Load IP Allow List
|
||||
@ -149,6 +152,9 @@ func loadServerRules(YAMLFile string, rs RuleSet) (*RuleSet, error) {
|
||||
|
||||
*rs.CAPTCHARule = *wrapper.CAPTCHARule
|
||||
*rs.VerifyBotRule = *wrapper.VerifyBotRule
|
||||
if wrapper.ExternalMigrationRule != nil {
|
||||
*rs.ExternalMigrationRule = *wrapper.ExternalMigrationRule
|
||||
}
|
||||
|
||||
rs.HTTPFloodRule.HTTPFloodSpeedLimit = make(map[int64]int64)
|
||||
rs.HTTPFloodRule.HTTPFloodSameURILimit = make(map[int64]int64)
|
||||
|
@ -31,6 +31,13 @@ type HTTPFloodRule struct {
|
||||
HTTPFloodSameURILimit map[int64]int64
|
||||
}
|
||||
|
||||
type ExternalMigrationRule struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
RedirectUrl string `yaml:"redirect_url"`
|
||||
SecretKey string `yaml:"secret_key"`
|
||||
SessionTimeout int64 `yaml:"session_timeout"`
|
||||
}
|
||||
|
||||
type SharedMemory struct {
|
||||
HTTPFloodSpeedLimitCounter *Counter
|
||||
HTTPFloodSameURILimitCounter *Counter
|
||||
|
@ -25,6 +25,7 @@ func CheckMain(w http.ResponseWriter, userRequestData dataType.UserRequest, rule
|
||||
checkFuncs = append(checkFuncs, check.URLBlockList)
|
||||
checkFuncs = append(checkFuncs, check.VerifyBot)
|
||||
checkFuncs = append(checkFuncs, check.HTTPFlood)
|
||||
checkFuncs = append(checkFuncs, check.ExternalMigration)
|
||||
checkFuncs = append(checkFuncs, check.Captcha)
|
||||
|
||||
for _, checkFunc := range checkFuncs {
|
||||
|
Reference in New Issue
Block a user