mirror of
https://github.com/Rayzggz/server_torii.git
synced 2025-06-17 04:31:22 +08:00
feat: config and checker of waiting room
This commit is contained in:
@ -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.WaitingRoom)
|
||||
checkFuncs = append(checkFuncs, check.Captcha)
|
||||
|
||||
for _, checkFunc := range checkFuncs {
|
||||
@ -106,6 +107,40 @@ func CheckMain(w http.ResponseWriter, userRequestData dataType.UserRequest, rule
|
||||
return
|
||||
}
|
||||
|
||||
} else if bytes.Compare(decision.HTTPCode, []byte("WAITING_ROOM")) == 0 {
|
||||
tpl, err := template.ParseFiles(cfg.ErrorPage + "/waiting_room.html")
|
||||
if err != nil {
|
||||
utils.LogError(userRequestData, fmt.Sprintf("Error parsing template: %v", err), "CheckMain")
|
||||
http.Error(w, "500 - Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
sessionID := string(decision.ResponseData)
|
||||
position, totalQueue := sharedMem.WaitingRoom.GetQueueInfo(sessionID, userRequestData, ruleSet.CAPTCHARule.SecretKey)
|
||||
|
||||
data := struct {
|
||||
EdgeTag string
|
||||
ConnectIP string
|
||||
Date string
|
||||
QueuePosition int
|
||||
TotalQueue int
|
||||
}{
|
||||
EdgeTag: cfg.NodeName,
|
||||
ConnectIP: userRequestData.RemoteIP,
|
||||
Date: time.Now().Format("2006-01-02 15:04:05"),
|
||||
QueuePosition: position,
|
||||
TotalQueue: totalQueue,
|
||||
}
|
||||
|
||||
w.Header().Set("Set-Cookie", "__torii_session_id="+sessionID+"; Path=/; Max-Age=86400; Priority=High; HttpOnly;")
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
if err = tpl.Execute(w, data); err != nil {
|
||||
utils.LogError(userRequestData, fmt.Sprintf("Error executing template: %v", err), "CheckMain")
|
||||
http.Error(w, "500 - Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
} else {
|
||||
//should never happen
|
||||
utils.LogError(userRequestData, fmt.Sprintf("Error access in wrong state: %v", decision), "CheckMain")
|
||||
|
Reference in New Issue
Block a user