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