|
@@ -41,8 +41,8 @@ class AdminLog extends Model
|
|
|
|
|
|
/**
|
|
|
* 记录日志
|
|
|
- * @param string $title
|
|
|
- * @param string $content
|
|
|
+ * @param string $title 日志标题
|
|
|
+ * @param string $content 日志内容
|
|
|
*/
|
|
|
public static function record($title = '', $content = '')
|
|
|
{
|
|
@@ -50,6 +50,9 @@ class AdminLog extends Model
|
|
|
$admin_id = $auth->isLogin() ? $auth->id : 0;
|
|
|
$username = $auth->isLogin() ? $auth->username : __('Unknown');
|
|
|
|
|
|
+ // 设置过滤函数
|
|
|
+ request()->filter('trim,strip_tags,htmlspecialchars');
|
|
|
+
|
|
|
$controllername = Loader::parseName(request()->controller());
|
|
|
$actionname = strtolower(request()->action());
|
|
|
$path = str_replace('.', '/', $controllername) . '/' . $actionname;
|
|
@@ -60,12 +63,12 @@ class AdminLog extends Model
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- $content = $content ? $content : self::$content;
|
|
|
+ $content = $content ?: self::$content;
|
|
|
if (!$content) {
|
|
|
- $content = request()->param('', null, 'trim,strip_tags,htmlspecialchars');
|
|
|
+ $content = request()->param('') ?: file_get_contents("php://input");
|
|
|
$content = self::getPureContent($content);
|
|
|
}
|
|
|
- $title = $title ? $title : self::$title;
|
|
|
+ $title = $title ?: self::$title;
|
|
|
if (!$title) {
|
|
|
$title = [];
|
|
|
$breadcrumb = Auth::instance()->getBreadcrumb($path);
|
|
@@ -77,18 +80,18 @@ class AdminLog extends Model
|
|
|
self::create([
|
|
|
'title' => $title,
|
|
|
'content' => !is_scalar($content) ? json_encode($content, JSON_UNESCAPED_UNICODE) : $content,
|
|
|
- 'url' => substr(request()->url(), 0, 1500),
|
|
|
+ 'url' => substr(xss_clean(strip_tags(request()->url())), 0, 1500),
|
|
|
'admin_id' => $admin_id,
|
|
|
'username' => $username,
|
|
|
'useragent' => substr(request()->server('HTTP_USER_AGENT'), 0, 255),
|
|
|
- 'ip' => request()->ip()
|
|
|
+ 'ip' => xss_clean(strip_tags(request()->ip()))
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取已屏蔽关键信息的数据
|
|
|
* @param $content
|
|
|
- * @return false|string
|
|
|
+ * @return array
|
|
|
*/
|
|
|
protected static function getPureContent($content)
|
|
|
{
|