mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-18 22:22:59 +08:00
feat: 增加清空日志功能
This commit is contained in:
parent
3a3670f660
commit
8214744e92
@ -1,6 +1,8 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"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"
|
||||
@ -44,3 +46,18 @@ func (b *BaseApi) GetOperationLogs(c *gin.Context) {
|
||||
Total: total,
|
||||
})
|
||||
}
|
||||
|
||||
func (b *BaseApi) CleanLogs(c *gin.Context) {
|
||||
logtype, ok := c.Params.Get("logtype")
|
||||
if !ok {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, errors.New("error logtype in path"))
|
||||
return
|
||||
}
|
||||
|
||||
if err := logService.CleanLogs(logtype); err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||
return
|
||||
}
|
||||
|
||||
helper.SuccessWithData(c, nil)
|
||||
}
|
||||
|
@ -8,9 +8,11 @@ import (
|
||||
type LogRepo struct{}
|
||||
|
||||
type ILogRepo interface {
|
||||
CleanLogin() error
|
||||
CreateLoginLog(user *model.LoginLog) error
|
||||
PageLoginLog(limit, offset int, opts ...DBOption) (int64, []model.LoginLog, error)
|
||||
|
||||
CleanOperation() error
|
||||
CreateOperationLog(user *model.OperationLog) error
|
||||
PageOperationLog(limit, offset int, opts ...DBOption) (int64, []model.OperationLog, error)
|
||||
}
|
||||
@ -19,6 +21,10 @@ func NewILogRepo() ILogRepo {
|
||||
return &LogRepo{}
|
||||
}
|
||||
|
||||
func (u *LogRepo) CleanLogin() error {
|
||||
return global.DB.Exec("delete from login_logs;").Error
|
||||
}
|
||||
|
||||
func (u *LogRepo) CreateLoginLog(log *model.LoginLog) error {
|
||||
return global.DB.Create(log).Error
|
||||
}
|
||||
@ -35,6 +41,10 @@ func (u *LogRepo) PageLoginLog(page, size int, opts ...DBOption) (int64, []model
|
||||
return count, ops, err
|
||||
}
|
||||
|
||||
func (u *LogRepo) CleanOperation() error {
|
||||
return global.DB.Exec("delete from operation_logs").Error
|
||||
}
|
||||
|
||||
func (u *LogRepo) CreateOperationLog(log *model.OperationLog) error {
|
||||
return global.DB.Create(log).Error
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ type ILogService interface {
|
||||
|
||||
CreateOperationLog(operation model.OperationLog) error
|
||||
PageOperationLog(search dto.PageInfo) (int64, interface{}, error)
|
||||
|
||||
CleanLogs(logtype string) error
|
||||
}
|
||||
|
||||
func NewILogService() ILogService {
|
||||
@ -70,6 +72,13 @@ func (u *LogService) PageOperationLog(search dto.PageInfo) (int64, interface{},
|
||||
return total, dtoOps, err
|
||||
}
|
||||
|
||||
func (u *LogService) CleanLogs(logtype string) error {
|
||||
if logtype == "operation" {
|
||||
return logRepo.CleanOperation()
|
||||
}
|
||||
return logRepo.CleanLogin()
|
||||
}
|
||||
|
||||
func filterSensitive(vars string) string {
|
||||
var Sensitives = []string{"password", "Password", "credential", "privateKey"}
|
||||
ops := make(map[string]interface{})
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
var (
|
||||
DefaultDataDir = "/opt/1Panel/data"
|
||||
LogDir = "opt/1Panel/log"
|
||||
ResourceDir = path.Join(DefaultDataDir, "resource")
|
||||
AppResourceDir = path.Join(ResourceDir, "apps")
|
||||
AppInstallDir = path.Join(DefaultDataDir, "apps")
|
||||
|
@ -16,5 +16,6 @@ func (s *LogRouter) InitLogRouter(Router *gin.RouterGroup) {
|
||||
{
|
||||
operationRouter.POST("login", baseApi.GetLoginLogs)
|
||||
operationRouter.POST("operation", baseApi.GetOperationLogs)
|
||||
operationRouter.POST("clean/:logtype", baseApi.CleanLogs)
|
||||
}
|
||||
}
|
||||
|
@ -9,3 +9,7 @@ export const getOperationLogs = (info: ReqPage) => {
|
||||
export const getLoginLogs = (info: ReqPage) => {
|
||||
return http.post<ResPage<Log.OperationLog>>(`/logs/login`, info);
|
||||
};
|
||||
|
||||
export const cleanLogs = (logtype: string) => {
|
||||
return http.post(`/logs/clean/${logtype}`);
|
||||
};
|
||||
|
@ -495,6 +495,7 @@ export default {
|
||||
loginAgent: '用户代理',
|
||||
loginStatus: '登录状态',
|
||||
system: '系统日志',
|
||||
deleteLogs: '清空日志',
|
||||
detail: {
|
||||
users: '用户',
|
||||
hosts: '主机',
|
||||
|
@ -3,6 +3,12 @@
|
||||
<Submenu activeName="login" />
|
||||
<el-card style="margin-top: 20px">
|
||||
<ComplexTable :pagination-config="paginationConfig" :data="data" @search="search">
|
||||
<template #toolbar>
|
||||
<el-button type="primary" @click="onClean()">
|
||||
{{ $t('logs.deleteLogs') }}
|
||||
</el-button>
|
||||
</template>
|
||||
|
||||
<el-table-column min-width="40" :label="$t('logs.loginIP')" prop="ip" />
|
||||
<el-table-column min-width="40" :label="$t('logs.loginAddress')" prop="address" />
|
||||
<el-table-column :label="$t('logs.loginAgent')" show-overflow-tooltip prop="agent" />
|
||||
@ -26,17 +32,22 @@
|
||||
/>
|
||||
</ComplexTable>
|
||||
</el-card>
|
||||
<ConfirmDialog ref="confirmDialogRef" @confirm="onSubmitClean"></ConfirmDialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import ComplexTable from '@/components/complex-table/index.vue';
|
||||
import ConfirmDialog from '@/components/confirm-dialog/index.vue';
|
||||
import { dateFromat } from '@/utils/util';
|
||||
import { getLoginLogs } from '@/api/modules/log';
|
||||
import { cleanLogs, getLoginLogs } from '@/api/modules/log';
|
||||
import Submenu from '@/views/log/index.vue';
|
||||
import { onMounted, reactive, ref } from '@vue/runtime-core';
|
||||
import i18n from '@/lang';
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
const data = ref();
|
||||
const confirmDialogRef = ref();
|
||||
const paginationConfig = reactive({
|
||||
currentPage: 1,
|
||||
pageSize: 15,
|
||||
@ -53,6 +64,21 @@ const search = async () => {
|
||||
paginationConfig.total = res.data.total;
|
||||
};
|
||||
|
||||
const onClean = async () => {
|
||||
let params = {
|
||||
header: i18n.global.t('logs.deleteLogs'),
|
||||
operationInfo: i18n.global.t('commons.msg.delete'),
|
||||
submitInputInfo: i18n.global.t('logs.deleteLogs'),
|
||||
};
|
||||
confirmDialogRef.value!.acceptParams(params);
|
||||
};
|
||||
|
||||
const onSubmitClean = async () => {
|
||||
await cleanLogs('login');
|
||||
search();
|
||||
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
search();
|
||||
});
|
||||
|
@ -3,6 +3,12 @@
|
||||
<Submenu activeName="operation" />
|
||||
<el-card style="margin-top: 20px">
|
||||
<ComplexTable :pagination-config="paginationConfig" :data="data" @search="search">
|
||||
<template #toolbar>
|
||||
<el-button type="primary" @click="onClean()">
|
||||
{{ $t('logs.deleteLogs') }}
|
||||
</el-button>
|
||||
</template>
|
||||
|
||||
<el-table-column :label="$t('logs.operatoin')" fix>
|
||||
<template #default="{ row }">
|
||||
{{ fmtOperation(row) }}
|
||||
@ -65,19 +71,24 @@
|
||||
/>
|
||||
</ComplexTable>
|
||||
</el-card>
|
||||
|
||||
<ConfirmDialog ref="confirmDialogRef" @confirm="onSubmitClean"></ConfirmDialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import ComplexTable from '@/components/complex-table/index.vue';
|
||||
import ConfirmDialog from '@/components/confirm-dialog/index.vue';
|
||||
import { dateFromat } from '@/utils/util';
|
||||
import { getOperationLogs } from '@/api/modules/log';
|
||||
import { cleanLogs, getOperationLogs } from '@/api/modules/log';
|
||||
import Submenu from '@/views/log/index.vue';
|
||||
import { onMounted, reactive, ref } from '@vue/runtime-core';
|
||||
import { Log } from '@/api/interface/log';
|
||||
import i18n from '@/lang';
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
const data = ref();
|
||||
const confirmDialogRef = ref();
|
||||
const paginationConfig = reactive({
|
||||
currentPage: 1,
|
||||
pageSize: 15,
|
||||
@ -131,6 +142,21 @@ const fmtBody = (value: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
const onClean = async () => {
|
||||
let params = {
|
||||
header: i18n.global.t('logs.deleteLogs'),
|
||||
operationInfo: i18n.global.t('commons.msg.delete'),
|
||||
submitInputInfo: i18n.global.t('logs.deleteLogs'),
|
||||
};
|
||||
confirmDialogRef.value!.acceptParams(params);
|
||||
};
|
||||
|
||||
const onSubmitClean = async () => {
|
||||
await cleanLogs('operation');
|
||||
search();
|
||||
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
search();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user