feature: IP预设置可配置化。
parent
6af96e2630
commit
a02c2ff306
|
@ -218,9 +218,9 @@ const intercepts = {
|
|||
```js
|
||||
dns: {
|
||||
mapping: {
|
||||
'api.github.com': 'usa', // "解决push的时候需要输入密码的问题",
|
||||
'gist.github.com': 'usa' // 解决gist无法访问的问题
|
||||
'*.githubusercontent.com': 'usa' // 解决github头像经常下载不到的问题
|
||||
'api.github.com': 'cloudflare', // "解决push的时候需要输入密码的问题",
|
||||
'gist.github.com': 'cloudflare' // 解决gist无法访问的问题
|
||||
'*.githubusercontent.com': 'cloudflare' // 解决github头像经常下载不到的问题
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -260,6 +260,70 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
},
|
||||
// 预设置IP列表
|
||||
preSetIpList: {
|
||||
'github.com': [
|
||||
'20.200.245.247',
|
||||
'20.27.177.113',
|
||||
'20.205.243.166',
|
||||
'20.248.137.48',
|
||||
'140.82.116.4', '140.82.114.4', '140.82.113.3',
|
||||
'20.26.156.215',
|
||||
'20.87.245.0',
|
||||
'20.201.28.151',
|
||||
'140.82.121.3', '140.82.121.4'
|
||||
],
|
||||
'api.github.com': [
|
||||
'20.87.245.6',
|
||||
'140.82.112.5',
|
||||
'140.82.116.6',
|
||||
'20.26.156.210',
|
||||
'20.200.245.245',
|
||||
'20.27.177.116',
|
||||
'20.248.137.49',
|
||||
'20.201.28.148',
|
||||
'140.82.113.6',
|
||||
'20.205.243.168',
|
||||
'140.82.121.6'
|
||||
],
|
||||
'codeload.github.com': [
|
||||
'20.26.156.216',
|
||||
'20.27.177.114',
|
||||
'20.87.245.7',
|
||||
'20.200.245.246',
|
||||
'20.201.28.149',
|
||||
'20.205.243.165',
|
||||
'20.248.137.55',
|
||||
'140.82.113.9',
|
||||
'140.82.114.10',
|
||||
'140.82.116.10',
|
||||
'140.82.121.9'
|
||||
],
|
||||
'*.githubusercontent.com': [
|
||||
'185.199.108.133',
|
||||
'185.199.109.133',
|
||||
'185.199.110.133',
|
||||
'185.199.111.133'
|
||||
],
|
||||
'github.githubassets.com': [
|
||||
'185.199.108.154',
|
||||
'185.199.109.154',
|
||||
'185.199.110.154',
|
||||
'185.199.111.154'
|
||||
],
|
||||
'collector.github.com': ['0.0.0.0'],
|
||||
'github.io': [
|
||||
'185.199.108.153',
|
||||
'185.199.109.153',
|
||||
'185.199.110.153',
|
||||
'185.199.111.153'
|
||||
],
|
||||
'hub.docker.com': [
|
||||
'44.221.37.199',
|
||||
'52.44.227.212',
|
||||
'54.156.140.159'
|
||||
]
|
||||
},
|
||||
whiteList: {
|
||||
'*.cn': true,
|
||||
'cn.*': true,
|
||||
|
@ -305,6 +369,7 @@ module.exports = {
|
|||
mapping: {
|
||||
'*.github.com': 'quad9',
|
||||
'*github*.com': 'quad9',
|
||||
'*.githubusercontent.com': 'quad9',
|
||||
'*.github.io': 'quad9',
|
||||
'*.docker.com': 'quad9',
|
||||
'*.stackoverflow.com': 'quad9',
|
||||
|
@ -325,7 +390,7 @@ module.exports = {
|
|||
enabled: true,
|
||||
interval: 300000,
|
||||
hostnameList: ['github.com'],
|
||||
dnsProviders: ['safe360', 'cloudflare', 'rubyfish']
|
||||
dnsProviders: ['cloudflare', 'safe360', 'rubyfish']
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
<!--
|
||||
<template>
|
||||
<a-drawer
|
||||
:title="title"
|
||||
|
@ -33,7 +34,7 @@
|
|||
</a-col>
|
||||
<a-col :span="5">
|
||||
<a-select :disabled="item.value === false" v-model="item.value">
|
||||
<a-select-option value="usa">USA DNS</a-select-option>
|
||||
<a-select-option value="cloudflare">CloudFlare DNS</a-select-option>
|
||||
<a-select-option value="aliyun">Aliyun DNS</a-select-option>
|
||||
</a-select>
|
||||
</a-col>
|
||||
|
@ -246,3 +247,4 @@ export default {
|
|||
margin-bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
-->
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
</template>
|
||||
|
||||
<div style="height: 100%" class="json-wrapper">
|
||||
|
||||
<a-tabs
|
||||
default-active-key="1"
|
||||
tab-position="left"
|
||||
|
@ -90,7 +89,12 @@
|
|||
</a-col>
|
||||
</a-row>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane tab="DNS设置" key="4">
|
||||
<a-tab-pane tab="IP预设置" key="4">
|
||||
<div>说明:IP预设置功能,需要与 `DNS设置` 或 `IP测速` 功能一起使用才会生效。</div>
|
||||
<vue-json-editor style="height:100%;margin-top:10px;" ref="editor" v-model="config.server.preSetIpList" mode="code"
|
||||
:show-btns="false" :expandedOnStart="true"></vue-json-editor>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane tab="DNS设置" key="5">
|
||||
<div>
|
||||
<a-row style="margin-top:10px">
|
||||
<a-col span="19">
|
||||
|
@ -119,7 +123,7 @@
|
|||
</a-row>
|
||||
</div>
|
||||
</a-tab-pane>
|
||||
<!-- <a-tab-pane tab="SNI" key="5">-->
|
||||
<!-- <a-tab-pane tab="SNI" key="6">-->
|
||||
<!-- <a-row style="margin-top:10px">-->
|
||||
<!-- <a-col span="19">-->
|
||||
<!-- <div>这里配置哪些域名要修改sni</div>-->
|
||||
|
@ -140,7 +144,7 @@
|
|||
<!-- </a-col>-->
|
||||
<!-- </a-row>-->
|
||||
<!-- </a-tab-pane>-->
|
||||
<a-tab-pane tab="IP测速" key="6">
|
||||
<a-tab-pane tab="IP测速" key="7">
|
||||
<div style="padding-right: 10px">
|
||||
<a-alert type="info" message="对从dns获取到的ip进行测速,使用速度最快的ip进行访问。(对使用增强功能的域名没啥用)"></a-alert>
|
||||
<a-form-item label="开启dns测速" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
|
@ -194,7 +198,7 @@
|
|||
<a-icon v-if="item.alive.length>0" type="check"/>
|
||||
<a-icon v-else type="info-circle"/>
|
||||
</a>
|
||||
<a-tag style="margin:2px;" v-for="(element,index) of item.backupList"
|
||||
<a-tag style="margin:2px;" v-for="(element,index) of item.backupList" :title="element.dns"
|
||||
:color="element.time?'green':'red'" :key='index'>{{ element.host }}
|
||||
{{ element.time }}{{ element.time ? 'ms' : '' }}
|
||||
</a-tag>
|
||||
|
@ -230,8 +234,8 @@ export default {
|
|||
key: 'server',
|
||||
dnsMappings: [],
|
||||
speedTestList: [],
|
||||
whiteList: [],
|
||||
sniList: []
|
||||
whiteList: []
|
||||
// sniList: []
|
||||
}
|
||||
},
|
||||
created () {
|
||||
|
@ -270,7 +274,7 @@ export default {
|
|||
ready () {
|
||||
this.initDnsMapping()
|
||||
this.initWhiteList()
|
||||
this.initSniList()
|
||||
// this.initSniList()
|
||||
if (this.config.server.dns.speedTest.dnsProviders) {
|
||||
this.speedDns = this.config.server.dns.speedTest.dnsProviders
|
||||
}
|
||||
|
@ -278,7 +282,7 @@ export default {
|
|||
async applyBefore () {
|
||||
this.submitDnsMapping()
|
||||
this.submitWhiteList()
|
||||
this.submitSniList()
|
||||
// this.submitSniList()
|
||||
},
|
||||
async applyAfter () {
|
||||
if (this.status.server.enabled) {
|
||||
|
@ -343,34 +347,34 @@ export default {
|
|||
this.whiteList.unshift({ key: '', value: true })
|
||||
},
|
||||
|
||||
// sniList
|
||||
initSniList () {
|
||||
this.sniList = []
|
||||
for (const key in this.config.server.sniList) {
|
||||
const value = this.config.server.sniList[key]
|
||||
this.sniList.push({
|
||||
key, value
|
||||
})
|
||||
}
|
||||
},
|
||||
submitSniList () {
|
||||
const sniList = {}
|
||||
for (const item of this.sniList) {
|
||||
if (item.key) {
|
||||
sniList[item.key] = item.value
|
||||
}
|
||||
}
|
||||
this.config.server.sniList = sniList
|
||||
},
|
||||
deleteSniList (item, index) {
|
||||
this.sniList.splice(index, 1)
|
||||
},
|
||||
restoreDefSniList (item, index) {
|
||||
|
||||
},
|
||||
addSniList () {
|
||||
this.sniList.unshift({ key: '', value: true })
|
||||
},
|
||||
// // sniList
|
||||
// initSniList () {
|
||||
// this.sniList = []
|
||||
// for (const key in this.config.server.sniList) {
|
||||
// const value = this.config.server.sniList[key]
|
||||
// this.sniList.push({
|
||||
// key, value
|
||||
// })
|
||||
// }
|
||||
// },
|
||||
// submitSniList () {
|
||||
// const sniList = {}
|
||||
// for (const item of this.sniList) {
|
||||
// if (item.key) {
|
||||
// sniList[item.key] = item.value
|
||||
// }
|
||||
// }
|
||||
// this.config.server.sniList = sniList
|
||||
// },
|
||||
// deleteSniList (item, index) {
|
||||
// this.sniList.splice(index, 1)
|
||||
// },
|
||||
// restoreDefSniList (item, index) {
|
||||
//
|
||||
// },
|
||||
// addSniList () {
|
||||
// this.sniList.unshift({ key: '', value: true })
|
||||
// },
|
||||
|
||||
async openLog () {
|
||||
const dir = await this.$api.info.getConfigDir()
|
||||
|
|
|
@ -3,57 +3,24 @@ const doh = require('dns-over-http')
|
|||
const BaseDNS = require('./base')
|
||||
const log = require('../../utils/util.log')
|
||||
const dohQueryAsync = promisify(doh.query)
|
||||
const matchUtil = require('../../utils/util.match')
|
||||
|
||||
module.exports = class DNSOverHTTPS extends BaseDNS {
|
||||
constructor (dnsServer) {
|
||||
constructor (dnsServer, preSetIpList) {
|
||||
super()
|
||||
this.dnsServer = dnsServer
|
||||
this.preSetIpList = preSetIpList
|
||||
}
|
||||
|
||||
async _lookup (hostname) {
|
||||
// 直接判断域名是否为example.com
|
||||
if (hostname === 'github.com') {
|
||||
log.info('域名github.com使用内置IP集')
|
||||
// 返回预设的IP地址集
|
||||
return ['140.82.114.4', '20.87.245.0', '20.27.177.113', '20.205.243.166', '20.248.137.48', '140.82.121.3', '140.82.116.4', '20.200.245.247', '20.26.156.215', '140.82.113.3', '140.82.121.4', '20.201.28.151']
|
||||
}
|
||||
// 直接判断域名是否为example.com
|
||||
if (hostname === 'api.github.com') {
|
||||
log.info('域名api.github.com使用内置IP集')
|
||||
// 返回预设的IP地址集
|
||||
return ['20.87.245.6', '140.82.112.5', '140.82.116.6', '20.26.156.210', '20.200.245.245', '20.27.177.116', '20.248.137.49', '20.201.28.148', '140.82.113.6', '20.205.243.168', '140.82.121.6']
|
||||
}
|
||||
if (hostname === 'codeload.github.com') {
|
||||
log.info('域名codeload.github.com使用内置IP集')
|
||||
// 返回预设的IP地址集
|
||||
return ['20.27.177.114', '140.82.116.10', '140.82.114.10', '20.26.156.216', '20.87.245.7', '20.200.245.246', '20.248.137.55', '20.205.243.165', '20.201.28.149', '140.82.121.9', '140.82.113.9']
|
||||
}
|
||||
if (hostname.match(/.*\.githubusercontent\.com$/)) {
|
||||
log.info('域名githubusercontent及其子域使用内置IP集')
|
||||
// 返回预设的IP地址集
|
||||
return ['185.199.111.133', '185.199.108.133', '185.199.109.133', '185.199.110.133']
|
||||
}
|
||||
if (hostname === 'github.githubassets.com') {
|
||||
log.info('域名github.githubassets.com使用内置IP集')
|
||||
// 返回预设的IP地址集
|
||||
return ['185.199.110.154', '185.199.111.154', '185.199.109.154', '185.199.108.154']
|
||||
}
|
||||
if (hostname === 'collector.github.com') {
|
||||
log.info('域名collector.github.com已根据AdGuard DNS filter规则拦截')
|
||||
// 返回预设的IP地址集
|
||||
return ['0.0.0.0']
|
||||
}
|
||||
if (hostname === 'github.io') {
|
||||
log.info('域名github.io使用内置IP集')
|
||||
// 返回预设的IP地址集
|
||||
return ['185.199.108.153', '185.199.109.153', '185.199.111.153', '185.199.110.153']
|
||||
}
|
||||
if (hostname === 'hub.docker.com') {
|
||||
log.info('域名hub.docker.com使用内置IP集')
|
||||
// 返回预设的IP地址集
|
||||
return ['54.156.140.159', '52.44.227.212', '44.221.37.199']
|
||||
// 获取当前域名的预设IP列表
|
||||
const hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, 'matched preSetIpList')
|
||||
if (hostnamePreSetIpList && hostnamePreSetIpList.length > 0) {
|
||||
hostnamePreSetIpList.isPreSet = true
|
||||
return hostnamePreSetIpList
|
||||
}
|
||||
|
||||
// 未预设当前域名的IP列表,则从dns服务器获取
|
||||
try {
|
||||
const result = await dohQueryAsync({ url: this.dnsServer }, [{ type: 'A', name: hostname }])
|
||||
if (result.answers.length === 0) {
|
||||
|
|
|
@ -4,7 +4,7 @@ const DNSOverIpAddress = require('./ipaddress.js')
|
|||
const matchUtil = require('../../utils/util.match')
|
||||
|
||||
module.exports = {
|
||||
initDNS (dnsProviders) {
|
||||
initDNS (dnsProviders, preSetIpList) {
|
||||
const dnsMap = {}
|
||||
for (const provider in dnsProviders) {
|
||||
const conf = dnsProviders[provider]
|
||||
|
@ -12,12 +12,18 @@ module.exports = {
|
|||
dnsMap[provider] = new DNSOverIpAddress(conf.server)
|
||||
continue
|
||||
}
|
||||
dnsMap[provider] = conf.type === 'https' ? new DNSOverHTTPS(conf.server) : new DNSOverTLS(conf.server)
|
||||
dnsMap[provider] = conf.type === 'https' ? new DNSOverHTTPS(conf.server, preSetIpList) : new DNSOverTLS(conf.server)
|
||||
}
|
||||
return dnsMap
|
||||
},
|
||||
hasDnsLookup (dnsConfig, hostname) {
|
||||
const providerName = matchUtil.matchHostname(dnsConfig.mapping, hostname, 'get dns providerName')
|
||||
let providerName = matchUtil.matchHostname(dnsConfig.mapping, hostname, 'get dns providerName')
|
||||
|
||||
// usa已重命名为cloudflare,以下为向下兼容处理
|
||||
if (providerName === 'usa') {
|
||||
providerName = 'cloudflare'
|
||||
}
|
||||
|
||||
if (providerName) {
|
||||
return dnsConfig.providers[providerName]
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ class SpeedTester {
|
|||
const one = this.getFromOneDns(dns).then(ipList => {
|
||||
if (ipList) {
|
||||
for (const ip of ipList) {
|
||||
ips[ip] = { dns: dnsKey }
|
||||
ips[ip] = { dns: ipList.isPreSet === true ? '预设IP' : dnsKey }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -48,7 +48,7 @@ module.exports = (config) => {
|
|||
host: serverConfig.host,
|
||||
port: serverConfig.port,
|
||||
dnsConfig: {
|
||||
providers: dnsUtil.initDNS(serverConfig.dns.providers),
|
||||
providers: dnsUtil.initDNS(serverConfig.dns.providers, matchUtil.domainMapRegexply(config.preSetIpList)),
|
||||
mapping: matchUtil.domainMapRegexply(dnsMapping),
|
||||
speedTest: config.dns.speedTest
|
||||
},
|
||||
|
|
|
@ -8,7 +8,7 @@ const dnsMap = dns.initDNS({
|
|||
// server: 'ipaddress',
|
||||
// cacheSize: 1000
|
||||
// },
|
||||
usa: {
|
||||
cloudflare: {
|
||||
type: 'https',
|
||||
server: 'https://1.1.1.1/dns-query',
|
||||
cacheSize: 1000
|
|
@ -6,7 +6,7 @@ const dnsProviders = dns.initDNS({
|
|||
server: 'https://dns.alidns.com/dns-query',
|
||||
cacheSize: 1000
|
||||
},
|
||||
usa: {
|
||||
cloudflare: {
|
||||
type: 'https',
|
||||
server: 'https://1.1.1.1/dns-query',
|
||||
cacheSize: 1000
|
||||
|
@ -54,24 +54,24 @@ const dnsProviders = dns.initDNS({
|
|||
|
||||
const hostname0 = 'github.com'
|
||||
// console.log('first')
|
||||
// dnsProviders.usa.lookup(hostname0)
|
||||
// dnsProviders.cloudflare.lookup(hostname0)
|
||||
console.log('test')
|
||||
dnsProviders.py233.lookup(hostname0)
|
||||
// dnsProviders.usa.lookup(hostname0)
|
||||
// dnsProviders.cloudflare.lookup(hostname0)
|
||||
// dnsProviders.ipaddress.lookup(hostname0)
|
||||
// dnsProviders.ipaddress.lookup(hostname0)
|
||||
|
||||
// const hostname = 'api.github.com'
|
||||
// dnsProviders.usa.lookup(hostname)
|
||||
// dnsProviders.cloudflare.lookup(hostname)
|
||||
|
||||
// const hostname1 = 'api.github.com'
|
||||
// dnsProviders.usa.lookup(hostname1)
|
||||
// dnsProviders.cloudflare.lookup(hostname1)
|
||||
//
|
||||
// const hostname2 = 'hk.docmirror.cn'
|
||||
// dnsProviders.usa.lookup(hostname2)
|
||||
// dnsProviders.cloudflare.lookup(hostname2)
|
||||
// const hostname3 = 'github.docmirror.cn'
|
||||
// dnsProviders.usa.lookup(hostname3)
|
||||
// dnsProviders.cloudflare.lookup(hostname3)
|
||||
// const hostname4 = 'gh.docmirror.top'
|
||||
// dnsProviders.usa.lookup(hostname4)
|
||||
// dnsProviders.cloudflare.lookup(hostname4)
|
||||
// const hostname5 = 'gh2.docmirror.top'
|
||||
// dnsProviders.usa.lookup(hostname5)
|
||||
// dnsProviders.cloudflare.lookup(hostname5)
|
||||
|
|
Loading…
Reference in New Issue