完善初始化向导、通知配置与证书流程

This commit is contained in:
xuans committed 2026-08-29 11:52:31 +08:00
1 parent b2833b761d
commit f85ef10527
41 files changed
+3645 -1697

No files matched your search

File diff suppressed because it is too large. Load diff
+114 -5
View File
@@ -27,6 +27,9 @@ export function useSetupWizard(props, emit) {
const dnsTestError = ref("");
const dnsProviders = ref([]);
const dnsCredentials = ref({});
const dnsCredentialsVisible = ref(true);
const emailCredentials = ref("");
const emailCredentialsVisible = ref(true);
const dnsTestDomain = ref(props.status.web_hostname || "");
const dnsVerification = ref(null);
const verificationClock = ref(Date.now());
@@ -60,6 +63,9 @@ export function useSetupWizard(props, emit) {
email_retry_intervals_secs: "30,120,600",
recipients: "",
dns_provider: props.status.dns_provider || "cloudflare",
propagation_timeout_secs: props.status.propagation_timeout_secs || 900,
propagation_polling_interval_secs:
props.status.propagation_polling_interval_secs || 10,
certificate_root: props.status.certificate_root || "",
web_hostname: props.status.web_hostname || "",
web_public_ip: props.status.web_public_ip || "",
@@ -70,6 +76,30 @@ export function useSetupWizard(props, emit) {
const targetLabel = computed(() =>
targetType.value === "hostname" ? "管理页面域名" : "公网 IP 地址",
);
const emailCredentialLabel = computed(() => {
switch (form.value.email_http_auth_mode) {
case "bearer":
return "Bearer Token 凭据(JSON)";
case "hmac_sha256":
return "HMAC-SHA256 凭据(JSON)";
case "session":
return "登录会话凭据(JSON)";
default:
return "HTTP 通知凭据";
}
});
const emailCredentialPlaceholder = computed(() => {
switch (form.value.email_http_auth_mode) {
case "bearer":
return '{"token":"请输入 Bearer Token"}';
case "hmac_sha256":
return '{"secret":"请输入签名密钥"}';
case "session":
return '{"account":"请输入账号","password":"请输入密码"}';
default:
return "无需填写凭据";
}
});
const resetURLPreview = computed(() => {
const rawHost =
targetType.value === "hostname"
@@ -191,6 +221,33 @@ export function useSetupWizard(props, emit) {
return payload;
}
function maskCredential(value) {
const text = String(value || "");
if (!text) return "";
return "•".repeat(Math.min(Math.max(text.length, 8), 64));
}
function emailCredentialPayload() {
if (
!form.value.email_http_enabled ||
form.value.email_http_auth_mode === "none"
) {
return {};
}
const text = emailCredentials.value.trim();
if (!text) return {};
const parsed = JSON.parse(text);
if (!parsed || Array.isArray(parsed) || typeof parsed !== "object") {
throw new Error("HTTP 通知凭据必须是 JSON 对象。");
}
for (const [key, value] of Object.entries(parsed)) {
if (!key.trim() || typeof value !== "string" || !value.trim()) {
throw new Error("HTTP 通知凭据的字段和值必须是非空文本。");
}
}
return parsed;
}
async function testDNS() {
dnsTestError.value = "";
resultMessage.value = "";
@@ -280,11 +337,24 @@ export function useSetupWizard(props, emit) {
if (
form.value.email_http_enabled &&
form.value.email_http_auth_mode !== "none" &&
!form.value.email_http_credential_ref.trim()
!form.value.email_http_credential_ref.trim() &&
!emailCredentials.value.trim()
) {
error.value = "启用 HTTP 通知认证后必须填写凭据引用。";
error.value = "启用 HTTP 通知认证后必须填写明文凭据或已有凭据引用。";
return false;
}
if (
form.value.email_http_enabled &&
form.value.email_http_auth_mode !== "none" &&
emailCredentials.value.trim()
) {
try {
emailCredentialPayload();
} catch (err) {
error.value = err.message || "HTTP 通知凭据格式无效。";
return false;
}
}
if (form.value.email_http_headers.trim()) {
try {
const headers = JSON.parse(form.value.email_http_headers);
@@ -299,6 +369,26 @@ export function useSetupWizard(props, emit) {
}
if (currentStep.value === 3) {
const propagationTimeout = Number(form.value.propagation_timeout_secs);
const propagationInterval = Number(
form.value.propagation_polling_interval_secs,
);
if (
!Number.isInteger(propagationTimeout) ||
propagationTimeout < 1 ||
propagationTimeout > 86400
) {
error.value = "DNS 传播最大等待时间必须在 1 至 86400 秒之间。";
return false;
}
if (
!Number.isInteger(propagationInterval) ||
propagationInterval < 1 ||
propagationInterval > propagationTimeout
) {
error.value = "DNS 传播检测间隔必须大于 0 且不超过最大等待时间。";
return false;
}
const provider = selectedDNSProvider.value;
if (!provider) {
error.value = "请选择 DNS 服务商。";
@@ -398,6 +488,12 @@ export function useSetupWizard(props, emit) {
error.value = "必须先完成 DNS API 在线验证;验证结果已过期时请重新测试。";
return;
}
try {
emailCredentialPayload();
} catch (err) {
error.value = err.message || "HTTP 通知凭据格式无效。";
return;
}
const hostname =
targetType.value === "hostname" ? form.value.web_hostname.trim() : "";
const publicIP =
@@ -422,9 +518,10 @@ export function useSetupWizard(props, emit) {
email_endpoint: form.value.email_endpoint,
email_http_path: form.value.email_http_path,
email_http_login_path: form.value.email_http_login_path,
email_http_auth_mode: form.value.email_http_auth_mode,
email_http_credential_ref: form.value.email_http_credential_ref,
email_http_headers: emailHeaders(),
email_http_auth_mode: form.value.email_http_auth_mode,
email_http_credential_ref: form.value.email_http_credential_ref,
email_http_credentials: emailCredentialPayload(),
email_http_headers: emailHeaders(),
email_event_mode: form.value.email_event_mode,
email_include_deployment_details:
form.value.email_include_deployment_details,
@@ -441,6 +538,12 @@ export function useSetupWizard(props, emit) {
dns_credential_ref: dnsVerification.value.credential_ref,
dns_verification_token: dnsVerification.value.verification_token,
dns_test_domain: dnsTestDomain.value.trim(),
propagation_timeout_secs: Number(
form.value.propagation_timeout_secs,
),
propagation_polling_interval_secs: Number(
form.value.propagation_polling_interval_secs,
),
certificate_root: form.value.certificate_root,
web_hostname: hostname,
web_public_ip: publicIP,
@@ -492,6 +595,10 @@ export function useSetupWizard(props, emit) {
dnsTestError,
dnsProviders,
dnsCredentials,
dnsCredentialsVisible,
maskCredential,
emailCredentials,
emailCredentialsVisible,
dnsTestDomain,
dnsVerification,
currentStep,
@@ -501,6 +608,8 @@ export function useSetupWizard(props, emit) {
selectedEmailDomain,
emailLocalPart,
targetLabel,
emailCredentialLabel,
emailCredentialPlaceholder,
resetURLPreview,
selectedDNSProvider,
dnsVerificationValid,
+302 -147
View File
@@ -22,6 +22,8 @@ const {
dnsTestError,
dnsProviders,
dnsCredentials,
dnsCredentialsVisible,
maskCredential,
dnsTestDomain,
dnsVerification,
currentStep,
@@ -172,162 +174,268 @@ const {
</div>
</fieldset>
<fieldset v-if="currentStep === 2" class="setup-step-card setup-notification-step">
<fieldset
v-if="currentStep === 2"
class="setup-step-card setup-notification-step"
>
<legend><span>02</span>服务与通知</legend>
<div class="setup-grid two-columns email-primary-grid">
<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 class="confirm-row compact-row"
><input
id="email-http-enabled"
v-model="form.email_http_enabled"
type="checkbox"
/><span><strong>启用 HTTP 邮件通知</strong><small>兼容 Smail 等 HTTP 邮件服务。</small></span></label
<div class="notification-layout">
<div class="notification-row notification-service-row">
<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 class="confirm-row compact-row">
<input
id="email-http-enabled"
v-model="form.email_http_enabled"
type="checkbox"
/>
<span>
<strong>启用 HTTP 邮件通知</strong>
<small>兼容 Smail 等 HTTP 邮件服务。</small>
</span>
</label>
<label v-if="form.email_http_enabled">
<span>第三方邮箱服务标识</span>
<input
id="email-provider"
name="email_provider"
v-model.trim="form.email_provider"
placeholder="例如 company-mail-api"
/>
</label>
</div>
<div
v-if="form.email_http_enabled"
class="notification-row notification-api-row"
>
<label v-if="form.email_http_enabled"
><span>第三方邮箱服务标识</span
><input
id="email-provider"
name="email_provider"
v-model.trim="form.email_provider"
placeholder="例如 company-mail-api"
/></label>
<label v-if="form.email_http_enabled"
><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>
<label v-if="form.email_http_enabled"
><span>HTTP 请求路径</span
><input
id="email-http-path"
v-model.trim="form.email_http_path"
placeholder="/api/email/send"
/></label>
<label v-if="form.email_http_enabled"
><span>HTTP 认证方式</span
><select
id="email-http-auth-mode"
v-model="form.email_http_auth_mode"
<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>
<label>
<span>HTTP 请求路径</span>
<input
id="email-http-path"
v-model.trim="form.email_http_path"
placeholder="/api/email/send"
/>
</label>
<label>
<span>HTTP 认证方式</span>
<select
id="email-http-auth-mode"
v-model="form.email_http_auth_mode"
>
<option value="none">无认证</option>
<option value="bearer">Bearer Token</option>
<option value="hmac_sha256">HMAC-SHA256</option>
<option value="session">账号登录会话</option>
</select>
</label>
</div>
<div
v-if="form.email_http_enabled"
class="notification-row notification-auth-row"
>
<label v-if="form.email_http_auth_mode === 'session'">
<span>登录请求路径</span>
<input
id="email-http-login-path"
v-model.trim="form.email_http_login_path"
placeholder="/api/login"
/>
</label>
<label>
<span>已有凭据引用(可选)</span>
<input
id="email-http-credential-ref"
v-model.trim="form.email_http_credential_ref"
placeholder="已有 secret://notification/... 引用"
/>
</label>
<div
v-if="form.email_http_auth_mode === 'none'"
class="notification-auth-note"
>
<option value="none">无认证</option>
<option value="bearer">Bearer Token</option>
<option value="hmac_sha256">HMAC-SHA256</option>
<option value="session">账号登录会话</option>
</select></label
>
<label
当前接口不启用认证,不需要填写凭据。
</div>
</div>
<div
v-if="
form.email_http_enabled &&
form.email_http_auth_mode === 'session'
form.email_http_auth_mode !== 'none'
"
><span>登录请求路径</span
><input
id="email-http-login-path"
v-model.trim="form.email_http_login_path"
placeholder="/api/login"
/></label>
<label v-if="form.email_http_enabled"
><span>凭据引用</span
><input
id="email-http-credential-ref"
v-model.trim="form.email_http_credential_ref"
placeholder="secret://notification/mail"
/></label>
<label v-if="form.email_http_enabled"
><span>发件人名称</span
><input
id="email-sender-name"
v-model.trim="form.email_sender_name"
placeholder="Scert"
/></label>
<label v-if="form.email_http_enabled"
><span>发件人地址</span
><input
id="email-sender-email"
v-model.trim="form.email_sender_email"
type="email"
placeholder="留空使用管理员邮箱"
/></label>
</div>
<div class="provider-description reset-preview">
<strong>密码重置地址</strong><span>{{ resetURLPreview }}</span
><span
>无需配置独立端口;只有手动启动 Scert-admin
后,此地址才会临时可用。</span
class="notification-credential-field"
>
</div>
<label v-if="form.email_http_enabled"
><span>通知收件人</span
><input
id="recipients"
name="recipients"
v-model="form.recipients"
placeholder="多个地址使用逗号分隔"
/></label>
<div v-if="form.email_http_enabled" class="setup-grid two-columns email-delivery-grid">
<label
><span>通知事件模式</span
><select v-model="form.email_event_mode">
<option value="detailed">详细事件</option>
<option value="unified">统一事件</option>
</select></label
<div class="credential-visibility-row">
<span>{{ emailCredentialLabel }}</span>
<label class="credential-visibility-control">
<input
v-model="emailCredentialsVisible"
type="checkbox"
/>
<span>显示凭据明文</span>
</label>
</div>
<textarea
v-if="emailCredentialsVisible"
id="email-http-credentials-visible"
v-model="emailCredentials"
rows="3"
autocomplete="off"
:placeholder="emailCredentialPlaceholder"
></textarea>
<textarea
v-else
id="email-http-credentials-masked"
:value="maskCredential(emailCredentials)"
rows="3"
readonly
autocomplete="off"
></textarea>
<small>
配置时允许明文显示;提交后仅保存加密凭据引用,普通配置文件不会保存密码或令牌。
</small>
</div>
<div
v-if="form.email_http_enabled"
class="provider-description reset-preview"
>
<label
><span>请求超时(秒)</span
><input
v-model.number="form.email_timeout_secs"
type="number"
min="1"
/></label>
<label
><span>重试次数</span
><input
v-model.number="form.email_retry_count"
type="number"
min="1"
/></label>
<label
><span>重试间隔(秒)</span
><input
v-model.trim="form.email_retry_intervals_secs"
placeholder="30,120,600"
/></label>
</div>
<label v-if="form.email_http_enabled" class="email-headers-field"
><span>HTTP 自定义请求头(JSON)</span
><textarea
v-model.trim="form.email_http_headers"
rows="2"
placeholder='例如:{"X-Tenant":"scert"}'
></textarea
></label>
<div v-if="form.email_http_enabled" class="setup-grid three-columns compact-options email-option-grid">
<label class="confirm-row compact-row"
><input v-model="form.email_include_deployment_details" type="checkbox" /><span>部署明细</span></label
<strong>密码重置地址</strong>
<span>{{ resetURLPreview }}</span>
<span>
无需配置独立端口;只有手动启动 Scert-admin
后,此地址才会临时可用。
</span>
</div>
<div
v-if="form.email_http_enabled"
class="notification-row notification-sender-row"
>
<label class="confirm-row compact-row"
><input v-model="form.email_include_certificate_serial" type="checkbox" /><span>证书序列号</span></label
<label>
<span>发件人名称</span>
<input
id="email-sender-name"
v-model.trim="form.email_sender_name"
placeholder="Scert"
/>
</label>
<label>
<span>发件人地址</span>
<input
id="email-sender-email"
v-model.trim="form.email_sender_email"
type="email"
placeholder="留空使用管理员邮箱"
/>
</label>
<label>
<span>通知收件人</span>
<input
id="recipients"
name="recipients"
v-model="form.recipients"
placeholder="多个地址使用逗号分隔"
/>
</label>
</div>
<div
v-if="form.email_http_enabled"
class="notification-row notification-delivery-row"
>
<label class="confirm-row compact-row"
><input v-model="form.email_include_management_url" type="checkbox" /><span>管理后台链接</span></label
<label>
<span>通知事件模式</span>
<select v-model="form.email_event_mode">
<option value="detailed">详细事件</option>
<option value="unified">统一事件</option>
</select>
</label>
<label>
<span>请求超时(秒)</span>
<input
v-model.number="form.email_timeout_secs"
type="number"
min="1"
/>
</label>
<label>
<span>重试次数</span>
<input
v-model.number="form.email_retry_count"
type="number"
min="1"
/>
</label>
<label>
<span>重试间隔(秒)</span>
<input
v-model.trim="form.email_retry_intervals_secs"
placeholder="30,120,600"
/>
</label>
</div>
<div
v-if="form.email_http_enabled"
class="notification-bottom-row"
>
<label class="email-headers-field">
<span>HTTP 自定义请求头(JSON)</span>
<textarea
v-model.trim="form.email_http_headers"
rows="2"
placeholder='例如:{"X-Tenant":"scert"}'
></textarea>
</label>
<div class="setup-grid three-columns compact-options email-option-grid">
<label class="confirm-row compact-row">
<input
v-model="form.email_include_deployment_details"
type="checkbox"
/>
<span>部署明细</span>
</label>
<label class="confirm-row compact-row">
<input
v-model="form.email_include_certificate_serial"
type="checkbox"
/>
<span>证书序列号</span>
</label>
<label class="confirm-row compact-row">
<input
v-model="form.email_include_management_url"
type="checkbox"
/>
<span>管理后台链接</span>
</label>
</div>
</div>
</div>
</fieldset>
<fieldset v-if="currentStep === 3" class="setup-step-card">
<legend><span>03</span>DNS 验证</legend>
<div class="setup-grid two-columns">
@@ -367,6 +475,34 @@ const {
></label
>
</div>
<div class="setup-grid two-columns propagation-grid">
<label>
<span>DNS 传播最大等待时间(秒)</span>
<input
id="propagation-timeout-secs"
name="propagation_timeout_secs"
v-model.number="form.propagation_timeout_secs"
type="number"
min="1"
max="86400"
required
/>
<small>默认 900 秒,最长允许等待 86400 秒。</small>
</label>
<label>
<span>DNS 传播检测间隔(秒)</span>
<input
id="propagation-polling-interval-secs"
name="propagation_polling_interval_secs"
v-model.number="form.propagation_polling_interval_secs"
type="number"
min="1"
:max="form.propagation_timeout_secs"
required
/>
<small>默认 10 秒,不能大于最大等待时间。</small>
</label>
</div>
<p v-if="dnsCatalogError" class="inline-error">
{{ dnsCatalogError }}
</p>
@@ -386,6 +522,16 @@ const {
v-if="selectedDNSProvider"
class="setup-grid two-columns credential-grid"
>
<div class="credential-visibility-row">
<span>DNS 凭据</span>
<label class="credential-visibility-control">
<input
v-model="dnsCredentialsVisible"
type="checkbox"
/>
<span>显示凭据明文</span>
</label>
</div>
<label
v-for="field in selectedDNSProvider.credential_fields"
:key="field.name"
@@ -395,8 +541,8 @@ const {
}}{{ field.required ? "(必填)" : "(可选)" }}</span
>
<textarea
v-if="field.name.includes('json')"
:id="`dns-credential-${field.name}`"
v-if="field.name.includes('json') && dnsCredentialsVisible"
:id="`dns-credential-json-${field.name}`"
:name="`dns_credential_${field.name}`"
v-model="dnsCredentials[field.name]"
:required="field.required"
@@ -404,13 +550,22 @@ const {
rows="4"
autocomplete="off"
></textarea>
<textarea
v-else-if="field.name.includes('json')"
:id="`dns-credential-masked-${field.name}`"
:name="`dns_credential_${field.name}`"
:value="maskCredential(dnsCredentials[field.name])"
rows="4"
readonly
autocomplete="off"
></textarea>
<input
v-else
:id="`dns-credential-${field.name}`"
:id="`dns-credential-value-${field.name}`"
:name="`dns_credential_${field.name}`"
v-model="dnsCredentials[field.name]"
:required="field.required"
:type="field.secret ? 'password' : 'text'"
:type="field.secret && !dnsCredentialsVisible ? 'password' : 'text'"
:placeholder="field.placeholder"
autocomplete="off"
/>
@@ -19,11 +19,12 @@
}
.access-shell--setup {
width: min(1360px, calc(100vw - 32px));
max-width: calc(100vw - 32px);
height: min(760px, calc(100vh - 32px));
max-height: calc(100vh - 32px);
width: min(1380px, calc(100vw - 40px));
max-width: calc(100vw - 40px);
height: min(790px, calc(100dvh - 40px));
max-height: calc(100dvh - 40px);
min-height: 0;
grid-template-columns: minmax(245px, 0.32fr) minmax(0, 0.68fr);
}
.access-shell--compact {
@@ -140,7 +141,27 @@
.access-shell--setup .access-panel-inner {
align-items: stretch;
padding: clamp(22px, 2.7vw, 42px);
padding: clamp(18px, 2.2vw, 32px);
}
.access-shell--setup .access-brand-content {
padding: clamp(28px, 2.8vw, 42px) clamp(22px, 2.2vw, 34px);
}
.access-shell--setup .access-logo {
width: clamp(64px, 6vw, 84px);
height: clamp(64px, 6vw, 84px);
margin-bottom: clamp(16px, 2vw, 24px);
}
.access-shell--setup .access-brand-title {
font-size: clamp(20px, 1.7vw, 29px);
}
.access-shell--setup .access-brand-description {
max-width: 290px;
font-size: 12px;
line-height: 1.7;
}
@media (max-width: 900px) {
@@ -155,6 +176,14 @@
border-radius: 22px;
}
.access-shell--setup {
width: min(calc(100% - 24px), 900px);
max-width: calc(100% - 24px);
height: calc(100dvh - 24px);
max-height: calc(100dvh - 24px);
grid-template-rows: 112px minmax(0, 1fr);
}
.access-brand-content {
display: grid;
grid-template-columns: auto minmax(0, 1fr);
@@ -204,6 +233,14 @@
border-radius: 17px;
}
.access-shell--setup {
width: calc(100% - 12px);
max-width: calc(100% - 12px);
height: calc(100dvh - 12px);
max-height: calc(100dvh - 12px);
grid-template-rows: 88px minmax(0, 1fr);
}
.access-brand-content {
column-gap: 11px;
padding: 9px 12px;