mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-12 10:55:51 +02:00
feat: add login failed ban ip list
This commit is contained in:
parent
ccb04c07d8
commit
cff843b82b
43 changed files with 2264 additions and 959 deletions
45
api/settings/auth.go
Normal file
45
api/settings/auth.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package settings
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetBanLoginIP(c *gin.Context) {
|
||||
b := query.BanIP
|
||||
|
||||
// clear expired banned IPs
|
||||
_, _ = b.Where(b.ExpiredAt.Lte(time.Now().Unix())).Delete()
|
||||
|
||||
banIps, err := b.Where(
|
||||
b.ExpiredAt.Gte(time.Now().Unix()),
|
||||
b.Attempts.Gte(settings.AuthSettings.MaxAttempts)).Find()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, banIps)
|
||||
}
|
||||
|
||||
func RemoveBannedIP(c *gin.Context) {
|
||||
var json struct {
|
||||
IP string `json:"ip"`
|
||||
}
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
b := query.BanIP
|
||||
_, err := b.Where(b.IP.Eq(json.IP)).Delete()
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusNoContent, nil)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue