1f7c491048
- 实现文件系统日志(FilesystemLog)记录文件管理器操作 - 实现操作日志(OperationLog)记录用户操作行为 - 实现数据库SQL日志(DatabaseSQLLog)模型和API - 实现SSH会话命令记录(SessionCommand)含命令输出和风险等级 - 添加IP提取服务支持X-Real-IP和X-Forwarded-For - 添加日志自动清理功能 - 修复ProFormSwitch required验证问题 - 修复设置页面默认值问题 - 修复文件上传错误检测逻辑 - 修复资产树key前缀问题 - 添加VNC/RDP设置默认值 - 修复文件管理标题翻译
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"next-terminal/server/model"
|
|
)
|
|
|
|
var SessionCommandRepository = new(sessionCommandRepository)
|
|
|
|
type sessionCommandRepository struct {
|
|
baseRepository
|
|
}
|
|
|
|
func (r sessionCommandRepository) FindBySessionId(c context.Context, sessionId string) (o []model.SessionCommand, err error) {
|
|
err = r.GetDB(c).Where("session_id = ?", sessionId).Order("created asc").Find(&o).Error
|
|
return
|
|
}
|
|
|
|
func (r sessionCommandRepository) FindByPage(c context.Context, pageIndex, pageSize int, sessionId string) (o []model.SessionCommand, total int64, err error) {
|
|
m := model.SessionCommand{}
|
|
db := r.GetDB(c).Table(m.TableName())
|
|
dbCounter := r.GetDB(c).Table(m.TableName())
|
|
|
|
if sessionId != "" {
|
|
db = db.Where("session_id = ?", sessionId)
|
|
dbCounter = dbCounter.Where("session_id = ?", sessionId)
|
|
}
|
|
|
|
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.SessionCommand, 0)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (r sessionCommandRepository) Create(c context.Context, o *model.SessionCommand) error {
|
|
return r.GetDB(c).Create(o).Error
|
|
}
|
|
|
|
func (r sessionCommandRepository) DeleteBySessionId(c context.Context, sessionId string) error {
|
|
return r.GetDB(c).Where("session_id = ?", sessionId).Delete(&model.SessionCommand{}).Error
|
|
}
|