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",