From 9899b3d291ebff1f3f33f30b216e6e7156779144 Mon Sep 17 00:00:00 2001 From: Onur Alp Soner Date: Sat, 9 Aug 2014 11:13:34 +0300 Subject: [PATCH] Closes #81 --- api/api.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/api/api.js b/api/api.js index 63c4b388d15..fbfe954844e 100644 --- a/api/api.js +++ b/api/api.js @@ -117,6 +117,13 @@ function validateUserForMgmtReadAPI(callback, params) { }); } +function getIpAddress(req) { + var ipAddress = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress; + + /* Since x-forwarded-for: client, proxy1, proxy2, proxy3 */ + return ipAddress.split(',')[0]; +} + if (cluster.isMaster) { var workerCount = (common.config.api.workers)? common.config.api.workers : os.cpus().length; @@ -297,9 +304,7 @@ if (cluster.isMaster) { } case '/i': { - var ipAddress = req.headers['x-forwarded-for'] || req.connection.remoteAddress; - - params.ip_address = params.qstring.ip_address || ipAddress.split(",")[0]; + params.ip_address = getIpAddress(req); params.user = { 'country':'Unknown', 'city':'Unknown'