Files
SafeLine/management/webserver/api/dashboard.go
T
Binbim b8788c239e
MCP Docker / build-and-push (push) Has been cancelled
feat: SafeLine CE 9.3.9 with pro features
- Remove telemetry: disabled all phone-home (installation notify, false positives, behavior tracking, upgrade tips)
- Version branding: removed 'ce-' prefix, product name changed to '长亭雷池 WAF'
- Detection engine enhancement: strict preset enables all 17 modules with aggressive configs
- Multi-user RBAC: admin/operator/viewer roles with password + TOTP 2FA
- Rate limiting: nginx limit_req per website (RPS, burst, action)
- JS Challenge: browser fingerprint verification page with cookie-based bypass
- Security fixes: removed InsecureSkipVerify, hardcoded credentials, NO_AUTH backdoor
2026-07-04 07:59:04 +08:00

118 lines
3.0 KiB
Go

package api
import (
"math"
"time"
"github.com/gin-gonic/gin"
"chaitin.cn/patronus/safeline-2/management/webserver/api/response"
"chaitin.cn/patronus/safeline-2/management/webserver/model"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
)
func GetDashboardCounts(c *gin.Context) {
var requested int64 = 0
var intercepted int64 = 0
db := database.GetDB()
var statisticTotalReq model.SystemStatistics
r := db.Where("type = 'total-req'").Where("created_at >= date_trunc('day',now())").First(&statisticTotalReq)
if r.RowsAffected > 0 {
requested = statisticTotalReq.Value
}
var statisticTotalDenied model.SystemStatistics
r = db.Where("type = 'total-denied'").Where("created_at >= date_trunc('day',now())").First(&statisticTotalDenied)
if r.RowsAffected > 0 {
intercepted = statisticTotalDenied.Value
}
response.Success(c, gin.H{"requested": requested, "intercepted": intercepted})
}
func GetDashboardSites(c *gin.Context) {
response.Success(c, gin.H{"normal": 0, "abnormal": 0})
}
func GetDashboardQps(c *gin.Context) {
var statistics []model.SystemStatistics
db := database.GetDB()
db.Where("type = 'req'").Order("created_at desc").Limit(75).Find(&statistics)
type Node struct {
Label string `json:"label"`
Value int64 `json:"value"`
}
var nodes = make([]Node, 0)
for i := len(statistics) - 1; i >= 0; i-- {
nodes = append(nodes, Node{
Label: statistics[i].CreatedAt.Format("2006-01-02 15:04:05"),
Value: int64(math.Ceil(float64(statistics[i].Value) / 5)),
})
}
response.Success(c, gin.H{"nodes": nodes, "total": len(nodes)})
}
func GetDashboardRequests(c *gin.Context) {
var statistics []model.SystemStatistics
db := database.GetDB()
db.Where("type = 'total-req'").Order("created_at desc").Limit(30).Find(&statistics)
type Node struct {
Label string `json:"label"`
Value int64 `json:"value"`
}
var nodes = make([]Node, 0)
for i := 30; i > len(statistics); i-- {
nodes = append(nodes, Node{
Label: time.Now().Add(-time.Duration(i-1) * time.Hour * 24).Format("2006-01-02"),
Value: 0,
})
}
for i := len(statistics) - 1; i >= 0; i-- {
nodes = append(nodes, Node{
Label: statistics[i].CreatedAt.Format("2006-01-02"),
Value: statistics[i].Value,
})
}
response.Success(c, gin.H{"nodes": nodes, "total": len(nodes)})
}
func GetDashboardIntercepts(c *gin.Context) {
var statistics []model.SystemStatistics
db := database.GetDB()
db.Where("type = 'total-denied'").Order("created_at desc").Limit(30).Find(&statistics)
type Node struct {
Label string `json:"label"`
Value int64 `json:"value"`
}
var nodes = make([]Node, 0)
for i := 30; i > len(statistics); i-- {
nodes = append(nodes, Node{
Label: time.Now().Add(-time.Duration(i-1) * time.Hour * 24).Format("2006-01-02"),
Value: 0,
})
}
for i := len(statistics) - 1; i >= 0; i-- {
nodes = append(nodes, Node{
Label: statistics[i].CreatedAt.Format("2006-01-02"),
Value: statistics[i].Value,
})
}
response.Success(c, gin.H{"nodes": nodes, "total": len(nodes)})
}