From d8d4e0beebe3b0bb8d6d29900cf49179b90828c9 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 8 Jun 2023 09:06:06 +0200 Subject: [PATCH] [Assist] added city and state support for geo extractor (#1314) * feat(assist): added support for city and state extraction from GeoLite.db * feat(assist): added new fields to base session info structure --- assist/Dockerfile | 2 +- assist/utils/assistHelper.js | 10 ++++++++-- ee/assist/Dockerfile | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/assist/Dockerfile b/assist/Dockerfile index 4a655996a..2f424414d 100644 --- a/assist/Dockerfile +++ b/assist/Dockerfile @@ -16,7 +16,7 @@ COPY . . RUN adduser -u 1001 openreplay -D USER 1001 -ADD --chown=1001 https://static.openreplay.com/geoip/GeoLite2-Country.mmdb $MAXMINDDB_FILE +ADD --chown=1001 https://static.openreplay.com/geoip/GeoLite2-City.mmdb $MAXMINDDB_FILE ENTRYPOINT ["/sbin/tini", "--"] CMD npm start \ No newline at end of file diff --git a/assist/utils/assistHelper.js b/assist/utils/assistHelper.js index ece1ea0f3..dc5444940 100644 --- a/assist/utils/assistHelper.js +++ b/assist/utils/assistHelper.js @@ -43,6 +43,8 @@ const BASE_sessionInfo = { "userDevice": "", "userDeviceType": "", "userCountry": "", + "userState": "", + "userCity": "", "projectId": 0 }; @@ -61,13 +63,17 @@ const extractSessionInfo = function (socket) { socket.handshake.query.sessionInfo.userDevice = ua.device.model || null; socket.handshake.query.sessionInfo.userDeviceType = ua.device.type || 'desktop'; socket.handshake.query.sessionInfo.userCountry = null; + socket.handshake.query.sessionInfo.userState = null; + socket.handshake.query.sessionInfo.userCity = null; if (geoip() !== null) { debug && console.log(`looking for location of ${socket.handshake.headers['x-forwarded-for'] || socket.handshake.address}`); try { let ip = socket.handshake.headers['x-forwarded-for'] || socket.handshake.address; ip = ip.split(",")[0]; - let country = geoip().country(ip); - socket.handshake.query.sessionInfo.userCountry = country.country.isoCode; + let info = geoip().city(ip); + socket.handshake.query.sessionInfo.userCountry = info.country.isoCode; + socket.handshake.query.sessionInfo.userCity = info.city.names.en; + socket.handshake.query.sessionInfo.userState = info.subdivisions.length > 0 ? info.subdivisions[0].names.en : null; } catch (e) { debug && console.log("geoip-country failed"); debug && console.log(e); diff --git a/ee/assist/Dockerfile b/ee/assist/Dockerfile index fe42cfc62..a8923012e 100644 --- a/ee/assist/Dockerfile +++ b/ee/assist/Dockerfile @@ -16,7 +16,7 @@ COPY . . RUN adduser -u 1001 openreplay -D USER 1001 -ADD --chown=1001 https://static.openreplay.com/geoip/GeoLite2-Country.mmdb $MAXMINDDB_FILE +ADD --chown=1001 https://static.openreplay.com/geoip/GeoLite2-City.mmdb $MAXMINDDB_FILE ENTRYPOINT ["/sbin/tini", "--"] CMD npm start \ No newline at end of file