pi-web-ui 0.112.0 → 0.113.0
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/CHANGELOG.md +38 -1
- package/bin/pi-web-ui.mjs +325 -45
- package/dist/server/agent-service-daemon.js +29 -4
- package/dist/server/agent-service.js +215 -35
- package/dist/server/canvas/canvas-agent-tool.js +2 -0
- package/dist/server/canvas/canvas-orchestrator.js +40 -1
- package/dist/server/canvas/pstack-skills-data.js +498 -0
- package/dist/server/dispatch-domain-handlers.js +36 -11
- package/dist/server/dsh/dsh-agent-service.js +52 -4
- package/dist/server/durable/durable-driver.js +37 -98
- package/dist/server/durable/durable-event-projector.js +253 -0
- package/dist/server/engine-probe.js +35 -11
- package/dist/server/index.js +67 -41
- package/dist/server/model-admin.js +185 -63
- package/dist/server/plugins.js +10 -6
- package/dist/server/remote-ssh-service.js +110 -12
- package/dist/server/serialize.js +1 -1
- package/dist/server/settings-service.js +36 -48
- package/dist/server/setup-page.js +632 -0
- package/dist/server/skill-discovery.js +361 -59
- package/dist/server/skill-maintenance.js +231 -0
- package/dist/server/skill-tool.js +32 -3
- package/dist/server/soft-cap.js +29 -7
- package/dist/server/subagents.js +246 -31
- package/dist/server/tool-host-factories.js +2 -0
- package/dist/server/tool-manager.js +106 -28
- package/dist/server/universal/drivers/claude-code.js +96 -4
- package/dist/server/universal/universal-session.js +19 -0
- package/package.json +1 -1
- package/plugins/catalog.json +10 -0
- package/web/dist/assets/{TerminalPanel-Dqr1dK28.js → TerminalPanel-3wojLfLk.js} +2 -2
- package/web/dist/assets/index-A8YXwnpZ.js +2008 -0
- package/web/dist/assets/index-BwL7qBh6.css +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-Dh8BX-lP.js +0 -720
- package/web/dist/assets/index-DqrC1I_a.css +0 -1
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modern /setup page HTML generation.
|
|
3
|
+
* Features:
|
|
4
|
+
* - Sleek modern dark mode (Tailwind / Radix / Vercel style)
|
|
5
|
+
* - Visual Token generation, toggle visibility, one-click copy with direct token URL
|
|
6
|
+
* - Status pills (active, pending restart, secure / insecure)
|
|
7
|
+
* - Clear guidance and tooltips
|
|
8
|
+
* - Security note: only localhost/loopback non-proxy requests can reach this page.
|
|
9
|
+
*/
|
|
10
|
+
export function renderSetupHtml() {
|
|
11
|
+
return `<!doctype html>
|
|
12
|
+
<html lang="zh-CN">
|
|
13
|
+
<head>
|
|
14
|
+
<meta charset="utf-8">
|
|
15
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
16
|
+
<title>pi-web-ui 本地配置中心</title>
|
|
17
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
18
|
+
<style>
|
|
19
|
+
:root {
|
|
20
|
+
--bg: #090a0f;
|
|
21
|
+
--card-bg: rgba(22, 24, 33, 0.75);
|
|
22
|
+
--card-border: rgba(255, 255, 255, 0.08);
|
|
23
|
+
--card-border-hover: rgba(255, 255, 255, 0.16);
|
|
24
|
+
--input-bg: rgba(13, 14, 20, 0.85);
|
|
25
|
+
--input-border: rgba(255, 255, 255, 0.12);
|
|
26
|
+
--input-focus: #3b82f6;
|
|
27
|
+
--primary: #3b82f6;
|
|
28
|
+
--primary-hover: #2563eb;
|
|
29
|
+
--text: #f3f4f6;
|
|
30
|
+
--text-muted: #9ca3af;
|
|
31
|
+
--text-dim: #6b7280;
|
|
32
|
+
--success: #10b981;
|
|
33
|
+
--success-bg: rgba(16, 185, 129, 0.12);
|
|
34
|
+
--warning: #f59e0b;
|
|
35
|
+
--warning-bg: rgba(245, 158, 11, 0.12);
|
|
36
|
+
--danger: #ef4444;
|
|
37
|
+
--danger-bg: rgba(239, 68, 68, 0.12);
|
|
38
|
+
--radius-sm: 6px;
|
|
39
|
+
--radius: 10px;
|
|
40
|
+
--radius-lg: 14px;
|
|
41
|
+
}
|
|
42
|
+
* {
|
|
43
|
+
box-sizing: border-box;
|
|
44
|
+
margin: 0;
|
|
45
|
+
padding: 0;
|
|
46
|
+
}
|
|
47
|
+
body {
|
|
48
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
49
|
+
background-color: var(--bg);
|
|
50
|
+
background-image:
|
|
51
|
+
radial-gradient(circle at 15% 15%, rgba(59, 130, 246, 0.08) 0%, transparent 40%),
|
|
52
|
+
radial-gradient(circle at 85% 85%, rgba(139, 92, 246, 0.06) 0%, transparent 40%);
|
|
53
|
+
background-attachment: fixed;
|
|
54
|
+
color: var(--text);
|
|
55
|
+
min-height: 100vh;
|
|
56
|
+
display: flex;
|
|
57
|
+
flex-direction: column;
|
|
58
|
+
align-items: center;
|
|
59
|
+
padding: 40px 16px;
|
|
60
|
+
line-height: 1.5;
|
|
61
|
+
-webkit-font-smoothing: antialiased;
|
|
62
|
+
}
|
|
63
|
+
.container {
|
|
64
|
+
width: 100%;
|
|
65
|
+
max-width: 620px;
|
|
66
|
+
}
|
|
67
|
+
.header {
|
|
68
|
+
margin-bottom: 28px;
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
justify-content: space-between;
|
|
72
|
+
}
|
|
73
|
+
.brand {
|
|
74
|
+
display: flex;
|
|
75
|
+
align-items: center;
|
|
76
|
+
gap: 12px;
|
|
77
|
+
}
|
|
78
|
+
.brand-icon {
|
|
79
|
+
width: 40px;
|
|
80
|
+
height: 40px;
|
|
81
|
+
border-radius: var(--radius);
|
|
82
|
+
background: linear-gradient(135deg, #3b82f6, #8b5cf6);
|
|
83
|
+
display: flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
justify-content: center;
|
|
86
|
+
color: #fff;
|
|
87
|
+
box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35);
|
|
88
|
+
}
|
|
89
|
+
.brand-icon svg {
|
|
90
|
+
width: 22px;
|
|
91
|
+
height: 22px;
|
|
92
|
+
}
|
|
93
|
+
.brand-text h1 {
|
|
94
|
+
font-size: 20px;
|
|
95
|
+
font-weight: 700;
|
|
96
|
+
letter-spacing: -0.02em;
|
|
97
|
+
color: #fff;
|
|
98
|
+
}
|
|
99
|
+
.brand-text p {
|
|
100
|
+
font-size: 13px;
|
|
101
|
+
color: var(--text-muted);
|
|
102
|
+
}
|
|
103
|
+
.sec-badge {
|
|
104
|
+
display: inline-flex;
|
|
105
|
+
align-items: center;
|
|
106
|
+
gap: 6px;
|
|
107
|
+
padding: 5px 10px;
|
|
108
|
+
border-radius: 9999px;
|
|
109
|
+
font-size: 12px;
|
|
110
|
+
font-weight: 500;
|
|
111
|
+
background: var(--success-bg);
|
|
112
|
+
color: var(--success);
|
|
113
|
+
border: 1px solid rgba(16, 185, 129, 0.25);
|
|
114
|
+
}
|
|
115
|
+
.sec-badge svg {
|
|
116
|
+
width: 14px;
|
|
117
|
+
height: 14px;
|
|
118
|
+
}
|
|
119
|
+
.card {
|
|
120
|
+
background: var(--card-bg);
|
|
121
|
+
backdrop-filter: blur(16px);
|
|
122
|
+
-webkit-backdrop-filter: blur(16px);
|
|
123
|
+
border: 1px solid var(--card-border);
|
|
124
|
+
border-radius: var(--radius-lg);
|
|
125
|
+
padding: 24px;
|
|
126
|
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
|
|
127
|
+
margin-bottom: 20px;
|
|
128
|
+
}
|
|
129
|
+
.card-title {
|
|
130
|
+
font-size: 15px;
|
|
131
|
+
font-weight: 600;
|
|
132
|
+
color: #fff;
|
|
133
|
+
margin-bottom: 16px;
|
|
134
|
+
display: flex;
|
|
135
|
+
align-items: center;
|
|
136
|
+
gap: 8px;
|
|
137
|
+
}
|
|
138
|
+
.field-group {
|
|
139
|
+
margin-bottom: 20px;
|
|
140
|
+
}
|
|
141
|
+
.field-group:last-child {
|
|
142
|
+
margin-bottom: 0;
|
|
143
|
+
}
|
|
144
|
+
.field-header {
|
|
145
|
+
display: flex;
|
|
146
|
+
align-items: center;
|
|
147
|
+
justify-content: space-between;
|
|
148
|
+
margin-bottom: 6px;
|
|
149
|
+
}
|
|
150
|
+
label {
|
|
151
|
+
font-size: 13px;
|
|
152
|
+
font-weight: 500;
|
|
153
|
+
color: #e5e7eb;
|
|
154
|
+
}
|
|
155
|
+
.field-hint {
|
|
156
|
+
font-size: 12px;
|
|
157
|
+
color: var(--text-dim);
|
|
158
|
+
margin-top: 5px;
|
|
159
|
+
line-height: 1.4;
|
|
160
|
+
}
|
|
161
|
+
.input-wrap {
|
|
162
|
+
position: relative;
|
|
163
|
+
display: flex;
|
|
164
|
+
align-items: center;
|
|
165
|
+
}
|
|
166
|
+
input {
|
|
167
|
+
width: 100%;
|
|
168
|
+
height: 40px;
|
|
169
|
+
background: var(--input-bg);
|
|
170
|
+
border: 1px solid var(--input-border);
|
|
171
|
+
border-radius: var(--radius);
|
|
172
|
+
padding: 0 12px;
|
|
173
|
+
font-size: 14px;
|
|
174
|
+
color: var(--text);
|
|
175
|
+
transition: all 0.15s ease;
|
|
176
|
+
outline: none;
|
|
177
|
+
font-family: inherit;
|
|
178
|
+
}
|
|
179
|
+
input:focus {
|
|
180
|
+
border-color: var(--input-focus);
|
|
181
|
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
|
|
182
|
+
}
|
|
183
|
+
.input-with-actions {
|
|
184
|
+
padding-right: 84px;
|
|
185
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
186
|
+
}
|
|
187
|
+
.input-actions {
|
|
188
|
+
position: absolute;
|
|
189
|
+
right: 6px;
|
|
190
|
+
display: flex;
|
|
191
|
+
gap: 4px;
|
|
192
|
+
}
|
|
193
|
+
.btn-icon {
|
|
194
|
+
background: transparent;
|
|
195
|
+
border: 0;
|
|
196
|
+
color: var(--text-muted);
|
|
197
|
+
padding: 6px;
|
|
198
|
+
border-radius: var(--radius-sm);
|
|
199
|
+
cursor: pointer;
|
|
200
|
+
display: flex;
|
|
201
|
+
align-items: center;
|
|
202
|
+
justify-content: center;
|
|
203
|
+
transition: all 0.15s ease;
|
|
204
|
+
}
|
|
205
|
+
.btn-icon:hover {
|
|
206
|
+
color: #fff;
|
|
207
|
+
background: rgba(255, 255, 255, 0.1);
|
|
208
|
+
}
|
|
209
|
+
.btn-icon svg {
|
|
210
|
+
width: 16px;
|
|
211
|
+
height: 16px;
|
|
212
|
+
}
|
|
213
|
+
.status-pill {
|
|
214
|
+
display: inline-flex;
|
|
215
|
+
align-items: center;
|
|
216
|
+
gap: 6px;
|
|
217
|
+
font-size: 12px;
|
|
218
|
+
padding: 2px 8px;
|
|
219
|
+
border-radius: 9999px;
|
|
220
|
+
margin-top: 6px;
|
|
221
|
+
}
|
|
222
|
+
.status-pill.active {
|
|
223
|
+
background: var(--success-bg);
|
|
224
|
+
color: var(--success);
|
|
225
|
+
}
|
|
226
|
+
.status-pill.inactive {
|
|
227
|
+
background: var(--warning-bg);
|
|
228
|
+
color: var(--warning);
|
|
229
|
+
}
|
|
230
|
+
.status-pill.danger {
|
|
231
|
+
background: var(--danger-bg);
|
|
232
|
+
color: var(--danger);
|
|
233
|
+
}
|
|
234
|
+
.grid-2 {
|
|
235
|
+
display: grid;
|
|
236
|
+
grid-template-columns: 1fr 1fr;
|
|
237
|
+
gap: 16px;
|
|
238
|
+
}
|
|
239
|
+
@media (max-width: 520px) {
|
|
240
|
+
.grid-2 {
|
|
241
|
+
grid-template-columns: 1fr;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
.actions-bar {
|
|
245
|
+
display: flex;
|
|
246
|
+
align-items: center;
|
|
247
|
+
justify-content: space-between;
|
|
248
|
+
padding-top: 10px;
|
|
249
|
+
}
|
|
250
|
+
.btn-primary {
|
|
251
|
+
background: var(--primary);
|
|
252
|
+
color: #fff;
|
|
253
|
+
border: 0;
|
|
254
|
+
border-radius: var(--radius);
|
|
255
|
+
padding: 10px 24px;
|
|
256
|
+
font-size: 14px;
|
|
257
|
+
font-weight: 500;
|
|
258
|
+
cursor: pointer;
|
|
259
|
+
transition: background 0.15s ease, transform 0.05s ease;
|
|
260
|
+
display: inline-flex;
|
|
261
|
+
align-items: center;
|
|
262
|
+
gap: 8px;
|
|
263
|
+
}
|
|
264
|
+
.btn-primary:hover {
|
|
265
|
+
background: var(--primary-hover);
|
|
266
|
+
}
|
|
267
|
+
.btn-primary:active {
|
|
268
|
+
transform: scale(0.98);
|
|
269
|
+
}
|
|
270
|
+
.btn-secondary {
|
|
271
|
+
background: rgba(255, 255, 255, 0.08);
|
|
272
|
+
color: var(--text);
|
|
273
|
+
border: 1px solid var(--card-border);
|
|
274
|
+
border-radius: var(--radius);
|
|
275
|
+
padding: 10px 18px;
|
|
276
|
+
font-size: 14px;
|
|
277
|
+
font-weight: 500;
|
|
278
|
+
cursor: pointer;
|
|
279
|
+
text-decoration: none;
|
|
280
|
+
display: inline-flex;
|
|
281
|
+
align-items: center;
|
|
282
|
+
gap: 6px;
|
|
283
|
+
transition: all 0.15s ease;
|
|
284
|
+
}
|
|
285
|
+
.btn-secondary:hover {
|
|
286
|
+
background: rgba(255, 255, 255, 0.14);
|
|
287
|
+
}
|
|
288
|
+
.banner {
|
|
289
|
+
padding: 12px 16px;
|
|
290
|
+
border-radius: var(--radius);
|
|
291
|
+
font-size: 13px;
|
|
292
|
+
margin-bottom: 20px;
|
|
293
|
+
display: none;
|
|
294
|
+
animation: fadeIn 0.2s ease;
|
|
295
|
+
}
|
|
296
|
+
.banner.ok {
|
|
297
|
+
display: flex;
|
|
298
|
+
background: var(--success-bg);
|
|
299
|
+
border: 1px solid rgba(16, 185, 129, 0.3);
|
|
300
|
+
color: #a7f3d0;
|
|
301
|
+
}
|
|
302
|
+
.banner.err {
|
|
303
|
+
display: flex;
|
|
304
|
+
background: var(--danger-bg);
|
|
305
|
+
border: 1px solid rgba(239, 68, 68, 0.3);
|
|
306
|
+
color: #fca5a5;
|
|
307
|
+
}
|
|
308
|
+
.banner.warn {
|
|
309
|
+
display: flex;
|
|
310
|
+
background: var(--warning-bg);
|
|
311
|
+
border: 1px solid rgba(245, 158, 11, 0.3);
|
|
312
|
+
color: #fde68a;
|
|
313
|
+
}
|
|
314
|
+
.banner-content {
|
|
315
|
+
flex: 1;
|
|
316
|
+
}
|
|
317
|
+
.banner-content strong {
|
|
318
|
+
display: block;
|
|
319
|
+
margin-bottom: 2px;
|
|
320
|
+
color: #fff;
|
|
321
|
+
}
|
|
322
|
+
.footer-text {
|
|
323
|
+
text-align: center;
|
|
324
|
+
font-size: 12px;
|
|
325
|
+
color: var(--text-dim);
|
|
326
|
+
margin-top: 24px;
|
|
327
|
+
line-height: 1.6;
|
|
328
|
+
}
|
|
329
|
+
.footer-text code {
|
|
330
|
+
background: rgba(255, 255, 255, 0.08);
|
|
331
|
+
padding: 2px 6px;
|
|
332
|
+
border-radius: 4px;
|
|
333
|
+
color: #e5e7eb;
|
|
334
|
+
}
|
|
335
|
+
@keyframes fadeIn {
|
|
336
|
+
from { opacity: 0; transform: translateY(-4px); }
|
|
337
|
+
to { opacity: 1; transform: translateY(0); }
|
|
338
|
+
}
|
|
339
|
+
.toast {
|
|
340
|
+
position: fixed;
|
|
341
|
+
bottom: 24px;
|
|
342
|
+
left: 50%;
|
|
343
|
+
transform: translateX(-50%) translateY(20px);
|
|
344
|
+
background: #1f2937;
|
|
345
|
+
color: #fff;
|
|
346
|
+
padding: 8px 16px;
|
|
347
|
+
border-radius: 9999px;
|
|
348
|
+
font-size: 13px;
|
|
349
|
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
|
|
350
|
+
opacity: 0;
|
|
351
|
+
pointer-events: none;
|
|
352
|
+
transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
|
353
|
+
display: flex;
|
|
354
|
+
align-items: center;
|
|
355
|
+
gap: 6px;
|
|
356
|
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
357
|
+
}
|
|
358
|
+
.toast.show {
|
|
359
|
+
opacity: 1;
|
|
360
|
+
transform: translateX(-50%) translateY(0);
|
|
361
|
+
}
|
|
362
|
+
</style>
|
|
363
|
+
</head>
|
|
364
|
+
<body>
|
|
365
|
+
<div class="container">
|
|
366
|
+
<div class="header">
|
|
367
|
+
<div class="brand">
|
|
368
|
+
<div class="brand-icon">
|
|
369
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
370
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/>
|
|
371
|
+
</svg>
|
|
372
|
+
</div>
|
|
373
|
+
<div class="brand-text">
|
|
374
|
+
<h1>本地配置中心</h1>
|
|
375
|
+
<p>服务启动与安全参数控制台</p>
|
|
376
|
+
</div>
|
|
377
|
+
</div>
|
|
378
|
+
<div class="sec-badge" title="硬门禁守护:非回环/反代请求直接403拦截">
|
|
379
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
380
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/>
|
|
381
|
+
</svg>
|
|
382
|
+
仅本机回环
|
|
383
|
+
</div>
|
|
384
|
+
</div>
|
|
385
|
+
|
|
386
|
+
<div id="banner" class="banner">
|
|
387
|
+
<div class="banner-content" id="banner-text"></div>
|
|
388
|
+
</div>
|
|
389
|
+
|
|
390
|
+
<div class="card">
|
|
391
|
+
<div class="card-title">
|
|
392
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
393
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/>
|
|
394
|
+
</svg>
|
|
395
|
+
访问认证 Token
|
|
396
|
+
</div>
|
|
397
|
+
|
|
398
|
+
<div class="field-group">
|
|
399
|
+
<div class="field-header">
|
|
400
|
+
<label for="token">访问密钥(Token)</label>
|
|
401
|
+
<button class="btn-icon" id="btn-gen" title="生成高强度随机 Token" type="button" style="font-size:12px;gap:4px;width:auto;padding:2px 8px;">
|
|
402
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:14px;height:14px;">
|
|
403
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
|
|
404
|
+
</svg>
|
|
405
|
+
随机生成
|
|
406
|
+
</button>
|
|
407
|
+
</div>
|
|
408
|
+
<div class="input-wrap">
|
|
409
|
+
<input id="token" type="password" class="input-with-actions" placeholder="留空则允许免密(仅建议本机开发使用)" autocomplete="new-password">
|
|
410
|
+
<div class="input-actions">
|
|
411
|
+
<button class="btn-icon" id="btn-toggle-token" title="显示/隐藏 Token" type="button">
|
|
412
|
+
<svg id="eye-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
413
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
|
|
414
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
|
|
415
|
+
</svg>
|
|
416
|
+
</button>
|
|
417
|
+
<button class="btn-icon" id="btn-copy-token" title="复制 Token 链接" type="button">
|
|
418
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
419
|
+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
|
|
420
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/>
|
|
421
|
+
</svg>
|
|
422
|
+
</button>
|
|
423
|
+
</div>
|
|
424
|
+
</div>
|
|
425
|
+
<div id="token-status-pill" class="status-pill"></div>
|
|
426
|
+
<p class="field-hint">Token 修改后<b>立即热生效</b>。设置后,外部浏览器请求需携带 Token(自动写入 Cookie 或使用 <code>?token=...</code> 访问)。</p>
|
|
427
|
+
</div>
|
|
428
|
+
</div>
|
|
429
|
+
|
|
430
|
+
<div class="card">
|
|
431
|
+
<div class="card-title">
|
|
432
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
433
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"/>
|
|
434
|
+
</svg>
|
|
435
|
+
网络与监听
|
|
436
|
+
</div>
|
|
437
|
+
|
|
438
|
+
<div class="grid-2">
|
|
439
|
+
<div class="field-group">
|
|
440
|
+
<label for="host">监听地址(Host)</label>
|
|
441
|
+
<input id="host" placeholder="127.0.0.1">
|
|
442
|
+
<p class="field-hint">127.0.0.1 仅本机;0.0.0.0 允许局域网或外部访问。</p>
|
|
443
|
+
</div>
|
|
444
|
+
|
|
445
|
+
<div class="field-group">
|
|
446
|
+
<label for="port">端口(Port)</label>
|
|
447
|
+
<input id="port" inputmode="numeric" placeholder="8787">
|
|
448
|
+
<p class="field-hint">默认 8787。保存后需重启生效。</p>
|
|
449
|
+
</div>
|
|
450
|
+
</div>
|
|
451
|
+
|
|
452
|
+
<div class="field-group">
|
|
453
|
+
<label for="allowHosts">Host 白名单</label>
|
|
454
|
+
<input id="allowHosts" placeholder="例如: pi.internal, myserver.local">
|
|
455
|
+
<p class="field-hint">逗号分隔。未配置口令且公网开放时,只允许匹配的 Host 访问;留空使用默认宽松规则。</p>
|
|
456
|
+
</div>
|
|
457
|
+
|
|
458
|
+
<div class="field-group">
|
|
459
|
+
<label for="allowOrigins">额外 Origin 白名单</label>
|
|
460
|
+
<input id="allowOrigins" placeholder="例如: https://chat.example.com">
|
|
461
|
+
<p class="field-hint">逗号分隔。主要用于反向代理或跨域嵌入场景。</p>
|
|
462
|
+
</div>
|
|
463
|
+
</div>
|
|
464
|
+
|
|
465
|
+
<div class="actions-bar">
|
|
466
|
+
<a id="btn-back" href="/" class="btn-secondary">
|
|
467
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
468
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
|
|
469
|
+
</svg>
|
|
470
|
+
返回主界面
|
|
471
|
+
</a>
|
|
472
|
+
<button id="save" class="btn-primary" type="button">
|
|
473
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
474
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/>
|
|
475
|
+
</svg>
|
|
476
|
+
保存配置
|
|
477
|
+
</button>
|
|
478
|
+
</div>
|
|
479
|
+
|
|
480
|
+
<div class="footer-text">
|
|
481
|
+
配置文件: <code id="config-path">~/.pi-web/server-config.json</code><br>
|
|
482
|
+
提示:命令行参数与环境变量的优先级高于此界面的持久化配置。
|
|
483
|
+
</div>
|
|
484
|
+
</div>
|
|
485
|
+
|
|
486
|
+
<div id="toast" class="toast">
|
|
487
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
488
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/>
|
|
489
|
+
</svg>
|
|
490
|
+
<span id="toast-text">已复制</span>
|
|
491
|
+
</div>
|
|
492
|
+
|
|
493
|
+
<script>
|
|
494
|
+
const $ = id => document.getElementById(id);
|
|
495
|
+
|
|
496
|
+
function showToast(text) {
|
|
497
|
+
const t = $("toast");
|
|
498
|
+
$("toast-text").textContent = text;
|
|
499
|
+
t.classList.add("show");
|
|
500
|
+
setTimeout(() => t.classList.remove("show"), 2000);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function showBanner(type, title, desc) {
|
|
504
|
+
const b = $("banner");
|
|
505
|
+
b.className = "banner " + type;
|
|
506
|
+
$("banner-text").innerHTML = "<strong>" + title + "</strong>" + (desc ? "<span>" + desc + "</span>" : "");
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function updateTokenPill(tokenSet, warning) {
|
|
510
|
+
const p = $("token-status-pill");
|
|
511
|
+
if (!tokenSet) {
|
|
512
|
+
p.className = "status-pill inactive";
|
|
513
|
+
p.textContent = "● 当前未设置 Token(免密模式)";
|
|
514
|
+
} else if (warning) {
|
|
515
|
+
p.className = "status-pill danger";
|
|
516
|
+
p.textContent = "● " + warning;
|
|
517
|
+
} else {
|
|
518
|
+
p.className = "status-pill active";
|
|
519
|
+
p.textContent = "● Token 保护中(状态良好)";
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// 密码框显示/隐藏
|
|
524
|
+
let pwdVisible = false;
|
|
525
|
+
$("btn-toggle-token").onclick = () => {
|
|
526
|
+
pwdVisible = !pwdVisible;
|
|
527
|
+
$("token").type = pwdVisible ? "text" : "password";
|
|
528
|
+
$("eye-icon").innerHTML = pwdVisible
|
|
529
|
+
? '<path stroke-linecap="round" stroke-linejoin="round" d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l18 18"/>'
|
|
530
|
+
: '<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/><path stroke-linecap="round" stroke-linejoin="round" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>';
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
// 随机生成 32 位 Token
|
|
534
|
+
$("btn-gen").onclick = () => {
|
|
535
|
+
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-";
|
|
536
|
+
const arr = new Uint8Array(28);
|
|
537
|
+
window.crypto.getRandomValues(arr);
|
|
538
|
+
let token = "";
|
|
539
|
+
for (let i = 0; i < arr.length; i++) token += chars[arr[i] % chars.length];
|
|
540
|
+
$("token").value = token;
|
|
541
|
+
$("token").type = "text";
|
|
542
|
+
pwdVisible = true;
|
|
543
|
+
updateTokenPill(true, "");
|
|
544
|
+
showToast("已生成随机 Token");
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
// 复制带 Token 的入口链接
|
|
548
|
+
$("btn-copy-token").onclick = () => {
|
|
549
|
+
const t = $("token").value.trim();
|
|
550
|
+
const base = window.location.origin;
|
|
551
|
+
const url = t ? (base + "/?token=" + encodeURIComponent(t)) : base;
|
|
552
|
+
navigator.clipboard.writeText(url).then(() => {
|
|
553
|
+
showToast(t ? "已复制免密登录直达链接" : "已复制主页链接");
|
|
554
|
+
}).catch(() => {
|
|
555
|
+
showToast("复制失败,请手动选取");
|
|
556
|
+
});
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
// 加载初始状态
|
|
560
|
+
fetch("/api/setup/status")
|
|
561
|
+
.then(r => {
|
|
562
|
+
if (!r.ok) throw new Error(r.status + " " + r.statusText);
|
|
563
|
+
return r.json();
|
|
564
|
+
})
|
|
565
|
+
.then(s => {
|
|
566
|
+
$("host").value = s.host || "";
|
|
567
|
+
$("port").value = s.port || "";
|
|
568
|
+
$("allowHosts").value = s.allowHosts || "";
|
|
569
|
+
$("allowOrigins").value = s.allowOrigins || "";
|
|
570
|
+
if (s.token) {
|
|
571
|
+
$("token").value = s.token;
|
|
572
|
+
}
|
|
573
|
+
updateTokenPill(s.tokenSet, s.tokenWarning);
|
|
574
|
+
if (s.configFile) $("config-path").textContent = s.configFile;
|
|
575
|
+
if (s.token) {
|
|
576
|
+
$("btn-back").href = "/?token=" + encodeURIComponent(s.token);
|
|
577
|
+
}
|
|
578
|
+
})
|
|
579
|
+
.catch(e => {
|
|
580
|
+
showBanner("err", "读取配置状态失败", e.message);
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
// 保存配置
|
|
584
|
+
$("save").onclick = () => {
|
|
585
|
+
const saveBtn = $("save");
|
|
586
|
+
saveBtn.disabled = true;
|
|
587
|
+
saveBtn.textContent = "保存中...";
|
|
588
|
+
|
|
589
|
+
const tokenVal = $("token").value;
|
|
590
|
+
fetch("/api/setup/save", {
|
|
591
|
+
method: "POST",
|
|
592
|
+
headers: { "Content-Type": "application/json" },
|
|
593
|
+
body: JSON.stringify({
|
|
594
|
+
token: tokenVal,
|
|
595
|
+
host: $("host").value,
|
|
596
|
+
port: $("port").value,
|
|
597
|
+
allowHosts: $("allowHosts").value,
|
|
598
|
+
allowOrigins: $("allowOrigins").value
|
|
599
|
+
})
|
|
600
|
+
})
|
|
601
|
+
.then(r => r.json().then(j => ({ st: r.status, j })))
|
|
602
|
+
.then(({ st, j }) => {
|
|
603
|
+
saveBtn.disabled = false;
|
|
604
|
+
saveBtn.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/></svg> 保存配置';
|
|
605
|
+
if (!j.ok) {
|
|
606
|
+
showBanner("err", "保存失败", j.error || st);
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const t = tokenVal.trim();
|
|
610
|
+
updateTokenPill(Boolean(t), t.length > 0 && t.length < 8 ? "口令短于 8 字符,局域网暴露时建议更长。" : "");
|
|
611
|
+
if (t) {
|
|
612
|
+
$("btn-back").href = "/?token=" + encodeURIComponent(t);
|
|
613
|
+
} else {
|
|
614
|
+
$("btn-back").href = "/";
|
|
615
|
+
}
|
|
616
|
+
if (j.restartRequired) {
|
|
617
|
+
showBanner("warn", "配置已保存", "Token 已热生效。监听地址、端口或白名单修改需重启服务后生效(pi-web-ui server restart)。");
|
|
618
|
+
} else {
|
|
619
|
+
showBanner("ok", "配置已保存并生效", "Token 已成功应用至当前运行中的服务。");
|
|
620
|
+
}
|
|
621
|
+
showToast("保存成功");
|
|
622
|
+
})
|
|
623
|
+
.catch(e => {
|
|
624
|
+
saveBtn.disabled = false;
|
|
625
|
+
saveBtn.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/></svg> 保存配置';
|
|
626
|
+
showBanner("err", "请求失败", e.message);
|
|
627
|
+
});
|
|
628
|
+
};
|
|
629
|
+
</script>
|
|
630
|
+
</body>
|
|
631
|
+
</html>`;
|
|
632
|
+
}
|