diff --git a/.gitignore b/.gitignore index e04554c..c9a07c7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ storage/cache/ storage/data/ storage/logs/ storage/uploads/ +config/config.secret.php *.zip _dbg_login.html start_local.sh diff --git a/app/Core/Helper.php b/app/Core/Helper.php index e6ec1ff..4d55496 100644 --- a/app/Core/Helper.php +++ b/app/Core/Helper.php @@ -544,12 +544,15 @@ if (!function_exists('site_url')) { */ function db_pending_upgrades(): int { + // V0.9.5:请求内缓存(一次请求内多次调用只算一次),避免每后台页重复 glob+md5_file+SELECT + static $cache = null; + if ($cache !== null) return $cache; try { - if (\Core\Db::driver() !== 'mysql') return 0; + if (\Core\Db::driver() !== 'mysql') { $cache = 0; return 0; } $dir = db_upgrade_dir(); - if (!is_dir($dir)) return 0; + if (!is_dir($dir)) { $cache = 0; return 0; } $files = glob($dir . '/*.sql') ?: []; - if (!$files) return 0; + if (!$files) { $cache = 0; return 0; } \Core\Installer::ensureUpgradeLog(); $applied = \Core\Db::query("SELECT file, hash FROM db_upgrades")->fetchAll(\PDO::FETCH_KEY_PAIR); $n = 0; @@ -560,8 +563,10 @@ if (!function_exists('site_url')) { $n++; } } + $cache = $n; return $n; } catch (\Throwable $e) { + $cache = 0; return 0; } } diff --git a/config/config.php b/config/config.php index 150a346..7dcce26 100644 --- a/config/config.php +++ b/config/config.php @@ -1,8 +1,24 @@ '', + 'admin_pass' => '', +], $secret); + return [ 'app' => [ 'name' => '酷冰甲 · 降温服', @@ -17,7 +33,7 @@ return [ 'port' => 3306, 'dbname' => 'coolcoth_comf', 'user' => 'coolcoth_comf', - 'pass' => 'QDBKzY817hDhTiKk', + 'pass' => $secret['db_pass'] ?: (getenv('COOLCOTH_DB_PASS') ?: ''), 'charset' => 'utf8mb4', ], 'file' => [ @@ -27,7 +43,7 @@ return [ // 后台登录账号(文件模式 / 首次安装) 'admin' => [ 'username' => 'admin', - 'password' => 'admin888', + 'password' => $secret['admin_pass'] ?: (getenv('COOLCOTH_ADMIN_PASS') ?: ''), // 本地规则红线:生产环境(mysql 模式)必须关闭配置文件兜底账号,禁用默认密码后门。 // 仅本地演示(file 模式)可临时置 true。远端已实测默认密码可登录,已置 false 封堵。 'allow_config_fallback' => false, diff --git a/config/config.secret.php.example b/config/config.secret.php.example new file mode 100644 index 0000000..71165d7 --- /dev/null +++ b/config/config.secret.php.example @@ -0,0 +1,9 @@ + '在此填入数据库密码', + 'admin_pass' => '在此填入后台密码(务必改为强口令,不要用 admin888)', +];