Showing
3 changed files
with
22 additions
and
9 deletions
@@ -21,7 +21,8 @@ const IP_WHITE_LIST = [ | @@ -21,7 +21,8 @@ const IP_WHITE_LIST = [ | ||
21 | '218.94.75.58', // 南京办公区域 | 21 | '218.94.75.58', // 南京办公区域 |
22 | '218.94.75.50', // 南京办公区域 | 22 | '218.94.75.50', // 南京办公区域 |
23 | '218.94.77.166', // 南京办公区域 | 23 | '218.94.77.166', // 南京办公区域 |
24 | - '222.73.196.18', // B站合作方单击次数快加白名单 | 24 | + |
25 | + // '222.73.196.18', // B站合作方单击次数快加白名单 | ||
25 | '123.206.73.107', // 腾讯云出口IP | 26 | '123.206.73.107', // 腾讯云出口IP |
26 | '139.199.35.21', // 腾讯云出口IP | 27 | '139.199.35.21', // 腾讯云出口IP |
27 | '139.199.29.44', // 腾讯云出口IP | 28 | '139.199.29.44', // 腾讯云出口IP |
@@ -66,10 +67,10 @@ const _excluded = (req) => { | @@ -66,10 +67,10 @@ const _excluded = (req) => { | ||
66 | let remoteIpSegment = `${remoteIp.split('.').slice(0, 2).join('.')}.`; | 67 | let remoteIpSegment = `${remoteIp.split('.').slice(0, 2).join('.')}.`; |
67 | 68 | ||
68 | return co(function* () { | 69 | return co(function* () { |
69 | - let cacheIpWhiteList = yield ipWhiteList(); | 70 | + let atWhiteList = yield ipWhiteList(remoteIp); |
70 | 71 | ||
71 | return Boolean( | 72 | return Boolean( |
72 | - _.includes(cacheIpWhiteList, remoteIp) || | 73 | + atWhiteList || |
73 | _.includes(IP_WHITE_LIST, remoteIp) || | 74 | _.includes(IP_WHITE_LIST, remoteIp) || |
74 | _.includes(IP_WHITE_SEGMENT, remoteIpSegment) || | 75 | _.includes(IP_WHITE_SEGMENT, remoteIpSegment) || |
75 | _.includes(PATH_WHITE_LIST, req.path) || | 76 | _.includes(PATH_WHITE_LIST, req.path) || |
1 | const co = Promise.coroutine; | 1 | const co = Promise.coroutine; |
2 | +const logger = global.yoho.logger; | ||
2 | const cache = global.yoho.cache.master; | 3 | const cache = global.yoho.cache.master; |
3 | -const WHITE_LIST_KEY = 'whitelist:ips'; | 4 | +const WHITE_LIST_KEY = 'whitelist:ip:'; |
5 | + | ||
6 | +module.exports = (remoteIp) => { | ||
7 | + let key = `${WHITE_LIST_KEY}${remoteIp}`; | ||
4 | 8 | ||
5 | -module.exports = () => { | ||
6 | return co(function* () { | 9 | return co(function* () { |
7 | - let listFromCache = yield cache.getAsync(WHITE_LIST_KEY); | 10 | + let result = Boolean(yield cache.getAsync(key)); |
11 | + | ||
12 | + logger.debug(key, result); | ||
8 | 13 | ||
9 | - return Promise.resolve(JSON.parse(listFromCache) || []); | 14 | + return result; |
10 | })(); | 15 | })(); |
11 | }; | 16 | }; |
@@ -15,8 +15,15 @@ module.exports = (limiter, policy) => { | @@ -15,8 +15,15 @@ module.exports = (limiter, policy) => { | ||
15 | cache.getAsync(blackKey), | 15 | cache.getAsync(blackKey), |
16 | cache.getAsync(whiteKey) | 16 | cache.getAsync(whiteKey) |
17 | ]).then((args) => { | 17 | ]).then((args) => { |
18 | - const blacklist = args[0] || [], | ||
19 | - whitelist = args[1] || []; | 18 | + let blacklist = []; |
19 | + let whitelist = []; | ||
20 | + | ||
21 | + try { | ||
22 | + blacklist = JSON.parse(args[0]); | ||
23 | + whitelist = JSON.parse(args[1]); | ||
24 | + } catch (error) { | ||
25 | + logger.error(error); | ||
26 | + } | ||
20 | 27 | ||
21 | if (blacklist.length === 0 && whitelist.length === 0) { | 28 | if (blacklist.length === 0 && whitelist.length === 0) { |
22 | return Promise.resolve(true); | 29 | return Promise.resolve(true); |
-
Please register or login to post a comment