mirror of
https://github.com/woodchen-ink/clash-and-dashboard.git
synced 2025-07-18 14:01:56 +08:00
feat(rules): add proxygroups
This commit is contained in:
parent
0c93e77bf6
commit
cc70575a86
@ -29,13 +29,13 @@ class Rules extends React.Component<RulesProps, RulesState> {
|
|||||||
async componentDidMount () {
|
async componentDidMount () {
|
||||||
const { config } = this.props
|
const { config } = this.props
|
||||||
await config.fetchAndParseConfig()
|
await config.fetchAndParseConfig()
|
||||||
const rules = config.config.rules
|
|
||||||
const proxies = {
|
const proxies = {
|
||||||
'REJECT': { type: 'Reject' }
|
'REJECT': { type: 'Reject' },
|
||||||
|
'DIRECT': { type: 'Direct' }
|
||||||
}
|
}
|
||||||
config.config.proxy.map(p => {
|
config.config.proxy.map(p => proxies[p.name] = { type: p.type })
|
||||||
proxies[p.name] = { type: p.type }
|
config.config.proxyGroup.map(p => proxies[p.name] = { type: p.type })
|
||||||
})
|
const rules = config.config.rules.filter(r => proxies[r.proxy])
|
||||||
this.setState({
|
this.setState({
|
||||||
rules,
|
rules,
|
||||||
proxies
|
proxies
|
||||||
@ -47,7 +47,6 @@ class Rules extends React.Component<RulesProps, RulesState> {
|
|||||||
const { config } = this.props
|
const { config } = this.props
|
||||||
const { rules } = this.state
|
const { rules } = this.state
|
||||||
config.config.rules = rules
|
config.config.rules = rules
|
||||||
console.log(config)
|
|
||||||
await config.updateConfig()
|
await config.updateConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,8 +68,6 @@ class Rules extends React.Component<RulesProps, RulesState> {
|
|||||||
rules: produce(rules, draftState => {
|
rules: produce(rules, draftState => {
|
||||||
draftState[index].payload = payload
|
draftState[index].payload = payload
|
||||||
})
|
})
|
||||||
}, () => {
|
|
||||||
this.saveConfig()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +169,7 @@ class Rules extends React.Component<RulesProps, RulesState> {
|
|||||||
inside={true}
|
inside={true}
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
onChange={ value => this.handleModifyPayload(index, value) }
|
onChange={ value => this.handleModifyPayload(index, value) }
|
||||||
onBlur={() => this.setState({ modifiedIndex: -1 })}
|
onBlur={() => { this.setState({ modifiedIndex: -1 });this.saveConfig() }}
|
||||||
style={{ maxWidth: 230 }}
|
style={{ maxWidth: 230 }}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
@ -59,22 +59,10 @@ export interface Socks5Proxy {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProxyGroup {
|
export type ProxyGroup = SelectProxyGroup | UrlTestProxyGroup | FallbackProxyGroup
|
||||||
|
|
||||||
/**
|
|
||||||
* proxy group name
|
|
||||||
*/
|
|
||||||
name?: string
|
|
||||||
|
|
||||||
/**
|
|
||||||
* configs of proxy server
|
|
||||||
* now support select and url-test
|
|
||||||
*/
|
|
||||||
config?: SelectProxyGroup | UrlTestProxyGroup | FallbackProxyGroup
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SelectProxyGroup {
|
export interface SelectProxyGroup {
|
||||||
|
name?: string
|
||||||
|
|
||||||
type?: 'select'
|
type?: 'select'
|
||||||
|
|
||||||
@ -83,6 +71,7 @@ export interface SelectProxyGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface FallbackProxyGroup {
|
export interface FallbackProxyGroup {
|
||||||
|
name?: string
|
||||||
|
|
||||||
type?: 'fallback'
|
type?: 'fallback'
|
||||||
|
|
||||||
@ -95,6 +84,7 @@ export interface FallbackProxyGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface UrlTestProxyGroup {
|
export interface UrlTestProxyGroup {
|
||||||
|
name?: string
|
||||||
|
|
||||||
type?: 'url-test'
|
type?: 'url-test'
|
||||||
|
|
||||||
|
@ -9,10 +9,11 @@ export interface Rule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum RuleType {
|
export enum RuleType {
|
||||||
DOMAIN = 'DOMAIN',
|
'DOMAIN' = 'DOMAIN',
|
||||||
'DOMAIN-SUFFIX' = 'DOMAIN-SUFFIX',
|
'DOMAIN-SUFFIX' = 'DOMAIN-SUFFIX',
|
||||||
'DOMAIN-KEYWORD' = 'DOMAIN-KEYWORD',
|
'DOMAIN-KEYWORD' = 'DOMAIN-KEYWORD',
|
||||||
'GEOIP' = 'GEOIP',
|
'GEOIP' = 'GEOIP',
|
||||||
'FINAL' = 'FINAL',
|
'FINAL' = 'FINAL',
|
||||||
'IP-CIDR' = 'IP-CIDR'
|
'IP-CIDR' = 'IP-CIDR',
|
||||||
|
'USER-AGENT' = 'USER-AGENT'
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ export class ConfigStore {
|
|||||||
|
|
||||||
// otherwise parse ini
|
// otherwise parse ini
|
||||||
const config = yaml.parse(rawConfig)
|
const config = yaml.parse(rawConfig)
|
||||||
|
console.log(config)
|
||||||
const externalController = config['external-controller'] as string || ''
|
const externalController = config['external-controller'] as string || ''
|
||||||
const host = externalController.split(':')
|
const host = externalController.split(':')
|
||||||
|
|
||||||
@ -40,13 +40,13 @@ export class ConfigStore {
|
|||||||
const proxyGroups = config['Proxy Group'] as any[] || []
|
const proxyGroups = config['Proxy Group'] as any[] || []
|
||||||
const proxyGroup: Models.ProxyGroup[] = proxyGroups
|
const proxyGroup: Models.ProxyGroup[] = proxyGroups
|
||||||
.filter(p => ['url-test', 'select', 'fallback'].includes(p.type))
|
.filter(p => ['url-test', 'select', 'fallback'].includes(p.type))
|
||||||
.map(p => ({ name: p.name, config: p }))
|
|
||||||
const rules = config['Rule'] as any[] || []
|
const rules = config['Rule'] as any[] || []
|
||||||
const rule: Models.Rule[] = rules.map(r => r.split(',')).filter(r => r.length !== 3).map(r => ({
|
const rule: Models.Rule[] = rules.map(r => r.split(',')).filter(r => r.length >= 3).map(r => ({
|
||||||
type: Models.RuleType[r[0] as string],
|
type: Models.RuleType[r[0] as string],
|
||||||
payload: r[1],
|
payload: r[1],
|
||||||
proxy: r[2]
|
proxy: r[2]
|
||||||
}))
|
}))
|
||||||
|
console.log(rule)
|
||||||
this.config = {
|
this.config = {
|
||||||
general: {
|
general: {
|
||||||
port: config.port || 0,
|
port: config.port || 0,
|
||||||
@ -88,10 +88,6 @@ export class ConfigStore {
|
|||||||
const { general, proxy, proxyGroup, rules } = this.config
|
const { general, proxy, proxyGroup, rules } = this.config
|
||||||
const externalController = `${general.externalControllerAddr}:${general.externalControllerPort}`
|
const externalController = `${general.externalControllerAddr}:${general.externalControllerPort}`
|
||||||
const Rule = rules.map(r => [r.type, r.payload, r.proxy].join(','))
|
const Rule = rules.map(r => [r.type, r.payload, r.proxy].join(','))
|
||||||
const proxyGroups = proxyGroup.map(p => ({
|
|
||||||
name: p.name,
|
|
||||||
...p.config
|
|
||||||
}))
|
|
||||||
const config = {
|
const config = {
|
||||||
'external-controller': externalController,
|
'external-controller': externalController,
|
||||||
port: general.port,
|
port: general.port,
|
||||||
@ -102,11 +98,11 @@ export class ConfigStore {
|
|||||||
'log-level': general.logLevel,
|
'log-level': general.logLevel,
|
||||||
mode: general.mode,
|
mode: general.mode,
|
||||||
Proxy: proxy,
|
Proxy: proxy,
|
||||||
'Proxy Group': proxyGroups,
|
'Proxy Group': proxyGroup,
|
||||||
Rule
|
Rule
|
||||||
}
|
}
|
||||||
const data = yaml.stringify(config)
|
const data = yaml.stringify(config)
|
||||||
console.log(data)
|
// console.log(data)
|
||||||
// jsBridge.writeConfigWithString(data)
|
jsBridge.writeConfigWithString(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user