restrict v8
This commit is contained in:
@@ -65,6 +65,7 @@ var Reports = &cli.Command{
|
||||
&cli.IntFlag{Name: "days", Value: 30, Usage: "Only count reports created within N days"},
|
||||
&cli.IntFlag{Name: "limit", Value: 30, Usage: "Max rows to print"},
|
||||
&cli.BoolFlag{Name: "pending", Usage: "List all pending reports across the site (ignores --email/--domain)"},
|
||||
&cli.BoolFlag{Name: "stats", Usage: "Show site-wide report statistics (ignores --email/--domain)"},
|
||||
},
|
||||
Action: runReports,
|
||||
}
|
||||
@@ -228,6 +229,9 @@ func runReports(ctx *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if ctx.Bool("stats") {
|
||||
return printReportStats(ctx.Context, database, ctx.Int("days"))
|
||||
}
|
||||
if ctx.Bool("pending") {
|
||||
return printPendingReports(ctx.Context, database, ctx.Int("limit"))
|
||||
}
|
||||
@@ -371,6 +375,52 @@ func printPendingReports(ctx context.Context, database *gorm.DB, limit int) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
// printReportStats 输出全站维度的举报统计。
|
||||
//
|
||||
// 这是「举报是否被武器化」的唯一观测手段:正常举报是分散的,组织化举报会表现为
|
||||
// 同一批 IP 集中打同一批箱主。没有这个视图,运营者只能一个 domain 一个 domain 地猜。
|
||||
func printReportStats(ctx context.Context, database *gorm.DB, days int) error {
|
||||
if days <= 0 {
|
||||
days = 7
|
||||
}
|
||||
since := time.Now().AddDate(0, 0, -days)
|
||||
store := db.NewReportsStore(database)
|
||||
|
||||
users, err := store.TopReportedUsers(ctx, since, 10)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "query top reported users")
|
||||
}
|
||||
reporters, err := store.TopReporters(ctx, since, 10)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "query top reporters")
|
||||
}
|
||||
|
||||
fmt.Printf("统计窗口:近 %d 天(仅待处理举报)\n", days)
|
||||
fmt.Println(strings.Repeat("-", 60))
|
||||
|
||||
fmt.Println("被举报最多的箱主:")
|
||||
if len(users) == 0 {
|
||||
fmt.Println(" 无")
|
||||
}
|
||||
for i, u := range users {
|
||||
fmt.Printf(" %2d. @%-20s %-14s %d 条\n", i+1, u.Domain, u.Name, u.Count)
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("举报来源 IP 最多:")
|
||||
if len(reporters) == 0 {
|
||||
fmt.Println(" 无")
|
||||
}
|
||||
for i, r := range reporters {
|
||||
fmt.Printf(" %2d. %-18s %d 次\n", i+1, r.ReporterIP, r.Count)
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("提示:同一 IP 集中举报同一批内容,或某箱主举报数远高于其他箱主时,")
|
||||
fmt.Println(" 先判断是组织化挂人还是举报被武器化,再决定是否处置。")
|
||||
return nil
|
||||
}
|
||||
|
||||
// truncateForCLI 按 rune 截断并压平换行,避免终端输出被长内容冲散。
|
||||
func truncateForCLI(s string, max int) string {
|
||||
s = strings.ReplaceAll(strings.ReplaceAll(s, "\r", " "), "\n", " ")
|
||||
|
||||
Reference in New Issue
Block a user