Skip to content

Commit

Permalink
add more sniff settings
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Nov 29, 2024
1 parent 04aad7f commit 09921d9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 65 deletions.
19 changes: 15 additions & 4 deletions src/main/utils/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,23 @@ export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
},
TLS: {
ports: [443]
},
QUIC: {
ports: [443]
}
},
'skip-domain': ['+.push.apple.com']
'skip-domain': ['+.push.apple.com'],
'skip-dst-address': [
'91.105.192.0/23',
'91.108.4.0/22',
'91.108.8.0/21',
'91.108.16.0/21',
'91.108.56.0/22',
'95.161.64.0/20',
'149.154.160.0/20',
'185.76.151.0/24',
'2001:67c:4e8::/48',
'2001:b28:f23c::/47',
'2001:b28:f23f::/48',
'2a0a:f280:203::/48'
]
},
profile: {
'store-selected': true,
Expand Down
135 changes: 74 additions & 61 deletions src/renderer/src/pages/sniffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SettingCard from '@renderer/components/base/base-setting-card'
import SettingItem from '@renderer/components/base/base-setting-item'
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
import { restartCore } from '@renderer/utils/ipc'
import React, { useState } from 'react'
import React, { ReactNode, useState } from 'react'
import { MdDeleteForever } from 'react-icons/md'

const Sniffer: React.FC = () => {
Expand All @@ -17,10 +17,25 @@ const Sniffer: React.FC = () => {
sniff = {
HTTP: { ports: [80, 443], 'override-destination': false },
TLS: { ports: [443] },
QUIC: { ports: [443] }
QUIC: { ports: [] }
},
'skip-domain': skipDomain = ['+.push.apple.com'],
'force-domain': forceDomain = []
'force-domain': forceDomain = [],
'skip-dst-address': skipDstAddress = [
'91.105.192.0/23',
'91.108.4.0/22',
'91.108.8.0/21',
'91.108.16.0/21',
'91.108.56.0/22',
'95.161.64.0/20',
'149.154.160.0/20',
'185.76.151.0/24',
'2001:67c:4e8::/48',
'2001:b28:f23c::/47',
'2001:b28:f23f::/48',
'2a0a:f280:203::/48'
],
'skip-src-address': skipSrcAddress = []
} = sniffer || {}
const [changed, setChanged] = useState(false)
const [values, originSetValues] = useState({
Expand All @@ -29,7 +44,9 @@ const Sniffer: React.FC = () => {
overrideDestination,
sniff,
skipDomain,
forceDomain
forceDomain,
skipDstAddress,
skipSrcAddress
})
const setValues = (v: typeof values): void => {
originSetValues(v)
Expand Down Expand Up @@ -58,20 +75,45 @@ const Sniffer: React.FC = () => {
}
})
}
const handleDomainChange = (type: string, value: string, index: number): void => {
const newDomains = [...values[type]]
if (index === newDomains.length) {
if (value.trim() !== '') {
newDomains.push(value)
}
} else {
if (value.trim() === '') {
newDomains.splice(index, 1)
const handleListChange = (type: string, value: string, index: number): void => {
const list = [...values[type]]
if (value.trim()) {
if (index < list.length) {
list[index] = value
} else {
newDomains[index] = value
list.push(value)
}
} else {
list.splice(index, 1)
}
setValues({ ...values, [type]: newDomains })
setValues({ ...values, [type]: list })
}
const renderListInputs = (type: string, placeholder: string): ReactNode => {
const currentItems = values[type]
const showNewLine = currentItems.every((item: string) => item.trim() !== '')

return [...currentItems, ...(showNewLine ? [''] : [])].map((item, index) => (
<div key={index} className="mt-2 flex">
<Input
fullWidth
size="sm"
placeholder={placeholder}
value={typeof item === 'string' ? item : item.domain}
onValueChange={(v) => handleListChange(type, v, index)}
/>
{index < values[type].length && (
<Button
className="ml-2"
size="sm"
variant="flat"
color="warning"
onClick={() => handleListChange(type, '', index)}
>
<MdDeleteForever className="text-lg" />
</Button>
)}
</div>
))
}

return (
Expand Down Expand Up @@ -144,6 +186,7 @@ const Sniffer: React.FC = () => {
<Input
size="sm"
className="w-[50%]"
placeholder="端口号,使用英文逗号分割"
value={values.sniff.HTTP?.ports.join(',')}
onValueChange={(v) => handleSniffPortChange('HTTP', v)}
/>
Expand All @@ -152,6 +195,7 @@ const Sniffer: React.FC = () => {
<Input
size="sm"
className="w-[50%]"
placeholder="端口号,使用英文逗号分割"
value={values.sniff.TLS?.ports.join(',')}
onValueChange={(v) => handleSniffPortChange('TLS', v)}
/>
Expand All @@ -160,60 +204,29 @@ const Sniffer: React.FC = () => {
<Input
size="sm"
className="w-[50%]"
placeholder="端口号,使用英文逗号分割"
value={values.sniff.QUIC?.ports.join(',')}
onValueChange={(v) => handleSniffPortChange('QUIC', v)}
/>
</SettingItem>
<div className="flex flex-col items-stretch">
<h3>跳过嗅探域名</h3>
{[...values.skipDomain, ''].map((d, index) => (
<div key={index} className="flex mt-2">
<Input
size="sm"
fullWidth
placeholder="例: push.apple.com"
value={d}
onValueChange={(v) => handleDomainChange('skipDomain', v, index)}
/>
{index < values.skipDomain.length && (
<Button
size="sm"
color="warning"
variant="flat"
className="ml-2"
onClick={() => handleDomainChange('skipDomain', '', index)}
>
<MdDeleteForever className="text-lg" />
</Button>
)}
</div>
))}
<h3>跳过域名嗅探</h3>
{renderListInputs('skipDomain', '例:+.push.apple.com')}
</div>
<Divider className="my-2" />
<div className="flex flex-col items-stretch">
<h3 className="mb-2">强制域名嗅探</h3>
{renderListInputs('forceDomain', '例:v2ex.com')}
</div>
<Divider className="my-2" />
<div className="flex flex-col items-stretch">
<h3 className="mb-2">跳过目标地址嗅探</h3>
{renderListInputs('skipDstAddress', '例:1.1.1.1/32')}
</div>
<Divider className="my-2" />
<div className="flex flex-col items-stretch">
<h3 className="mb-2">强制嗅探域名</h3>
{[...values.forceDomain, ''].map((d, index) => (
<div key={index} className="flex mb-2">
<Input
size="sm"
fullWidth
placeholder="例: v2ex.com"
value={d}
onValueChange={(v) => handleDomainChange('forceDomain', v, index)}
/>
{index < values.forceDomain.length && (
<Button
size="sm"
color="warning"
variant="flat"
className="ml-2"
onClick={() => handleDomainChange('forceDomain', '', index)}
>
<MdDeleteForever className="text-lg" />
</Button>
)}
</div>
))}
<h3 className="mb-2">跳过来源地址嗅探</h3>
{renderListInputs('skipSrcAddress', '例:192.168.1.1/24')}
</div>
</SettingCard>
</BasePage>
Expand Down
2 changes: 2 additions & 0 deletions src/shared/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ interface IMihomoSnifferConfig {
'force-dns-mapping'?: boolean
'force-domain'?: string[]
'skip-domain'?: string[]
'skip-dst-address'?: string[]
'skip-src-address'?: string[]
sniff?: {
HTTP?: {
ports: (number | string)[]
Expand Down

0 comments on commit 09921d9

Please sign in to comment.