diff --git a/api-docs/reboot.php b/api-docs/reboot.php new file mode 100644 index 0000000..3d3ba9f --- /dev/null +++ b/api-docs/reboot.php @@ -0,0 +1,86 @@ +// 腾讯云API签名v3实现示例 +// 本代码基于腾讯云API签名v3文档实现: https://cloud.tencent.com/document/product/213/30654 +// 请严格按照文档说明使用,不建议随意修改签名相关代码 + $authorization, + "Content-Type" => "application/json; charset=utf-8", + "Host" => $host, + "X-TC-Action" => $action, + "X-TC-Timestamp" => $timestamp, + "X-TC-Version" => $version +]; +if ($req_region) { + $headers["X-TC-Region"] = $req_region; +} +if ($token) { + $headers["X-TC-Token"] = $token; +} + +try { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $endpoint); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); + curl_setopt($ch, CURLOPT_HTTPHEADER, array_map(function ($k, $v) { return "$k: $v"; }, array_keys($headers), $headers)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($ch); + curl_close($ch); + + echo $response; +} catch (Exception $err) { + echo $err->getMessage(); +} + +?> \ No newline at end of file diff --git a/api-docs/shutdown.php b/api-docs/shutdown.php new file mode 100644 index 0000000..d772b25 --- /dev/null +++ b/api-docs/shutdown.php @@ -0,0 +1,86 @@ +// 腾讯云API签名v3实现示例 +// 本代码基于腾讯云API签名v3文档实现: https://cloud.tencent.com/document/product/213/30654 +// 请严格按照文档说明使用,不建议随意修改签名相关代码 + $authorization, + "Content-Type" => "application/json; charset=utf-8", + "Host" => $host, + "X-TC-Action" => $action, + "X-TC-Timestamp" => $timestamp, + "X-TC-Version" => $version +]; +if ($req_region) { + $headers["X-TC-Region"] = $req_region; +} +if ($token) { + $headers["X-TC-Token"] = $token; +} + +try { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $endpoint); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); + curl_setopt($ch, CURLOPT_HTTPHEADER, array_map(function ($k, $v) { return "$k: $v"; }, array_keys($headers), $headers)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($ch); + curl_close($ch); + + echo $response; +} catch (Exception $err) { + echo $err->getMessage(); +} + +?> \ No newline at end of file diff --git a/api-docs/start.php b/api-docs/start.php new file mode 100644 index 0000000..222f473 --- /dev/null +++ b/api-docs/start.php @@ -0,0 +1,86 @@ +// 腾讯云API签名v3实现示例 +// 本代码基于腾讯云API签名v3文档实现: https://cloud.tencent.com/document/product/213/30654 +// 请严格按照文档说明使用,不建议随意修改签名相关代码 + $authorization, + "Content-Type" => "application/json; charset=utf-8", + "Host" => $host, + "X-TC-Action" => $action, + "X-TC-Timestamp" => $timestamp, + "X-TC-Version" => $version +]; +if ($req_region) { + $headers["X-TC-Region"] = $req_region; +} +if ($token) { + $headers["X-TC-Token"] = $token; +} + +try { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $endpoint); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); + curl_setopt($ch, CURLOPT_HTTPHEADER, array_map(function ($k, $v) { return "$k: $v"; }, array_keys($headers), $headers)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($ch); + curl_close($ch); + + echo $response; +} catch (Exception $err) { + echo $err->getMessage(); +} + +?> \ No newline at end of file diff --git a/config_add.php b/config_add.php index 5145895..bf7087f 100644 --- a/config_add.php +++ b/config_add.php @@ -134,16 +134,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $apiKey = trim($_POST['api_key']); $autoMonitor = isset($_POST['auto_monitor']) ? 1 : 0; - if (empty($apiLabel) || empty($siteType) || empty($siteUrl) || empty($account) || empty($apiKey)) { - $message = '
'; - } else { - // 验证URL格式:不允许包含路径 - $parsedUrl = parse_url($siteUrl); - if (!$parsedUrl || !isset($parsedUrl['scheme']) || !isset($parsedUrl['host'])) { - $message = ''; - } elseif (isset($parsedUrl['path']) && $parsedUrl['path'] !== '/') { - $message = ''; + // 将前端类型转换为数据库类型 + $dbSiteType = $siteType; + if ($siteType === 'tencent_cvm' || $siteType === 'tencent_lh') { + $dbSiteType = 'tencent'; + } + + // 验证必填字段(腾讯云需要siteUrl) + if ($siteType === 'tencent_cvm' || $siteType === 'tencent_lh') { + // 腾讯云:siteUrl必填(API域名) + if (empty($apiLabel) || empty($siteType) || empty($siteUrl) || empty($account) || empty($apiKey)) { + $message = ''; } else { + $db = getVpsDB(); // 检查API标识是否已存在 @@ -153,11 +156,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } else { $configId = $db->insert( 'INSERT INTO configs (api_label, site_type, site_url, account, api_key, auto_monitor) VALUES (?, ?, ?, ?, ?, ?)', - [$apiLabel, $siteType, $siteUrl, $account, $apiKey, $autoMonitor] + [$apiLabel, $dbSiteType, $siteUrl, $account, $apiKey, $autoMonitor] ); if ($configId) { - $message = ''; + $typeName = ($siteType === 'tencent_cvm') ? 'CVM云服务器' : '轻量应用服务器'; + $message = ''; // 如果是首次添加配置,提示运行install.sh $configCount = $db->queryOne('SELECT COUNT(*) as count FROM configs')['count']; @@ -193,12 +197,92 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } // 自动刷新VPS列表 - if ($siteType === 'mofang') { + if ($dbSiteType === 'mofang') { refreshVpsListForConfig($configId); $message .= 'app/install.sh 安装监控服务' . htmlspecialchars(implode("\n", $output)) . '