feat: 完善日志审计功能
- 实现文件系统日志(FilesystemLog)记录文件管理器操作 - 实现操作日志(OperationLog)记录用户操作行为 - 实现数据库SQL日志(DatabaseSQLLog)模型和API - 实现SSH会话命令记录(SessionCommand)含命令输出和风险等级 - 添加IP提取服务支持X-Real-IP和X-Forwarded-For - 添加日志自动清理功能 - 修复ProFormSwitch required验证问题 - 修复设置页面默认值问题 - 修复文件上传错误检测逻辑 - 修复资产树key前缀问题 - 添加VNC/RDP设置默认值 - 修复文件管理标题翻译
This commit is contained in:
@@ -21,6 +21,21 @@ import (
|
||||
|
||||
type AssetApi struct{}
|
||||
|
||||
func recordOperationLog(c echo.Context, action, content, status, errorMessage string) {
|
||||
account, _ := GetCurrentAccount(c)
|
||||
clientIP := service.PropertyService.GetClientIP(c)
|
||||
_ = service.OperationLogService.Record(context.TODO(), service.OperationLogParams{
|
||||
AccountId: account.ID,
|
||||
AccountName: account.Username,
|
||||
Action: action,
|
||||
Content: content,
|
||||
IP: clientIP,
|
||||
Status: status,
|
||||
ErrorMessage: errorMessage,
|
||||
UserAgent: c.Request().UserAgent(),
|
||||
})
|
||||
}
|
||||
|
||||
func (assetApi AssetApi) AssetCreateEndpoint(c echo.Context) error {
|
||||
m := maps.Map{}
|
||||
if err := c.Bind(&m); err != nil {
|
||||
@@ -30,10 +45,13 @@ func (assetApi AssetApi) AssetCreateEndpoint(c echo.Context) error {
|
||||
account, _ := GetCurrentAccount(c)
|
||||
m["owner"] = account.ID
|
||||
|
||||
assetName, _ := m["name"].(string)
|
||||
if _, err := service.AssetService.Create(context.TODO(), m); err != nil {
|
||||
recordOperationLog(c, "asset-add", "创建资产: "+assetName, "failed", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
recordOperationLog(c, "asset-add", "创建资产: "+assetName, "success", "")
|
||||
return Success(c, nil)
|
||||
}
|
||||
|
||||
@@ -167,9 +185,12 @@ func (assetApi AssetApi) AssetUpdateEndpoint(c echo.Context) error {
|
||||
if err := c.Bind(&m); err != nil {
|
||||
return err
|
||||
}
|
||||
assetName, _ := m["name"].(string)
|
||||
if err := service.AssetService.UpdateById(id, m); err != nil {
|
||||
recordOperationLog(c, "asset-edit", "更新资产: "+assetName, "failed", err.Error())
|
||||
return err
|
||||
}
|
||||
recordOperationLog(c, "asset-edit", "更新资产: "+assetName, "success", "")
|
||||
return Success(c, nil)
|
||||
}
|
||||
|
||||
@@ -178,10 +199,12 @@ func (assetApi AssetApi) AssetDeleteEndpoint(c echo.Context) error {
|
||||
split := strings.Split(id, ",")
|
||||
for i := range split {
|
||||
if err := service.AssetService.DeleteById(split[i]); err != nil {
|
||||
recordOperationLog(c, "asset-del", "删除资产: "+id, "failed", err.Error())
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
recordOperationLog(c, "asset-del", "删除资产: "+id, "success", "")
|
||||
return Success(c, nil)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user