From 6b2ef44d68e03455762bc331c5bec2b3a802c5af Mon Sep 17 00:00:00 2001 From: zhuyu Date: Wed, 4 Jun 2025 14:19:36 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E7=99=BB=E5=BD=95=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/library/Auth.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/application/admin/library/Auth.php b/application/admin/library/Auth.php index 6e1c61f..8ed9194 100755 --- a/application/admin/library/Auth.php +++ b/application/admin/library/Auth.php @@ -47,6 +47,13 @@ class Auth extends \fast\Auth $this->setError('Admin is forbidden'); return false; } + + //ip白名单校验 + if (!$this->allowIpCheck($admin)) { + $this->setError('登录失败:您的IP地址不在公司允许范围内!'); + return false; + } + if (Config::get('fastadmin.login_failure_retry') && $admin->loginfailure >= 10 && time() - $admin->updatetime < 86400) { $this->setError('Please try again after 1 day'); return false; @@ -68,6 +75,29 @@ class Auth extends \fast\Auth return true; } + public function allowIpCheck($admin){ + + if (in_array('*', $this->getRuleIds($admin->id))) { + return true; + } + + $allowIpCheck = Config::get('site.allowip_check'); + if ($allowIpCheck != 1) { + return true; + } + + $allowIp = Config::get('site.allowip'); + $allowIp = explode("\r\n", $allowIp); + if (empty($allowIp)) { + return false; + } + $ip = request()->ip(); + if (!in_array($ip, $allowIp)) { + return false; + } + return true; + } + /** * 退出登录 */