Initial release: CPCHECK cloud port detection tool
Web-based TCP/UDP port checker with firewall/GFW diagnosis, PM2 deployment config, and Ubuntu one-click install script. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,278 @@
|
||||
:root {
|
||||
--bg: #0f1419;
|
||||
--surface: #1a2332;
|
||||
--surface-hover: #243044;
|
||||
--border: #2d3a4f;
|
||||
--text: #e7ecf3;
|
||||
--text-muted: #8b9cb3;
|
||||
--primary: #3b82f6;
|
||||
--primary-hover: #2563eb;
|
||||
--success: #22c55e;
|
||||
--warning: #f59e0b;
|
||||
--danger: #ef4444;
|
||||
--info: #06b6d4;
|
||||
--radius: 10px;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
min-height: 100vh;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem 1.5rem;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
header {
|
||||
text-align: center;
|
||||
margin-bottom: 2.5rem;
|
||||
}
|
||||
|
||||
header h1 {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.05em;
|
||||
background: linear-gradient(135deg, var(--primary), var(--info));
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: var(--text-muted);
|
||||
margin-top: 0.5rem;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.check-form {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 1.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1.25rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
flex: 1;
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
.form-group.flex-2 {
|
||||
flex: 2;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-muted);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
background: var(--bg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
padding: 0.65rem 0.85rem;
|
||||
color: var(--text);
|
||||
font-size: 0.95rem;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary);
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
width: 100%;
|
||||
background: var(--primary);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
padding: 0.75rem 1.5rem;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
background: var(--primary-hover);
|
||||
}
|
||||
|
||||
.btn-primary:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.error-box {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
border: 1px solid var(--danger);
|
||||
border-radius: var(--radius);
|
||||
padding: 1rem 1.25rem;
|
||||
color: var(--danger);
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.result-box {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 1.5rem;
|
||||
animation: fadeIn 0.3s ease;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; transform: translateY(8px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
.result-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.result-header h2 {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.elapsed {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.diagnosis-card {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 1rem;
|
||||
padding: 1.25rem;
|
||||
border-radius: var(--radius);
|
||||
margin-bottom: 1.5rem;
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.diagnosis-card.success { background: rgba(34, 197, 94, 0.08); border-color: rgba(34, 197, 94, 0.3); }
|
||||
.diagnosis-card.warning { background: rgba(245, 158, 11, 0.08); border-color: rgba(245, 158, 11, 0.3); }
|
||||
.diagnosis-card.danger { background: rgba(239, 68, 68, 0.08); border-color: rgba(239, 68, 68, 0.3); }
|
||||
.diagnosis-card.info { background: rgba(6, 182, 212, 0.08); border-color: rgba(6, 182, 212, 0.3); }
|
||||
|
||||
.diagnosis-icon {
|
||||
font-size: 1.75rem;
|
||||
line-height: 1;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.diagnosis-content h3 {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.diagnosis-content p {
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.info-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
background: var(--bg);
|
||||
border-radius: 6px;
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
display: block;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 0.2rem;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.status-open { color: var(--success); }
|
||||
.status-closed { color: var(--danger); }
|
||||
.status-filtered { color: var(--warning); }
|
||||
.status-unknown { color: var(--text-muted); }
|
||||
|
||||
.details-section h3 {
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 0.75rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.details-list {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.details-list li {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-muted);
|
||||
padding-left: 1rem;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.details-list li::before {
|
||||
content: "›";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
footer {
|
||||
margin-top: auto;
|
||||
padding-top: 2rem;
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.form-row {
|
||||
flex-direction: column;
|
||||
}
|
||||
.form-group.flex-2 {
|
||||
min-width: 100%;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>CPCHECK - 云服务器端口检测</title>
|
||||
<link rel="stylesheet" href="/static/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<h1>CPCHECK</h1>
|
||||
<p class="subtitle">云服务器端口检测工具 · 快速定位端口问题</p>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<form id="checkForm" class="check-form">
|
||||
<div class="form-row">
|
||||
<div class="form-group flex-2">
|
||||
<label for="host">域名 / IP 地址</label>
|
||||
<input type="text" id="host" name="host" placeholder="例如: example.com 或 8.8.8.8" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="port">端口</label>
|
||||
<input type="number" id="port" name="port" min="1" max="65535" placeholder="443" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="protocol">协议</label>
|
||||
<select id="protocol" name="protocol">
|
||||
<option value="tcp" selected>TCP</option>
|
||||
<option value="udp">UDP</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" id="submitBtn" class="btn-primary">
|
||||
<span class="btn-text">开始检测</span>
|
||||
<span class="btn-loading" hidden>检测中...</span>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div id="errorBox" class="error-box" hidden></div>
|
||||
|
||||
<div id="resultBox" class="result-box" hidden>
|
||||
<div class="result-header">
|
||||
<h2>检测结果</h2>
|
||||
<span id="elapsed" class="elapsed"></span>
|
||||
</div>
|
||||
|
||||
<div id="diagnosisCard" class="diagnosis-card">
|
||||
<div id="diagnosisIcon" class="diagnosis-icon"></div>
|
||||
<div class="diagnosis-content">
|
||||
<h3 id="diagnosisTitle"></h3>
|
||||
<p id="diagnosisMessage"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="info-grid">
|
||||
<div class="info-item">
|
||||
<span class="info-label">目标</span>
|
||||
<span id="infoTarget" class="info-value"></span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">解析 IP</span>
|
||||
<span id="infoIp" class="info-value"></span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">端口状态</span>
|
||||
<span id="infoStatus" class="info-value"></span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">主机可达</span>
|
||||
<span id="infoReachable" class="info-value"></span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">连接延迟</span>
|
||||
<span id="infoLatency" class="info-value"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="details-section">
|
||||
<h3>检测详情</h3>
|
||||
<ul id="detailsList" class="details-list"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<p>CPCHECK v1.0 · 支持 TCP/UDP 端口检测</p>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,103 @@
|
||||
const DIAGNOSIS_CONFIG = {
|
||||
port_open: { title: "端口开放", icon: "✓", class: "success" },
|
||||
port_not_open: { title: "端口未开放", icon: "✗", class: "danger" },
|
||||
likely_firewall: { title: "可能被防火墙拦截", icon: "⚠", class: "warning" },
|
||||
likely_blocked: { title: "可能被墙或过滤", icon: "⊘", class: "danger" },
|
||||
host_unreachable: { title: "主机不可达", icon: "✗", class: "danger" },
|
||||
dns_failed: { title: "DNS 解析失败", icon: "✗", class: "danger" },
|
||||
udp_ambiguous: { title: "UDP 状态不确定", icon: "?", class: "info" },
|
||||
};
|
||||
|
||||
const STATUS_LABELS = {
|
||||
open: { text: "开放", class: "status-open" },
|
||||
closed: { text: "关闭", class: "status-closed" },
|
||||
filtered: { text: "被过滤", class: "status-filtered" },
|
||||
unknown: { text: "不确定", class: "status-unknown" },
|
||||
};
|
||||
|
||||
const form = document.getElementById("checkForm");
|
||||
const submitBtn = document.getElementById("submitBtn");
|
||||
const btnText = submitBtn.querySelector(".btn-text");
|
||||
const btnLoading = submitBtn.querySelector(".btn-loading");
|
||||
const errorBox = document.getElementById("errorBox");
|
||||
const resultBox = document.getElementById("resultBox");
|
||||
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
hideError();
|
||||
resultBox.hidden = true;
|
||||
setLoading(true);
|
||||
|
||||
const host = document.getElementById("host").value.trim();
|
||||
const port = parseInt(document.getElementById("port").value, 10);
|
||||
const protocol = document.getElementById("protocol").value;
|
||||
|
||||
try {
|
||||
const resp = await fetch("/api/check", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ host, port, protocol }),
|
||||
});
|
||||
|
||||
const json = await resp.json();
|
||||
|
||||
if (!resp.ok) {
|
||||
throw new Error(json.detail || json.error || "请求失败");
|
||||
}
|
||||
|
||||
if (!json.success || !json.data) {
|
||||
throw new Error(json.error || "检测失败");
|
||||
}
|
||||
|
||||
renderResult(json.data);
|
||||
} catch (err) {
|
||||
showError(err.message || "网络错误,请稍后重试");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
function setLoading(loading) {
|
||||
submitBtn.disabled = loading;
|
||||
btnText.hidden = loading;
|
||||
btnLoading.hidden = !loading;
|
||||
}
|
||||
|
||||
function showError(msg) {
|
||||
errorBox.textContent = msg;
|
||||
errorBox.hidden = false;
|
||||
}
|
||||
|
||||
function hideError() {
|
||||
errorBox.hidden = true;
|
||||
}
|
||||
|
||||
function renderResult(data) {
|
||||
const diag = DIAGNOSIS_CONFIG[data.diagnosis] || DIAGNOSIS_CONFIG.udp_ambiguous;
|
||||
const status = STATUS_LABELS[data.port_status] || STATUS_LABELS.unknown;
|
||||
|
||||
const card = document.getElementById("diagnosisCard");
|
||||
card.className = `diagnosis-card ${diag.class}`;
|
||||
document.getElementById("diagnosisIcon").textContent = diag.icon;
|
||||
document.getElementById("diagnosisTitle").textContent = diag.title;
|
||||
document.getElementById("diagnosisMessage").textContent = data.diagnosis_message;
|
||||
|
||||
document.getElementById("elapsed").textContent = `耗时 ${data.elapsed_ms}ms`;
|
||||
document.getElementById("infoTarget").textContent = `${data.host}:${data.port} (${data.protocol.toUpperCase()})`;
|
||||
document.getElementById("infoIp").textContent = data.resolved_ip || "-";
|
||||
document.getElementById("infoStatus").innerHTML =
|
||||
`<span class="${status.class}">${status.text}</span>`;
|
||||
document.getElementById("infoReachable").textContent = data.host_reachable ? "是" : "否";
|
||||
document.getElementById("infoLatency").textContent =
|
||||
data.latency_ms != null ? `${data.latency_ms} ms` : "-";
|
||||
|
||||
const list = document.getElementById("detailsList");
|
||||
list.innerHTML = "";
|
||||
(data.details || []).forEach((d) => {
|
||||
const li = document.createElement("li");
|
||||
li.textContent = d;
|
||||
list.appendChild(li);
|
||||
});
|
||||
|
||||
resultBox.hidden = false;
|
||||
}
|
||||
Reference in New Issue
Block a user