optimize: 在匹配拦截配置时,可匹配到多个 ‘域名匹配符’ 下的拦截配置。
parent
faf029827b
commit
0f7a258d2a
|
@ -65,7 +65,7 @@ function doDiff (oldObj, newObj) {
|
|||
|
||||
function deleteNullItems (target) {
|
||||
lodash.forEach(target, (item, key) => {
|
||||
if (item == null) {
|
||||
if (item == null || item === '[delete]') {
|
||||
delete target[key]
|
||||
}
|
||||
if (lodash.isObject(item)) {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
:style="{ height: '100%' }"
|
||||
>
|
||||
<a-tab-pane tab="拦截设置" key="1" >
|
||||
<vue-json-editor style="height:100%;" ref="editor" v-model="targetConfig.intercepts" mode="code" :show-btns="false" :expandedOnStart="true" @json-change="onJsonChange" ></vue-json-editor>
|
||||
<vue-json-editor style="height:100%;" ref="editor" v-model="targetConfig.intercepts" mode="code" :show-btns="false" :expandedOnStart="true" @json-change="onJsonChange"></vue-json-editor>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane tab="DNS设置" key="2">
|
||||
<div>
|
||||
|
|
|
@ -138,7 +138,6 @@
|
|||
<!-- <a-button type="danger" icon="minus" @click="deleteSniList(item,index)"/>-->
|
||||
<!-- </a-col>-->
|
||||
<!-- </a-row>-->
|
||||
|
||||
<!-- </a-tab-pane>-->
|
||||
<a-tab-pane tab="IP测速" key="6">
|
||||
<div>
|
||||
|
@ -201,7 +200,6 @@
|
|||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
</div>
|
||||
</a-tab-pane>
|
||||
</a-tabs>
|
||||
|
|
|
@ -18,7 +18,7 @@ function matched (hostname, overWallTargetMap) {
|
|||
log.info(`matchHostname: matched overwall: '${hostname}' -> '${ret}' in pac.txt`)
|
||||
return true
|
||||
} else {
|
||||
// log.debug(`matchHostname: matched overwall: Not-Matched '${hostname}' -> '${ret}' in pac.txt`)
|
||||
log.debug(`matchHostname: matched overwall: Not-Matched '${hostname}' -> '${ret}' in pac.txt`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ module.exports = (config) => {
|
|||
const matchInterceptsOpts = {}
|
||||
for (const regexp in interceptOpts) { // 遍历拦截配置
|
||||
const interceptOpt = interceptOpts[regexp]
|
||||
interceptOpt.key = regexp
|
||||
// interceptOpt.key = regexp
|
||||
if (regexp !== true && regexp !== 'true') {
|
||||
if (!matchUtil.isMatched(rOptions.path, regexp)) {
|
||||
continue
|
||||
|
|
|
@ -94,6 +94,16 @@ function merge (oldObj, newObj) {
|
|||
}
|
||||
})
|
||||
}
|
||||
function deleteNullItems (target) {
|
||||
lodash.forEach(target, (item, key) => {
|
||||
if (item == null || item === '[delete]') {
|
||||
delete target[key]
|
||||
}
|
||||
if (lodash.isObject(item)) {
|
||||
deleteNullItems(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function matchHostnameAll (hostMap, hostname, action) {
|
||||
// log.debug('matchHostnameAll:', action, hostMap)
|
||||
|
@ -108,29 +118,9 @@ function matchHostnameAll (hostMap, hostname, action) {
|
|||
}
|
||||
|
||||
let values = {}
|
||||
let hasValue = false
|
||||
let value
|
||||
|
||||
// 域名快速匹配:直接匹配 或者 两种前缀通配符匹配
|
||||
let value = hostMap.origin[hostname]
|
||||
if (value) {
|
||||
log.info(`matchHostnameAll: ${action}: '${hostname}' -> '${hostname}': ${JSON.stringify(value)}`)
|
||||
values = merge(values, value)
|
||||
hasValue = true
|
||||
}
|
||||
value = hostMap.origin['*' + hostname]
|
||||
if (value) {
|
||||
log.info(`matchHostnameAll: ${action}: '${hostname}' -> '*${hostname}': ${JSON.stringify(value)}`)
|
||||
values = merge(values, value)
|
||||
hasValue = true
|
||||
}
|
||||
value = hostMap.origin['*.' + hostname]
|
||||
if (value) {
|
||||
log.info(`matchHostnameAll: ${action}: '${hostname}' -> '*.${hostname}': ${JSON.stringify(value)}`)
|
||||
values = merge(values, value)
|
||||
hasValue = true
|
||||
}
|
||||
|
||||
// 通配符匹配 或 正则表达式匹配
|
||||
// 通配符匹配 或 正则表达式匹配(优先级:1,最低)
|
||||
for (const target in hostMap) {
|
||||
if (target === 'origin') {
|
||||
continue
|
||||
|
@ -149,17 +139,37 @@ function matchHostnameAll (hostMap, hostname, action) {
|
|||
// 正则表达式匹配
|
||||
if (hostname.match(regexp)) {
|
||||
value = hostMap[target]
|
||||
// log.info(`matchHostname: ${action}: '${hostname}' -> '${target}': ${JSON.stringify(value)}`)
|
||||
log.info(`matchHostnameOne: ${action}: '${hostname}' -> '${target}': ${JSON.stringify(value)}`)
|
||||
values = merge(values, value)
|
||||
hasValue = true
|
||||
}
|
||||
}
|
||||
|
||||
if (hasValue) {
|
||||
log.info(`*matchHostnameAll*: ${action}: '${hostname}':`, JSON.stringify(values))
|
||||
// 域名快速匹配:直接匹配 或者 两种前缀通配符匹配
|
||||
// 优先级:2
|
||||
value = hostMap.origin['*' + hostname]
|
||||
if (value) {
|
||||
log.info(`matchHostnameOne: ${action}: '${hostname}' -> '*${hostname}': ${JSON.stringify(value)}`)
|
||||
values = merge(values, value)
|
||||
}
|
||||
// 优先级:3
|
||||
value = hostMap.origin['*.' + hostname]
|
||||
if (value) {
|
||||
log.info(`matchHostnameOne: ${action}: '${hostname}' -> '*.${hostname}': ${JSON.stringify(value)}`)
|
||||
values = merge(values, value)
|
||||
}
|
||||
// 优先级:4,最高(注:优先级高的配置,可以覆盖优先级低的配置,甚至有空配置时,可以移除已有配置)
|
||||
value = hostMap.origin[hostname]
|
||||
if (value) {
|
||||
log.info(`matchHostnameOne: ${action}: '${hostname}' -> '${hostname}': ${JSON.stringify(value)}`)
|
||||
values = merge(values, value)
|
||||
}
|
||||
|
||||
if (!lodash.isEmpty(values)) {
|
||||
deleteNullItems(values)
|
||||
log.info(`matchHostnameAll: ${action}: '${hostname}':`, JSON.stringify(values))
|
||||
return values
|
||||
} else {
|
||||
log.debug(`*matchHostnameAll*: ${action}: '${hostname}' Not-Matched`)
|
||||
log.debug(`matchHostnameAll: ${action}: '${hostname}' Not-Matched`)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue