replaced fxa-geodb with load balancer header
This commit is contained in:
parent
7d35e8f61f
commit
8ad4597114
68
package-lock.json
generated
68
package-lock.json
generated
@ -2380,11 +2380,6 @@
|
|||||||
"tweetnacl": "^0.14.3"
|
"tweetnacl": "^0.14.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"big-integer": {
|
|
||||||
"version": "1.6.48",
|
|
||||||
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.48.tgz",
|
|
||||||
"integrity": "sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w=="
|
|
||||||
},
|
|
||||||
"big.js": {
|
"big.js": {
|
||||||
"version": "5.2.2",
|
"version": "5.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz",
|
||||||
@ -2437,11 +2432,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bluebird": {
|
|
||||||
"version": "3.5.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.2.tgz",
|
|
||||||
"integrity": "sha512-dhHTWMI7kMx5whMQntl7Vr9C6BvV10lFXDAasnqnrMYhXVCzzk6IO9Fo2L75jXHT07WrOngL1WDXOp+yYS91Yg=="
|
|
||||||
},
|
|
||||||
"bn.js": {
|
"bn.js": {
|
||||||
"version": "4.11.8",
|
"version": "4.11.8",
|
||||||
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
|
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
|
||||||
@ -3621,14 +3611,6 @@
|
|||||||
"sha.js": "^2.4.8"
|
"sha.js": "^2.4.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cron": {
|
|
||||||
"version": "1.5.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/cron/-/cron-1.5.0.tgz",
|
|
||||||
"integrity": "sha512-j7zMFLrcSta53xqOvETUt8ge+PM14GtF47gEGJJeVlM6qP24/eWHSgtiWiEiKBR2sHS8xZaBQZq4D7vFXg8dcQ==",
|
|
||||||
"requires": {
|
|
||||||
"moment-timezone": "^0.5.x"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"cross-env": {
|
"cross-env": {
|
||||||
"version": "6.0.3",
|
"version": "6.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/cross-env/-/cross-env-6.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/cross-env/-/cross-env-6.0.3.tgz",
|
||||||
@ -6854,34 +6836,6 @@
|
|||||||
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
|
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"fxa-geodb": {
|
|
||||||
"version": "1.0.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/fxa-geodb/-/fxa-geodb-1.0.4.tgz",
|
|
||||||
"integrity": "sha512-f+uNgA+6OxmLAHhZvMztwPrByhkaVmSrKcb5Q1TI7Zz/onSQPYCJs388are7nWQdXI94pncqmSPxmT9kOUllEA==",
|
|
||||||
"requires": {
|
|
||||||
"bluebird": "3.5.2",
|
|
||||||
"cron": "1.5.0",
|
|
||||||
"maxmind": "2.8.0",
|
|
||||||
"mkdirp": "0.5.1",
|
|
||||||
"mozlog": "2.2.0",
|
|
||||||
"request": "2.88.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"minimist": {
|
|
||||||
"version": "0.0.8",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
|
|
||||||
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
|
|
||||||
},
|
|
||||||
"mkdirp": {
|
|
||||||
"version": "0.5.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
|
||||||
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
|
||||||
"requires": {
|
|
||||||
"minimist": "0.0.8"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"gaxios": {
|
"gaxios": {
|
||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/gaxios/-/gaxios-3.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/gaxios/-/gaxios-3.0.3.tgz",
|
||||||
@ -9734,15 +9688,6 @@
|
|||||||
"integrity": "sha512-APMBEanjybaPzUrfqU0IMU5I0AswKMH7k8OTLs0vvV4KZpExkTkY87nR/zpbuTPj+gARop7aGUbl11pnDfW6xg==",
|
"integrity": "sha512-APMBEanjybaPzUrfqU0IMU5I0AswKMH7k8OTLs0vvV4KZpExkTkY87nR/zpbuTPj+gARop7aGUbl11pnDfW6xg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"maxmind": {
|
|
||||||
"version": "2.8.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/maxmind/-/maxmind-2.8.0.tgz",
|
|
||||||
"integrity": "sha512-U3/jQRUoMf4pQ/Tm7JNtGRaM9z82fATB2TiGgs0kEKMPZn/UbOnlyGMRItJ2+KWrwjz9a7PqRzy3/haq9XfUOQ==",
|
|
||||||
"requires": {
|
|
||||||
"big-integer": "^1.6.31",
|
|
||||||
"tiny-lru": "^1.6.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"md5.js": {
|
"md5.js": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
|
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
|
||||||
@ -10300,14 +10245,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz",
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz",
|
||||||
"integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg=="
|
"integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg=="
|
||||||
},
|
},
|
||||||
"moment-timezone": {
|
|
||||||
"version": "0.5.28",
|
|
||||||
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.28.tgz",
|
|
||||||
"integrity": "sha512-TDJkZvAyKIVWg5EtVqRzU97w0Rb0YVbfpqyjgu6GwXCAohVRqwZjf4fOzDE6p1Ch98Sro/8hQQi65WDXW5STPw==",
|
|
||||||
"requires": {
|
|
||||||
"moment": ">= 2.9.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"morgan": {
|
"morgan": {
|
||||||
"version": "1.10.0",
|
"version": "1.10.0",
|
||||||
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz",
|
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz",
|
||||||
@ -15805,11 +15742,6 @@
|
|||||||
"integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=",
|
"integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"tiny-lru": {
|
|
||||||
"version": "1.6.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/tiny-lru/-/tiny-lru-1.6.4.tgz",
|
|
||||||
"integrity": "sha512-Et+J3Css66XPSLWjLF9wmgbECsGiExlEL+jxsFerTQF6N6dpxswDTPAfIrAbQKO5c1uhgq2xvo5zMk1W+kBDNA=="
|
|
||||||
},
|
|
||||||
"tmp": {
|
"tmp": {
|
||||||
"version": "0.0.33",
|
"version": "0.0.33",
|
||||||
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz",
|
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz",
|
||||||
|
@ -142,7 +142,6 @@
|
|||||||
"configstore": "github:dannycoates/configstore#master",
|
"configstore": "github:dannycoates/configstore#master",
|
||||||
"convict": "^5.2.0",
|
"convict": "^5.2.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"fxa-geodb": "^1.0.4",
|
|
||||||
"helmet": "^3.21.2",
|
"helmet": "^3.21.2",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"mozlog": "^2.2.0",
|
"mozlog": "^2.2.0",
|
||||||
|
@ -3,10 +3,6 @@ const fetch = require('node-fetch');
|
|||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
const pkg = require('../package.json');
|
const pkg = require('../package.json');
|
||||||
|
|
||||||
const geoip = config.ip_db
|
|
||||||
? require('fxa-geodb')({ dbPath: config.ip_db })
|
|
||||||
: () => ({});
|
|
||||||
|
|
||||||
const HOUR = 1000 * 60 * 60;
|
const HOUR = 1000 * 60 * 60;
|
||||||
|
|
||||||
function truncateToHour(timestamp) {
|
function truncateToHour(timestamp) {
|
||||||
@ -24,20 +20,11 @@ function userId(fileId, ownerId) {
|
|||||||
return hash.digest('hex').substring(32);
|
return hash.digest('hex').substring(32);
|
||||||
}
|
}
|
||||||
|
|
||||||
function location(ip) {
|
|
||||||
try {
|
|
||||||
return geoip(ip);
|
|
||||||
} catch (e) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function statUploadEvent(data) {
|
function statUploadEvent(data) {
|
||||||
const loc = location(data.ip);
|
|
||||||
const event = {
|
const event = {
|
||||||
session_id: -1,
|
session_id: -1,
|
||||||
country: loc.country,
|
country: data.country,
|
||||||
region: loc.state,
|
region: data.state,
|
||||||
user_id: userId(data.id, data.owner),
|
user_id: userId(data.id, data.owner),
|
||||||
app_version: pkg.version,
|
app_version: pkg.version,
|
||||||
time: truncateToHour(Date.now()),
|
time: truncateToHour(Date.now()),
|
||||||
@ -57,11 +44,10 @@ function statUploadEvent(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function statDownloadEvent(data) {
|
function statDownloadEvent(data) {
|
||||||
const loc = location(data.ip);
|
|
||||||
const event = {
|
const event = {
|
||||||
session_id: -1,
|
session_id: -1,
|
||||||
country: loc.country,
|
country: data.country,
|
||||||
region: loc.state,
|
region: data.state,
|
||||||
user_id: userId(data.id, data.owner),
|
user_id: userId(data.id, data.owner),
|
||||||
app_version: pkg.version,
|
app_version: pkg.version,
|
||||||
time: truncateToHour(Date.now()),
|
time: truncateToHour(Date.now()),
|
||||||
@ -77,11 +63,10 @@ function statDownloadEvent(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function statDeleteEvent(data) {
|
function statDeleteEvent(data) {
|
||||||
const loc = location(data.ip);
|
|
||||||
const event = {
|
const event = {
|
||||||
session_id: -1,
|
session_id: -1,
|
||||||
country: loc.country,
|
country: data.country,
|
||||||
region: loc.state,
|
region: data.state,
|
||||||
user_id: userId(data.id, data.owner),
|
user_id: userId(data.id, data.owner),
|
||||||
app_version: pkg.version,
|
app_version: pkg.version,
|
||||||
time: truncateToHour(Date.now()),
|
time: truncateToHour(Date.now()),
|
||||||
@ -97,11 +82,10 @@ function statDeleteEvent(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function statReportEvent(data) {
|
function statReportEvent(data) {
|
||||||
const loc = location(data.ip);
|
|
||||||
const event = {
|
const event = {
|
||||||
session_id: -1,
|
session_id: -1,
|
||||||
country: loc.country,
|
country: data.country,
|
||||||
region: loc.state,
|
region: data.state,
|
||||||
user_id: userId(data.id, data.owner),
|
user_id: userId(data.id, data.owner),
|
||||||
app_version: pkg.version,
|
app_version: pkg.version,
|
||||||
time: truncateToHour(Date.now()),
|
time: truncateToHour(Date.now()),
|
||||||
@ -118,8 +102,16 @@ function statReportEvent(data) {
|
|||||||
return sendBatch([event]);
|
return sendBatch([event]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function clientEvent(event, ua, language, session_id, deltaT, platform, ip) {
|
function clientEvent(
|
||||||
const loc = location(ip);
|
event,
|
||||||
|
ua,
|
||||||
|
language,
|
||||||
|
session_id,
|
||||||
|
deltaT,
|
||||||
|
platform,
|
||||||
|
country,
|
||||||
|
state
|
||||||
|
) {
|
||||||
const ep = event.event_properties || {};
|
const ep = event.event_properties || {};
|
||||||
const up = event.user_properties || {};
|
const up = event.user_properties || {};
|
||||||
const event_properties = {
|
const event_properties = {
|
||||||
@ -155,7 +147,7 @@ function clientEvent(event, ua, language, session_id, deltaT, platform, ip) {
|
|||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
app_version: pkg.version,
|
app_version: pkg.version,
|
||||||
country: loc.country,
|
country: country,
|
||||||
device_id: event.device_id,
|
device_id: event.device_id,
|
||||||
event_properties,
|
event_properties,
|
||||||
event_type: event.event_type,
|
event_type: event.event_type,
|
||||||
@ -163,7 +155,7 @@ function clientEvent(event, ua, language, session_id, deltaT, platform, ip) {
|
|||||||
os_name: ua.os.name,
|
os_name: ua.os.name,
|
||||||
os_version: ua.os.version,
|
os_version: ua.os.version,
|
||||||
platform,
|
platform,
|
||||||
region: loc.state,
|
region: state,
|
||||||
session_id,
|
session_id,
|
||||||
time: event.time + deltaT,
|
time: event.time + deltaT,
|
||||||
user_id: event.user_id,
|
user_id: event.user_id,
|
||||||
|
@ -11,6 +11,8 @@ module.exports = async function(req, res) {
|
|||||||
statDeleteEvent({
|
statDeleteEvent({
|
||||||
id,
|
id,
|
||||||
ip: req.ip,
|
ip: req.ip,
|
||||||
|
country: req.geo.country,
|
||||||
|
state: req.geo.state,
|
||||||
owner: meta.owner,
|
owner: meta.owner,
|
||||||
download_count: meta.dl,
|
download_count: meta.dl,
|
||||||
ttl,
|
ttl,
|
||||||
|
@ -31,6 +31,8 @@ module.exports = async function(req, res) {
|
|||||||
statDownloadEvent({
|
statDownloadEvent({
|
||||||
id,
|
id,
|
||||||
ip: req.ip,
|
ip: req.ip,
|
||||||
|
country: req.geo.country,
|
||||||
|
state: req.geo.state,
|
||||||
owner: meta.owner,
|
owner: meta.owner,
|
||||||
download_count: dl,
|
download_count: dl,
|
||||||
ttl,
|
ttl,
|
||||||
|
@ -93,6 +93,19 @@ module.exports = function(app) {
|
|||||||
);
|
);
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
app.use(function(req, res, next) {
|
||||||
|
try {
|
||||||
|
// set by the load balancer
|
||||||
|
const [country, state] = req.header('X-Client-Geo-Location').split(',');
|
||||||
|
req.geo = {
|
||||||
|
country,
|
||||||
|
state
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
req.geo = {};
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(bodyParser.text());
|
app.use(bodyParser.text());
|
||||||
app.get('/', language, pages.index);
|
app.get('/', language, pages.index);
|
||||||
|
@ -12,7 +12,8 @@ module.exports = async function(req, res) {
|
|||||||
data.session_id + deltaT,
|
data.session_id + deltaT,
|
||||||
deltaT,
|
deltaT,
|
||||||
data.platform,
|
data.platform,
|
||||||
req.ip
|
req.geo.country,
|
||||||
|
req.geo.state
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
const status = await sendBatch(events);
|
const status = await sendBatch(events);
|
||||||
|
@ -9,6 +9,8 @@ module.exports = async function(req, res) {
|
|||||||
statReportEvent({
|
statReportEvent({
|
||||||
id,
|
id,
|
||||||
ip: req.ip,
|
ip: req.ip,
|
||||||
|
country: req.geo.country,
|
||||||
|
state: req.geo.state,
|
||||||
owner: meta.owner,
|
owner: meta.owner,
|
||||||
reason: req.body.reason,
|
reason: req.body.reason,
|
||||||
download_limit: meta.dlimit,
|
download_limit: meta.dlimit,
|
||||||
|
@ -111,6 +111,8 @@ module.exports = function(ws, req) {
|
|||||||
statUploadEvent({
|
statUploadEvent({
|
||||||
id: newId,
|
id: newId,
|
||||||
ip: req.ip,
|
ip: req.ip,
|
||||||
|
country: req.geo.country,
|
||||||
|
state: req.geo.state,
|
||||||
owner,
|
owner,
|
||||||
dlimit,
|
dlimit,
|
||||||
timeLimit,
|
timeLimit,
|
||||||
|
Loading…
Reference in New Issue
Block a user