diff --git a/upgrade.php b/upgrade.php index 5c3da63..812b8e9 100644 --- a/upgrade.php +++ b/upgrade.php @@ -4,8 +4,26 @@ * * 读取 VERSION 文件确定目标版本,自动检测数据库当前版本, * 依次执行增量 SQL 升级脚本。 + * + * 仅限班主任(拥有系统升级权限 manage_upgrade)使用。 */ +// 登录与权限校验:仅班主任(系统升级权限)可访问与执行 +require_once __DIR__ . '/frontend/config.php'; + +if (!isset($_SESSION['user_id']) + || ($_SESSION['user_type'] ?? '') !== 'admin' + || !has_perm('manage_upgrade')) { + if ($_SERVER['REQUEST_METHOD'] === 'POST' || isset($_GET['action'])) { + header('Content-Type: application/json; charset=utf-8'); + http_response_code(403); + echo json_encode(['success' => false, 'error' => '未授权:仅班主任(系统升级权限)可执行升级操作']); + exit(); + } + header('Location: /index.php'); + exit(); +} + // =========================================== // 辅助函数 // ===========================================