Skip to content

Commit

Permalink
add fakeip settings and modify sniff
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Aug 7, 2024
1 parent 4d2678b commit 8a52e56
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 18 deletions.
6 changes: 4 additions & 2 deletions src/main/utils/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
ipv6: false,
'enhanced-mode': 'fake-ip',
'fake-ip-range': '198.18.0.1/16',
'fake-ip-filter': ['*', '+.lan', '+.local', '+.market.xiaomi.com'],
'use-hosts': false,
'use-system-hosts': false,
nameserver: ['https://doh.pub/dns-query', 'https://dns.alidns.com/dns-query']
},
sniffer: {
enable: true,
'parse-pure-ip': true,
'parse-pure-ip': false,
'override-destination': false,
sniff: {
HTTP: {
ports: [80, 443]
ports: [80, 443],
'override-destination': false
},
TLS: {
ports: [443]
Expand Down
65 changes: 55 additions & 10 deletions src/renderer/src/pages/dns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const DNS: React.FC = () => {
const { dns, hosts } = controledMihomoConfig || {}
const {
ipv6 = false,
'fake-ip-range': fakeIPRange = '198.18.0.1/16',
'fake-ip-filter': fakeIPFilter = [
'*',
'+.lan',
'+.local',
'+.market.xiaomi.com',
],
'enhanced-mode': enhancedMode = 'fake-ip',
'use-hosts': useHosts = false,
'use-system-hosts': useSystemHosts = false,
Expand All @@ -22,25 +29,27 @@ const DNS: React.FC = () => {
ipv6,
useHosts,
enhancedMode,
fakeIPRange,
fakeIPFilter,
useSystemHosts,
nameserver,
hosts: Object.entries(hosts || {}).map(([domain, value]) => ({ domain, value }))
})

const handleNameserverChange = (value: string, index: number): void => {
const newNameservers = [...values.nameserver]
if (index === newNameservers.length) {
const handleListChange = (type: string, value: string, index: number): void => {
const newValues = [...values[type]]
if (index === newValues.length) {
if (value.trim() !== '') {
newNameservers.push(value)
newValues.push(value)
}
} else {
if (value.trim() === '') {
newNameservers.splice(index, 1)
newValues.splice(index, 1)
} else {
newNameservers[index] = value
newValues[index] = value
}
}
setValues({ ...values, nameserver: newNameservers })
setValues({ ...values, [type]: newValues })
}
const handleHostsChange = (domain: string, value: string, index: number): void => {
const newHosts = [...values.hosts]
Expand Down Expand Up @@ -81,6 +90,8 @@ const DNS: React.FC = () => {
onSave({
dns: {
ipv6: values.ipv6,
'fake-ip-range': values.fakeIPRange,
'fake-ip-filter': values.fakeIPFilter,
'enhanced-mode': values.enhancedMode,
'use-hosts': values.useHosts,
'use-system-hosts': values.useSystemHosts,
Expand All @@ -107,6 +118,40 @@ const DNS: React.FC = () => {
<Tab key="normal" title="取消映射" className="select-none" />
</Tabs>
</SettingItem>
{values.enhancedMode === 'fake-ip' ? (
<><SettingItem title="回应范围" divider>
<Input
size="sm"
className="w-[50%]"
value={values.fakeIPRange}
onValueChange={(v) => {
setValues({ ...values, fakeIPRange: v })
}} />
</SettingItem><div className="flex flex-col items-stretch">
<h3 className="select-none mb-2">真实IP回应</h3>
{[...values.fakeIPFilter, ''].map((ns, index) => (
<div key={index} className="mb-2 flex">
<Input
fullWidth
size="sm"
placeholder="例: +.lan"
value={ns}
onValueChange={(v) => handleListChange('fakeIPFilter', v, index)} />
{index < values.fakeIPFilter.length && (
<Button
className="ml-2"
size="sm"
variant="flat"
color="warning"
onClick={() => handleListChange('fakeIPFilter', '', index)}
>
<MdDeleteForever className="text-lg" />
</Button>
)}
</div>
))}
</div><Divider style={{ marginTop: '2px', marginBottom: '6px' }} /></>
) : null}
<SettingItem title="IPv6" divider>
<Switch
size="sm"
Expand All @@ -125,23 +170,23 @@ const DNS: React.FC = () => {
size="sm"
placeholder="例: tls://223.5.5.5"
value={ns}
onValueChange={(v) => handleNameserverChange(v, index)}
onValueChange={(v) => handleListChange('nameserver', v, index)}
/>
{index < values.nameserver.length && (
<Button
className="ml-2"
size="sm"
variant="flat"
color="warning"
onClick={() => handleNameserverChange('', index)}
onClick={() => handleListChange('nameserver', '', index)}
>
<MdDeleteForever className="text-lg" />
</Button>
)}
</div>
))}
</div>
<Divider />
<Divider style={{ marginTop: '2px', marginBottom: '6px' }} />
<SettingItem title="使用系统hosts" divider>
<Switch
size="sm"
Expand Down
23 changes: 17 additions & 6 deletions src/renderer/src/pages/sniffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Sniffer: React.FC = () => {
'parse-pure-ip': parsePureIP = true,
'override-destination': overrideDestination = false,
sniff = {
HTTP: { ports: [80, 443] },
HTTP: { ports: [80, 443], 'override-destination': false },
TLS: { ports: [443] },
QUIC: { ports: [443] }
},
Expand Down Expand Up @@ -92,7 +92,18 @@ const Sniffer: React.FC = () => {
size="sm"
isSelected={values.overrideDestination}
onValueChange={(v) => {
setValues({ ...values, overrideDestination: v })
setValues({
...values,
overrideDestination: v,
sniff: {
...values.sniff,
HTTP: {
...values.sniff.HTTP,
'override-destination': v,
ports: values.sniff.HTTP?.ports || [80, 443]
}
}
});
}}
/>
</SettingItem>
Expand Down Expand Up @@ -154,7 +165,7 @@ const Sniffer: React.FC = () => {
</div>
))}
</div>
<Divider />
<Divider style={{ marginTop: '2px', marginBottom: '6px' }} />
<div className="flex flex-col items-stretch">
<h3 className="select-none mb-2">强制嗅探</h3>
{[...values.forceDomain, ''].map((d, index) => (
Expand Down Expand Up @@ -182,7 +193,7 @@ const Sniffer: React.FC = () => {
</div>
</SettingCard>
</BasePage>
)
}
);
};

export default Sniffer
export default Sniffer;
1 change: 1 addition & 0 deletions src/shared/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ interface IMihomoDNSConfig {
ipv6?: boolean
'enhanced-mode'?: DnsMode
'fake-ip-range'?: string
'fake-ip-filter'?: string[]
'use-hosts'?: boolean
'use-system-hosts'?: boolean
'respect-rules'?: boolean
Expand Down

0 comments on commit 8a52e56

Please sign in to comment.