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
+74
View File
@@ -0,0 +1,74 @@
package repository
import (
"context"
"time"
"next-terminal/server/model"
)
var OperationLogRepository = new(operationLogRepository)
type operationLogRepository struct {
baseRepository
}
func (r operationLogRepository) FindByPage(c context.Context, pageIndex, pageSize int, accountName, action, status string, order, field string) (o []model.OperationLog, total int64, err error) {
m := model.OperationLog{}
db := r.GetDB(c).Table(m.TableName())
dbCounter := r.GetDB(c).Table(m.TableName())
if accountName != "" {
db = db.Where("account_name like ?", "%"+accountName+"%")
dbCounter = dbCounter.Where("account_name like ?", "%"+accountName+"%")
}
if action != "" {
db = db.Where("action = ?", action)
dbCounter = dbCounter.Where("action = ?", action)
}
if status != "" {
db = db.Where("status = ?", status)
dbCounter = dbCounter.Where("status = ?", status)
}
err = dbCounter.Count(&total).Error
if err != nil {
return nil, 0, err
}
orderBy := "created desc"
if order != "" && field != "" {
orderBy = field + " " + order
}
err = db.Order(orderBy).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&o).Error
if o == nil {
o = make([]model.OperationLog, 0)
}
return
}
func (r operationLogRepository) Create(c context.Context, o *model.OperationLog) error {
return r.GetDB(c).Create(o).Error
}
func (r operationLogRepository) DeleteById(c context.Context, id string) error {
return r.GetDB(c).Where("id = ?", id).Delete(&model.OperationLog{}).Error
}
func (r operationLogRepository) DeleteAll(c context.Context) error {
return r.GetDB(c).Where("1 = 1").Delete(&model.OperationLog{}).Error
}
func (r operationLogRepository) FindOutTimeLog(c context.Context, dayLimit int) (o []model.OperationLog, 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 operationLogRepository) Count(c context.Context) (total int64, err error) {
err = r.GetDB(c).Model(&model.OperationLog{}).Count(&total).Error
return
}