Files
ProxyPanel/app/Http/Middleware/isForbidden.php
兔姬桑 ce9618236f 2.5.a 管理路由全面改写 与 代码拆分
1. 全面改写项目-管理面板的路由;
2. 拆分过于Contoller;
3. 优化了按钮过多的图表的显示;
4. 初步应用 Laravel的 表单验证功能;
5. 初步应用 Laravel的 component 功能 拆分/模块化前端代码;
6. 优化部分系统的判断逻辑;
7. 针对2.4.0以前的面板,追加辅助矫正数据库的sql文件;
2020-10-01 12:34:19 +08:00

68 lines
2.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Middleware;
use Agent;
use App\Components\IP;
use Closure;
use Illuminate\Http\Request;
use Log;
use Response;
class isForbidden
{
/**
* 限制机器人、指定IP访问
*
* @param Request $request
* @param Closure $next
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
// 拒绝机器人访问
if (sysConfig('is_forbid_robot') && Agent::isRobot()) {
Log::info("识别到机器人访问(".IP::getClientIp().")");
return Response::view('auth.error', ['message' => trans('error.ForbiddenRobot')], 403);
}
// 拒绝通过订阅链接域名访问网站,防止网站被探测
if (false !== strpos(sysConfig('subscribe_domain'), $request->getHost())
&& !str_contains(sysConfig('subscribe_domain'), sysConfig('website_url'))) {
Log::info("识别到通过订阅链接访问,强制跳转至百度(".IP::getClientIp().")");
return redirect('https://www.baidu.com');
}
$ip = IP::getClientIP();
$ipLocation = IP::getIPInfo($ip);
// 拒绝无IP请求
if (!$ipLocation || empty(array_filter($ipLocation))) {
return Response::view('auth.error', ['message' => trans('error.ForbiddenAccess')], 403);
}
if (!in_array($ipLocation['country'], ['本机地址', '局域网'])) {
// 拒绝大陆IP访问
if (sysConfig('is_forbid_china') && in_array($ipLocation['country'], ['China', '中国'])
&& !in_array($ipLocation['province'], ['香港', '澳门', '台湾', '台湾省'])) {
Log::info('识别到大陆IP拒绝访问'.$ip);
return Response::view('auth.error', ['message' => trans('error.ForbiddenChina')], 403);
}
// 拒绝非大陆IP访问
if (sysConfig('is_forbid_oversea') && !in_array($ipLocation['country'], ['China', '中国', 'Taiwan', 'Hong Kong', 'Macao'])) {
Log::info('识别到海外IP拒绝访问'.$ip.' - '.$ipLocation['country']);
return Response::view('auth.error', ['message' => trans('error.ForbiddenOversea')], 403);
}
}
return $next($request);
}
}