miaopanel
1<script setup lang="ts">
2import { computed, inject, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
3import { api } from '../api'
4import { navigate, route } from '../router'
5import { clearLeaveGuard, setLeaveGuard } from '../guard'
6import type { Site, SiteOptions } from '../types'
7import { time } from '../format'
8import ConfirmDialog from '../components/ConfirmDialog.vue'
9import DirPicker from '../components/DirPicker.vue'
10
11const props = defineProps<{ id: number }>()
12const notify = inject<(text: string, kind?: 'ok' | 'error' | 'warn') => void>('notify')!
13
14type Tab = 'overview' | 'runtime' | 'security' | 'ssl' | 'logs' | 'config'
15const tabs: { value: Tab; label: string }[] = [
16 { value: 'overview', label: '概览' },
17 { value: 'runtime', label: '运行与域名' },
18 { value: 'security', label: '安全与性能' },
19 { value: 'ssl', label: 'SSL 证书' },
20 { value: 'logs', label: '日志' },
21 { value: 'config', label: '配置' },
22]
23
24const site = ref<Site | null>(null)
25const tab = ref<Tab>('overview')
26const loading = ref(true)
27const saving = ref(false)
28const baseline = ref('')
29const lifeBusy = ref(false)
30const mobilePicker = ref(false)
31const runtimes = ref<{ php: string[] }>({ php: [] })
32
33const options = reactive<SiteOptions>({
34 https_redirect: false,
35 hsts: false,
36 security_headers: true,
37 limit_rate_kb: 0,
38 conn_per_ip: 0,
39 conn_per_server: 0,
40 anti_leech: false,
41 anti_leech_hosts: [],
42 ip_mode: '',
43 ip_list: [],
44 waf: true,
45 waf_rate: 20,
46 waf_burst: 40,
47 custom_nginx: '',
48 listen_port: 0,
49})
50
51const form = reactive({
52 domainsText: '',
53 root: '',
54 php: '',
55 port: 0,
56 upstream: '',
57 remark: '',
58 runUser: 'www',
59 startCmd: '',
60 env: '',
61})
62
63const ipText = ref('')
64const refererText = ref('')
65const appKinds = ['go', 'node', 'proxy']
66
67const isApp = computed(() => appKinds.includes(site.value?.kind ?? ''))
68const kindLabel = computed(() => {
69 const map: Record<string, string> = {
70 static: '静态站点',
71 php: 'PHP',
72 go: 'Go 应用',
73 node: 'Node 应用',
74 proxy: '反向代理',
75 }
76 return map[site.value?.kind ?? ''] ?? site.value?.kind
77})
78
79const phpOptions = computed(() => {
80 const list = runtimes.value.php ?? []
81 if (form.php && !list.includes(form.php)) return [form.php, ...list]
82 return list.length ? list : [form.php || '8.2']
83})
84
85const live = computed(() => {
86 const s = site.value
87 if (!s) return { text: '加载中', cls: 'off' }
88 const state = s.live_status ?? ''
89 if (state === 'preview') return { text: 'nginx 未安装', cls: 'err' }
90 if (!isApp.value) {
91 return state === 'inactive' ? { text: '已停止', cls: 'off' } : { text: '运行中', cls: 'ok' }
92 }
93 switch (state) {
94 case 'active':
95 return { text: '运行中', cls: 'ok' }
96 case 'activating':
97 case 'reloading':
98 return { text: '启动中', cls: '' }
99 case 'failed':
100 return { text: '异常', cls: 'err' }
101 case 'inactive':
102 return { text: '已停止', cls: 'off' }
103 case 'unsupported':
104 return { text: '系统不支持', cls: 'err' }
105 default:
106 return state === ''
107 ? { text: s.status === 'running' ? '运行中' : '已停止', cls: s.status === 'running' ? 'ok' : 'off' }
108 : { text: '状态未知', cls: 'off' }
109 }
110})
111
112const accessURL = computed(() => {
113 const s = site.value
114 if (!s) return ''
115 const host = s.domains.find((d) => !d.startsWith('*.')) ?? s.domains[0] ?? ''
116 if (!host) return ''
117 // TLS is always served on 443 regardless of the custom HTTP listener.
118 if (s.ssl_enabled) return `https://${host}`
119 const port = s.options.listen_port || 80
120 return `http://${host}${port && port !== 80 ? ':' + port : ''}`
121})
122
123function parseList(text: string) {
124 return text
125 .split(/[\s,]+/)
126 .map((v) => v.trim())
127 .filter(Boolean)
128}
129
130function parseDomains(text: string) {
131 return text
132 .split(/[\s,;]+/)
133 .map((d) => d.trim().toLowerCase())
134 .filter(Boolean)
135}
136
137function payload() {
138 return {
139 name: site.value?.name ?? '',
140 kind: site.value?.kind ?? '',
141 domains: parseDomains(form.domainsText),
142 root: form.root.trim(),
143 port: isApp.value ? Number(form.port) || 0 : 0,
144 php_version: site.value?.kind === 'php' ? form.php : '',
145 run_user: form.runUser.trim() || 'www',
146 start_cmd: form.startCmd,
147 env: form.env,
148 upstream: form.upstream.trim(),
149 remark: form.remark,
150 options: {
151 ...options,
152 ip_list: parseList(ipText.value),
153 anti_leech_hosts: parseList(refererText.value),
154 },
155 }
156}
157
158const dirty = computed(() => !!site.value && JSON.stringify(payload()) !== baseline.value)
159
160function fill(s: Site) {
161 site.value = s
162 Object.assign(options, {
163 https_redirect: false,
164 hsts: false,
165 security_headers: true,
166 limit_rate_kb: 0,
167 conn_per_ip: 0,
168 conn_per_server: 0,
169 anti_leech: false,
170 anti_leech_hosts: [],
171 ip_mode: '',
172 ip_list: [],
173 waf: true,
174 waf_rate: 20,
175 waf_burst: 40,
176 custom_nginx: '',
177 listen_port: 0,
178 ...s.options,
179 })
180 form.domainsText = s.domains.join('\n')
181 form.root = s.root
182 form.php = s.php_version
183 form.port = s.port
184 form.upstream = s.upstream
185 form.remark = s.remark
186 form.runUser = s.run_user
187 form.startCmd = s.start_cmd
188 form.env = s.env
189 ipText.value = (s.options.ip_list ?? []).join('\n')
190 refererText.value = (s.options.anti_leech_hosts ?? []).join('\n')
191 baseline.value = JSON.stringify(payload())
192}
193
194async function loadSite() {
195 loading.value = true
196 try {
197 const s = await api.get<Site>(`api/v1/sites/${props.id}`)
198 fill(s)
199 if (!runtimes.value.php.length) {
200 try {
201 runtimes.value = await api.get<{ php: string[] }>('api/v1/system/runtimes')
202 } catch {
203 /* runtime detection is optional */
204 }
205 }
206 } catch (e) {
207 notify((e as Error).message, 'error')
208 } finally {
209 loading.value = false
210 }
211}
212
213function resetForm() {
214 if (site.value) fill(site.value)
215}
216
217async function save() {
218 if (!site.value) return
219 if (!parseDomains(form.domainsText).length) {
220 notify('请至少填写一个域名', 'error')
221 return
222 }
223 if (site.value.kind === 'proxy' && !/^https?:\/\//i.test(form.upstream.trim())) {
224 notify('上游地址必须以 http:// 或 https:// 开头', 'error')
225 return
226 }
227 saving.value = true
228 try {
229 const updated = await api.put<Site>(`api/v1/sites/${props.id}`, payload())
230 fill(updated)
231 notify('配置已保存并重载 nginx')
232 } catch (e) {
233 notify((e as Error).message, 'error')
234 } finally {
235 saving.value = false
236 }
237}
238
239async function life(act: 'start' | 'stop' | 'restart') {
240 lifeBusy.value = true
241 try {
242 await api.post(`api/v1/sites/${props.id}/action`, { action: act })
243 notify(act === 'start' ? '应用已启动' : act === 'stop' ? '应用已停止' : '应用已重启')
244 await loadSite()
245 } catch (e) {
246 notify((e as Error).message, 'error')
247 } finally {
248 lifeBusy.value = false
249 }
250}
251
252function setTab(next: Tab) {
253 tab.value = next
254 route.value = { ...route.value, tab: next }
255 history.replaceState(null, '', `#/sites/${props.id}/${next}`)
256}
257
258function openSite() {
259 if (accessURL.value) window.open(accessURL.value, '_blank', 'noopener')
260}
261
262function chooseRoot(path: string) {
263 form.root = path
264 mobilePicker.value = false
265}
266
267async function copy(text: string, label = '已复制') {
268 try {
269 await navigator.clipboard.writeText(text)
270 notify(label)
271 } catch {
272 notify('浏览器不允许访问剪贴板', 'error')
273 }
274}
275
276/* ---------------- delete ---------------- */
277const deleting = ref(false)
278const deleteBusy = ref(false)
279const deleteError = ref('')
280
281async function confirmDelete(payloadValue: { option: string }) {
282 if (!site.value) return
283 deleteBusy.value = true
284 deleteError.value = ''
285 try {
286 const removeFiles = payloadValue.option === 'remove'
287 await api.del(`api/v1/sites/${props.id}?remove_files=${removeFiles ? 1 : 0}`)
288 notify(`站点 ${site.value.name} 已删除`)
289 baseline.value = JSON.stringify(payload())
290 deleting.value = false
291 navigate('sites')
292 } catch (e) {
293 deleteError.value = (e as Error).message
294 } finally {
295 deleteBusy.value = false
296 }
297}
298
299/* ---------------- SSL ---------------- */
300interface SSLStatus {
301 enabled: boolean
302 cert?: {
303 domains: string
304 issuer: string
305 not_before: number
306 not_after: number
307 staging: boolean
308 auto_renew: boolean
309 }
310 days_left: number
311 dns: Record<string, boolean>
312}
313const ssl = ref<SSLStatus | null>(null)
314const sslBusy = ref(false)
315const sslError = ref('')
316const sslElapsed = ref(0)
317let sslTimer: number | undefined
318
319function startSSLClock() {
320 sslElapsed.value = 0
321 stopSSLClock()
322 sslTimer = window.setInterval(() => {
323 sslElapsed.value += 1
324 }, 1000)
325}
326function stopSSLClock() {
327 if (sslTimer !== undefined) {
328 window.clearInterval(sslTimer)
329 sslTimer = undefined
330 }
331}
332
333async function loadSSL() {
334 try {
335 ssl.value = await api.get<SSLStatus>(`api/v1/sites/${props.id}/ssl`)
336 sslError.value = ''
337 } catch (e) {
338 sslError.value = (e as Error).message
339 }
340}
341
342async function issueSSL(staging: boolean) {
343 sslBusy.value = true
344 sslError.value = ''
345 startSSLClock()
346 try {
347 await api.post(`api/v1/sites/${props.id}/ssl/issue`, { staging, auto_renew: true })
348 notify(staging ? '测试证书已签发(浏览器不会信任)' : '证书申请成功,HTTPS 已启用')
349 await Promise.all([loadSSL(), loadSite()])
350 } catch (e) {
351 sslError.value = (e as Error).message
352 notify((e as Error).message, 'error')
353 } finally {
354 sslBusy.value = false
355 stopSSLClock()
356 }
357}
358
359async function sslAction(action: 'enable' | 'disable') {
360 sslBusy.value = true
361 sslError.value = ''
362 try {
363 await api.post(`api/v1/sites/${props.id}/ssl/${action}`, {})
364 notify(action === 'enable' ? 'HTTPS 已启用' : 'HTTPS 已关闭')
365 await Promise.all([loadSSL(), loadSite()])
366 } catch (e) {
367 sslError.value = (e as Error).message
368 } finally {
369 sslBusy.value = false
370 }
371}
372
373/* ---------------- logs ---------------- */
374const logType = ref('access')
375const logLines = ref<string[]>([])
376const logBusy = ref(false)
377const logAuto = ref(false)
378const logFollow = ref(true)
379const logCount = ref(300)
380const logUpdated = ref(0)
381const logBox = ref<HTMLElement | null>(null)
382let logTimer: number | undefined
383
384async function loadLogs() {
385 logBusy.value = true
386 try {
387 const res = await api.get<{ lines: string[] }>(
388 `api/v1/sites/${props.id}/logs?type=${encodeURIComponent(logType.value)}&lines=${logCount.value}`,
389 )
390 logLines.value = res.lines ?? []
391 logUpdated.value = Math.floor(Date.now() / 1000)
392 if (logFollow.value) {
393 requestAnimationFrame(() => {
394 if (logBox.value) logBox.value.scrollTop = logBox.value.scrollHeight
395 })
396 }
397 } catch (e) {
398 logLines.value = []
399 notify((e as Error).message, 'error')
400 } finally {
401 logBusy.value = false
402 }
403}
404
405function syncLogTimer() {
406 if (logTimer !== undefined) {
407 window.clearInterval(logTimer)
408 logTimer = undefined
409 }
410 if (tab.value === 'logs' && logAuto.value) {
411 logTimer = window.setInterval(() => {
412 if (!document.hidden) void loadLogs()
413 }, 5000)
414 }
415}
416
417/* ---------------- config / rewrite ---------------- */
418const configFiles = ref<Record<string, string>>({})
419const configPath = ref('')
420const configBusy = ref(false)
421const configView = ref<'files' | 'rewrite'>('files')
422const rewrite = ref('')
423const rewriteBusy = ref(false)
424
425async function loadConfig() {
426 configBusy.value = true
427 try {
428 const res = await api.get<{ files: Record<string, string>; main: string }>(
429 `api/v1/sites/${props.id}/config`,
430 )
431 configFiles.value = res.files
432 configPath.value = res.main
433 } catch (e) {
434 notify((e as Error).message, 'error')
435 } finally {
436 configBusy.value = false
437 }
438}
439
440async function loadRewrite() {
441 try {
442 const res = await api.get<{ content: string }>(`api/v1/sites/${props.id}/rewrite`)
443 rewrite.value = res.content
444 } catch (e) {
445 notify((e as Error).message, 'error')
446 }
447}
448
449async function saveRewrite() {
450 rewriteBusy.value = true
451 try {
452 await api.put(`api/v1/sites/${props.id}/rewrite`, { content: rewrite.value })
453 notify('伪静态已保存,nginx 校验通过')
454 } catch (e) {
455 notify((e as Error).message, 'error')
456 } finally {
457 rewriteBusy.value = false
458 }
459}
460
461/* ---------------- lifecycle of the page ---------------- */
462const guard = () => !dirty.value || window.confirm('当前页面有未保存的修改,确定离开并丢弃?')
463
464watch(tab, (next) => {
465 if (next === 'logs') {
466 if (!logLines.value.length) void loadLogs()
467 syncLogTimer()
468 } else {
469 syncLogTimer()
470 }
471 if (next === 'ssl' && !ssl.value) void loadSSL()
472 if (next === 'config') {
473 if (!Object.keys(configFiles.value).length) void loadConfig()
474 if (!rewrite.value) void loadRewrite()
475 }
476})
477
478watch(logAuto, syncLogTimer)
479
480onMounted(async () => {
481 const initial = route.value.tab as Tab | undefined
482 if (initial && tabs.some((t) => t.value === initial)) tab.value = initial
483 setLeaveGuard(guard, () => dirty.value)
484 window.addEventListener('keydown', onKey)
485 await loadSite()
486 logType.value = isApp.value ? 'app' : 'access'
487 if (tab.value === 'ssl') void loadSSL()
488 if (tab.value === 'logs') void loadLogs()
489 if (tab.value === 'config') {
490 void loadConfig()
491 void loadRewrite()
492 }
493})
494
495onUnmounted(() => {
496 clearLeaveGuard(guard)
497 stopSSLClock()
498 if (logTimer !== undefined) window.clearInterval(logTimer)
499 window.removeEventListener('keydown', onKey)
500})
501
502function onKey(e: KeyboardEvent) {
503 if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 's') {
504 if (tab.value === 'runtime' || tab.value === 'security') {
505 e.preventDefault()
506 if (dirty.value) void save()
507 } else if (tab.value === 'config' && configView.value === 'rewrite') {
508 e.preventDefault()
509 void saveRewrite()
510 }
511 }
512}
513</script>
514
515<template>
516 <div class="card detail">
517 <div class="detail-head">
518 <button class="btn btn-ghost btn-sm" @click="navigate('sites')">← 网站列表</button>
519 <div class="detail-title">
520 <h2>{{ site?.name ?? '站点' }}</h2>
521 <div class="mono muted">{{ site?.domains.join(' ') }}</div>
522 </div>
523 <span class="badge" :class="live.cls">{{ live.text }}</span>
524 <div class="spacer"></div>
525 <button v-if="accessURL" class="btn btn-ghost btn-sm" @click="openSite">打开站点 ↗</button>
526 <button v-if="accessURL" class="btn btn-ghost btn-sm" @click="copy(accessURL, '访问地址已复制')">
527 复制地址
528 </button>
529 <button v-if="isApp" class="btn btn-ghost btn-sm" :disabled="lifeBusy" @click="life('restart')">
530 <span v-if="lifeBusy" class="spin"></span>
531 重启应用
532 </button>
533 </div>
534
535 <div class="tabs">
536 <button
537 v-for="item in tabs"
538 :key="item.value"
539 class="tab"
540 :class="{ active: tab === item.value }"
541 @click="setTab(item.value)"
542 >
543 {{ item.label }}
544 </button>
545 </div>
546
547 <div v-if="loading" class="empty">加载中…</div>
548
549 <template v-else-if="site">
550 <!-- overview -->
551 <div v-if="tab === 'overview'">
552 <div class="grid cols-2">
553 <dl class="kv">
554 <dt>类型</dt>
555 <dd>{{ kindLabel }}</dd>
556 <dt>状态</dt>
557 <dd>
558 <span class="badge" :class="live.cls">{{ live.text }}</span>
559 <span v-if="live.text === 'nginx 未安装'" class="hint">站点配置已写入,但 nginx 未安装,访问不会生效</span>
560 </dd>
561 <dt>网站目录</dt>
562 <dd class="mono">{{ site.root }}</dd>
563 <dt>访问端口</dt>
564 <dd class="mono">{{ site.options.listen_port || 80 }}</dd>
565 <template v-if="isApp">
566 <dt>应用端口</dt>
567 <dd class="mono">{{ site.port }}</dd>
568 <dt>上游地址</dt>
569 <dd class="mono">{{ site.upstream }}</dd>
570 </template>
571 <template v-if="site.kind === 'php'">
572 <dt>PHP 版本</dt>
573 <dd class="mono">{{ site.php_version }}</dd>
574 </template>
575 <dt>运行用户</dt>
576 <dd class="mono">{{ site.run_user }}</dd>
577 <dt>创建时间</dt>
578 <dd class="mono">{{ time(site.created_at) }}</dd>
579 </dl>
580
581 <div class="card inner">
582 <h3>常用操作</h3>
583 <div class="row action-stack">
584 <button
585 v-if="isApp && live.text !== '运行中'"
586 class="btn btn-primary btn-sm"
587 :disabled="lifeBusy"
588 @click="life('start')"
589 >
590 启动应用
591 </button>
592 <button
593 v-if="isApp && live.text === '运行中'"
594 class="btn btn-ghost btn-sm"
595 :disabled="lifeBusy"
596 @click="life('stop')"
597 >
598 停止应用
599 </button>
600 <button class="btn btn-ghost btn-sm" @click="setTab('logs')">查看日志</button>
601 <button class="btn btn-ghost btn-sm" @click="setTab('ssl')">
602 {{ site.ssl_enabled ? '管理证书' : '申请 HTTPS' }}
603 </button>
604 <button class="btn btn-ghost btn-sm" @click="setTab('runtime')">修改域名 / 目录</button>
605 <button class="btn btn-ghost btn-sm" @click="loadSite">刷新状态</button>
606 </div>
607 <p class="hint">
608 应用状态来自 systemd 实时查询;静态与 PHP 站点由 nginx 直接提供服务。
609 </p>
610 </div>
611 </div>
612
613 <div class="danger-zone">
614 <div>
615 <b>删除站点</b>
616 <p class="hint">删除配置、systemd 单元与证书;网站目录可选择是否一并删除。</p>
617 </div>
618 <button class="btn btn-danger btn-sm" @click="deleteError = ''; deleting = true">删除站点</button>
619 </div>
620 </div>
621
622 <!-- runtime + basic info -->
623 <div v-else-if="tab === 'runtime'" class="form-grid">
624 <label class="field full">
625 域名(每行一个,支持泛解析)
626 <textarea v-model="form.domainsText" class="textarea" style="min-height: 90px"></textarea>
627 <span class="tip">修改后立即重载 nginx;泛解析需要 DNS 侧支持。</span>
628 </label>
629
630 <label class="field full">
631 网站目录
632 <div class="input-group">
633 <input v-model="form.root" class="input mono" />
634 <button class="btn btn-ghost" type="button" @click="mobilePicker = true">浏览</button>
635 </div>
636 <span class="tip">必须位于面板的网站根目录内。</span>
637 </label>
638
639 <label v-if="site.kind === 'php'" class="field">
640 PHP 版本
641 <select v-model="form.php" class="select">
642 <option v-for="v in phpOptions" :key="v" :value="v">PHP {{ v }}</option>
643 </select>
644 </label>
645
646 <label v-if="isApp && site.kind !== 'proxy'" class="field">
647 应用端口
648 <input v-model.number="form.port" class="input" type="number" min="1" max="65535" />
649 <span class="tip">nginx 反代到 127.0.0.1:{{ form.port || '端口' }}。</span>
650 </label>
651
652 <label v-if="site.kind === 'proxy'" class="field full">
653 上游地址
654 <input v-model="form.upstream" class="input mono" placeholder="http://127.0.0.1:3000" />
655 </label>
656
657 <label class="field">
658 运行用户
659 <input v-model="form.runUser" class="input mono" :disabled="!isApp" />
660 </label>
661
662 <label class="field">
663 备注
664 <input v-model="form.remark" class="input" placeholder="可选" />
665 </label>
666
667 <label v-if="isApp" class="field full">
668 启动命令
669 <input v-model="form.startCmd" class="input mono" />
670 </label>
671
672 <label v-if="isApp" class="field full">
673 环境变量(每行 KEY=VALUE)
674 <textarea v-model="form.env" class="textarea" style="min-height: 80px"></textarea>
675 </label>
676
677 <div class="field full">
678 <span class="tip">
679 站点标识 <b class="mono">{{ site.name }}</b> 用于目录与 systemd 单元,创建后不可修改。
680 </span>
681 </div>
682 </div>
683
684 <!-- security -->
685 <div v-else-if="tab === 'security'">
686 <div class="form-grid">
687 <div class="full">
688 <h3 class="section-title">WAF 与限速</h3>
689 <div class="grid cols-2">
690 <label class="check">
691 <input v-model="options.waf" type="checkbox" />
692 启用 WAF(恶意 UA / 敏感路径 / 限速)
693 </label>
694 <label class="check">
695 <input v-model="options.security_headers" type="checkbox" />
696 注入安全响应头
697 </label>
698 <label class="field">
699 WAF 突发值(全局限速 20 请求/秒)
700 <input v-model.number="options.waf_burst" class="input" type="number" min="1" />
701 </label>
702 <label class="field">
703 单 IP 并发连接
704 <input v-model.number="options.conn_per_ip" class="input" type="number" min="0" />
705 </label>
706 <label class="field">
707 整站并发连接
708 <input v-model.number="options.conn_per_server" class="input" type="number" min="0" />
709 </label>
710 <label class="field">
711 单连接限速(KB/s,0 为不限)
712 <input v-model.number="options.limit_rate_kb" class="input" type="number" min="0" />
713 </label>
714 <label class="check" style="align-self: end">
715 <input v-model="options.anti_leech" type="checkbox" />
716 开启防盗链
717 </label>
718 </div>
719 </div>
720
721 <label class="field full">
722 防盗链允许的域名(留空使用站点域名)
723 <textarea v-model="refererText" class="textarea" style="min-height: 70px"></textarea>
724 </label>
725
726 <label class="field">
727 IP 访问控制
728 <select v-model="options.ip_mode" class="select">
729 <option value="">不限制</option>
730 <option value="allow">仅允许以下 IP</option>
731 <option value="deny">拒绝以下 IP</option>
732 </select>
733 </label>
734
735 <label class="field full">
736 IP 列表(支持 CIDR,每行一个)
737 <textarea v-model="ipText" class="textarea" style="min-height: 70px" placeholder="10.0.0.0/8"></textarea>
738 </label>
739
740 <label class="field full">
741 自定义 nginx 片段(追加到 server 块)
742 <textarea v-model="options.custom_nginx" class="textarea"></textarea>
743 </label>
744 </div>
745 </div>
746
747 <!-- ssl -->
748 <div v-else-if="tab === 'ssl'">
749 <div v-if="sslError" class="alert" style="margin-bottom: 12px">{{ sslError }}</div>
750 <div v-if="sslBusy" class="alert ok" style="margin-bottom: 12px">
751 <span class="spin"></span>
752 正在向 Let's Encrypt 申请证书(已等待 {{ sslElapsed }} 秒,通常 10–30 秒)。请勿关闭页面。
753 </div>
754
755 <template v-if="ssl">
756 <div class="row" style="margin-bottom: 12px">
757 <span class="badge" :class="ssl.enabled ? 'ok' : 'off'">
758 {{ ssl.enabled ? 'HTTPS 已启用' : 'HTTPS 未启用' }}
759 </span>
760 <span v-if="ssl.cert" class="badge" :class="ssl.cert.staging ? 'off' : 'ok'">
761 {{ ssl.cert.staging ? '测试证书' : '正式证书' }}
762 </span>
763 <span v-if="ssl.cert" class="muted">剩余 {{ ssl.days_left }} 天</span>
764 <span v-if="ssl.cert" class="muted">· 到期 {{ time(ssl.cert.not_after) }}</span>
765 </div>
766
767 <template v-if="ssl.cert">
768 <dl class="kv">
769 <dt>域名</dt>
770 <dd class="mono">{{ ssl.cert.domains.split(',').join(' ') }}</dd>
771 <dt>签发机构</dt>
772 <dd>{{ ssl.cert.issuer }}</dd>
773 <dt>生效时间</dt>
774 <dd class="mono">{{ time(ssl.cert.not_before) }}</dd>
775 <dt>自动续期</dt>
776 <dd>{{ ssl.cert.auto_renew ? '已开启(到期前 30 天自动续签)' : '已关闭' }}</dd>
777 </dl>
778
779 <div class="row" style="margin-top: 16px">
780 <button
781 v-if="!ssl.enabled"
782 class="btn btn-primary btn-sm"
783 :disabled="sslBusy"
784 @click="sslAction('enable')"
785 >
786 启用 HTTPS
787 </button>
788 <button v-else class="btn btn-ghost btn-sm" :disabled="sslBusy" @click="sslAction('disable')">
789 关闭 HTTPS
790 </button>
791 <button class="btn btn-ghost btn-sm" :disabled="sslBusy" @click="issueSSL(ssl.cert.staging)">
792 重新签发
793 </button>
794 <button v-if="ssl.cert.staging" class="btn btn-primary btn-sm" :disabled="sslBusy" @click="issueSSL(false)">
795 换取正式证书
796 </button>
797 </div>
798 </template>
799
800 <template v-else>
801 <p class="hint">将为此站点的全部域名申请一张 Let's Encrypt 证书。签发前请确认:</p>
802 <ul class="ssl-hint">
803 <li>域名已添加 A / AAAA 记录指向本机</li>
804 <li>服务器 80 端口可从公网访问(HTTP-01 验证)</li>
805 <li>泛解析(*.example.com)暂不支持,请填写具体子域名</li>
806 </ul>
807 <div class="ssl-dns">
808 <div v-for="(ok, domain) in ssl.dns" :key="domain" class="dns-row">
809 <span class="badge" :class="ok ? 'ok' : 'err'">{{ ok ? '解析正常' : '未解析' }}</span>
810 <span class="mono">{{ domain }}</span>
811 </div>
812 </div>
813 <div class="row" style="margin-top: 16px">
814 <button class="btn btn-primary" :disabled="sslBusy" @click="issueSSL(false)">申请证书</button>
815 <button class="btn btn-ghost" :disabled="sslBusy" @click="issueSSL(true)">申请测试证书</button>
816 </div>
817 </template>
818 </template>
819 <div v-else class="empty">加载中…</div>
820 </div>
821
822 <!-- logs -->
823 <div v-else-if="tab === 'logs'">
824 <div class="row log-toolbar">
825 <select v-model="logType" class="select" style="width: 150px" @change="loadLogs">
826 <option value="access">访问日志</option>
827 <option value="error">错误日志</option>
828 <option v-if="isApp" value="app">应用日志</option>
829 </select>
830 <select v-model.number="logCount" class="select" style="width: 120px" @change="loadLogs">
831 <option :value="300">最近 300 行</option>
832 <option :value="500">最近 500 行</option>
833 <option :value="1000">最近 1000 行</option>
834 </select>
835 <label class="check"><input v-model="logAuto" type="checkbox" /> 自动刷新</label>
836 <label class="check"><input v-model="logFollow" type="checkbox" /> 跟随最新</label>
837 <div class="spacer"></div>
838 <button class="btn btn-ghost btn-sm" :disabled="logBusy" @click="loadLogs">
839 <span v-if="logBusy" class="spin"></span>
840 刷新
841 </button>
842 <button
843 class="btn btn-ghost btn-sm"
844 :disabled="!logLines.length"
845 @click="copy(logLines.join('\n'), '日志已复制')"
846 >
847 复制
848 </button>
849 </div>
850 <p class="hint log-meta">
851 {{ logLines.length }} 行
852 <span v-if="logUpdated"> · 更新于 {{ time(logUpdated) }}</span>
853 </p>
854 <pre ref="logBox" class="log">{{ logLines.join('\n') || '暂无日志' }}</pre>
855 </div>
856
857 <!-- config -->
858 <div v-else class="config-tab">
859 <div class="row" style="margin-bottom: 12px">
860 <div class="seg">
861 <button :class="{ active: configView === 'files' }" @click="configView = 'files'">只读配置</button>
862 <button :class="{ active: configView === 'rewrite' }" @click="configView = 'rewrite'">伪静态</button>
863 </div>
864 <div class="spacer"></div>
865 <button v-if="configView === 'files'" class="btn btn-ghost btn-sm" :disabled="configBusy" @click="loadConfig">
866 刷新
867 </button>
868 </div>
869
870 <template v-if="configView === 'files'">
871 <p class="hint">配置由面板生成,手动修改会在下次保存时被覆盖;如需扩展请用「安全与性能」中的自定义片段。</p>
872 <div class="file-list">
873 <button
874 v-for="(_, path) in configFiles"
875 :key="path"
876 :class="{ active: configPath === String(path) }"
877 @click="configPath = String(path)"
878 >
879 {{ String(path).split('/').pop() }}
880 </button>
881 </div>
882 <pre class="code">{{ configFiles[configPath] || '选择上方文件查看内容' }}</pre>
883 </template>
884
885 <template v-else>
886 <p class="hint">伪静态规则写入 rewrite 片段,保存前会执行 nginx -t 校验,失败自动回滚。</p>
887 <textarea v-model="rewrite" class="textarea mono" style="min-height: 320px"></textarea>
888 <div class="row end" style="margin-top: 12px">
889 <button class="btn btn-primary" :disabled="rewriteBusy" @click="saveRewrite">
890 <span v-if="rewriteBusy" class="spin"></span>
891 保存伪静态
892 </button>
893 </div>
894 </template>
895 </div>
896 </template>
897
898 <div
899 v-if="(tab === 'runtime' || tab === 'security') && site"
900 class="save-bar"
901 :class="{ dirty }"
902 >
903 <span v-if="dirty" class="save-state"><b>未保存</b> · Ctrl/⌘ + S 快速保存</span>
904 <span v-else class="save-state">所有修改已保存</span>
905 <div class="spacer"></div>
906 <button class="btn btn-ghost btn-sm" :disabled="!dirty || saving" @click="resetForm">撤销修改</button>
907 <button class="btn btn-primary btn-sm" :disabled="!dirty || saving" @click="save">
908 <span v-if="saving" class="spin"></span>
909 保存并重载
910 </button>
911 </div>
912
913 <DirPicker
914 v-if="mobilePicker"
915 title="选择网站目录"
916 :initial="form.root || '/'"
917 select-label="使用此目录"
918 @close="mobilePicker = false"
919 @select="chooseRoot"
920 />
921
922 <ConfirmDialog
923 v-if="deleting && site"
924 :title="`删除站点 ${site.name}`"
925 message="删除后 nginx 配置、systemd 单元和证书记录都会被移除,操作不可撤销。"
926 confirm-text="删除站点"
927 danger
928 :options="[
929 { value: 'keep', label: '仅删除站点配置', description: '网站目录与文件完整保留' },
930 {
931 value: 'remove',
932 label: '同时删除网站目录',
933 description: '目录内容将被永久删除,无法恢复',
934 danger: true,
935 },
936 ]"
937 :require-text-map="{ remove: site.name }"
938 :busy="deleteBusy"
939 :error="deleteError"
940 @close="deleting = false"
941 @confirm="confirmDelete"
942 />
943 </div>
944</template>
945
946<style scoped>
947.detail {
948 display: flex;
949 flex-direction: column;
950 gap: 4px;
951}
952.detail-head {
953 display: flex;
954 align-items: center;
955 gap: 10px;
956 flex-wrap: wrap;
957 margin-bottom: 6px;
958}
959.detail-title h2 {
960 margin: 0;
961 font-size: 18px;
962}
963.detail-title .mono {
964 font-size: 11.5px;
965}
966.tabs {
967 position: sticky;
968 top: 66px;
969 z-index: 4;
970 background: #fff;
971 padding-top: 4px;
972}
973.inner {
974 background: #fbfefd;
975 box-shadow: none;
976}
977.action-stack {
978 flex-wrap: wrap;
979 gap: 8px;
980 margin-bottom: 8px;
981}
982.danger-zone {
983 display: flex;
984 align-items: center;
985 justify-content: space-between;
986 gap: 16px;
987 margin-top: 18px;
988 padding: 14px 16px;
989 border: 1px solid #fecaca;
990 border-radius: 12px;
991 background: #fffafa;
992 flex-wrap: wrap;
993}
994.danger-zone p {
995 margin: 4px 0 0;
996}
997.section-title {
998 margin: 4px 0 10px;
999 font-size: 14px;
1000}
1001.tip {
1002 color: var(--muted);
1003 font-size: 12px;
1004}
1005.save-bar {
1006 position: sticky;
1007 bottom: 12px;
1008 display: flex;
1009 align-items: center;
1010 gap: 10px;
1011 margin-top: 18px;
1012 padding: 10px 14px;
1013 border-radius: 12px;
1014 border: 1px solid var(--line);
1015 background: rgba(251, 254, 253, 0.96);
1016 backdrop-filter: blur(8px);
1017 box-shadow: 0 10px 30px rgba(23, 58, 67, 0.1);
1018}
1019.save-bar.dirty {
1020 border-color: rgba(245, 158, 11, 0.5);
1021 background: #fffdf5;
1022}
1023.save-state {
1024 font-size: 12.5px;
1025 color: var(--muted);
1026}
1027.log-toolbar {
1028 gap: 10px;
1029 flex-wrap: wrap;
1030 margin-bottom: 8px;
1031}
1032.log-meta {
1033 margin: 0 0 8px;
1034}
1035.config-tab .file-list {
1036 margin-top: 10px;
1037}
1038.seg {
1039 display: inline-flex;
1040 padding: 3px;
1041 border-radius: 10px;
1042 background: #f1f9f8;
1043}
1044.seg button {
1045 border: none;
1046 background: none;
1047 padding: 6px 12px;
1048 border-radius: 8px;
1049 cursor: pointer;
1050 font: inherit;
1051 color: var(--muted);
1052}
1053.seg button.active {
1054 background: #fff;
1055 color: #0f766e;
1056 font-weight: 600;
1057 box-shadow: 0 1px 6px rgba(23, 58, 67, 0.1);
1058}
1059@media (max-width: 720px) {
1060 .tabs {
1061 top: 0;
1062 }
1063 .detail-head {
1064 gap: 6px;
1065 }
1066}
1067</style>