From 7f8fada880a6bd2a3205378d971cdee4ed2257a9 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Fri, 23 Oct 2026 20:07:30 +0000 Subject: [PATCH] Options: Sicherheit tab (saved channel passwords, cleanup, identities) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Opt-in saved channel passwords per server (dropped when rejected), delete button, clear cache / collected URLs on exit, "Cache löschen" (service worker caches + icon/avatar/GIF caches, refetched right away) and a shortcut to the identities dialog. Master password greyed out for now. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- web/src/App.css | 9 ++ web/src/App.tsx | 183 ++++++++++++++++++++++++++++++++++++- web/src/lib/still.tsx | 5 + web/src/locales/cs-CZ.json | 16 +++- web/src/locales/de.json | 16 +++- web/src/locales/en.json | 16 +++- web/src/locales/fa.json | 16 +++- web/src/locales/zh-CN.json | 16 +++- 8 files changed, 268 insertions(+), 9 deletions(-) diff --git a/web/src/App.css b/web/src/App.css index fb97b8d..d6c2223 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -4759,3 +4759,12 @@ border: 1px solid var(--border-soft); border-radius: 4px; } + +/* Options -> Sicherheit */ +.ts-security-row { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + flex-wrap: wrap; +} diff --git a/web/src/App.tsx b/web/src/App.tsx index 64187c4..fdc47bf 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -150,7 +150,7 @@ import { saveSelectedIconPack, type IconPack, } from "./iconpack"; -import { StillImg } from "./lib/still"; +import { StillImg, clearStillCache } from "./lib/still"; import { DEFAULT_DOWNLOAD_SETTINGS, canPickFolder, @@ -662,6 +662,63 @@ function loadWhisperSettings(): WhisperSettings { } } +const SECURITY_SETTINGS_KEY = "webspeak3:security-settings"; +const CHANNEL_PASSWORDS_KEY = "webspeak3:channel-passwords"; + +/** Options -> Sicherheit. */ +interface SecuritySettings { + saveChannelPasswords: boolean; + clearCacheOnExit: boolean; + clearUrlsOnExit: boolean; +} + +const DEFAULT_SECURITY_SETTINGS: SecuritySettings = { + saveChannelPasswords: false, + clearCacheOnExit: false, + clearUrlsOnExit: false, +}; + +function loadSecuritySettings(): SecuritySettings { + try { + return { ...DEFAULT_SECURITY_SETTINGS, ...JSON.parse(localStorage.getItem(SECURITY_SETTINGS_KEY) ?? "{}") }; + } catch { + return DEFAULT_SECURITY_SETTINGS; + } +} + +/** Saved channel passwords: server host -> channel id -> password. */ +function loadChannelPasswords(): Record> { + try { + return JSON.parse(localStorage.getItem(CHANNEL_PASSWORDS_KEY) ?? "{}"); + } catch { + return {}; + } +} + +function storedChannelPassword(host: string, channelId: number): string | undefined { + return loadChannelPasswords()[host.trim().toLowerCase()]?.[channelId]; +} + +/** null removes the entry. */ +function storeChannelPassword(host: string, channelId: number, password: string | null): void { + const all = loadChannelPasswords(); + const key = host.trim().toLowerCase(); + const server = { ...all[key] }; + if (password === null) delete server[channelId]; + else server[channelId] = password; + all[key] = server; + localStorage.setItem(CHANNEL_PASSWORDS_KEY, JSON.stringify(all)); +} + +/** The service worker's CacheStorage; the app shell comes from the network until the worker refills it. */ +async function clearBrowserCaches(): Promise { + try { + await Promise.all((await caches.keys()).map((key) => caches.delete(key))); + } catch { + // No CacheStorage (insecure context): nothing to clear. + } +} + const TREE_OPTIONS_KEY = "webspeak3:tree-options"; /** Design tab -> "Channel Baum" and "GIF Animation" (TS3's options). */ @@ -716,6 +773,8 @@ const DisplayPrefsContext = createContext<{ setDownloadDir: (dir: FileSystemDirectoryHandle | null) => void; chat: ChatSettings; setChat: (next: ChatSettings) => void; + security: SecuritySettings; + setSecurity: (next: SecuritySettings) => void; }>({ tree: DEFAULT_TREE_OPTIONS, setTree: () => {}, @@ -731,6 +790,8 @@ const DisplayPrefsContext = createContext<{ setDownloadDir: () => {}, chat: DEFAULT_CHAT_SETTINGS, setChat: () => {}, + security: DEFAULT_SECURITY_SETTINGS, + setSecurity: () => {}, }); const DISCONNECT_MESSAGE_KEY = "webspeak3:disconnect-message"; const COLLECTED_URLS_KEY = "webspeak3:collected-urls"; @@ -6517,6 +6578,76 @@ function ChatPanel() { ); } +function SecurityPanel({ onOpenIdentities, onClearCache }: { onOpenIdentities: () => void; onClearCache: () => void }) { + const t = useT(); + const { security, setSecurity } = useContext(DisplayPrefsContext); + const set = (patch: Partial) => setSecurity({ ...security, ...patch }); + return ( + <> +

{t("options.section.sicherheit")}

+

{t("securitySettings.subtitle")}

+
+
+ {t("securitySettings.passwords")} +
+ + +
+
+ + +
+
+
+ {t("securitySettings.cleanup")} + + +
+ +
+
+
+ {t("securitySettings.identities")} +
+ +
+
+
+ + ); +} + function DesignPanel({ designSelection, onSelectionChange, @@ -7473,6 +7604,8 @@ function OptionsDialog({ chatImages, onChatImagesChange, onOpenWhisperLists, + onOpenIdentities, + onClearCache, }: { section: string; onSectionChange: (id: string) => void; @@ -7490,6 +7623,8 @@ function OptionsDialog({ chatImages: boolean; onChatImagesChange: (on: boolean) => void; onOpenWhisperLists: () => void; + onOpenIdentities: () => void; + onClearCache: () => void; }) { const t = useT(); const active = OPTIONS_SECTIONS.find((s) => s.id === section) ?? OPTIONS_SECTIONS[0]; @@ -7550,6 +7685,8 @@ function OptionsDialog({ ) : active.id === "chat" ? ( + ) : active.id === "sicherheit" ? ( + ) : ( <>

{t(`options.section.${active.id}`)}

@@ -8036,6 +8173,19 @@ function AppInner() { downloadSettingsRef.current = downloadSettings; const [downloadDir, setDownloadDir] = useState(null); const [chatSettings, setChatSettings] = useState(loadChatSettings); + const [securitySettings, setSecuritySettings] = useState(loadSecuritySettings); + const securitySettingsRef = useRef(securitySettings); + securitySettingsRef.current = securitySettings; + // "... beim Beenden": pagehide is the last event a closing tab reliably gets. + useEffect(() => { + const onHide = () => { + const settings = securitySettingsRef.current; + if (settings.clearUrlsOnExit) localStorage.removeItem(COLLECTED_URLS_KEY); + if (settings.clearCacheOnExit) void clearBrowserCaches(); + }; + window.addEventListener("pagehide", onHide); + return () => window.removeEventListener("pagehide", onHide); + }, []); const chatSettingsRef = useRef(chatSettings); chatSettingsRef.current = chatSettings; // "Hinweis für eingehende Nachrichten" for the two fixed tabs (private chats have their own flag). @@ -8079,8 +8229,13 @@ function AppInner() { setChatSettings(next); saveChatSettings(next); }, + security: securitySettings, + setSecurity: (next: SecuritySettings) => { + setSecuritySettings(next); + localStorage.setItem(SECURITY_SETTINGS_KEY, JSON.stringify(next)); + }, }), - [treeOptions, iconPacks, iconPackId, whisperSettings, downloadSettings, downloadDir, chatSettings] + [treeOptions, iconPacks, iconPackId, whisperSettings, downloadSettings, downloadDir, chatSettings, securitySettings] ); const iconPackStyle = iconPackCss(iconPacks.find((p) => p.id === iconPackId)); const [micOn, setMicOn] = useState(false); @@ -9231,6 +9386,8 @@ function AppInner() { // A cached password just got rejected (channel password changed, // or was wrong) - drop it so the next auto-switch doesn't reuse it. channelPasswordCacheRef.current.delete(data.channelId); + if (storedChannelPassword(connectHost, data.channelId) !== undefined) + storeChannelPassword(connectHost, data.channelId, null); setChannelPasswordPrompt((prev) => ({ channelId: data.channelId, channelName: channels.find((c) => c.id === data.channelId)?.name ?? "", @@ -9596,7 +9753,9 @@ function AppInner() { const state = isActive ? { clients, ownClientId } : rec.parked; const lastChannel = state?.clients.find((c) => c.id === state.ownClientId)?.channel; if (lastChannel) { - const cachedPassword = isActive ? channelPasswordCacheRef.current.get(lastChannel) : undefined; + const cachedPassword = isActive + ? (channelPasswordCacheRef.current.get(lastChannel) ?? savedChannelPassword(lastChannel)) + : undefined; params = { ...params, defaultChannel: `/${lastChannel}`, channelPassword: cachedPassword ?? params.channelPassword }; sessionParamsRef.current.set(sessionId, params); } @@ -10577,13 +10736,27 @@ function AppInner() { appendLog({ text: t("tree.joinNotConnected"), kind: "error" }); return; } - const password = channelPassword ?? channelPasswordCacheRef.current.get(id); + const password = channelPassword ?? channelPasswordCacheRef.current.get(id) ?? savedChannelPassword(id); socket.send(JSON.stringify({ type: "switchChannel", channelId: id, channelPassword: password })); }; + const savedChannelPassword = (channelId: number) => + securitySettings.saveChannelPasswords ? storedChannelPassword(host, channelId) : undefined; + + // Options -> Sicherheit -> "Cache löschen": icons/avatars download again right away. + const handleClearCache = () => { + void clearBrowserCaches(); + clearStillCache(); + setServerIconImages({}); + requestedIconPathsRef.current.clear(); + requestedAvatarHashesRef.current.clear(); + appendLog({ text: t("securitySettings.cacheCleared"), kind: "info" }); + }; + const handleChannelPasswordSubmit = (password: string) => { if (!channelPasswordPrompt) return; channelPasswordCacheRef.current.set(channelPasswordPrompt.channelId, password); + if (securitySettings.saveChannelPasswords) storeChannelPassword(host, channelPasswordPrompt.channelId, password); handleSwitchChannel(channelPasswordPrompt.channelId, password); setChannelPasswordPrompt(null); }; @@ -12690,6 +12863,8 @@ function AppInner() { {optionsDialogOpen && ( setWhisperListsOpen(true)} + onOpenIdentities={() => setIdentitiesOpen(true)} + onClearCache={handleClearCache} section={optionsSection} onSectionChange={setOptionsSection} onClose={() => setOptionsDialogOpen(false)} diff --git a/web/src/lib/still.tsx b/web/src/lib/still.tsx index 47efa0b..ad38463 100644 --- a/web/src/lib/still.tsx +++ b/web/src/lib/still.tsx @@ -2,6 +2,11 @@ import { useEffect, useState, type ImgHTMLAttributes } from "react"; const stills = new Map(); +/** Options -> Sicherheit -> "Cache löschen". */ +export function clearStillCache(): void { + stills.clear(); +} + /** First frame of an (animated) image as a PNG data URL, or null when the * browser won't let us read it (cross-origin image without CORS). */ function freeze(src: string): Promise { diff --git a/web/src/locales/cs-CZ.json b/web/src/locales/cs-CZ.json index 20e9599..a473e16 100644 --- a/web/src/locales/cs-CZ.json +++ b/web/src/locales/cs-CZ.json @@ -794,5 +794,19 @@ "chatSettings.notifyChannel": "Kanál", "chatSettings.notifyPrivate": "Soukromé", "chatSettings.linesUnit": "řádků", - "chatSettings.last": "posledních" + "chatSettings.last": "posledních", + "securitySettings.subtitle": "Nastavení zabezpečení", + "securitySettings.passwords": "Hesla", + "securitySettings.saveChannelPasswords": "Ukládat hesla kanálů", + "securitySettings.clearChannelPasswords": "Smazat hesla kanálů", + "securitySettings.channelPasswordsCleared": "Uložená hesla kanálů byla smazána.", + "securitySettings.masterPassword": "Použít hlavní heslo", + "securitySettings.changeMasterPassword": "Změnit hlavní heslo", + "securitySettings.cleanup": "Úklid", + "securitySettings.clearCacheOnExit": "Vyprázdnit mezipaměť při ukončení", + "securitySettings.clearUrlsOnExit": "Smazat URL při ukončení", + "securitySettings.clearCache": "Vyprázdnit mezipaměť", + "securitySettings.cacheCleared": "Mezipaměť vyprázdněna.", + "securitySettings.identities": "Identity", + "securitySettings.manageIdentities": "Spravovat identity" } diff --git a/web/src/locales/de.json b/web/src/locales/de.json index e0e7429..213d7ad 100644 --- a/web/src/locales/de.json +++ b/web/src/locales/de.json @@ -794,5 +794,19 @@ "chatSettings.notifyChannel": "Channel", "chatSettings.notifyPrivate": "Privat", "chatSettings.linesUnit": "Zeilen", - "chatSettings.last": "letzten" + "chatSettings.last": "letzten", + "securitySettings.subtitle": "Sicherheitseinstellungen", + "securitySettings.passwords": "Passwörter", + "securitySettings.saveChannelPasswords": "Channel Passwörter speichern", + "securitySettings.clearChannelPasswords": "Channel Passwörter löschen", + "securitySettings.channelPasswordsCleared": "Gespeicherte Channel Passwörter wurden gelöscht.", + "securitySettings.masterPassword": "Master Passwort benutzen", + "securitySettings.changeMasterPassword": "Master Passwort ändern", + "securitySettings.cleanup": "Aufräumen", + "securitySettings.clearCacheOnExit": "Cache beim Beenden leeren", + "securitySettings.clearUrlsOnExit": "URLs beim Beenden löschen", + "securitySettings.clearCache": "Cache löschen", + "securitySettings.cacheCleared": "Cache gelöscht.", + "securitySettings.identities": "Identitäten", + "securitySettings.manageIdentities": "Identitäten verwalten" } diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 3d46d0d..e9e8400 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -794,5 +794,19 @@ "chatSettings.notifyChannel": "Channel", "chatSettings.notifyPrivate": "Private", "chatSettings.linesUnit": "lines", - "chatSettings.last": "last" + "chatSettings.last": "last", + "securitySettings.subtitle": "Security settings", + "securitySettings.passwords": "Passwords", + "securitySettings.saveChannelPasswords": "Save channel passwords", + "securitySettings.clearChannelPasswords": "Delete channel passwords", + "securitySettings.channelPasswordsCleared": "Saved channel passwords were deleted.", + "securitySettings.masterPassword": "Use master password", + "securitySettings.changeMasterPassword": "Change master password", + "securitySettings.cleanup": "Cleanup", + "securitySettings.clearCacheOnExit": "Clear cache on exit", + "securitySettings.clearUrlsOnExit": "Delete URLs on exit", + "securitySettings.clearCache": "Clear cache", + "securitySettings.cacheCleared": "Cache cleared.", + "securitySettings.identities": "Identities", + "securitySettings.manageIdentities": "Manage identities" } diff --git a/web/src/locales/fa.json b/web/src/locales/fa.json index 33cf191..fa2e6cc 100644 --- a/web/src/locales/fa.json +++ b/web/src/locales/fa.json @@ -793,5 +793,19 @@ "chatSettings.notifyChannel": "کانال", "chatSettings.notifyPrivate": "خصوصی", "chatSettings.linesUnit": "خط", - "chatSettings.last": "آخرین" + "chatSettings.last": "آخرین", + "securitySettings.subtitle": "تنظیمات امنیتی", + "securitySettings.passwords": "رمزها", + "securitySettings.saveChannelPasswords": "ذخیره رمز کانال‌ها", + "securitySettings.clearChannelPasswords": "حذف رمز کانال‌ها", + "securitySettings.channelPasswordsCleared": "رمزهای ذخیره‌شده کانال حذف شدند.", + "securitySettings.masterPassword": "استفاده از رمز اصلی", + "securitySettings.changeMasterPassword": "تغییر رمز اصلی", + "securitySettings.cleanup": "پاک‌سازی", + "securitySettings.clearCacheOnExit": "خالی کردن حافظه نهان هنگام خروج", + "securitySettings.clearUrlsOnExit": "حذف URLها هنگام خروج", + "securitySettings.clearCache": "خالی کردن حافظه نهان", + "securitySettings.cacheCleared": "حافظه نهان خالی شد.", + "securitySettings.identities": "هویت‌ها", + "securitySettings.manageIdentities": "مدیریت هویت‌ها" } diff --git a/web/src/locales/zh-CN.json b/web/src/locales/zh-CN.json index 13512bc..a1543f6 100644 --- a/web/src/locales/zh-CN.json +++ b/web/src/locales/zh-CN.json @@ -793,5 +793,19 @@ "chatSettings.notifyChannel": "频道", "chatSettings.notifyPrivate": "私聊", "chatSettings.linesUnit": "行", - "chatSettings.last": "最近" + "chatSettings.last": "最近", + "securitySettings.subtitle": "安全设置", + "securitySettings.passwords": "密码", + "securitySettings.saveChannelPasswords": "保存频道密码", + "securitySettings.clearChannelPasswords": "删除频道密码", + "securitySettings.channelPasswordsCleared": "已删除保存的频道密码。", + "securitySettings.masterPassword": "使用主密码", + "securitySettings.changeMasterPassword": "更改主密码", + "securitySettings.cleanup": "清理", + "securitySettings.clearCacheOnExit": "退出时清空缓存", + "securitySettings.clearUrlsOnExit": "退出时删除 URL", + "securitySettings.clearCache": "清空缓存", + "securitySettings.cacheCleared": "缓存已清空。", + "securitySettings.identities": "身份", + "securitySettings.manageIdentities": "管理身份" }