Files
terminal/server/repository/access_log.go
T
admin 1f7c491048 feat: 完善日志审计功能
- 实现文件系统日志(FilesystemLog)记录文件管理器操作
- 实现操作日志(OperationLog)记录用户操作行为
- 实现数据库SQL日志(DatabaseSQLLog)模型和API
- 实现SSH会话命令记录(SessionCommand)含命令输出和风险等级
- 添加IP提取服务支持X-Real-IP和X-Forwarded-For
- 添加日志自动清理功能
- 修复ProFormSwitch required验证问题
- 修复设置页面默认值问题
- 修复文件上传错误检测逻辑
- 修复资产树key前缀问题
- 添加VNC/RDP设置默认值
- 修复文件管理标题翻译
2026-04-19 06:57:42 +08:00

60 lines
1.7 KiB
Go

package repository
import (
"context"
"next-terminal/server/model"
)
var AccessLogRepository = new(accessLogRepository)
type accessLogRepository struct {
baseRepository
}
func (r accessLogRepository) Create(c context.Context, o *model.AccessLog) error {
return r.GetDB(c).Create(o).Error
}
func (r accessLogRepository) FindById(c context.Context, id string) (o model.AccessLog, err error) {
err = r.GetDB(c).Where("id = ?", id).First(&o).Error
return
}
func (r accessLogRepository) FindByPage(c context.Context, pageIndex, pageSize int, domain, websiteId, accountId string) (o []model.AccessLog, total int64, err error) {
db := r.GetDB(c).Model(&model.AccessLog{})
if domain != "" {
db = db.Where("domain LIKE ?", "%"+domain+"%")
}
if websiteId != "" {
db = db.Where("website_id = ?", websiteId)
}
if accountId != "" {
db = db.Where("account_id = ?", accountId)
}
err = db.Count(&total).Error
if err != nil {
return nil, 0, err
}
err = db.Order("created desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&o).Error
return
}
func (r accessLogRepository) DeleteById(c context.Context, id string) error {
return r.GetDB(c).Where("id = ?", id).Delete(&model.AccessLog{}).Error
}
func (r accessLogRepository) DeleteAll(c context.Context) error {
return r.GetDB(c).Where("1 = 1").Delete(&model.AccessLog{}).Error
}
func (r accessLogRepository) FindOutTimeLog(c context.Context, limit int) (o []model.AccessLog, err error) {
err = r.GetDB(c).Where("strftime('%s', created) < strftime('%s', 'now', '-' || ? || ' days')", limit).Find(&o).Error
return
}
func (r accessLogRepository) Count(c context.Context) (total int64, err error) {
err = r.GetDB(c).Model(&model.AccessLog{}).Count(&total).Error
return
}