// Package serversecurity_v1 服务器安全监控日志模块接口契约。 // 规范(2026-08-27):全部 POST;URL 不含任何参数(查询/路径参数均禁止);入参一律走 body。 package serversecurity_v1 import "github.com/gogf/gf/v2/frame/g" // ---------- 上报(宿主机采集脚本调用,open 组 + 内部 token 校验) ---------- // SecurityLogItem 单条安全日志。 type SecurityLogItem struct { LogTime string `json:"logTime"` // 事件发生时间 YYYY-MM-DD HH:MM:SS SrcIp string `json:"srcIp"` // 来源 IP SrcPort int `json:"srcPort"` // 来源端口 DestPort int `json:"destPort"` // 目标端口(如 22025) EventType string `json:"eventType"` // failed_ssh / accepted_ssh / banned / unbanned Detail string `json:"detail"` // 日志详情/原文 } // SecurityLogReportReq 上报请求。 type SecurityLogReportReq struct { g.Meta `path:"/security/log/report" method:"post" tags:"Open/Security" summary:"上报服务器安全日志(内部脚本调用)"` Token string `json:"token" v:"required"` // 内部上报令牌 List []SecurityLogItem `json:"list" v:"required|min-length:1"` } // SecurityLogReportRes 上报结果。 type SecurityLogReportRes struct { Accepted int `json:"accepted"` // 成功入库条数 } // ---------- 查询(admin 组,受权限保护) ---------- // SecurityLogListReq 分页查询请求。 type SecurityLogListReq struct { g.Meta `path:"/server-security/log/list" method:"post" tags:"Admin/Security/Log" summary:"安全日志分页查询"` Page int `json:"page" d:"1" v:"min:1"` Size int `json:"size" d:"10" v:"min:1|max:100"` SrcIp string `json:"srcIp"` // 来源 IP 精确/模糊 EventType string `json:"eventType"` // 事件类型过滤(空=全部) DestPort int `json:"destPort"` // 目标端口(0=全部) DateFrom string `json:"dateFrom"` // 起始时间 YYYY-MM-DD HH:MM:SS DateTo string `json:"dateTo"` // 结束时间 YYYY-MM-DD HH:MM:SS } // SecurityLogListItem 日志列表项。 type SecurityLogListItem struct { Id uint64 `json:"id"` LogTime string `json:"logTime"` SrcIp string `json:"srcIp"` SrcPort int `json:"srcPort"` DestPort int `json:"destPort"` EventType string `json:"eventType"` EventName string `json:"eventName"` // 派生:事件中文名 Detail string `json:"detail"` CreatedAt string `json:"createdAt"` } // SecurityLogListRes 分页查询结果。 type SecurityLogListRes struct { List []*SecurityLogListItem `json:"list"` Total int `json:"total"` } // ---------- 统计(admin 组,受权限保护) ---------- // SecurityLogStatsReq 统计请求。 type SecurityLogStatsReq struct { g.Meta `path:"/server-security/log/stats" method:"post" tags:"Admin/Security/Log" summary:"安全日志统计(默认最近24h)"` DateFrom string `json:"dateFrom"` // 起始时间(空=24小时前) DateTo string `json:"dateTo"` // 结束时间(空=当前) } // SecurityTopIp TOP 攻击来源 IP。 type SecurityTopIp struct { SrcIp string `json:"srcIp"` Count int `json:"count"` } // SecurityByType 按事件类型分布。 type SecurityByType struct { EventType string `json:"eventType"` EventName string `json:"eventName"` Count int `json:"count"` } // SecurityLogStatsRes 统计结果。 type SecurityLogStatsRes struct { Total int `json:"total"` // 范围内总记录 Failed int `json:"failed"` // SSH 爆破尝试 Banned int `json:"banned"` // fail2ban 封禁 Accepted int `json:"accepted"` // 成功登录 TopIps []SecurityTopIp `json:"topIps"` // TOP 攻击源(按条数) ByType []SecurityByType `json:"byType"` // 按类型分布 }