mirror of
https://github.com/Rayzggz/server_torii.git
synced 2025-06-22 06:51:31 +08:00
feat: HTTP FLOOD Speed Limit
add shared memory
This commit is contained in:
@ -12,9 +12,9 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type CheckFunc func(dataType.UserRequest, *config.RuleSet, *action.Decision)
|
||||
type CheckFunc func(dataType.UserRequest, *config.RuleSet, *action.Decision, *dataType.SharedMemory)
|
||||
|
||||
func CheckMain(w http.ResponseWriter, userRequestData dataType.UserRequest, ruleSet *config.RuleSet, cfg *config.MainConfig) {
|
||||
func CheckMain(w http.ResponseWriter, userRequestData dataType.UserRequest, ruleSet *config.RuleSet, cfg *config.MainConfig, sharedMem *dataType.SharedMemory) {
|
||||
decision := action.NewDecision()
|
||||
|
||||
checkFuncs := make([]CheckFunc, 0)
|
||||
@ -23,10 +23,11 @@ func CheckMain(w http.ResponseWriter, userRequestData dataType.UserRequest, rule
|
||||
checkFuncs = append(checkFuncs, check.URLAllowList)
|
||||
checkFuncs = append(checkFuncs, check.URLBlockList)
|
||||
checkFuncs = append(checkFuncs, check.VerifyBot)
|
||||
checkFuncs = append(checkFuncs, check.HTTPFlood)
|
||||
checkFuncs = append(checkFuncs, check.Captcha)
|
||||
|
||||
for _, checkFunc := range checkFuncs {
|
||||
checkFunc(userRequestData, ruleSet, decision)
|
||||
checkFunc(userRequestData, ruleSet, decision, sharedMem)
|
||||
if decision.State == action.Done {
|
||||
break
|
||||
}
|
||||
|
@ -10,15 +10,15 @@ import (
|
||||
)
|
||||
|
||||
// StartServer starts the HTTP server
|
||||
func StartServer(cfg *config.MainConfig, ruleSet *config.RuleSet) error {
|
||||
func StartServer(cfg *config.MainConfig, ruleSet *config.RuleSet, sharedMem *dataType.SharedMemory) error {
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
userRequestData := processRequestData(cfg, r)
|
||||
|
||||
if strings.HasPrefix(userRequestData.Uri, cfg.WebPath) {
|
||||
CheckTorii(w, r, userRequestData, ruleSet, cfg)
|
||||
CheckTorii(w, r, userRequestData, ruleSet, cfg, sharedMem)
|
||||
} else {
|
||||
CheckMain(w, userRequestData, ruleSet, cfg)
|
||||
CheckMain(w, userRequestData, ruleSet, cfg, sharedMem)
|
||||
}
|
||||
|
||||
})
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func CheckTorii(w http.ResponseWriter, r *http.Request, reqData dataType.UserRequest, ruleSet *config.RuleSet, cfg *config.MainConfig) {
|
||||
func CheckTorii(w http.ResponseWriter, r *http.Request, reqData dataType.UserRequest, ruleSet *config.RuleSet, cfg *config.MainConfig, sharedMem *dataType.SharedMemory) {
|
||||
decision := action.NewDecision()
|
||||
|
||||
decision.SetCode(action.Continue, []byte("403"))
|
||||
|
Reference in New Issue
Block a user