exports.newAndSave = newAndSave;
exports.isInBlackList = isInBlackList;
exports.getBlackListByIp = getBlackListByIp;
exports.removeBlackListByIp = removeBlackListByIp;
exports.newAndSaveOneHourTempForbidden = newAndSaveOneHourTempForbidden;
exports.newAndSaveOneDayTempForbidden = newAndSaveOneDayTempForbidden;
exports.newAndSaveForeverForbidden = newAndSaveForeverForbidden;
exports.newAndSaveTempForbidden = newAndSaveTempForbidden;
中间件详情:
复制代码 代码如下:
/**
* Created by YCXJ-wanglihui on 2014/5/28.
*/
'use strict';
var BlackListProxy = require('../../proxy').BlackListPorxy;
var IpAnswerLogProxy = require('../../proxy').IpAnswerLogProxy;
var EventProxy = require('eventproxy');
/**
* 判断是否需要将Ip移动至黑名单中
* @param req
* @param res
* @param next
*/
var isNeedMoveToBlackList = function(req, res, next){
var ip = req.ip;
//判断是否在黑名单中
requireNotInBlackList(req, res, function(){
var ep = new EventProxy();
ep.fail(next);
ep.all('minuteCount', 'hourCount', 'dayCount', function(minuteCount, hourCount, dayCount){
if(minuteCount > 10){
BlackListProxy.newAndSaveOneHourTempForbidden(ip, function(err, blackList){
if(err){
return next(err);
}else{
return res.send('提交过于频繁,1小时后重试!');
}
});
}else if(hourCount > 100){
BlackListProxy.newAndSaveOneDayTempForbidden(ip, function(err, blackList){
if(err){
return next(err);
}else{
return res.send('提交过于频繁,1天后重试!');
}
})
}else if(dayCount > 1000){
BlackListProxy.newAndSaveOneDayTempForbidden(ip, function(err, blackList){
if(err){
return next(err);
}else{
return res.send('提交过于频繁,1天后重试!');
}
})
}else{
return next();
}
})