Skip to content

Commit 74d7820

Browse files
feature: 系统代理自定义排除域名,可配置为不排除,用于继续代理国内域名白名单中的域名。
1 parent f44dc79 commit 74d7820

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

packages/core/src/shell/scripts/set-system-proxy/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,11 @@ function getDomesticDomainAllowList () {
155155
}
156156

157157
function getProxyExcludeIpStr (split) {
158+
const proxyExcludeIpConfig = config.get().proxy.excludeIpList
159+
158160
let excludeIpStr = ''
159-
for (const ip in config.get().proxy.excludeIpList) {
160-
if (config.get().proxy.excludeIpList[ip] === true) {
161+
for (const ip in proxyExcludeIpConfig) {
162+
if (proxyExcludeIpConfig[ip] === true) {
161163
excludeIpStr += ip + split
162164
}
163165
}
@@ -166,12 +168,18 @@ function getProxyExcludeIpStr (split) {
166168
// log.debug('系统代理排除域名(excludeIpStr):', excludeIpStr)
167169
if (config.get().proxy.excludeDomesticDomainAllowList) {
168170
try {
169-
let domesticDomainAllowList = getDomesticDomainAllowList()
171+
const domesticDomainAllowList = getDomesticDomainAllowList()
170172
if (domesticDomainAllowList) {
171-
domesticDomainAllowList = (`${domesticDomainAllowList}\n`).replaceAll(/[\r\n]+/g, '\n').replaceAll(/[\d*\-.A-Z]*[^\d\n*\-.A-Z][^\n]*\n/gi, '').trim().replaceAll(/\s*\n\s*/g, split)
172-
if (domesticDomainAllowList) {
173-
excludeIpStr += domesticDomainAllowList
174-
log.info('系统代理排除列表拼接国内域名')
173+
const domesticDomainList = (`\n${domesticDomainAllowList}`).replaceAll(/[\r\n]+/g, '\n').match(/(?<=\n)(?:[\w\-.*]+|\[[\w:]+\])(?=\n)/g)
174+
if (domesticDomainList && domesticDomainList.length > 0) {
175+
for (const domesticDomain of domesticDomainList) {
176+
if (proxyExcludeIpConfig[domesticDomain] !== false) {
177+
excludeIpStr += domesticDomain + split
178+
} else {
179+
log.info('系统代理排除列表拼接国内域名时,跳过域名,系统代理将继续代理它:', domesticDomain)
180+
}
181+
}
182+
log.info('系统代理排除列表拼接国内域名成功')
175183
} else {
176184
log.info('国内域名为空,不进行系统代理排除列表拼接国内域名')
177185
}

packages/gui/src/view/pages/plugin/overwall.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ export default {
1111
servers: undefined,
1212
overwallOptions: [
1313
{
14-
value: true,
1514
label: '启用',
15+
value: 'true',
1616
},
1717
{
18-
value: false,
1918
label: '禁用',
19+
value: 'false',
2020
},
2121
],
2222
}
@@ -49,22 +49,22 @@ export default {
4949
for (const key in targetsMap) {
5050
const value = targetsMap[key]
5151
this.targets.push({
52-
key,
53-
value,
52+
key: key || '',
53+
value: value === true ? 'true' : 'false',
5454
})
5555
}
5656
},
5757
deleteTarget (item, index) {
5858
this.targets.splice(index, 1)
5959
},
6060
addTarget () {
61-
this.targets.unshift({ key: '', value: true })
61+
this.targets.unshift({ key: '', value: 'true' })
6262
},
6363
saveTarget () {
6464
const map = {}
6565
for (const item of this.targets) {
6666
if (item.key) {
67-
map[item.key] = item.value
67+
map[item.key] = item.value === 'true'
6868
}
6969
}
7070
this.config.plugin.overwall.targets = map
@@ -165,8 +165,8 @@ export default {
165165
</a-col>
166166
<a-col :span="4">
167167
<a-select v-model="item.value" style="width:100%">
168-
<a-select-option v-for="(item) of overwallOptions" :key="item.value" :value="item.value">
169-
{{ item.label }}
168+
<a-select-option v-for="(item2) of overwallOptions" :key="item2.value" :value="item2.value">
169+
{{ item2.label }}
170170
</a-select-option>
171171
</a-select>
172172
</a-col>

packages/gui/src/view/pages/proxy.vue

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ export default {
99
key: 'proxy',
1010
loopbackVisible: false,
1111
excludeIpList: [],
12+
excludeIpOptions: [
13+
{
14+
label: '排除',
15+
value: 'true',
16+
},
17+
{
18+
label: '不排除',
19+
value: 'false',
20+
},
21+
],
1222
}
1323
},
1424
async created () {
@@ -43,13 +53,13 @@ export default {
4353
for (const key in this.config.proxy.excludeIpList) {
4454
const value = this.config.proxy.excludeIpList[key]
4555
this.excludeIpList.push({
46-
key,
47-
value,
56+
key: key || '',
57+
value: value === true ? 'true' : 'false',
4858
})
4959
}
5060
},
5161
addExcludeIp () {
52-
this.excludeIpList.unshift({ key: '', value: true })
62+
this.excludeIpList.unshift({ key: '', value: 'true' })
5363
},
5464
delExcludeIp (item, index) {
5565
this.excludeIpList.splice(index, 1)
@@ -58,7 +68,7 @@ export default {
5868
const excludeIpList = {}
5969
for (const item of this.excludeIpList) {
6070
if (item.key) {
61-
excludeIpList[item.key] = item.value
71+
excludeIpList[item.key] = item.value === 'true'
6272
}
6373
}
6474
this.config.proxy.excludeIpList = excludeIpList
@@ -122,6 +132,9 @@ export default {
122132
<a-checkbox v-model="config.proxy.excludeDomesticDomainAllowList">
123133
是否排除国内域名白名单
124134
</a-checkbox>
135+
<div class="form-help">
136+
国内域名白名单内收录了国内可直接访问的域名,这些域名将不被代理<br>当里面某些域名你希望代理时,你可以配置这些域名为<code>不排除</code>,也可以关闭国内域名白名单
137+
</div>
125138
</a-form-item>
126139
<a-form-item label="自动更新国内域名" :label-col="labelCol" :wrapper-col="wrapperCol">
127140
<a-checkbox v-model="config.proxy.autoUpdateDomesticDomainAllowList">
@@ -142,15 +155,22 @@ export default {
142155
<a-form-item label="自定义排除域名" :label-col="labelCol" :wrapper-col="wrapperCol">
143156
<a-row :gutter="10">
144157
<a-col :span="22">
145-
<span>访问的域名或IP符合下列配置时,将跳过系统代理</span>
158+
<span>国内域名不包含的域名,可以在此处定义;配置为 <code>不排除</code>时,将被代理</span>
146159
</a-col>
147160
<a-col :span="2">
148161
<a-button type="primary" icon="plus" @click="addExcludeIp()" />
149162
</a-col>
150163
</a-row>
151164
<a-row v-for="(item, index) of excludeIpList" :key="index" :gutter="10">
152-
<a-col :span="22">
153-
<a-input v-model="item.key" :disabled="item.value === false" />
165+
<a-col :span="17">
166+
<a-input v-model="item.key" />
167+
</a-col>
168+
<a-col :span="5">
169+
<a-select v-model="item.value" style="width:100%">
170+
<a-select-option v-for="(item2) of excludeIpOptions" :key="item2.value" :value="item2.value">
171+
{{ item2.label }}
172+
</a-select-option>
173+
</a-select>
154174
</a-col>
155175
<a-col :span="2">
156176
<a-button type="danger" icon="minus" @click="delExcludeIp(item, index)" />

0 commit comments

Comments
 (0)