mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
M001: add secure admin foundation
This commit is contained in:
1 parent
960be106bb
commit
31f320d4c1
32 files changed
+2518
-679
No files matched your search
@@ -0,0 +1,169 @@
|
||||
<template>
|
||||
<div class="admin-root">
|
||||
<div v-if="loading" class="center-card compact"><span class="spinner"></span><p>{{ tr('loading') }}</p></div>
|
||||
|
||||
<main v-else-if="screen === 'setup'" class="auth-layout">
|
||||
<section class="auth-intro">
|
||||
<div class="admin-brand"><span><Icon name="waveform" :size="24" /></span><div><strong>WebSpeak</strong><small>{{ tr('adminConsole') }}</small></div></div>
|
||||
<div class="intro-copy"><i>{{ tr('firstSetup') }}</i><h1>{{ tr('setupTitle') }}</h1><p>{{ tr('setupLead') }}</p></div>
|
||||
<div class="step-list">
|
||||
<button v-for="item in setupSteps" :key="item.index" :class="{ active: setupStep === item.index, done: setupStep > item.index }" type="button" @click="goToSetupStep(item.index)"><span>{{ setupStep > item.index ? '✓' : item.index }}</span><div><strong>{{ item.title }}</strong><small>{{ item.lead }}</small></div></button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="auth-panel">
|
||||
<div class="panel-tools"><button type="button" @click="toggleLanguage">{{ tr('languageSwitch') }}</button></div>
|
||||
<form class="setup-card" @submit.prevent="nextSetupStep">
|
||||
<header><small>{{ tr('stepCounter', { current: setupStep, total: 3 }) }}</small><h2>{{ setupSteps[setupStep - 1]?.title }}</h2><p>{{ setupSteps[setupStep - 1]?.lead }}</p></header>
|
||||
<div v-if="errorMessage" class="alert error">{{ errorMessage }}</div>
|
||||
|
||||
<div v-if="setupStep === 1" class="form-stack">
|
||||
<label><span>{{ tr('bootstrapCode') }}</span><input v-model.trim="setup.bootstrapCode" autocomplete="one-time-code" maxlength="128" :placeholder="tr('bootstrapPlaceholder')" /></label>
|
||||
<label><span>{{ tr('newPassword') }}</span><input v-model="setup.adminPassword" type="password" autocomplete="new-password" maxlength="1024" :placeholder="tr('passwordPlaceholder')" /><small>{{ tr('passwordHint') }}</small></label>
|
||||
<label><span>{{ tr('confirmPassword') }}</span><input v-model="setup.confirmPassword" type="password" autocomplete="new-password" maxlength="1024" /></label>
|
||||
<div class="strength"><i :style="{ width: `${passwordStrength}%` }"></i></div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="setupStep === 2" class="form-stack">
|
||||
<label><span>{{ tr('serverAddress') }}</span><input v-model.trim="setup.target" autocomplete="url" :placeholder="tr('serverPlaceholder')" /><small>{{ tr('serverHint') }}</small></label>
|
||||
<label><span>{{ tr('serverPassword') }} <em>{{ tr('optional') }}</em></span><input v-model="setup.serverPassword" type="password" autocomplete="off" :placeholder="setup.hasPassword ? tr('passwordConfigured') : tr('optionalPassword')" /></label>
|
||||
<button class="secondary-button" type="button" :disabled="testing || !setup.target" @click="testSetupConnection"><span v-if="testing" class="spinner small"></span><Icon v-else name="activity" :size="17" /> {{ testing ? tr('testing') : tr('testConnection') }}</button>
|
||||
<div v-if="testResult" :class="['test-result', testResult.ok ? 'success' : 'error']"><Icon :name="testResult.ok ? 'check' : 'close'" :size="18" /><div><strong>{{ testResult.ok ? tr('connectionReady') : tr('connectionFailed') }}</strong><small>{{ testResultText }}</small></div></div>
|
||||
</div>
|
||||
|
||||
<div v-else class="form-stack">
|
||||
<fieldset><legend>{{ tr('accessMode') }}</legend><label class="choice"><input v-model="setup.accessMode" type="radio" value="fixed" /><span><strong>{{ tr('fixedMode') }}</strong><small>{{ tr('fixedModeLead') }}</small></span></label><label class="choice"><input v-model="setup.accessMode" type="radio" value="open" /><span><strong>{{ tr('openMode') }}</strong><small>{{ tr('openModeLead') }}</small></span></label></fieldset>
|
||||
<label><span>{{ tr('siteName') }}</span><input v-model.trim="setup.siteName" maxlength="80" /></label>
|
||||
<label><span>{{ tr('welcomeText') }} <em>{{ tr('optional') }}</em></span><textarea v-model="setup.welcomeText" maxlength="500" rows="3"></textarea></label>
|
||||
</div>
|
||||
|
||||
<footer><button v-if="setupStep > 1" class="text-button" type="button" @click="setupStep--">{{ tr('back') }}</button><span></span><button class="primary-button" :disabled="submitting" type="submit"><span v-if="submitting" class="spinner small"></span>{{ setupStep === 3 ? tr('finishSetup') : tr('continue') }}<Icon v-if="!submitting" name="chevron-right" :size="17" /></button></footer>
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<main v-else-if="screen === 'login'" class="login-page">
|
||||
<section class="login-card">
|
||||
<div class="admin-brand centered"><span><Icon name="waveform" :size="24" /></span><div><strong>WebSpeak</strong><small>{{ tr('adminConsole') }}</small></div></div>
|
||||
<header><h1>{{ tr('welcomeAdmin') }}</h1><p>{{ tr('loginLead') }}</p></header>
|
||||
<form @submit.prevent="login"><div v-if="errorMessage" class="alert error">{{ errorMessage }}</div><label><span>{{ tr('adminPassword') }}</span><input v-model="loginPassword" type="password" autocomplete="current-password" autofocus /></label><button class="primary-button wide" :disabled="submitting" type="submit"><span v-if="submitting" class="spinner small"></span>{{ tr('login') }}</button></form>
|
||||
<button class="language-link" type="button" @click="toggleLanguage">{{ tr('languageSwitch') }}</button>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<div v-else class="admin-shell">
|
||||
<aside class="admin-sidebar">
|
||||
<div class="admin-brand"><span><Icon name="waveform" :size="22" /></span><div><strong>WebSpeak</strong><small>{{ tr('adminConsole') }}</small></div></div>
|
||||
<nav><RouterLink to="/admin" exact-active-class="active"><Icon name="activity" :size="18" />{{ tr('overview') }}</RouterLink><RouterLink to="/admin/server" active-class="active"><Icon name="server" :size="18" />{{ tr('server') }}</RouterLink></nav>
|
||||
<div class="sidebar-bottom"><a href="/" target="_blank"><Icon name="share" :size="16" />{{ tr('openGuest') }}</a><button type="button" @click="logout"><Icon name="door" :size="16" />{{ tr('logout') }}</button></div>
|
||||
</aside>
|
||||
|
||||
<main class="admin-main">
|
||||
<header class="admin-topbar"><div><small>{{ tr('adminConsole') }}</small><h1>{{ currentPageTitle }}</h1></div><div><span class="running-dot"></span>{{ tr('gatewayRunning') }}<button type="button" @click="toggleLanguage">{{ tr('languageSwitch') }}</button></div></header>
|
||||
|
||||
<div v-if="errorMessage" class="alert error page-alert">{{ errorMessage }}</div>
|
||||
<section v-if="route.path === '/admin/server'" class="page-content">
|
||||
<div class="page-heading"><div><h2>{{ tr('serverSettings') }}</h2><p>{{ tr('serverSettingsLead') }}</p></div><button class="primary-button" :disabled="submitting" @click="saveServerSettings">{{ submitting ? tr('saving') : tr('saveChanges') }}</button></div>
|
||||
<div class="settings-grid">
|
||||
<article class="settings-card"><h3>{{ tr('teamSpeakTarget') }}</h3><label><span>{{ tr('serverAddress') }}</span><input v-model.trim="serverForm.target" :placeholder="tr('serverPlaceholder')" /></label><div class="password-row"><label><span>{{ tr('serverPassword') }}</span><input v-model="serverForm.serverPassword" type="password" autocomplete="off" :disabled="serverForm.passwordAction !== 'replace'" :placeholder="serverForm.hasPassword ? tr('passwordConfigured') : tr('optionalPassword')" /></label><div class="password-actions"><button type="button" :class="{ active: serverForm.passwordAction === 'replace' }" @click="serverForm.passwordAction = 'replace'">{{ tr('change') }}</button><button v-if="serverForm.hasPassword" type="button" :class="{ danger: serverForm.passwordAction === 'remove' }" @click="serverForm.passwordAction = 'remove'">{{ tr('remove') }}</button></div></div><button class="secondary-button" type="button" :disabled="testing" @click="testServerConnection"><span v-if="testing" class="spinner small"></span><Icon v-else name="activity" :size="17" />{{ testing ? tr('testing') : tr('testConnection') }}</button><div v-if="testResult" :class="['test-result', testResult.ok ? 'success' : 'error']"><Icon :name="testResult.ok ? 'check' : 'close'" :size="18" /><div><strong>{{ testResult.ok ? tr('connectionReady') : tr('connectionFailed') }}</strong><small>{{ testResultText }}</small></div></div></article>
|
||||
<article class="settings-card"><h3>{{ tr('accessAndIdentity') }}</h3><fieldset><legend>{{ tr('accessMode') }}</legend><label class="choice"><input v-model="serverForm.accessMode" type="radio" value="fixed" /><span><strong>{{ tr('fixedMode') }}</strong><small>{{ tr('fixedModeLead') }}</small></span></label><label class="choice"><input v-model="serverForm.accessMode" type="radio" value="open" /><span><strong>{{ tr('openMode') }}</strong><small>{{ tr('openModeLead') }}</small></span></label></fieldset><label><span>{{ tr('siteName') }}</span><input v-model.trim="serverForm.siteName" maxlength="80" /></label><label><span>{{ tr('welcomeText') }}</span><textarea v-model="serverForm.welcomeText" maxlength="500" rows="4"></textarea></label></article>
|
||||
</div>
|
||||
<article class="readonly-card"><h3>{{ tr('runtimeFacts') }}</h3><dl><div><dt>{{ tr('detectedProtocol') }}</dt><dd>{{ serverForm.detectedProtocol?.toUpperCase() || tr('unknown') }}</dd></div><div><dt>{{ tr('lastTest') }}</dt><dd>{{ formatDate(serverForm.lastTestAt) }}</dd></div><div><dt>{{ tr('latency') }}</dt><dd>{{ serverForm.lastTestLatencyMs == null ? '—' : `${serverForm.lastTestLatencyMs} ms` }}</dd></div><div><dt>{{ tr('internalPort') }}</dt><dd>3040</dd></div></dl></article>
|
||||
</section>
|
||||
|
||||
<section v-else class="page-content">
|
||||
<div v-if="overview.legacyConfigImported" class="alert info import-notice"><span>{{ tr('legacyImported') }}</span><button type="button" @click="dismissLegacyNotice">{{ tr('gotIt') }}</button></div>
|
||||
<div class="hero-status"><div><small>{{ tr('systemStatus') }}</small><h2>{{ tr('everythingRunning') }}</h2><p>{{ tr('overviewLead') }}</p></div><span class="status-badge"><i></i>{{ tr('running') }}</span></div>
|
||||
<div class="metric-grid"><article><span><Icon name="activity" :size="20" /></span><small>{{ tr('gateway') }}</small><strong>{{ overview.gateway.version || '—' }}</strong><em>{{ formatUptime(overview.gateway.uptimeSeconds) }}</em></article><article><span><Icon name="server" :size="20" /></span><small>{{ tr('teamSpeakTarget') }}</small><strong>{{ overview.teamSpeak.target || '—' }}</strong><em>{{ targetStatusText }}</em></article><article><span><Icon name="users" :size="20" /></span><small>{{ tr('activeSessions') }}</small><strong>{{ overview.sessions.active }} / {{ overview.sessions.limit }}</strong><em>{{ tr('peakSessions', { count: overview.sessions.peak }) }}</em></article></div>
|
||||
<div class="overview-columns"><article class="overview-card"><header><div><h3>{{ tr('targetHealth') }}</h3><p>{{ tr('targetHealthLead') }}</p></div><RouterLink to="/admin/server">{{ tr('manage') }}</RouterLink></header><dl><div><dt>{{ tr('status') }}</dt><dd><i :class="overview.teamSpeak.status"></i>{{ targetStatusText }}</dd></div><div><dt>{{ tr('detectedProtocol') }}</dt><dd>{{ overview.teamSpeak.protocol?.toUpperCase() || tr('unknown') }}</dd></div><div><dt>{{ tr('lastTest') }}</dt><dd>{{ formatDate(overview.teamSpeak.lastTestAt) }}</dd></div><div><dt>{{ tr('latency') }}</dt><dd>{{ overview.teamSpeak.latencyMs == null ? '—' : `${overview.teamSpeak.latencyMs} ms` }}</dd></div></dl></article><article class="overview-card"><header><div><h3>{{ tr('recentEvents') }}</h3><p>{{ tr('recentEventsLead') }}</p></div></header><ul class="event-list"><li v-for="event in overview.recentEvents" :key="`${event.event}-${event.createdAt}`"><span><Icon name="check" :size="14" /></span><div><strong>{{ eventName(event.event) }}</strong><small>{{ formatDate(event.createdAt) }}</small></div></li><li v-if="!overview.recentEvents.length" class="empty-event">{{ tr('noRecentEvents') }}</li></ul></article></div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from "vue";
|
||||
import { RouterLink, useRoute, useRouter } from "vue-router";
|
||||
import Icon from "../components/Icon.vue";
|
||||
|
||||
type Language = "zh" | "en";
|
||||
type Screen = "setup" | "login" | "admin";
|
||||
type AccessMode = "fixed" | "open";
|
||||
interface ProbeState { ok: boolean; protocol?: string | null; latencyMs?: number; serverName?: string | null; code?: string }
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const language = ref<Language>((localStorage.getItem("webspeak:language") as Language) || "zh");
|
||||
const loading = ref(true);
|
||||
const screen = ref<Screen>("login");
|
||||
const csrfToken = ref("");
|
||||
const setupStep = ref(1);
|
||||
const submitting = ref(false);
|
||||
const testing = ref(false);
|
||||
const errorMessage = ref("");
|
||||
const loginPassword = ref("");
|
||||
const testResult = ref<ProbeState | null>(null);
|
||||
|
||||
const setup = reactive({ bootstrapCode: "", adminPassword: "", confirmPassword: "", target: "127.0.0.1:9987", serverPassword: "", hasPassword: false, accessMode: "fixed" as AccessMode, siteName: "WebSpeak", welcomeText: "" });
|
||||
const serverForm = reactive({ target: "", serverPassword: "", passwordAction: "keep" as "keep" | "replace" | "remove", hasPassword: false, accessMode: "fixed" as AccessMode, siteName: "WebSpeak", welcomeText: "", detectedProtocol: null as string | null, lastTestAt: null as string | null, lastTestLatencyMs: null as number | null });
|
||||
const overview = reactive({ gateway: { version: "", uptimeSeconds: 0 }, teamSpeak: { target: "", status: "unknown", protocol: null as string | null, lastTestAt: null as string | null, latencyMs: null as number | null }, sessions: { active: 0, peak: 0, limit: 100 }, recentEvents: [] as Array<{ event: string; createdAt: string }>, legacyConfigImported: false });
|
||||
|
||||
const copy = {
|
||||
zh: {
|
||||
loading: "正在载入管理控制台…", adminConsole: "管理控制台", firstSetup: "首次配置", setupTitle: "几分钟内完成 WebSpeak 配置", setupLead: "建立管理员安全域、连接 TeamSpeak,并决定访客可以连接到哪里。", secureAdmin: "保护管理入口", secureAdminLead: "使用 Bootstrap 代码创建唯一的管理员密码。", connectTeamSpeak: "连接 TeamSpeak", connectTeamSpeakLead: "填写服务器地址并进行真实连接测试。", accessExperience: "访问与站点", accessExperienceLead: "选择访问策略并设置访客看到的内容。", stepCounter: "第 {{current}} / {{total}} 步", bootstrapCode: "Bootstrap 代码", bootstrapPlaceholder: "从启动日志中复制", newPassword: "新管理员密码", passwordPlaceholder: "至少 12 个字符", passwordHint: "无需特定符号组合,建议使用长且唯一的密码。", confirmPassword: "确认管理员密码", serverAddress: "TeamSpeak 服务器地址", serverPlaceholder: "例如 ts.example.com:9987", serverHint: "支持主机名、IPv4 与 [IPv6]:端口;不需要选择 TS3 或 TS6。", serverPassword: "服务器密码", optional: "可选", optionalPassword: "无密码则留空", passwordConfigured: "已配置密码(留空保持不变)", testConnection: "测试连接", testing: "正在测试…", connectionReady: "连接成功", connectionFailed: "连接失败", accessMode: "访客访问模式", fixedMode: "仅限此 TeamSpeak 服务器", fixedModeLead: "访客只需填写昵称,目标和密码由 WebSpeak 管理。", openMode: "允许访客输入其他服务器", openModeLead: "访客可输入公网 TeamSpeak 地址;内网和保留地址会被阻止。", siteName: "站点显示名称", welcomeText: "欢迎文本", back: "返回", continue: "继续", finishSetup: "完成配置", languageSwitch: "English", welcomeAdmin: "欢迎回来", loginLead: "输入管理员密码以管理此 WebSpeak 实例。", adminPassword: "管理员密码", login: "登录", overview: "概览", server: "服务器", openGuest: "打开访客页面", logout: "退出登录", gatewayRunning: "网关运行中", serverSettings: "服务器设置", serverSettingsLead: "管理默认 TeamSpeak 目标、访问策略和访客页面内容。", saving: "正在保存…", saveChanges: "保存更改", teamSpeakTarget: "TeamSpeak 目标", change: "修改", remove: "移除", accessAndIdentity: "访问与站点信息", runtimeFacts: "运行时信息", detectedProtocol: "检测到的协议", lastTest: "最近测试", latency: "延迟", internalPort: "内部端口", unknown: "未知", legacyImported: "已导入旧 config.json。WebSpeak 现在由管理控制台管理,原文件不会再作为实时配置源。", gotIt: "知道了", systemStatus: "系统状态", everythingRunning: "WebSpeak 正常运行", overviewLead: "管理服务可用;TeamSpeak 可达性以最近一次连接测试为准。", running: "运行中", gateway: "网关", activeSessions: "活动会话", peakSessions: "本次启动峰值 {{count}}", targetHealth: "目标状态", targetHealthLead: "最近一次短连接测试的结果。", manage: "管理", status: "状态", recentEvents: "最近事件", recentEventsLead: "仅记录管理和系统事件,不包含聊天内容。", noRecentEvents: "暂无事件", reachable: "可连接", unreachable: "不可连接", notTested: "尚未测试", setupPasswordsMismatch: "两次输入的密码不一致。", setupPasswordShort: "管理员密码至少需要 12 个字符。", connectionTestRequired: "请先成功测试 TeamSpeak 连接。", invalidBootstrap: "Bootstrap 代码无效。", invalidPassword: "管理员密码错误。", rateLimited: "尝试次数过多,请稍后再试。", requestFailed: "请求失败,请检查输入后重试。", saved: "设置已保存", loginEvent: "管理员登录成功", logoutEvent: "管理员退出登录", settingsEvent: "服务器设置已更新", initializedEvent: "管理员初始化完成", importedEvent: "已导入旧配置", testEvent: "连接测试完成",
|
||||
},
|
||||
en: {
|
||||
loading: "Loading the admin console…", adminConsole: "Admin Console", firstSetup: "FIRST SETUP", setupTitle: "Configure WebSpeak in a few minutes", setupLead: "Secure the admin area, connect TeamSpeak, and decide where guests may connect.", secureAdmin: "Secure admin access", secureAdminLead: "Use the bootstrap code to create the single administrator password.", connectTeamSpeak: "Connect TeamSpeak", connectTeamSpeakLead: "Enter the server address and run a real connection test.", accessExperience: "Access and site", accessExperienceLead: "Choose the access policy and guest-facing content.", stepCounter: "Step {{current}} of {{total}}", bootstrapCode: "Bootstrap code", bootstrapPlaceholder: "Copy it from the startup log", newPassword: "New admin password", passwordPlaceholder: "At least 12 characters", passwordHint: "No symbol template is required; use a long, unique password.", confirmPassword: "Confirm admin password", serverAddress: "TeamSpeak server address", serverPlaceholder: "e.g. ts.example.com:9987", serverHint: "Hostnames, IPv4 and [IPv6]:port are supported. TS3/TS6 is detected automatically.", serverPassword: "Server password", optional: "Optional", optionalPassword: "Leave blank when unused", passwordConfigured: "Password configured (leave blank to keep it)", testConnection: "Test connection", testing: "Testing…", connectionReady: "Connection ready", connectionFailed: "Connection failed", accessMode: "Guest access mode", fixedMode: "Only this TeamSpeak server", fixedModeLead: "Guests enter only a nickname; WebSpeak manages the target and password.", openMode: "Allow other TeamSpeak servers", openModeLead: "Guests may enter public TeamSpeak addresses; private and reserved networks are blocked.", siteName: "Site display name", welcomeText: "Welcome text", back: "Back", continue: "Continue", finishSetup: "Finish setup", languageSwitch: "中文", welcomeAdmin: "Welcome back", loginLead: "Enter the admin password to manage this WebSpeak instance.", adminPassword: "Admin password", login: "Sign in", overview: "Overview", server: "Server", openGuest: "Open guest page", logout: "Log out", gatewayRunning: "Gateway running", serverSettings: "Server settings", serverSettingsLead: "Manage the default TeamSpeak target, access policy, and guest-facing content.", saving: "Saving…", saveChanges: "Save changes", teamSpeakTarget: "TeamSpeak target", change: "Change", remove: "Remove", accessAndIdentity: "Access and site identity", runtimeFacts: "Runtime facts", detectedProtocol: "Detected protocol", lastTest: "Last test", latency: "Latency", internalPort: "Internal port", unknown: "Unknown", legacyImported: "Legacy config.json was imported. WebSpeak is now managed here and the old file is no longer a live configuration source.", gotIt: "Got it", systemStatus: "SYSTEM STATUS", everythingRunning: "WebSpeak is running", overviewLead: "The management service is available. TeamSpeak reachability reflects the latest connection test.", running: "Running", gateway: "Gateway", activeSessions: "Active sessions", peakSessions: "Peak this run: {{count}}", targetHealth: "Target health", targetHealthLead: "Result of the latest short-lived connection test.", manage: "Manage", status: "Status", recentEvents: "Recent events", recentEventsLead: "Only system and admin events are recorded; chat content is excluded.", noRecentEvents: "No recent events", reachable: "Reachable", unreachable: "Unreachable", notTested: "Not tested", setupPasswordsMismatch: "The two passwords do not match.", setupPasswordShort: "The admin password must be at least 12 characters.", connectionTestRequired: "Run a successful TeamSpeak connection test first.", invalidBootstrap: "The bootstrap code is invalid.", invalidPassword: "The admin password is incorrect.", rateLimited: "Too many attempts. Try again later.", requestFailed: "The request failed. Check the fields and try again.", saved: "Settings saved", loginEvent: "Administrator signed in", logoutEvent: "Administrator signed out", settingsEvent: "Server settings changed", initializedEvent: "Administrator setup completed", importedEvent: "Legacy configuration imported", testEvent: "Connection test completed",
|
||||
},
|
||||
} as const;
|
||||
|
||||
const zhCopyOverrides: Partial<Record<keyof typeof copy.zh, string>> = {
|
||||
secureAdminLead: "使用初始化代码创建唯一的管理员密码。",
|
||||
bootstrapCode: "初始化代码",
|
||||
invalidBootstrap: "初始化代码无效。",
|
||||
};
|
||||
function tr(key: keyof typeof copy.zh, vars: Record<string, string | number> = {}): string { let value: string = language.value === "zh" ? zhCopyOverrides[key] ?? copy.zh[key] : copy.en[key] ?? copy.zh[key]; for (const [name, replacement] of Object.entries(vars)) value = value.replaceAll(`{{${name}}}`, String(replacement)); return value; }
|
||||
const setupSteps = computed(() => [{ index: 1, title: tr('secureAdmin'), lead: tr('secureAdminLead') }, { index: 2, title: tr('connectTeamSpeak'), lead: tr('connectTeamSpeakLead') }, { index: 3, title: tr('accessExperience'), lead: tr('accessExperienceLead') }]);
|
||||
const passwordStrength = computed(() => Math.min(100, Math.max(8, setup.adminPassword.length * 5 + (/[\s\W]/.test(setup.adminPassword) ? 15 : 0))));
|
||||
const currentPageTitle = computed(() => route.path === "/admin/server" ? tr('server') : tr('overview'));
|
||||
const testResultText = computed(() => { if (!testResult.value) return ""; if (!testResult.value.ok) return errorText(testResult.value.code); return [testResult.value.protocol?.toUpperCase(), testResult.value.serverName, testResult.value.latencyMs == null ? null : `${testResult.value.latencyMs} ms`].filter(Boolean).join(" · "); });
|
||||
const targetStatusText = computed(() => overview.teamSpeak.status === "reachable" ? tr('reachable') : overview.teamSpeak.status === "unreachable" ? tr('unreachable') : tr('notTested'));
|
||||
|
||||
onMounted(bootstrapView);
|
||||
watch(() => [setup.target, setup.serverPassword], () => { if (!testing.value) testResult.value = null; });
|
||||
watch(() => [serverForm.target, serverForm.serverPassword, serverForm.passwordAction], () => { if (!testing.value && screen.value === "admin") testResult.value = null; });
|
||||
|
||||
async function bootstrapView() { loading.value = true; try { const session = await getJson("/api/admin/session"); if (!session.initialized) { screen.value = "setup"; if (route.path !== "/admin/setup") await router.replace("/admin/setup"); } else if (!session.authenticated) { screen.value = "login"; if (route.path !== "/admin/login") await router.replace("/admin/login"); } else { csrfToken.value = String(session.csrfToken || ""); screen.value = "admin"; if (route.path === "/admin/login" || route.path === "/admin/setup") await router.replace("/admin"); await Promise.all([loadOverview(), loadServerSettings()]); } } catch { errorMessage.value = tr('requestFailed'); } finally { loading.value = false; } }
|
||||
function applySetupDefaults(value: Record<string, unknown>) { if (typeof value.target === "string") setup.target = value.target; if (value.accessMode === "open") setup.accessMode = "open"; if (typeof value.siteName === "string") setup.siteName = value.siteName; if (typeof value.welcomeText === "string") setup.welcomeText = value.welcomeText; setup.hasPassword = Boolean(value.hasPassword); }
|
||||
function goToSetupStep(step: number) { if (step < setupStep.value) setupStep.value = step; }
|
||||
async function nextSetupStep() { errorMessage.value = ""; if (setupStep.value === 1) { if (setup.adminPassword.length < 12) return void (errorMessage.value = tr('setupPasswordShort')); if (setup.adminPassword !== setup.confirmPassword) return void (errorMessage.value = tr('setupPasswordsMismatch')); submitting.value = true; try { applySetupDefaults(await sendJson("/api/admin/setup/defaults", "POST", { bootstrapCode: setup.bootstrapCode }, false)); setupStep.value = 2; } catch (error) { errorMessage.value = errorText((error as ApiError).code); } finally { submitting.value = false; } return; } if (setupStep.value === 2) { if (!testResult.value?.ok) return void (errorMessage.value = tr('connectionTestRequired')); setupStep.value = 3; return; } await finishSetup(); }
|
||||
async function testSetupConnection() { await runTest("/api/admin/setup/test", { bootstrapCode: setup.bootstrapCode, target: setup.target, serverPassword: setup.serverPassword, passwordAction: setup.serverPassword ? "replace" : "keep" }); }
|
||||
async function finishSetup() { submitting.value = true; try { const result = await sendJson("/api/admin/setup", "POST", { bootstrapCode: setup.bootstrapCode, adminPassword: setup.adminPassword, target: setup.target, serverPassword: setup.serverPassword, passwordAction: setup.serverPassword ? "replace" : "keep", accessMode: setup.accessMode, siteName: setup.siteName, welcomeText: setup.welcomeText }, false); csrfToken.value = String(result.csrfToken || ""); screen.value = "admin"; await router.replace("/admin"); await Promise.all([loadOverview(), loadServerSettings()]); } catch (error) { errorMessage.value = errorText((error as ApiError).code); } finally { submitting.value = false; } }
|
||||
async function login() { submitting.value = true; errorMessage.value = ""; try { const result = await sendJson("/api/admin/login", "POST", { password: loginPassword.value }, false); csrfToken.value = String(result.csrfToken || ""); loginPassword.value = ""; screen.value = "admin"; await router.replace("/admin"); await Promise.all([loadOverview(), loadServerSettings()]); } catch (error) { errorMessage.value = errorText((error as ApiError).code); } finally { submitting.value = false; } }
|
||||
async function logout() { try { await sendJson("/api/admin/logout", "POST", {}); } finally { csrfToken.value = ""; screen.value = "login"; await router.replace("/admin/login"); } }
|
||||
async function loadOverview() { Object.assign(overview, await getJson("/api/admin/overview")); }
|
||||
async function loadServerSettings() { const value = await getJson("/api/admin/server"); Object.assign(serverForm, value, { serverPassword: "", passwordAction: "keep" }); }
|
||||
async function saveServerSettings() { submitting.value = true; errorMessage.value = ""; try { const result = await sendJson("/api/admin/server", "PUT", serverPayload()); Object.assign(serverForm, result.settings, { serverPassword: "", passwordAction: "keep" }); await loadOverview(); } catch (error) { errorMessage.value = errorText((error as ApiError).code); } finally { submitting.value = false; } }
|
||||
async function testServerConnection() { await runTest("/api/admin/server/test", { target: serverForm.target, serverPassword: serverForm.passwordAction === "replace" ? serverForm.serverPassword : undefined, passwordAction: serverForm.passwordAction }); if (testResult.value?.ok) { await loadOverview(); serverForm.detectedProtocol = testResult.value.protocol ?? null; serverForm.lastTestAt = new Date().toISOString(); serverForm.lastTestLatencyMs = testResult.value.latencyMs ?? null; } }
|
||||
function serverPayload() { return { target: serverForm.target, serverPassword: serverForm.passwordAction === "replace" ? serverForm.serverPassword : undefined, passwordAction: serverForm.passwordAction, accessMode: serverForm.accessMode, siteName: serverForm.siteName, welcomeText: serverForm.welcomeText }; }
|
||||
async function runTest(url: string, body: Record<string, unknown>) { testing.value = true; errorMessage.value = ""; testResult.value = null; try { testResult.value = await sendJson(url, "POST", body, url.includes("/server/test")); } catch (error) { testResult.value = { ok: false, code: (error as ApiError).code }; } finally { testing.value = false; } }
|
||||
async function dismissLegacyNotice() { await sendJson("/api/admin/legacy-import/dismiss", "POST", {}); overview.legacyConfigImported = false; }
|
||||
function toggleLanguage() { language.value = language.value === "zh" ? "en" : "zh"; localStorage.setItem("webspeak:language", language.value); }
|
||||
function formatDate(value: string | null) { return value ? new Intl.DateTimeFormat(language.value === "zh" ? "zh-CN" : "en-US", { dateStyle: "medium", timeStyle: "short" }).format(new Date(value)) : "—"; }
|
||||
function formatUptime(seconds: number) { const hours = Math.floor(seconds / 3600); const minutes = Math.floor((seconds % 3600) / 60); return language.value === "zh" ? `已运行 ${hours} 小时 ${minutes} 分钟` : `Up ${hours}h ${minutes}m`; }
|
||||
function eventName(event: string) { if (event === "ADMIN_LOGIN_FAILED") return language.value === "zh" ? "管理员登录失败" : "Administrator login failed"; if (event === "CONNECTION_TEST_SUCCEEDED") return language.value === "zh" ? "连接测试成功" : "Connection test succeeded"; if (event === "CONNECTION_TEST_FAILED") return language.value === "zh" ? "连接测试失败" : "Connection test failed"; const names: Record<string, keyof typeof copy.zh> = { ADMIN_LOGIN_SUCCEEDED: "loginEvent", ADMIN_LOGOUT: "logoutEvent", SETTINGS_CHANGED: "settingsEvent", ADMIN_INITIALIZED: "initializedEvent", LEGACY_CONFIG_IMPORTED: "importedEvent", CONNECTION_TEST: "testEvent" }; return names[event] ? tr(names[event]) : language.value === "zh" ? "系统事件" : event.replaceAll("_", " "); }
|
||||
function errorText(code?: string) { if (code === "INVALID_BOOTSTRAP") return tr('invalidBootstrap'); if (code === "INVALID_PASSWORD") return tr('invalidPassword'); if (code === "INVALID_ADMIN_PASSWORD") return tr('setupPasswordShort'); if (code === "RATE_LIMITED") return tr('rateLimited'); const probe: Record<string, { zh: string; en: string }> = { INVALID_TARGET: { zh: "TeamSpeak 服务器地址格式无效。", en: "The TeamSpeak server address is invalid." }, HOST_NOT_FOUND: { zh: "找不到服务器主机名。", en: "The server hostname could not be resolved." }, UNREACHABLE: { zh: "无法连接 TeamSpeak 服务器。", en: "The TeamSpeak server is unreachable." }, TIMEOUT: { zh: "连接 TeamSpeak 超时。", en: "The TeamSpeak connection timed out." }, PROTOCOL_NEGOTIATION_FAILED: { zh: "无法识别 TeamSpeak 协议。", en: "TeamSpeak protocol negotiation failed." }, SERVER_REJECTED: { zh: "TeamSpeak 服务器拒绝了连接。", en: "The TeamSpeak server rejected the connection." }, TARGET_NOT_ALLOWED: { zh: "此地址不允许在开放模式中使用。", en: "This target is not allowed in open mode." } }; return probe[code || ""]?.[language.value] ?? tr('requestFailed'); }
|
||||
|
||||
interface ApiError extends Error { code?: string }
|
||||
async function getJson(url: string): Promise<any> { const response = await fetch(url, { headers: { accept: "application/json" } }); return parseResponse(response); }
|
||||
async function sendJson(url: string, method: string, body: unknown, authenticated = true): Promise<any> { const response = await fetch(url, { method, headers: { "content-type": "application/json", accept: "application/json", ...(authenticated && csrfToken.value ? { "x-csrf-token": csrfToken.value } : {}) }, body: JSON.stringify(body) }); return parseResponse(response); }
|
||||
async function parseResponse(response: Response) { const value = await response.json().catch(() => ({})); if (!response.ok) { const error = new Error(String(value.code || response.statusText)) as ApiError; error.code = String(value.code || "REQUEST_FAILED"); if (response.status === 401 && screen.value === "admin") { screen.value = "login"; void router.replace("/admin/login"); } throw error; } return value; }
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.intro-copy h1{font-size:clamp(38px,4.2vw,56px)!important;line-height:1.05!important;letter-spacing:-.055em!important}
|
||||
:global(*){box-sizing:border-box}:global(body){margin:0;font-family:Inter,"Segoe UI","PingFang SC",sans-serif;color:#20302c;background:#f4f8f6}.admin-root{min-height:100dvh}.auth-layout{display:grid;min-height:100dvh;grid-template-columns:minmax(360px,.82fr) minmax(520px,1.18fr)}.auth-intro{display:flex;flex-direction:column;padding:48px clamp(38px,6vw,92px);color:#e8fffa;background:radial-gradient(circle at 20% 0,rgba(90,211,191,.28),transparent 32rem),#063f3b}.admin-brand{display:flex;align-items:center;gap:12px}.admin-brand>span{display:grid;place-items:center;width:42px;height:42px;color:#fff;background:#07877d;border-radius:12px;box-shadow:0 8px 22px rgba(0,0,0,.15)}.admin-brand strong,.admin-brand small{display:block}.admin-brand strong{font-size:20px;letter-spacing:-.04em}.admin-brand small{margin-top:3px;color:#9bc9c2;font-size:11px}.intro-copy{margin:auto 0 48px}.intro-copy i{color:#75e3d2;font-size:12px;font-style:normal;font-weight:800;letter-spacing:.12em}.intro-copy h1{max-width:540px;margin:16px 0;font-size:clamp(40px,5vw,66px);line-height:1.03;letter-spacing:-.065em}.intro-copy p{max-width:530px;color:#a9d0ca;font-size:16px;line-height:1.75}.step-list{display:grid;gap:10px}.step-list button{display:flex;align-items:center;gap:13px;width:100%;padding:13px;color:#89bbb4;text-align:left;background:transparent;border:1px solid transparent;border-radius:12px}.step-list button.active{color:#fff;background:rgba(255,255,255,.08);border-color:rgba(255,255,255,.1)}.step-list button.done{color:#8ee4d7}.step-list button>span{display:grid;place-items:center;width:28px;height:28px;flex:none;border:1px solid currentColor;border-radius:50%;font-size:12px;font-weight:800}.step-list strong,.step-list small{display:block}.step-list strong{font-size:13px}.step-list small{margin-top:3px;font-size:10px;opacity:.75}.auth-panel{position:relative;display:grid;place-items:center;padding:80px 40px;background:radial-gradient(circle at 80% 10%,rgba(99,205,188,.15),transparent 25rem),#f5f9f7}.panel-tools{position:absolute;top:28px;right:34px}.panel-tools button,.language-link,.admin-topbar button{color:#08766e;background:#e4f3ef;border:1px solid #cae7e0;border-radius:8px;padding:8px 12px;font-size:11px;font-weight:700;cursor:pointer}.setup-card,.login-card{width:min(560px,100%);padding:36px;background:#fff;border:1px solid #dfeae6;border-radius:20px;box-shadow:0 20px 55px rgba(27,69,61,.09)}.setup-card header small{color:#07877d;font-size:11px;font-weight:800;letter-spacing:.08em}.setup-card header h2,.login-card h1{margin:10px 0 7px;font-size:29px;letter-spacing:-.045em}.setup-card header p,.login-card header p{margin:0;color:#71817c;font-size:13px;line-height:1.6}.form-stack,.login-card form{display:grid;gap:17px;margin-top:27px}label>span,fieldset legend{display:block;margin-bottom:7px;color:#40514c;font-size:12px;font-weight:700}label em{color:#91a09c;font-size:10px;font-style:normal;font-weight:500}label small{display:block;margin-top:6px;color:#899792;font-size:10px;line-height:1.5}input,textarea{width:100%;padding:11px 12px;color:#22332f;background:#fbfdfc;border:1px solid #dbe7e3;border-radius:9px;font:inherit;font-size:13px;outline:none}input{height:43px}input:focus,textarea:focus{border-color:#54bdb2;box-shadow:0 0 0 3px rgba(84,189,178,.13)}textarea{resize:vertical}.strength{height:4px;overflow:hidden;background:#e7eeeb;border-radius:4px}.strength i{display:block;height:100%;background:linear-gradient(90deg,#e7a452,#50c5a2);transition:.2s}fieldset{display:grid;gap:9px;margin:0;padding:0;border:0}.choice{display:flex;align-items:flex-start;gap:10px;padding:13px;border:1px solid #dfe9e6;border-radius:10px;cursor:pointer}.choice:has(input:checked){border-color:#62bfb5;background:#eff8f6}.choice input{width:16px;height:16px;flex:none;margin:2px 0}.choice strong,.choice small{display:block}.choice strong{font-size:12px}.choice small{margin-top:4px;color:#7b8985;font-size:10px;line-height:1.45}.setup-card footer{display:flex;align-items:center;justify-content:space-between;margin-top:28px;padding-top:20px;border-top:1px solid #edf1ef}.primary-button,.secondary-button,.text-button{display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:42px;padding:0 18px;border:0;border-radius:9px;font-size:12px;font-weight:800;cursor:pointer}.primary-button{color:#fff;background:#087d74}.primary-button:hover{background:#056b63}.primary-button:disabled,.secondary-button:disabled{opacity:.55;cursor:not-allowed}.secondary-button{color:#08776e;background:#eaf6f3;border:1px solid #cfe9e3}.text-button{color:#687a74;background:transparent}.wide{width:100%}.spinner{display:inline-block;width:22px;height:22px;border:2px solid #cde6df;border-top-color:#087d74;border-radius:50%;animation:spin .7s linear infinite}.spinner.small{width:15px;height:15px;border-color:rgba(255,255,255,.35);border-top-color:currentColor}@keyframes spin{to{transform:rotate(360deg)}}.alert{padding:12px 14px;border-radius:9px;font-size:12px;linLine truncated
|
||||
@media(max-width:850px){.auth-layout{display:block}.auth-intro{min-height:auto;padding:28px 24px}.intro-copy{margin:55px 0 35px}.step-list{display:none}.auth-panel{padding:35px 18px 60px}.panel-tools{top:18px;right:18px}.admin-shell{display:block}.admin-sidebar{position:static;width:100%;height:auto;flex-direction:row;align-items:center;padding:12px 16px}.admin-sidebar .admin-brand{padding:0}.admin-sidebar .admin-brand small{display:none}.admin-sidebar nav{display:flex;margin-left:auto}.admin-sidebar nav a{font-size:0}.admin-sidebar nav a .ui-icon{width:20px;height:20px}.sidebar-bottom{display:flex;margin:0 0 0 8px;padding:0;border:0}.sidebar-bottom a{display:none}.sidebar-bottom button{font-size:0}.settings-grid,.overview-columns{grid-template-columns:1fr}.readonly-card dl{grid-template-columns:1fr 1fr}.admin-topbar{padding:0 18px}.page-content{width:min(100% - 28px,700px);padding-top:24px}.metric-grid{grid-template-columns:1fr}.hero-status{align-items:flex-start;gap:20px}.hero-status p{max-width:75%}}
|
||||
@media(max-width:520px){.setup-card,.login-card{padding:25px 20px;border-radius:15px}.setup-card header h2{font-size:24px}.admin-topbar>div:last-child{font-size:0}.page-heading{gap:15px}.page-heading .primary-button{padding-inline:12px}.settings-card,.readonly-card,.overview-card{padding:18px}.readonly-card dl,.overview-card dl{grid-template-columns:1fr}.password-row{grid-template-columns:1fr}.password-actions{padding:0}.hero-status{padding:23px}.status-badge{display:none}}
|
||||
</style>
|
||||
+66
-146
@@ -6,18 +6,18 @@
|
||||
<div class="brand-lockup">
|
||||
<div class="brand-mark"><Icon name="waveform" :size="22" /></div>
|
||||
<div>
|
||||
<strong>TeamSpeak <span>Web</span></strong>
|
||||
<strong>{{ siteName }}</strong>
|
||||
<small>{{ t('browserWorkspace') }}</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="header-tools"><div class="header-note"><span class="tiny-dot"></span> {{ t('secureGateway') }}</div><button class="guide-button" type="button" :title="t('configGuide')" @click="configGuideOpen = true"><Icon name="help" :size="15" /> {{ t('configGuide') }}</button><button class="language-switch" :aria-label="t('langSwitch')" @click="toggleLanguage">{{ t('langSwitch') }}</button></div>
|
||||
<div class="header-tools"><div class="header-note"><span class="tiny-dot"></span> {{ t('secureGateway') }}</div><a class="guide-button" href="/admin"><Icon name="settings" :size="15" /> {{ t('adminConsole') }}</a><button class="language-switch" :aria-label="t('langSwitch')" @click="toggleLanguage">{{ t('langSwitch') }}</button></div>
|
||||
</header>
|
||||
|
||||
<main class="join-content">
|
||||
<div class="join-copy">
|
||||
<div class="eyebrow"><span class="eyebrow-dot"></span> {{ t('privateAudio') }}</div>
|
||||
<h1>{{ t('joinLine1') }}<br /><em>{{ t('joinLine2') }}</em></h1>
|
||||
<p class="join-description">{{ t('joinDescription') }}</p>
|
||||
<p class="join-description">{{ welcomeText || t('joinDescription') }}</p>
|
||||
<div class="promise-list">
|
||||
<div class="promise-item"><span class="promise-icon"><Icon name="waveform" :size="16" /></span><span><b>{{ t('highQuality') }}</b><small>{{ t('opusAudio') }}</small></span></div>
|
||||
<div class="promise-item"><span class="promise-icon mint"><Icon name="shield" :size="16" /></span><span><b>{{ t('secureJoin') }}</b><small>{{ t('inviteProtected') }}</small></span></div>
|
||||
@@ -32,19 +32,19 @@
|
||||
|
||||
<div v-if="voiceState.error" class="notice error-notice"><span class="notice-symbol">!</span><span>{{ localizedMessage(voiceState.error) }}</span></div>
|
||||
<div v-if="browserError" class="notice warning-notice"><span class="notice-symbol">i</span><span>{{ localizedMessage(browserError) }}</span></div>
|
||||
<div v-if="!serverConfigLoading && !initialized" class="notice warning-notice"><span class="notice-symbol">i</span><span>{{ t('notConfigured') }} <a href="/admin/setup">{{ t('configureNow') }}</a></span></div>
|
||||
|
||||
<form class="join-form" @submit.prevent="doConnect">
|
||||
<div class="field-grid">
|
||||
<div>
|
||||
<label class="field-label" for="server-host">{{ t('serverAddress') }}</label>
|
||||
<div class="field-wrap"><Icon name="server" :size="17" /><input id="server-host" v-model="serverHost" autocomplete="url" :placeholder="t('serverAddressPlaceholder')" /></div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="field-label" for="server-port">{{ t('serverPort') }}</label>
|
||||
<div class="field-wrap"><Icon name="hash" :size="17" /><input id="server-port" v-model="serverPort" inputmode="numeric" type="number" min="1" max="65535" :placeholder="t('serverPortPlaceholder')" /></div>
|
||||
</div>
|
||||
<form v-if="initialized" class="join-form" @submit.prevent="doConnect">
|
||||
<div v-if="accessMode === 'open'">
|
||||
<label class="field-label" for="server-address">{{ t('serverAddress') }}</label>
|
||||
<div class="field-wrap"><Icon name="server" :size="17" /><input id="server-address" v-model="serverAddress" autocomplete="url" :placeholder="t('serverAddressPlaceholder')" /></div>
|
||||
</div>
|
||||
<p class="field-hint">{{ t('serverAddressHint') }}</p>
|
||||
<p v-if="accessMode === 'open'" class="field-hint">{{ t('serverAddressHint') }}</p>
|
||||
|
||||
<template v-if="accessMode === 'open'">
|
||||
<label class="field-label" for="server-password">{{ t('serverPassword') }} <span>{{ t('optional') }}</span></label>
|
||||
<div class="field-wrap"><Icon name="lock" :size="17" /><input id="server-password" v-model="serverPassword" type="password" autocomplete="off" :placeholder="t('optionalPassword')" /></div>
|
||||
</template>
|
||||
|
||||
<label class="field-label" for="nickname">{{ t('nickname') }}</label>
|
||||
<div class="field-wrap">
|
||||
@@ -58,7 +58,7 @@
|
||||
<input id="channel" v-model="channel" :placeholder="t('emptyDefault')" @keyup.enter="doConnect" />
|
||||
</div>
|
||||
|
||||
<button class="primary-button connect-button" :disabled="!nickname.trim() || !validServerPort || !serverHost.trim() || serverConfigLoading || voiceState.connecting" type="submit">
|
||||
<button class="primary-button connect-button" :disabled="!canJoin || serverConfigLoading || voiceState.connecting" type="submit">
|
||||
<span v-if="voiceState.connecting" class="button-spinner"></span>
|
||||
<span>{{ voiceState.connecting ? t('connecting') : t('enterVoice') }}</span>
|
||||
<Icon v-if="!voiceState.connecting" name="chevron-right" :size="17" />
|
||||
@@ -161,23 +161,6 @@
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<!-- Configuration guide modal -->
|
||||
<div v-if="configGuideOpen" class="modal-backdrop config-guide-backdrop" @click.self="configGuideOpen = false">
|
||||
<section class="config-guide-modal" role="dialog" aria-modal="true" :aria-labelledby="'config-guide-title'">
|
||||
<header class="config-guide-header"><div><span class="card-kicker">{{ t('configGuideKicker') }}</span><h2 id="config-guide-title">{{ t('configGuideTitle') }}</h2><p>{{ t('configGuideLead') }}</p></div><button class="round-icon" type="button" :title="t('close')" @click="configGuideOpen = false"><Icon name="close" :size="19" /></button></header>
|
||||
<div class="config-guide-content">
|
||||
<div class="config-guide-steps">
|
||||
<article><span>1</span><div><strong>{{ t('configStepCopyTitle') }}</strong><p>{{ t('configStepCopyLead') }}</p><code>cp config.example.json config.json</code></div></article>
|
||||
<article><span>2</span><div><strong>{{ t('configStepEditTitle') }}</strong><p>{{ t('configStepEditLead') }}</p></div></article>
|
||||
<article><span>3</span><div><strong>{{ t('configStepRestartTitle') }}</strong><p>{{ t('configStepRestartLead') }}</p><code>node dist/index.js</code></div></article>
|
||||
</div>
|
||||
<section class="config-editor"><div class="config-editor-heading"><div><span class="section-kicker">{{ t('configPreview') }}</span><strong>{{ t('configPreviewLead') }}</strong></div><button class="copy-config-button" type="button" @click="copyConfigTemplate"><Icon name="copy" :size="15" /> {{ t('copyConfig') }}</button></div><div class="config-guide-fields"><label class="config-guide-wide"><span>{{ t('serverPassword') }}</span><input v-model="guideServerPassword" type="password" :placeholder="t('optionalPassword')" /></label></div><pre>{{ configTemplate }}</pre></section>
|
||||
<div class="config-guide-note"><Icon name="help" :size="16" /><span>{{ t('configGuideNote') }}</span></div>
|
||||
</div>
|
||||
<footer class="config-guide-footer"><button class="text-button" type="button" @click="configGuideOpen = false">{{ t('close') }}</button><button class="primary-button save-button" type="button" @click="copyConfigTemplate"><Icon name="copy" :size="16" /> {{ t('copyConfig') }}</button></footer>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- Audio settings modal -->
|
||||
<div v-if="settingsOpen" class="modal-backdrop" @click.self="settingsOpen = false">
|
||||
<section class="settings-modal" role="dialog" aria-modal="true" :aria-labelledby="'settings-title'">
|
||||
@@ -237,16 +220,18 @@ const query = new URLSearchParams(location.search);
|
||||
const initialChannel = query.get("channel") ?? "";
|
||||
const nickname = ref(localStorage.getItem("webspeak:nickname") ?? "");
|
||||
const channel = ref(initialChannel);
|
||||
const serverHost = ref(query.get("tsHost") ?? localStorage.getItem("webspeak:ts-host") ?? location.hostname);
|
||||
const serverPort = ref(query.get("tsPort") ?? localStorage.getItem("webspeak:ts-port") ?? "9987");
|
||||
const serverAddress = ref(initialServerAddress());
|
||||
const serverPassword = ref("");
|
||||
const accessMode = ref<"fixed" | "open">("fixed");
|
||||
const initialized = ref(false);
|
||||
const siteName = ref("WebSpeak");
|
||||
const welcomeText = ref("");
|
||||
const browserError = ref("");
|
||||
const serverConfigLoading = ref(true);
|
||||
const memberQuery = ref("");
|
||||
const messageDraft = ref("");
|
||||
const selectedChannelId = ref("");
|
||||
const settingsOpen = ref(false);
|
||||
const configGuideOpen = ref(false);
|
||||
const guideServerPassword = ref("");
|
||||
const audioSettingsError = ref("");
|
||||
const pttActive = ref(false);
|
||||
const toast = ref("");
|
||||
@@ -259,6 +244,9 @@ const translations: Record<Language, Record<string, string>> = {
|
||||
zh: {
|
||||
browserWorkspace: "浏览器语音工作台",
|
||||
secureGateway: "安全语音网关",
|
||||
adminConsole: "管理控制台",
|
||||
notConfigured: "WebSpeak 尚未完成首次配置。",
|
||||
configureNow: "立即配置",
|
||||
privateAudio: "私密社区语音",
|
||||
joinLine1: "连接服务器,",
|
||||
joinLine2: "马上开始交流。",
|
||||
@@ -277,8 +265,6 @@ const translations: Record<Language, Record<string, string>> = {
|
||||
joinLead: "输入一个昵称,选择进入的频道。",
|
||||
serverAddress: "TeamSpeak 服务器地址",
|
||||
serverAddressPlaceholder: "例如:ts.example.com 或 127.0.0.1",
|
||||
serverPort: "语音端口",
|
||||
serverPortPlaceholder: "9987",
|
||||
serverAddressHint: "这是网关服务器连接的 TeamSpeak 地址,不是浏览器直接连接地址。",
|
||||
nickname: "你的昵称",
|
||||
nicknamePlaceholder: "例如:Alex Rivera",
|
||||
@@ -301,22 +287,6 @@ const translations: Record<Language, Record<string, string>> = {
|
||||
serverOptions: "更多服务器选项",
|
||||
online: "在线",
|
||||
audioSettings: "音频设置",
|
||||
configGuide: "配置引导",
|
||||
configGuideKicker: "首次部署",
|
||||
configGuideTitle: "完成服务端配置",
|
||||
configGuideLead: "按下面三步准备 config.json,网页客户端就能连接你指定的 TeamSpeak 服务器。",
|
||||
configStepCopyTitle: "复制配置模板",
|
||||
configStepCopyLead: "在项目根目录执行命令,创建服务端配置文件。",
|
||||
configStepEditTitle: "确认连接参数",
|
||||
configStepEditLead: "在下方预览中确认 TeamSpeak 服务器地址、语音端口和密码;应用端口固定为 3040,协议会自动检测。",
|
||||
configStepRestartTitle: "保存并重启服务",
|
||||
configStepRestartLead: "保存 config.json 后重新启动 WebSpeak 服务,新的默认配置才会生效。",
|
||||
configPreview: "配置预览",
|
||||
configPreviewLead: "复制下面的 JSON 到项目根目录的 config.json",
|
||||
copyConfig: "复制配置",
|
||||
configGuideNote: "浏览器不能直接写入服务器文件;复制后请在运行 WebSpeak 的服务器上保存 config.json。",
|
||||
configCopiedToast: "配置 JSON 已复制",
|
||||
configCopyFailedToast: "复制失败,请手动复制配置内容",
|
||||
serverPassword: "服务器密码",
|
||||
optionalPassword: "没有密码可留空",
|
||||
switchChannel: "切换频道",
|
||||
@@ -410,6 +380,9 @@ const translations: Record<Language, Record<string, string>> = {
|
||||
en: {
|
||||
browserWorkspace: "Browser voice workspace",
|
||||
secureGateway: "Secure voice gateway",
|
||||
adminConsole: "Admin console",
|
||||
notConfigured: "WebSpeak setup has not been completed.",
|
||||
configureNow: "Configure now",
|
||||
privateAudio: "Private community audio",
|
||||
joinLine1: "Connect to your server,",
|
||||
joinLine2: "start the conversation.",
|
||||
@@ -428,8 +401,6 @@ const translations: Record<Language, Record<string, string>> = {
|
||||
joinLead: "Choose a nickname and the channel to enter.",
|
||||
serverAddress: "TeamSpeak server address",
|
||||
serverAddressPlaceholder: "e.g. ts.example.com or 127.0.0.1",
|
||||
serverPort: "Voice port",
|
||||
serverPortPlaceholder: "9987",
|
||||
serverAddressHint: "This is the TeamSpeak address reached by the gateway, not a direct browser connection.",
|
||||
nickname: "Your nickname",
|
||||
nicknamePlaceholder: "e.g. Alex Rivera",
|
||||
@@ -452,22 +423,6 @@ const translations: Record<Language, Record<string, string>> = {
|
||||
serverOptions: "More server options",
|
||||
online: "Online",
|
||||
audioSettings: "Audio settings",
|
||||
configGuide: "Setup guide",
|
||||
configGuideKicker: "FIRST DEPLOYMENT",
|
||||
configGuideTitle: "Finish server configuration",
|
||||
configGuideLead: "Follow these three steps to prepare config.json for the TeamSpeak server you want to use.",
|
||||
configStepCopyTitle: "Copy the template",
|
||||
configStepCopyLead: "Run the command in the project root to create the server configuration file.",
|
||||
configStepEditTitle: "Confirm connection settings",
|
||||
configStepEditLead: "Confirm the TeamSpeak address, voice port, and password below; WebSpeak listens on fixed port 3040 and detects the protocol automatically.",
|
||||
configStepRestartTitle: "Save and restart",
|
||||
configStepRestartLead: "Save config.json and restart WebSpeak for the new default settings to take effect.",
|
||||
configPreview: "CONFIG PREVIEW",
|
||||
configPreviewLead: "Copy this JSON into config.json in the project root",
|
||||
copyConfig: "Copy config",
|
||||
configGuideNote: "A browser cannot write files on the server. Copy this content, then save config.json on the machine running WebSpeak.",
|
||||
configCopiedToast: "Config JSON copied",
|
||||
configCopyFailedToast: "Copy failed. Copy the configuration manually",
|
||||
serverPassword: "Server password",
|
||||
optionalPassword: "Leave blank if not required",
|
||||
switchChannel: "Switch channel",
|
||||
@@ -560,6 +515,17 @@ const translations: Record<Language, Record<string, string>> = {
|
||||
},
|
||||
};
|
||||
|
||||
function initialServerAddress(): string {
|
||||
const explicit = query.get("server") ?? query.get("target") ?? localStorage.getItem("webspeak:server-target");
|
||||
if (explicit?.trim()) return explicit.trim();
|
||||
const host = (query.get("tsHost") ?? localStorage.getItem("webspeak:ts-host") ?? location.hostname).trim();
|
||||
const port = (query.get("tsPort") ?? localStorage.getItem("webspeak:ts-port") ?? "9987").trim();
|
||||
if (!host) return `127.0.0.1:${port}`;
|
||||
if (/^[^:]+:\d+$/.test(host) || /^\[[^\]]+\]:\d+$/.test(host)) return host;
|
||||
if (host.startsWith("[") || !host.includes(":")) return `${host}:${port}`;
|
||||
return `[${host}]:${port}`;
|
||||
}
|
||||
|
||||
function getInitialLanguage(): Language {
|
||||
const stored = localStorage.getItem("webspeak:language");
|
||||
if (stored === "zh" || stored === "en") return stored;
|
||||
@@ -586,6 +552,9 @@ function localizedMessage(message: string) {
|
||||
"TeamSpeak 服务器地址无效": "The TeamSpeak server address is invalid",
|
||||
"TeamSpeak 服务器连接失败": "Could not connect to the TeamSpeak server",
|
||||
"服务器当前已满,请稍后重试": "The server is full. Try again shortly",
|
||||
"WebSpeak 尚未完成首次配置": "WebSpeak setup has not been completed",
|
||||
"此 TeamSpeak 服务器地址不允许连接": "This TeamSpeak server address is not allowed",
|
||||
"请输入有效的昵称": "Enter a valid nickname",
|
||||
};
|
||||
if (exact[message]) return exact[message];
|
||||
if (message.startsWith("麦克风访问失败:")) return `Microphone access failed: ${message.slice(8)}`;
|
||||
@@ -681,18 +650,16 @@ onUnmounted(() => {
|
||||
});
|
||||
|
||||
function doConnect() {
|
||||
const host = serverHost.value.trim();
|
||||
const port = Number.parseInt(serverPort.value, 10);
|
||||
if (!nickname.value.trim() || !host || !validServerPort.value || voiceState.connecting) return;
|
||||
if (!canJoin.value || voiceState.connecting) return;
|
||||
clearError();
|
||||
nickname.value = nickname.value.trim();
|
||||
serverHost.value = host;
|
||||
serverPort.value = String(port);
|
||||
localStorage.setItem("webspeak:nickname", nickname.value);
|
||||
localStorage.setItem("webspeak:ts-host", host);
|
||||
localStorage.setItem("webspeak:ts-port", String(port));
|
||||
if (accessMode.value === "open") {
|
||||
serverAddress.value = serverAddress.value.trim();
|
||||
localStorage.setItem("webspeak:server-target", serverAddress.value);
|
||||
}
|
||||
selectedChannelId.value = "";
|
||||
connect(host, port, channel.value.trim(), nickname.value);
|
||||
connect(serverAddress.value, channel.value.trim(), nickname.value, accessMode.value === "open" ? serverPassword.value : "");
|
||||
}
|
||||
|
||||
function doDisconnect() {
|
||||
@@ -719,50 +686,34 @@ function channelLabel(item: TreeChannel) {
|
||||
function doShare() {
|
||||
const invite = new URL(location.href);
|
||||
invite.searchParams.delete("token");
|
||||
if (serverHost.value.trim()) invite.searchParams.set("tsHost", serverHost.value.trim());
|
||||
if (validServerPort.value) invite.searchParams.set("tsPort", String(Number.parseInt(serverPort.value, 10)));
|
||||
invite.searchParams.delete("target");
|
||||
invite.searchParams.delete("tsHost");
|
||||
invite.searchParams.delete("tsPort");
|
||||
invite.searchParams.delete("server");
|
||||
if (accessMode.value === "open" && serverAddress.value.trim()) invite.searchParams.set("server", serverAddress.value.trim());
|
||||
if (channel.value) invite.searchParams.set("channel", channel.value);
|
||||
navigator.clipboard?.writeText(invite.toString()).then(() => showToast(t("copiedToast")), () => showToast(t("copyFailedToast")));
|
||||
}
|
||||
|
||||
const validServerPort = computed(() => {
|
||||
const port = Number.parseInt(serverPort.value, 10);
|
||||
return Number.isInteger(port) && port > 0 && port <= 65535;
|
||||
});
|
||||
|
||||
const configTemplate = computed(() => {
|
||||
const tsPort = Number.parseInt(serverPort.value, 10);
|
||||
const config: Record<string, unknown> = {
|
||||
tsHost: serverHost.value.trim() || "127.0.0.1",
|
||||
tsPort: Number.isInteger(tsPort) && tsPort > 0 && tsPort <= 65535 ? tsPort : 9987,
|
||||
tsServerPassword: guideServerPassword.value,
|
||||
};
|
||||
return JSON.stringify(config, null, 2);
|
||||
});
|
||||
|
||||
async function copyConfigTemplate() {
|
||||
try {
|
||||
if (!navigator.clipboard) throw new Error("clipboard unavailable");
|
||||
await navigator.clipboard.writeText(configTemplate.value);
|
||||
showToast(t("configCopiedToast"));
|
||||
} catch {
|
||||
showToast(t("configCopyFailedToast"));
|
||||
}
|
||||
}
|
||||
const canJoin = computed(() => Boolean(
|
||||
initialized.value
|
||||
&& nickname.value.trim()
|
||||
&& (accessMode.value === "fixed" || serverAddress.value.trim()),
|
||||
));
|
||||
|
||||
async function loadPublicConfig() {
|
||||
try {
|
||||
const response = await fetch("/api/public-config", { headers: { accept: "application/json" } });
|
||||
if (!response.ok) return;
|
||||
const config = await response.json() as { tsHost?: unknown; tsPort?: unknown };
|
||||
if (!query.has("tsHost") && !localStorage.getItem("webspeak:ts-host") && typeof config.tsHost === "string" && config.tsHost.trim()) {
|
||||
serverHost.value = config.tsHost.trim();
|
||||
}
|
||||
if (!query.has("tsPort") && !localStorage.getItem("webspeak:ts-port") && Number.isInteger(config.tsPort)) {
|
||||
serverPort.value = String(config.tsPort);
|
||||
}
|
||||
const config = await response.json() as { initialized?: unknown; siteName?: unknown; welcomeText?: unknown; accessMode?: unknown; target?: unknown };
|
||||
initialized.value = config.initialized === true;
|
||||
if (typeof config.siteName === "string" && config.siteName.trim()) siteName.value = config.siteName.trim();
|
||||
if (typeof config.welcomeText === "string") welcomeText.value = config.welcomeText;
|
||||
accessMode.value = config.accessMode === "open" ? "open" : "fixed";
|
||||
const hasUserTarget = query.has("server") || query.has("target") || query.has("tsHost") || Boolean(localStorage.getItem("webspeak:server-target"));
|
||||
if (!hasUserTarget && typeof config.target === "string" && config.target.trim()) serverAddress.value = config.target.trim();
|
||||
} catch {
|
||||
// The sensible browser-host/9987 defaults remain usable when the API is unavailable.
|
||||
// Keep joining disabled until the gateway can confirm its initialized policy.
|
||||
} finally {
|
||||
serverConfigLoading.value = false;
|
||||
}
|
||||
@@ -1112,48 +1063,17 @@ function stopPointerTalk() {
|
||||
/* Keep connected controls in the header; the old bottom dock consumed the
|
||||
chat viewport and made the settings action appear detached from its icon. */
|
||||
.header-tools { align-items: center; }
|
||||
.guide-button { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 10px; color: #006a64; background: #edf7f4; border: 1px solid #d7ebe6; border-radius: 8px; font-size: 12px; font-weight: 700; cursor: pointer; }
|
||||
.guide-button { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 10px; color: #006a64; background: #edf7f4; border: 1px solid #d7ebe6; border-radius: 8px; font-size: 12px; font-weight: 700; text-decoration: none; cursor: pointer; }
|
||||
.guide-button:hover { color: #fff; background: #006a64; border-color: #006a64; }
|
||||
.workspace-actions { align-items: center; flex-wrap: nowrap; }
|
||||
.workspace-actions .header-action { flex: 0 0 34px; padding: 0; line-height: 0; }
|
||||
.workspace-actions .header-action .ui-icon { margin: 0; }
|
||||
.settings-mode-switch { width: fit-content; margin: 0 0 7px; }
|
||||
.settings-hint { margin: -1px 0 19px; color: #8b9994; font-size: 11px; }
|
||||
.config-guide-modal { display: flex; width: min(900px, 100%); max-height: min(820px, calc(100dvh - 40px)); flex-direction: column; overflow: hidden; border-radius: 18px; background: #fff; box-shadow: 0 24px 70px rgba(16,40,35,.24); }
|
||||
.config-guide-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 22px; padding: 28px 32px 23px; border-bottom: 1px solid #edf1ef; }
|
||||
.config-guide-header h2 { margin: 8px 0 6px; color: #202c29; font-size: 27px; letter-spacing: -.045em; }
|
||||
.config-guide-header p { max-width: 650px; margin: 0; color: #71817b; font-size: 13px; line-height: 1.6; }
|
||||
.config-guide-content { display: grid; grid-template-columns: minmax(230px, .82fr) minmax(360px, 1.18fr); gap: 26px; min-height: 0; overflow-y: auto; padding: 27px 32px; }
|
||||
.config-guide-steps { display: flex; flex-direction: column; gap: 14px; }
|
||||
.config-guide-steps article { display: flex; align-items: flex-start; gap: 12px; padding: 14px; border: 1px solid #e7efec; border-radius: 12px; background: #f9fbfa; }
|
||||
.config-guide-steps article > span { display: grid; place-items: center; width: 25px; height: 25px; flex: 0 0 auto; color: #fff; background: #006a64; border-radius: 50%; font-size: 12px; font-weight: 800; }
|
||||
.config-guide-steps strong { display: block; color: #32413c; font-size: 13px; }
|
||||
.config-guide-steps p { margin: 5px 0 8px; color: #788882; font-size: 11px; line-height: 1.55; }
|
||||
.config-guide-steps code { display: block; padding: 7px 8px; overflow-x: auto; color: #286a63; background: #eaf5f2; border-radius: 6px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; white-space: nowrap; }
|
||||
.config-editor { min-width: 0; padding: 16px; border: 1px solid #e2ece8; border-radius: 13px; background: #fbfdfc; }
|
||||
.config-editor-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 13px; margin-bottom: 15px; }
|
||||
.config-editor-heading strong { display: block; margin-top: 5px; color: #51615b; font-size: 12px; font-weight: 600; }
|
||||
.copy-config-button { display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; min-height: 31px; padding: 0 9px; color: #006a64; background: #e2f2ef; border-radius: 7px; font-size: 11px; font-weight: 700; cursor: pointer; }
|
||||
.copy-config-button:hover { color: #fff; background: #006a64; }
|
||||
.config-guide-fields { display: grid; grid-template-columns: minmax(0, 1fr) 145px; gap: 11px; margin-bottom: 14px; }
|
||||
.config-guide-fields label { display: flex; flex-direction: column; gap: 6px; color: #5a6b64; font-size: 10px; font-weight: 600; }
|
||||
.config-guide-fields input, .config-guide-fields select { width: 100%; min-height: 36px; padding: 0 9px; color: #394742; border: 1px solid #dfebe6; border-radius: 7px; outline: none; background: #fff; font-size: 12px; }
|
||||
.config-guide-fields input:focus, .config-guide-fields select:focus { border-color: #81d8d0; box-shadow: 0 0 0 2px rgba(129,216,208,.2); }
|
||||
.config-guide-wide { grid-column: 1 / -1; }
|
||||
.config-editor pre { max-height: 255px; margin: 0; overflow: auto; padding: 14px; color: #48615a; background: #eef6f3; border-radius: 9px; font: 11px/1.65 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; }
|
||||
.config-guide-note { grid-column: 1 / -1; display: flex; align-items: flex-start; gap: 8px; padding: 11px 13px; color: #66817a; background: #eef7f4; border-radius: 9px; font-size: 11px; line-height: 1.55; }
|
||||
.config-guide-note .ui-icon { flex: 0 0 auto; color: #4f9c91; }
|
||||
.config-guide-footer { display: flex; justify-content: flex-end; gap: 12px; min-height: 67px; padding: 14px 32px; border-top: 1px solid #edf1ef; }
|
||||
|
||||
@media (max-width: 740px) {
|
||||
.header-tools { gap: 7px; }
|
||||
.header-note, .guide-button span { display: none; }
|
||||
.guide-button { width: 32px; justify-content: center; padding: 0; }
|
||||
.config-guide-modal { max-height: calc(100dvh - 24px); }
|
||||
.config-guide-header { padding: 22px 20px 18px; }
|
||||
.config-guide-header h2 { font-size: 23px; }
|
||||
.config-guide-content { display: block; padding: 20px; }
|
||||
.config-editor { margin-top: 18px; }
|
||||
.config-guide-footer { padding-inline: 20px; }
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user