mirror of
https://github.com/Awuqing/BackupX.git
synced 2026-05-11 09:59:56 +08:00
Three community-requested features: 1. CLI password reset: `backupx reset-password --username admin --password xxx` Docker users can run via `docker exec`. No full app init needed. 2. Audit logging: async fire-and-forget audit trail for all key operations (login, CRUD on tasks/targets/records, settings changes). New UI page at /audit with category filter and pagination. 3. Multi-source path backup: file backup tasks now support multiple source directories packed into a single tar archive. Backward compatible with existing single sourcePath field.
30 lines
727 B
Go
30 lines
727 B
Go
package http
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"backupx/server/internal/service"
|
||
"github.com/gin-gonic/gin"
|
||
)
|
||
|
||
// recordAudit 从 gin context 中提取用户信息并记录审计日志(nil 安全)
|
||
func recordAudit(c *gin.Context, auditService *service.AuditService, category, action, targetType, targetID, targetName, detail string) {
|
||
if auditService == nil {
|
||
return
|
||
}
|
||
username := ""
|
||
if subject, exists := c.Get(contextUserSubjectKey); exists {
|
||
username = fmt.Sprintf("%v", subject)
|
||
}
|
||
auditService.Record(service.AuditEntry{
|
||
Username: username,
|
||
Category: category,
|
||
Action: action,
|
||
TargetType: targetType,
|
||
TargetID: targetID,
|
||
TargetName: targetName,
|
||
Detail: detail,
|
||
ClientIP: c.ClientIP(),
|
||
})
|
||
}
|