limiter.go 492 B

1234567891011121314151617181920212223
  1. package middleware
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/lejianwen/rustdesk-api/v2/global"
  5. "github.com/lejianwen/rustdesk-api/v2/http/response"
  6. "net/http"
  7. )
  8. func Limiter() gin.HandlerFunc {
  9. return func(c *gin.Context) {
  10. loginLimiter := global.LoginLimiter
  11. clientIp := c.ClientIP()
  12. banned, _ := loginLimiter.CheckSecurityStatus(clientIp)
  13. if banned {
  14. response.Fail(c, http.StatusLocked, response.TranslateMsg(c, "Banned"))
  15. c.Abort()
  16. return
  17. }
  18. c.Next()
  19. }
  20. }