2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 13:47:15 +08:00

feat: 添加操作日志记录功能和前端日志查看页面 (#1227)

* Initial plan

* feat: 添加操作日志记录功能和前端日志查看页面

Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>

* fix: 修复 HttpLog 中 IP 字符串处理的类型安全问题

Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>

* fix: lint

* feat: 完善面板内日志记录,添加网站/数据库/项目/计划任务/备份CRUD日志

Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>

* feat: 完善更多模块的日志记录(证书/SSH/Webhook/用户/设置/安全)

Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>

* fix: 改进cert_dns删除方法,在删除前获取实体信息用于日志记录

Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>

* fix: lint

* feat: 从session获取操作员ID并在前端显示用户名

Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>

* fix: lint

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>
Co-authored-by: 耗子 <haozi@loli.email>
This commit is contained in:
Copilot
2026-01-12 23:31:22 +08:00
committed by GitHub
parent 1012e5a246
commit f2e41a3364
64 changed files with 1305 additions and 248 deletions

View File

@@ -1,8 +1,10 @@
package data
import (
"context"
"errors"
"fmt"
"log/slog"
"github.com/leonelquinteros/gotext"
cryptossh "golang.org/x/crypto/ssh"
@@ -14,14 +16,16 @@ import (
)
type sshRepo struct {
t *gotext.Locale
db *gorm.DB
t *gotext.Locale
db *gorm.DB
log *slog.Logger
}
func NewSSHRepo(t *gotext.Locale, db *gorm.DB) biz.SSHRepo {
func NewSSHRepo(t *gotext.Locale, db *gorm.DB, log *slog.Logger) biz.SSHRepo {
return &sshRepo{
t: t,
db: db,
t: t,
db: db,
log: log,
}
}
@@ -41,7 +45,7 @@ func (r *sshRepo) Get(id uint) (*biz.SSH, error) {
return ssh, nil
}
func (r *sshRepo) Create(req *request.SSHCreate) error {
func (r *sshRepo) Create(ctx context.Context, req *request.SSHCreate) error {
conf := pkgssh.ClientConfig{
AuthMethod: pkgssh.AuthMethod(req.AuthMethod),
Host: fmt.Sprintf("%s:%d", req.Host, req.Port),
@@ -64,10 +68,17 @@ func (r *sshRepo) Create(req *request.SSHCreate) error {
Remark: req.Remark,
}
return r.db.Create(ssh).Error
if err = r.db.Create(ssh).Error; err != nil {
return err
}
// 记录日志
r.log.Info("ssh created", slog.String("type", biz.OperationTypeSSH), slog.Uint64("operator_id", getOperatorID(ctx)), slog.String("name", req.Name), slog.String("host", req.Host))
return nil
}
func (r *sshRepo) Update(req *request.SSHUpdate) error {
func (r *sshRepo) Update(ctx context.Context, req *request.SSHUpdate) error {
conf := pkgssh.ClientConfig{
AuthMethod: pkgssh.AuthMethod(req.AuthMethod),
Host: fmt.Sprintf("%s:%d", req.Host, req.Port),
@@ -91,9 +102,28 @@ func (r *sshRepo) Update(req *request.SSHUpdate) error {
Remark: req.Remark,
}
return r.db.Model(ssh).Where("id = ?", req.ID).Select("*").Updates(ssh).Error
if err = r.db.Model(ssh).Where("id = ?", req.ID).Select("*").Updates(ssh).Error; err != nil {
return err
}
// 记录日志
r.log.Info("ssh updated", slog.String("type", biz.OperationTypeSSH), slog.Uint64("operator_id", getOperatorID(ctx)), slog.Uint64("id", uint64(req.ID)), slog.String("name", req.Name))
return nil
}
func (r *sshRepo) Delete(id uint) error {
return r.db.Delete(&biz.SSH{}, id).Error
func (r *sshRepo) Delete(ctx context.Context, id uint) error {
ssh, err := r.Get(id)
if err != nil {
return err
}
if err = r.db.Delete(&biz.SSH{}, id).Error; err != nil {
return err
}
// 记录日志
r.log.Info("ssh deleted", slog.String("type", biz.OperationTypeSSH), slog.Uint64("operator_id", getOperatorID(ctx)), slog.Uint64("id", uint64(id)), slog.String("name", ssh.Name))
return nil
}