cfpilot 0.50.0 → 0.60.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/cfpilot-kernel-VERSION +2 -2
- package/assets/control.js +28 -37
- package/assets/dataplane.js +14 -23
- package/assets/edge-relay/dashboard-worker.js +6 -0
- package/assets/edge-relay/dashboard.html +204 -0
- package/assets/edge-relay/schema.sql +26 -0
- package/assets/edge-relay/worker.js +890 -0
- package/assets/worker.js +32 -40
- package/dist/cli.js +1076 -99
- package/package.json +2 -2
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>MobiHop 云监测台</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root { color-scheme: dark; }
|
|
9
|
+
* { box-sizing: border-box; }
|
|
10
|
+
body { margin:0; font-family: system-ui, -apple-system, sans-serif; background:#0b1220; color:#e2e8f0; }
|
|
11
|
+
header { padding:16px 24px; border-bottom:1px solid #1e293b; display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:12px; }
|
|
12
|
+
h1 { margin:0; font-size:18px; }
|
|
13
|
+
.sub { color:#64748b; font-size:13px; }
|
|
14
|
+
main { padding:24px; }
|
|
15
|
+
.grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(140px,1fr)); gap:12px; margin-bottom:20px; }
|
|
16
|
+
.card { background:#111a2e; border:1px solid #1e293b; border-radius:10px; padding:14px; }
|
|
17
|
+
.card .label { color:#64748b; font-size:12px; }
|
|
18
|
+
.card .val { font-size:24px; font-weight:600; margin-top:4px; }
|
|
19
|
+
.table-wrap { overflow-x:auto; -webkit-overflow-scrolling:touch; border-radius:10px; }
|
|
20
|
+
table { width:100%; min-width:720px; border-collapse:collapse; background:#111a2e; border:1px solid #1e293b; }
|
|
21
|
+
th,td { padding:10px 12px; text-align:left; font-size:13px; border-bottom:1px solid #1e293b; white-space:nowrap; }
|
|
22
|
+
th { color:#94a3b8; background:#0f172a; font-weight:500; }
|
|
23
|
+
tr:last-child td { border-bottom:none; }
|
|
24
|
+
.dot { display:inline-block; width:8px; height:8px; border-radius:50%; margin-right:6px; }
|
|
25
|
+
.dot.on { background:#22c55e; box-shadow:0 0 6px #22c55e; }
|
|
26
|
+
.dot.off { background:#475569; }
|
|
27
|
+
.mono { font-family: ui-monospace, monospace; font-size:12px; }
|
|
28
|
+
.err { color:#f87171; padding:12px; }
|
|
29
|
+
.cfg { font-size:12px; color:#64748b; display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
|
|
30
|
+
input { background:#0f172a; border:1px solid #334155; color:#e2e8f0; padding:6px 10px; border-radius:6px; font-size:13px; }
|
|
31
|
+
button { background:#2563eb; color:#fff; border:none; padding:6px 12px; border-radius:6px; cursor:pointer; font-size:13px; }
|
|
32
|
+
button:hover { background:#1d4ed8; }
|
|
33
|
+
button.ghost { background:#1e293b; }
|
|
34
|
+
button.ghost:hover { background:#334155; }
|
|
35
|
+
.auth-box { max-width:420px; margin:40px auto; background:#111a2e; border:1px solid #1e293b; border-radius:12px; padding:24px; }
|
|
36
|
+
.auth-box h2 { margin:0 0 6px; font-size:18px; }
|
|
37
|
+
.auth-box p { color:#64748b; font-size:13px; margin:0 0 16px; }
|
|
38
|
+
.auth-box label { display:block; font-size:12px; color:#94a3b8; margin:12px 0 4px; }
|
|
39
|
+
.auth-box input { width:100%; }
|
|
40
|
+
.auth-box .row { display:flex; gap:8px; margin-top:16px; }
|
|
41
|
+
.auth-box .row button { flex:1; }
|
|
42
|
+
.modal-backdrop { position:fixed; inset:0; background:rgba(0,0,0,.6); display:flex; align-items:center; justify-content:center; z-index:50; }
|
|
43
|
+
.modal { background:#111a2e; border:1px solid #1e293b; border-radius:12px; padding:24px; width:90%; max-width:420px; }
|
|
44
|
+
.modal h3 { margin:0 0 12px; font-size:16px; }
|
|
45
|
+
.modal label { display:block; font-size:12px; color:#94a3b8; margin:10px 0 4px; }
|
|
46
|
+
.modal input { width:100%; }
|
|
47
|
+
.modal .row { display:flex; gap:8px; margin-top:16px; justify-content:flex-end; }
|
|
48
|
+
@media (max-width: 640px) {
|
|
49
|
+
header { padding:12px 16px; }
|
|
50
|
+
main { padding:16px; }
|
|
51
|
+
.cfg input { width:100%; }
|
|
52
|
+
h1 { font-size:16px; }
|
|
53
|
+
.card .val { font-size:20px; }
|
|
54
|
+
}
|
|
55
|
+
</style>
|
|
56
|
+
</head>
|
|
57
|
+
<body>
|
|
58
|
+
<header id="hdr" style="display:none">
|
|
59
|
+
<div>
|
|
60
|
+
<h1>MobiHop 云监测台</h1>
|
|
61
|
+
<div class="sub">只读监测 · 节点心跳 · 免费托管</div>
|
|
62
|
+
</div>
|
|
63
|
+
<div class="cfg">
|
|
64
|
+
API: <input id="api" /> <button onclick="saveApi()">保存</button>
|
|
65
|
+
<button class="ghost" onclick="openChangePw()">修改密码</button>
|
|
66
|
+
<button class="ghost" onclick="logout()">退出</button>
|
|
67
|
+
</div>
|
|
68
|
+
</header>
|
|
69
|
+
<main>
|
|
70
|
+
<div id="view-setup" class="auth-box" style="display:none">
|
|
71
|
+
<h2>未配置密码</h2>
|
|
72
|
+
<p>监测台密码尚未初始化。请通过部署脚本(deploy-cf.ps1)设置登录密码,或联系管理员。</p>
|
|
73
|
+
<p id="setup-err" class="err"></p>
|
|
74
|
+
</div>
|
|
75
|
+
<div id="view-login" class="auth-box" style="display:none">
|
|
76
|
+
<h2>登录</h2>
|
|
77
|
+
<p>请输入监测台密码。</p>
|
|
78
|
+
<label>密码</label>
|
|
79
|
+
<input id="login-pw" type="password" onkeydown="if(event.key==='Enter')doLogin()" />
|
|
80
|
+
<div class="row"><button onclick="doLogin()">登录</button></div>
|
|
81
|
+
<p id="login-err" class="err"></p>
|
|
82
|
+
</div>
|
|
83
|
+
<div id="view-app" style="display:none">
|
|
84
|
+
<div class="grid">
|
|
85
|
+
<div class="card"><div class="label">设备总数</div><div class="val" id="total">—</div></div>
|
|
86
|
+
<div class="card"><div class="label">在线</div><div class="val" id="online">—</div></div>
|
|
87
|
+
<div class="card"><div class="label">离线</div><div class="val" id="offline">—</div></div>
|
|
88
|
+
<div class="card"><div class="label">最后刷新</div><div class="val" id="refresh" style="font-size:14px">—</div></div>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="table-wrap">
|
|
91
|
+
<table>
|
|
92
|
+
<thead><tr><th>状态</th><th>设备</th><th>Node ID</th><th>虚拟 IP</th><th>版本</th><th>最后 IP</th><th>最后心跳</th></tr></thead>
|
|
93
|
+
<tbody id="rows"><tr><td colspan="7" style="text-align:center;color:#64748b">加载中…</td></tr></tbody>
|
|
94
|
+
</table>
|
|
95
|
+
</div>
|
|
96
|
+
<p id="err" class="err"></p>
|
|
97
|
+
</div>
|
|
98
|
+
</main>
|
|
99
|
+
<div id="modal" style="display:none"></div>
|
|
100
|
+
<script>
|
|
101
|
+
const DEFAULT_API = location.origin;
|
|
102
|
+
const apiInput = document.getElementById('api');
|
|
103
|
+
if (apiInput) apiInput.value = localStorage.getItem('monitor_api') || DEFAULT_API;
|
|
104
|
+
function saveApi(){ if(apiInput) localStorage.setItem('monitor_api', apiInput.value); load(); }
|
|
105
|
+
function apiUrl(){ const el=document.getElementById('api'); const v = el? el.value : (localStorage.getItem('monitor_api')||DEFAULT_API); return (v||DEFAULT_API).replace(/\/+$/,''); }
|
|
106
|
+
function token(){ return localStorage.getItem('monitor_session') || ''; }
|
|
107
|
+
function setToken(t){ if(t) localStorage.setItem('monitor_session', t); else localStorage.removeItem('monitor_session'); }
|
|
108
|
+
function fmtTime(ms){ if(!ms) return '—'; return new Date(ms).toLocaleString('zh-CN',{hour12:false}); }
|
|
109
|
+
function show(id){ ['view-setup','view-login','view-app'].forEach(v=>{ const e=document.getElementById(v); if(e) e.style.display = v===id?'block':'none'; }); const hdr=document.getElementById('hdr'); if(hdr) hdr.style.display = id==='view-app'?'flex':'none'; }
|
|
110
|
+
async function apiFetch(path, opts){ opts=opts||{}; opts.headers = Object.assign({'Content-Type':'application/json'}, opts.headers||{}); const t=token(); if(t) opts.headers['Authorization']='Bearer '+t; const r=await fetch(apiUrl()+path, opts); return r; }
|
|
111
|
+
|
|
112
|
+
async function init(){
|
|
113
|
+
try {
|
|
114
|
+
const r = await fetch(apiUrl()+'/auth/status');
|
|
115
|
+
const d = await r.json();
|
|
116
|
+
if (d.setupRequired) { show('view-setup'); }
|
|
117
|
+
else if (!token()) { show('view-login'); }
|
|
118
|
+
else { show('view-app'); load(); }
|
|
119
|
+
} catch(e){ document.getElementById('login-err').textContent='连接失败: '+e.message; show('view-login'); }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function doSetup(){ /* disabled: password must be set via deploy script */ }
|
|
123
|
+
|
|
124
|
+
async function doLogin(){
|
|
125
|
+
const pw=document.getElementById('login-pw').value;
|
|
126
|
+
const err=document.getElementById('login-err');
|
|
127
|
+
err.textContent='';
|
|
128
|
+
try {
|
|
129
|
+
const r=await fetch(apiUrl()+'/auth/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({password:pw})});
|
|
130
|
+
const d=await r.json();
|
|
131
|
+
if(!r.ok){ err.textContent=d.message||'登录失败'; return; }
|
|
132
|
+
setToken(d.token); show('view-app'); load();
|
|
133
|
+
} catch(e){ err.textContent='失败: '+e.message; }
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function logout(){
|
|
137
|
+
try { await apiFetch('/auth/logout',{method:'POST'}); } catch(e){}
|
|
138
|
+
setToken(''); show('view-login');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function openChangePw(){
|
|
142
|
+
const m=document.getElementById('modal');
|
|
143
|
+
m.style.display='flex';
|
|
144
|
+
m.innerHTML = `<div class="modal">
|
|
145
|
+
<h3>修改密码</h3>
|
|
146
|
+
<label>旧密码</label><input id="cp-old" type="password" />
|
|
147
|
+
<label>新密码(至少 8 位)</label><input id="cp-new" type="password" />
|
|
148
|
+
<label>确认新密码</label><input id="cp-new2" type="password" />
|
|
149
|
+
<p id="cp-err" class="err"></p>
|
|
150
|
+
<div class="row"><button class="ghost" onclick="closeModal()">取消</button><button onclick="doChangePw()">确认</button></div>
|
|
151
|
+
</div>`;
|
|
152
|
+
}
|
|
153
|
+
function closeModal(){ const m=document.getElementById('modal'); m.style.display='none'; m.innerHTML=''; }
|
|
154
|
+
async function doChangePw(){
|
|
155
|
+
const oldPw=document.getElementById('cp-old').value;
|
|
156
|
+
const newPw=document.getElementById('cp-new').value;
|
|
157
|
+
const newPw2=document.getElementById('cp-new2').value;
|
|
158
|
+
const err=document.getElementById('cp-err');
|
|
159
|
+
err.textContent='';
|
|
160
|
+
if(newPw.length<8){ err.textContent='新密码至少 8 位'; return; }
|
|
161
|
+
if(newPw!==newPw2){ err.textContent='两次新密码不一致'; return; }
|
|
162
|
+
try {
|
|
163
|
+
const r=await apiFetch('/auth/change-password',{method:'POST',body:JSON.stringify({oldPassword:oldPw,newPassword:newPw})});
|
|
164
|
+
const d=await r.json();
|
|
165
|
+
if(!r.ok){ err.textContent=d.message||'修改失败'; return; }
|
|
166
|
+
closeModal();
|
|
167
|
+
alert('密码已修改,请重新登录');
|
|
168
|
+
logout();
|
|
169
|
+
} catch(e){ err.textContent='失败: '+e.message; }
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function load(){
|
|
173
|
+
const err = document.getElementById('err');
|
|
174
|
+
err.textContent = '';
|
|
175
|
+
try {
|
|
176
|
+
const r = await apiFetch('/devices');
|
|
177
|
+
if(r.status===401){ setToken(''); show('view-login'); return; }
|
|
178
|
+
if(!r.ok) throw new Error('HTTP ' + r.status);
|
|
179
|
+
const data = await r.json();
|
|
180
|
+
const devs = data.devices || [];
|
|
181
|
+
document.getElementById('total').textContent = devs.length;
|
|
182
|
+
const on = devs.filter(d=>d.online).length;
|
|
183
|
+
document.getElementById('online').textContent = on;
|
|
184
|
+
document.getElementById('offline').textContent = devs.length - on;
|
|
185
|
+
document.getElementById('refresh').textContent = fmtTime(data.generatedAtMs);
|
|
186
|
+
const tbody = document.getElementById('rows');
|
|
187
|
+
if(devs.length===0){ tbody.innerHTML = '<tr><td colspan="7" style="text-align:center;color:#64748b">暂无设备。节点需配置 monitoring 上报。</td></tr>'; return; }
|
|
188
|
+
tbody.innerHTML = devs.map(d => `<tr>
|
|
189
|
+
<td><span class="dot ${d.online?'on':'off'}"></span>${d.online?'在线':'离线'}</td>
|
|
190
|
+
<td>${d.alias||'—'}</td>
|
|
191
|
+
<td class="mono">${d.nodeId}</td>
|
|
192
|
+
<td class="mono">${d.virtualIpv4||'—'}</td>
|
|
193
|
+
<td>${d.version||'—'}</td>
|
|
194
|
+
<td class="mono">${d.lastIp||'—'}</td>
|
|
195
|
+
<td>${fmtTime(d.lastSeenMs)}</td>
|
|
196
|
+
</tr>`).join('');
|
|
197
|
+
} catch(e){ err.textContent = '加载失败: ' + e.message; }
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
init();
|
|
201
|
+
setInterval(()=>{ if(document.getElementById('view-app').style.display!=='none') load(); }, 15000);
|
|
202
|
+
</script>
|
|
203
|
+
</body>
|
|
204
|
+
</html>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
-- MobiHop 云监测台 D1 schema(与 cf-monitor 历史一致,合并后随统一 Worker 使用)
|
|
2
|
+
CREATE TABLE IF NOT EXISTS devices (
|
|
3
|
+
node_id TEXT PRIMARY KEY,
|
|
4
|
+
alias TEXT,
|
|
5
|
+
virtual_ipv4 TEXT,
|
|
6
|
+
version TEXT,
|
|
7
|
+
last_ip TEXT,
|
|
8
|
+
online INTEGER NOT NULL DEFAULT 0,
|
|
9
|
+
last_seen_ms INTEGER NOT NULL,
|
|
10
|
+
updated_at_ms INTEGER NOT NULL
|
|
11
|
+
);
|
|
12
|
+
CREATE INDEX IF NOT EXISTS idx_devices_last_seen ON devices(last_seen_ms DESC);
|
|
13
|
+
|
|
14
|
+
CREATE TABLE IF NOT EXISTS auth (
|
|
15
|
+
id INTEGER PRIMARY KEY,
|
|
16
|
+
password_hash TEXT,
|
|
17
|
+
salt TEXT,
|
|
18
|
+
updated_at_ms INTEGER NOT NULL
|
|
19
|
+
);
|
|
20
|
+
CREATE TABLE IF NOT EXISTS sessions (
|
|
21
|
+
token TEXT PRIMARY KEY,
|
|
22
|
+
created_at_ms INTEGER NOT NULL,
|
|
23
|
+
expires_at_ms INTEGER NOT NULL
|
|
24
|
+
);
|
|
25
|
+
CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expires_at_ms);
|
|
26
|
+
|