去除日志配置

This commit is contained in:
Anyon 2020-12-09 16:21:29 +08:00
parent 2058bcadba
commit 8d3744ba87
6 changed files with 2 additions and 132 deletions

View File

@ -96,7 +96,7 @@ class Config extends Controller
$post['storage']['allow_exts'] = join(',', $exts);
}
foreach ($post as $name => $value) sysconf($name, $value);
sysoplog('系统配置管理', "修改存储参数成功");
sysoplog('系统配置管理', "修改系统存储参数");
$this->success('修改文件存储成功!');
}
}

View File

@ -68,32 +68,6 @@ class Oplog extends Controller
}
}
/**
* 日志行为配置
* @auth true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function config()
{
if ($this->request->isGet()) {
$this->fetch();
} else {
$data = $this->_vali([
'oplog_state.in:0,1' => '日志状态值异常!',
'oplog_state.require' => '日志状态不能为空!',
'oplog_days.require' => '保存天数不能为空!',
]);
foreach ($data as $name => $value) {
sysconf($name, $value);
}
$GLOBALS['oplogs'] = [];
sysoplog('系统运维管理', '修改系统日志行为配置');
$this->success('日志配置成功!');
}
}
/**
* 清理系统日志
* @auth true

View File

@ -1,72 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
use think\admin\service\AdminService;
use think\admin\service\SystemService;
use think\helper\Str;
try {
/*! 全局数据变更数据 */
$GLOBALS['oplogs'] = [];
/*! 数据变更日志开关状态 */
if (sysconf('base.oplog_state') > 0) {
/*! 数据变更批量写入 */
app()->event->listen('HttpEnd', function () {
if (is_array($GLOBALS['oplogs']) && count($GLOBALS['oplogs']) > 0) {
foreach (array_chunk($GLOBALS['oplogs'], 100) as $items) {
app()->db->name('SystemOplog')->insertAll($items);
}
$GLOBALS['oplogs'] = [];
$days = floatval(sysconf('base.oplog_days'));
if (rand(1, 100) <= 10 && $days > 0) {
$lastdate = date('Y-m-d H:i:s', strtotime("-{$days}days"));
app()->db->name('SystemOplog')->where('create_at', '<', $lastdate)->delete();
}
}
});
/*! 数据操作SQL语句监听分析 */
app()->db->listen(function ($sqlstr) {
[$type] = explode(' ', $sqlstr);
if (in_array($type, ['INSERT', 'UPDATE', 'DELETE']) && AdminService::instance()->isLogin()) {
[$sqlstr] = explode('GROUP BY', explode('ORDER BY', $sqlstr)[0]);
if (preg_match('/^INSERT\s+INTO\s+`(.*?)`\s+SET\s+(.*?)\s*$/i', $sqlstr, $matches)) {
if (stripos($matches[1] = Str::studly($matches[1]), 'SystemOplog') === false) {
$matches[2] = substr(str_replace(['`', '\''], '', $matches[2]), 0, 800);
$GLOBALS['oplogs'][] = SystemService::instance()->getOplog("添加 {$matches[1]} 数据", $matches[2]);
}
} elseif (preg_match('/^INSERT\s*INTO\s+`(.*?)`\s+(.*?)\s+VALUES\s+(.*?)\s*$/i', $sqlstr, $matches)) {
if (stripos($matches[1] = Str::studly($matches[1]), 'SystemOplog') === false) {
$matches[2] = substr(str_replace(['`', '\''], '', $matches[2]), 0, 200);
$matches[3] = substr(str_replace(['`', '\''], '', $matches[3]), 0, 600);
$GLOBALS['oplogs'][] = SystemService::instance()->getOplog("添加 {$matches[1]} 数据", "{$matches[2]} VALUES {$matches[3]}");
}
} elseif (preg_match('/^UPDATE\s+`(.*?)`\s+SET\s+(.*?)\s+WHERE\s+(.*?)\s*$/i', $sqlstr, $matches)) {
if (stripos($matches[1] = Str::studly($matches[1]), 'SystemOplog') === false) {
$matches[3] = substr(str_replace(['`', '\''], '', $matches[3]), 0, 150);
$matches[2] = substr(str_replace(['`', '\''], '', $matches[2]), 0, 800);
$GLOBALS['oplogs'][] = SystemService::instance()->getOplog("更新 {$matches[1]} 数据 {$matches[3]}", $matches[2]);
}
} elseif (preg_match('/^DELETE\s*FROM\s*`(.*?)`\s*WHERE\s*(.*?)\s*$/i', $sqlstr, $matches)) {
if (stripos($matches[1] = Str::studly($matches[1]), 'SystemOplog') === false) {
$matches[2] = str_replace(['`', '\''], '', $matches[2]);
$GLOBALS['oplogs'][] = SystemService::instance()->getOplog("删除 {$matches[1]} 数据 {$matches[2]}", "");
}
}
}
});
}
} catch (\Exception $exception) {
app()->log->error($exception->getMessage());
}

View File

@ -1,29 +0,0 @@
<form onsubmit="return false" data-auto="true" action="{:request()->url()}" method="post" class='layui-form layui-card' autocomplete="off">
<div class="layui-card-body padding-left-40">
<div class="layui-form-item">
<span class="color-green font-w7 label-required-prev">记录数据变更日志</span>
<div class="layui-input">
{foreach [1 => '记录数据变更日志',0 => '不记录数据变更日志'] as $k=>$v}
{if intval(sysconf('base.oplog_state')) eq $k}
<label class="think-radio">
<input checked type="radio" value="{$k}" name="oplog_state">{$v}
</label>
{else}
<label class="think-radio">
<input type="radio" value="{$k}" name="oplog_state">{$v}
</label>
{/if}{/foreach}
</div>
</div>
<label class="layui-form-item relative block">
<span class="color-green font-w7">操作日志保留天数</span>
<input class="layui-input" required data-blur-number="0" name="oplog_days" value="{:sysconf('base.oplog_days')?:0}">
<p class="help-block">注意:当日志保留天数设置为 0 时则为永久保留日志,系统不会进行删除!</p>
</label>
<div class="hr-line-dashed margin-top-20"></div>
<div class="layui-form-item text-center">
<button class="layui-btn" type="submit">保存配置</button>
<button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消修改吗?" data-close>取消修改</button>
</div>
</div>
</form>

View File

@ -1,9 +1,6 @@
{extend name='main'}
{block name="button"}
<!--{if auth('config')}-->
<a class="layui-btn layui-btn-sm layui-btn-primary" data-modal="{:url('config')}">日志配置</a>
<!--{/if}-->
<!--{if auth("clear")}-->
<button data-load='{:url("clear")}' data-confirm="确定要消除所有日志吗?" class='layui-btn layui-btn-sm layui-btn-primary'>清理日志</button>
<!--{/if}-->

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2020-12-02 14:53:34
// This file is automatically generated at:2020-12-09 16:19:09
declare (strict_types = 1);
return array (
0 => 'think\\admin\\Library',