mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 22:55:36 +00:00
fix:修复系统配置中的禁止访问IP和时区配置项无效的问题
This commit is contained in:
parent
543ce30d06
commit
bd4b5c6dd3
@ -46,6 +46,7 @@ class Config extends Model
|
||||
|
||||
public function getValueAttr($value, $row)
|
||||
{
|
||||
if (!isset($row['type'])) return $value;
|
||||
if (in_array($row['type'], $this->jsonDecodeType)) {
|
||||
$arr = json_decode($value, true);
|
||||
return $arr ? $arr : [];
|
||||
@ -86,6 +87,7 @@ class Config extends Model
|
||||
|
||||
public function getContentAttr($value, $row)
|
||||
{
|
||||
if (!isset($row['type'])) return '';
|
||||
if (in_array($row['type'], $this->needContent)) {
|
||||
$arr = json_decode($value, true);
|
||||
return $arr ? $arr : [];
|
||||
|
@ -20,6 +20,8 @@ use app\admin\model\User as UserModel;
|
||||
*/
|
||||
class Install extends Api
|
||||
{
|
||||
protected $useSystemSettings = false;
|
||||
|
||||
/**
|
||||
* 环境检查状态
|
||||
*/
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
// 这是系统自动生成的middleware定义文件
|
||||
return [
|
||||
\app\common\middleware\AllowCrossDomain::class,
|
||||
\think\middleware\LoadLangPack::class,
|
||||
|
@ -2,6 +2,9 @@
|
||||
// 应用公共文件
|
||||
|
||||
use think\facade\Db;
|
||||
use think\Response;
|
||||
use think\facade\Config;
|
||||
use think\exception\HttpResponseException;
|
||||
|
||||
if (!function_exists('path_is_writable')) {
|
||||
/**
|
||||
@ -286,3 +289,30 @@ if (!function_exists('hsv2rgb')) {
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('ip_check')) {
|
||||
function ip_check($ip = null)
|
||||
{
|
||||
$ip = is_null($ip) ? request()->ip() : $ip;
|
||||
$noAccess = get_sys_config('no_access_ip');
|
||||
$noAccess = !$noAccess ? [] : array_filter(explode("\n", str_replace("\r\n", "\n", $noAccess)));
|
||||
if ($noAccess && \Symfony\Component\HttpFoundation\IpUtils::checkIp($ip, $noAccess)) {
|
||||
$response = Response::create(['msg' => 'No permission request'], 'json', 403);
|
||||
throw new HttpResponseException($response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('set_timezone')) {
|
||||
function set_timezone($timezone = null)
|
||||
{
|
||||
$defaultTimezone = Config::get('app.default_timezone');
|
||||
$timezone = is_null($timezone) ? get_sys_config('time_zone') : $timezone;
|
||||
if ($timezone && $defaultTimezone != $timezone) {
|
||||
Config::set([
|
||||
'app.default_timezone' => $timezone
|
||||
]);
|
||||
date_default_timezone_set($timezone);
|
||||
}
|
||||
}
|
||||
}
|
@ -19,6 +19,12 @@ class Api extends BaseController
|
||||
*/
|
||||
protected $responseType = 'json';
|
||||
|
||||
/**
|
||||
* 应用站点系统设置
|
||||
* @var bool
|
||||
*/
|
||||
protected $useSystemSettings = true;
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
@ -29,6 +35,13 @@ class Api extends BaseController
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
if ($this->useSystemSettings) {
|
||||
// ip检查
|
||||
ip_check();
|
||||
// 时区设定
|
||||
set_timezone();
|
||||
}
|
||||
|
||||
parent::initialize();
|
||||
$this->request->filter('trim,strip_tags,htmlspecialchars');
|
||||
|
||||
|
@ -26,7 +26,8 @@
|
||||
"topthink/think-multi-app": "^1.0",
|
||||
"ext-mysqli": "*",
|
||||
"topthink/think-throttle": "^1.3",
|
||||
"phpmailer/phpmailer": "^6.6"
|
||||
"phpmailer/phpmailer": "^6.6",
|
||||
"symfony/http-foundation": "^2.7 || ^3.0 || ^4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "^4.2",
|
||||
|
Loading…
Reference in New Issue
Block a user