summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api/configs.ts9
-rw-r--r--src/components/Config.tsx52
-rw-r--r--src/i18n/en.ts3
-rw-r--r--src/i18n/zh.ts3
-rw-r--r--src/store/configs.ts39
-rw-r--r--src/store/types.ts1
6 files changed, 80 insertions, 27 deletions
diff --git a/src/api/configs.ts b/src/api/configs.ts
index ed2b1e9..3734958 100644
--- a/src/api/configs.ts
+++ b/src/api/configs.ts
@@ -3,6 +3,7 @@ import { ClashGeneralConfig, TunPartial } from 'src/store/types';
import { ClashAPIConfig } from 'src/types';
const endpoint = '/configs';
+const updateGeoDatabasesFileEndpoint = '/configs/geo';
const flushFakeIPPoolEndpoint = '/cache/fakeip/flush';
export async function fetchConfigs(apiConfig: ClashAPIConfig) {
@@ -40,6 +41,14 @@ export async function reloadConfigFile(
return await fetch(url + endpoint + '?force=true', { ...init, body, method: 'PUT' });
}
+export async function updateGeoDatabasesFile(
+ apiConfig: ClashAPIConfig
+) {
+ const { url, init } = getURLAndInit(apiConfig);
+ const body = '{"path": "", "payload": ""}';
+ return await fetch(url + updateGeoDatabasesFileEndpoint, { ...init, body, method: 'POST' });
+}
+
export async function flushFakeIPPool(
apiConfig: ClashAPIConfig
) {
diff --git a/src/components/Config.tsx b/src/components/Config.tsx
index 7d0bcd3..a8438c1 100644
--- a/src/components/Config.tsx
+++ b/src/components/Config.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { LogOut, RotateCw, Trash2 } from 'react-feather';
+import { DownloadCloud, LogOut, RotateCw, Trash2 } from 'react-feather';
import { useTranslation } from 'react-i18next';
import * as logsApi from 'src/api/logs';
import Select from 'src/components/shared/Select';
@@ -17,6 +17,7 @@ import {
getConfigs,
reloadConfigFile,
updateConfigs,
+ updateGeoDatabasesFile,
} from '../store/configs';
import { openModal } from '../store/modals';
import Button from './Button';
@@ -46,7 +47,6 @@ const portFields = [
{ key: 'socks-port', label: 'SOCKS5 Proxy Port' },
{ key: 'mixed-port', label: 'Mixed Port' },
{ key: 'redir-port', label: 'Redir Port' },
- { key: 'tproxy-port', label: 'TProxy Port' },
{ key: 'mitm-port', label: 'MITM Port' },
];
@@ -131,21 +131,13 @@ function ConfigImpl({
[configState]
);
- const handleSwitchOnChange = useCallback(
- (checked: boolean) => {
- const name = 'allow-lan';
- const value = checked;
- setConfigState(name, value);
- dispatch(updateConfigs(apiConfig, { 'allow-lan': value }));
- },
- [apiConfig, dispatch, setConfigState]
- );
-
const handleChangeValue = useCallback(
({ name, value }) => {
switch (name) {
case 'mode':
case 'log-level':
+ case 'allow-lan':
+ case 'sniffing':
setConfigState(name, value);
dispatch(updateConfigs(apiConfig, { [name]: value }));
if (name === 'log-level') {
@@ -153,7 +145,6 @@ function ConfigImpl({
}
break;
case 'mitm-port':
- case 'tproxy-port':
case 'redir-port':
case 'socks-port':
case 'mixed-port':
@@ -167,7 +158,7 @@ function ConfigImpl({
case 'enable':
case 'stack':
setTunConfigState(name, value);
- dispatch(updateConfigs(apiConfig, { 'tun': {[name]: value }}));
+ dispatch(updateConfigs(apiConfig, { 'tun': { [name]: value }}));
break;
default:
return;
@@ -192,7 +183,6 @@ function ConfigImpl({
case 'socks-port':
case 'mixed-port':
case 'redir-port':
- case 'tproxy-port':
case 'mitm-port': {
const num = parseInt(value, 10);
if (num < 0 || num > 65535) return;
@@ -214,6 +204,10 @@ function ConfigImpl({
dispatch(reloadConfigFile(apiConfig));
},[apiConfig, dispatch]);
+ const handleUpdateGeoDatabasesFile = useCallback(() => {
+ dispatch(updateGeoDatabasesFile(apiConfig));
+ },[apiConfig, dispatch]);
+
const handleFlushFakeIPPool = useCallback(() => {
dispatch(flushFakeIPPool(apiConfig));
},[apiConfig, dispatch]);
@@ -262,12 +256,27 @@ function ConfigImpl({
</div>
<div>
- <div className={s0.label}>Allow LAN</div>
+ <div className={s0.label}>{t('allow_lan')}</div>
<div className={s0.wrapSwitch}>
<Switch
name="allow-lan"
checked={configState['allow-lan']}
- onChange={handleSwitchOnChange}
+ onChange={(value: boolean) =>
+ handleChangeValue({ name: 'allow-lan', value: value })
+ }
+ />
+ </div>
+ </div>
+
+ <div>
+ <div className={s0.label}>{t('tls_sniffing')}</div>
+ <div className={s0.wrapSwitch}>
+ <Switch
+ name="sniffing"
+ checked={configState['sniffing']}
+ onChange={(value: boolean) =>
+ handleChangeValue({ name: 'sniffing', value: value })
+ }
/>
</div>
</div>
@@ -317,6 +326,15 @@ function ConfigImpl({
</div>
<div>
+ <div className={s0.label}>GEO Databases</div>
+ <Button
+ start={<DownloadCloud size={16} />}
+ label={t('update_geo_databases_file')}
+ onClick={handleUpdateGeoDatabasesFile}
+ />
+ </div>
+
+ <div>
<div className={s0.label}>FakeIP</div>
<Button
start={<Trash2 size={16} />}
diff --git a/src/i18n/en.ts b/src/i18n/en.ts
index 1f86610..ac45dec 100644
--- a/src/i18n/en.ts
+++ b/src/i18n/en.ts
@@ -37,6 +37,9 @@ export const data = {
update_all_rule_provider: 'Update all rule providers',
update_all_proxy_provider: 'Update all proxy providers',
reload_config_file: 'Reload config file',
+ update_geo_databases_file: 'Update GEO databases file',
flush_fake_ip_pool: 'Flush fake-ip data',
enable_tun_device: 'Enable TUN Device',
+ allow_lan: 'Allow LAN',
+ tls_sniffing: 'TLS Sniffing',
};
diff --git a/src/i18n/zh.ts b/src/i18n/zh.ts
index 09cf639..0efb10e 100644
--- a/src/i18n/zh.ts
+++ b/src/i18n/zh.ts
@@ -37,6 +37,9 @@ export const data = {
update_all_rule_provider: '更新所有 rule provider',
update_all_proxy_provider: '更新所有 proxy providers',
reload_config_file: '重载配置文件',
+ update_geo_databases_file: '更新 GEO 数据库文件',
flush_fake_ip_pool: '清空 FakeIP 数据库',
enable_tun_device: '开启 TUN 转发',
+ allow_lan: '允许局域网连接',
+ tls_sniffing: 'SNI 嗅探',
};
diff --git a/src/store/configs.ts b/src/store/configs.ts
index c4b95de..2a5c21a 100644
--- a/src/store/configs.ts
+++ b/src/store/configs.ts
@@ -87,12 +87,7 @@ export function updateConfigs(
});
dispatch('storeConfigsOptimisticUpdateConfigs', (s) => {
- if (partialConfg.tun != null) {
- s.configs.configs.tun = { ...s.configs.configs.tun, ...partialConfg.tun };
- } else {
- const config: generalConfig = {...s.configs.configs, ...partialConfg};
- s.configs.configs = config
- }
+ s.configs.configs = { ...s.configs.configs, ...partialConfg } as generalConfig;
});
};
}
@@ -105,12 +100,35 @@ export function reloadConfigFile(apiConfig: ClashAPIConfig) {
(res) => {
if (res.ok === false) {
// eslint-disable-next-line no-console
- console.log('Error update configs', res.statusText);
+ console.log('Error reload config file', res.statusText);
}
},
(err) => {
// eslint-disable-next-line no-console
- console.log('Error update configs', err);
+ console.log('Error reload config file', err);
+ throw err;
+ }
+ )
+ .then(() => {
+ dispatch(fetchConfigs(apiConfig));
+ });
+ };
+}
+
+export function updateGeoDatabasesFile(apiConfig: ClashAPIConfig) {
+ return async (dispatch: DispatchFn) => {
+ configsAPI
+ .updateGeoDatabasesFile(apiConfig)
+ .then(
+ (res) => {
+ if (res.ok === false) {
+ // eslint-disable-next-line no-console
+ console.log('Error update geo databases file', res.statusText);
+ }
+ },
+ (err) => {
+ // eslint-disable-next-line no-console
+ console.log('Error update geo databases file', err);
throw err;
}
)
@@ -128,12 +146,12 @@ export function flushFakeIPPool(apiConfig: ClashAPIConfig) {
(res) => {
if (res.ok === false) {
// eslint-disable-next-line no-console
- console.log('Error update configs', res.statusText);
+ console.log('Error flush FakeIP pool', res.statusText);
}
},
(err) => {
// eslint-disable-next-line no-console
- console.log('Error update configs', err);
+ console.log('Error flush FakeIP pool', err);
throw err;
}
)
@@ -154,6 +172,7 @@ export const initialState: StateConfigs = {
'allow-lan': false,
mode: 'rule',
'log-level': 'uninit',
+ sniffing: false,
tun: {
enable: false,
device: '',
diff --git a/src/store/types.ts b/src/store/types.ts
index 5ce542f..3a3e412 100644
--- a/src/store/types.ts
+++ b/src/store/types.ts
@@ -34,6 +34,7 @@ export type ClashGeneralConfig = {
'allow-lan': boolean;
mode: string;
'log-level': string;
+ sniffing?: boolean;
tun?: ClashTunConfig;
};