mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
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
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:
parent
4952151281
commit
672063f4de
@ -172,6 +172,11 @@ func batchDeleteUser(c *gin.Context) (any, error) {
|
||||
// @Success 200 {object} model.PaginatedResponse[[]model.OnlineUser, model.OnlineUser]
|
||||
// @Router /online-user [get]
|
||||
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"))
|
||||
if err != nil || limit < 1 {
|
||||
limit = 25
|
||||
@ -182,8 +187,21 @@ func listOnlineUser(c *gin.Context) (*model.Value[[]*model.OnlineUser], error) {
|
||||
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]{
|
||||
Value: singleton.GetOnlineUsers(limit, offset),
|
||||
Value: users,
|
||||
Pagination: model.Pagination{
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
|
10
model/waf.go
10
model/waf.go
@ -115,6 +115,14 @@ func BlockIP(db *gorm.DB, ip string, reason uint8, uid int64) error {
|
||||
BlockIdentifier: uid,
|
||||
}
|
||||
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 {
|
||||
if err := tx.Where(&w).Attrs(WAF{
|
||||
BlockReason: reason,
|
||||
@ -122,7 +130,7 @@ func BlockIP(db *gorm.DB, ip string, reason uint8, uid int64) error {
|
||||
}).FirstOrCreate(&w).Error; err != nil {
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -2,17 +2,17 @@
|
||||
name: "OfficialAdmin"
|
||||
repository: "https://github.com/nezhahq/admin-frontend"
|
||||
author: "nezhahq"
|
||||
version: "v1.4.0"
|
||||
version: "v1.4.2"
|
||||
isadmin: true
|
||||
isofficial: true
|
||||
- path: "user-dist"
|
||||
name: "Official"
|
||||
repository: "https://github.com/hamster1963/nezha-dash-v1"
|
||||
author: "hamster1963"
|
||||
version: "v1.7.8"
|
||||
version: "v1.8.0"
|
||||
isofficial: true
|
||||
- path: "nazhua-dist"
|
||||
name: "Nazhua"
|
||||
repository: "https://github.com/hi2shark/nazhua"
|
||||
author: "hi2hi"
|
||||
version: "v0.4.24"
|
||||
version: "v0.4.25"
|
||||
|
Loading…
Reference in New Issue
Block a user