403, 'msg' => '访问密码错误或者未输入密码,请拼接?pass=API_PASS后再尝试访问'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); exit; } // 处理操作请求 $message = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; $hostId = $_POST['host_id'] ?? ''; $configId = intval($_POST['config_id'] ?? 0); if ($action && !empty($hostId) && $configId > 0) { $result = null; Logger::info("[操作请求] action={$action}, host_id={$hostId}, config_id={$configId}", 'index.php'); // 获取配置信息以确定平台类型 $db = getVpsDB(); $config = $db->queryOne('SELECT * FROM configs WHERE id = ?', [$configId]); if ($config) { if ($config['site_type'] === 'mofang') { if ($action === 'reboot') { $result = mofangHardReboot($configId, $hostId); } elseif ($action === 'on') { $result = mofangPowerOn($configId, $hostId); } elseif ($action === 'off') { $result = mofangPowerOff($configId, $hostId); } } elseif ($config['site_type'] === 'tencent') { // 腾讯云智能操作(自动识别CVM或轻量服务器) if ($action === 'reboot') { $result = tencentSmartReboot($configId, $hostId); } elseif ($action === 'on') { $result = tencentSmartPowerOn($configId, $hostId); } elseif ($action === 'off') { $result = tencentSmartPowerOff($configId, $hostId); } } elseif ($config['site_type'] === 'aliyun') { // 阿里云ECS操作 if ($action === 'reboot') { $result = aliyunReboot($configId, $hostId); } elseif ($action === 'on') { $result = aliyunPowerOn($configId, $hostId); } elseif ($action === 'off') { $result = aliyunPowerOff($configId, $hostId); } } elseif ($config['site_type'] === 'aliyun_swas') { // 阿里云轻量应用服务器操作 if ($action === 'reboot') { $result = aliyunSwasReboot($configId, $hostId); } elseif ($action === 'on') { $result = aliyunSwasPowerOn($configId, $hostId); } elseif ($action === 'off') { $result = aliyunSwasPowerOff($configId, $hostId); } } } if ($result && isset($result['status']) && $result['status'] === 200) { $message = '

✅ 操作成功

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

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

❌ 操作失败

' . htmlspecialchars($errorMsg) . '

'; } } elseif ($action === 'refresh_single_config') { // 单独刷新某个配置 $configId = intval($_POST['config_id'] ?? 0); if ($configId > 0) { $configDb = getVpsDB(); $config = $configDb->queryOne('SELECT * FROM configs WHERE id = ?', [$configId]); if ($config) { $success = false; $typeName = ''; if ($config['site_type'] === 'mofang') { require_once __DIR__ . '/mofangidc.php'; $success = refreshVpsListForConfig($configId); $typeName = '魔方平台'; } elseif ($config['site_type'] === 'tencent') { require_once __DIR__ . '/tencentcloud.php'; // 同时刷新CVM和轻量 $cvmSuccess = refreshTencentCvmListForConfig($configId); $lhSuccess = refreshTencentLighthouseListForConfig($configId); $success = $cvmSuccess || $lhSuccess; $typeName = '腾讯云'; } elseif ($config['site_type'] === 'aliyun') { require_once __DIR__ . '/aliyun.php'; $success = refreshAliyunEcsListForConfig($configId); $typeName = '阿里云ECS'; } elseif ($config['site_type'] === 'aliyun_swas') { require_once __DIR__ . '/aliyun.php'; $success = refreshAliyunSwasListForConfig($configId); $typeName = '阿里云轻量'; } if ($success) { $message = '

✅ 刷新成功

已刷新配置「' . htmlspecialchars($config['api_label']) . '」(' . $typeName . ')的VPS列表

'; } else { $message = '

❌ 刷新失败

配置「' . htmlspecialchars($config['api_label']) . '」刷新失败,请检查API凭证和网络连接

'; } } else { $message = '
❌ 配置不存在
'; } } else { $message = '
❌ 无效的配置ID
'; } } elseif ($action === 'refresh_vps_list') { // 手动刷新VPS列表(全部) $count = 0; // 刷新魔方平台的VPS列表 $mofangCount = refreshAllVpsLists(); $count += $mofangCount; // 刷新腾讯云的CVM和轻量应用服务器列表 $tencentCount = refreshAllTencentVpsLists(); $count += $tencentCount; // 刷新阿里云的ECS列表 $aliyunCount = refreshAllAliyunVpsLists(); $count += $aliyunCount; $message = '

✅ 刷新完成

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

'; // 获取每个VPS的详细信息并更新数据库 $listDb = getVpsListDB(); $configDb = getVpsDB(); $configs = $configDb->query('SELECT * FROM configs'); foreach ($configs as $config) { if ($config['site_type'] === 'mofang') { // 获取该配置下的所有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'])) { preg_match('/(\d+)/', $option['value'], $matches); if (!empty($matches)) { $cpuCores = intval($matches[1]); } } if ($option['key'] === 'memory' && isset($option['value'])) { $memorySize = $option['value']; } } } // 更新数据库 $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] ); } } } elseif ($config['site_type'] === 'tencent') { // 腾讯云实例已在refreshAllTencentVpsLists中更新了详细信息,这里不需要额外处理 Logger::info("[refresh_vps_list] 腾讯云配置 {$config['id']} 已刷新", 'index.php'); } elseif ($config['site_type'] === 'aliyun') { // 阿里云ECS实例已在refreshAllAliyunVpsLists中更新了详细信息,这里不需要额外处理 Logger::info("[refresh_vps_list] 阿里云配置 {$config['id']} 已刷新", 'index.php'); } elseif ($config['site_type'] === 'aliyun_swas') { // 阿里云轻量应用服务器实例已在refreshAllAliyunVpsLists中更新了详细信息,这里不需要额外处理 Logger::info("[refresh_vps_list] 阿里云轻量配置 {$config['id']} 已刷新", 'index.php'); } } $message .= '
✅ 已更新VPS详细信息(CPU、内存等)
'; } } // 获取所有配置 $db = getVpsDB(); $configs = $db->query('SELECT * FROM configs ORDER BY id'); // 构建配置ID到配置的映射 $configMap = []; foreach ($configs as $config) { $configMap[$config['id']] = $config; // 存储完整配置信息 } // 获取所有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]['api_label'] ?? '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; } // 构建api_label到config_id的映射(用于单独刷新) $apiLabelToConfigId = []; foreach ($configs as $config) { $apiLabelToConfigId[$config['api_label']] = $config['id']; } // 统计信息 $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,请点击右上角“🔄 刷新此配置”按钮获取

12) { $displayId = substr($vpsId, 0, 10) . '...'; $showTooltip = true; } ?>
title="">#
IP地址
产品名称
CPU/内存
磁盘/带宽/系统
价格
到期时间