diff --git a/changelog.md b/changelog.md index 29e1183..3093c1b 100644 --- a/changelog.md +++ b/changelog.md @@ -5,3 +5,4 @@ ### Features - 支持自定义CSS样式 +- 添加用户验证相关设置 diff --git a/src/main/utils/init.ts b/src/main/utils/init.ts index cb4c25c..e8ef5a3 100644 --- a/src/main/utils/init.ts +++ b/src/main/utils/init.ts @@ -26,7 +26,12 @@ import { existsSync } from 'fs' import path from 'path' import { startPacServer, startSubStoreServer } from '../resolve/server' import { triggerSysProxy } from '../sys/sysproxy' -import { getAppConfig, patchAppConfig } from '../config' +import { + getAppConfig, + getControledMihomoConfig, + patchAppConfig, + patchControledMihomoConfig +} from '../config' import { app } from 'electron' async function initDirs(): Promise { @@ -138,10 +143,37 @@ async function migration(): Promise { ], useSubStore = true } = await getAppConfig() + const { + 'skip-auth-prefixes': skipAuthPrefixes, + authentication, + 'bind-address': bindAddress, + 'lan-allowed-ips': lanAllowedIps, + 'lan-disallowed-ips': lanDisallowedIps + } = await getControledMihomoConfig() // add substore sider card if (useSubStore && !siderOrder.includes('substore')) { await patchAppConfig({ siderOrder: [...siderOrder, 'substore'] }) } + // add default skip auth prefix + if (!skipAuthPrefixes) { + await patchControledMihomoConfig({ 'skip-auth-prefixes': ['127.0.0.1/32'] }) + } + // add default authentication + if (!authentication) { + await patchControledMihomoConfig({ authentication: [] }) + } + // add default bind address + if (!bindAddress) { + await patchControledMihomoConfig({ 'bind-address': '*' }) + } + // add default lan allowed ips + if (!lanAllowedIps) { + await patchControledMihomoConfig({ 'lan-allowed-ips': ['0.0.0.0/0', '::/0'] }) + } + // add default lan disallowed ips + if (!lanDisallowedIps) { + await patchControledMihomoConfig({ 'lan-disallowed-ips': [] }) + } } function initDeeplink(): void { diff --git a/src/main/utils/template.ts b/src/main/utils/template.ts index fe278e8..dce3282 100644 --- a/src/main/utils/template.ts +++ b/src/main/utils/template.ts @@ -50,6 +50,11 @@ export const defaultControledMihomoConfig: Partial = { 'tcp-concurrent': false, 'log-level': 'info', 'find-process-mode': 'strict', + 'bind-address': '*', + 'lan-allowed-ips': ['0.0.0.0/0', '::/0'], + 'lan-disallowed-ips': [], + authentication: [], + 'skip-auth-prefixes': ['127.0.0.1/32'], tun: { enable: false, device: 'Mihomo', diff --git a/src/renderer/src/pages/mihomo.tsx b/src/renderer/src/pages/mihomo.tsx index 175e689..a6a37ee 100644 --- a/src/renderer/src/pages/mihomo.tsx +++ b/src/renderer/src/pages/mihomo.tsx @@ -1,4 +1,4 @@ -import { Button, Input, Select, SelectItem, Switch } from '@nextui-org/react' +import { Button, Divider, Input, Select, SelectItem, Switch } from '@nextui-org/react' import BasePage from '@renderer/components/base/base-page' import SettingCard from '@renderer/components/base/base-setting-card' import SettingItem from '@renderer/components/base/base-setting-item' @@ -11,6 +11,7 @@ import PubSub from 'pubsub-js' import { mihomoUpgrade, restartCore, triggerSysProxy } from '@renderer/utils/ipc' import React, { useState } from 'react' import InterfaceModal from '@renderer/components/mihomo/interface-modal' +import { MdDeleteForever } from 'react-icons/md' const CoreMap = { mihomo: '稳定版', @@ -25,9 +26,13 @@ const Mihomo: React.FC = () => { ipv6, 'external-controller': externalController = '127.0.0.1:9090', secret, + authentication = [], + 'skip-auth-prefixes': skipAuthPrefixes = ['127.0.0.1/32'], 'log-level': logLevel = 'info', 'find-process-mode': findProcessMode = 'strict', 'allow-lan': allowLan, + 'lan-allowed-ips': lanAllowedIps = ['0.0.0.0/0', '::/0'], + 'lan-disallowed-ips': lanDisallowedIps = [], 'unified-delay': unifiedDelay, 'tcp-concurrent': tcpConcurrent, 'mixed-port': mixedPort = 7890, @@ -51,7 +56,10 @@ const Mihomo: React.FC = () => { externalController.split(':')[1] ) const [secretInput, setSecretInput] = useState(secret) - + const [lanAllowedIpsInput, setLanAllowedIpsInput] = useState(lanAllowedIps) + const [lanDisallowedIpsInput, setLanDisallowedIpsInput] = useState(lanDisallowedIps) + const [authenticationInput, setAuthenticationInput] = useState(authentication) + const [skipAuthPrefixesInput, setSkipAuthPrefixesInput] = useState(skipAuthPrefixes) const [upgrading, setUpgrading] = useState(false) const [lanOpen, setLanOpen] = useState(false) @@ -381,6 +389,240 @@ const Mihomo: React.FC = () => { }} /> + {allowLan && ( + <> + + {lanAllowedIpsInput.join('') !== lanAllowedIps.join('') && ( + + )} + +
+ {[...lanAllowedIpsInput, ''].map((ipcidr, index) => { + return ( +
+ { + if (index === lanAllowedIpsInput.length) { + setLanAllowedIpsInput([...lanAllowedIpsInput, v]) + } else { + setLanAllowedIpsInput( + lanAllowedIpsInput.map((a, i) => (i === index ? v : a)) + ) + } + }} + /> + {index < lanAllowedIpsInput.length && ( + + )} +
+ ) + })} +
+ + + {lanDisallowedIpsInput.join('') !== lanDisallowedIps.join('') && ( + + )} + +
+ {[...lanDisallowedIpsInput, ''].map((ipcidr, index) => { + return ( +
+ { + if (index === lanDisallowedIpsInput.length) { + setLanDisallowedIpsInput([...lanDisallowedIpsInput, v]) + } else { + setLanDisallowedIpsInput( + lanDisallowedIpsInput.map((a, i) => (i === index ? v : a)) + ) + } + }} + /> + {index < lanDisallowedIpsInput.length && ( + + )} +
+ ) + })} +
+ + + )} + + {authenticationInput.join('') !== authentication.join('') && ( + + )} + +
+ {[...authenticationInput, ''].map((auth, index) => { + const [user, pass] = auth.split(':') + return ( +
+
+ { + if (index === authenticationInput.length) { + setAuthenticationInput([...authenticationInput, `${v}:${pass || ''}`]) + } else { + setAuthenticationInput( + authenticationInput.map((a, i) => + i === index ? `${v}:${pass || ''}` : a + ) + ) + } + }} + /> +
+ : +
+ { + if (index === authenticationInput.length) { + setAuthenticationInput([...authenticationInput, `${user || ''}:${v}`]) + } else { + setAuthenticationInput( + authenticationInput.map((a, i) => + i === index ? `${user || ''}:${v}` : a + ) + ) + } + }} + /> + {index < authenticationInput.length && ( + + )} +
+
+ ) + })} +
+ + + {skipAuthPrefixesInput.join('') !== skipAuthPrefixes.join('') && ( + + )} + +
+ {[...skipAuthPrefixesInput, ''].map((ipcidr, index) => { + return ( +
+ { + if (index === skipAuthPrefixesInput.length) { + setSkipAuthPrefixesInput([...skipAuthPrefixesInput, v]) + } else { + setSkipAuthPrefixesInput( + skipAuthPrefixesInput.map((a, i) => (i === index ? v : a)) + ) + } + }} + /> + {index < skipAuthPrefixesInput.length && index !== 0 && ( + + )} +
+ ) + })} +
+