完善证书申请续期与安装初始化流程

This commit is contained in:
xuans committed 2026-08-27 00:31:40 +08:00
1 parent fd8d8608f5
commit 07636abe44
66 files changed
+9470 -165

No files matched your search

+1
View File
@@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/png" href="/Scert.png" />
<title>Scert SSL 证书管理</title>
</head>
<body>
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

+221 -17
View File
@@ -1,19 +1,157 @@
<script setup>
import { onMounted, ref } from 'vue'
import { computed, onMounted, ref } from 'vue'
import SetupWizard from './components/SetupWizard.vue'
const scertLogo = '/Scert.png'
const status = ref(null)
const setupState = ref(null)
const bootstrapping = ref(true)
const domains = ref([])
const loading = ref(true)
const saving = ref(false)
const error = ref('')
const notice = ref('')
const formError = ref('')
const showForm = ref(false)
const editingId = ref('')
const certificateTypeLabels = { single: '单域名', wildcard: '泛域名', san: 'SAN 多域名' }
const domainStatusLabels = { pending: '等待处理', active: '正常', error: '错误' }
const domainStatusLabels = { pending: '等待申请', active: '正常', error: '错误' }
const httpsModeLabels = { direct: '核心服务 HTTPS', proxy: '反向代理 HTTPS' }
const environmentLabels = { staging: '测试环境', production: '生产环境' }
const dnsProviders = [
{ value: 'cloudflare', label: 'Cloudflare' },
{ value: 'aliyun', label: '阿里云 DNS' },
{ value: 'dnspod', label: 'DNSPod' },
{ value: 'cname', label: 'CNAME 委派' },
{ value: 'huaweicloud', label: '华为云' },
{ value: 'tencentcloud', label: '腾讯云' },
{ value: 'route53', label: 'AWS Route 53' },
{ value: 'googlecloud', label: 'Google Cloud DNS' },
{ value: 'other', label: '其他服务商' },
]
const isEditing = computed(() => Boolean(editingId.value))
const formTitle = computed(() => (isEditing.value ? '编辑域名配置' : '添加托管域名'))
const form = ref(createEmptyForm())
function createEmptyForm() {
return {
name: '',
certificate_type: 'single',
sans: '',
auto_renew: true,
acme_environment: 'staging',
dns_provider: '',
}
}
function displayLabel(labels, value) {
return labels[value] || (value ? '未知' : '—')
}
function formatDate(value) {
if (!value) return '尚未签发'
return new Intl.DateTimeFormat('zh-CN', { dateStyle: 'medium', timeZone: 'Asia/Shanghai' }).format(new Date(value))
}
function daysRemaining(value) {
if (!value) return '待申请'
const days = Math.ceil((new Date(value).getTime() - Date.now()) / 86400000)
return days >= 0 ? `剩余 ${days} 天` : `已过期 ${Math.abs(days)} 天`
}
function statusClass(value) {
return value === 'active' ? 'success' : value === 'error' ? 'danger' : 'warning'
}
function openCreate() {
editingId.value = ''
form.value = createEmptyForm()
formError.value = ''
showForm.value = true
}
function openEdit(item) {
editingId.value = item.id
form.value = {
name: item.name,
certificate_type: item.certificate_type,
sans: (item.sans || []).filter((name) => name !== item.name).join('\n'),
auto_renew: item.auto_renew !== false,
acme_environment: item.acme_environment || 'staging',
dns_provider: item.dns_provider || '',
}
formError.value = ''
showForm.value = true
}
function closeForm() {
if (!saving.value) showForm.value = false
}
function parseSANs(value) {
return value.split(/[\n,,]/).map((item) => item.trim()).filter(Boolean)
}
async function saveDomain() {
formError.value = ''
notice.value = ''
if (!form.value.name.trim()) {
formError.value = '请输入主域名'
return
}
if (form.value.certificate_type === 'san' && parseSANs(form.value.sans).length === 0) {
formError.value = 'SAN 证书至少需要填写一个附加域名'
return
}
saving.value = true
try {
const payload = {
name: form.value.name,
certificate_type: form.value.certificate_type,
sans: parseSANs(form.value.sans),
auto_renew: form.value.auto_renew,
acme_environment: form.value.acme_environment,
dns_provider: form.value.dns_provider,
}
const path = isEditing.value ? `/api/v1/domains/${editingId.value}` : '/api/v1/domains'
const response = await fetch(path, {
method: isEditing.value ? 'PUT' : 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
})
const result = await response.json().catch(() => ({}))
if (!response.ok) throw new Error(result.error || '保存域名失败')
showForm.value = false
notice.value = isEditing.value ? '域名配置已更新' : '域名已添加,等待申请证书'
await loadData()
} catch (err) {
formError.value = err.message || '保存域名失败'
} finally {
saving.value = false
}
}
async function deleteDomain(item) {
if (!window.confirm(`确定删除域名“${item.name}”吗?删除前请确认没有正在执行的任务。`)) return
error.value = ''
notice.value = ''
try {
const response = await fetch(`/api/v1/domains/${item.id}`, { method: 'DELETE' })
if (!response.ok) {
const result = await response.json().catch(() => ({}))
throw new Error(result.error || '删除域名失败')
}
notice.value = '域名已删除'
await loadData()
} catch (err) {
error.value = err.message || '删除域名失败'
}
}
async function loadData() {
loading.value = true
error.value = ''
@@ -26,23 +164,54 @@ async function loadData() {
status.value = await statusResponse.json()
domains.value = (await domainResponse.json()).items || []
} catch {
error.value = '无法连接核心服务'
error.value = '无法连接核心服务,请先启动 scert serve'
} finally {
loading.value = false
}
}
onMounted(loadData)
async function bootstrap() {
bootstrapping.value = true
error.value = ''
try {
const response = await fetch('/api/v1/setup/status')
const result = await response.json().catch(() => ({}))
if (!response.ok) throw new Error(result.error || '读取初始化状态失败')
setupState.value = result
if (result.initialized) await loadData()
} catch (err) {
error.value = err.message || '无法连接核心服务,请先启动 scert serve'
} finally {
bootstrapping.value = false
}
}
async function handleInitialized(result) {
setupState.value = { ...setupState.value, initialized: true }
notice.value = result.message || '初始化配置已保存,请重启服务。'
await loadData()
}
onMounted(bootstrap)
</script>
<template>
<main class="page-shell">
<main v-if="bootstrapping" class="bootstrap-screen">
<img class="bootstrap-mark" :src="scertLogo" alt="Scert 标志" />
<strong>正在检查 Scert 初始化状态……</strong>
<p v-if="error">{{ error }}</p>
</main>
<SetupWizard v-else-if="setupState && !setupState.initialized" :status="setupState" @initialized="handleInitialized" />
<main v-else class="page-shell">
<header class="topbar">
<div>
<p class="eyebrow">SCERT / SSL 证书管理</p>
<h1>证书管理总览</h1>
</div>
<button class="secondary-button" type="button" @click="loadData">刷新状态</button>
<div class="topbar-actions">
<button class="secondary-button" type="button" @click="loadData">刷新状态</button>
<button class="primary-button" type="button" @click="openCreate">添加域名</button>
</div>
</header>
<section class="hero-card">
@@ -50,30 +219,65 @@ onMounted(loadData)
<span class="status-dot" :class="{ online: status }"></span>
<span class="status-label">{{ status ? '核心服务运行中' : '等待连接核心服务' }}</span>
<h2>让证书续期和部署变得可追踪</h2>
<p>首轮界面展示服务状态和托管域名,后续将接入 ACME、DNS 验证与远程部署流程。</p>
<p>统一管理单域名、泛域名和 SAN 证书,后续将接入 lego、DNS 验证与远程部署流程。</p>
</div>
<div class="hero-mark">S</div>
<img class="hero-mark" :src="scertLogo" alt="Scert 标志" />
</section>
<p v-if="error" class="error-banner">{{ error }}。请先执行 <code>scert serve</code>。</p>
<p v-if="error" class="error-banner">{{ error }}</p>
<p v-if="notice" class="notice-banner">{{ notice }}</p>
<section class="metrics-grid">
<article class="metric-card"><span>服务版本</span><strong>{{ status?.version || '—' }}</strong></article>
<article class="metric-card"><span>数据库</span><strong>{{ displayLabel({ sqlite: 'SQLite', mysql: 'MySQL' }, status?.database_driver) || '—' }}</strong></article>
<article class="metric-card"><span>HTTPS 模式</span><strong>{{ displayLabel(httpsModeLabels, status?.https_mode) || '—' }}</strong></article>
<article class="metric-card"><span>数据库</span><strong>{{ displayLabel({ sqlite: 'SQLite', mysql: 'MySQL' }, status?.database_driver) }}</strong></article>
<article class="metric-card"><span>HTTPS 模式</span><strong>{{ displayLabel(httpsModeLabels, status?.https_mode) }}</strong></article>
<article class="metric-card"><span>托管域名</span><strong>{{ domains.length }}</strong></article>
</section>
<section class="panel">
<div class="panel-heading"><div><p class="eyebrow">域名列表</p><h2>托管域名</h2></div><span class="muted">首轮占位视图</span></div>
<div class="panel-heading">
<div><p class="eyebrow">域名配置</p><h2>托管域名</h2></div>
<span class="muted">共 {{ domains.length }} 个配置</span>
</div>
<div v-if="loading" class="empty-state">正在读取域名状态……</div>
<div v-else-if="domains.length === 0" class="empty-state">暂未添加托管域名,请通过 CLI 执行 <code>scert domain add</code>。</div>
<div v-else-if="domains.length === 0" class="empty-state">
<strong>还没有托管域名</strong>
<span>添加第一个域名,开始管理证书申请和自动续期。</span>
<button class="primary-button" type="button" @click="openCreate">添加托管域名</button>
</div>
<div v-else class="domain-list">
<div v-for="item in domains" :key="item.id" class="domain-row">
<div><strong>{{ item.name }}</strong><span>{{ displayLabel(certificateTypeLabels, item.certificate_type) }} · {{ displayLabel(domainStatusLabels, item.status) }}</span></div>
<span class="tag">待处理</span>
</div>
<article v-for="item in domains" :key="item.id" class="domain-row">
<div class="domain-main">
<div class="domain-title-line"><strong>{{ item.name }}</strong><span class="tag" :class="statusClass(item.status)">{{ displayLabel(domainStatusLabels, item.status) }}</span></div>
<div class="domain-meta">
<span>{{ displayLabel(certificateTypeLabels, item.certificate_type) }}</span>
<span>{{ displayLabel(environmentLabels, item.acme_environment) }}</span>
<span>{{ item.auto_renew ? '自动续期已开启' : '自动续期已关闭' }}</span>
<span>{{ (item.sans || []).length }} 个证书标识</span>
</div>
</div>
<div class="domain-expiry"><strong>{{ daysRemaining(item.expires_at) }}</strong><span>{{ formatDate(item.expires_at) }}</span></div>
<div class="row-actions"><button class="text-button" type="button" @click="openEdit(item)">编辑</button><button class="text-button danger-text" type="button" @click="deleteDomain(item)">删除</button></div>
</article>
</div>
</section>
<div v-if="showForm" class="modal-backdrop" @click.self="closeForm">
<section class="modal-card" role="dialog" aria-modal="true" :aria-label="formTitle">
<div class="modal-heading"><div><p class="eyebrow">域名配置</p><h2>{{ formTitle }}</h2></div><button class="close-button" type="button" aria-label="关闭" @click="closeForm">×</button></div>
<form @submit.prevent="saveDomain">
<label class="field" for="domain-name"><span>主域名</span><input id="domain-name" name="name" v-model="form.name" type="text" placeholder="例如 example.com" autocomplete="off" /></label>
<label class="field" for="certificate-type"><span>证书类型</span><select id="certificate-type" name="certificate_type" v-model="form.certificate_type"><option value="single">单域名</option><option value="wildcard">泛域名</option><option value="san">SAN 多域名</option></select></label>
<label v-if="form.certificate_type === 'san'" class="field" for="domain-sans"><span>附加域名 <small>每行一个,也支持逗号分隔</small></span><textarea id="domain-sans" name="sans" v-model="form.sans" rows="4" placeholder="www.example.com&#10;api.example.com"></textarea></label>
<div class="form-grid">
<label class="field" for="acme-environment"><span>ACME 环境</span><select id="acme-environment" name="acme_environment" v-model="form.acme_environment"><option value="staging">测试环境</option><option value="production">生产环境</option></select></label>
<label class="field" for="dns-provider"><span>DNS 验证服务商</span><select id="dns-provider" name="dns_provider" v-model="form.dns_provider"><option value="">暂不选择</option><option v-for="provider in dnsProviders" :key="provider.value" :value="provider.value">{{ provider.label }}</option></select></label>
</div>
<label class="switch-field" for="auto-renew"><input id="auto-renew" name="auto_renew" v-model="form.auto_renew" type="checkbox" /><span><strong>启用自动续期</strong><small>证书剩余有效期达到阈值时自动创建续期任务</small></span></label>
<p v-if="formError" class="form-error">{{ formError }}</p>
<div class="modal-actions"><button class="secondary-button" type="button" :disabled="saving" @click="closeForm">取消</button><button class="primary-button" type="submit" :disabled="saving">{{ saving ? '保存中……' : '保存配置' }}</button></div>
</form>
</section>
</div>
</main>
</template>
+366
View File
@@ -0,0 +1,366 @@
<script setup>
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
const scertLogo = '/Scert.png'
const props = defineProps({ status: { type: Object, required: true } })
const emit = defineEmits(['initialized'])
const submitting = ref(false)
const error = ref('')
const resultMessage = ref('')
const dnsCatalogLoading = ref(true)
const dnsCatalogError = ref('')
const dnsTesting = ref(false)
const dnsTestError = ref('')
const dnsProviders = ref([])
const dnsCredentials = ref({})
const dnsTestDomain = ref(props.status.web_hostname || '')
const dnsVerification = ref(null)
const verificationClock = ref(Date.now())
let verificationTimer
const targetType = ref(props.status.web_public_ip ? 'ip' : 'hostname')
const form = ref({
admin_username: '',
admin_password: '',
confirm_password: '',
server_port: props.status.server_port || 8080,
reset_service_port: props.status.reset_service_port || 8091,
email_provider: '',
email_endpoint: '',
recipients: '',
dns_provider: props.status.dns_provider || 'cloudflare',
certificate_root: props.status.certificate_root || '',
web_hostname: props.status.web_hostname || '',
web_public_ip: props.status.web_public_ip || '',
web_enabled: props.status.web_enabled !== false,
https_mode: props.status.https_mode || 'direct',
})
const targetLabel = computed(() => (targetType.value === 'hostname' ? 'Web 管理域名' : '公网 IP 地址'))
const selectedDNSProvider = computed(() => dnsProviders.value.find((provider) => provider.id === form.value.dns_provider) || null)
const dnsVerificationValid = computed(() => {
verificationClock.value
if (!dnsVerification.value?.verification_token || !dnsVerification.value?.credential_ref) return false
return new Date(dnsVerification.value.expires_at).getTime() > Date.now()
})
function invalidateDNSVerification() {
dnsVerification.value = null
dnsTestError.value = ''
}
function formatVerificationExpiry(value) {
if (!value) return ''
return new Intl.DateTimeFormat('zh-CN', {
dateStyle: 'medium',
timeStyle: 'medium',
timeZone: 'Asia/Shanghai',
}).format(new Date(value))
}
async function loadDNSProviders() {
dnsCatalogLoading.value = true
dnsCatalogError.value = ''
try {
const response = await fetch('/api/v1/setup/dns/providers')
const result = await response.json().catch(() => ({}))
if (!response.ok) throw new Error(result.error || '读取 DNS 服务商列表失败')
dnsProviders.value = Array.isArray(result.items) ? result.items : []
if (!dnsProviders.value.some((provider) => provider.id === form.value.dns_provider)) {
form.value.dns_provider = dnsProviders.value.find((provider) => provider.available)?.id || ''
}
} catch (err) {
dnsCatalogError.value = err.message || '读取 DNS 服务商列表失败'
} finally {
dnsCatalogLoading.value = false
}
}
function credentialPayload() {
const payload = {}
for (const field of selectedDNSProvider.value?.credential_fields || []) {
const value = String(dnsCredentials.value[field.name] || '').trim()
if (value) payload[field.name] = value
}
return payload
}
async function testDNS() {
dnsTestError.value = ''
resultMessage.value = ''
invalidateDNSVerification()
const provider = selectedDNSProvider.value
if (!provider) {
dnsTestError.value = '请选择 DNS 服务商。'
return
}
if (!provider.available) {
dnsTestError.value = '该 DNS 服务商在线验证适配器尚未开放。'
return
}
const testDomain = dnsTestDomain.value.trim()
if (!testDomain) {
dnsTestError.value = '请填写 DNS 权限测试域名。'
return
}
for (const field of provider.credential_fields || []) {
if (field.required && !String(dnsCredentials.value[field.name] || '').trim()) {
dnsTestError.value = `请填写${field.label}。`
return
}
}
dnsTesting.value = true
try {
const response = await fetch('/api/v1/setup/dns/test', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
provider: provider.id,
test_domain: testDomain,
credentials: credentialPayload(),
}),
})
const result = await response.json().catch(() => ({}))
if (!response.ok) throw new Error(result.error || 'DNS API 在线验证失败')
dnsVerification.value = result
} catch (err) {
dnsTestError.value = err.message || 'DNS API 在线验证失败'
} finally {
dnsTesting.value = false
}
}
function recipients() {
return form.value.recipients.split(/[\n,,]/).map((item) => item.trim()).filter(Boolean)
}
async function submit() {
error.value = ''
resultMessage.value = ''
if (form.value.admin_password.length < 8) {
error.value = '超级管理员密码至少需要 8 个字符。'
return
}
if (form.value.admin_password !== form.value.confirm_password) {
error.value = '两次输入的超级管理员密码不一致。'
return
}
if (Number(form.value.server_port) === Number(form.value.reset_service_port)) {
error.value = '主服务端口与密码重置服务端口不能相同。'
return
}
if (!dnsVerificationValid.value) {
error.value = '必须先完成 DNS API 在线验证;验证结果已过期时请重新测试。'
return
}
const hostname = targetType.value === 'hostname' ? form.value.web_hostname.trim() : ''
const publicIP = targetType.value === 'ip' ? form.value.web_public_ip.trim() : ''
if (!hostname && !publicIP) {
error.value = `请填写${targetLabel.value}。`
return
}
submitting.value = true
try {
const response = await fetch('/api/v1/setup', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
admin_username: form.value.admin_username,
admin_password: form.value.admin_password,
server_port: Number(form.value.server_port),
reset_service_port: Number(form.value.reset_service_port),
email_provider: form.value.email_provider,
email_endpoint: form.value.email_endpoint,
recipients: recipients(),
dns_provider: form.value.dns_provider,
dns_credential_ref: dnsVerification.value.credential_ref,
dns_verification_token: dnsVerification.value.verification_token,
dns_test_domain: dnsTestDomain.value.trim(),
certificate_root: form.value.certificate_root,
web_hostname: hostname,
web_public_ip: publicIP,
web_enabled: form.value.web_enabled,
https_mode: form.value.https_mode,
}),
})
const result = await response.json().catch(() => ({}))
if (!response.ok) throw new Error(result.error || '保存初始化配置失败')
resultMessage.value = result.message || '初始化配置已保存。'
emit('initialized', result)
} catch (err) {
error.value = err.message || '保存初始化配置失败'
} finally {
submitting.value = false
}
}
watch(() => form.value.dns_provider, () => {
dnsCredentials.value = {}
invalidateDNSVerification()
})
watch(dnsCredentials, invalidateDNSVerification, { deep: true })
watch(dnsTestDomain, invalidateDNSVerification)
onMounted(() => {
loadDNSProviders()
verificationTimer = window.setInterval(() => { verificationClock.value = Date.now() }, 30000)
})
onUnmounted(() => {
if (verificationTimer) window.clearInterval(verificationTimer)
})
</script>
<template>
<main class="setup-shell">
<section class="setup-intro">
<img class="brand-mark" :src="scertLogo" alt="Scert 标志" />
<p class="setup-eyebrow">SCERT 首次运行</p>
<h1>配置证书管理服务</h1>
<p>Scert 与 Scert-admin 将共享本次配置。初始化接口仅允许从本机访问,完成后请重启服务。</p>
<div class="service-summary">
<span><strong>Scert</strong> 证书管理与 Web 服务</span>
<span><strong>Scert-admin</strong> 超级管理员密码重置</span>
</div>
<div class="warning-card">
<strong>当前开发阶段说明</strong>
<span>DNS API 在线测试与凭据加密存储已经接入;go-acme/lego 证书签发和 HTTPS 切换仍在后续任务中,本页不会伪报证书申请成功。</span>
</div>
</section>
<section class="setup-card">
<header>
<div><p class="setup-eyebrow">初始化向导</p><h2>基础配置</h2></div>
<span class="local-badge">仅限本机</span>
</header>
<form id="setup-form" name="setup_form" @submit.prevent="submit">
<fieldset>
<legend><span>01</span>超级管理员</legend>
<div class="setup-grid three-columns">
<label><span>用户名</span><input id="admin-username" name="admin_username" v-model.trim="form.admin_username" required autocomplete="username" placeholder="例如 scert-admin" /></label>
<label><span>密码</span><input id="admin-password" name="admin_password" v-model="form.admin_password" required minlength="8" type="password" autocomplete="new-password" placeholder="至少 8 个字符" /></label>
<label><span>确认密码</span><input id="confirm-password" name="confirm_password" v-model="form.confirm_password" required minlength="8" type="password" autocomplete="new-password" placeholder="再次输入密码" /></label>
</div>
</fieldset>
<fieldset>
<legend><span>02</span>服务与通知</legend>
<div class="setup-grid two-columns">
<label><span>Scert 主服务端口</span><input id="server-port" name="server_port" v-model.number="form.server_port" required min="1" max="65535" type="number" /></label>
<label><span>Scert-admin 重置端口</span><input id="reset-service-port" name="reset_service_port" v-model.number="form.reset_service_port" required min="1" max="65535" type="number" /></label>
<label><span>第三方邮箱服务标识</span><input id="email-provider" name="email_provider" v-model.trim="form.email_provider" placeholder="例如 company-mail-api" /></label>
<label><span>邮件 API 地址</span><input id="email-endpoint" name="email_endpoint" v-model.trim="form.email_endpoint" type="url" placeholder="https://mail.example.com/send" /></label>
</div>
<label><span>通知收件人</span><input id="recipients" name="recipients" v-model="form.recipients" placeholder="多个地址使用逗号分隔" /></label>
</fieldset>
<fieldset>
<legend><span>03</span>DNS 验证</legend>
<div class="setup-grid two-columns">
<label><span>DNS 服务商</span><select id="dns-provider" name="dns_provider" v-model="form.dns_provider" required :disabled="dnsCatalogLoading"><option v-if="dnsCatalogLoading" value="">正在读取服务商……</option><option v-for="provider in dnsProviders" :key="provider.id" :value="provider.id">{{ provider.name }}{{ provider.available ? '' : '(适配器待开放)' }}</option></select></label>
<label><span>DNS 权限测试域名</span><input id="dns-test-domain" name="dns_test_domain" v-model.trim="dnsTestDomain" required placeholder="例如 example.com" /><small>使用域名时可填写 Web 管理域名;使用公网 IP 时必须另填一个由当前 DNS 账号管理的域名。</small></label>
</div>
<p v-if="dnsCatalogError" class="inline-error">{{ dnsCatalogError }}</p>
<div v-if="selectedDNSProvider" class="provider-description" :class="{ unavailable: !selectedDNSProvider.available }">
<strong>{{ selectedDNSProvider.available ? '在线验证可用' : '当前仅提供字段模型' }}</strong>
<span>{{ selectedDNSProvider.description }}</span>
</div>
<div v-if="selectedDNSProvider" class="setup-grid two-columns credential-grid">
<label v-for="field in selectedDNSProvider.credential_fields" :key="field.name">
<span>{{ field.label }}{{ field.required ? '(必填)' : '(可选)' }}</span>
<textarea v-if="field.name.includes('json')" :id="`dns-credential-${field.name}`" :name="`dns_credential_${field.name}`" v-model="dnsCredentials[field.name]" :required="field.required" :placeholder="field.placeholder" rows="4" autocomplete="off"></textarea>
<input v-else :id="`dns-credential-${field.name}`" :name="`dns_credential_${field.name}`" v-model="dnsCredentials[field.name]" :required="field.required" :type="field.secret ? 'password' : 'text'" :placeholder="field.placeholder" autocomplete="off" />
</label>
</div>
<div class="dns-test-actions">
<button class="dns-test-button" type="button" :disabled="dnsTesting || dnsCatalogLoading || !selectedDNSProvider?.available" @click="testDNS">{{ dnsTesting ? '正在创建并清理测试记录……' : '测试 DNS API' }}</button>
<span>测试会临时创建 DNS-01 TXT 记录并自动清理,明文凭据不会写入普通配置文件。</span>
</div>
<p v-if="dnsTestError" class="inline-error">{{ dnsTestError }}</p>
<div v-if="dnsVerificationValid" class="dns-verification-success">
<strong>DNS API 在线验证通过</strong>
<span>凭据已加密保存,本次验证结果有效至 {{ formatVerificationExpiry(dnsVerification.expires_at) }}。修改服务商、测试域名或凭据后需要重新测试。</span>
</div>
</fieldset>
<fieldset>
<legend><span>04</span>Web 与证书目录</legend>
<div class="target-switch"><button type="button" :class="{ active: targetType === 'hostname' }" @click="targetType = 'hostname'">使用域名</button><button type="button" :class="{ active: targetType === 'ip' }" @click="targetType = 'ip'">使用公网 IP</button></div>
<div class="setup-grid two-columns">
<label v-if="targetType === 'hostname'"><span>Web 管理域名</span><input id="web-hostname" name="web_hostname" v-model.trim="form.web_hostname" required placeholder="scert.example.com" /></label>
<label v-else><span>公网 IP 地址</span><input id="web-public-ip" name="web_public_ip" v-model.trim="form.web_public_ip" required placeholder="203.0.113.10" /></label>
<label><span>证书部署根目录</span><input id="certificate-root" name="certificate_root" v-model.trim="form.certificate_root" required /></label>
<label><span>HTTPS 模式</span><select id="https-mode" name="https_mode" v-model="form.https_mode"><option value="direct">默认:核心服务直接终止 HTTPS</option><option value="proxy">高级:Nginx/Caddy 终止公网 HTTPS</option></select></label>
</div>
<label class="confirm-row"><input id="web-enabled" name="web_enabled" v-model="form.web_enabled" type="checkbox" /><span><strong>初始化完成后开启 Web 页面</strong><small>桌面端可通过此开关决定是否启用浏览器管理页面。</small></span></label>
</fieldset>
<p v-if="error" class="setup-error">{{ error }}</p>
<p v-if="resultMessage" class="setup-success">{{ resultMessage }}</p>
<footer><span>初始化程序将自动配置本机防火墙;云安全组仍需放行主服务端口。Scert-admin 只允许本机访问。</span><button type="submit" :disabled="submitting || dnsTesting">{{ submitting ? '正在保存……' : '保存初始化配置' }}</button></footer>
</form>
</section>
</main>
</template>
<style scoped>
.setup-shell { min-height: 100dvh; display: grid; grid-template-columns: minmax(280px, .72fr) minmax(640px, 1.4fr); background: #f4f7fb; color: #172033; }
.setup-intro { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: clamp(34px, 5vw, 78px); overflow: hidden; color: #fff; background: radial-gradient(circle at 18% 12%, rgba(111,160,255,.6), transparent 32%), linear-gradient(145deg, #132752, #244c92 62%, #2e64b8); }
.brand-mark { display: block; width: 96px; height: 96px; margin-bottom: 22px; object-fit: contain; filter: drop-shadow(0 14px 22px rgba(0,0,0,.2)); }
.setup-eyebrow { margin: 0 0 8px; color: #446a9f; font-size: 12px; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }
.setup-intro .setup-eyebrow { color: #bad2ff; }
.setup-intro h1 { margin: 0 0 18px; font-size: clamp(34px, 4vw, 58px); line-height: 1.08; }
.setup-intro > p:not(.setup-eyebrow) { max-width: 580px; margin: 0; color: #d7e4fb; line-height: 1.8; }
.service-summary { display: grid; gap: 10px; margin-top: 34px; }
.service-summary span { padding: 12px 15px; border: 1px solid rgba(255,255,255,.17); border-radius: 12px; background: rgba(255,255,255,.08); color: #dce8fb; font-size: 13px; }
.service-summary strong { color: #fff; }
.warning-card { display: grid; gap: 7px; margin-top: 28px; padding: 16px; border-left: 3px solid #ffd37a; background: rgba(8,21,51,.25); color: #dce8fb; font-size: 12px; line-height: 1.65; }
.warning-card strong { color: #ffe5ad; }
.setup-card { align-self: start; width: min(100%, 1080px); margin: 0 auto; padding: clamp(28px, 4vw, 58px); }
.setup-card > header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 28px; }
.setup-card h2 { margin: 0; font-size: 32px; }
.local-badge { padding: 7px 11px; border-radius: 99px; color: #2f63b2; background: #e5efff; font-size: 12px; font-weight: 800; }
form { display: grid; gap: 18px; }
fieldset { min-width: 0; margin: 0; padding: 22px; border: 1px solid #dde5f0; border-radius: 18px; background: rgba(255,255,255,.92); box-shadow: 0 10px 35px rgba(31,50,87,.04); }
legend { padding: 0 8px; color: #243653; font-size: 15px; font-weight: 900; }
legend span { display: inline-grid; place-items: center; width: 28px; height: 28px; margin-right: 9px; border-radius: 9px; color: #fff; background: #315faa; font-size: 11px; }
.setup-grid { display: grid; gap: 14px; }
.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label { display: grid; gap: 7px; margin-top: 14px; color: #34445f; font-size: 12px; font-weight: 800; }
input, select, textarea { min-width: 0; width: 100%; padding: 0 12px; border: 1px solid #d4deeb; border-radius: 10px; outline: 0; color: #172033; background: #fbfcfe; font: inherit; font-weight: 500; }
input, select { height: 43px; }
textarea { min-height: 96px; padding-top: 11px; padding-bottom: 11px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: #4f7ed5; box-shadow: 0 0 0 3px rgba(79,126,213,.12); }
label > small { color: #53647b; font-weight: 500; line-height: 1.5; }
.provider-description, .dns-verification-success { display: grid; gap: 5px; margin-top: 14px; padding: 13px 14px; border-radius: 12px; font-size: 12px; line-height: 1.55; }
.provider-description { color: #435571; background: #f4f7fb; }
.provider-description.unavailable { color: #805f20; background: #fff8e8; }
.provider-description strong, .dns-verification-success strong { font-size: 13px; }
.credential-grid { margin-top: 2px; }
.dns-test-actions { display: flex; align-items: center; gap: 14px; margin-top: 16px; color: #53647b; font-size: 12px; line-height: 1.5; }
.dns-test-button { flex: 0 0 auto; min-width: 160px; padding: 10px 15px; border: 0; border-radius: 10px; color: #fff; background: #315faa; font-weight: 900; }
.inline-error { margin: 13px 0 0; padding: 11px 13px; border: 1px solid #efc6c6; border-radius: 10px; color: #a33d3d; background: #fff1f1; font-size: 12px; }
.dns-verification-success { border: 1px solid #bfe7d1; color: #24734b; background: #effbf4; }
.confirm-row { grid-template-columns: auto 1fr; align-items: flex-start; padding: 13px 14px; border-radius: 12px; background: #f6f8fc; }
.confirm-row input { width: 18px; height: 18px; margin-top: 2px; accent-color: #315faa; }
.confirm-row strong, .confirm-row small { display: block; }
.confirm-row small { margin-top: 5px; color: #53647b; font-weight: 500; line-height: 1.5; }
.target-switch { display: inline-flex; gap: 4px; margin-top: 14px; padding: 4px; border-radius: 10px; background: #edf2f8; }
.target-switch button { padding: 8px 13px; border: 0; border-radius: 8px; color: #4d6078; background: transparent; font-weight: 800; }
.target-switch button.active { color: #274f91; background: #fff; box-shadow: 0 3px 10px rgba(36,64,107,.1); }
.setup-error, .setup-success { margin: 0; padding: 13px 16px; border-radius: 11px; font-size: 13px; }
.setup-error { border: 1px solid #efc6c6; color: #a33d3d; background: #fff1f1; }
.setup-success { border: 1px solid #bfe7d1; color: #24734b; background: #effbf4; }
footer { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 5px 2px 30px; color: #53647b; font-size: 12px; line-height: 1.6; }
footer button { flex: 0 0 auto; min-width: 170px; padding: 12px 18px; border: 0; border-radius: 11px; color: #fff; background: #315faa; font-weight: 900; box-shadow: 0 8px 20px rgba(49,95,170,.22); }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .62; }
@media (max-width: 1050px) { .setup-shell { grid-template-columns: 1fr; } .setup-intro { position: static; height: auto; min-height: 330px; padding: 44px clamp(24px, 6vw, 64px); } .setup-intro h1 { font-size: 40px; } .service-summary { grid-template-columns: 1fr 1fr; } .warning-card { margin-top: 18px; } }
@media (max-width: 760px) { .setup-intro { min-height: auto; padding: 34px 20px; } .brand-mark { width: 72px; height: 72px; margin-bottom: 18px; } .setup-intro h1 { font-size: 34px; } .service-summary, .three-columns, .two-columns { grid-template-columns: 1fr; } .setup-card { padding: 28px 15px; } .setup-card h2 { font-size: 27px; } fieldset { padding: 17px 14px; } .dns-test-actions { align-items: stretch; flex-direction: column; } .dns-test-button { width: 100%; } footer { align-items: stretch; flex-direction: column; } footer button { width: 100%; } }
</style>
+41 -6
View File
@@ -1,21 +1,29 @@
:root { font-family: Inter, "Microsoft YaHei", sans-serif; color: #172033; background: #f4f7fb; font-synthesis: none; }
* { box-sizing: border-box; }
.bootstrap-screen { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 14px; padding: 24px; color: #31415d; background: #f4f7fb; text-align: center; }
.bootstrap-screen p { margin: 0; color: #a33d3d; }
.bootstrap-mark { display: block; width: 86px; height: 86px; object-fit: contain; filter: drop-shadow(0 14px 20px rgba(36,76,146,.22)); }
body { margin: 0; min-width: 320px; }
button { font: inherit; cursor: pointer; }
.page-shell { max-width: 1180px; margin: 0 auto; padding: 42px 28px 70px; }
.topbar, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar-actions, .row-actions, .modal-actions { display: flex; align-items: center; gap: 10px; }
.eyebrow { margin: 0 0 9px; color: #687792; font-size: 11px; font-weight: 800; letter-spacing: .15em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(30px, 5vw, 52px); letter-spacing: -.05em; }
h2 { margin-bottom: 10px; font-size: clamp(24px, 4vw, 38px); letter-spacing: -.04em; }
.secondary-button { border: 1px solid #d5ddea; border-radius: 12px; background: #fff; color: #32405a; padding: 11px 16px; font-weight: 700; }
.primary-button { border: 1px solid #315aaa; border-radius: 12px; background: #315aaa; color: #fff; padding: 11px 16px; font-weight: 800; box-shadow: 0 8px 18px rgba(49, 90, 170, .18); }
.primary-button:disabled, .secondary-button:disabled { cursor: wait; opacity: .6; }
.hero-card { display: flex; align-items: center; justify-content: space-between; min-height: 250px; margin: 36px 0 18px; padding: 36px 42px; border-radius: 28px; color: #fff; background: linear-gradient(120deg, #182b5b, #315aaa); box-shadow: 0 20px 45px rgba(42, 75, 145, .2); }
.hero-card p { max-width: 650px; margin-bottom: 0; color: #d5e1ff; line-height: 1.8; }
.status-label { font-size: 13px; font-weight: 800; }
.status-dot { display: inline-block; width: 9px; height: 9px; margin-right: 8px; border-radius: 50%; background: #ffba58; }
.status-dot.online { background: #5ee0a0; box-shadow: 0 0 0 5px rgba(94, 224, 160, .15); }
.hero-mark { display: grid; place-items: center; width: 112px; height: 112px; border: 1px solid rgba(255,255,255,.35); border-radius: 32px; color: #cfe0ff; font-size: 62px; font-weight: 900; }
.error-banner { margin: 18px 0; padding: 14px 18px; border: 1px solid #f0c4c4; border-radius: 12px; color: #9c3b3b; background: #fff2f2; }
.hero-mark { display: block; width: 138px; height: 138px; object-fit: contain; filter: drop-shadow(0 16px 24px rgba(0,0,0,.18)); }
.error-banner, .notice-banner { margin: 18px 0; padding: 14px 18px; border-radius: 12px; }
.error-banner { border: 1px solid #f0c4c4; color: #9c3b3b; background: #fff2f2; }
.notice-banner { border: 1px solid #bfe7d1; color: #24734b; background: #effbf4; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.metric-card, .panel { border: 1px solid #e2e8f2; border-radius: 20px; background: rgba(255,255,255,.86); box-shadow: 0 10px 30px rgba(31, 50, 87, .04); }
.metric-card { padding: 22px; }
@@ -24,11 +32,38 @@ h2 { margin-bottom: 10px; font-size: clamp(24px, 4vw, 38px); letter-spacing: -.0
.panel { padding: 28px; }
.panel-heading { margin-bottom: 22px; }
.panel-heading h2 { margin-bottom: 0; font-size: 26px; }
.empty-state { padding: 36px 10px; color: #7a879d; text-align: center; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 52px 10px; color: #7a879d; text-align: center; }
.empty-state strong { color: #32405a; font-size: 17px; }
code { padding: 2px 6px; border-radius: 6px; background: #eef2f8; font-family: Consolas, monospace; }
.domain-list { display: grid; gap: 10px; }
.domain-row { display: flex; align-items: center; justify-content: space-between; padding: 15px 16px; border: 1px solid #edf0f5; border-radius: 13px; }
.domain-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 22px; padding: 17px 18px; border: 1px solid #edf0f5; border-radius: 13px; }
.domain-row strong, .domain-row span { display: block; }
.domain-row strong { margin-bottom: 5px; }
.domain-title-line { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.domain-title-line strong { margin-bottom: 0; font-size: 17px; }
.domain-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 9px; }
.domain-meta span, .domain-expiry span { color: #7a879d; font-size: 12px; }
.domain-expiry { min-width: 105px; text-align: right; }
.domain-expiry strong { margin-bottom: 5px; font-size: 13px; }
.text-button { padding: 5px 3px; border: 0; color: #315aaa; background: transparent; font-weight: 800; }
.danger-text { color: #ba5555; }
.tag { padding: 5px 10px; border-radius: 99px; background: #fff3d8; color: #9b6a1a !important; font-size: 12px !important; }
@media (max-width: 760px) { .page-shell { padding: 26px 16px 48px; } .hero-card { align-items: flex-start; padding: 28px; } .hero-mark { display: none; } .metrics-grid { grid-template-columns: repeat(2, 1fr); } .panel { padding: 20px; } }
.tag.success { background: #e7f8ee; color: #24734b !important; }
.tag.danger { background: #fff0f0; color: #ba5555 !important; }
.modal-backdrop { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 20px; background: rgba(18, 31, 58, .45); }
.modal-card { width: min(100%, 560px); max-height: calc(100vh - 40px); overflow: auto; padding: 30px; border: 1px solid #e2e8f2; border-radius: 22px; background: #fff; box-shadow: 0 24px 70px rgba(19, 38, 79, .25); }
.modal-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.modal-heading h2 { margin-bottom: 0; font-size: 28px; }
.close-button { width: 34px; height: 34px; border: 0; border-radius: 10px; color: #687792; background: #f1f4f8; font-size: 24px; line-height: 1; }
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 17px; color: #32405a; font-size: 13px; font-weight: 800; }
.field small, .switch-field small { margin-left: 5px; color: #8995a8; font-size: 11px; font-weight: 500; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid #d8e0eb; border-radius: 10px; outline: 0; padding: 11px 12px; color: #172033; background: #fbfcfe; font: inherit; font-weight: 500; }
.field textarea { resize: vertical; line-height: 1.6; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #4f7ed5; box-shadow: 0 0 0 3px rgba(79, 126, 213, .12); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.switch-field { display: flex; align-items: flex-start; gap: 10px; margin: 4px 0 20px; color: #32405a; font-size: 13px; }
.switch-field input { width: 18px; height: 18px; accent-color: #315aaa; }
.switch-field strong, .switch-field small { display: block; }
.switch-field small { margin: 5px 0 0; }
.form-error { margin: 0 0 16px; color: #ba5555; font-size: 13px; }
.modal-actions { justify-content: flex-end; padding-top: 5px; }
@media (max-width: 760px) { .page-shell { padding: 26px 16px 48px; } .topbar { align-items: flex-start; flex-direction: column; } .topbar-actions { width: 100%; } .topbar-actions button { flex: 1; } .hero-card { align-items: flex-start; padding: 28px; } .hero-mark { display: none; } .metrics-grid { grid-template-columns: repeat(2, 1fr); } .panel { padding: 20px; } .panel-heading { align-items: flex-start; flex-direction: column; gap: 8px; } .domain-row { grid-template-columns: 1fr auto; gap: 14px; } .domain-expiry { text-align: left; } .row-actions { grid-column: 1 / -1; justify-content: flex-end; border-top: 1px solid #edf0f5; padding-top: 10px; } .modal-card { padding: 22px; } .form-grid { grid-template-columns: 1fr; gap: 0; } }
+5 -3
View File
@@ -3,11 +3,13 @@ import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
publicDir: 'logo',
server: {
port: 5173,
host: process.env.SCERT_DEV_HOST || '127.0.0.1',
port: Number(process.env.SCERT_DEV_PORT || 5173),
proxy: {
'/api': 'http://127.0.0.1:8080',
'/healthz': 'http://127.0.0.1:8080',
'/api': process.env.SCERT_API_TARGET || 'http://127.0.0.1:8090',
'/healthz': process.env.SCERT_API_TARGET || 'http://127.0.0.1:8090',
},
},
})