From 08d09cc5f3b294e0f500c0d31738780c786029b1 Mon Sep 17 00:00:00 2001 From: Tunglies Date: Mon, 23 Nov 2026 07:50:37 +0000 Subject: [PATCH] feat(connections): configure rules from connection details (#8649) * fix(connections): align detail actions in narrow layouts * feat(connections): configure domain and process rules * feat(connections): prefer clicked targets and support IP rules * feat(connections): support parent domain rule editing Closes #7900 * feat(connections): select the root domain for suffix rules * fix(connections): accept empty rule extensions * feat(connections): allow editing IP rule ranges --- Changelog.md | 2 + package.json | 1 + pnpm-lock.yaml | 16 + .../connection/connection-detail.tsx | 161 +++++- .../connection/connection-row-item.tsx | 15 +- .../connection/connection-rule-dialog.tsx | 525 ++++++++++++++++++ src/components/connection/connection-rule.ts | 163 ++++++ .../connection/connection-table.tsx | 26 +- src/locales/ar/connections.json | 36 ++ src/locales/de/connections.json | 36 ++ src/locales/en/connections.json | 36 ++ src/locales/es/connections.json | 36 ++ src/locales/fa/connections.json | 36 ++ src/locales/id/connections.json | 36 ++ src/locales/jp/connections.json | 36 ++ src/locales/ko/connections.json | 36 ++ src/locales/pt/connections.json | 36 ++ src/locales/ru/connections.json | 36 ++ src/locales/tr/connections.json | 36 ++ src/locales/tt/connections.json | 36 ++ src/locales/zh/connections.json | 36 ++ src/locales/zhtw/connections.json | 36 ++ src/pages/connections.tsx | 9 +- src/types/generated/i18n-keys.ts | 34 ++ src/types/generated/i18n-resources.ts | 36 ++ 25 files changed, 1454 insertions(+), 38 deletions(-) create mode 100644 src/components/connection/connection-rule-dialog.tsx create mode 100644 src/components/connection/connection-rule.ts diff --git a/Changelog.md b/Changelog.md index 7db3a6e3b..ccc4051e4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -39,6 +39,7 @@ - 修复断开链式代理时清空已选节点,导致再次连接需要重新选择 - 修复「连接」页表格排序时表头换行、标题位置跳动 - 修复「TUN 设置」未手动保存时,界面显示的默认 MTU 1500 未生效 +- 修复连接详情较窄时操作按钮偏离右侧 - 修复「链式代理」节点列表按名称排序,未保持订阅中的节点顺序 - 修复规则模式下 Muse AI 解锁检测显示错误的出口地区 - 修复使用系统代理或本地代理认证时首页 IP 信息显示直连地址或报错 @@ -63,6 +64,7 @@ ✨ 新增功能 - 新增连接页面按网络协议(TCP/UDP)筛选连接 +- 新增从连接详情设置域名、进程或源/目标 IP 规则,支持识别主域、匹配子域、自定义 IP 网段及修改已有规则 - 新增规则模式下在规则流量未经过的代理组选节点时,自动将首个包含该组的 `select` 代理组切换到该组,可在「杂项设置」关闭 diff --git a/package.json b/package.json index 5fac7fcb2..7fe2fcf7a 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "rehype-sanitize": "^6.0.0", "swr": "^2.5.1", "tauri-plugin-mihomo-api": "github:clash-verge-rev/tauri-plugin-mihomo#main", + "tldts": "7.4.19", "types-pac": "^1.0.3", "validator": "^13.15.35" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6ee5b0592..e465caf28 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -304,6 +304,9 @@ importers: tauri-plugin-mihomo-api: specifier: github:clash-verge-rev/tauri-plugin-mihomo#main version: https://codeload.github.com/clash-verge-rev/tauri-plugin-mihomo/tar.gz/7e4fa8642cf6c394ed88b5a969420d8eab60087f + tldts: + specifier: 7.4.19 + version: 7.4.19 types-pac: specifier: ^1.0.3 version: 1.0.3 @@ -4044,6 +4047,13 @@ packages: resolution: {integrity: sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==} engines: {node: '>=12.0.0'} + tldts-core@7.5.2: + resolution: {integrity: sha512-8W1topazDwhMKbm2I83IPa57Ow5VUxFgLbXv42+vSILnv8FY5OHvdEY/tS6WoWeMbxkHZQhra5cmeFHriKptSQ==} + + tldts@7.4.19: + resolution: {integrity: sha512-48dH6aSpQnpbzDUc4vIQZ1VjB8tkK+e8c1yx05/SZK+rkssgjEOlxDd/yU8/a4vGYQ9vRgJr9dwMq9TJ0b3X2Q==} + hasBin: true + trim-lines@3.0.1: resolution: {integrity: sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==} @@ -8147,6 +8157,12 @@ snapshots: fdir: 6.5.0(picomatch@4.0.7) picomatch: 4.0.7 + tldts-core@7.5.2: {} + + tldts@7.4.19: + dependencies: + tldts-core: 7.5.2 + trim-lines@3.0.1: {} trough@2.2.0: {} diff --git a/src/components/connection/connection-detail.tsx b/src/components/connection/connection-detail.tsx index 77cda53d7..80c3abc3c 100644 --- a/src/components/connection/connection-detail.tsx +++ b/src/components/connection/connection-detail.tsx @@ -5,10 +5,24 @@ import { useCallback, useImperativeHandle, useState, type Ref } from 'react' import { useTranslation } from 'react-i18next' import { closeConnection } from 'tauri-plugin-mihomo-api' +import { useProfiles } from '@/hooks/use-profiles' import parseTraffic from '@/utils/parse-traffic' +import { + getConnectionRuleTargets, + type ConnectionRuleKind, +} from './connection-rule' +import { + ConnectionRuleDialog, + type ConnectionRuleTarget, +} from './connection-rule-dialog' + export interface ConnectionDetailRef { - open: (detail: IConnectionsItem, closed: boolean) => void + open: ( + detail: IConnectionsItem, + closed: boolean, + preferredKind?: ConnectionRuleKind, + ) => void close: () => void } @@ -16,7 +30,12 @@ export function ConnectionDetail({ ref }: { ref?: Ref }) { const [open, setOpen] = useState(false) const [detail, setDetail] = useState(null) const [closed, setClosed] = useState(false) + const [preferredKind, setPreferredKind] = + useState('domain') const theme = useTheme() + const [ruleTarget, setRuleTarget] = useState( + null, + ) const onClose = useCallback(() => { setOpen(false) @@ -25,51 +44,90 @@ export function ConnectionDetail({ ref }: { ref?: Ref }) { }, []) useImperativeHandle(ref, () => ({ - open: (detail: IConnectionsItem, closed: boolean) => { + open: ( + detail: IConnectionsItem, + closed: boolean, + preferredKind = 'domain', + ) => { if (open) return setOpen(true) setDetail(detail) setClosed(closed) + setPreferredKind(preferredKind) }, close: onClose, })) return ( - - ) : null - } - /> + <> + { + setRuleTarget(target) + onClose() + }} + /> + ) : null + } + /> + {ruleTarget && ( + setRuleTarget(null)} + /> + )} + ) } interface InnerProps { data: IConnectionsItem closed: boolean + preferredKind: ConnectionRuleKind onClose?: () => void + onAddRule: (target: ConnectionRuleTarget) => void } -const InnerConnectionDetail = ({ data, closed, onClose }: InnerProps) => { +const InnerConnectionDetail = ({ + data, + closed, + preferredKind, + onClose, + onAddRule, +}: InnerProps) => { const { t } = useTranslation() + const { current } = useProfiles() const { metadata, rulePayload } = data + const targets = getConnectionRuleTargets(metadata) + const canAddRule = Boolean( + current?.uid && + current.option?.rules && + (targets.domain || + targets.process || + targets.source || + targets.destination), + ) const theme = useTheme() const chains = [...data.chains].reverse().join(' / ') const rule = rulePayload ? `${data.rule}(${rulePayload})` : data.rule @@ -105,7 +163,7 @@ const InnerConnectionDetail = ({ data, closed, onClose }: InnerProps) => { { label: t('connections.components.fields.rule'), value: rule }, { label: t('connections.components.fields.process'), - value: `${metadata.process}${metadata.processPath ? `(${metadata.processPath})` : ''}`, + value: `${metadata.process ?? ''}${metadata.processPath ? `(${metadata.processPath})` : ''}`, }, { label: t('connections.components.fields.time'), @@ -132,7 +190,14 @@ const InnerConnectionDetail = ({ data, closed, onClose }: InnerProps) => { const onDelete = useLockFn(async () => closeConnection(data.id)) return ( - + {information.map((each) => (
{each.label} @@ -147,8 +212,32 @@ const InnerConnectionDetail = ({ data, closed, onClose }: InnerProps) => {
))} - {!closed && ( - + + + {!closed && ( + )} + + {!canAddRule && ( + + {t( + targets.domain || + targets.process || + targets.source || + targets.destination + ? 'connections.ruleDialog.noProfile' + : 'connections.ruleDialog.noMetadata', + )} )} diff --git a/src/components/connection/connection-row-item.tsx b/src/components/connection/connection-row-item.tsx index 9eb5de4e0..2f9c6482f 100644 --- a/src/components/connection/connection-row-item.tsx +++ b/src/components/connection/connection-row-item.tsx @@ -7,11 +7,12 @@ import { closeConnection } from 'tauri-plugin-mihomo-api' import { RelativeTime } from './connection-relative-time' import type { ConnectionRowView } from './connection-row-view' +import type { ConnectionRuleKind } from './connection-rule' interface Props { row: ConnectionRowView closed: boolean - onShowDetail: (id: string) => void + onShowDetail: (id: string, preferredKind?: ConnectionRuleKind) => void } const tagStyle = { @@ -86,7 +87,17 @@ export const ConnectionRowItem = memo(
{row.network} {row.type} - {row.process && {row.process}} + {row.process && ( + { + event.stopPropagation() + onShowDetail(row.id, 'process') + }} + > + {row.process} + + )} {row.chains && {row.chains}} diff --git a/src/components/connection/connection-rule-dialog.tsx b/src/components/connection/connection-rule-dialog.tsx new file mode 100644 index 000000000..7839041e5 --- /dev/null +++ b/src/components/connection/connection-rule-dialog.tsx @@ -0,0 +1,525 @@ +import { + Alert, + Autocomplete, + Box, + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + FormControlLabel, + MenuItem, + Radio, + RadioGroup, + TextField, + Typography, +} from '@mui/material' +import { useLockFn } from 'ahooks' +import { useEffect, useState } from 'react' +import { useTranslation } from 'react-i18next' + +import { + useClashConfigData, + useProxiesData, +} from '@/providers/app-data-context' +import { getProfiles, readProfileFile, saveProfileFile } from '@/services/cmds' +import { mutate } from '@/services/mutate' +import { showNotice } from '@/services/notice-service' + +import { + getConnectionIPRule, + getConnectionRuleTargets, + getConnectionRules, + getConnectionRootDomain, + isConnectionRuleDomain, + findConnectionRule, + saveConnectionRule, + type ConnectionRuleKind, +} from './connection-rule' + +export interface ConnectionRuleTarget { + metadata: IConnectionsItem['metadata'] + profileUid: string + profileName: string + rulesUid: string + preferredKind: ConnectionRuleKind +} + +type DomainScope = 'DOMAIN' | 'DOMAIN-SUFFIX' | 'ROOT-DOMAIN' + +function getInitialKind(target: ConnectionRuleTarget) { + const targets = getConnectionRuleTargets(target.metadata) + return targets[target.preferredKind] + ? target.preferredKind + : ((['domain', 'process', 'source', 'destination'] as const).find( + (kind) => targets[kind], + ) ?? 'domain') +} + +export function ConnectionRuleDialog({ + target, + onClose, +}: { + target: ConnectionRuleTarget + onClose: () => void +}) { + const { t } = useTranslation() + const { proxyView } = useProxiesData() + const { clashConfig } = useClashConfigData() + const targets = getConnectionRuleTargets(target.metadata) + const [rootDomain, setRootDomain] = useState() + const [kind, setKind] = useState(() => + getInitialKind(target), + ) + const [policy, setPolicy] = useState(null) + const [scope, setScope] = useState('DOMAIN') + const [matchingInput, setMatchingInput] = useState( + () => targets[getInitialKind(target)]?.value ?? '', + ) + const [rules, setRules] = useState(null) + const [loadAttempt, setLoadAttempt] = useState(0) + const [loading, setLoading] = useState(true) + const [saving, setSaving] = useState(false) + const [error, setError] = useState('') + const selected = targets[kind] + const matchingRoot = kind === 'domain' && scope === 'ROOT-DOMAIN' + const editingDomain = kind === 'domain' && scope === 'DOMAIN-SUFFIX' + const editingIP = kind === 'source' || kind === 'destination' + const matchingValue = matchingRoot + ? (rootDomain ?? '') + : editingDomain || editingIP + ? matchingInput + : (selected?.value ?? '') + const invalidDomain = + editingDomain && + !isConnectionRuleDomain(matchingInput, targets.domain?.value ?? '') + const ipRule = editingIP + ? getConnectionIPRule(matchingInput, kind === 'source') + : undefined + const invalidIP = editingIP && !ipRule + const invalidValue = invalidDomain || invalidIP + const condition = editingIP + ? ipRule + : selected + ? { + type: + kind === 'domain' && scope !== 'DOMAIN' + ? 'DOMAIN-SUFFIX' + : selected.type, + value: kind === 'domain' ? matchingValue.trim() : selected.value, + } + : undefined + const existing = + rules && condition && !invalidValue + ? findConnectionRule(rules, condition) + : undefined + const modifying = Boolean(existing) + const groups = proxyView + ? proxyView.groups.length || !proxyView.global + ? proxyView.groups + : [proxyView.global] + : [] + const policies = [ + ...new Set(['DIRECT', 'REJECT', ...groups.map((group) => group.name)]), + ] + + const kindLabels = { + domain: t('connections.ruleDialog.domain'), + process: t('connections.components.fields.process'), + source: t('connections.ruleDialog.sourceIp'), + destination: t('connections.ruleDialog.destinationIp'), + } + + const unavailablePolicy = Boolean(policy && !policies.includes(policy)) + const blocked = loading || saving || rules === null + + useEffect(() => { + let cancelled = false + const ruleTargets = getConnectionRuleTargets(target.metadata) + Promise.all([ + readProfileFile(target.rulesUid), + ruleTargets.domain + ? getConnectionRootDomain(ruleTargets.domain.value) + : undefined, + ]) + .then(([content, root]) => { + const loadedRules = getConnectionRules(content) + const initialKind = getInitialKind(target) + const selectedTarget = ruleTargets[initialKind] + const initial = selectedTarget + ? (findConnectionRule(loadedRules, selectedTarget) ?? + (initialKind === 'domain' + ? findConnectionRule(loadedRules, { + ...selectedTarget, + type: 'DOMAIN-SUFFIX', + }) + : undefined)) + : undefined + if (cancelled) return + setRootDomain(root) + setRules(loadedRules) + setPolicy(initial?.policy ?? null) + setScope(initial?.type === 'DOMAIN-SUFFIX' ? 'DOMAIN-SUFFIX' : 'DOMAIN') + }) + .catch((err: unknown) => { + if (!cancelled) + setError(err instanceof Error ? err.message : String(err)) + }) + .finally(() => { + if (!cancelled) setLoading(false) + }) + return () => { + cancelled = true + } + }, [target, loadAttempt]) + + const handleSave = useLockFn(async () => { + if ( + blocked || + !condition || + invalidValue || + !policy || + !policies.includes(policy) + ) + return + if (/[\r\n,]/u.test(condition.value) || /[\r\n,]/u.test(policy)) { + setError(t('connections.ruleDialog.unsupportedValue')) + return + } + setSaving(true) + setError('') + try { + const result = await mutate( + async () => { + const checkProfile = async () => { + const profiles = await getProfiles() + const current = profiles.items?.find( + (item) => item.uid === profiles.current, + ) + if ( + profiles.current !== target.profileUid || + current?.option?.rules !== target.rulesUid + ) { + throw new Error(t('connections.ruleDialog.profileChanged')) + } + } + await checkProfile() + const content = await readProfileFile(target.rulesUid) + const updated = saveConnectionRule(content, condition, policy) + await checkProfile() + return saveProfileFile(target.rulesUid, updated) + }, + { id: `save-profile-file:${target.rulesUid}`, errorNotice: false }, + ) + if (!result.ok || !result.value) { + setError(t('connections.ruleDialog.applyFailed')) + return + } + showNotice.success('connections.ruleDialog.saved') + onClose() + } catch (err) { + setError(err instanceof Error ? err.message : String(err)) + } finally { + setSaving(false) + } + }) + + return ( + + + {t( + modifying + ? 'connections.ruleDialog.modifyTitle' + : 'connections.ruleDialog.title', + )} + + + + { + const next = event.target.value as ConnectionRuleKind + const nextTarget = targets[next] + const rule = + rules && nextTarget + ? (findConnectionRule(rules, nextTarget) ?? + (next === 'domain' + ? findConnectionRule(rules, { + ...nextTarget, + type: 'DOMAIN-SUFFIX', + }) + : undefined)) + : undefined + setMatchingInput(nextTarget?.value ?? '') + setKind(next) + setPolicy(rule?.policy ?? null) + setScope( + rule?.type === 'DOMAIN-SUFFIX' ? 'DOMAIN-SUFFIX' : 'DOMAIN', + ) + }} + > + {(['domain', 'process', 'source', 'destination'] as const).map( + (option) => ( + + {kindLabels[option]} + {!targets[option] && + ` · ${t('connections.ruleDialog.unavailable')}`} + + ), + )} + + {kind === 'process' ? ( + <> + {target.metadata.process?.trim() && ( + + )} + {selected?.type === 'PROCESS-PATH' && ( + + )} + + ) : ( + { + const value = event.target.value + setMatchingInput(value) + const nextCondition = editingIP + ? getConnectionIPRule(value, kind === 'source') + : isConnectionRuleDomain(value, targets.domain?.value ?? '') + ? { type: 'DOMAIN-SUFFIX', value: value.trim() } + : undefined + const match = + rules && nextCondition + ? findConnectionRule(rules, nextCondition) + : undefined + if (match) setPolicy(match.policy) + }} + error={invalidValue} + helperText={ + editingDomain || matchingRoot ? ( + <> + {t('connections.ruleDialog.connectionHost', { + host: targets.domain?.value, + })} + {invalidDomain && ( + <> +
+ {t('connections.ruleDialog.invalidDomain')} + + )} + + ) : invalidIP ? ( + t('connections.ruleDialog.invalidIp') + ) : undefined + } + slotProps={{ + input: { readOnly: !editingDomain && !editingIP }, + htmlInput: { + title: condition?.value, + }, + }} + /> + )} +
+ {kind === 'domain' && ( + { + const nextScope = value as DomainScope + setScope(nextScope) + setMatchingInput(targets.domain?.value ?? '') + const match = + rules && targets.domain + ? findConnectionRule(rules, { + type: nextScope === 'DOMAIN' ? 'DOMAIN' : 'DOMAIN-SUFFIX', + value: + nextScope === 'ROOT-DOMAIN' + ? (rootDomain ?? '') + : targets.domain.value, + }) + : undefined + setPolicy(match?.policy ?? null) + }} + sx={{ mt: 0.5 }} + > + } + disabled={blocked} + label={t('connections.ruleDialog.exactDomain')} + /> + } + disabled={blocked} + label={t('connections.ruleDialog.allSubdomains')} + /> + {rootDomain && + rootDomain.toLowerCase() !== + targets.domain?.value.toLowerCase() && ( + } + disabled={blocked} + label={t('connections.ruleDialog.rootDomain', { + domain: rootDomain, + })} + /> + )} + + )} + {(kind === 'source' || kind === 'destination') && ( + + {t( + kind === 'source' + ? 'connections.ruleDialog.sourceHint' + : 'connections.ruleDialog.destinationHint', + )} + + )} + {kind === 'process' && ( + + {selected?.type === 'PROCESS-PATH' + ? t('connections.ruleDialog.processPathHint') + : t('connections.ruleDialog.processNameHint')} + + )} + + value === 'DIRECT' + ? t('proxies.components.enums.policies.DIRECT') + : value === 'REJECT' + ? t('proxies.components.enums.policies.REJECT') + : value + } + getOptionDisabled={(value) => !policies.includes(value)} + value={policy} + onChange={(_, value) => setPolicy(value)} + disabled={blocked} + loading={loading} + renderInput={(params) => ( + + )} + /> + {clashConfig && clashConfig.mode !== 'rule' && ( + + {t('connections.ruleDialog.ruleModeHint')} + + )} + {error && ( + + + {error} + {rules === null && ( + + )} + + + )} + + {t( + modifying + ? 'connections.ruleDialog.editDestination' + : 'connections.ruleDialog.destination', + { + name: target.profileName, + }, + )} + + + {t('connections.ruleDialog.newConnections')} + +
+ + + + +
+ ) +} diff --git a/src/components/connection/connection-rule.ts b/src/components/connection/connection-rule.ts new file mode 100644 index 000000000..22fe372da --- /dev/null +++ b/src/components/connection/connection-rule.ts @@ -0,0 +1,163 @@ +import { dump, loadAll } from 'js-yaml' +import isFQDN from 'validator/es/lib/isFQDN' +import isIP from 'validator/es/lib/isIP' +import isIPRange from 'validator/es/lib/isIPRange' + +export type ConnectionRuleKind = 'domain' | 'process' | 'source' | 'destination' + +function getAddressRule(address: string | undefined, source: boolean) { + const ip = address?.trim() + if (!ip || !isIP(ip)) return undefined + return getConnectionIPRule(`${ip}/${isIP(ip, 4) ? 32 : 128}`, source) +} + +export function getConnectionIPRule(value: string, source: boolean) { + const cidr = value.trim() + if (cidr.includes('%') || !isIPRange(cidr)) return undefined + const ipv4 = isIP(cidr.split('/')[0], 4) + return { + type: source ? 'SRC-IP-CIDR' : ipv4 ? 'IP-CIDR' : 'IP-CIDR6', + value: cidr, + } +} + +export function getConnectionRuleTargets( + metadata: Pick< + IConnectionsItem['metadata'], + | 'host' + | 'process' + | 'processPath' + | 'sourceIP' + | 'destinationIP' + | 'remoteDestination' + >, +) { + const host = metadata.host?.trim() ?? '' + const path = metadata.processPath + const name = metadata.process + const domain = + host && !isIP(host) && isFQDN(host, { require_tld: false }) + ? { type: 'DOMAIN', value: host } + : undefined + const process = path?.trim() + ? { type: 'PROCESS-PATH', value: path } + : name?.trim() + ? { type: 'PROCESS-NAME', value: name } + : undefined + const source = getAddressRule(metadata.sourceIP, true) + const destination = + getAddressRule(metadata.destinationIP, false) ?? + getAddressRule(metadata.remoteDestination, false) + return { domain, process, source, destination } +} + +export function isConnectionRuleDomain(value: string, host: string) { + const domain = value.trim() + if (!domain || isIP(domain) || !isFQDN(domain, { require_tld: false })) + return false + const normalized = domain.toLowerCase() + const current = host.toLowerCase() + return ( + normalized === current || + (domain.split('.').length >= 2 && current.endsWith(`.${normalized}`)) + ) +} + +export async function getConnectionRootDomain(host: string) { + const { parse } = await import('tldts') + const { domain, isIcann, isPrivate } = parse(host, { + allowPrivateDomains: true, + }) + return domain && (isIcann || isPrivate) ? domain : undefined +} + +function parseRuleExtension(content: string) { + const documents = loadAll(content) + if (documents.length > 1) { + throw new Error('The rule extension must contain a single YAML document.') + } + const parsed = documents[0] + if ( + parsed !== undefined && + parsed !== null && + (typeof parsed !== 'object' || + Array.isArray(parsed) || + Object.getPrototypeOf(parsed) !== Object.prototype) + ) { + throw new Error('The rule extension must be a YAML mapping.') + } + const config = (parsed ?? {}) as Record + for (const key of ['prepend', 'append', 'delete']) { + const sequence = config[key] + if ( + sequence != null && + (!Array.isArray(sequence) || + sequence.some((item) => typeof item !== 'string')) + ) { + throw new Error('The rule extension contains an invalid rule list.') + } + } + return config +} + +interface RuleCondition { + type: string + value: string +} + +function matchesConnectionRule(raw: string, target: RuleCondition) { + const parts = raw.split(',').map((part) => part.trim()) + const hasNoResolve = + (target.type === 'IP-CIDR' || target.type === 'IP-CIDR6') && + parts.length === 4 && + parts[3] === 'no-resolve' + if (parts.length !== 3 && !hasNoResolve) return false + if (target.type === 'DOMAIN' || target.type === 'DOMAIN-SUFFIX') { + return ( + parts[0] === target.type && + parts[1].toLowerCase() === target.value.toLowerCase() + ) + } + return parts[0] === target.type && parts[1] === target.value +} + +export function getConnectionRules(content: string): string[] { + const config = parseRuleExtension(content) + return [ + ...((config.prepend ?? []) as string[]), + ...((config.append ?? []) as string[]), + ] +} + +export function findConnectionRule(rules: string[], target: RuleCondition) { + for (const raw of rules) { + if (matchesConnectionRule(raw, target)) { + const [type, , policy] = raw.split(',').map((part) => part.trim()) + return { type, policy } + } + } + return undefined +} + +export function saveConnectionRule( + content: string, + target: RuleCondition, + policy: string, +): string { + const config = parseRuleExtension(content) + const rule = `${target.type},${target.value},${policy}` + let replaced = false + for (const key of ['prepend', 'append']) { + if (!Array.isArray(config[key])) continue + config[key] = (config[key] as string[]).flatMap((raw) => { + if (!matchesConnectionRule(raw, target)) return [raw] + if (replaced) return [] + replaced = true + return [raw.split(',').length === 4 ? `${rule},no-resolve` : rule] + }) + } + if (!replaced) { + config.prepend = [rule, ...((config.prepend ?? []) as string[])] + } + return dump(config, { forceQuotes: true }) +} diff --git a/src/components/connection/connection-table.tsx b/src/components/connection/connection-table.tsx index 111a46a9a..6270a65e1 100644 --- a/src/components/connection/connection-table.tsx +++ b/src/components/connection/connection-table.tsx @@ -29,6 +29,7 @@ import { getConnectionStartTime, getConnectionTypeLabel, } from './connection-row-view' +import type { ConnectionRuleKind } from './connection-rule' const ROW_HEIGHT = 40 const RESIZE_HANDLE_WIDTH = 6 @@ -257,7 +258,7 @@ const renderCell = ( interface RowComponentProps { row: IConnectionsItem columns: DisplayColumn[] - onShowDetail: (id: string) => void + onShowDetail: (id: string, preferredKind?: ConnectionRuleKind) => void getSnapshot: (row: IConnectionsItem) => TableRowSnapshot borderColor: string virtualTop: number @@ -273,7 +274,22 @@ const RowComponent = memo( virtualTop, }: RowComponentProps) { const handleClick = useCallback( - () => onShowDetail(row.id), + (event: ReactMouseEvent) => { + const field = + event.target instanceof Element + ? event.target.closest('[data-connection-field]') + ?.dataset.connectionField + : undefined + const preferredKind = + field === 'process' + ? 'process' + : field === 'source' + ? 'source' + : field === 'remoteDestination' + ? 'destination' + : 'domain' + onShowDetail(row.id, preferredKind) + }, [onShowDetail, row.id], ) const snapshot = getSnapshot(row) @@ -295,6 +311,7 @@ const RowComponent = memo( {columns.map((column) => (
void + onShowDetail: (id: string, preferredKind?: ConnectionRuleKind) => void columnManagerOpen: boolean onCloseColumnManager: () => void } @@ -343,7 +360,8 @@ export const ConnectionTable = (props: Props) => { const onShowDetailRef = useRef(rawOnShowDetail) onShowDetailRef.current = rawOnShowDetail const onShowDetail = useCallback( - (id: string) => onShowDetailRef.current(id), + (id: string, preferredKind?: ConnectionRuleKind) => + onShowDetailRef.current(id, preferredKind), [], ) const { t } = useTranslation() diff --git a/src/locales/ar/connections.json b/src/locales/ar/connections.json index c5bcd0057..ad0bd1a91 100644 --- a/src/locales/ar/connections.json +++ b/src/locales/ar/connections.json @@ -30,5 +30,41 @@ "title": "الأعمدة", "dragHandle": "Drag handle" } + }, + "ruleDialog": { + "title": "Add rule…", + "matchBy": "Match by", + "domain": "Domain", + "unavailable": "Not available", + "destination": "Add to the prepend rules of “{{name}}”.", + "newConnections": "New connections will match the updated configuration.", + "processPathHint": "Matches all destinations accessed by processes at this path.", + "processNameHint": "Matches all destinations accessed by processes with this name.", + "ruleModeHint": "Rule-based routing takes effect in Rule mode.", + "addAndApply": "Add and apply", + "profileChanged": "The active profile changed. Close this dialog and add the rule again.", + "applyFailed": "The rule could not be applied. Your selection has been kept.", + "unsupportedValue": "This value contains characters that cannot be used in a quick rule.", + "saved": "Rule saved and configuration applied.", + "noMetadata": "This connection has no domain, process or IP information for configuring a rule.", + "noProfile": "No active profile with an editable rule extension is available.", + "entry": "Configure rule…", + "modifyTitle": "Modify rule", + "domainScope": "Domain scope", + "exactDomain": "Only this domain", + "allSubdomains": "This domain and all its subdomains", + "rootDomain": "النطاق الرئيسي وجميع نطاقاته الفرعية ({{domain}})", + "policyUnavailable": "This policy is no longer available. Choose another policy.", + "editDestination": "Update the existing rule in “{{name}}”, keeping its position.", + "saveAndApply": "Save and apply", + "sourceIp": "Source IP", + "destinationIp": "Destination IP", + "sourceHint": "Matches all requests from this IP or subnet, including requests from other applications. No port filtering.", + "destinationHint": "Matches this destination IP or subnet across all domains. No port filtering.", + "fullPath": "Full path", + "connectionHost": "Current connection domain: {{host}}", + "invalidDomain": "Enter the current domain or a parent domain with at least two labels.", + "matchingDomain": "Matching domain", + "invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6." } } diff --git a/src/locales/de/connections.json b/src/locales/de/connections.json index 5f5b62dff..b7d71ac66 100644 --- a/src/locales/de/connections.json +++ b/src/locales/de/connections.json @@ -30,5 +30,41 @@ "title": "Spalten", "dragHandle": "Ziehpunkt" } + }, + "ruleDialog": { + "title": "Add rule…", + "matchBy": "Match by", + "domain": "Domain", + "unavailable": "Not available", + "destination": "Add to the prepend rules of “{{name}}”.", + "newConnections": "New connections will match the updated configuration.", + "processPathHint": "Matches all destinations accessed by processes at this path.", + "processNameHint": "Matches all destinations accessed by processes with this name.", + "ruleModeHint": "Rule-based routing takes effect in Rule mode.", + "addAndApply": "Add and apply", + "profileChanged": "The active profile changed. Close this dialog and add the rule again.", + "applyFailed": "The rule could not be applied. Your selection has been kept.", + "unsupportedValue": "This value contains characters that cannot be used in a quick rule.", + "saved": "Rule saved and configuration applied.", + "noMetadata": "This connection has no domain, process or IP information for configuring a rule.", + "noProfile": "No active profile with an editable rule extension is available.", + "entry": "Configure rule…", + "modifyTitle": "Modify rule", + "domainScope": "Domain scope", + "exactDomain": "Only this domain", + "allSubdomains": "This domain and all its subdomains", + "rootDomain": "Hauptdomain und alle Subdomains ({{domain}})", + "policyUnavailable": "This policy is no longer available. Choose another policy.", + "editDestination": "Update the existing rule in “{{name}}”, keeping its position.", + "saveAndApply": "Save and apply", + "sourceIp": "Source IP", + "destinationIp": "Destination IP", + "sourceHint": "Matches all requests from this IP or subnet, including requests from other applications. No port filtering.", + "destinationHint": "Matches this destination IP or subnet across all domains. No port filtering.", + "fullPath": "Full path", + "connectionHost": "Current connection domain: {{host}}", + "invalidDomain": "Enter the current domain or a parent domain with at least two labels.", + "matchingDomain": "Matching domain", + "invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6." } } diff --git a/src/locales/en/connections.json b/src/locales/en/connections.json index 82b3cebac..59b805648 100644 --- a/src/locales/en/connections.json +++ b/src/locales/en/connections.json @@ -30,5 +30,41 @@ "title": "Columns", "dragHandle": "Drag handle" } + }, + "ruleDialog": { + "title": "Add rule…", + "matchBy": "Match by", + "domain": "Domain", + "unavailable": "Not available", + "destination": "Add to the prepend rules of “{{name}}”.", + "newConnections": "New connections will match the updated configuration.", + "processPathHint": "Matches all destinations accessed by processes at this path.", + "processNameHint": "Matches all destinations accessed by processes with this name.", + "ruleModeHint": "Rule-based routing takes effect in Rule mode.", + "addAndApply": "Add and apply", + "profileChanged": "The active profile changed. Close this dialog and add the rule again.", + "applyFailed": "The rule could not be applied. Your selection has been kept.", + "unsupportedValue": "This value contains characters that cannot be used in a quick rule.", + "saved": "Rule saved and configuration applied.", + "noMetadata": "This connection has no domain, process or IP information for configuring a rule.", + "noProfile": "No active profile with an editable rule extension is available.", + "entry": "Configure rule…", + "modifyTitle": "Modify rule", + "domainScope": "Domain scope", + "exactDomain": "Only this domain", + "allSubdomains": "This domain and all its subdomains", + "rootDomain": "Root domain and all its subdomains ({{domain}})", + "policyUnavailable": "This policy is no longer available. Choose another policy.", + "editDestination": "Update the existing rule in “{{name}}”, keeping its position.", + "saveAndApply": "Save and apply", + "sourceIp": "Source IP", + "destinationIp": "Destination IP", + "sourceHint": "Matches all requests from this IP or subnet, including requests from other applications. No port filtering.", + "destinationHint": "Matches this destination IP or subnet across all domains. No port filtering.", + "fullPath": "Full path", + "connectionHost": "Current connection domain: {{host}}", + "invalidDomain": "Enter the current domain or a parent domain with at least two labels.", + "matchingDomain": "Matching domain", + "invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6." } } diff --git a/src/locales/es/connections.json b/src/locales/es/connections.json index 1b49bc17c..8513d7c9c 100644 --- a/src/locales/es/connections.json +++ b/src/locales/es/connections.json @@ -30,5 +30,41 @@ "title": "Columnas", "dragHandle": "Drag handle" } + }, + "ruleDialog": { + "title": "Add rule…", + "matchBy": "Match by", + "domain": "Domain", + "unavailable": "Not available", + "destination": "Add to the prepend rules of “{{name}}”.", + "newConnections": "New connections will match the updated configuration.", + "processPathHint": "Matches all destinations accessed by processes at this path.", + "processNameHint": "Matches all destinations accessed by processes with this name.", + "ruleModeHint": "Rule-based routing takes effect in Rule mode.", + "addAndApply": "Add and apply", + "profileChanged": "The active profile changed. Close this dialog and add the rule again.", + "applyFailed": "The rule could not be applied. Your selection has been kept.", + "unsupportedValue": "This value contains characters that cannot be used in a quick rule.", + "saved": "Rule saved and configuration applied.", + "noMetadata": "This connection has no domain, process or IP information for configuring a rule.", + "noProfile": "No active profile with an editable rule extension is available.", + "entry": "Configure rule…", + "modifyTitle": "Modify rule", + "domainScope": "Domain scope", + "exactDomain": "Only this domain", + "allSubdomains": "This domain and all its subdomains", + "rootDomain": "Dominio principal y todos sus subdominios ({{domain}})", + "policyUnavailable": "This policy is no longer available. Choose another policy.", + "editDestination": "Update the existing rule in “{{name}}”, keeping its position.", + "saveAndApply": "Save and apply", + "sourceIp": "Source IP", + "destinationIp": "Destination IP", + "sourceHint": "Matches all requests from this IP or subnet, including requests from other applications. No port filtering.", + "destinationHint": "Matches this destination IP or subnet across all domains. No port filtering.", + "fullPath": "Full path", + "connectionHost": "Current connection domain: {{host}}", + "invalidDomain": "Enter the current domain or a parent domain with at least two labels.", + "matchingDomain": "Matching domain", + "invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6." } } diff --git a/src/locales/fa/connections.json b/src/locales/fa/connections.json index a8c8687e7..631da6cd1 100644 --- a/src/locales/fa/connections.json +++ b/src/locales/fa/connections.json @@ -30,5 +30,41 @@ "title": "ستون‌ها", "dragHandle": "Drag handle" } + }, + "ruleDialog": { + "title": "Add rule…", + "matchBy": "Match by", + "domain": "Domain", + "unavailable": "Not available", + "destination": "Add to the prepend rules of “{{name}}”.", + "newConnections": "New connections will match the updated configuration.", + "processPathHint": "Matches all destinations accessed by processes at this path.", + "processNameHint": "Matches all destinations accessed by processes with this name.", + "ruleModeHint": "Rule-based routing takes effect in Rule mode.", + "addAndApply": "Add and apply", + "profileChanged": "The active profile changed. Close this dialog and add the rule again.", + "applyFailed": "The rule could not be applied. Your selection has been kept.", + "unsupportedValue": "This value contains characters that cannot be used in a quick rule.", + "saved": "Rule saved and configuration applied.", + "noMetadata": "This connection has no domain, process or IP information for configuring a rule.", + "noProfile": "No active profile with an editable rule extension is available.", + "entry": "Configure rule…", + "modifyTitle": "Modify rule", + "domainScope": "Domain scope", + "exactDomain": "Only this domain", + "allSubdomains": "This domain and all its subdomains", + "rootDomain": "دامنهٔ اصلی و همهٔ زیردامنه‌های آن ({{domain}})", + "policyUnavailable": "This policy is no longer available. Choose another policy.", + "editDestination": "Update the existing rule in “{{name}}”, keeping its position.", + "saveAndApply": "Save and apply", + "sourceIp": "Source IP", + "destinationIp": "Destination IP", + "sourceHint": "Matches all requests from this IP or subnet, including requests from other applications. No port filtering.", + "destinationHint": "Matches this destination IP or subnet across all domains. No port filtering.", + "fullPath": "Full path", + "connectionHost": "Current connection domain: {{host}}", + "invalidDomain": "Enter the current domain or a parent domain with at least two labels.", + "matchingDomain": "Matching domain", + "invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6." } } diff --git a/src/locales/id/connections.json b/src/locales/id/connections.json index 29748ccf9..0c2722dca 100644 --- a/src/locales/id/connections.json +++ b/src/locales/id/connections.json @@ -30,5 +30,41 @@ "title": "Kolom", "dragHandle": "Drag handle" } + }, + "ruleDialog": { + "title": "Add rule…", + "matchBy": "Match by", + "domain": "Domain", + "unavailable": "Not available", + "destination": "Add to the prepend rules of “{{name}}”.", + "newConnections": "New connections will match the updated configuration.", + "processPathHint": "Matches all destinations accessed by processes at this path.", + "processNameHint": "Matches all destinations accessed by processes with this name.", + "ruleModeHint": "Rule-based routing takes effect in Rule mode.", + "addAndApply": "Add and apply", + "profileChanged": "The active profile changed. Close this dialog and add the rule again.", + "applyFailed": "The rule could not be applied. Your selection has been kept.", + "unsupportedValue": "This value contains characters that cannot be used in a quick rule.", + "saved": "Rule saved and configuration applied.", + "noMetadata": "This connection has no domain, process or IP information for configuring a rule.", + "noProfile": "No active profile with an editable rule extension is available.", + "entry": "Configure rule…", + "modifyTitle": "Modify rule", + "domainScope": "Domain scope", + "exactDomain": "Only this domain", + "allSubdomains": "This domain and all its subdomains", + "rootDomain": "Domain utama dan semua subdomainnya ({{domain}})", + "policyUnavailable": "This policy is no longer available. Choose another policy.", + "editDestination": "Update the existing rule in “{{name}}”, keeping its position.", + "saveAndApply": "Save and apply", + "sourceIp": "Source IP", + "destinationIp": "Destination IP", + "sourceHint": "Matches all requests from this IP or subnet, including requests from other applications. No port filtering.", + "destinationHint": "Matches this destination IP or subnet across all domains. No port filtering.", + "fullPath": "Full path", + "connectionHost": "Current connection domain: {{host}}", + "invalidDomain": "Enter the current domain or a parent domain with at least two labels.", + "matchingDomain": "Matching domain", + "invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6." } } diff --git a/src/locales/jp/connections.json b/src/locales/jp/connections.json index 25fb84e8a..375fb277d 100644 --- a/src/locales/jp/connections.json +++ b/src/locales/jp/connections.json @@ -30,5 +30,41 @@ "title": "列", "dragHandle": "Drag handle" } + }, + "ruleDialog": { + "title": "Add rule…", + "matchBy": "Match by", + "domain": "Domain", + "unavailable": "Not available", + "destination": "Add to the prepend rules of “{{name}}”.", + "newConnections": "New connections will match the updated configuration.", + "processPathHint": "Matches all destinations accessed by processes at this path.", + "processNameHint": "Matches all destinations accessed by processes with this name.", + "ruleModeHint": "Rule-based routing takes effect in Rule mode.", + "addAndApply": "Add and apply", + "profileChanged": "The active profile changed. Close this dialog and add the rule again.", + "applyFailed": "The rule could not be applied. Your selection has been kept.", + "unsupportedValue": "This value contains characters that cannot be used in a quick rule.", + "saved": "Rule saved and configuration applied.", + "noMetadata": "This connection has no domain, process or IP information for configuring a rule.", + "noProfile": "No active profile with an editable rule extension is available.", + "entry": "Configure rule…", + "modifyTitle": "Modify rule", + "domainScope": "Domain scope", + "exactDomain": "Only this domain", + "allSubdomains": "This domain and all its subdomains", + "rootDomain": "メインドメインとすべてのサブドメイン({{domain}})", + "policyUnavailable": "This policy is no longer available. Choose another policy.", + "editDestination": "Update the existing rule in “{{name}}”, keeping its position.", + "saveAndApply": "Save and apply", + "sourceIp": "Source IP", + "destinationIp": "Destination IP", + "sourceHint": "Matches all requests from this IP or subnet, including requests from other applications. No port filtering.", + "destinationHint": "Matches this destination IP or subnet across all domains. No port filtering.", + "fullPath": "Full path", + "connectionHost": "Current connection domain: {{host}}", + "invalidDomain": "Enter the current domain or a parent domain with at least two labels.", + "matchingDomain": "Matching domain", + "invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6." } } diff --git a/src/locales/ko/connections.json b/src/locales/ko/connections.json index 88173f6ac..08d78156e 100644 --- a/src/locales/ko/connections.json +++ b/src/locales/ko/connections.json @@ -30,5 +30,41 @@ "title": "열", "dragHandle": "Drag handle" } + }, + "ruleDialog": { + "title": "Add rule…", + "matchBy": "Match by", + "domain": "Domain", + "unavailable": "Not available", + "destination": "Add to the prepend rules of “{{name}}”.", + "newConnections": "New connections will match the updated configuration.", + "processPathHint": "Matches all destinations accessed by processes at this path.", + "processNameHint": "Matches all destinations accessed by processes with this name.", + "ruleModeHint": "Rule-based routing takes effect in Rule mode.", + "addAndApply": "Add and apply", + "profileChanged": "The active profile changed. Close this dialog and add the rule again.", + "applyFailed": "The rule could not be applied. Your selection has been kept.", + "unsupportedValue": "This value contains characters that cannot be used in a quick rule.", + "saved": "Rule saved and configuration applied.", + "noMetadata": "This connection has no domain, process or IP information for configuring a rule.", + "noProfile": "No active profile with an editable rule extension is available.", + "entry": "Configure rule…", + "modifyTitle": "Modify rule", + "domainScope": "Domain scope", + "exactDomain": "Only this domain", + "allSubdomains": "This domain and all its subdomains", + "rootDomain": "기본 도메인 및 모든 하위 도메인 ({{domain}})", + "policyUnavailable": "This policy is no longer available. Choose another policy.", + "editDestination": "Update the existing rule in “{{name}}”, keeping its position.", + "saveAndApply": "Save and apply", + "sourceIp": "Source IP", + "destinationIp": "Destination IP", + "sourceHint": "Matches all requests from this IP or subnet, including requests from other applications. No port filtering.", + "destinationHint": "Matches this destination IP or subnet across all domains. No port filtering.", + "fullPath": "Full path", + "connectionHost": "Current connection domain: {{host}}", + "invalidDomain": "Enter the current domain or a parent domain with at least two labels.", + "matchingDomain": "Matching domain", + "invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6." } } diff --git a/src/locales/pt/connections.json b/src/locales/pt/connections.json index 8034e7599..47d10af19 100644 --- a/src/locales/pt/connections.json +++ b/src/locales/pt/connections.json @@ -30,5 +30,41 @@ "title": "Colunas", "dragHandle": "Alça de arrastar" } + }, + "ruleDialog": { + "title": "Add rule…", + "matchBy": "Match by", + "domain": "Domain", + "unavailable": "Not available", + "destination": "Add to the prepend rules of “{{name}}”.", + "newConnections": "New connections will match the updated configuration.", + "processPathHint": "Matches all destinations accessed by processes at this path.", + "processNameHint": "Matches all destinations accessed by processes with this name.", + "ruleModeHint": "Rule-based routing takes effect in Rule mode.", + "addAndApply": "Add and apply", + "profileChanged": "The active profile changed. Close this dialog and add the rule again.", + "applyFailed": "The rule could not be applied. Your selection has been kept.", + "unsupportedValue": "This value contains characters that cannot be used in a quick rule.", + "saved": "Rule saved and configuration applied.", + "noMetadata": "This connection has no domain, process or IP information for configuring a rule.", + "noProfile": "No active profile with an editable rule extension is available.", + "entry": "Configure rule…", + "modifyTitle": "Modify rule", + "domainScope": "Domain scope", + "exactDomain": "Only this domain", + "allSubdomains": "This domain and all its subdomains", + "rootDomain": "Domínio principal e todos os seus subdomínios ({{domain}})", + "policyUnavailable": "This policy is no longer available. Choose another policy.", + "editDestination": "Update the existing rule in “{{name}}”, keeping its position.", + "saveAndApply": "Save and apply", + "sourceIp": "Source IP", + "destinationIp": "Destination IP", + "sourceHint": "Matches all requests from this IP or subnet, including requests from other applications. No port filtering.", + "destinationHint": "Matches this destination IP or subnet across all domains. No port filtering.", + "fullPath": "Full path", + "connectionHost": "Current connection domain: {{host}}", + "invalidDomain": "Enter the current domain or a parent domain with at least two labels.", + "matchingDomain": "Matching domain", + "invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6." } } diff --git a/src/locales/ru/connections.json b/src/locales/ru/connections.json index 37b8adaef..e7e7ff3e3 100644 --- a/src/locales/ru/connections.json +++ b/src/locales/ru/connections.json @@ -30,5 +30,41 @@ "title": "Столбцы", "dragHandle": "Маркер перетаскивания" } + }, + "ruleDialog": { + "title": "Add rule…", + "matchBy": "Match by", + "domain": "Domain", + "unavailable": "Not available", + "destination": "Add to the prepend rules of “{{name}}”.", + "newConnections": "New connections will match the updated configuration.", + "processPathHint": "Matches all destinations accessed by processes at this path.", + "processNameHint": "Matches all destinations accessed by processes with this name.", + "ruleModeHint": "Rule-based routing takes effect in Rule mode.", + "addAndApply": "Add and apply", + "profileChanged": "The active profile changed. Close this dialog and add the rule again.", + "applyFailed": "The rule could not be applied. Your selection has been kept.", + "unsupportedValue": "This value contains characters that cannot be used in a quick rule.", + "saved": "Rule saved and configuration applied.", + "noMetadata": "This connection has no domain, process or IP information for configuring a rule.", + "noProfile": "No active profile with an editable rule extension is available.", + "entry": "Configure rule…", + "modifyTitle": "Modify rule", + "domainScope": "Domain scope", + "exactDomain": "Only this domain", + "allSubdomains": "This domain and all its subdomains", + "rootDomain": "Основной домен и все его поддомены ({{domain}})", + "policyUnavailable": "This policy is no longer available. Choose another policy.", + "editDestination": "Update the existing rule in “{{name}}”, keeping its position.", + "saveAndApply": "Save and apply", + "sourceIp": "Source IP", + "destinationIp": "Destination IP", + "sourceHint": "Matches all requests from this IP or subnet, including requests from other applications. No port filtering.", + "destinationHint": "Matches this destination IP or subnet across all domains. No port filtering.", + "fullPath": "Full path", + "connectionHost": "Current connection domain: {{host}}", + "invalidDomain": "Enter the current domain or a parent domain with at least two labels.", + "matchingDomain": "Matching domain", + "invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6." } } diff --git a/src/locales/tr/connections.json b/src/locales/tr/connections.json index b8f85292a..5f9d2f372 100644 --- a/src/locales/tr/connections.json +++ b/src/locales/tr/connections.json @@ -30,5 +30,41 @@ "title": "Sütunlar", "dragHandle": "Sürükleme tutamacı" } + }, + "ruleDialog": { + "title": "Add rule…", + "matchBy": "Match by", + "domain": "Domain", + "unavailable": "Not available", + "destination": "Add to the prepend rules of “{{name}}”.", + "newConnections": "New connections will match the updated configuration.", + "processPathHint": "Matches all destinations accessed by processes at this path.", + "processNameHint": "Matches all destinations accessed by processes with this name.", + "ruleModeHint": "Rule-based routing takes effect in Rule mode.", + "addAndApply": "Add and apply", + "profileChanged": "The active profile changed. Close this dialog and add the rule again.", + "applyFailed": "The rule could not be applied. Your selection has been kept.", + "unsupportedValue": "This value contains characters that cannot be used in a quick rule.", + "saved": "Rule saved and configuration applied.", + "noMetadata": "This connection has no domain, process or IP information for configuring a rule.", + "noProfile": "No active profile with an editable rule extension is available.", + "entry": "Configure rule…", + "modifyTitle": "Modify rule", + "domainScope": "Domain scope", + "exactDomain": "Only this domain", + "allSubdomains": "This domain and all its subdomains", + "rootDomain": "Ana alan adı ve tüm alt alan adları ({{domain}})", + "policyUnavailable": "This policy is no longer available. Choose another policy.", + "editDestination": "Update the existing rule in “{{name}}”, keeping its position.", + "saveAndApply": "Save and apply", + "sourceIp": "Source IP", + "destinationIp": "Destination IP", + "sourceHint": "Matches all requests from this IP or subnet, including requests from other applications. No port filtering.", + "destinationHint": "Matches this destination IP or subnet across all domains. No port filtering.", + "fullPath": "Full path", + "connectionHost": "Current connection domain: {{host}}", + "invalidDomain": "Enter the current domain or a parent domain with at least two labels.", + "matchingDomain": "Matching domain", + "invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6." } } diff --git a/src/locales/tt/connections.json b/src/locales/tt/connections.json index 48a28d4b8..39a84800b 100644 --- a/src/locales/tt/connections.json +++ b/src/locales/tt/connections.json @@ -30,5 +30,41 @@ "title": "Баганалар", "dragHandle": "Drag handle" } + }, + "ruleDialog": { + "title": "Add rule…", + "matchBy": "Match by", + "domain": "Domain", + "unavailable": "Not available", + "destination": "Add to the prepend rules of “{{name}}”.", + "newConnections": "New connections will match the updated configuration.", + "processPathHint": "Matches all destinations accessed by processes at this path.", + "processNameHint": "Matches all destinations accessed by processes with this name.", + "ruleModeHint": "Rule-based routing takes effect in Rule mode.", + "addAndApply": "Add and apply", + "profileChanged": "The active profile changed. Close this dialog and add the rule again.", + "applyFailed": "The rule could not be applied. Your selection has been kept.", + "unsupportedValue": "This value contains characters that cannot be used in a quick rule.", + "saved": "Rule saved and configuration applied.", + "noMetadata": "This connection has no domain, process or IP information for configuring a rule.", + "noProfile": "No active profile with an editable rule extension is available.", + "entry": "Configure rule…", + "modifyTitle": "Modify rule", + "domainScope": "Domain scope", + "exactDomain": "Only this domain", + "allSubdomains": "This domain and all its subdomains", + "rootDomain": "Төп домен һәм аның барлык субдоменнары ({{domain}})", + "policyUnavailable": "This policy is no longer available. Choose another policy.", + "editDestination": "Update the existing rule in “{{name}}”, keeping its position.", + "saveAndApply": "Save and apply", + "sourceIp": "Source IP", + "destinationIp": "Destination IP", + "sourceHint": "Matches all requests from this IP or subnet, including requests from other applications. No port filtering.", + "destinationHint": "Matches this destination IP or subnet across all domains. No port filtering.", + "fullPath": "Full path", + "connectionHost": "Current connection domain: {{host}}", + "invalidDomain": "Enter the current domain or a parent domain with at least two labels.", + "matchingDomain": "Matching domain", + "invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6." } } diff --git a/src/locales/zh/connections.json b/src/locales/zh/connections.json index 33a447813..c81584a76 100644 --- a/src/locales/zh/connections.json +++ b/src/locales/zh/connections.json @@ -30,5 +30,41 @@ "title": "列设置", "dragHandle": "拖拽控件" } + }, + "ruleDialog": { + "title": "添加规则…", + "matchBy": "匹配对象", + "domain": "域名", + "unavailable": "未获取", + "destination": "添加到「{{name}}」的前置规则。", + "newConnections": "新建立的连接将按更新后的配置匹配。", + "processPathHint": "匹配此路径对应进程访问的所有目标。", + "processNameHint": "匹配所有同名进程访问的所有目标。", + "ruleModeHint": "规则分流在规则模式下生效。", + "addAndApply": "添加并应用", + "profileChanged": "当前订阅已切换,请关闭弹窗后重新添加规则。", + "applyFailed": "规则未能应用,已保留当前选择。", + "unsupportedValue": "此内容包含快捷规则不支持的字符。", + "saved": "规则已保存,配置已应用。", + "noMetadata": "此连接没有可用于设置规则的域名、进程或 IP 信息。", + "noProfile": "当前没有可编辑规则扩展的活动订阅。", + "entry": "设置规则…", + "modifyTitle": "修改规则", + "domainScope": "域名匹配范围", + "exactDomain": "仅此域名", + "allSubdomains": "此域名及所有子域名", + "rootDomain": "主域名及所有子域名({{domain}})", + "policyUnavailable": "此策略已不可用,请选择其他策略。", + "editDestination": "修改「{{name}}」中的现有规则,保留排序。", + "saveAndApply": "保存并应用", + "sourceIp": "源 IP", + "destinationIp": "目标 IP", + "sourceHint": "匹配来自此 IP 或网段的所有请求,可能包含其他应用,不限定端口。", + "destinationHint": "匹配访问此目标 IP 或网段的请求,覆盖所有域名,不限定端口。", + "fullPath": "完整路径", + "connectionHost": "当前连接域名:{{host}}", + "invalidDomain": "请输入当前连接域名或其父域名,父域名至少包含两级。", + "matchingDomain": "匹配域名", + "invalidIp": "请输入有效的 IP/前缀长度,IPv4 为 0–32,IPv6 为 0–128。" } } diff --git a/src/locales/zhtw/connections.json b/src/locales/zhtw/connections.json index 520f3a855..fd3a67849 100644 --- a/src/locales/zhtw/connections.json +++ b/src/locales/zhtw/connections.json @@ -30,5 +30,41 @@ "title": "欄位設定", "dragHandle": "拖曳以移動" } + }, + "ruleDialog": { + "title": "Add rule…", + "matchBy": "Match by", + "domain": "Domain", + "unavailable": "Not available", + "destination": "Add to the prepend rules of “{{name}}”.", + "newConnections": "New connections will match the updated configuration.", + "processPathHint": "Matches all destinations accessed by processes at this path.", + "processNameHint": "Matches all destinations accessed by processes with this name.", + "ruleModeHint": "Rule-based routing takes effect in Rule mode.", + "addAndApply": "Add and apply", + "profileChanged": "The active profile changed. Close this dialog and add the rule again.", + "applyFailed": "The rule could not be applied. Your selection has been kept.", + "unsupportedValue": "This value contains characters that cannot be used in a quick rule.", + "saved": "Rule saved and configuration applied.", + "noMetadata": "This connection has no domain, process or IP information for configuring a rule.", + "noProfile": "No active profile with an editable rule extension is available.", + "entry": "Configure rule…", + "modifyTitle": "Modify rule", + "domainScope": "Domain scope", + "exactDomain": "Only this domain", + "allSubdomains": "This domain and all its subdomains", + "rootDomain": "主網域及所有子網域({{domain}})", + "policyUnavailable": "This policy is no longer available. Choose another policy.", + "editDestination": "Update the existing rule in “{{name}}”, keeping its position.", + "saveAndApply": "Save and apply", + "sourceIp": "Source IP", + "destinationIp": "Destination IP", + "sourceHint": "Matches all requests from this IP or subnet, including requests from other applications. No port filtering.", + "destinationHint": "Matches this destination IP or subnet across all domains. No port filtering.", + "fullPath": "Full path", + "connectionHost": "Current connection domain: {{host}}", + "invalidDomain": "Enter the current domain or a parent domain with at least two labels.", + "matchingDomain": "Matching domain", + "invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6." } } diff --git a/src/pages/connections.tsx b/src/pages/connections.tsx index 7a11a1497..80df49cb8 100644 --- a/src/pages/connections.tsx +++ b/src/pages/connections.tsx @@ -35,6 +35,7 @@ import { getConnectionStartTime, useConnectionRowViews, } from '@/components/connection/connection-row-view' +import type { ConnectionRuleKind } from '@/components/connection/connection-rule' import { ConnectionTable } from '@/components/connection/connection-table' import { useConnectionData } from '@/hooks/use-connection-data' import { useConnectionSetting } from '@/hooks/use-connection-setting' @@ -161,10 +162,14 @@ const ConnectionsPage = () => { ) const showDetailById = useCallback( - (id: string) => { + (id: string, preferredKind: ConnectionRuleKind = 'domain') => { const connection = filterConn.find((item) => item.id === id) if (connection) { - detailRef.current?.open(connection, connectionsType === 'closed') + detailRef.current?.open( + connection, + connectionsType === 'closed', + preferredKind, + ) } }, [connectionsType, filterConn], diff --git a/src/types/generated/i18n-keys.ts b/src/types/generated/i18n-keys.ts index 4444480a2..879684130 100644 --- a/src/types/generated/i18n-keys.ts +++ b/src/types/generated/i18n-keys.ts @@ -22,6 +22,40 @@ export const translationKeys = [ 'connections.components.actions.closeConnection', 'connections.components.columnManager.title', 'connections.components.columnManager.dragHandle', + 'connections.ruleDialog.title', + 'connections.ruleDialog.matchBy', + 'connections.ruleDialog.domain', + 'connections.ruleDialog.unavailable', + 'connections.ruleDialog.destination', + 'connections.ruleDialog.newConnections', + 'connections.ruleDialog.processPathHint', + 'connections.ruleDialog.processNameHint', + 'connections.ruleDialog.ruleModeHint', + 'connections.ruleDialog.addAndApply', + 'connections.ruleDialog.profileChanged', + 'connections.ruleDialog.applyFailed', + 'connections.ruleDialog.unsupportedValue', + 'connections.ruleDialog.saved', + 'connections.ruleDialog.noMetadata', + 'connections.ruleDialog.noProfile', + 'connections.ruleDialog.entry', + 'connections.ruleDialog.modifyTitle', + 'connections.ruleDialog.domainScope', + 'connections.ruleDialog.exactDomain', + 'connections.ruleDialog.allSubdomains', + 'connections.ruleDialog.rootDomain', + 'connections.ruleDialog.policyUnavailable', + 'connections.ruleDialog.editDestination', + 'connections.ruleDialog.saveAndApply', + 'connections.ruleDialog.sourceIp', + 'connections.ruleDialog.destinationIp', + 'connections.ruleDialog.sourceHint', + 'connections.ruleDialog.destinationHint', + 'connections.ruleDialog.fullPath', + 'connections.ruleDialog.connectionHost', + 'connections.ruleDialog.invalidDomain', + 'connections.ruleDialog.matchingDomain', + 'connections.ruleDialog.invalidIp', 'home.page.tooltips.lightweightMode', 'home.page.tooltips.manual', 'home.page.tooltips.settings', diff --git a/src/types/generated/i18n-resources.ts b/src/types/generated/i18n-resources.ts index ed1a2bdc2..2eff3d7e6 100644 --- a/src/types/generated/i18n-resources.ts +++ b/src/types/generated/i18n-resources.ts @@ -36,6 +36,42 @@ export interface TranslationResources { page: { title: string } + ruleDialog: { + addAndApply: string + allSubdomains: string + applyFailed: string + connectionHost: string + destination: string + destinationHint: string + destinationIp: string + domain: string + domainScope: string + editDestination: string + entry: string + exactDomain: string + fullPath: string + invalidDomain: string + invalidIp: string + matchBy: string + matchingDomain: string + modifyTitle: string + newConnections: string + noMetadata: string + noProfile: string + policyUnavailable: string + processNameHint: string + processPathHint: string + profileChanged: string + rootDomain: string + ruleModeHint: string + saveAndApply: string + saved: string + sourceHint: string + sourceIp: string + title: string + unavailable: string + unsupportedValue: string + } } home: { components: {