2022-08-16 23:30:23 +08:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2022-10-17 16:32:31 +08: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 22:31:51 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
2022-08-16 23:30:23 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Logs
|
|
|
|
// @Summary Page login logs
|
|
|
|
// @Description 获取系统登录日志列表分页
|
|
|
|
// @Accept json
|
2023-02-07 18:48:32 +08:00
|
|
|
// @Param request body dto.SearchLgLogWithPage true "request"
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Success 200 {object} dto.PageResult
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /logs/login [post]
|
2022-11-15 17:20:57 +08:00
|
|
|
func (b *BaseApi) GetLoginLogs(c *gin.Context) {
|
2023-02-07 18:48:32 +08:00
|
|
|
var req dto.SearchLgLogWithPage
|
2022-08-16 23:30:23 +08:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-15 17:20:57 +08:00
|
|
|
total, list, err := logService.PageLoginLog(req)
|
2022-08-16 23:30:23 +08: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 22:31:51 +08:00
|
|
|
// @Tags Logs
|
|
|
|
// @Summary Page operation logs
|
|
|
|
// @Description 获取系统操作日志列表分页
|
|
|
|
// @Accept json
|
2023-02-07 18:48:32 +08:00
|
|
|
// @Param request body dto.SearchOpLogWithPage true "request"
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Success 200 {object} dto.PageResult
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /logs/operation [post]
|
2022-11-15 17:20:57 +08:00
|
|
|
func (b *BaseApi) GetOperationLogs(c *gin.Context) {
|
2023-02-07 18:48:32 +08:00
|
|
|
var req dto.SearchOpLogWithPage
|
2022-08-16 23:30:23 +08:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-15 17:20:57 +08:00
|
|
|
total, list, err := logService.PageOperationLog(req)
|
|
|
|
if err != nil {
|
2022-08-16 23:30:23 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2022-11-15 17:20:57 +08:00
|
|
|
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Items: list,
|
|
|
|
Total: total,
|
|
|
|
})
|
2022-08-16 23:30:23 +08:00
|
|
|
}
|
2022-11-15 18:44:50 +08:00
|
|
|
|
2023-01-04 22:31:51 +08: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 18:44:50 +08:00
|
|
|
func (b *BaseApi) CleanLogs(c *gin.Context) {
|
2023-01-04 22:31:51 +08: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 18:44:50 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
if err := logService.CleanLogs(req.LogType); err != nil {
|
2022-11-15 18:44:50 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2023-08-02 16:47:30 +08:00
|
|
|
|
2023-09-20 16:24:26 +08:00
|
|
|
// @Tags Logs
|
|
|
|
// @Summary Load system log files
|
|
|
|
// @Description 获取系统日志文件列表
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /logs/system/files [get]
|
|
|
|
func (b *BaseApi) GetSystemFiles(c *gin.Context) {
|
|
|
|
data, err := logService.ListSystemLogFile()
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, data)
|
|
|
|
}
|
|
|
|
|
2023-08-02 16:47:30 +08:00
|
|
|
// @Tags Logs
|
|
|
|
// @Summary Load system logs
|
|
|
|
// @Description 获取系统日志
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-09-20 16:24:26 +08:00
|
|
|
// @Router /logs/system [post]
|
2023-08-02 16:47:30 +08:00
|
|
|
func (b *BaseApi) GetSystemLogs(c *gin.Context) {
|
2023-09-20 16:24:26 +08:00
|
|
|
var req dto.OperationWithName
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
data, err := logService.LoadSystemLog(req.Name)
|
2023-08-02 16:47:30 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, data)
|
|
|
|
}
|