恢复预设IP功能
parent
4097a34c78
commit
4e56d4dc2c
|
@ -84,7 +84,7 @@ module.exports = class BaseDNS {
|
||||||
|
|
||||||
async _lookupInternal (hostname) {
|
async _lookupInternal (hostname) {
|
||||||
// 获取当前域名的预设IP列表
|
// 获取当前域名的预设IP列表
|
||||||
let hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, 'matched preSetIpList')
|
let hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, `matched preSetIpList(${this.dnsName})`)
|
||||||
if (hostnamePreSetIpList && (hostnamePreSetIpList.length > 0 || hostnamePreSetIpList.length === undefined)) {
|
if (hostnamePreSetIpList && (hostnamePreSetIpList.length > 0 || hostnamePreSetIpList.length === undefined)) {
|
||||||
if (hostnamePreSetIpList.length > 0) {
|
if (hostnamePreSetIpList.length > 0) {
|
||||||
hostnamePreSetIpList = hostnamePreSetIpList.slice()
|
hostnamePreSetIpList = hostnamePreSetIpList.slice()
|
||||||
|
|
|
@ -68,16 +68,14 @@ module.exports = {
|
||||||
return dnsMap
|
return dnsMap
|
||||||
},
|
},
|
||||||
hasDnsLookup (dnsConfig, hostname) {
|
hasDnsLookup (dnsConfig, hostname) {
|
||||||
let providerName = null
|
|
||||||
|
|
||||||
// 先匹配 预设IP配置
|
// 先匹配 预设IP配置
|
||||||
const hostnamePreSetIpList = matchUtil.matchHostname(dnsConfig.preSetIpList, hostname, 'matched preSetIpList')
|
const hostnamePreSetIpList = matchUtil.matchHostname(dnsConfig.preSetIpList, hostname, 'matched preSetIpList(hasDnsLookup)')
|
||||||
if (hostnamePreSetIpList) {
|
if (hostnamePreSetIpList) {
|
||||||
return dnsConfig.dnsMap.PreSet
|
return dnsConfig.dnsMap.PreSet
|
||||||
}
|
}
|
||||||
|
|
||||||
// 再匹配 DNS映射配置
|
// 再匹配 DNS映射配置
|
||||||
providerName = matchUtil.matchHostname(dnsConfig.mapping, hostname, 'get dns providerName')
|
const providerName = matchUtil.matchHostname(dnsConfig.mapping, hostname, 'get dns providerName')
|
||||||
|
|
||||||
// 由于DNS中的usa已重命名为cloudflare,所以做以下处理,为了向下兼容
|
// 由于DNS中的usa已重命名为cloudflare,所以做以下处理,为了向下兼容
|
||||||
if (providerName === 'usa' && dnsConfig.dnsMap.usa == null && dnsConfig.dnsMap.cloudflare != null) {
|
if (providerName === 'usa' && dnsConfig.dnsMap.usa == null && dnsConfig.dnsMap.cloudflare != null) {
|
||||||
|
|
|
@ -1,40 +1,13 @@
|
||||||
const matchUtil = require('../../utils/util.match')
|
|
||||||
const BaseDNS = require('./base')
|
const BaseDNS = require('./base')
|
||||||
|
|
||||||
function mapToList (ipMap) {
|
|
||||||
const ipList = []
|
|
||||||
for (const key in ipMap) {
|
|
||||||
if (ipMap[key]) { // 配置为 ture 时才生效
|
|
||||||
ipList.push(key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ipList
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = class DNSOverPreSetIpList extends BaseDNS {
|
module.exports = class DNSOverPreSetIpList extends BaseDNS {
|
||||||
constructor (preSetIpList) {
|
constructor (preSetIpList) {
|
||||||
super()
|
super('PreSet', null, preSetIpList)
|
||||||
this.preSetIpList = preSetIpList
|
|
||||||
this.name = 'PreSet'
|
this.name = 'PreSet'
|
||||||
this.type = 'PreSet'
|
this.type = 'PreSet'
|
||||||
}
|
}
|
||||||
|
|
||||||
async _lookup (hostname) {
|
async _lookup (_hostname) {
|
||||||
// 获取当前域名的预设IP列表
|
|
||||||
let hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, 'matched preSetIpList')
|
|
||||||
if (hostnamePreSetIpList && (hostnamePreSetIpList.length > 0 || hostnamePreSetIpList.length === undefined)) {
|
|
||||||
if (hostnamePreSetIpList.length > 0) {
|
|
||||||
hostnamePreSetIpList = hostnamePreSetIpList.slice()
|
|
||||||
} else {
|
|
||||||
hostnamePreSetIpList = mapToList(hostnamePreSetIpList)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hostnamePreSetIpList.length > 0) {
|
|
||||||
return hostnamePreSetIpList
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 未预设当前域名的IP列表
|
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ class SpeedTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFromOneDns (dns) {
|
async getFromOneDns (dns) {
|
||||||
return await dns._lookup(this.hostname)
|
return await dns._lookupInternal(this.hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
async test () {
|
async test () {
|
||||||
|
|
Loading…
Reference in New Issue