日志升级与缓存修复最终版
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../WhitelistGate.php';
|
||||
require_once __DIR__ . '/../CloakJudgmentCache.php';
|
||||
require_once __DIR__ . '/../RiskSecondaryGate.php';
|
||||
|
||||
/**
|
||||
* 流量判定主流水线
|
||||
*
|
||||
* 阶段顺序(不可调换):
|
||||
* 1. Session 快速路径 → 2. GeoIP 国家 → 3. 黑白名单 → 4. 广告来源 → 5. 临时链接 → 6. API/指纹
|
||||
* 优先级(高 → 低):
|
||||
* 1. 白名单链接参数 WHITE_PARAMS
|
||||
* 2. 白名单 IP
|
||||
* 3. 黑名单
|
||||
* 4. 屏蔽模式:安全页(zp) / 真实页(fp)
|
||||
* 5. 正常屏蔽(ip_check):Session 最终缓存 > 阶段缓存续跑 > 完整判定
|
||||
*/
|
||||
class CheckPipeline
|
||||
{
|
||||
/**
|
||||
* 在调用方(ip_check 顶层)作用域执行完整判定链。
|
||||
* 依赖全局:$v_info, $config_name, $__cloak_debug_on, $reason
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function run()
|
||||
@@ -23,15 +28,64 @@ class CheckPipeline
|
||||
|
||||
CloakPipelineTimer::init();
|
||||
|
||||
CloakPipelineTimer::stage('Session快速路径');
|
||||
if (self::resolveSessionFastPath()) {
|
||||
CloakPipelineTimer::stage('白名单链接参数');
|
||||
if (self::resolveWhitelistParamsFastPath()) {
|
||||
include __DIR__ . '/stages/resolve_whitelist_fast_path_hit.inc.php';
|
||||
CloakPipelineTimer::finish();
|
||||
return;
|
||||
}
|
||||
|
||||
CloakPipelineTimer::stage('白名单IP');
|
||||
if (self::resolveWhitelistIpFastPath()) {
|
||||
include __DIR__ . '/stages/resolve_whitelist_fast_path_hit.inc.php';
|
||||
CloakPipelineTimer::finish();
|
||||
return;
|
||||
}
|
||||
|
||||
CloakPipelineTimer::stage('黑名单');
|
||||
if (self::resolveBlacklistFastPath()) {
|
||||
include __DIR__ . '/stages/resolve_blacklist_fast_path_hit.inc.php';
|
||||
CloakPipelineTimer::finish();
|
||||
return;
|
||||
}
|
||||
|
||||
CloakPipelineTimer::stage('安全页模式');
|
||||
if (self::resolveZpFastPath()) {
|
||||
include __DIR__ . '/stages/resolve_zp_fast_path_hit.inc.php';
|
||||
CloakPipelineTimer::finish();
|
||||
return;
|
||||
}
|
||||
|
||||
CloakPipelineTimer::stage('真实页模式');
|
||||
if (self::resolveFpFastPath()) {
|
||||
include __DIR__ . '/stages/resolve_fp_fast_path_hit.inc.php';
|
||||
CloakPipelineTimer::finish();
|
||||
return;
|
||||
}
|
||||
|
||||
CloakPipelineTimer::stage('客户端缓存快速路径');
|
||||
if (self::resolveClientCacheFastPath()) {
|
||||
include __DIR__ . '/stages/resolve_session_fast_path_hit.inc.php';
|
||||
CloakPipelineTimer::finish();
|
||||
return;
|
||||
}
|
||||
|
||||
CloakPipelineTimer::stage('客户端阶段缓存续跑');
|
||||
if (self::resolvePartialCacheResume()) {
|
||||
include __DIR__ . '/stages/run_main_api_fingerprint.inc.php';
|
||||
CloakPipelineTimer::finish();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_step(__LINE__, 'Session 快速路径', 'skip', '未命中缓存,进入完整判定流程(DEBUG 已重置 visit_to_*)');
|
||||
cloak_dbg_step(__LINE__, '完整判定', 'info', '未命中早期快速路径,进入完整判定');
|
||||
}
|
||||
|
||||
CloakPipelineTimer::stage('黑白名单');
|
||||
include __DIR__ . '/stages/apply_whitelist_blacklist.inc.php';
|
||||
if (!empty($_SESSION['check_result'])) {
|
||||
CloakPipelineTimer::finish();
|
||||
return;
|
||||
}
|
||||
|
||||
CloakPipelineTimer::stage('GeoIP国家判定');
|
||||
@@ -41,8 +95,6 @@ class CheckPipeline
|
||||
return;
|
||||
}
|
||||
|
||||
CloakPipelineTimer::stage('黑白名单');
|
||||
include __DIR__ . '/stages/apply_whitelist_blacklist.inc.php';
|
||||
CloakPipelineTimer::stage('广告来源限制');
|
||||
include __DIR__ . '/stages/run_ad_source_guard.inc.php';
|
||||
CloakPipelineTimer::stage('临时链接参数');
|
||||
@@ -51,20 +103,108 @@ class CheckPipeline
|
||||
CloakPipelineTimer::finish();
|
||||
}
|
||||
|
||||
public static function resolveWhitelistParamsFastPath()
|
||||
{
|
||||
return WhitelistGate::matchesWhitelistParams();
|
||||
}
|
||||
|
||||
public static function resolveWhitelistIpFastPath()
|
||||
{
|
||||
global $v_info;
|
||||
|
||||
if (WhitelistGate::matchesWhitelistParams()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return WhitelistGate::matchesWhitelistIp(WhitelistGate::resolveVisitorIp($v_info));
|
||||
}
|
||||
|
||||
public static function resolveBlacklistFastPath()
|
||||
{
|
||||
global $v_info;
|
||||
|
||||
if (!defined('BLACKLIST_GROUP_ID') || (int) BLACKLIST_GROUP_ID <= 0) {
|
||||
return false;
|
||||
}
|
||||
$blEntries = ip_group_list_addresses((int) BLACKLIST_GROUP_ID);
|
||||
|
||||
return ip_visitor_in_blacklist_entries($v_info->v_ip, $blEntries);
|
||||
}
|
||||
|
||||
public static function resolveClientCacheFastPath()
|
||||
{
|
||||
global $__cloak_debug_on, $v_info;
|
||||
|
||||
if ($__cloak_debug_on || SHOW_SITE_MODE_SWITCH !== 'ip_check') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cached = CloakJudgmentCache::getFinal();
|
||||
if ($cached === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CloakJudgmentCache::applyToSession($cached);
|
||||
CloakJudgmentCache::applyToVisitorInfo($v_info, $cached);
|
||||
|
||||
if ($__cloak_debug_on) {
|
||||
CloakDebugPage::setFlag('session_cached', true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function resolvePartialCacheResume()
|
||||
{
|
||||
global $__cloak_debug_on, $v_info, $reason;
|
||||
|
||||
if ($__cloak_debug_on || SHOW_SITE_MODE_SWITCH !== 'ip_check') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cached = CloakJudgmentCache::get();
|
||||
if (!CloakJudgmentCache::isPartial($cached)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CloakJudgmentCache::applyToSession($cached);
|
||||
CloakJudgmentCache::applyToVisitorInfo($v_info, $cached);
|
||||
$_SESSION['visit_to_2'] = '2';
|
||||
|
||||
if ($reason === '') {
|
||||
$reason = 'Session byApi阶段缓存:待二次风控';
|
||||
}
|
||||
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_step(__LINE__, '客户端阶段缓存续跑', 'pass', '命中 byapi 阶段缓存,跳过 GeoIP/Guard/byApi');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否命中 session 缓存结果(true = 跳过完整判定)
|
||||
*
|
||||
* @return bool
|
||||
* @deprecated
|
||||
*/
|
||||
public static function resolveSessionFastPath()
|
||||
{
|
||||
global $__cloak_debug_on;
|
||||
return self::resolveClientCacheFastPath();
|
||||
}
|
||||
|
||||
return (
|
||||
!$__cloak_debug_on
|
||||
&& SHOW_SITE_MODE_SWITCH === 'ip_check'
|
||||
&& isset($_SESSION['check_result'])
|
||||
&& ($_SESSION['check_result'] === 'true' || $_SESSION['check_result'] === 'false')
|
||||
);
|
||||
/**
|
||||
* @deprecated 使用 resolveWhitelistParamsFastPath / resolveWhitelistIpFastPath
|
||||
*/
|
||||
public static function resolveWhitelistFastPath()
|
||||
{
|
||||
return self::resolveWhitelistParamsFastPath() || self::resolveWhitelistIpFastPath();
|
||||
}
|
||||
|
||||
public static function resolveZpFastPath()
|
||||
{
|
||||
return defined('SHOW_SITE_MODE_SWITCH') && SHOW_SITE_MODE_SWITCH === 'zp';
|
||||
}
|
||||
|
||||
public static function resolveFpFastPath()
|
||||
{
|
||||
return defined('SHOW_SITE_MODE_SWITCH') && SHOW_SITE_MODE_SWITCH === 'fp';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../WhitelistGate.php';
|
||||
require_once __DIR__ . '/../Page/FpPageRenderer.php';
|
||||
require_once __DIR__ . '/../Page/RiskPageRenderer.php';
|
||||
require_once __DIR__ . '/../FpUrlHelper.php';
|
||||
require_once __DIR__ . '/../RiskSecondaryGate.php';
|
||||
require_once __DIR__ . '/../RiskSecondaryCache.php';
|
||||
require_once __DIR__ . '/../RiskSecondarySession.php';
|
||||
require_once __DIR__ . '/../ClientIpResolver.php';
|
||||
|
||||
/**
|
||||
@@ -18,6 +20,12 @@ class RouteResolver
|
||||
{
|
||||
extract($ctx, EXTR_SKIP);
|
||||
|
||||
// 白名单优先于正品模式:跳过二次风控等,直达真实页
|
||||
if (!empty($_SESSION['cloak_whitelist_fast'])) {
|
||||
self::renderWhitelistFp($logs, $config_name ?? '');
|
||||
return;
|
||||
}
|
||||
|
||||
// 正品模式:始终走安全页逻辑
|
||||
if (SHOW_SITE_MODE_SWITCH == 'zp') {
|
||||
self::renderSafePage($logs, $v_info);
|
||||
@@ -28,13 +36,26 @@ class RouteResolver
|
||||
|| SHOW_SITE_MODE_SWITCH == 'fp';
|
||||
|
||||
if ($showFp) {
|
||||
self::renderFpOrRisk($logs, $v_info);
|
||||
self::renderFpOrRisk($logs, $v_info, $config_name ?? '');
|
||||
return;
|
||||
}
|
||||
|
||||
self::renderSafePage($logs, $v_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 白名单快速路径:写日志并输出真实页,不触发二次风控 / API
|
||||
*
|
||||
* @param array $logs
|
||||
* @param string $config_name
|
||||
*/
|
||||
private static function renderWhitelistFp(array $logs, $config_name = '')
|
||||
{
|
||||
$logs['result'] = 'true';
|
||||
$logs['reason'] = '';
|
||||
self::renderFpPage($logs, $config_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $logs
|
||||
*/
|
||||
@@ -69,7 +90,7 @@ class RouteResolver
|
||||
}
|
||||
}
|
||||
|
||||
private static function renderFpOrRisk(array $logs, $v_info)
|
||||
private static function renderFpOrRisk(array $logs, $v_info, $config_name = '')
|
||||
{
|
||||
if (AUTO_BLACK == 'ON') {
|
||||
$times = howmanytimesbyip($v_info->v_ip);
|
||||
@@ -81,21 +102,22 @@ class RouteResolver
|
||||
$_SESSION['visit_to_3'] = '1';
|
||||
}
|
||||
|
||||
if (RiskSecondaryGate::isEnabled()) {
|
||||
if (RiskSecondaryGate::isEnabledForRequest()) {
|
||||
$cached = RiskSecondaryCache::get(ClientIpResolver::resolve());
|
||||
if ($cached !== null) {
|
||||
self::renderFromRiskCache($logs, $v_info, $cached);
|
||||
self::renderFromRiskCache($logs, $v_info, $cached, $config_name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (($_SESSION['visit_to_3'] ?? '1') != '3'
|
||||
&& RiskSecondaryGate::isEnabled()) {
|
||||
&& RiskSecondaryGate::isEnabledForRequest()) {
|
||||
// 二次风控:先写 wait 状态,f_check 完成后再更新 result / fp_url(避免 true+空跳转)
|
||||
$logs['result'] = 'wait';
|
||||
$logs['reason'] = '二次风控检测中';
|
||||
$logs['fp_url'] = '';
|
||||
$log_id = write_log_db($logs);
|
||||
RiskSecondarySession::markWaitLog($log_id);
|
||||
$riskCtx = [
|
||||
'logs' => $logs,
|
||||
'v_info' => $v_info,
|
||||
@@ -111,22 +133,36 @@ class RouteResolver
|
||||
|
||||
$logs['result'] = 'true';
|
||||
$logs['reason'] = '';
|
||||
FpPageRenderer::render(['logs' => $logs]);
|
||||
self::renderFpPage($logs, $config_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $logs
|
||||
* @param string $config_name
|
||||
*/
|
||||
private static function renderFpPage(array $logs, $config_name = '')
|
||||
{
|
||||
FpPageRenderer::render([
|
||||
'logs' => $logs,
|
||||
'config_name' => $config_name,
|
||||
'skip_log' => RiskSecondarySession::shouldSkipFpPageLog(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 二次风控 Session 缓存命中:跳过 cloakjs / byApiRisk。
|
||||
*
|
||||
* @param array $logs
|
||||
* @param array $cached
|
||||
* @param array $logs
|
||||
* @param array $cached
|
||||
* @param string $config_name
|
||||
*/
|
||||
private static function renderFromRiskCache(array $logs, $v_info, array $cached)
|
||||
private static function renderFromRiskCache(array $logs, $v_info, array $cached, $config_name = '')
|
||||
{
|
||||
RiskSecondaryCache::applyToSession($cached);
|
||||
$apiResponse = RiskSecondaryCache::toApiResponse($cached);
|
||||
|
||||
$logs['result'] = $apiResponse['result'] ? 'true' : 'false';
|
||||
$logs['reason'] = $apiResponse['reason'];
|
||||
$logs['reason'] = cloak_cache_hit_log_reason($logs['result']);
|
||||
$logs['fp_url'] = trim((string) ($apiResponse['link'] ?? ''));
|
||||
if ($logs['fp_url'] === '') {
|
||||
$logs['fp_url'] = $logs['result'] === 'true'
|
||||
@@ -139,7 +175,7 @@ class RouteResolver
|
||||
return;
|
||||
}
|
||||
|
||||
FpPageRenderer::render(['logs' => $logs]);
|
||||
self::renderFpPage($logs, $config_name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* 仅用本地 MaxMind 解析国家并写入访客信息/Session(不做国家允许列表或其它判定)
|
||||
*
|
||||
* 依赖全局:$v_info, $__cloak_debug_on
|
||||
*/
|
||||
$ip = ClientIpResolver::resolve();
|
||||
if ($ip !== '' && $ip !== '0.0.0.0') {
|
||||
$v_info->v_ip = $ip;
|
||||
$_SESSION['gcu_ip'] = $ip;
|
||||
}
|
||||
|
||||
if (GeoIpCountryResolver::isAvailable()) {
|
||||
$geoMeta = GeoIpCountryResolver::resolveWithMeta($ip);
|
||||
$countryCode = $geoMeta['code'];
|
||||
$geoSource = $geoMeta['source'];
|
||||
if ($countryCode !== null && $countryCode !== '') {
|
||||
$v_info->v_country = $countryCode;
|
||||
$_SESSION['gcu_country'] = $countryCode;
|
||||
}
|
||||
if (!empty($GLOBALS['__cloak_debug_on'])) {
|
||||
cloak_dbg_step(__LINE__, 'MaxMind国家记录', 'log', '仅记录国家,不参与判定', [
|
||||
'ip' => $ip,
|
||||
'country' => $countryCode,
|
||||
'geo_source' => $geoSource,
|
||||
]);
|
||||
}
|
||||
} elseif (!empty($GLOBALS['__cloak_debug_on'])) {
|
||||
cloak_dbg_step(__LINE__, 'MaxMind国家记录', 'skip', '本地 GeoIP 库不可用');
|
||||
}
|
||||
@@ -1,69 +1,46 @@
|
||||
<?php
|
||||
//指定ip显示仿品(优先数据库白名单组,其次兼容旧版 SHOW_SITE_IP 逗号列表)
|
||||
if (defined('WHITELIST_GROUP_ID') && (int) WHITELIST_GROUP_ID > 0) {
|
||||
$ips_fp_ary = ip_group_list_addresses((int) WHITELIST_GROUP_ID);
|
||||
} else {
|
||||
$ips_fp_ary = array_filter(array_map('trim', explode(',', SHOW_SITE_IP)), static function ($v) {
|
||||
return $v !== '';
|
||||
});
|
||||
}
|
||||
$reason = ""; // 判断理由
|
||||
|
||||
$whiteParamsMatched = false;
|
||||
if( !empty(WHITE_PARAMS) ) {
|
||||
$wparams = explode('=', WHITE_PARAMS, 2);
|
||||
|
||||
if(count($wparams) == 2) {
|
||||
$pk = $wparams[0];
|
||||
$pv = $wparams[1];
|
||||
}
|
||||
|
||||
if(isset($_GET[$pk]) && strip_tags($_GET[$pk]) == $pv) {
|
||||
$whiteParamsMatched = true;
|
||||
|
||||
// 黑白名单(完整判定链内):链接参数白名单 > IP 白名单 > 黑名单
|
||||
$reason = $reason ?? '';
|
||||
|
||||
if (WhitelistGate::matchesWhitelistParams()) {
|
||||
$_SESSION['check_result'] = 'true';
|
||||
$reason = '白名单链接参数';
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_step(__LINE__, '链接参数白名单', 'pass', defined('WHITE_PARAMS') ? WHITE_PARAMS : '');
|
||||
cloak_dbg_record(__LINE__, 'true', $reason, ['stage' => 'whitelist_params']);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (WhitelistGate::matchesWhitelistIp(WhitelistGate::resolveVisitorIp($v_info))) {
|
||||
$_SESSION['check_result'] = 'true';
|
||||
$reason = '白名单';
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_step(__LINE__, 'IP 白名单', 'pass', 'IP 在白名单组/列表中');
|
||||
cloak_dbg_record(__LINE__, 'true', $reason, ['stage' => 'whitelist_ip']);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($__cloak_debug_on && defined('WHITE_PARAMS') && WHITE_PARAMS !== '') {
|
||||
cloak_dbg_step(__LINE__, '链接参数白名单', 'skip', '参数不匹配: ' . WHITE_PARAMS);
|
||||
}
|
||||
|
||||
$match = false;
|
||||
if (defined('BLACKLIST_GROUP_ID') && (int) BLACKLIST_GROUP_ID > 0) {
|
||||
$blEntries = ip_group_list_addresses((int) BLACKLIST_GROUP_ID);
|
||||
$match = ip_visitor_in_blacklist_entries($v_info->v_ip, $blEntries);
|
||||
$match = ip_visitor_in_blacklist_entries($v_info->v_ip, $blEntries);
|
||||
}
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_step(__LINE__,'黑名单检查', $match ? 'fail' : 'pass', $match ? 'IP 在黑名单组内' : '未命中黑名单', [
|
||||
'ip' => $v_info->v_ip,
|
||||
cloak_dbg_step(__LINE__, '黑名单检查', $match ? 'fail' : 'pass', $match ? 'IP 在黑名单组内' : '未命中黑名单', [
|
||||
'ip' => $v_info->v_ip,
|
||||
'group_id' => defined('BLACKLIST_GROUP_ID') ? BLACKLIST_GROUP_ID : 0,
|
||||
]);
|
||||
}
|
||||
if ($match) {
|
||||
$_SESSION["check_result"] = "false";
|
||||
$reason = "黑名单";
|
||||
$_SESSION['check_result'] = 'false';
|
||||
$reason = '黑名单';
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_record(__LINE__,'false', $reason, ['stage' => 'blacklist']);
|
||||
cloak_dbg_record(__LINE__, 'false', $reason, ['stage' => 'blacklist']);
|
||||
}
|
||||
}
|
||||
|
||||
if(in_array($v_info->v_ip, $ips_fp_ary) ) {
|
||||
$_SESSION["check_result"] = "true";
|
||||
$reason = "白名单";
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_step(__LINE__,'IP 白名单', 'pass', 'IP 在白名单组/列表中');
|
||||
cloak_dbg_record(__LINE__,'true', $reason, ['stage' => 'whitelist_ip']);
|
||||
}
|
||||
} elseif( !empty(WHITE_PARAMS) ) {
|
||||
$wparams = explode('=', WHITE_PARAMS, 2);
|
||||
if(count($wparams) == 2) {
|
||||
$pk = $wparams[0];
|
||||
$pv = $wparams[1];
|
||||
}
|
||||
if(isset($_GET[$pk]) && strip_tags($_GET[$pk]) == $pv) {
|
||||
$_SESSION["check_result"] = "true";
|
||||
$reason = "白名单链接参数";
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_step(__LINE__,'链接参数白名单', 'pass', WHITE_PARAMS);
|
||||
cloak_dbg_record(__LINE__,'true', $reason, ['stage' => 'whitelist_params']);
|
||||
}
|
||||
}
|
||||
} elseif ($__cloak_debug_on && !empty(WHITE_PARAMS)) {
|
||||
cloak_dbg_step(__LINE__,'链接参数白名单', 'skip', '参数不匹配: ' . WHITE_PARAMS);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* 黑名单快速路径:记录国家后直达安全页判定
|
||||
*/
|
||||
include __DIR__ . '/apply_geoip_country_log_only.inc.php';
|
||||
|
||||
global $reason;
|
||||
|
||||
$_SESSION['check_result'] = 'false';
|
||||
$reason = '黑名单';
|
||||
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_step(__LINE__, '黑名单快速路径', 'fail', 'IP 在黑名单组内');
|
||||
cloak_dbg_record(__LINE__, 'false', $reason, ['stage' => 'blacklist_fast_path']);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 真实页模式(fp)快速路径:跳过正常屏蔽判定与二次风控,直达真实页
|
||||
*/
|
||||
include __DIR__ . '/apply_geoip_country_log_only.inc.php';
|
||||
|
||||
global $reason;
|
||||
|
||||
$_SESSION['check_result'] = 'true';
|
||||
$reason = '真实页模式';
|
||||
$_SESSION['visit_to_2'] = '2';
|
||||
$_SESSION['visit_to_3'] = '3';
|
||||
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_step(__LINE__, '真实页模式', 'pass', '跳过正常屏蔽判定链');
|
||||
cloak_dbg_record(__LINE__, 'true', $reason, ['stage' => 'fp_fast_path']);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 白名单快速路径:仅 MaxMind 国家记录,跳过其余判定,直达真实页
|
||||
*/
|
||||
include __DIR__ . '/apply_geoip_country_log_only.inc.php';
|
||||
|
||||
global $reason;
|
||||
|
||||
$_SESSION['check_result'] = 'true';
|
||||
$reason = WhitelistGate::matchReason($v_info);
|
||||
$_SESSION['visit_to_3'] = '3';
|
||||
$_SESSION['cloak_whitelist_fast'] = true;
|
||||
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_step(__LINE__, '白名单快速路径', 'pass', $reason);
|
||||
cloak_dbg_record(__LINE__, 'true', $reason, ['stage' => 'whitelist_fast_path']);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* 正品模式快速路径:仅 MaxMind 国家记录,跳过其余判定,无条件安全页
|
||||
*/
|
||||
include __DIR__ . '/apply_geoip_country_log_only.inc.php';
|
||||
|
||||
global $reason;
|
||||
|
||||
$_SESSION['check_result'] = 'false';
|
||||
$reason = '正品模式';
|
||||
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_step(__LINE__, '正品模式', 'pass', '仅记录国家,无条件安全页');
|
||||
cloak_dbg_record(__LINE__, 'false', $reason, ['stage' => 'zp_fast_path']);
|
||||
}
|
||||
@@ -22,6 +22,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (($_SESSION['visit_to_2'] ?? '') == '2' && class_exists('CloakJudgmentCache', false) && !CloakJudgmentCache::hasSession()) {
|
||||
$_SESSION['visit_to_2'] = '1';
|
||||
}
|
||||
|
||||
if($_SESSION['visit_to_1'] == '1' && $_SESSION['visit_to_2'] != '2') // $_SESSION['visit_to_2'] 为2时表示已经判断过所有规则。
|
||||
{
|
||||
if ($__cloak_debug_on) {
|
||||
@@ -86,7 +90,7 @@
|
||||
// 已完成指纹跳转(URL 含 time),但 Cookie 未写入:终止再次重定向
|
||||
$v_info->check_result = 'false';
|
||||
|
||||
$reason = cloak_reason_or($reason, '指纹Cookie未写入(已完成前端检测)');
|
||||
$reason = cloak_reason_or($reason, '已完成前端检测,但指纹Cookie未写入(隐私模式、广告拦截等可能阻止Cookie写入)');
|
||||
$_SESSION['check_result'] = 'false';
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_step(__LINE__, 'JS 指纹检测', 'fail', 'URL 含 time 但指纹 Cookie 缺失,停止重定向');
|
||||
@@ -149,6 +153,14 @@
|
||||
if ($__api_return !== null) {
|
||||
$_SESSION["check_result"] = trim($v_info->check_result);
|
||||
$reason = cloak_api_reason($__api_return, $_SESSION["check_result"]);
|
||||
if (class_exists('CloakJudgmentCache', false)) {
|
||||
CloakJudgmentCache::storeFromByApi([
|
||||
'ip' => $v_info->v_ip,
|
||||
'country' => $v_info->v_country,
|
||||
'result' => $_SESSION['check_result'],
|
||||
'reason' => $reason,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$_SESSION["check_result"] = "false";
|
||||
$reason = cloak_reason_or($reason, 'API未调用:缺少访客信息(ip/Browser/Accept-Language)');
|
||||
@@ -175,15 +187,33 @@
|
||||
}
|
||||
}
|
||||
} elseif (($_SESSION['visit_to_2'] ?? '') == '2') {
|
||||
if (!empty($_SESSION["check_result"])) {
|
||||
$cached = class_exists('CloakJudgmentCache', false) ? CloakJudgmentCache::get() : null;
|
||||
if ($cached !== null) {
|
||||
CloakJudgmentCache::applyToSession($cached);
|
||||
CloakJudgmentCache::applyToVisitorInfo($v_info, $cached);
|
||||
$_SESSION['check_result'] = trim((string) ($cached['result'] ?? 'false'));
|
||||
if ($reason === '') {
|
||||
if (CloakJudgmentCache::isPartial($cached)) {
|
||||
$reason = 'Session byApi阶段缓存:待二次风控';
|
||||
} else {
|
||||
$reason = ($_SESSION['check_result'] === 'true')
|
||||
? 'Session API缓存:判定通过'
|
||||
: '缓存';
|
||||
}
|
||||
}
|
||||
} elseif (!empty($_SESSION["check_result"])) {
|
||||
if ($reason === '') {
|
||||
$reason = ($_SESSION['check_result'] === 'true')
|
||||
? 'Session API缓存:判定通过'
|
||||
: 'Session API缓存:判定拒绝';
|
||||
: '缓存';
|
||||
}
|
||||
} else {
|
||||
$_SESSION["check_result"] = 'false';
|
||||
$_SESSION['check_result'] = 'false';
|
||||
$reason = cloak_reason_or($reason, 'Session状态异常(visit_to_2=2但无缓存结果),默认安全页');
|
||||
$_SESSION['visit_to_2'] = '1';
|
||||
if (class_exists('CloakJudgmentCache', false)) {
|
||||
CloakJudgmentCache::clear();
|
||||
}
|
||||
}
|
||||
if ($__cloak_debug_on) {
|
||||
cloak_dbg_step(__LINE__,'主判定块 (API)', 'skip', 'visit_to_2=2,本块已跳过(' . $reason . ')');
|
||||
|
||||
Reference in New Issue
Block a user