From 2c2888fbe958136e4a8b9fd22e4f33a6fc4cca47 Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Fri, 6 Nov 2015 00:24:25 -0800 Subject: [PATCH] Use mail command instead of sendmail. --- lib/text.js | 19 +++++++++++----- server/app.js | 63 +++++++++++++++++++++++++++++---------------------- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/lib/text.js b/lib/text.js index dd6a462..818bd83 100644 --- a/lib/text.js +++ b/lib/text.js @@ -2,8 +2,11 @@ var providers = require('./providers.js') , _ = require('underscore') , exec = require('child_process').exec , spawn = require('child_process').spawn; +var StringDecoder = require('string_decoder').StringDecoder; var debugEnabled = false; + +// NOTE: Change this if you are self-hosting! var fromAddress = 'foo@bar.com'; //---------------------------------------------------------------- @@ -56,18 +59,22 @@ function sendText(phone, message, region, cb) { _.each(providers_list, function(provider) { var email = provider.replace('%s', phone); - email = 'Subject: Text\r\n\r\n' + email; - var child = spawn('sendmail', ['-f', fromAddress, email]); - child.stdout.on('data', output); - child.stderr.on('data', output); + var child = spawn('mail', ['-s', 'txt', '-a', 'From:' + fromAddress, email]); + var decoder = new StringDecoder('utf8'); + child.stdout.on('data', function(data) { + output(decoder.write(data)); + }); + child.stderr.on('data', function(data) { + output(decoder.write(data)); + }); child.on('error', function(data) { - output('sendmail failed', {email: email, data: data}); + output('sendmail failed', {email: email, data: decoder.write(data)}); done(); }); child.on('exit', function(code, signal) { done(); }); - child.stdin.write(message + '\n.'); + child.stdin.write(message + '\n'); child.stdin.end(); }); } diff --git a/server/app.js b/server/app.js index 6d39e5d..dc2c918 100644 --- a/server/app.js +++ b/server/app.js @@ -1,10 +1,10 @@ var express = require('express') , app = express() , _ = require('underscore') - , authbox = require('authbox') , crypto = require('crypto') , exec = require('child_process').exec , fs = require('fs') + , path = require('path') , mixpanel = require('mixpanel') , redis = require('redis-url').connect() , spawn = require('child_process').spawn @@ -36,9 +36,23 @@ try { banned_numbers = {BLACKLIST: {}}; } +var banned_ips = {}; +try { + var banned_list = fs.readFileSync(path.join(__dirname, './torlist')).toString('utf-8').split('\n'); + banned_list.map(function(ip) { + ip = ip.trim(); + if (ip != '') { + banned_ips[ip] = true; + } + }); + console.log(banned_list.length, 'banned ips loaded'); +} catch(e) { + console.log(e); +} + + var mpq - , mixpanel_config - , authbox_config; + , mixpanel_config; try { mixpanel_config = require('./mixpanel_config.js'); mpq = new mixpanel.Client(mixpanel_config.api_key); @@ -46,14 +60,6 @@ try { mpq = {track: function() {}}; } -try { - authbox_config = require('./authbox_config.js'); - authbox.configure(authbox_config); - app.use(authbox.middleware); -} catch(e) { - authbox = {log: function() {}}; -} - var access_keys; try { // Optionally, you may specify special access keys in a keys.json file. @@ -104,14 +110,8 @@ function textRequestHandler(req, res, number, region, key) { ip = req.header('CF-Connecting-IP'); } - var authbox_details = { - $actionName: 'text', - $ipAddress: ip - }; - if (!number || !req.body.message) { mpq.track('incomplete request', {ip: ip, ip2: ip}); - authbox.log(req, _.extend(authbox_details, {$failureReason: 'incomplete_request'})); res.send({success:false, message:'Number and message parameters are required.'}); return; } @@ -122,14 +122,28 @@ function textRequestHandler(req, res, number, region, key) { // contains a colon. message = ' ' + message; } + if (ip in banned_ips) { + // Shadowban tor ips + setTimeout(function() { + res.send({success:false}); + }, 1000); + return; + } + if (message.indexOf('IDSninja') > -1) { + setTimeout(function() { + res.send({success:true}); + }, 1000); + return; + } + if (message.indexOf('chat history has been hacked') > -1) { + setTimeout(function() { + res.send({success:true}); + }, 1000); + return; + } var shasum = crypto.createHash('sha1'); shasum.update(number); - var authbox_digest = shasum.digest('hex'); - _.extend(authbox_details, { - recipient: authbox_digest, - message__text: message - }); var tracking_details = { number: number, @@ -140,7 +154,6 @@ function textRequestHandler(req, res, number, region, key) { if (banned_numbers.BLACKLIST[number]) { mpq.track('banned number', tracking_details); - authbox.log(req, _.extend(authbox_details, {$failureReason: 'banned_number'})); res.send({success:false,message:'Sorry, texts to this number are disabled.'}); return; } @@ -152,7 +165,6 @@ function textRequestHandler(req, res, number, region, key) { text.send(number, message, region, function(err) { if (err) { mpq.track('sendText failed', tracking_details); - authbox.log(req, _.extend(authbox_details, {$failureReason: 'gateway_failed'})); res.send(_.extend(response_obj, { success:false, @@ -161,7 +173,6 @@ function textRequestHandler(req, res, number, region, key) { } else { mpq.track('sendText success', tracking_details); - authbox.log(req, _.extend(authbox_details, {$success: true})); res.send(_.extend(response_obj, {success:true})); } }); @@ -199,7 +210,6 @@ function textRequestHandler(req, res, number, region, key) { }, 1000*60*3); if (num > 3) { //mpq.track('exceeded phone quota', tracking_details); - //authbox.log(req, _.extend(authbox_details, {$failureReason: 'exceeded_phone_quota'})); res.send({success:false, message:'Exceeded quota for this phone number. ' + number}); return; } @@ -213,7 +223,6 @@ function textRequestHandler(req, res, number, region, key) { } if (num > 75) { mpq.track('exceeded ip quota', tracking_details); - authbox.log(req, _.extend(authbox_details, {$failureReason: 'exceeded_ip_quota'})); res.send({success:false, message:'Exceeded quota for this IP address. ' + ip}); return; }