优化系统代理排除地址配置,数据格式由Array改为Object,方便远程配置添加配置。

pull/274/head
王良 2024-02-22 00:59:29 +08:00
parent 92c580c487
commit 6a83041fe0
4 changed files with 195 additions and 87 deletions

View File

@ -34,7 +34,7 @@ const ProxyPlugin = function (context) {
log.info('关闭系统代理成功') log.info('关闭系统代理成功')
return true return true
} catch (err) { } catch (err) {
log.error('关闭系统代理失败', err) log.error('关闭系统代理失败:', err)
return false return false
} }
}, },
@ -55,107 +55,186 @@ module.exports = {
use: 'local', use: 'local',
other: [], other: [],
setEnv: false, setEnv: false,
excludeIpList: [ excludeIpList: {
// region 中国大陆,可直接访问,无需代理 // region 常用国内可访问域名
// 中国大陆域名,大部分可直接访问,无需代理 // 中国大陆
'*.cn', '*.cn': true,
'cn.*', 'cn.*': true,
'*china*': true,
// 系统之家
'*.xitongzhijia.net': true,
// CSDN // CSDN
'*.csdn.net', '*.csdn.net': true,
// 百度 // 百度
'*.baidu.com', '*.baidu.com': true,
'*.baiducontent.com': true,
'*.bdimg.com': true,
'*.bdstatic.com': true,
'*.bdydns.com': true,
// 腾讯 // 腾讯
'*.tencent.com', '*.tencent.com': true,
'*.qq.com', '*.qq.com': true,
'*.weixin.com', '*.weixin.com': true,
'*.wechat.com', '*.weixinbridge.com': true,
'*.wechat.com': true,
'*.idqqimg.com': true,
'*.gtimg.com': true,
'*.qpic.com': true,
'*.qlogo.com': true,
'*.myapp.com': true,
'*.myqcloud.com': true,
// 阿里 // 阿里
'*.alipay.com', '*.aliyun.com': true,
'*.taobao.com', '*.alipay.com': true,
'*.tmall.com', '*.taobao.com': true,
'*.aliyun.com', '*.tmall.com': true,
'*.dingtalk.com', // 不排除会导致钉钉的团队文档打不开(原因未知) '*.alipayobjects.com': true,
'*.dingtalk.com': true,
'*.mmstat.com': true,
'*.alicdn.com': true,
'*.hdslb.com': true,
// Gitee // Gitee
'gitee.com', 'gitee.com': true,
'*.gitee.com', '*.gitee.com': true,
'*.gitee.io', '*.gitee.io': true,
'*.giteeusercontent.com': true,
// Mozilla Firefox
'*.mozilla.org': true,
'*.mozilla.com': true,
'*.mozilla.net': true,
'*.firefox.com': true,
'*.firefox.org': true,
'*.mozillademos.org': true,
'*.mozillians.org': true,
'*.mozillians.net': true,
'*.mozillians.com': true,
// OSS // OSS
'*.sonatype.org', '*.sonatype.org': true,
// Maven镜像 // Maven镜像
'*.maven.org', '*.maven.org': true,
// Maven Repository // Maven Repository
'*.mvnrepository.com', '*.mvnrepository.com': true,
'challenges.cloudflare.com', // 在访问 mvnrepository.com 的人机校验时使用,国内可直接访问,所以不需要代理,代理了反而变慢了。 'challenges.cloudflare.com': true, // 在访问 mvnrepository.com 的人机校验时使用,国内可直接访问,所以不需要代理,代理了反而变慢了。
// 苹果 // 苹果
'*.apple.com', '*.apple.com': true,
'*.icloud.com', '*.icloud.com': true,
// 微软 // 微软
'*.microsoft.com', '*.microsoft.com': true,
'*.windows.com', '*.windows.com': true,
'*.office.com', '*.office.com': true,
'*.office.net', '*.office.net': true,
'*.live.com', '*.live.com': true,
'*.msn.com', '*.msn.com': true,
// WPS // WPS
'*.wps.com', '*.wps.com': true,
// 奇虎 // 奇虎
'*.qihoo.com', '*.qihoo.com': true,
'*.qihucdn.com', '*.qihucdn.com': true,
// 360 // 360
'*.360.com', '*.360.com': true,
'*.360safe.com', '*.360safe.com': true,
'*.360buyimg.com', '*.360buyimg.com': true,
'*.360buy.com', '*.360buy.com': true,
// 京东 // 京东
'*.jd.com', '*.jd.com': true,
'*.jcloud.com', '*.jcloud.com': true,
'*.jcloudcs.com', '*.jcloudcs.com': true,
'*.jcloudcache.com', '*.jcloudcache.com': true,
'*.jcloudcdn.com', '*.jcloudcdn.com': true,
'*.jcloudlb.com', '*.jcloudlb.com': true,
// 哔哩哔哩
'*.bilibili.com': true,
'*.bilivideo.com.com': true,
'*.biliapi.net': true,
// 移动
'*.10086.com': true,
'*.10086cloud.com': true,
// 移动139邮箱
'*.139.com': true,
// 迅雷
'*.xunlei.com': true,
// 网站ICP备案查询
'*.icpapi.com': true,
// AGE动漫
'*.agedm.*': true,
'*.zhimg.com': true,
'*.bdxiguaimg.com': true,
'*.toutiaoimg.com': true,
'*.bytecdntp.com': true,
'*.bytegoofy.com': true,
'*.toutiao.com': true,
'*.toutiaovod.com': true,
'*.aliyuncs.com': true,
'*.127.net': true,
'43.240.74.134': true,
// ZzzFun
'*.zzzfun.one': true,
'*.zzzfun.vip': true,
// 必应
'*.bing.com': true,
// 我的个人域名
'*.easyj.icu': true,
// 未知公司
'*.bcebos.com': true,
'icannwiki.org': true,
'*.icannwiki.org': true,
'*.sectigo.com': true,
'*.pingdom.net': true,
// endregion // endregion
// 本地地址,无需代理 // 本地地址,无需代理
'localhost', 'localhost': true,
'localhost.*', // 部分VPN会在host中添加这种格式的域名指向127.0.0.1,所以也排除掉 'localhost.*': true, // 部分VPN会在host中添加这种格式的域名指向127.0.0.1,所以也排除掉
'127.*', '127.*': true,
'test.*', // 本地开发时,测试用的虚拟域名格式,无需代理 'test.*': true, // 本地开发时,测试用的虚拟域名格式,无需代理
// 服务器端常用地址,无需代理 // 服务器端常用地址,无需代理
'10.*', '10.*': true,
'172.16.*', '172.16.*': true,
'172.17.*', '172.17.*': true,
'172.18.*', '172.18.*': true,
'172.19.*', '172.19.*': true,
'172.20.*', '172.20.*': true,
'172.21.*', '172.21.*': true,
'172.22.*', '172.22.*': true,
'172.23.*', '172.23.*': true,
'172.24.*', '172.24.*': true,
'172.25.*', '172.25.*': true,
'172.26.*', '172.26.*': true,
'172.27.*', '172.27.*': true,
'172.28.*', '172.28.*': true,
'172.29.*', '172.29.*': true,
'172.30.*', '172.30.*': true,
'172.31.*', '172.31.*': true,
// 局域网地址,无需代理 // 局域网地址,无需代理
'192.168.*' '192.168.*': true
] }
}, },
status: { status: {
enabled: false, enabled: false,

View File

@ -25,7 +25,7 @@ async function _winUnsetProxy (exec, setEnv) {
regKey.get('HTTPS_PROXY', (err) => { regKey.get('HTTPS_PROXY', (err) => {
if (!err) { if (!err) {
regKey.remove('HTTPS_PROXY', async (err) => { regKey.remove('HTTPS_PROXY', async (err) => {
log.info('删除环境变量https_proxy', err) log.warn('删除环境变量https_proxy失败:', err)
await exec('setx DS_REFRESH "1"') await exec('setx DS_REFRESH "1"')
}) })
} }
@ -41,17 +41,19 @@ async function _winSetProxy (exec, ip, port, setEnv) {
config = require('../../../config.js') config = require('../../../config.js')
} }
let lanIpStr = '' let excludeIpStr = ''
for (const excludeIpPattern of config.get().proxy.excludeIpList) { for (const ip in config.get().proxy.excludeIpList) {
// 跳过起注释作用的数据 if (config.get().proxy.excludeIpList[ip] === true) {
if (excludeIpPattern.indexOf('#') >= 0) { excludeIpStr += ip + ';'
continue
} }
lanIpStr += excludeIpPattern + ';'
} }
// http=127.0.0.1:8888;https=127.0.0.1:8888 考虑这种方式 // http=127.0.0.1:8888;https=127.0.0.1:8888 考虑这种方式
const proxyPath = extraPath.getProxyExePath() const proxyPath = extraPath.getProxyExePath()
await execFile(proxyPath, ['global', `http=http://${ip}:${port};https=http://${ip}:${port}`, lanIpStr]) const execFun = 'global'
const proxyAddr = `http=http://${ip}:${port};https=http://${ip}:${port}`
log.info(`执行“设置系统代理”的命令: ${proxyPath} ${execFun} ${proxyAddr} ${excludeIpStr}`)
await execFile(proxyPath, [execFun, proxyAddr, excludeIpStr])
if (setEnv) { if (setEnv) {
log.info('同时设置 https_proxy') log.info('同时设置 https_proxy')
@ -77,8 +79,7 @@ const executor = {
return _winUnsetProxy(exec, setEnv) return _winUnsetProxy(exec, setEnv)
} else { } else {
// 设置代理 // 设置代理
log.info('设置代理:', ip, port, setEnv)
log.info('设置代理', ip, port, setEnv)
return _winSetProxy(exec, ip, port, setEnv) return _winSetProxy(exec, ip, port, setEnv)
} }
}, },

View File

@ -41,6 +41,9 @@ export default {
} }
}, },
async apply () { async apply () {
if (this.applyLoading === true) {
return
}
this.applyLoading = true this.applyLoading = true
await this.applyBefore() await this.applyBefore()
await this.saveConfig() await this.saveConfig()

View File

@ -39,15 +39,15 @@
<span>访问的域名或IP符合下列格式时将跳过系统代理</span> <span>访问的域名或IP符合下列格式时将跳过系统代理</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 :gutter="10" v-for="(item,index) of getProxyConfig().excludeIpList" :key='index'> <a-row :gutter="10" v-for="(item,index) of excludeIpList" :key='index'>
<a-col :span="22"> <a-col :span="22">
<a-input v-model="getProxyConfig().excludeIpList[index]"></a-input> <a-input :disabled="item.value === false" v-model="item.key"></a-input>
</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)"/>
</a-col> </a-col>
</a-row> </a-row>
</div> </div>
@ -77,7 +77,7 @@
<div>1此设置用于解决OneNoteMicrosoftStoreOutlook等UWP应用无法访问网络的问题</div> <div>1此设置用于解决OneNoteMicrosoftStoreOutlook等UWP应用无法访问网络的问题</div>
<div>2点击右上方按钮打开EnableLoopback然后按下图所示操作即可</div> <div>2点击右上方按钮打开EnableLoopback然后按下图所示操作即可</div>
<div>3注意此操作需要<b style="color:red">DevSidecar以管理员身份启动</b>才能打开下面的EnableLoopback设置界面</div> <div>3注意此操作需要<b style="color:red">DevSidecar以管理员身份启动</b>才能打开下面的EnableLoopback设置界面</div>
<img style="margin-top:20px;border:1px solid #eee" width="80%" src="loopback.png" /> <img style="margin-top:20px;border:1px solid #eee" width="80%" src="loopback.png"/>
</div> </div>
</a-drawer> </a-drawer>
@ -93,7 +93,8 @@ export default {
data () { data () {
return { return {
key: 'proxy', key: 'proxy',
loopbackVisible: false loopbackVisible: false,
excludeIpList: []
} }
}, },
async created () { async created () {
@ -102,7 +103,13 @@ export default {
}, },
methods: { methods: {
async openExternal (url) { async openExternal (url) {
this.$api.ipc.openExternal(url) await this.$api.ipc.openExternal(url)
},
ready () {
this.initExcludeIpList()
},
async applyBefore () {
this.submitExcludeIpList()
}, },
async applyAfter () { async applyAfter () {
await this.$api.proxy.restart() await this.$api.proxy.restart()
@ -121,11 +128,29 @@ export default {
getProxyConfig () { getProxyConfig () {
return this.config.proxy return this.config.proxy
}, },
initExcludeIpList () {
this.excludeIpList = []
for (const key in this.config.proxy.excludeIpList) {
const value = this.config.proxy.excludeIpList[key]
this.excludeIpList.push({
key, value
})
}
},
addExcludeIp () { addExcludeIp () {
this.getProxyConfig().excludeIpList.unshift('') this.excludeIpList.unshift({ key: '', value: true })
}, },
delExcludeIp (item, index) { delExcludeIp (item, index) {
this.getProxyConfig().excludeIpList.splice(index, 1) this.excludeIpList.splice(index, 1)
},
submitExcludeIpList () {
const excludeIpList = {}
for (const item of this.excludeIpList) {
if (item.key) {
excludeIpList[item.key] = item.value
}
}
this.config.proxy.excludeIpList = excludeIpList
} }
} }
} }