修复配置获取
This commit is contained in:
@@ -134,6 +134,7 @@ if ($__cloak_risk_enhanced) {
|
||||
_0x5aa8d7.set('ip', '<?php echo isset($v_info) && is_object($v_info) ? htmlspecialchars((string) $v_info->v_ip, ENT_QUOTES, 'UTF-8') : ''; ?>');
|
||||
_0x5aa8d7.set('ciso', '<?php echo isset($v_info) && is_object($v_info) ? htmlspecialchars((string) $v_info->v_country, ENT_QUOTES, 'UTF-8') : ''; ?>');
|
||||
_0x5aa8d7.set('log_id', '<?php echo (int) ($log_id ?? 0); ?>');
|
||||
_0x5aa8d7.set('config_name', '<?php echo htmlspecialchars((string) ($config_name ?? ''), ENT_QUOTES, 'UTF-8'); ?>');
|
||||
_0x5aa8d7.set('isEmulator', false);
|
||||
_0x5aa8d7.set('referer', document.referrer);
|
||||
_0x5aa8d7.set('risk_enhanced', __cloakRiskEnhanced);
|
||||
|
||||
+112
-6
@@ -41,7 +41,9 @@ class ConfigLoader
|
||||
}
|
||||
|
||||
/**
|
||||
* 同域多落地页:入口脚本有独立配置时优先脚本名;否则按 HTTP Host(多站/宝塔);再回退脚本名或 index
|
||||
* 同域多落地页:入口脚本有独立配置时优先脚本名;
|
||||
* 伪静态/rewrite 落到 index.php 时从 REQUEST_URI 路径解析配置名;
|
||||
* 否则按 HTTP Host(多站/宝塔);再回退脚本名或 index
|
||||
*
|
||||
* @return string 实际加载的配置名
|
||||
*/
|
||||
@@ -50,13 +52,15 @@ class ConfigLoader
|
||||
$host = $host ?? ($_SERVER['HTTP_HOST'] ?? '');
|
||||
$baseDir = dirname(__DIR__);
|
||||
$scriptSanitized = self::sanitizeConfigName((string) $scriptBaseName);
|
||||
$scriptConfigFile = $baseDir . '/check_config/' . $scriptSanitized . '_config.php';
|
||||
$scriptConfigExists = $scriptSanitized !== 'index'
|
||||
&& $scriptSanitized !== 'ip_check'
|
||||
&& file_exists($scriptConfigFile);
|
||||
if ($scriptConfigExists) {
|
||||
if (self::hasConfigFile($scriptSanitized, $baseDir)) {
|
||||
return self::loadByName($scriptSanitized);
|
||||
}
|
||||
|
||||
$uriConfigName = self::resolveConfigNameFromRequestUri($baseDir);
|
||||
if ($uriConfigName !== null) {
|
||||
return self::loadByName($uriConfigName);
|
||||
}
|
||||
|
||||
if ($host !== '') {
|
||||
return self::loadByHost($host);
|
||||
}
|
||||
@@ -66,6 +70,108 @@ class ConfigLoader
|
||||
return self::loadByName('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 URL 或路径解析落地页配置名(不含 query)。
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function resolveConfigNameFromUrl($url, $baseDir = null)
|
||||
{
|
||||
if ($url === '') {
|
||||
return null;
|
||||
}
|
||||
$path = parse_url($url, PHP_URL_PATH);
|
||||
if (!is_string($path)) {
|
||||
return null;
|
||||
}
|
||||
return self::resolveConfigNameFromPath($path, $baseDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 REQUEST_URI 路径段解析落地页配置名(不含 query)。
|
||||
* 用于 nginx try_files → index.php 等场景:/PH-fwa037?utm=... 仍应对应 PH-fwa037 配置。
|
||||
*
|
||||
* @return string|null 可加载的配置名;无法解析时 null
|
||||
*/
|
||||
public static function resolveConfigNameFromRequestUri($baseDir = null)
|
||||
{
|
||||
$uri = (string) ($_SERVER['REQUEST_URI'] ?? '');
|
||||
if ($uri === '') {
|
||||
return null;
|
||||
}
|
||||
$path = parse_url($uri, PHP_URL_PATH);
|
||||
if (!is_string($path)) {
|
||||
return null;
|
||||
}
|
||||
return self::resolveConfigNameFromPath($path, $baseDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public static function resolveConfigNameFromPath($path, $baseDir = null)
|
||||
{
|
||||
$baseDir = $baseDir ?: dirname(__DIR__);
|
||||
$path = (string) $path;
|
||||
if ($path === '' || $path === '/') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$basename = basename($path);
|
||||
$name = self::sanitizeConfigName($basename);
|
||||
if ($name === 'index' || $name === 'ip_check' || $name === 'f_check') {
|
||||
return null;
|
||||
}
|
||||
if (!self::hasConfigFile($name, $baseDir)) {
|
||||
return null;
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 二次风控 f_check / byApiRisk:优先 hdata.config_name,其次落地页 URL 路径,再 Host 映射。
|
||||
*
|
||||
* @param string $pageUrl hdata.domain(浏览器当前页完整 URL)
|
||||
* @param string|null $fallbackHost 兜底 Host(通常为 HTTP_HOST)
|
||||
* @param string|null $explicitConfigName hdata.config_name(ip_check 阶段已解析的配置名)
|
||||
* @return string 实际加载的配置名
|
||||
*/
|
||||
public static function loadForFingerprint($pageUrl, $fallbackHost = null, $explicitConfigName = null)
|
||||
{
|
||||
$baseDir = dirname(__DIR__);
|
||||
|
||||
if ($explicitConfigName !== null && trim((string) $explicitConfigName) !== '') {
|
||||
$explicit = self::sanitizeConfigName($explicitConfigName);
|
||||
if (self::hasConfigFile($explicit, $baseDir)) {
|
||||
return self::loadByName($explicit, $baseDir);
|
||||
}
|
||||
}
|
||||
|
||||
$fromUrl = self::resolveConfigNameFromUrl((string) $pageUrl, $baseDir);
|
||||
if ($fromUrl !== null) {
|
||||
return self::loadByName($fromUrl, $baseDir);
|
||||
}
|
||||
|
||||
$host = $fallbackHost ?? ($_SERVER['HTTP_HOST'] ?? '');
|
||||
if ($host !== '') {
|
||||
return self::loadByHost($host, $baseDir);
|
||||
}
|
||||
|
||||
return self::loadByName('index', $baseDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $configName
|
||||
*/
|
||||
private static function hasConfigFile($configName, $baseDir)
|
||||
{
|
||||
$configName = self::sanitizeConfigName($configName);
|
||||
if ($configName === 'index' || $configName === 'ip_check') {
|
||||
return false;
|
||||
}
|
||||
return file_exists($baseDir . '/check_config/' . $configName . '_config.php');
|
||||
}
|
||||
|
||||
public static function sanitizeConfigName($name)
|
||||
{
|
||||
$name = trim((string) $name);
|
||||
|
||||
@@ -130,3 +130,4 @@
|
||||
2026-06-20 10:45:40 | 写入数据库 | false | indBXSXX | async=1
|
||||
2026-06-20 10:46:58 | 写入数据库 | false | indBXSXX | async=1
|
||||
2026-06-20 10:47:37 | 写入数据库 | false | indBXSXX | async=1
|
||||
2026-06-22 19:15:55 | 写入数据库 | false | index | async=1
|
||||
|
||||
@@ -48,7 +48,12 @@ class FCheckHandler
|
||||
if (!class_exists('ConfigLoader', false)) {
|
||||
require_once dirname(__DIR__, 2) . '/config/ConfigLoader.php';
|
||||
}
|
||||
$config_name = ConfigLoader::loadByHost($fp_host);
|
||||
$explicitConfig = trim((string) ($fingerprint_info['config_name'] ?? ''));
|
||||
$config_name = ConfigLoader::loadForFingerprint(
|
||||
(string) ($fingerprint_info['domain'] ?? ''),
|
||||
$fp_host,
|
||||
$explicitConfig !== '' ? $explicitConfig : null
|
||||
);
|
||||
$log_id = (int) ($fingerprint_info['log_id'] ?? 0);
|
||||
if ($log_id <= 0) {
|
||||
$log_id = VisitorVisitContext::currentLogId();
|
||||
@@ -191,9 +196,10 @@ class FCheckHandler
|
||||
RiskSecondaryCache::applyToSession($cached);
|
||||
$response = RiskSecondaryCache::toApiResponse($cached);
|
||||
|
||||
$resultStr = $response['result'] ? 'true' : 'false';
|
||||
$update_log = [
|
||||
'result' => $response['result'] ? 'true' : 'false',
|
||||
'reason' => cloak_cache_hit_log_reason($update_log['result']),
|
||||
'result' => $resultStr,
|
||||
'reason' => cloak_cache_hit_log_reason($resultStr),
|
||||
'fp_url' => trim((string) ($response['link'] ?? '')),
|
||||
];
|
||||
if ($update_log['fp_url'] === '') {
|
||||
|
||||
@@ -154,7 +154,14 @@ class FpRiskExplain
|
||||
if (!class_exists('DomainRepository', false)) {
|
||||
require_once __DIR__ . '/DomainRepository.php';
|
||||
}
|
||||
if (!class_exists('ConfigLoader', false)) {
|
||||
require_once dirname(__DIR__, 2) . '/config/ConfigLoader.php';
|
||||
}
|
||||
|
||||
$configName = ConfigLoader::resolveConfigNameFromUrl((string) $domain, $baseDir);
|
||||
if ($configName === null) {
|
||||
$configName = DomainRepository::resolveConfigNameForHost((string) $host, $baseDir);
|
||||
}
|
||||
$file = $baseDir . '/check_config/' . $configName . '_config.php';
|
||||
if (!is_file($file)) {
|
||||
$configName = 'index';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../FpUrlHelper.php';
|
||||
require_once dirname(__DIR__, 3) . '/config/ConfigLoader.php';
|
||||
|
||||
/**
|
||||
* 真实页输出(原 page_6.php)
|
||||
@@ -15,7 +16,9 @@ class FpPageRenderer
|
||||
|
||||
$my_url = $_SERVER['PHP_SELF'];
|
||||
$my_file_name = substr($my_url, strrpos($my_url, '/') + 1);
|
||||
$cong_name = str_replace('.php', '', $my_file_name);
|
||||
$cong_name = !empty($ctx['config_name'])
|
||||
? ConfigLoader::sanitizeConfigName($ctx['config_name'])
|
||||
: str_replace('.php', '', $my_file_name);
|
||||
|
||||
$resolved = FpUrlHelper::resolve($cong_name, true);
|
||||
$fp_url = $resolved['url'];
|
||||
|
||||
@@ -122,6 +122,7 @@ class RouteResolver
|
||||
'logs' => $logs,
|
||||
'v_info' => $v_info,
|
||||
'log_id' => $log_id,
|
||||
'config_name' => $config_name,
|
||||
];
|
||||
if (CLOAK_REDIRECT_METHOD == 'curl') {
|
||||
self::renderRiskCurlInject($riskCtx);
|
||||
|
||||
@@ -22,6 +22,37 @@ $tests['script_priority_over_host'] = ($loadedScript === $key);
|
||||
$loadedIndex = ConfigLoader::loadForRequest('index', 'unknown-host-no-mapping.test');
|
||||
$tests['index_uses_host_fallback'] = ($loadedIndex === 'index');
|
||||
|
||||
$uriKey = 'reg_uri_' . substr(md5((string) microtime(true)), 0, 6);
|
||||
$uriCfgFile = $root . '/check_config/' . $uriKey . '_config.php';
|
||||
file_put_contents($uriCfgFile, "<?php define('SHOW_SITE_MODE_SWITCH','ip_check');\n");
|
||||
$prevUri = $_SERVER['REQUEST_URI'] ?? null;
|
||||
$_SERVER['REQUEST_URI'] = '/' . $uriKey . '?utm_campaign=test&fbclid=abc';
|
||||
$loadedUri = ConfigLoader::loadForRequest('index', 'unknown-host-no-mapping.test');
|
||||
$tests['uri_slug_over_index_script'] = ($loadedUri === $uriKey);
|
||||
$tests['uri_parse_strips_query'] = (function () use ($root, $uriKey, $uriCfgFile) {
|
||||
$_SERVER['REQUEST_URI'] = '/' . $uriKey . '.php?utm=1';
|
||||
$fromPhp = ConfigLoader::resolveConfigNameFromRequestUri($root);
|
||||
$_SERVER['REQUEST_URI'] = '/' . $uriKey . '?utm=1';
|
||||
$fromPretty = ConfigLoader::resolveConfigNameFromRequestUri($root);
|
||||
return $fromPhp === $uriKey && $fromPretty === $uriKey;
|
||||
})();
|
||||
$tests['fingerprint_from_page_url'] = (function () use ($root, $uriKey, $uriCfgFile) {
|
||||
$pageUrl = 'https://shop.example.com/' . $uriKey . '?utm=1&fbclid=abc';
|
||||
$loaded = ConfigLoader::loadForFingerprint($pageUrl, 'shop.example.com');
|
||||
return $loaded === $uriKey;
|
||||
})();
|
||||
$tests['fingerprint_prefers_explicit_config'] = (function () use ($root, $uriKey, $uriCfgFile) {
|
||||
$pageUrl = 'https://other.example.com/wrong-slug?utm=1';
|
||||
$loaded = ConfigLoader::loadForFingerprint($pageUrl, 'other.example.com', $uriKey);
|
||||
return $loaded === $uriKey;
|
||||
})();
|
||||
if ($prevUri === null) {
|
||||
unset($_SERVER['REQUEST_URI']);
|
||||
} else {
|
||||
$_SERVER['REQUEST_URI'] = $prevUri;
|
||||
}
|
||||
@unlink($uriCfgFile);
|
||||
|
||||
$key = 'reg_test_' . substr(md5((string) time()), 0, 6);
|
||||
$cfgFile = $root . '/check_config/' . $key . '_config.php';
|
||||
file_put_contents($cfgFile, "<?php define('SHOW_SITE_MODE_SWITCH','ip_check');\n");
|
||||
|
||||
Reference in New Issue
Block a user