Fix IP rate limiting. Use the correct IP address. Use fewer mixpanel

events.
This commit is contained in:
Ian Webster 2013-11-13 10:32:04 -08:00
parent bc087b8cc2
commit cca5d7c462

22
app.js
View File

@ -40,9 +40,7 @@ app.post('/text', function(req, res) {
return; return;
} }
var ip = req.headers['X-Real-IP'] || req.connection.remoteAddress; var ip = req.header('X-Real-IP');// || req.connection.remoteAddress;
mpq.track('text',
{number: req.body.number, message: req.body.message, ip: ip});
var number = stripPhone(req.body.number); var number = stripPhone(req.body.number);
if (number.length < 9 || number.length > 10) { if (number.length < 9 || number.length > 10) {
@ -70,7 +68,7 @@ app.post('/text', function(req, res) {
}, 1000*60*3); }, 1000*60*3);
if (num > 3) { if (num > 3) {
mpq.track('exceeded phone quota'); mpq.track('exceeded phone quota');
res.send({success:false,message:'Exceeded quota for this phone number.'}); res.send({success:false,message:'Exceeded quota for this phone number. ' + number});
return; return;
} }
@ -81,21 +79,27 @@ app.post('/text', function(req, res) {
res.send({success:false,message:'Could not validate IP quota.'}); res.send({success:false,message:'Could not validate IP quota.'});
return; return;
} }
/*
if (num > 75) { if (num > 75) {
mpq.track('exceeded ip quota'); mpq.track('exceeded ip quota');
res.send({success:false,message:'Exceeded quota for this IP address.'}); res.send({success:false,message:'Exceeded quota for this IP address. ' + ip});
return; return;
} }
*/ setTimeout(function() {
redis.decr(ipkey, function(err, num) {
if (err) {
mpq.track('failed to decr ip key', {ipkey: ipkey});
console.log('*** WARNING failed to decr ' + ipkey);
}
});
}, 1000*60*60*24);
sendText(req.body.number, req.body.message, function(err) { sendText(req.body.number, req.body.message, function(err) {
if (err) { if (err) {
mpq.track('sendText failed'); mpq.track('sendText failed', {number: req.body.number, message: req.body.message, ip: ip});
res.send({success:false,message:'Communication with SMS gateway failed.'}); res.send({success:false,message:'Communication with SMS gateway failed.'});
} }
else { else {
mpq.track('sendText success'); mpq.track('sendText success', {number: req.body.number, message: req.body.message, ip: ip});
res.send({success:true}); res.send({success:true});
} }
}); });