From 02b74b9a52fe17930a622b7fa5e008aecf0edf1f Mon Sep 17 00:00:00 2001 From: Dominique Da Silva Date: Sat, 9 Nov 2019 01:48:04 +0000 Subject: [PATCH] Replaced geoip-ultralight with geoip-country --- config/default.toml | 9 +++++---- lib/models/links.js | 12 +++++++----- lib/tools.js | 2 ++ routes/subscription.js | 5 +++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/config/default.toml b/config/default.toml index 9e8f065f..7b48fb7b 100644 --- a/config/default.toml +++ b/config/default.toml @@ -195,13 +195,14 @@ canvasBackgroundStyle = "bluish" canvasLabelsColor = "#4b5666" [views.template] - -showeditor = false +showeditor=false [views.lists] +statuscolored=false -statuscolored = false - +[geoip] +# Alternative directory containing the files geoip-country.dat and geoip-country6.dat +datadirectory=false [reports] # The whole reporting functionality can be disabled below if the they are not needed and the DB cannot be diff --git a/lib/models/links.js b/lib/models/links.js index e7ce5591..5650d416 100644 --- a/lib/models/links.js +++ b/lib/models/links.js @@ -5,7 +5,7 @@ let shortid = require('shortid'); let util = require('util'); let _ = require('../translate')._; -let geoip = require('geoip-ultralight'); +let geoip = require('geoip-country'); let campaigns = require('./campaigns'); let subscriptions = require('./subscriptions'); let lists = require('./lists'); @@ -57,7 +57,8 @@ module.exports.countClick = (remoteIp, useragent, campaignCid, listCid, subscrip return callback(err); } - let country = geoip.lookupCountry(remoteIp) || null; + let geodata = geoip.lookup(remoteIp); + let country = geodata && geodata.country || null; let device = ua_parser(useragent, { unknownUserAgentDeviceType: 'desktop', emptyUserAgentDeviceType: 'desktop' }); let query = 'INSERT INTO `campaign_tracker__' + data.campaign.id + '` (`list`, `subscriber`, `link`, `ip`, `device_type`, `country`) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE `count`=`count`+1'; connection.query(query, [data.list.id, data.subscription.id, linkId, remoteIp, device.type, country], (err, result) => { @@ -173,7 +174,8 @@ module.exports.countOpen = (remoteIp, useragent, campaignCid, listCid, subscript return callback(err); } - let country = geoip.lookupCountry(remoteIp) || null; + let geodata = geoip.lookup(remoteIp); + let country = geodata && geodata.country || null; let device = ua_parser(useragent, { unknownUserAgentDeviceType: 'desktop', emptyUserAgentDeviceType: 'desktop' }); let query = 'INSERT INTO `campaign_tracker__' + data.campaign.id + '` (`list`, `subscriber`, `link`, `ip`, `device_type`, `country`) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE `count`=`count`+1'; connection.query(query, [data.list.id, data.subscription.id, -1, remoteIp, device.type, country], (err, result) => { @@ -272,7 +274,7 @@ module.exports.updateLinks = (campaign, list, subscription, serviceUrl, message, // tracking is disabled, do not modify the message return setImmediate(() => callback(null, message)); } - + // insert tracking image if (!campaign.openTrackingDisabled) { let inserted = false; @@ -289,7 +291,7 @@ module.exports.updateLinks = (campaign, list, subscription, serviceUrl, message, return callback(null, message); } } - + if (!campaign.clickTrackingDisabled) { let re = /(]* href\s*=[\s"']*)(http[^"'>\s]+)/gi; let urls = new Set(); diff --git a/lib/tools.js b/lib/tools.js index 37d53e1f..ab3e8525 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -17,6 +17,8 @@ let htmlToText = require('html-to-text'); let blockedUsers = ['abuse', 'admin', 'billing', 'compliance', 'devnull', 'dns', 'ftp', 'hostmaster', 'inoc', 'ispfeedback', 'ispsupport', 'listrequest', 'list', 'maildaemon', 'noc', 'noreply', 'noreply', 'null', 'phish', 'phishing', 'postmaster', 'privacy', 'registrar', 'root', 'security', 'spam', 'support', 'sysadmin', 'tech', 'undisclosedrecipients', 'unsubscribe', 'usenet', 'uucp', 'webmaster', 'www']; +global.geodatadir = config.geoip.datadirectory || undefined; + module.exports = { toDbKey, fromDbKey, diff --git a/routes/subscription.js b/routes/subscription.js index 2693deda..a1d24644 100644 --- a/routes/subscription.js +++ b/routes/subscription.js @@ -16,7 +16,7 @@ let _ = require('../lib/translate')._; let util = require('util'); let cors = require('cors'); let cache = require('memory-cache'); -let geoip = require('geoip-ultralight'); +let geoip = require('geoip-country'); let confirmations = require('../lib/models/confirmations'); let mailHelpers = require('../lib/subscription-mail-helpers'); @@ -74,7 +74,8 @@ function checkAndExecuteConfirmation(req, action, errorMsg, next, exec) { router.get('/confirm/subscribe/:cid', (req, res, next) => { checkAndExecuteConfirmation(req, 'subscribe', 'Request invalid or already completed. If your subscription request is still pending, please subscribe again.', next, (confirmation, list) => { const data = confirmation.data; - let optInCountry = geoip.lookupCountry(confirmation.ip) || null; + let geodata = geoip.lookup(confirmation.ip); + let optInCountry = geodata && geodata.country || null; const meta = { cid: req.params.cid,