新增maxmind数据库本地判断国家,并且将优先级调整至最高
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* 流量判定主流水线
|
||||
*
|
||||
* 阶段顺序(不可调换):
|
||||
* 1. Session 快速路径 → 2. 黑白名单 → 3. 广告来源限制 → 4. 临时链接 → 5. API/指纹
|
||||
* 1. Session 快速路径 → 2. GeoIP 国家 → 3. 黑白名单 → 4. 广告来源 → 5. 临时链接 → 6. API/指纹
|
||||
*/
|
||||
class CheckPipeline
|
||||
{
|
||||
@@ -34,6 +34,13 @@ class CheckPipeline
|
||||
cloak_dbg_step(__LINE__, 'Session 快速路径', 'skip', '未命中缓存,进入完整判定流程(DEBUG 已重置 visit_to_*)');
|
||||
}
|
||||
|
||||
CloakPipelineTimer::stage('GeoIP国家判定');
|
||||
include __DIR__ . '/stages/check_country_geoip.inc.php';
|
||||
if (!empty($_SESSION['check_result'])) {
|
||||
CloakPipelineTimer::finish();
|
||||
return;
|
||||
}
|
||||
|
||||
CloakPipelineTimer::stage('黑白名单');
|
||||
include __DIR__ . '/stages/apply_whitelist_blacklist.inc.php';
|
||||
CloakPipelineTimer::stage('广告来源限制');
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* 屏蔽模式:GeoIP 国家判定(本地 MaxMind + 30 天 IP 缓存)
|
||||
*
|
||||
* 依赖全局:$v_info, $reason, $__cloak_debug_on
|
||||
*/
|
||||
if (!defined('SHOW_SITE_MODE_SWITCH') || SHOW_SITE_MODE_SWITCH !== 'ip_check') {
|
||||
return;
|
||||
}
|
||||
if (!defined('CLOAK_GEOIP_ENABLED') || strtoupper(CLOAK_GEOIP_ENABLED) !== 'ON') {
|
||||
return;
|
||||
}
|
||||
if (!empty($_SESSION['check_result'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ip = ClientIpResolver::resolve();
|
||||
if ($ip !== '' && $ip !== '0.0.0.0') {
|
||||
$v_info->v_ip = $ip;
|
||||
$_SESSION['gcu_ip'] = $ip;
|
||||
}
|
||||
|
||||
$geoMeta = GeoIpCountryResolver::resolveWithMeta($ip);
|
||||
$countryCode = $geoMeta['code'];
|
||||
$geoSource = $geoMeta['source'];
|
||||
|
||||
if ($countryCode !== null && $countryCode !== '') {
|
||||
$v_info->v_country = $countryCode;
|
||||
$_SESSION['gcu_country'] = $countryCode;
|
||||
}
|
||||
|
||||
$allowlist = CountryAllowlist::parse(defined('SHOW_SITE_COUNTRY') ? SHOW_SITE_COUNTRY : '');
|
||||
if (!CountryAllowlist::isAllowed($countryCode, $allowlist)) {
|
||||
$_SESSION['check_result'] = 'false';
|
||||
if ($countryCode === null || $countryCode === '') {
|
||||
$reason = '无法识别访客国家';
|
||||
} else {
|
||||
$reason = '国家不符:' . $countryCode;
|
||||
}
|
||||
if (!empty($GLOBALS['__cloak_debug_on'])) {
|
||||
cloak_dbg_step(__LINE__, 'GeoIP国家判定', 'fail', $reason, [
|
||||
'ip' => $ip,
|
||||
'country' => $countryCode,
|
||||
'allowlist' => $allowlist,
|
||||
'geo_source' => $geoSource,
|
||||
]);
|
||||
cloak_dbg_record(__LINE__, 'false', $reason, ['stage' => 'geoip_country']);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($GLOBALS['__cloak_debug_on'])) {
|
||||
cloak_dbg_step(__LINE__, 'GeoIP国家判定', 'pass', '国家允许或列表为空', [
|
||||
'ip' => $ip,
|
||||
'country' => $countryCode,
|
||||
'allowlist' => $allowlist,
|
||||
'geo_source' => $geoSource,
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user