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:
2026-04-19 06:57:42 +08:00
parent a2a1613384
commit 1f7c491048
42 changed files with 1214 additions and 130 deletions
+59
View File
@@ -0,0 +1,59 @@
package repository
import (
"context"
"time"
"next-terminal/server/model"
)
var FilesystemLogRepository = new(filesystemLogRepository)
type filesystemLogRepository struct {
baseRepository
}
func (r filesystemLogRepository) FindByPage(c context.Context, pageIndex, pageSize int, action string) (o []model.FilesystemLog, total int64, err error) {
m := model.FilesystemLog{}
db := r.GetDB(c).Table(m.TableName())
dbCounter := r.GetDB(c).Table(m.TableName())
if action != "" {
db = db.Where("action = ?", action)
dbCounter = dbCounter.Where("action = ?", action)
}
err = dbCounter.Count(&total).Error
if err != nil {
return nil, 0, err
}
err = db.Order("created desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&o).Error
if o == nil {
o = make([]model.FilesystemLog, 0)
}
return
}
func (r filesystemLogRepository) Create(c context.Context, o *model.FilesystemLog) error {
return r.GetDB(c).Create(o).Error
}
func (r filesystemLogRepository) DeleteById(c context.Context, id string) error {
return r.GetDB(c).Where("id = ?", id).Delete(&model.FilesystemLog{}).Error
}
func (r filesystemLogRepository) DeleteAll(c context.Context) error {
return r.GetDB(c).Where("1 = 1").Delete(&model.FilesystemLog{}).Error
}
func (r filesystemLogRepository) FindOutTimeLog(c context.Context, dayLimit int) (o []model.FilesystemLog, err error) {
limitTime := time.Now().Add(time.Duration(-dayLimit*24) * time.Hour)
err = r.GetDB(c).Where("created < ?", limitTime).Find(&o).Error
return
}
func (r filesystemLogRepository) Count(c context.Context) (total int64, err error) {
err = r.GetDB(c).Model(&model.FilesystemLog{}).Count(&total).Error
return
}