MRBS 1.12.2 等保2.0二级整改完整提交
包含:登录失败锁定、90天密码有效期、30分钟会话超时、 强制改密、登录审计日志、屏幕水印、企业背景图、 备案信息固定底部、favicon、JS空集合保护、 会话过期体验优化(403 JSON)、display_errors 关闭、 固定 key 根治 Integrity check failed 等全部改动 注意:config.inc.php/.htaccess/.user.ini 含敏感信息, 通过 .gitignore 排除,勿推送到公开仓库。
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the Monolog package.
|
||||
*
|
||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Monolog\Processor;
|
||||
|
||||
/**
|
||||
* Injects url/method and remote IP of the current web request in all records
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class WebProcessor implements ProcessorInterface
|
||||
{
|
||||
/**
|
||||
* @var array<string, mixed>|\ArrayAccess<string, mixed>
|
||||
*/
|
||||
protected $serverData;
|
||||
|
||||
/**
|
||||
* Default fields
|
||||
*
|
||||
* Array is structured as [key in record.extra => key in $serverData]
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $extraFields = [
|
||||
'url' => 'REQUEST_URI',
|
||||
'ip' => 'REMOTE_ADDR',
|
||||
'http_method' => 'REQUEST_METHOD',
|
||||
'server' => 'SERVER_NAME',
|
||||
'referrer' => 'HTTP_REFERER',
|
||||
'user_agent' => 'HTTP_USER_AGENT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param array<string, mixed>|\ArrayAccess<string, mixed>|null $serverData Array or object w/ ArrayAccess that provides access to the $_SERVER data
|
||||
* @param array<string, string>|array<string>|null $extraFields Field names and the related key inside $serverData to be added (or just a list of field names to use the default configured $serverData mapping). If not provided it defaults to: [url, ip, http_method, server, referrer] + unique_id if present in server data
|
||||
*/
|
||||
public function __construct($serverData = null, ?array $extraFields = null)
|
||||
{
|
||||
if (null === $serverData) {
|
||||
$this->serverData = &$_SERVER;
|
||||
} elseif (is_array($serverData) || $serverData instanceof \ArrayAccess) {
|
||||
$this->serverData = $serverData;
|
||||
} else {
|
||||
throw new \UnexpectedValueException('$serverData must be an array or object implementing ArrayAccess.');
|
||||
}
|
||||
|
||||
$defaultEnabled = ['url', 'ip', 'http_method', 'server', 'referrer'];
|
||||
if (isset($this->serverData['UNIQUE_ID'])) {
|
||||
$this->extraFields['unique_id'] = 'UNIQUE_ID';
|
||||
$defaultEnabled[] = 'unique_id';
|
||||
}
|
||||
|
||||
if (null === $extraFields) {
|
||||
$extraFields = $defaultEnabled;
|
||||
}
|
||||
if (isset($extraFields[0])) {
|
||||
foreach (array_keys($this->extraFields) as $fieldName) {
|
||||
if (!in_array($fieldName, $extraFields)) {
|
||||
unset($this->extraFields[$fieldName]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->extraFields = $extraFields;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function __invoke(array $record): array
|
||||
{
|
||||
// skip processing if for some reason request data
|
||||
// is not present (CLI or wonky SAPIs)
|
||||
if (!isset($this->serverData['REQUEST_URI'])) {
|
||||
return $record;
|
||||
}
|
||||
|
||||
$record['extra'] = $this->appendExtraFields($record['extra']);
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
public function addExtraField(string $extraName, string $serverName): self
|
||||
{
|
||||
$this->extraFields[$extraName] = $serverName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $extra
|
||||
* @return mixed[]
|
||||
*/
|
||||
private function appendExtraFields(array $extra): array
|
||||
{
|
||||
foreach ($this->extraFields as $extraName => $serverName) {
|
||||
$extra[$extraName] = $this->serverData[$serverName] ?? null;
|
||||
}
|
||||
|
||||
return $extra;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user