From 667bd65ff4592c9c2e3dc28b9a959f5f4679fcce Mon Sep 17 00:00:00 2001 From: Anyon Date: Sat, 19 Sep 2020 18:12:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0SQL=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/sys.php | 42 +++++++++++++++++++++++++++++++++ app/admin/view/oplog/index.html | 4 ++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 app/admin/sys.php diff --git a/app/admin/sys.php b/app/admin/sys.php new file mode 100644 index 000000000..c84f61d4a --- /dev/null +++ b/app/admin/sys.php @@ -0,0 +1,42 @@ +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, 200); + return sysoplog("添加数据 {$matches[1]}", "添加数据:{$matches[2]}"); + } + } 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, 200); + $matches[2] = substr(str_replace(['`', ' '], '', $matches[2]), 0, 200); + return sysoplog("更新数据 {$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]); + return sysoplog("删除数据 {$matches[1]}", "删除条件:{$matches[2]}"); + } + } + } +}); \ No newline at end of file diff --git a/app/admin/view/oplog/index.html b/app/admin/view/oplog/index.html index b8df29964..aaf0cea9d 100644 --- a/app/admin/view/oplog/index.html +++ b/app/admin/view/oplog/index.html @@ -37,8 +37,8 @@ {$vo.node|default='-'} -

{$vo.action|default='-'}

-

{$vo.content|default='-'}

+

{$vo.action|default='-'}

+

{$vo.content|default='-'}

{$vo.geoip|default='-'}