From a95d5214c8235a052b79ca24b051ffd28ddac8df Mon Sep 17 00:00:00 2001 From: Zakk Date: Sun, 27 Sep 2026 18:48:38 +1000 Subject: [PATCH] feat(overview): explain why backend features are off Overview now lists the features that are off or limited before the available ones, each with its state, the reason and, on honk, the experimental.native_api setting that turns it on. Activity's status card counts them and keeps its link to the details. --- e2e/overview.spec.ts | 23 ++++++ src/features/activity/Activity.tsx | 5 +- src/features/activity/messages.ts | 3 + src/features/activity/useActivity.ts | 7 +- src/features/overview/Overview.tsx | 54 ++++++++++--- src/features/overview/messages.ts | 69 +++++++++++++++++ src/features/overview/view.ts | 38 ++------- src/features/shared/limits.test.ts | 109 ++++++++++++++++++++++++++ src/features/shared/limits.ts | 112 +++++++++++++++++++++++++++ src/i18n/locales/en.ts | 24 ++++++ src/i18n/locales/zh-CN.ts | 24 ++++++ src/i18n/locales/zh-TW.ts | 24 ++++++ src/ui/styles/indicators-charts.css | 30 ++++++- 13 files changed, 477 insertions(+), 45 deletions(-) create mode 100644 src/features/shared/limits.test.ts create mode 100644 src/features/shared/limits.ts diff --git a/e2e/overview.spec.ts b/e2e/overview.spec.ts index 4e2398bd..1de18966 100644 --- a/e2e/overview.spec.ts +++ b/e2e/overview.spec.ts @@ -243,3 +243,26 @@ test('a read the backend never answers fails at the deadline and recovers on ret await alert.getByRole('button', {name: 'Retry', exact: true}).click(); await expect(alert).toHaveCount(0); }); + +test('features that are off lead the list with their honk setting, and Activity counts them', async ({page}) => { + const {api, handlers} = await mockBackend(page); + const capabilities = await api.capabilities(); + capabilities.resources.events.available = false; + capabilities.resources.traffic_history.available = false; + capabilities.resources.config.writable = false; + handlers['GET capabilities'] = async () => capabilities; + await page.goto('/#/overview'); + const limits = page.getByRole('list', {name: 'Features that are off or limited', exact: true}); + const traffic = limits.getByRole('listitem').filter({hasText: 'Traffic history'}); + await expect(traffic).toContainText('Not recorded'); + await expect(traffic.locator('code')).toHaveText(['experimental.native_api.record_traffic: true']); + // The configuration leads the list. + const config = limits.getByRole('listitem').first(); + await expect(config).toContainText('ConfigurationRead-only'); + await expect(config.locator('code').first()).toHaveText('experimental.native_api.config_write: true'); + await expect(page.getByText('Restart honk after changing this section:')).toBeVisible(); + // The available features stay dots and no longer repeat what the list explains. + await expect(page.locator('.rp-capability').filter({hasText: 'Traffic history'})).toHaveCount(0); + await page.goto('/#/activity'); + await expect(page.locator('.rp-quick').getByText('3 features are off', {exact: true})).toBeVisible(); +}); diff --git a/src/features/activity/Activity.tsx b/src/features/activity/Activity.tsx index edc6a20d..d531ffe9 100644 --- a/src/features/activity/Activity.tsx +++ b/src/features/activity/Activity.tsx @@ -26,7 +26,10 @@ export function Activity() {
- {vm.status.text} +
+ {vm.status.text} + {vm.limited && {vm.limited}} +
{t('act.viewDetails')} diff --git a/src/features/activity/messages.ts b/src/features/activity/messages.ts index 2fdabdbb..b28c2e49 100644 --- a/src/features/activity/messages.ts +++ b/src/features/activity/messages.ts @@ -22,6 +22,7 @@ export const messages = defineMessages({ 'act.memoryNearLimit': '接近上限', 'act.traffic': '流量', 'act.viewDetails': '查看詳情', + 'act.limited': '{n} 項功能未開啟', 'act.mode': '出站模式', 'act.global': '全域目標', 'mode.rule': '規則', @@ -81,6 +82,7 @@ export const messages = defineMessages({ 'act.memoryNearLimit': '接近上限', 'act.traffic': '流量', 'act.viewDetails': '查看详情', + 'act.limited': '{n} 项功能未开启', 'act.mode': '出站模式', 'act.global': '全局目标', 'mode.rule': '规则', @@ -140,6 +142,7 @@ export const messages = defineMessages({ 'act.memoryNearLimit': 'Near limit', 'act.traffic': 'Traffic', 'act.viewDetails': 'View details', + 'act.limited': {one: '{n} feature is off', other: '{n} features are off'}, 'act.mode': 'Outbound mode', 'act.global': 'Global target', 'mode.rule': 'Rule', diff --git a/src/features/activity/useActivity.ts b/src/features/activity/useActivity.ts index 13b90fd1..93762d13 100644 --- a/src/features/activity/useActivity.ts +++ b/src/features/activity/useActivity.ts @@ -1,5 +1,5 @@ import {useCallback, useMemo, useState} from 'react'; -import {useCapabilities, useRuntime, useRuntimeMemory, useTrafficHistory} from '../../store'; +import {useCapabilities, useRuntime, useRuntimeMemory, useTrafficHistory, useVersion} from '../../store'; import {useT, useLang, LOCALE, formatNumber} from '../../i18n'; import {formatBytes, formatRate} from '../../i18n/format'; import {usePalette} from '../../ui/charts'; @@ -9,6 +9,7 @@ import {useNotices} from './useNotices'; import {useMode} from './useMode'; import {activityView, trafficState} from './view'; import {offered} from '../../api/capabilities'; +import {backendLimits} from '../shared/limits'; export function useActivity() { const t = useT(); @@ -50,10 +51,14 @@ export function useActivity() { () => activityView(runtime.data, memory.data, t, resources?.runtime.available, locale), [runtime.data, memory.data, t, resources?.runtime.available, locale] ); + const version = useVersion(); + // Overview lists these with their reasons; here the status card only counts them. + const limited = useMemo(() => (capabilities.data ? backendLimits(capabilities.data, version.data, t).length : 0), [capabilities.data, version.data, t]); const notices = useNotices(); const mode = useMode(); return { ...view, + limited: limited > 0 ? t('act.limited', {n: limited}) : null, mode, notices, range, diff --git a/src/features/overview/Overview.tsx b/src/features/overview/Overview.tsx index 89740440..65a78441 100644 --- a/src/features/overview/Overview.tsx +++ b/src/features/overview/Overview.tsx @@ -1,9 +1,10 @@ import {VisuallyHidden} from 'react-aria'; import {useOverview} from './useOverview'; import {useT} from '../../i18n'; -import {ActionGroup, Badge, Card, Bar, DataTable, Kv, Light, TextTooltip, ErrorMessage, Loading, Empty} from '../../ui/ui'; +import {ActionGroup, Badge, Card, Bar, DataTable, Kv, Light, Link, TextTooltip, ErrorMessage, Loading, Empty} from '../../ui/ui'; import Download from '../../ui/icons/Download'; import {tableLayout} from '../../ui/Table'; +import {nativeApiSection} from '../shared/limits'; // While a section loads, invisible cells in the loaded body's grid wrap into the same rows at any width, so the // card keeps its height when the values arrive; `extra` holds the lines below the grid. @@ -139,15 +140,50 @@ export function Overview() { {vm.resources.state === 'ready' ? ( -
- {vm.resources.rows.map(row => ( -
- {/* The dot leads its label, so a wide column cannot set it nearer the next label than its own. */} - {row.label} - {row.dotOnly ? {row.text} : {row.text}} + <> + {vm.resources.limits.length > 0 && ( +
+ {vm.resources.limits.map(limit => ( +
+
+ {limit.label} + {limit.state} +
+

{limit.reason}

+ {limit.keys.length > 0 && ( +

+ {limit.keys.map(key => ( + + {key} + + ))} +

+ )} + {limit.link && ( + + {limit.link.text} + + )} +
+ ))}
- ))} -
+ )} + {vm.resources.restart && ( +

+ {t('ov.lim.restart')} {nativeApiSection} +

+ )} +
+ {vm.resources.rows.map(row => ( +
+ {/* The dot leads its label, so a wide column cannot set it nearer the next label than its own. */} + {row.label} + {/* The status is the dot alone; the text still reaches assistive technology. */} + {row.text} +
+ ))} +
+ ) : vm.resources.state === 'loading' ? ( ) : vm.errors.capabilities ? null : ( diff --git a/src/features/overview/messages.ts b/src/features/overview/messages.ts index fa15883a..5243dbdd 100644 --- a/src/features/overview/messages.ts +++ b/src/features/overview/messages.ts @@ -54,6 +54,29 @@ export const messages = defineMessages({ 'ov.r.trafficHistory': '流量歷史', 'ov.r.memoryHistory': '記憶體歷史', 'ov.r.outbounds': '出站計數', + 'ov.r.dnsLog': 'DNS 記錄', + 'ov.lim.title': '未開啟或受限的功能', + 'ov.lim.notProvided': '此後端不提供此功能。', + 'ov.lim.notLoaded': '未載入', + 'ov.lim.configMissing': '後端尚未接受任何組態,或上次重載失敗。', + 'ov.lim.configWrite': '寫入組態需要 honk 允許組態寫入,並設定密鑰或啟用密碼登入。', + 'ov.lim.notRecorded': '未記錄', + 'ov.lim.recordOff': 'honk 預設不記錄此項,需在組態中啟用。', + 'ov.lim.flowsSwitch': '可在後端選項中啟用。', + 'ov.lim.flowsSwitchDefault': '可在後端選項中啟用,下列組態項決定啟動時的預設值。', + 'ov.lim.notRunning': '未運作', + 'ov.lim.probesOff': '後端的探測服務未運作。', + 'ov.lim.noUpdate': '無法更新', + 'ov.lim.geoNeedsConfig': '更新需要組態寫入,見上方的組態。', + 'ov.lim.geoNoSources': '沒有下載網址。請設定下列網址,或讓 honk 能開啟其狀態資料庫。', + 'ov.lim.geoNoUrl': '未設定下載網址。', + 'ov.lim.subscriptions': '訂閱', + 'ov.lim.noRefresh': '無法重新整理', + 'ov.lim.subscriptionsOff': '訂閱服務未運作。', + 'ov.lim.manage': '節點與來源', + 'ov.lim.noEdit': '無法編輯', + 'ov.lim.mainReadOnly': '主組態檔案不可寫入。', + 'ov.lim.restart': '修改此區段後需重新啟動 honk:', 'ov.f.kind': '類型', 'ov.f.state': '狀態', 'ov.f.visibility': '可見度', @@ -163,6 +186,29 @@ export const messages = defineMessages({ 'ov.r.trafficHistory': '流量历史', 'ov.r.memoryHistory': '内存历史', 'ov.r.outbounds': '出站计数', + 'ov.r.dnsLog': 'DNS 记录', + 'ov.lim.title': '未开启或受限的功能', + 'ov.lim.notProvided': '此后端不提供此功能。', + 'ov.lim.notLoaded': '未加载', + 'ov.lim.configMissing': '后端尚未接受任何配置,或上次重载失败。', + 'ov.lim.configWrite': '写入配置需要 honk 允许配置写入,并设置密钥或开启密码登录。', + 'ov.lim.notRecorded': '未记录', + 'ov.lim.recordOff': 'honk 默认不记录此项,需在配置中开启。', + 'ov.lim.flowsSwitch': '可在后端选项中开启。', + 'ov.lim.flowsSwitchDefault': '可在后端选项中开启,下列配置项决定启动时的默认值。', + 'ov.lim.notRunning': '未运行', + 'ov.lim.probesOff': '后端的探测服务未运行。', + 'ov.lim.noUpdate': '无法更新', + 'ov.lim.geoNeedsConfig': '更新需要配置写入,见上方的配置。', + 'ov.lim.geoNoSources': '没有下载网址。请设置下列网址,或让 honk 能打开其状态数据库。', + 'ov.lim.geoNoUrl': '未设置下载网址。', + 'ov.lim.subscriptions': '订阅', + 'ov.lim.noRefresh': '无法刷新', + 'ov.lim.subscriptionsOff': '订阅服务未运行。', + 'ov.lim.manage': '节点与来源', + 'ov.lim.noEdit': '无法编辑', + 'ov.lim.mainReadOnly': '主配置文件不可写入。', + 'ov.lim.restart': '修改此区段后需重启 honk:', 'ov.f.kind': '类型', 'ov.f.state': '状态', 'ov.f.visibility': '可见度', @@ -272,6 +318,29 @@ export const messages = defineMessages({ 'ov.r.trafficHistory': 'Traffic history', 'ov.r.memoryHistory': 'Memory history', 'ov.r.outbounds': 'Outbound counters', + 'ov.r.dnsLog': 'DNS log', + 'ov.lim.title': 'Features that are off or limited', + 'ov.lim.notProvided': 'The backend does not provide it.', + 'ov.lim.notLoaded': 'Not loaded', + 'ov.lim.configMissing': 'The backend has not accepted a configuration yet, or the last reload failed.', + 'ov.lim.configWrite': 'Writing requires honk to allow configuration writes and a secret or password sign-in.', + 'ov.lim.notRecorded': 'Not recorded', + 'ov.lim.recordOff': 'honk records it only when its configuration turns it on.', + 'ov.lim.flowsSwitch': 'It can be turned on in Backend options.', + 'ov.lim.flowsSwitchDefault': 'It can be turned on in Backend options. The setting below is the default at startup.', + 'ov.lim.notRunning': 'Not running', + 'ov.lim.probesOff': 'The backend probe service is not running.', + 'ov.lim.noUpdate': 'Cannot update', + 'ov.lim.geoNeedsConfig': 'Updating requires configuration writes. See Configuration above.', + 'ov.lim.geoNoSources': 'No download URLs. Set the URLs below, or let honk open its state database.', + 'ov.lim.geoNoUrl': 'No download URL is set.', + 'ov.lim.subscriptions': 'Subscriptions', + 'ov.lim.noRefresh': 'Cannot refresh', + 'ov.lim.subscriptionsOff': 'The subscription service is not running.', + 'ov.lim.manage': 'Nodes and sources', + 'ov.lim.noEdit': 'Cannot edit', + 'ov.lim.mainReadOnly': 'The main configuration file is not writable.', + 'ov.lim.restart': 'Restart honk after changing this section:', 'ov.f.kind': 'Kind', 'ov.f.state': 'State', 'ov.f.visibility': 'Visibility', diff --git a/src/features/overview/view.ts b/src/features/overview/view.ts index 20120b14..09174a59 100644 --- a/src/features/overview/view.ts +++ b/src/features/overview/view.ts @@ -7,6 +7,7 @@ import {parseU64, pctU64} from '../../api/u64'; import {formatNumber, type Translator as LabelFn} from '../../i18n'; import {backendMessage, oneLine} from '../../i18n/backend'; import type {Help, KvItem} from '../../ui/ui'; +import {backendLimits, resourceLabels} from '../shared/limits'; const datapathValues: Record = { ebpf: 'ov.v.ebpf', userspace: 'ov.v.userspace', @@ -106,24 +107,6 @@ export function memoryFields(memory: RuntimeMemory, label: LabelFn, locale: stri ); } -const resourceLabels = { - connections: 'nav.connections', - flows: 'rule.flows', - routing_trace: 'ov.r.routingTrace', - dns_query: 'ov.r.dnsQuery', - dns_cache: 'ov.r.dnsCache', - events: 'nav.events', - probes: 'ov.r.probes', - traffic_history: 'ov.r.trafficHistory', - memory_history: 'ov.r.memoryHistory', - runtime_outbounds: 'ov.r.outbounds', - logs: 'nav.logs', - providers: 'nodes.providers', - config: 'nav.config', - runtime_settings: 'settings.runtime', - geodata: 'settings.geodata' -} as const satisfies Record; - export function overviewView( data: {capabilities?: Capabilities; runtime?: Runtime; version?: Version; memory?: RuntimeMemory; datapath?: Datapath}, loading: {capabilities: boolean; runtime: boolean; version: boolean; memory: boolean; datapath: boolean}, @@ -138,6 +121,7 @@ export function overviewView( const cpu = runtime?.process.cpu_percent; const percent = pctU64(memory?.cgroup?.current_bytes ?? null, memory?.cgroup?.limit_bytes ?? null); const count = (value: number | null) => (value === null ? '—' : formatNumber(value, locale)); + const limits = capabilities ? backendLimits(capabilities, version, t) : []; const section = (present: boolean, busy: boolean) => (present ? ('ready' as const) : busy ? ('loading' as const) : ('unavailable' as const)); return { status: { @@ -230,21 +214,13 @@ export function overviewView( }, resources: { state: section(!!capabilities, loading.capabilities), + // What is off or limited comes first with its reason; the rest are available and show as dots. + limits, + restart: limits.some(limit => limit.keys.length > 0), rows: capabilities ? (Object.keys(resourceLabels) as Array) - .map(id => { - const available = capabilities.resources[id].available !== false; - return { - id, - label: t(resourceLabels[id]), - tone: available ? ('ok' as const) : ('muted' as const), - text: t(available ? 'ov.available' : 'ov.notAvailable'), - // Most rows are available, so their status is the dot alone and only the exceptions are spelled out; - // the text still reaches assistive technology. - dotOnly: available - }; - }) - .sort((a, b) => Number(a.tone === 'muted') - Number(b.tone === 'muted')) + .filter(id => !limits.some(limit => limit.id === id)) + .map(id => ({id, label: t(resourceLabels[id]), text: t('ov.available')})) : [] }, canExport: !!runtime diff --git a/src/features/shared/limits.test.ts b/src/features/shared/limits.test.ts new file mode 100644 index 00000000..615210f2 --- /dev/null +++ b/src/features/shared/limits.test.ts @@ -0,0 +1,109 @@ +import {describe, expect, it} from 'vitest'; +import type {Capabilities, Version} from '../../api/model'; +import {capabilities, version} from '../../api/mock/fixtures'; +import {translate, type Translator} from '../../i18n'; +import {backendLimits} from './limits'; +const t: Translator = (key, params) => translate('en', key, params); +const other = {...version, api: {...version.api, name: 'other/backend'}} as unknown as Version; +type Resources = Capabilities['resources']; +const patched = (patch: {[K in keyof Resources]?: Partial}): Capabilities => ({ + ...capabilities, + resources: Object.fromEntries( + Object.entries(capabilities.resources).map(([id, resource]) => [id, {...resource, ...patch[id as keyof Resources]}]) + ) as Resources +}); +const find = (limits: ReturnType, id: string) => limits.find(limit => limit.id === id); + +describe('backendLimits', () => { + it('lists nothing when every feature is on', () => { + expect(backendLimits(capabilities, version, t)).toEqual([]); + }); + + it('reports a missing configuration without a setting', () => { + const config = find(backendLimits(patched({config: {available: false}}), version, t), 'config'); + expect(config).toMatchObject({state: t('ov.lim.notLoaded'), reason: t('ov.lim.configMissing'), keys: []}); + }); + + it('names what configuration writes require on honk and only the state elsewhere', () => { + const readOnly = patched({config: {writable: false}}); + expect(find(backendLimits(readOnly, version, t), 'config')).toMatchObject({ + state: t('config.readOnly'), + reason: t('ov.lim.configWrite'), + keys: ['experimental.native_api.config_write: true', 'experimental.native_api.secret', 'experimental.native_api.password_auth: true'] + }); + expect(find(backendLimits(patched({config: {writable: undefined}}), version, t), 'config')?.state).toBe(t('config.readOnly')); + expect(find(backendLimits(readOnly, other, t), 'config')).toMatchObject({reason: t('ov.lim.notProvided'), keys: []}); + expect(find(backendLimits(readOnly, undefined, t), 'config')?.keys).toEqual([]); + }); + + it('points each recorder at its honk switch', () => { + const off = patched({traffic_history: {available: false}, memory_history: {available: false}, logs: {available: false}, dns_log: {available: false}}); + const limits = backendLimits(off, version, t); + for (const [id, key] of [ + ['traffic_history', 'record_traffic'], + ['memory_history', 'record_memory'], + ['logs', 'record_logs'], + ['dns_log', 'record_dns_log'] + ]) { + expect(find(limits, id)).toMatchObject({state: t('ov.lim.notRecorded'), reason: t('ov.lim.recordOff'), keys: [`experimental.native_api.${key}: true`]}); + expect(find(backendLimits(off, other, t), id)).toMatchObject({reason: t('ov.lim.notProvided'), keys: []}); + } + }); + + it('sends flows that are not recording to the runtime settings, with the honk default', () => { + const off = patched({flows: {recording: 'off'}}); + expect(find(backendLimits(off, version, t), 'flows')).toMatchObject({ + state: t('ov.lim.notRecorded'), + reason: t('ov.lim.flowsSwitchDefault'), + keys: ['experimental.native_api.record_flows: true'], + link: {href: '#/settings?card=runtime', text: t('settings.runtime')} + }); + expect(find(backendLimits(off, other, t), 'flows')).toMatchObject({reason: t('ov.lim.flowsSwitch'), keys: []}); + const fixed = patched({flows: {recording: 'off'}, runtime_settings: {fields: ['log.level']}}); + expect(find(backendLimits(fixed, version, t), 'flows')).toMatchObject({reason: t('ov.lim.recordOff'), link: undefined}); + expect(find(backendLimits(patched({flows: {recording: 'sampled'}}), version, t), 'flows')).toBeUndefined(); + }); + + it('explains geodata that cannot update by the first missing piece', () => { + const stuck = {available: true, can_update: false} as const; + expect(find(backendLimits(patched({geodata: stuck, config: {writable: false}}), version, t), 'geodata')).toMatchObject({ + state: t('ov.lim.noUpdate'), + reason: t('ov.lim.geoNeedsConfig'), + keys: [] + }); + const noSources = patched({geodata: {...stuck, configurable_sources: false}}); + expect(find(backendLimits(noSources, version, t), 'geodata')).toMatchObject({ + reason: t('ov.lim.geoNoSources'), + keys: ['experimental.native_api.geosite_download_url', 'experimental.native_api.geoip_download_url', '/state/honk.db'] + }); + expect(find(backendLimits(noSources, other, t), 'geodata')).toMatchObject({reason: t('ov.lim.notProvided'), keys: []}); + expect(find(backendLimits(patched({geodata: {...stuck, configurable_sources: true}}), version, t), 'geodata')).toMatchObject({ + reason: t('ov.lim.geoNoUrl'), + link: {href: '#/settings?card=geodata', text: t('settings.geodata')} + }); + }); + + it('reports subscriptions, editing and probes without a setting', () => { + const limits = backendLimits(patched({providers: {can_refresh: false}, nodes: {can_manage: false}, probes: {available: false}}), version, t); + expect(find(limits, 'providers')).toMatchObject({ + label: t('ov.lim.subscriptions'), + state: t('ov.lim.noRefresh'), + reason: t('ov.lim.subscriptionsOff'), + keys: [] + }); + expect(find(limits, 'manage')).toMatchObject({label: t('ov.lim.manage'), state: t('ov.lim.noEdit'), reason: t('ov.lim.mainReadOnly'), keys: []}); + expect(find(limits, 'probes')).toMatchObject({state: t('ov.lim.notRunning'), reason: t('ov.lim.probesOff'), keys: []}); + expect(find(backendLimits(patched({providers: {can_manage: false}}), version, t), 'manage')).toBeDefined(); + }); + + it('marks any other missing feature as not provided and ignores suspend and resume', () => { + const limits = backendLimits(patched({events: {available: false}, suspend: {available: false}, resume: {available: false}}), version, t); + expect(limits.map(limit => limit.id)).toEqual(['events']); + expect(limits[0]).toMatchObject({label: t('nav.events'), state: t('ov.notAvailable'), reason: t('ov.lim.notProvided'), keys: []}); + }); + + it('puts the configuration first', () => { + const limits = backendLimits(patched({connections: {available: false}, config: {writable: false}}), version, t); + expect(limits.map(limit => limit.id)).toEqual(['config', 'connections']); + }); +}); diff --git a/src/features/shared/limits.ts b/src/features/shared/limits.ts new file mode 100644 index 00000000..2c0e9d5f --- /dev/null +++ b/src/features/shared/limits.ts @@ -0,0 +1,112 @@ +import type {Capabilities, Version} from '../../api/model'; +import type {Key, Translator as LabelFn} from '../../i18n'; +import {href} from '../../shell/route'; + +export const resourceLabels = { + connections: 'nav.connections', + flows: 'rule.flows', + routing_trace: 'ov.r.routingTrace', + dns_query: 'ov.r.dnsQuery', + dns_cache: 'ov.r.dnsCache', + dns_log: 'ov.r.dnsLog', + events: 'nav.events', + probes: 'ov.r.probes', + traffic_history: 'ov.r.trafficHistory', + memory_history: 'ov.r.memoryHistory', + runtime_outbounds: 'ov.r.outbounds', + logs: 'nav.logs', + providers: 'nodes.providers', + config: 'nav.config', + runtime_settings: 'settings.runtime', + geodata: 'settings.geodata' +} as const satisfies Record; +type Resource = keyof typeof resourceLabels; + +// Every honk switch named here lives under this section, which honk reads only at startup. +export const nativeApiSection = 'experimental.native_api'; +const nativeApi = (setting: string) => `${nativeApiSection}.${setting}`; +// Recorders honk leaves off unless its configuration turns them on. +const recorders: Partial> = { + traffic_history: 'record_traffic', + memory_history: 'record_memory', + logs: 'record_logs', + dns_log: 'record_dns_log' +}; + +export type BackendLimit = { + id: string; + label: string; + state: string; + reason: string; + // honk configuration that lifts the limit; empty for another backend or where no setting helps. + keys: string[]; + link?: {href: string; text: string}; +}; + +// The backend features that are off or limited, each with why and, on honk, the setting that turns it on. Every +// resource that is unavailable appears here, so the rest of the resources are available. +export function backendLimits(capabilities: Capabilities, version: Pick | undefined, t: LabelFn): BackendLimit[] { + const resources = capabilities.resources; + const honk = version?.api.name === 'dae/honk-native'; + const notProvided = t('ov.lim.notProvided'); + const item = (id: Resource, state: Key, reason: string, keys: string[] = [], link?: BackendLimit['link']): BackendLimit => ({ + id, + label: t(resourceLabels[id]), + state: t(state), + reason, + keys: honk ? keys : [], + link + }); + const configWritable = resources.config.available && resources.config.writable === true; + const limits: BackendLimit[] = []; + if (!resources.config.available) limits.push(item('config', 'ov.lim.notLoaded', t('ov.lim.configMissing'))); + else if (!configWritable) + // Several conditions in honk collapse into this one flag, so the reason names what writing requires. + limits.push( + item('config', 'config.readOnly', honk ? t('ov.lim.configWrite') : notProvided, [ + nativeApi('config_write: true'), + nativeApi('secret'), + nativeApi('password_auth: true') + ]) + ); + for (const id of Object.keys(resourceLabels) as Resource[]) { + if (id === 'config') continue; + const recorder = recorders[id]; + if (recorder && !resources[id].available) { + limits.push(item(id, 'ov.lim.notRecorded', honk ? t('ov.lim.recordOff') : notProvided, [nativeApi(recorder + ': true')])); + } else if (id === 'probes' && !resources.probes.available) { + limits.push(item(id, 'ov.lim.notRunning', t('ov.lim.probesOff'))); + } else if (!resources[id].available) { + limits.push(item(id, 'ov.notAvailable', notProvided)); + } else if (id === 'flows' && resources.flows.recording === 'off') { + // Recording can be switched while running; honk's setting is only the default it starts with. + const switchable = resources.runtime_settings.available && (resources.runtime_settings.fields ?? []).includes('record_flows'); + limits.push( + item( + id, + 'ov.lim.notRecorded', + switchable ? t(honk ? 'ov.lim.flowsSwitchDefault' : 'ov.lim.flowsSwitch') : honk ? t('ov.lim.recordOff') : notProvided, + [nativeApi('record_flows: true')], + switchable ? {href: href('settings', {card: 'runtime'}), text: t('settings.runtime')} : undefined + ) + ); + } else if (id === 'geodata' && resources.geodata.can_update !== true) { + const geodata = resources.geodata; + if (!configWritable) limits.push(item(id, 'ov.lim.noUpdate', t('ov.lim.geoNeedsConfig'))); + else if (geodata.configurable_sources !== true) + limits.push( + item(id, 'ov.lim.noUpdate', honk ? t('ov.lim.geoNoSources') : notProvided, [ + nativeApi('geosite_download_url'), + nativeApi('geoip_download_url'), + '/state/honk.db' + ]) + ); + else limits.push(item(id, 'ov.lim.noUpdate', t('ov.lim.geoNoUrl'), [], {href: href('settings', {card: 'geodata'}), text: t('settings.geodata')})); + } else if (id === 'providers' && resources.providers.can_refresh === false) { + limits.push({...item(id, 'ov.lim.noRefresh', t('ov.lim.subscriptionsOff')), label: t('ov.lim.subscriptions')}); + } + if (id === 'providers' && (resources.nodes.can_manage === false || resources.providers.can_manage === false)) + limits.push({id: 'manage', label: t('ov.lim.manage'), state: t('ov.lim.noEdit'), reason: t('ov.lim.mainReadOnly'), keys: []}); + } + return limits; +} diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.ts index d59b49d8..1c2e5768 100644 --- a/src/i18n/locales/en.ts +++ b/src/i18n/locales/en.ts @@ -23,6 +23,7 @@ export const messages = { 'act.memoryNearLimit': 'Near limit', 'act.traffic': 'Traffic', 'act.viewDetails': 'View details', + 'act.limited': {one: '{n} feature is off', other: '{n} features are off'}, 'act.mode': 'Outbound mode', 'act.global': 'Global target', 'mode.rule': 'Rule', @@ -599,6 +600,29 @@ export const messages = { 'ov.r.trafficHistory': 'Traffic history', 'ov.r.memoryHistory': 'Memory history', 'ov.r.outbounds': 'Outbound counters', + 'ov.r.dnsLog': 'DNS log', + 'ov.lim.title': 'Features that are off or limited', + 'ov.lim.notProvided': 'The backend does not provide it.', + 'ov.lim.notLoaded': 'Not loaded', + 'ov.lim.configMissing': 'The backend has not accepted a configuration yet, or the last reload failed.', + 'ov.lim.configWrite': 'Writing requires honk to allow configuration writes and a secret or password sign-in.', + 'ov.lim.notRecorded': 'Not recorded', + 'ov.lim.recordOff': 'honk records it only when its configuration turns it on.', + 'ov.lim.flowsSwitch': 'It can be turned on in Backend options.', + 'ov.lim.flowsSwitchDefault': 'It can be turned on in Backend options. The setting below is the default at startup.', + 'ov.lim.notRunning': 'Not running', + 'ov.lim.probesOff': 'The backend probe service is not running.', + 'ov.lim.noUpdate': 'Cannot update', + 'ov.lim.geoNeedsConfig': 'Updating requires configuration writes. See Configuration above.', + 'ov.lim.geoNoSources': 'No download URLs. Set the URLs below, or let honk open its state database.', + 'ov.lim.geoNoUrl': 'No download URL is set.', + 'ov.lim.subscriptions': 'Subscriptions', + 'ov.lim.noRefresh': 'Cannot refresh', + 'ov.lim.subscriptionsOff': 'The subscription service is not running.', + 'ov.lim.manage': 'Nodes and sources', + 'ov.lim.noEdit': 'Cannot edit', + 'ov.lim.mainReadOnly': 'The main configuration file is not writable.', + 'ov.lim.restart': 'Restart honk after changing this section:', 'ov.f.kind': 'Kind', 'ov.f.state': 'State', 'ov.f.visibility': 'Visibility', diff --git a/src/i18n/locales/zh-CN.ts b/src/i18n/locales/zh-CN.ts index 4c893dd8..751fe99b 100644 --- a/src/i18n/locales/zh-CN.ts +++ b/src/i18n/locales/zh-CN.ts @@ -23,6 +23,7 @@ export const messages = { 'act.memoryNearLimit': '接近上限', 'act.traffic': '流量', 'act.viewDetails': '查看详情', + 'act.limited': '{n} 项功能未开启', 'act.mode': '出站模式', 'act.global': '全局目标', 'mode.rule': '规则', @@ -573,6 +574,29 @@ export const messages = { 'ov.r.trafficHistory': '流量历史', 'ov.r.memoryHistory': '内存历史', 'ov.r.outbounds': '出站计数', + 'ov.r.dnsLog': 'DNS 记录', + 'ov.lim.title': '未开启或受限的功能', + 'ov.lim.notProvided': '此后端不提供此功能。', + 'ov.lim.notLoaded': '未加载', + 'ov.lim.configMissing': '后端尚未接受任何配置,或上次重载失败。', + 'ov.lim.configWrite': '写入配置需要 honk 允许配置写入,并设置密钥或开启密码登录。', + 'ov.lim.notRecorded': '未记录', + 'ov.lim.recordOff': 'honk 默认不记录此项,需在配置中开启。', + 'ov.lim.flowsSwitch': '可在后端选项中开启。', + 'ov.lim.flowsSwitchDefault': '可在后端选项中开启,下列配置项决定启动时的默认值。', + 'ov.lim.notRunning': '未运行', + 'ov.lim.probesOff': '后端的探测服务未运行。', + 'ov.lim.noUpdate': '无法更新', + 'ov.lim.geoNeedsConfig': '更新需要配置写入,见上方的配置。', + 'ov.lim.geoNoSources': '没有下载网址。请设置下列网址,或让 honk 能打开其状态数据库。', + 'ov.lim.geoNoUrl': '未设置下载网址。', + 'ov.lim.subscriptions': '订阅', + 'ov.lim.noRefresh': '无法刷新', + 'ov.lim.subscriptionsOff': '订阅服务未运行。', + 'ov.lim.manage': '节点与来源', + 'ov.lim.noEdit': '无法编辑', + 'ov.lim.mainReadOnly': '主配置文件不可写入。', + 'ov.lim.restart': '修改此区段后需重启 honk:', 'ov.f.kind': '类型', 'ov.f.state': '状态', 'ov.f.visibility': '可见度', diff --git a/src/i18n/locales/zh-TW.ts b/src/i18n/locales/zh-TW.ts index 2e74e5ff..1c0b8ce5 100644 --- a/src/i18n/locales/zh-TW.ts +++ b/src/i18n/locales/zh-TW.ts @@ -22,6 +22,7 @@ export const messages = { 'act.memoryNearLimit': '接近上限', 'act.traffic': '流量', 'act.viewDetails': '查看詳情', + 'act.limited': '{n} 項功能未開啟', 'act.mode': '出站模式', 'act.global': '全域目標', 'mode.rule': '規則', @@ -572,6 +573,29 @@ export const messages = { 'ov.r.trafficHistory': '流量歷史', 'ov.r.memoryHistory': '記憶體歷史', 'ov.r.outbounds': '出站計數', + 'ov.r.dnsLog': 'DNS 記錄', + 'ov.lim.title': '未開啟或受限的功能', + 'ov.lim.notProvided': '此後端不提供此功能。', + 'ov.lim.notLoaded': '未載入', + 'ov.lim.configMissing': '後端尚未接受任何組態,或上次重載失敗。', + 'ov.lim.configWrite': '寫入組態需要 honk 允許組態寫入,並設定密鑰或啟用密碼登入。', + 'ov.lim.notRecorded': '未記錄', + 'ov.lim.recordOff': 'honk 預設不記錄此項,需在組態中啟用。', + 'ov.lim.flowsSwitch': '可在後端選項中啟用。', + 'ov.lim.flowsSwitchDefault': '可在後端選項中啟用,下列組態項決定啟動時的預設值。', + 'ov.lim.notRunning': '未運作', + 'ov.lim.probesOff': '後端的探測服務未運作。', + 'ov.lim.noUpdate': '無法更新', + 'ov.lim.geoNeedsConfig': '更新需要組態寫入,見上方的組態。', + 'ov.lim.geoNoSources': '沒有下載網址。請設定下列網址,或讓 honk 能開啟其狀態資料庫。', + 'ov.lim.geoNoUrl': '未設定下載網址。', + 'ov.lim.subscriptions': '訂閱', + 'ov.lim.noRefresh': '無法重新整理', + 'ov.lim.subscriptionsOff': '訂閱服務未運作。', + 'ov.lim.manage': '節點與來源', + 'ov.lim.noEdit': '無法編輯', + 'ov.lim.mainReadOnly': '主組態檔案不可寫入。', + 'ov.lim.restart': '修改此區段後需重新啟動 honk:', 'ov.f.kind': '類型', 'ov.f.state': '狀態', 'ov.f.visibility': '可見度', diff --git a/src/ui/styles/indicators-charts.css b/src/ui/styles/indicators-charts.css index 7f9e1de3..32049889 100644 --- a/src/ui/styles/indicators-charts.css +++ b/src/ui/styles/indicators-charts.css @@ -150,9 +150,33 @@ white-space: nowrap; font-size: var(--rp-text-xs); } -.rp-capability.unavailable { - color: var(--rp-negative-text); - --dot: var(--rp-negative); +/* A feature that is off or limited: its label and state, then why, the setting that turns it on and where to go. */ +.rp-limit { + display: flex; + flex-direction: column; + align-items: flex-start; + gap: 4px; + min-width: 0; +} +.rp-limit-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + align-self: stretch; +} +/* One key per line, so keys that go together never read as one setting. */ +.rp-limit-keys { + display: flex; + flex-direction: column; + gap: 2px; + margin: 0; + min-width: 0; +} +/* A dotted key is one word, so a phone breaks it anywhere rather than scroll the card. */ +.rp-limit-keys > code, +.rp-limit-note > code { + overflow-wrap: anywhere; } .rp-legend { display: flex;