Get client ip address correctly

This commit is contained in:
Pavel Djundik 2017-10-12 10:57:25 +03:00
parent c2f1edcbde
commit 280eea970a

View File

@ -181,11 +181,11 @@ module.exports = function() {
return server; return server;
}; };
function getClientIp(request) { function getClientIp(socket) {
let ip = request.connection.remoteAddress; let ip = socket.handshake.address;
if (Helper.config.reverseProxy) { if (Helper.config.reverseProxy) {
const forwarded = (request.headers["x-forwarded-for"] || "").split(/\s*,\s*/).filter(Boolean); const forwarded = (socket.request.headers["x-forwarded-for"] || "").split(/\s*,\s*/).filter(Boolean);
if (forwarded.length && net.isIP(forwarded[0])) { if (forwarded.length && net.isIP(forwarded[0])) {
ip = forwarded[0]; ip = forwarded[0];
@ -458,7 +458,7 @@ function initializeClient(socket, client, token, lastMessage) {
client.generateToken((newToken) => { client.generateToken((newToken) => {
token = newToken; token = newToken;
client.updateSession(token, getClientIp(socket.request), socket.request); client.updateSession(token, getClientIp(socket), socket.request);
sendInitEvent(token); sendInitEvent(token);
}); });
@ -474,7 +474,7 @@ function performAuthentication(data) {
const finalInit = () => initializeClient(socket, client, data.token || null, data.lastMessage || -1); const finalInit = () => initializeClient(socket, client, data.token || null, data.lastMessage || -1);
const initClient = () => { const initClient = () => {
client.ip = getClientIp(socket.request); client.ip = getClientIp(socket);
// If webirc is enabled perform reverse dns lookup // If webirc is enabled perform reverse dns lookup
if (Helper.config.webirc === null) { if (Helper.config.webirc === null) {
@ -523,7 +523,7 @@ function performAuthentication(data) {
// We have found an existing user and client has provided a token // We have found an existing user and client has provided a token
if (client && data.token && typeof client.config.sessions[data.token] !== "undefined") { if (client && data.token && typeof client.config.sessions[data.token] !== "undefined") {
client.updateSession(data.token, getClientIp(socket.request), socket.request); client.updateSession(data.token, getClientIp(socket), socket.request);
authCallback(true); authCallback(true);
return; return;