2022-08-16 15:30:23 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2022-10-17 08:32:31 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
2023-01-04 14:31:51 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
2022-08-16 15:30:23 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Logs
|
|
|
|
// @Summary Page login logs
|
|
|
|
// @Description 获取系统登录日志列表分页
|
|
|
|
// @Accept json
|
2023-02-07 10:48:32 +00:00
|
|
|
// @Param request body dto.SearchLgLogWithPage true "request"
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Success 200 {object} dto.PageResult
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /logs/login [post]
|
2022-11-15 09:20:57 +00:00
|
|
|
func (b *BaseApi) GetLoginLogs(c *gin.Context) {
|
2023-02-07 10:48:32 +00:00
|
|
|
var req dto.SearchLgLogWithPage
|
2022-08-16 15:30:23 +00:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-15 09:20:57 +00:00
|
|
|
total, list, err := logService.PageLoginLog(req)
|
2022-08-16 15:30:23 +00:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Items: list,
|
|
|
|
Total: total,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Logs
|
|
|
|
// @Summary Page operation logs
|
|
|
|
// @Description 获取系统操作日志列表分页
|
|
|
|
// @Accept json
|
2023-02-07 10:48:32 +00:00
|
|
|
// @Param request body dto.SearchOpLogWithPage true "request"
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Success 200 {object} dto.PageResult
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /logs/operation [post]
|
2022-11-15 09:20:57 +00:00
|
|
|
func (b *BaseApi) GetOperationLogs(c *gin.Context) {
|
2023-02-07 10:48:32 +00:00
|
|
|
var req dto.SearchOpLogWithPage
|
2022-08-16 15:30:23 +00:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-15 09:20:57 +00:00
|
|
|
total, list, err := logService.PageOperationLog(req)
|
|
|
|
if err != nil {
|
2022-08-16 15:30:23 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2022-11-15 09:20:57 +00:00
|
|
|
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Items: list,
|
|
|
|
Total: total,
|
|
|
|
})
|
2022-08-16 15:30:23 +00:00
|
|
|
}
|
2022-11-15 10:44:50 +00:00
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Logs
|
|
|
|
// @Summary Clean operation logs
|
|
|
|
// @Description 清空操作日志
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.CleanLog true "request"
|
|
|
|
// @Success 200 {object} dto.PageResult
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /logs/clean [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["logType"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"清空 [logType] 日志信息","formatEN":"Clean the [logType] log information"}
|
2022-11-15 10:44:50 +00:00
|
|
|
func (b *BaseApi) CleanLogs(c *gin.Context) {
|
2023-01-04 14:31:51 +00:00
|
|
|
var req dto.CleanLog
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
2022-11-15 10:44:50 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
if err := logService.CleanLogs(req.LogType); err != nil {
|
2022-11-15 10:44:50 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|