mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-16 16:32:11 +08:00
feat(connections): allow editing IP rule ranges
This commit is contained in:
+1
-1
@@ -51,7 +51,7 @@
|
||||
<summary><strong> ✨ 新增功能 </strong></summary>
|
||||
|
||||
- 新增连接页面按网络协议(TCP/UDP)筛选连接
|
||||
- 新增从连接详情设置域名、进程或源/目标 IP 规则,支持自动识别主域、匹配子域及修改已有规则
|
||||
- 新增从连接详情设置域名、进程或源/目标 IP 规则,支持识别主域、匹配子域、自定义 IP 网段及修改已有规则
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import { mutate } from '@/services/mutate'
|
||||
import { showNotice } from '@/services/notice-service'
|
||||
|
||||
import {
|
||||
getConnectionIPRule,
|
||||
getConnectionRuleTargets,
|
||||
getConnectionRules,
|
||||
getConnectionRootDomain,
|
||||
@@ -72,7 +73,9 @@ export function ConnectionRuleDialog({
|
||||
)
|
||||
const [policy, setPolicy] = useState<string | null>(null)
|
||||
const [scope, setScope] = useState<DomainScope>('DOMAIN')
|
||||
const [domainValue, setDomainValue] = useState(targets.domain?.value ?? '')
|
||||
const [matchingInput, setMatchingInput] = useState(
|
||||
() => targets[getInitialKind(target)]?.value ?? '',
|
||||
)
|
||||
const [rules, setRules] = useState<string[] | null>(null)
|
||||
const [loadAttempt, setLoadAttempt] = useState(0)
|
||||
const [loading, setLoading] = useState(true)
|
||||
@@ -81,25 +84,33 @@ export function ConnectionRuleDialog({
|
||||
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
|
||||
? domainValue
|
||||
: editingDomain || editingIP
|
||||
? matchingInput
|
||||
: (selected?.value ?? '')
|
||||
const invalidDomain =
|
||||
editingDomain &&
|
||||
!isConnectionRuleDomain(domainValue, targets.domain?.value ?? '')
|
||||
const condition = selected
|
||||
? {
|
||||
type:
|
||||
kind === 'domain' && scope !== 'DOMAIN'
|
||||
? 'DOMAIN-SUFFIX'
|
||||
: selected.type,
|
||||
value: kind === 'domain' ? matchingValue.trim() : selected.value,
|
||||
}
|
||||
!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 && !invalidDomain
|
||||
rules && condition && !invalidValue
|
||||
? findConnectionRule(rules, condition)
|
||||
: undefined
|
||||
const modifying = Boolean(existing)
|
||||
@@ -166,7 +177,7 @@ export function ConnectionRuleDialog({
|
||||
if (
|
||||
blocked ||
|
||||
!condition ||
|
||||
invalidDomain ||
|
||||
invalidValue ||
|
||||
!policy ||
|
||||
!policies.includes(policy)
|
||||
)
|
||||
@@ -244,7 +255,7 @@ export function ConnectionRuleDialog({
|
||||
})
|
||||
: undefined))
|
||||
: undefined
|
||||
setDomainValue(targets.domain?.value ?? '')
|
||||
setMatchingInput(nextTarget?.value ?? '')
|
||||
setKind(next)
|
||||
setPolicy(rule?.policy ?? null)
|
||||
setScope(
|
||||
@@ -303,21 +314,22 @@ export function ConnectionRuleDialog({
|
||||
: kindLabels[kind]
|
||||
}
|
||||
value={matchingValue}
|
||||
disabled={editingDomain && blocked}
|
||||
disabled={(editingDomain || editingIP) && blocked}
|
||||
onChange={(event) => {
|
||||
const value = event.target.value
|
||||
setDomainValue(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 &&
|
||||
isConnectionRuleDomain(value, targets.domain?.value ?? '')
|
||||
? findConnectionRule(rules, {
|
||||
type: 'DOMAIN-SUFFIX',
|
||||
value: value.trim(),
|
||||
})
|
||||
rules && nextCondition
|
||||
? findConnectionRule(rules, nextCondition)
|
||||
: undefined
|
||||
if (match) setPolicy(match.policy)
|
||||
}}
|
||||
error={invalidDomain}
|
||||
error={invalidValue}
|
||||
helperText={
|
||||
editingDomain || matchingRoot ? (
|
||||
<>
|
||||
@@ -331,10 +343,12 @@ export function ConnectionRuleDialog({
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
) : invalidIP ? (
|
||||
t('connections.ruleDialog.invalidIp')
|
||||
) : undefined
|
||||
}
|
||||
slotProps={{
|
||||
input: { readOnly: !editingDomain },
|
||||
input: { readOnly: !editingDomain && !editingIP },
|
||||
htmlInput: {
|
||||
title: condition?.value,
|
||||
},
|
||||
@@ -350,7 +364,7 @@ export function ConnectionRuleDialog({
|
||||
onChange={(_, value) => {
|
||||
const nextScope = value as DomainScope
|
||||
setScope(nextScope)
|
||||
setDomainValue(targets.domain?.value ?? '')
|
||||
setMatchingInput(targets.domain?.value ?? '')
|
||||
const match =
|
||||
rules && targets.domain
|
||||
? findConnectionRule(rules, {
|
||||
@@ -493,7 +507,7 @@ export function ConnectionRuleDialog({
|
||||
disabled={
|
||||
blocked ||
|
||||
!condition ||
|
||||
invalidDomain ||
|
||||
invalidValue ||
|
||||
!policy ||
|
||||
!policies.includes(policy)
|
||||
}
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
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
|
||||
const ipv4 = isIP(ip, 4)
|
||||
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: `${ip}/${ipv4 ? 32 : 128}`,
|
||||
value: cidr,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "Save and apply",
|
||||
"sourceIp": "Source IP",
|
||||
"destinationIp": "Destination IP",
|
||||
"sourceHint": "Matches all requests from this IP, including requests from other applications. No port filtering.",
|
||||
"destinationHint": "Matches this destination IP across all domains. No port filtering.",
|
||||
"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"
|
||||
"matchingDomain": "Matching domain",
|
||||
"invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "Save and apply",
|
||||
"sourceIp": "Source IP",
|
||||
"destinationIp": "Destination IP",
|
||||
"sourceHint": "Matches all requests from this IP, including requests from other applications. No port filtering.",
|
||||
"destinationHint": "Matches this destination IP across all domains. No port filtering.",
|
||||
"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"
|
||||
"matchingDomain": "Matching domain",
|
||||
"invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "Save and apply",
|
||||
"sourceIp": "Source IP",
|
||||
"destinationIp": "Destination IP",
|
||||
"sourceHint": "Matches all requests from this IP, including requests from other applications. No port filtering.",
|
||||
"destinationHint": "Matches this destination IP across all domains. No port filtering.",
|
||||
"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"
|
||||
"matchingDomain": "Matching domain",
|
||||
"invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "Save and apply",
|
||||
"sourceIp": "Source IP",
|
||||
"destinationIp": "Destination IP",
|
||||
"sourceHint": "Matches all requests from this IP, including requests from other applications. No port filtering.",
|
||||
"destinationHint": "Matches this destination IP across all domains. No port filtering.",
|
||||
"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"
|
||||
"matchingDomain": "Matching domain",
|
||||
"invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "Save and apply",
|
||||
"sourceIp": "Source IP",
|
||||
"destinationIp": "Destination IP",
|
||||
"sourceHint": "Matches all requests from this IP, including requests from other applications. No port filtering.",
|
||||
"destinationHint": "Matches this destination IP across all domains. No port filtering.",
|
||||
"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"
|
||||
"matchingDomain": "Matching domain",
|
||||
"invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "Save and apply",
|
||||
"sourceIp": "Source IP",
|
||||
"destinationIp": "Destination IP",
|
||||
"sourceHint": "Matches all requests from this IP, including requests from other applications. No port filtering.",
|
||||
"destinationHint": "Matches this destination IP across all domains. No port filtering.",
|
||||
"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"
|
||||
"matchingDomain": "Matching domain",
|
||||
"invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "Save and apply",
|
||||
"sourceIp": "Source IP",
|
||||
"destinationIp": "Destination IP",
|
||||
"sourceHint": "Matches all requests from this IP, including requests from other applications. No port filtering.",
|
||||
"destinationHint": "Matches this destination IP across all domains. No port filtering.",
|
||||
"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"
|
||||
"matchingDomain": "Matching domain",
|
||||
"invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "Save and apply",
|
||||
"sourceIp": "Source IP",
|
||||
"destinationIp": "Destination IP",
|
||||
"sourceHint": "Matches all requests from this IP, including requests from other applications. No port filtering.",
|
||||
"destinationHint": "Matches this destination IP across all domains. No port filtering.",
|
||||
"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"
|
||||
"matchingDomain": "Matching domain",
|
||||
"invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "Save and apply",
|
||||
"sourceIp": "Source IP",
|
||||
"destinationIp": "Destination IP",
|
||||
"sourceHint": "Matches all requests from this IP, including requests from other applications. No port filtering.",
|
||||
"destinationHint": "Matches this destination IP across all domains. No port filtering.",
|
||||
"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"
|
||||
"matchingDomain": "Matching domain",
|
||||
"invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "Save and apply",
|
||||
"sourceIp": "Source IP",
|
||||
"destinationIp": "Destination IP",
|
||||
"sourceHint": "Matches all requests from this IP, including requests from other applications. No port filtering.",
|
||||
"destinationHint": "Matches this destination IP across all domains. No port filtering.",
|
||||
"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"
|
||||
"matchingDomain": "Matching domain",
|
||||
"invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "Save and apply",
|
||||
"sourceIp": "Source IP",
|
||||
"destinationIp": "Destination IP",
|
||||
"sourceHint": "Matches all requests from this IP, including requests from other applications. No port filtering.",
|
||||
"destinationHint": "Matches this destination IP across all domains. No port filtering.",
|
||||
"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"
|
||||
"matchingDomain": "Matching domain",
|
||||
"invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "Save and apply",
|
||||
"sourceIp": "Source IP",
|
||||
"destinationIp": "Destination IP",
|
||||
"sourceHint": "Matches all requests from this IP, including requests from other applications. No port filtering.",
|
||||
"destinationHint": "Matches this destination IP across all domains. No port filtering.",
|
||||
"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"
|
||||
"matchingDomain": "Matching domain",
|
||||
"invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "保存并应用",
|
||||
"sourceIp": "源 IP",
|
||||
"destinationIp": "目标 IP",
|
||||
"sourceHint": "匹配来自此 IP 的所有请求,可能包含其他应用,不限定端口。",
|
||||
"destinationHint": "匹配访问此目标 IP 的请求,覆盖所有域名,不限定端口。",
|
||||
"sourceHint": "匹配来自此 IP 或网段的所有请求,可能包含其他应用,不限定端口。",
|
||||
"destinationHint": "匹配访问此目标 IP 或网段的请求,覆盖所有域名,不限定端口。",
|
||||
"fullPath": "完整路径",
|
||||
"connectionHost": "当前连接域名:{{host}}",
|
||||
"invalidDomain": "请输入当前连接域名或其父域名,父域名至少包含两级。",
|
||||
"matchingDomain": "匹配域名"
|
||||
"matchingDomain": "匹配域名",
|
||||
"invalidIp": "请输入有效的 IP/前缀长度,IPv4 为 0–32,IPv6 为 0–128。"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
"saveAndApply": "Save and apply",
|
||||
"sourceIp": "Source IP",
|
||||
"destinationIp": "Destination IP",
|
||||
"sourceHint": "Matches all requests from this IP, including requests from other applications. No port filtering.",
|
||||
"destinationHint": "Matches this destination IP across all domains. No port filtering.",
|
||||
"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"
|
||||
"matchingDomain": "Matching domain",
|
||||
"invalidIp": "Enter a valid IP/prefix length: 0–32 for IPv4 or 0–128 for IPv6."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ export const translationKeys = [
|
||||
'connections.ruleDialog.connectionHost',
|
||||
'connections.ruleDialog.invalidDomain',
|
||||
'connections.ruleDialog.matchingDomain',
|
||||
'connections.ruleDialog.invalidIp',
|
||||
'home.page.tooltips.lightweightMode',
|
||||
'home.page.tooltips.manual',
|
||||
'home.page.tooltips.settings',
|
||||
|
||||
@@ -51,6 +51,7 @@ export interface TranslationResources {
|
||||
exactDomain: string
|
||||
fullPath: string
|
||||
invalidDomain: string
|
||||
invalidIp: string
|
||||
matchBy: string
|
||||
matchingDomain: string
|
||||
modifyTitle: string
|
||||
|
||||
Reference in New Issue
Block a user