Files
nxxy335 804b04de60 移除登录失败限流;修复连接信息被 e2e 串味为 127.0.0.1
- bootstrap.php/login.php:整体移除「5 次失败锁 10 分钟」限流,登录失败仅即时提示原因
- 新增 tools/fix-config.php:一键双写修正连接地址(默认 exam.nxxy335.top),清空账号密码让用户重输真实卷王凭据
- NY_DATA 隔离落地:run-all.sh 给写配置的 e2e 指向临时目录;修 Windows Git Bash /c/... 路径规范化 bug;.ny-test-data 加 .gitignore
- 清理 dead throttle 引用(e2e 脚本 + docs)
- 修 login.php 真实 bug:ny_is_auth() 分支在加载 $cfg 前引用导致 Undefined variable 警告
- 全量测试 116 通过(PHP 44 + e2e 72)
2026-09-11 17:25:22 +08:00

65 lines
2.6 KiB
PHP
Raw Permalink 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
/**
* 修复 / 重置系统连接配置(终端一次性工具)
*
* 背景:
* 连接配置同时存在于 data/ny.db(SQLite,加载时优先)与 data/config.json(文件备份)。
* ny_load_config() 以 DB 为准,因此一旦部署实例的 ny.db 被 e2e 测试串味或误改写成
* 127.0.0.1 / mock 地址,登录页就会显示「系统连接信息已配置(127.0.0.1/api)」且连不上真实卷王。
* 本工具通过 ny_save_config 双写,一次性把两处都纠正回正确的生产地址。
*
* 用法:
* php tools/fix-config.php [--base-url=https://exam.nxxy335.top] [--api-prefix=/api] [--keep-creds]
*
* 默认行为:
* - base_url 修正为 https://exam.nxxy335.top(可用 --base-url 覆盖)
* - api_prefix 修正为 /api
* - 账号/密码清空(绝不臆造真实卷王凭据),需在登录页重新输入真实账号
* - 加 --keep-creds 则保留现有账号密码不动
*
* 测试隔离:可用 NY_DATA=/tmp/xxx 指向临时目录,不影响生产库。
*/
declare(strict_types=1);
require __DIR__ . '/../bootstrap.php';
$args = array_slice($argv, 1);
$baseUrl = 'https://exam.nxxy335.top';
$apiPrefix = '/api';
$keepCreds = false;
foreach ($args as $a) {
if (strncmp($a, '--base-url=', 11) === 0) {
$baseUrl = substr($a, 11);
} elseif (strncmp($a, '--api-prefix=', 13) === 0) {
$apiPrefix = substr($a, 13);
} elseif ($a === '--keep-creds') {
$keepCreds = true;
} elseif ($a === '--help' || $a === '-h') {
echo "用法: php tools/fix-config.php [--base-url=URL] [--api-prefix=/api] [--keep-creds]\n";
exit(0);
}
}
$cfg = ny_load_config();
$before = (string)($cfg['base_url'] ?? '');
$cfg['base_url'] = rtrim(trim($baseUrl), '/');
$cfg['api_prefix'] = '/' . ltrim(trim($apiPrefix), '/');
if (!$keepCreds) {
$cfg['username'] = '';
$cfg['password'] = '';
}
$ok = ny_save_config($cfg);
if (!$ok) {
fwrite(STDERR, "保存失败:DB 与文件均不可写?请检查 " . NY_DATA . " 目录权限。\n");
exit(1);
}
$host = (string) parse_url($cfg['base_url'], PHP_URL_HOST);
echo "修复前 base_url = " . ($before === '' ? '(空)' : $before) . "\n";
echo "修复后 base_url = " . $cfg['base_url'] . "\n";
echo "api_prefix = " . $cfg['api_prefix'] . "\n";
echo "登录页将显示 = 系统连接信息已配置(" . $host . $cfg['api_prefix'] . ")\n";
echo "账号/密码 = " . ($keepCreds ? '保持不变' : '已清空(请在登录页重新输入真实卷王账号)') . "\n";
echo "配置来源 = " . ny_config_source() . "\n";
echo "OK\n";