feat: block user manual & upgrade frontend
Some checks failed
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Contributors / contributors (push) Has been cancelled
Sync / sync-to-jihulab (push) Has been cancelled
Run Tests / tests (macos) (push) Has been cancelled
Run Tests / tests (ubuntu) (push) Has been cancelled
Run Tests / tests (windows) (push) Has been cancelled

This commit is contained in:
naiba 2024-12-23 19:50:41 +08:00
parent 4952151281
commit 672063f4de
3 changed files with 31 additions and 5 deletions

View File

@ -172,6 +172,11 @@ func batchDeleteUser(c *gin.Context) (any, error) {
// @Success 200 {object} model.PaginatedResponse[[]model.OnlineUser, model.OnlineUser] // @Success 200 {object} model.PaginatedResponse[[]model.OnlineUser, model.OnlineUser]
// @Router /online-user [get] // @Router /online-user [get]
func listOnlineUser(c *gin.Context) (*model.Value[[]*model.OnlineUser], error) { func listOnlineUser(c *gin.Context) (*model.Value[[]*model.OnlineUser], error) {
var isAdmin bool
u, ok := c.Get(model.CtxKeyAuthorizedUser)
if ok {
isAdmin = u.(*model.User).Role == model.RoleAdmin
}
limit, err := strconv.Atoi(c.Query("limit")) limit, err := strconv.Atoi(c.Query("limit"))
if err != nil || limit < 1 { if err != nil || limit < 1 {
limit = 25 limit = 25
@ -182,8 +187,21 @@ func listOnlineUser(c *gin.Context) (*model.Value[[]*model.OnlineUser], error) {
offset = 0 offset = 0
} }
users := singleton.GetOnlineUsers(limit, offset)
if !isAdmin {
var newUsers []*model.OnlineUser
for _, user := range users {
newUsers = append(newUsers, &model.OnlineUser{
UserID: user.UserID,
IP: utils.IPDesensitize(user.IP),
ConnectedAt: user.ConnectedAt,
})
}
users = newUsers
}
return &model.Value[[]*model.OnlineUser]{ return &model.Value[[]*model.OnlineUser]{
Value: singleton.GetOnlineUsers(limit, offset), Value: users,
Pagination: model.Pagination{ Pagination: model.Pagination{
Offset: offset, Offset: offset,
Limit: limit, Limit: limit,

View File

@ -115,6 +115,14 @@ func BlockIP(db *gorm.DB, ip string, reason uint8, uid int64) error {
BlockIdentifier: uid, BlockIdentifier: uid,
} }
now := uint64(time.Now().Unix()) now := uint64(time.Now().Unix())
var count interface{}
if reason == WAFBlockReasonTypeManual {
count = 99999
} else {
count = gorm.Expr("count + 1")
}
return db.Transaction(func(tx *gorm.DB) error { return db.Transaction(func(tx *gorm.DB) error {
if err := tx.Where(&w).Attrs(WAF{ if err := tx.Where(&w).Attrs(WAF{
BlockReason: reason, BlockReason: reason,
@ -122,7 +130,7 @@ func BlockIP(db *gorm.DB, ip string, reason uint8, uid int64) error {
}).FirstOrCreate(&w).Error; err != nil { }).FirstOrCreate(&w).Error; err != nil {
return err return err
} }
return tx.Exec("UPDATE nz_waf SET count = count + 1, block_reason = ?, block_timestamp = ? WHERE ip = ? and block_identifier = ?", reason, now, ipBinary, uid).Error return tx.Exec("UPDATE nz_waf SET count = ?, block_reason = ?, block_timestamp = ? WHERE ip = ? and block_identifier = ?", count, reason, now, ipBinary, uid).Error
}) })
} }

View File

@ -2,17 +2,17 @@
name: "OfficialAdmin" name: "OfficialAdmin"
repository: "https://github.com/nezhahq/admin-frontend" repository: "https://github.com/nezhahq/admin-frontend"
author: "nezhahq" author: "nezhahq"
version: "v1.4.0" version: "v1.4.2"
isadmin: true isadmin: true
isofficial: true isofficial: true
- path: "user-dist" - path: "user-dist"
name: "Official" name: "Official"
repository: "https://github.com/hamster1963/nezha-dash-v1" repository: "https://github.com/hamster1963/nezha-dash-v1"
author: "hamster1963" author: "hamster1963"
version: "v1.7.8" version: "v1.8.0"
isofficial: true isofficial: true
- path: "nazhua-dist" - path: "nazhua-dist"
name: "Nazhua" name: "Nazhua"
repository: "https://github.com/hi2shark/nazhua" repository: "https://github.com/hi2shark/nazhua"
author: "hi2hi" author: "hi2hi"
version: "v0.4.24" version: "v0.4.25"