修复日志页面卡顿我呢提

This commit is contained in:
root
2026-06-15 22:42:59 +08:00
parent 1a52201ec7
commit bcb9f293a6
151 changed files with 2461 additions and 471 deletions
+37
View File
@@ -230,6 +230,14 @@ $ntVerifyOut = shell_exec($ntVerifyCmd);
$ntVerifyJson = json_decode((string) $ntVerifyOut, true);
reg_assert('f_check nt.txt 畸形行跳过且 fp 索引合法', ($ntVerifyJson['ok'] ?? false) === true, (string) $ntVerifyOut);
$riskCacheOut = shell_exec(escapeshellarg(PHP_BINARY) . ' ' . escapeshellarg($root . '/tools/verify_risk_cache.php') . ' 2>/dev/null');
$riskCacheJson = json_decode((string) $riskCacheOut, true);
reg_assert('二次风控 Session 缓存与 CORS', ($riskCacheJson['ok'] ?? false) === true, (string) $riskCacheOut);
$datalistHelperOut = shell_exec(escapeshellarg(PHP_BINARY) . ' ' . escapeshellarg($root . '/tools/verify_datalist_helper.php') . ' 2>/dev/null');
$datalistHelperJson = json_decode((string) $datalistHelperOut, true);
reg_assert('日志列表 VisitorLogListHelper', ($datalistHelperJson['ok'] ?? false) === true, (string) $datalistHelperOut);
// ── 12. ConfigLoader / 宝塔部署文件 ───────────────────────────
echo "[12] ConfigLoader 与宝塔部署\n";
require_once $root . '/config/ConfigLoader.php';
@@ -322,6 +330,24 @@ if (defined('DB_NAME')) {
if ($waitId) {
$conn->query('DELETE FROM `visitor_logs` WHERE `id` = ' . (int) $waitId);
}
$GLOBALS['__cloak_force_sync_log'] = true;
$simLogId = @write_log_db(array_merge($sampleLogs, [
'visit_md5_code' => 'reg_sim_' . substr(md5((string) microtime(true)), 0, 12),
'is_simulation' => 1,
'sim_source_log_id' => 99999,
'reason' => VisitorSimulationRunner::tagReason('regression'),
]));
unset($GLOBALS['__cloak_force_sync_log']);
reg_assert('模拟日志 is_simulation 写入', $simLogId !== null && (int) $simLogId > 0);
if ($simLogId) {
$chk = $conn->query('SELECT is_simulation, sim_source_log_id FROM visitor_logs WHERE id=' . (int) $simLogId);
$simRow = $chk ? $chk->fetch_assoc() : null;
reg_assert('模拟列 is_simulation=1', $simRow && (int) $simRow['is_simulation'] === 1);
reg_assert('模拟列 sim_source_log_id', $simRow && (int) $simRow['sim_source_log_id'] === 99999);
$conn->query('DELETE FROM visitor_logs WHERE id=' . (int) $simLogId);
}
$conn->close();
}
} else {
@@ -335,6 +361,17 @@ CloakDebugPage::init();
CloakDebugPage::stepAt(__LINE__, 'regression', 'info', 'ok');
reg_assert('CloakDebugPage::stepAt 可调用', true);
// ── 11. 模拟测试组件 ─────────────────────────────────────────
echo "[11] 模拟测试组件\n";
require_once $root . '/lib/Cloak/VisitorSimulationRunner.php';
reg_assert('FCheckHandler 已加载', class_exists('FCheckHandler', false));
reg_assert('SimulationRouteResolver 已加载', class_exists('SimulationRouteResolver', false));
reg_assert('VisitorSimulationRunner 已加载', class_exists('VisitorSimulationRunner', false));
$tagged = VisitorSimulationRunner::tagReason('国家不符');
reg_assert('VisitorSimulationRunner::tagReason 前缀', strpos($tagged, '[模拟测试]') === 0, $tagged);
$badPrefill = VisitorSimulationRunner::prefillFromLog(0);
reg_assert('prefillFromLog(0) 返回失败', empty($badPrefill['ok']));
// ── 汇总 ──────────────────────────────────────────────────────
echo "\n=== 汇总 ===\n";
echo "通过: {$passed} 失败: {$failed} 跳过: {$skipped}\n";
Regular → Executable
View File
+10
View File
@@ -12,6 +12,16 @@ $tests['normalize_strips_www'] = DomainRepository::normalizeHostname('www.Shop.E
$tests['host_to_key'] = DomainRepository::hostToConfigKey('shop.example.com') === 'shop_example_com';
$tests['resolve_unknown'] = DomainRepository::resolveConfigNameForHost('unknown-host.test', $root) === 'index';
$key = 'reg_script_' . substr(md5((string) microtime(true)), 0, 6);
$cfgFile = $root . '/check_config/' . $key . '_config.php';
file_put_contents($cfgFile, "<?php define('SHOW_SITE_MODE_SWITCH','ip_check');\n");
$loadedScript = ConfigLoader::loadForRequest($key, 'unknown-host-no-mapping.test');
$tests['script_priority_over_host'] = ($loadedScript === $key);
@unlink($cfgFile);
$loadedIndex = ConfigLoader::loadForRequest('index', 'unknown-host-no-mapping.test');
$tests['index_uses_host_fallback'] = ($loadedIndex === 'index');
$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");
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env php
<?php
/**
* VisitorLogListHelper 回归(CLI JSON
*/
if (PHP_SAPI !== 'cli') {
exit(1);
}
$root = dirname(__DIR__);
require_once $root . '/cong.php';
require_once $root . '/lib/DbHelper.php';
require_once $root . '/lib/Cloak/VisitorLogListHelper.php';
$tests = [];
$conn = @new mysqli('localhost', DB_USERNAME, DB_PASSWORD, DB_NAME);
if ($conn->connect_error) {
echo json_encode(['ok' => false, 'error' => 'db'], JSON_UNESCAPED_UNICODE) . "\n";
exit(1);
}
$where = VisitorLogListHelper::buildWhere($conn, ['visit_date' => '2026-01-15']);
$tests['date_range_where'] = strpos($where, 'visit_date') !== false && strpos($where, 'DATE_FORMAT') === false;
$sql = VisitorLogListHelper::listSelectSql('1', 0, 10, true);
$tests['lean_select_no_fp_hdata'] = strpos($sql, '`fp_hdata`,') === false && strpos($sql, 'has_fp_hdata') !== false;
$row = VisitorLogListHelper::formatListRow([
'country' => 'US',
'reason' => 'test',
'result' => 'wait',
'judge_timing' => '',
'has_fp_hdata' => 1,
'has_api_by_request' => 1,
], ['US' => '美国'], []);
$tests['format_wait'] = $row['result'] === '检测中';
$tests['format_lazy_api'] = $row['api_by_request_text'] === '__LAZY__';
$tests['format_fp_flag'] = $row['fp_hdata_text'] === '有指纹数据';
$tests['no_explain_html'] = !array_key_exists('fp_hdata_explain_html', $row);
$conn->close();
$ok = !in_array(false, $tests, true);
echo json_encode(['ok' => $ok, 'tests' => $tests], JSON_UNESCAPED_UNICODE) . "\n";
exit($ok ? 0 : 1);
Regular → Executable
+4 -1
View File
@@ -55,7 +55,10 @@ if ($tests['resolver_available']) {
$tests['normalize_iso2'] = CountryCodeNormalizer::toAlpha2('us') === 'US';
$tests['normalize_name'] = CountryCodeNormalizer::toAlpha2('United States') === 'US';
$tests['allowlist_name'] = CountryAllowlist::isAllowed('United Kingdom', CountryAllowlist::parse('GB,US'));
if (!$tests['normalize_iso2'] || !$tests['normalize_name'] || !$tests['allowlist_name']) {
$tests['allowlist_fullwidth_comma'] = CountryAllowlist::isAllowed('BR', CountryAllowlist::parse('BRCN'));
$tests['allowlist_country_name'] = CountryAllowlist::isAllowed('BR', CountryAllowlist::parse('Brazil,China'));
if (!$tests['normalize_iso2'] || !$tests['normalize_name'] || !$tests['allowlist_name']
|| !$tests['allowlist_fullwidth_comma'] || !$tests['allowlist_country_name']) {
$ok = false;
}
}
+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env php
<?php
/**
* 二次风控 Session 缓存回归(CLI 输出 JSON
*/
if (PHP_SAPI !== 'cli') {
exit(1);
}
$root = dirname(__DIR__);
require_once $root . '/cong.php';
require_once $root . '/lib/CloakHttpHelpers.php';
require_once $root . '/lib/Cloak/ClientIpResolver.php';
require_once $root . '/lib/Cloak/RiskSecondaryCache.php';
$_SESSION = [];
$tests = [];
RiskSecondaryCache::store([
'ip' => '203.0.113.10',
'result' => 'true',
'reason' => 'ok',
'fp_url' => 'https://fp.example/a',
]);
$hit = RiskSecondaryCache::get('203.0.113.10');
$tests['same_ip_hit'] = is_array($hit) && ($hit['result'] ?? '') === 'true';
RiskSecondaryCache::applyToSession($hit);
$tests['apply_session'] = ($_SESSION['visit_to_3'] ?? '') == 3 && ($_SESSION['check_result'] ?? '') === 'true';
$miss = RiskSecondaryCache::get('198.51.100.1');
$tests['ip_change_miss'] = $miss === null && empty($_SESSION[RiskSecondaryCache::SESSION_KEY]);
$tests['ip_change_resets_visit_to_3'] = ($_SESSION['visit_to_3'] ?? '') === '1';
RiskSecondaryCache::store([
'ip' => '203.0.113.10',
'result' => 'false',
'reason' => 'deny',
'fp_url' => 'https://zp.example/',
]);
$api = RiskSecondaryCache::toApiResponse(RiskSecondaryCache::get('203.0.113.10'));
$tests['to_api_response'] = $api['result'] === false && $api['reason'] === RiskSecondaryCache::hitReason();
RiskSecondaryCache::clear();
$tests['clear'] = RiskSecondaryCache::get('203.0.113.10') === null;
$originOk = false;
$_SERVER['HTTP_HOST'] = 'cloak.example.com';
$_SERVER['HTTP_ORIGIN'] = 'https://www.example.com';
require_once $root . '/lib/Cloak/CloakSession.php';
$ref = new ReflectionClass('CloakFcheckCors');
$method = $ref->getMethod('isAllowedOrigin');
$method->setAccessible(true);
$originOk = (bool) $method->invoke(null, 'https://www.example.com');
$tests['cors_sibling_subdomain'] = $originOk;
$badOrigin = !(bool) $method->invoke(null, 'https://evil.other.com');
$tests['cors_reject_foreign'] = $badOrigin;
$ok = !in_array(false, $tests, true);
echo json_encode(['ok' => $ok, 'tests' => $tests], JSON_UNESCAPED_UNICODE) . "\n";
exit($ok ? 0 : 1);
Regular → Executable
View File
Regular → Executable
View File