From 47d6a60f4ce1f7f72ab3963be58a82e168640ae5 Mon Sep 17 00:00:00 2001 From: WispX <1591788658@qq.com> Date: Wed, 18 Mar 2020 09:11:14 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=A2=9E=E5=8A=A0IP=E5=B0=81?= =?UTF-8?q?=E7=A6=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/http/middleware/Initialize.php | 14 +++++++++++++- application/sql/install.sql | 1 + application/sql/update.sql | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/application/http/middleware/Initialize.php b/application/http/middleware/Initialize.php index a3b60234..94913026 100644 --- a/application/http/middleware/Initialize.php +++ b/application/http/middleware/Initialize.php @@ -2,10 +2,15 @@ namespace app\http\middleware; +use app\common\traits\Core; +use think\exception\HttpResponseException; +use think\facade\Response; use think\Request; class Initialize { + use Core; + public function handle(Request $request, \Closure $next) { // 检测程序是否已安装 @@ -15,7 +20,14 @@ class Initialize } } - // ... + // 检测封禁IP + $banIp = $this->getConfig('ban_ip'); + if ($banIp) { + $ips = explode(',', str_replace(',', ',', $banIp)); + if (in_array($request->ip(), $ips)) { + throw new HttpResponseException(Response::code(403)); + } + } return $next($request); } diff --git a/application/sql/install.sql b/application/sql/install.sql index e8a9b7f2..f395cfe5 100644 --- a/application/sql/install.sql +++ b/application/sql/install.sql @@ -133,6 +133,7 @@ INSERT INTO `lsky_config` (`id`, `key`, `type`, `input_type`, `name`, `title`, ` (NULL, 'other', 'bool', 'checkbox', 'soft_delete', '软删除', '删除图片时不删除源文件,不建议开启', '0', ''), (NULL, 'other', 'bool', 'checkbox', 'open_api', '开启API', '是否开放接口', '0', ''), +(NULL, 'other', 'textarea', 'textarea', 'ban_ip', '封禁IP', '封禁IP, 多个使用逗号隔开', '', ''), (NULL, 'storage_strategy', 'select', 'text', 'storage_strategy', '储存策略', NULL, 'local', ''), (NULL, 'local', 'text', 'text', 'local_cdn_domain', '域名', NULL, '', ''), diff --git a/application/sql/update.sql b/application/sql/update.sql index fb2cd826..5e2ccc9d 100644 --- a/application/sql/update.sql +++ b/application/sql/update.sql @@ -100,4 +100,5 @@ UPDATE `lsky_config` SET `value` = '1.5.8' WHERE `lsky_config`.`name` = 'system_ -- v1.6.0 UPDATE `lsky_config` SET `value` = '1.6.0' WHERE `lsky_config`.`name` = 'system_version'; INSERT IGNORE INTO `lsky_config` (`id`, `key`, `type`, `input_type`, `name`, `title`, `tip`, `value`, `extend`) VALUES +(NULL, 'other', 'textarea', 'textarea', 'ban_ip', '封禁IP', '封禁IP, 多个使用逗号隔开', '', ''), (NULL, 'remote', 'bool', 'checkbox', 'remote_pasv', '被动模式', NULL, '0', '');