添加腾讯云源(暂不支持开关机)
This commit is contained in:
1 parent
88f7fc7141
commit
cbd886bd0a
7 files changed
+1342
-64
No files matched your search
@@ -2,6 +2,7 @@
|
||||
require_once __DIR__ . '/app/db_helper.php';
|
||||
require_once __DIR__ . '/app/logger.php';
|
||||
require_once __DIR__ . '/mofangidc.php';
|
||||
require_once __DIR__ . '/tencentcloud.php';
|
||||
|
||||
// 存储API_PASS
|
||||
$tokenFile = __DIR__ . '/app/pass.php';
|
||||
@@ -34,23 +35,49 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
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);
|
||||
// 获取配置信息以确定平台类型
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($result && isset($result['status']) && $result['status'] === 200) {
|
||||
$message = '<div class="success-message"><h3>✅ 操作成功</h3><p>VPS #' . $hostId . ' 已成功执行操作</p></div>';
|
||||
} else {
|
||||
$errorMsg = $result['msg'] ?? '未知错误';
|
||||
$errorMsg = $result['error'] ?? $result['msg'] ?? '未知错误';
|
||||
$message = '<div class="error-message"><h3>❌ 操作失败</h3><p>' . htmlspecialchars($errorMsg) . '</p></div>';
|
||||
}
|
||||
} elseif ($action === 'refresh_vps_list') {
|
||||
// 手动刷新VPS列表
|
||||
$count = refreshAllVpsLists();
|
||||
$count = 0;
|
||||
|
||||
// 刷新魔方平台的VPS列表
|
||||
$mofangCount = refreshAllVpsLists();
|
||||
$count += $mofangCount;
|
||||
|
||||
// 刷新腾讯云的CVM和轻量应用服务器列表
|
||||
$tencentCount = refreshAllTencentVpsLists();
|
||||
$count += $tencentCount;
|
||||
|
||||
$message = '<div class="success-message"><h3>✅ 刷新完成</h3><p>已成功刷新 ' . $count . ' 个配置的VPS列表</p></div>';
|
||||
|
||||
// 获取每个VPS的详细信息并更新数据库
|
||||
@@ -59,47 +86,47 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$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'];
|
||||
if ($config['site_type'] === 'mofang') {
|
||||
// 获取该配置下的所有VPS
|
||||
$vpsItems = $listDb->query('SELECT vps_id FROM vps_list WHERE config_id = ?', [$config['id']]);
|
||||
|
||||
// 获取VPS详细信息
|
||||
$details = mofangGetVpsDetails($config['id'], $vpsId);
|
||||
|
||||
if ($details && isset($details['status']) && $details['status'] === 200 && isset($details['data']['host'])) {
|
||||
$host = $details['data']['host'];
|
||||
foreach ($vpsItems as $vpsItem) {
|
||||
$vpsId = $vpsItem['vps_id'];
|
||||
|
||||
// 解析CPU和内存信息
|
||||
$cpuCores = null;
|
||||
$memorySize = null;
|
||||
// 获取VPS详细信息
|
||||
$details = mofangGetVpsDetails($config['id'], $vpsId);
|
||||
|
||||
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 ($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'];
|
||||
}
|
||||
}
|
||||
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]
|
||||
);
|
||||
}
|
||||
|
||||
// 更新数据库
|
||||
$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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,10 +138,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$db = getVpsDB();
|
||||
$configs = $db->query('SELECT * FROM configs ORDER BY id');
|
||||
|
||||
// 构建配置ID到api_label的映射
|
||||
// 构建配置ID到配置的映射
|
||||
$configMap = [];
|
||||
foreach ($configs as $config) {
|
||||
$configMap[$config['id']] = $config['api_label'];
|
||||
$configMap[$config['id']] = $config; // 存储完整配置信息
|
||||
}
|
||||
|
||||
// 获取所有VPS列表(从vpslist.db查询)
|
||||
@@ -124,7 +151,7 @@ $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';
|
||||
$vps['api_label'] = $configMap[$configId]['api_label'] ?? 'Unknown';
|
||||
}
|
||||
unset($vps);
|
||||
|
||||
@@ -503,9 +530,23 @@ foreach ($vpsList as $vps) {
|
||||
<button type="submit" name="action" value="off" class="btn btn-danger" onclick="return confirm('确认关机?')">
|
||||
🔴 关机
|
||||
</button>
|
||||
<?php
|
||||
// 根据平台类型显示不同的重启按钮
|
||||
$configId = $vps['config_id'];
|
||||
$siteType = isset($configMap[$configId]) ? $configMap[$configId]['site_type'] : '';
|
||||
if ($siteType === 'tencent') {
|
||||
// 腾讯云:普通重启
|
||||
?>
|
||||
<button type="submit" name="action" value="reboot" class="btn btn-warning" onclick="return confirm('确认重启?')">
|
||||
🔄 重启
|
||||
</button>
|
||||
<?php } else {
|
||||
// 魔方等其他平台:硬重启
|
||||
?>
|
||||
<button type="submit" name="action" value="reboot" class="btn btn-warning" onclick="return confirm('确认硬重启?')">
|
||||
🔄 硬重启
|
||||
</button>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user