diff --git a/appengine/cloudsql/app.js b/appengine/cloudsql/app.js index f4201e9333..0516fc7a77 100644 --- a/appengine/cloudsql/app.js +++ b/appengine/cloudsql/app.js @@ -17,6 +17,7 @@ var format = require('util').format; var express = require('express'); var mysql = require('mysql'); +var crypto = require('crypto'); var app = express(); app.enable('trust proxy'); @@ -33,11 +34,13 @@ var connection = mysql.createConnection({ }); app.get('/', function(req, res, next) { + var hash = crypto.createHash('sha256'); // Add this visit to the database var visit = { timestamp: new Date(), - userIp: req.ip + // Store a hash of the ip address + userIp: hash.update(req.ip).digest('hex').substr(0, 7) }; connection.query('INSERT INTO `visits` SET ?', visit, function(err) { @@ -52,7 +55,7 @@ app.get('/', function(req, res, next) { var visits = results.map(function(visit) { return format( - 'Time: %s, Addr: %s', + 'Time: %s, AddrHash: %s', visit.timestamp, visit.userIp); }); diff --git a/appengine/datastore/app.js b/appengine/datastore/app.js index 9e0574ee46..b68e49aa15 100644 --- a/appengine/datastore/app.js +++ b/appengine/datastore/app.js @@ -18,6 +18,7 @@ var format = require('util').format; var express = require('express'); var gcloud = require('gcloud'); +var crypto = require('crypto'); var app = express(); app.enable('trust proxy'); @@ -29,12 +30,15 @@ var dataset = gcloud.datastore.dataset({ }); app.get('/', function(req, res, next) { + var hash = crypto.createHash('sha256'); + // Add this visit to the datastore dataset.save({ key: dataset.key('visit'), data: { timestamp: new Date(), - userIp: req.ip + // Store a hash of the ip address + userIp: hash.update(req.ip).digest('hex').substr(0, 7) } }, function(err) { if (err) { return next(err); } @@ -49,7 +53,7 @@ app.get('/', function(req, res, next) { var visits = entities.map(function(entity) { return format( - 'Time: %s, Addr: %s', + 'Time: %s, AddrHash: %s', entity.data.timestamp, entity.data.userIp); }); diff --git a/appengine/disk/app.js b/appengine/disk/app.js index c085c6e0c3..60f60083c6 100644 --- a/appengine/disk/app.js +++ b/appengine/disk/app.js @@ -18,13 +18,17 @@ var fs = require('fs'); var util = require('util'); var express = require('express'); +var crypto = require('crypto'); var app = express(); app.enable('trust proxy'); app.get('/', function(req, res, next) { var instanceId = process.env.GAE_MODULE_INSTANCE || '1'; - var userIp = util.format('%s\n', req.ip); + var hash = crypto.createHash('sha256'); + // Only store a hash of the ip address + var ip = hash.update(req.ip).digest('hex').substr(0, 7); + var userIp = util.format('%s\n', ip); fs.appendFile('/tmp/seen.txt', userIp, function(err) { if (err) { return next(err); } diff --git a/appengine/express-memcached-session/server.js b/appengine/express-memcached-session/server.js index fe13133b8e..eff12bc457 100644 --- a/appengine/express-memcached-session/server.js +++ b/appengine/express-memcached-session/server.js @@ -18,6 +18,7 @@ var session = require('express-session'); var cookieParser = require('cookie-parser'); var MemcachedStore = require('connect-memcached')(session); var publicIp = require('public-ip'); +var crypto = require('crypto'); var app = express(); @@ -33,9 +34,10 @@ app.use(session({ app.get('/', function(req, res){ publicIp.v4(function (err, ip) { + var hash = crypto.createHash('sha256'); - // This shows the IP for each - res.write('
' + ip + '
'); + // This shows the hashed IP for each + res.write('
' + hash.update(ip).digest('hex').substr(0, 7) + '
'); if(req.session.views) { ++req.session.views;