feature: 系统代理自定义排除域名,可配置为不排除,用于继续代理国内域名白名单中的域名。

pull/445/head
王良 2025-01-24 17:27:08 +08:00
parent f44dc790c7
commit 74d78207bf
3 changed files with 50 additions and 22 deletions

View File

@ -155,9 +155,11 @@ function getDomesticDomainAllowList () {
} }
function getProxyExcludeIpStr (split) { function getProxyExcludeIpStr (split) {
const proxyExcludeIpConfig = config.get().proxy.excludeIpList
let excludeIpStr = '' let excludeIpStr = ''
for (const ip in config.get().proxy.excludeIpList) { for (const ip in proxyExcludeIpConfig) {
if (config.get().proxy.excludeIpList[ip] === true) { if (proxyExcludeIpConfig[ip] === true) {
excludeIpStr += ip + split excludeIpStr += ip + split
} }
} }
@ -166,12 +168,18 @@ function getProxyExcludeIpStr (split) {
// log.debug('系统代理排除域名excludeIpStr:', excludeIpStr) // log.debug('系统代理排除域名excludeIpStr:', excludeIpStr)
if (config.get().proxy.excludeDomesticDomainAllowList) { if (config.get().proxy.excludeDomesticDomainAllowList) {
try { try {
let domesticDomainAllowList = getDomesticDomainAllowList() const domesticDomainAllowList = getDomesticDomainAllowList()
if (domesticDomainAllowList) { 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) const domesticDomainList = (`\n${domesticDomainAllowList}`).replaceAll(/[\r\n]+/g, '\n').match(/(?<=\n)(?:[\w\-.*]+|\[[\w:]+\])(?=\n)/g)
if (domesticDomainAllowList) { if (domesticDomainList && domesticDomainList.length > 0) {
excludeIpStr += domesticDomainAllowList for (const domesticDomain of domesticDomainList) {
log.info('系统代理排除列表拼接国内域名') if (proxyExcludeIpConfig[domesticDomain] !== false) {
excludeIpStr += domesticDomain + split
} else {
log.info('系统代理排除列表拼接国内域名时,跳过域名,系统代理将继续代理它:', domesticDomain)
}
}
log.info('系统代理排除列表拼接国内域名成功')
} else { } else {
log.info('国内域名为空,不进行系统代理排除列表拼接国内域名') log.info('国内域名为空,不进行系统代理排除列表拼接国内域名')
} }

View File

@ -11,12 +11,12 @@ export default {
servers: undefined, servers: undefined,
overwallOptions: [ overwallOptions: [
{ {
value: true,
label: '启用', label: '启用',
value: 'true',
}, },
{ {
value: false,
label: '禁用', label: '禁用',
value: 'false',
}, },
], ],
} }
@ -49,8 +49,8 @@ export default {
for (const key in targetsMap) { for (const key in targetsMap) {
const value = targetsMap[key] const value = targetsMap[key]
this.targets.push({ this.targets.push({
key, key: key || '',
value, value: value === true ? 'true' : 'false',
}) })
} }
}, },
@ -58,13 +58,13 @@ export default {
this.targets.splice(index, 1) this.targets.splice(index, 1)
}, },
addTarget () { addTarget () {
this.targets.unshift({ key: '', value: true }) this.targets.unshift({ key: '', value: 'true' })
}, },
saveTarget () { saveTarget () {
const map = {} const map = {}
for (const item of this.targets) { for (const item of this.targets) {
if (item.key) { if (item.key) {
map[item.key] = item.value map[item.key] = item.value === 'true'
} }
} }
this.config.plugin.overwall.targets = map this.config.plugin.overwall.targets = map
@ -165,8 +165,8 @@ export default {
</a-col> </a-col>
<a-col :span="4"> <a-col :span="4">
<a-select v-model="item.value" style="width:100%"> <a-select v-model="item.value" style="width:100%">
<a-select-option v-for="(item) of overwallOptions" :key="item.value" :value="item.value"> <a-select-option v-for="(item2) of overwallOptions" :key="item2.value" :value="item2.value">
{{ item.label }} {{ item2.label }}
</a-select-option> </a-select-option>
</a-select> </a-select>
</a-col> </a-col>

View File

@ -9,6 +9,16 @@ export default {
key: 'proxy', key: 'proxy',
loopbackVisible: false, loopbackVisible: false,
excludeIpList: [], excludeIpList: [],
excludeIpOptions: [
{
label: '排除',
value: 'true',
},
{
label: '不排除',
value: 'false',
},
],
} }
}, },
async created () { async created () {
@ -43,13 +53,13 @@ export default {
for (const key in this.config.proxy.excludeIpList) { for (const key in this.config.proxy.excludeIpList) {
const value = this.config.proxy.excludeIpList[key] const value = this.config.proxy.excludeIpList[key]
this.excludeIpList.push({ this.excludeIpList.push({
key, key: key || '',
value, value: value === true ? 'true' : 'false',
}) })
} }
}, },
addExcludeIp () { addExcludeIp () {
this.excludeIpList.unshift({ key: '', value: true }) this.excludeIpList.unshift({ key: '', value: 'true' })
}, },
delExcludeIp (item, index) { delExcludeIp (item, index) {
this.excludeIpList.splice(index, 1) this.excludeIpList.splice(index, 1)
@ -58,7 +68,7 @@ export default {
const excludeIpList = {} const excludeIpList = {}
for (const item of this.excludeIpList) { for (const item of this.excludeIpList) {
if (item.key) { if (item.key) {
excludeIpList[item.key] = item.value excludeIpList[item.key] = item.value === 'true'
} }
} }
this.config.proxy.excludeIpList = excludeIpList this.config.proxy.excludeIpList = excludeIpList
@ -122,6 +132,9 @@ export default {
<a-checkbox v-model="config.proxy.excludeDomesticDomainAllowList"> <a-checkbox v-model="config.proxy.excludeDomesticDomainAllowList">
是否排除国内域名白名单 是否排除国内域名白名单
</a-checkbox> </a-checkbox>
<div class="form-help">
国内域名白名单内收录了国内可直接访问的域名这些域名将不被代理<br>当里面某些域名你希望代理时你可以配置这些域名为<code>不排除</code>也可以关闭国内域名白名单
</div>
</a-form-item> </a-form-item>
<a-form-item label="自动更新国内域名" :label-col="labelCol" :wrapper-col="wrapperCol"> <a-form-item label="自动更新国内域名" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-checkbox v-model="config.proxy.autoUpdateDomesticDomainAllowList"> <a-checkbox v-model="config.proxy.autoUpdateDomesticDomainAllowList">
@ -142,15 +155,22 @@ export default {
<a-form-item label="自定义排除域名" :label-col="labelCol" :wrapper-col="wrapperCol"> <a-form-item label="自定义排除域名" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-row :gutter="10"> <a-row :gutter="10">
<a-col :span="22"> <a-col :span="22">
<span>访问的域名或IP符合下列配置时将跳过系统代理</span> <span>国内域名不包含的域名可以在此处定义配置为 <code>不排除</code>将被代理</span>
</a-col> </a-col>
<a-col :span="2"> <a-col :span="2">
<a-button type="primary" icon="plus" @click="addExcludeIp()" /> <a-button type="primary" icon="plus" @click="addExcludeIp()" />
</a-col> </a-col>
</a-row> </a-row>
<a-row v-for="(item, index) of excludeIpList" :key="index" :gutter="10"> <a-row v-for="(item, index) of excludeIpList" :key="index" :gutter="10">
<a-col :span="22"> <a-col :span="17">
<a-input v-model="item.key" :disabled="item.value === false" /> <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>
<a-col :span="2"> <a-col :span="2">
<a-button type="danger" icon="minus" @click="delExcludeIp(item, index)" /> <a-button type="danger" icon="minus" @click="delExcludeIp(item, index)" />