refactor: 清理旧版兼容性,升级为 bcrypt 密码算法

- 密码哈希从 MD5+SHA1 升级为 bcrypt
- 删除 super_admins/users 表中的 salt 字段
- 删除旧版升级文件(upgrade.php, check_upgrade, execute_upgrade, sql/upgrades/)
- 删除 PASSWORD_SALT 配置项
- 清理所有'兼容 Python 版'注释
- 新项目独立,无历史包袱
This commit is contained in:
2026-06-22 10:45:13 +08:00
parent 124d7f645e
commit 4193a1a153
17 changed files with 76 additions and 1319 deletions

View File

@@ -1,69 +0,0 @@
<?php
/**
* 检查数据库版本是否需要升级(代理至后端 API
*/
require_once __DIR__ . '/../config.php';
header('Content-Type: application/json; charset=utf-8');
// 只有班主任才能检查升级
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
echo json_encode(['error' => '未授权']);
exit();
}
$role = $_SESSION['role'] ?? '';
if ($role !== '班主任') {
echo json_encode(['needs_upgrade' => false]);
exit();
}
// 从 session 获取 JWT token
$token = $_SESSION['jwt_token'] ?? '';
if (empty($token)) {
echo json_encode(['error' => '会话已过期,请重新登录']);
exit();
}
// 调用后端 API
$apiUrl = API_BASE_URL . '/api/upgrade/check';
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $apiUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => API_TIMEOUT,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
],
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2
]);
$apiResponse = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (empty($apiResponse)) {
echo json_encode(['error' => '无法连接升级服务']);
exit();
}
$result = json_decode($apiResponse, true);
if (!$result) {
echo json_encode(['error' => '升级服务返回数据格式错误']);
exit();
}
// 后端返回非200时尝试解析实际错误信息
if ($httpCode !== 200 || !isset($result['success']) || !$result['success']) {
$errorMsg = $result['message'] ?? ($result['error'] ?? '升级检查失败');
echo json_encode(['error' => $errorMsg]);
exit();
}
// 转发后端返回的升级数据
$data = $result['data'] ?? [];
echo json_encode($data);

View File

@@ -1,104 +0,0 @@
<?php
/**
* 执行单个升级步骤(代理至后端 API
*/
require_once __DIR__ . '/../config.php';
header('Content-Type: application/json; charset=utf-8');
// 验证登录和权限admin 班主任 或 super_admin
if (!isset($_SESSION['user_id']) || !in_array($_SESSION['user_type'], ['admin', 'super_admin'])) {
http_response_code(401);
echo json_encode(['success' => false, 'error' => '未授权']);
exit();
}
$userType = $_SESSION['user_type'];
$role = $_SESSION['role'] ?? '';
if ($userType === 'admin' && $role !== '班主任') {
http_response_code(403);
echo json_encode(['success' => false, 'error' => '权限不足']);
exit();
}
// 只接受 POST
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(400);
echo json_encode(['success' => false, 'error' => '无效请求']);
exit();
}
$input = json_decode(file_get_contents('php://input'), true);
$stepVersion = $input['version'] ?? '';
if (empty($stepVersion)) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => '缺少版本号参数']);
exit();
}
// 从 session 获取 JWT token
$token = $_SESSION['jwt_token'] ?? '';
if (empty($token)) {
http_response_code(401);
echo json_encode(['success' => false, 'error' => '会话已过期,请重新登录']);
exit();
}
// 调用后端 API
$apiUrl = API_BASE_URL . '/api/upgrade/step';
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $apiUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(['version' => $stepVersion]),
CURLOPT_TIMEOUT => API_TIMEOUT,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
],
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2
]);
$apiResponse = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (empty($apiResponse)) {
http_response_code(500);
echo json_encode([
'success' => false,
'version' => $stepVersion,
'error' => '无法连接升级服务'
]);
exit();
}
$result = json_decode($apiResponse, true);
if (!$result) {
http_response_code(500);
echo json_encode([
'success' => false,
'version' => $stepVersion,
'error' => '升级服务返回数据格式错误'
]);
exit();
}
// 后端返回非200或 success=false 时,提取实际错误信息
if ($httpCode !== 200 || !isset($result['success']) || !$result['success']) {
$errorMsg = $result['message'] ?? ($result['error'] ?? '升级失败');
http_response_code(500);
echo json_encode([
'success' => false,
'version' => $stepVersion,
'error' => $errorMsg
]);
exit();
}
// 转发后端返回的数据
$data = $result['data'] ?? [];
echo json_encode($data);