Skip to content

Commit

Permalink
feature: 系统代理自定义排除域名,可配置为不排除,用于继续代理国内域名白名单中的域名。
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Jan 24, 2025
1 parent f44dc79 commit 74d7820
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
22 changes: 15 additions & 7 deletions packages/core/src/shell/scripts/set-system-proxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ function getDomesticDomainAllowList () {
}

function getProxyExcludeIpStr (split) {
const proxyExcludeIpConfig = config.get().proxy.excludeIpList

let excludeIpStr = ''
for (const ip in config.get().proxy.excludeIpList) {
if (config.get().proxy.excludeIpList[ip] === true) {
for (const ip in proxyExcludeIpConfig) {
if (proxyExcludeIpConfig[ip] === true) {
excludeIpStr += ip + split
}
}
Expand All @@ -166,12 +168,18 @@ function getProxyExcludeIpStr (split) {
// log.debug('系统代理排除域名(excludeIpStr):', excludeIpStr)
if (config.get().proxy.excludeDomesticDomainAllowList) {
try {
let domesticDomainAllowList = getDomesticDomainAllowList()
const domesticDomainAllowList = getDomesticDomainAllowList()
if (domesticDomainAllowList) {
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)
if (domesticDomainAllowList) {
excludeIpStr += domesticDomainAllowList
log.info('系统代理排除列表拼接国内域名')
const domesticDomainList = (`\n${domesticDomainAllowList}`).replaceAll(/[\r\n]+/g, '\n').match(/(?<=\n)(?:[\w\-.*]+|\[[\w:]+\])(?=\n)/g)
if (domesticDomainList && domesticDomainList.length > 0) {
for (const domesticDomain of domesticDomainList) {
if (proxyExcludeIpConfig[domesticDomain] !== false) {
excludeIpStr += domesticDomain + split
} else {
log.info('系统代理排除列表拼接国内域名时,跳过域名,系统代理将继续代理它:', domesticDomain)
}
}
log.info('系统代理排除列表拼接国内域名成功')
} else {
log.info('国内域名为空,不进行系统代理排除列表拼接国内域名')
}
Expand Down
16 changes: 8 additions & 8 deletions packages/gui/src/view/pages/plugin/overwall.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export default {
servers: undefined,
overwallOptions: [
{
value: true,
label: '启用',
value: 'true',
},
{
value: false,
label: '禁用',
value: 'false',
},
],
}
Expand Down Expand Up @@ -49,22 +49,22 @@ export default {
for (const key in targetsMap) {
const value = targetsMap[key]
this.targets.push({
key,
value,
key: key || '',
value: value === true ? 'true' : 'false',
})
}
},
deleteTarget (item, index) {
this.targets.splice(index, 1)
},
addTarget () {
this.targets.unshift({ key: '', value: true })
this.targets.unshift({ key: '', value: 'true' })
},
saveTarget () {
const map = {}
for (const item of this.targets) {
if (item.key) {
map[item.key] = item.value
map[item.key] = item.value === 'true'
}
}
this.config.plugin.overwall.targets = map
Expand Down Expand Up @@ -165,8 +165,8 @@ export default {
</a-col>
<a-col :span="4">
<a-select v-model="item.value" style="width:100%">
<a-select-option v-for="(item) of overwallOptions" :key="item.value" :value="item.value">
{{ item.label }}
<a-select-option v-for="(item2) of overwallOptions" :key="item2.value" :value="item2.value">
{{ item2.label }}
</a-select-option>
</a-select>
</a-col>
Expand Down
34 changes: 27 additions & 7 deletions packages/gui/src/view/pages/proxy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ export default {
key: 'proxy',
loopbackVisible: false,
excludeIpList: [],
excludeIpOptions: [
{
label: '排除',
value: 'true',
},
{
label: '不排除',
value: 'false',
},
],
}
},
async created () {
Expand Down Expand Up @@ -43,13 +53,13 @@ export default {
for (const key in this.config.proxy.excludeIpList) {
const value = this.config.proxy.excludeIpList[key]
this.excludeIpList.push({
key,
value,
key: key || '',
value: value === true ? 'true' : 'false',
})
}
},
addExcludeIp () {
this.excludeIpList.unshift({ key: '', value: true })
this.excludeIpList.unshift({ key: '', value: 'true' })
},
delExcludeIp (item, index) {
this.excludeIpList.splice(index, 1)
Expand All @@ -58,7 +68,7 @@ export default {
const excludeIpList = {}
for (const item of this.excludeIpList) {
if (item.key) {
excludeIpList[item.key] = item.value
excludeIpList[item.key] = item.value === 'true'
}
}
this.config.proxy.excludeIpList = excludeIpList
Expand Down Expand Up @@ -122,6 +132,9 @@ export default {
<a-checkbox v-model="config.proxy.excludeDomesticDomainAllowList">
是否排除国内域名白名单
</a-checkbox>
<div class="form-help">
国内域名白名单内收录了国内可直接访问的域名,这些域名将不被代理<br>当里面某些域名你希望代理时,你可以配置这些域名为<code>不排除</code>,也可以关闭国内域名白名单
</div>
</a-form-item>
<a-form-item label="自动更新国内域名" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-checkbox v-model="config.proxy.autoUpdateDomesticDomainAllowList">
Expand All @@ -142,15 +155,22 @@ export default {
<a-form-item label="自定义排除域名" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-row :gutter="10">
<a-col :span="22">
<span>访问的域名或IP符合下列配置时,将跳过系统代理</span>
<span>国内域名不包含的域名,可以在此处定义;配置为 <code>不排除</code>时,将被代理</span>
</a-col>
<a-col :span="2">
<a-button type="primary" icon="plus" @click="addExcludeIp()" />
</a-col>
</a-row>
<a-row v-for="(item, index) of excludeIpList" :key="index" :gutter="10">
<a-col :span="22">
<a-input v-model="item.key" :disabled="item.value === false" />
<a-col :span="17">
<a-input v-model="item.key" />
</a-col>
<a-col :span="5">
<a-select v-model="item.value" style="width:100%">
<a-select-option v-for="(item2) of excludeIpOptions" :key="item2.value" :value="item2.value">
{{ item2.label }}
</a-select-option>
</a-select>
</a-col>
<a-col :span="2">
<a-button type="danger" icon="minus" @click="delExcludeIp(item, index)" />
Expand Down

0 comments on commit 74d7820

Please sign in to comment.