Files
Nexus/web/_env_check.php
T
Your Name f9045a8404 refactor: 仓库结构扁平化 + PHP前端合并到Nexus仓库
- 将 Nexus/Nexus/* 移到仓库根目录(消除双层嵌套)
- 删除旧的多层空壳目录 (server/, web/, agent/, deploy/, docs/)
- 将PHP前端 (web/) 合并进Nexus仓库 — 统一管理
- 部署时 git clone Nexus 仓库即可,不再需要两个仓库

目录结构:
  server/     ← Python FastAPI后端
  web/        ← PHP前端 (install.php, config.php, etc)
  deploy/     ← Supervisor + Shell健康检查
  docs/       ← 部署文档
  tests/      ← 测试
  .env        ← 不在git中 (install.php生成)
  .gitignore  ← 排除 .env, SECRETS.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 17:24:21 +08:00

67 lines
2.6 KiB
PHP
Raw 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
/**
* .env 配置检测横幅
* 检查 Python 后端的 .env 是否正确配置
* 问题修复后横幅自动消失
*/
$currentPage = basename($_SERVER['PHP_SELF']);
if (in_array($currentPage, ['login.php', 'install.php'])) return;
// 每 5 分钟检测一次
if (isset($_SESSION['env_checked']) && $_SESSION['env_checked'] > time() - 300) {
return; // 已检测且正常
}
$_SESSION['env_checked'] = time();
$apiBase = defined('API_BASE_URL') ? API_BASE_URL : 'http://localhost:8600';
$apiKey = defined('API_KEY') ? API_KEY : '';
$warnings = [];
// 检查:Python API 是否在线
$ch = curl_init($apiBase . '/health');
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 3]);
$resp = @curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
// API 不在线 → 不检查 .env(由 _banner.php 处理)
$_SESSION['env_warnings'] = [];
return;
}
// 检查:SECRET_KEY 是否为默认值(通过 /api/servers/config 获取)
$ch = curl_init($apiBase . '/api/servers/config');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 3,
CURLOPT_HTTPHEADER => $apiKey ? ["X-API-Key: $apiKey"] : [],
]);
$resp = @curl_exec($ch);
$configData = json_decode($resp, true) ?: [];
curl_close($ch);
if (empty($configData)) {
$warnings[] = ['type' => 'api', 'msg' => 'API_KEY 未配置或与 Python .env 不一致'];
} else {
// 检查默认值
if (($configData['api_key'] ?? '') === '') {
$warnings[] = ['type' => 'apikey', 'msg' => 'API_KEY 为空 — API 端点无认证保护'];
}
if (($configData['telegram_bot_token'] ?? '') === '' && ($configData['telegram_chat_id'] ?? '') === '') {
// Telegram 是可选的,仅提示
}
}
$_SESSION['env_warnings'] = $warnings;
$showBanner = !empty($warnings);
if ($showBanner):
?>
<div id="envBanner" style="background:#fff3cd;border-bottom:2px solid #ffc107;padding:10px 20px;font-size:13px;display:flex;align-items:center;gap:12px;">
<span style="font-size:16px;">⚠️</span>
<span style="flex:1;"><b>.env 配置警告</b> — <?= count($warnings) ?> 项需要处理:<?= implode('', array_column($warnings, 'msg')) ?></span>
<a href="settings.php" style="background:#ffc107;color:#000;padding:6px 14px;border-radius:4px;text-decoration:none;font-size:12px;font-weight:600;">前往修复 →</a>
<button onclick="document.getElementById('envBanner').style.display='none'" style="background:none;border:none;font-size:18px;cursor:pointer;color:#856404;">×</button>
</div>
<?php endif; ?>