'use strict'; const Controller = require('egg').Controller; const filePath = require('../../config/filespath'); class LogController extends Controller { // ssl日志查询 async logquery() { const { ctx } = this; try { const type = ctx.request.query.type; let res; if (type === 'ssl') res = await this.service.shell.shell(`tail -n 100 ${filePath.ssllog}`); if (type === 'sec') res = await this.service.shell.shell(`tail -n 100 ${filePath.swanlog}`); if (type === 'systemct') res = await this.service.shell.shell(`tail -n 100 ${filePath.systemctllog}`); if (res.errcode === 0) { ctx.body = { errcode: 0, errmsg: '', data: res.data }; } else { this.ctx.body = { errcode: -0, errmsg: '获取日志失败' }; } } catch (error) { const body = { errcode: -1002, errmsg: '日志查询失败失败', error }; throw new Error(JSON.stringify(body)); } } // ssl日志下载 async logdownload() { try { const type = this.ctx.request.query.type; let res; if (type === 'ssl') res = await this.secservice.fileshandler.download({ filePath: filePath.ssllog }); if (type === 'sec') res = await this.secservice.fileshandler.download({ filePath: filePath.ssllog }); if (type === 'systemct') res = await this.secservice.fileshandler.download({ filePath: filePath.ssllog }); if (res) { this.ctx.body = res; } else { this.ctx.body = { errcode: -0, errmsg: '下载日志失败' }; } } catch (error) { const body = { errcode: -1002, errmsg: '下载失败', error }; throw new Error(JSON.stringify(body)); } } } module.exports = LogController;