From bd4b5c6dd3ed0af4522d202da67e21a1cfb830fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=99=E7=A0=81=E7=94=9F=E8=8A=B1?= <18523774412@qq.com> Date: Thu, 21 Jul 2022 10:29:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=AD=E7=9A=84=E7=A6=81=E6=AD=A2=E8=AE=BF?= =?UTF-8?q?=E9=97=AEIP=E5=92=8C=E6=97=B6=E5=8C=BA=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/model/Config.php | 2 ++ app/api/controller/Install.php | 2 ++ app/api/middleware.php | 1 - app/common.php | 30 ++++++++++++++++++++++++++++++ app/common/controller/Api.php | 13 +++++++++++++ composer.json | 3 ++- 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/app/admin/model/Config.php b/app/admin/model/Config.php index e76698c7..da9d935e 100644 --- a/app/admin/model/Config.php +++ b/app/admin/model/Config.php @@ -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 : []; diff --git a/app/api/controller/Install.php b/app/api/controller/Install.php index 50c4a9ab..22b56ab0 100644 --- a/app/api/controller/Install.php +++ b/app/api/controller/Install.php @@ -20,6 +20,8 @@ use app\admin\model\User as UserModel; */ class Install extends Api { + protected $useSystemSettings = false; + /** * 环境检查状态 */ diff --git a/app/api/middleware.php b/app/api/middleware.php index 502342ae..8b6c89a2 100644 --- a/app/api/middleware.php +++ b/app/api/middleware.php @@ -1,5 +1,4 @@ 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); + } + } } \ No newline at end of file diff --git a/app/common/controller/Api.php b/app/common/controller/Api.php index f9a4f250..eff56eb6 100644 --- a/app/common/controller/Api.php +++ b/app/common/controller/Api.php @@ -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'); diff --git a/composer.json b/composer.json index 03776648..f3501c13 100644 --- a/composer.json +++ b/composer.json @@ -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",