mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +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
|
@ -1,10 +1,12 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"errors"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -30,3 +32,16 @@ func Login(name string, password string) (user *model.Auth, err error) {
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
func BanIP(ip string) {
|
||||
b := query.BanIP
|
||||
banIP, err := b.Where(b.IP.Eq(ip)).First()
|
||||
if err != nil || banIP.ExpiredAt <= time.Now().Unix() {
|
||||
_ = b.Create(&model.BanIP{
|
||||
IP: ip,
|
||||
Attempts: 1,
|
||||
ExpiredAt: time.Now().Unix() + int64(settings.AuthSettings.BanThresholdMinutes*60),
|
||||
})
|
||||
}
|
||||
_, _ = b.Where(b.IP.Eq(ip)).UpdateSimple(b.Attempts.Add(1))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue