Authored by 郭成尧

done

... ... @@ -21,7 +21,8 @@ const IP_WHITE_LIST = [
'218.94.75.58', // 南京办公区域
'218.94.75.50', // 南京办公区域
'218.94.77.166', // 南京办公区域
'222.73.196.18', // B站合作方单击次数快加白名单
// '222.73.196.18', // B站合作方单击次数快加白名单
'123.206.73.107', // 腾讯云出口IP
'139.199.35.21', // 腾讯云出口IP
'139.199.29.44', // 腾讯云出口IP
... ... @@ -66,10 +67,10 @@ const _excluded = (req) => {
let remoteIpSegment = `${remoteIp.split('.').slice(0, 2).join('.')}.`;
return co(function* () {
let cacheIpWhiteList = yield ipWhiteList();
let atWhiteList = yield ipWhiteList(remoteIp);
return Boolean(
_.includes(cacheIpWhiteList, remoteIp) ||
atWhiteList ||
_.includes(IP_WHITE_LIST, remoteIp) ||
_.includes(IP_WHITE_SEGMENT, remoteIpSegment) ||
_.includes(PATH_WHITE_LIST, req.path) ||
... ...
const co = Promise.coroutine;
const logger = global.yoho.logger;
const cache = global.yoho.cache.master;
const WHITE_LIST_KEY = 'whitelist:ips';
const WHITE_LIST_KEY = 'whitelist:ip:';
module.exports = (remoteIp) => {
let key = `${WHITE_LIST_KEY}${remoteIp}`;
module.exports = () => {
return co(function* () {
let listFromCache = yield cache.getAsync(WHITE_LIST_KEY);
let result = Boolean(yield cache.getAsync(key));
logger.debug(key, result);
return Promise.resolve(JSON.parse(listFromCache) || []);
return result;
})();
};
... ...
... ... @@ -15,8 +15,15 @@ module.exports = (limiter, policy) => {
cache.getAsync(blackKey),
cache.getAsync(whiteKey)
]).then((args) => {
const blacklist = args[0] || [],
whitelist = args[1] || [];
let blacklist = [];
let whitelist = [];
try {
blacklist = JSON.parse(args[0]);
whitelist = JSON.parse(args[1]);
} catch (error) {
logger.error(error);
}
if (blacklist.length === 0 && whitelist.length === 0) {
return Promise.resolve(true);
... ...