403, 'msg' => '访问密码错误或者未输入密码,请拼接?pass=API_PASS后再尝试访问'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); exit; } // 处理操作请求 $message = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; $hostId = intval($_POST['host_id'] ?? 0); $configId = intval($_POST['config_id'] ?? 0); if ($action && $hostId > 0 && $configId > 0) { $result = null; if ($action === 'reboot') { $result = mofangHardReboot($configId, $hostId); } elseif ($action === 'on') { $result = mofangPowerOn($configId, $hostId); } elseif ($action === 'off') { $result = mofangPowerOff($configId, $hostId); } if ($result && isset($result['status']) && $result['status'] === 200) { $message = '

✅ 操作成功

VPS #' . $hostId . ' 已成功执行操作

'; } else { $errorMsg = $result['msg'] ?? '未知错误'; $message = '

❌ 操作失败

' . htmlspecialchars($errorMsg) . '

'; } } elseif ($action === 'refresh_vps_list') { // 手动刷新VPS列表 $count = refreshAllVpsLists(); $message = '

✅ 刷新完成

已成功刷新 ' . $count . ' 个配置的VPS列表

'; // 获取每个VPS的详细信息并更新数据库 $listDb = getVpsListDB(); $configDb = getVpsDB(); $configs = $configDb->query('SELECT * FROM configs'); foreach ($configs as $config) { if ($config['site_type'] !== 'mofang') { continue; // 目前只支持魔方平台 } // 获取该配置下的所有VPS $vpsItems = $listDb->query('SELECT vps_id FROM vps_list WHERE config_id = ?', [$config['id']]); foreach ($vpsItems as $vpsItem) { $vpsId = $vpsItem['vps_id']; // 获取VPS详细信息 $details = mofangGetVpsDetails($config['id'], $vpsId); if ($details && isset($details['status']) && $details['status'] === 200 && isset($details['data']['host'])) { $host = $details['data']['host']; // 解析CPU和内存信息 $cpuCores = null; $memorySize = null; if (isset($host['config_option']) && is_array($host['config_option'])) { foreach ($host['config_option'] as $option) { if ($option['key'] === 'cpu' && isset($option['value'])) { // 提取数字,例如 "16核" -> 16 preg_match('/(\d+)/', $option['value'], $matches); if (!empty($matches)) { $cpuCores = intval($matches[1]); } } if ($option['key'] === 'memory' && isset($option['value'])) { $memorySize = $option['value']; // 例如 "16G" } } } // 更新数据库 $listDb->execute( 'UPDATE vps_list SET cpu_cores = ?, memory_size = ?, last_check = CURRENT_TIMESTAMP WHERE config_id = ? AND vps_id = ?', [$cpuCores, $memorySize, $config['id'], $vpsId] ); } } } $message .= '
✅ 已更新VPS详细信息(CPU、内存等)
'; } } // 获取所有配置 $db = getVpsDB(); $configs = $db->query('SELECT * FROM configs ORDER BY id'); // 构建配置ID到api_label的映射 $configMap = []; foreach ($configs as $config) { $configMap[$config['id']] = $config['api_label']; } // 获取所有VPS列表(从vpslist.db查询) $listDb = getVpsListDB(); $vpsList = $listDb->query('SELECT * FROM vps_list ORDER BY config_id, vps_id'); // 为每个VPS添加api_label foreach ($vpsList as &$vps) { $configId = $vps['config_id']; $vps['api_label'] = $configMap[$configId] ?? 'Unknown'; } unset($vps); Logger::info("Total VPS count: " . count($vpsList), 'index.php'); if (!empty($vpsList)) { Logger::debug("First VPS: " . json_encode($vpsList[0]), 'index.php'); } // 按api_label分组 $vpsByApiLabel = []; foreach ($vpsList as $vps) { $apiLabel = $vps['api_label']; if (!isset($vpsByApiLabel[$apiLabel])) { $vpsByApiLabel[$apiLabel] = []; } $vpsByApiLabel[$apiLabel][] = $vps; } // 统计信息 $totalCount = count($vpsList); $runningCount = 0; $offCount = 0; foreach ($vpsList as $vps) { if ($vps['status'] === 'on') { $runningCount++; } elseif ($vps['status'] === 'off') { $offCount++; } } ?> VPS管理面板 - VPS Hub

🖥️ VPS Hub 管理面板

实时查看和管理您的云服务器

➕ 添加配置源
总计: 台服务器
运行中:
已关机:

📭 暂无配置

请先添加VPS配置才能开始管理

➕ 添加第一个配置
$labelVps): ?>
- 台VPS

此配置下暂无VPS,请点击“手动刷新VPS列表”获取

#
IP地址
产品名称
CPU/内存
磁盘/带宽/系统
价格
到期时间