Filter ping payload

main
Elbert Alias 4 years ago
parent 9575493057
commit 4b53c4af1b

@ -263,12 +263,12 @@ const Driver = {
return return
} }
const { hostname } = new URL(url) const { protocol, hostname } = new URL(url)
// Cache detections // Cache detections
const cache = (Driver.cache.hostnames[hostname] = { const cache = (Driver.cache.hostnames[hostname] = {
...(Driver.cache.hostnames[hostname] || { ...(Driver.cache.hostnames[hostname] || {
url, url: `${protocol}//${hostname}`,
detections: [], detections: [],
hits: incrementHits ? 0 : 1 hits: incrementHits ? 0 : 1
}), }),
@ -508,25 +508,22 @@ const Driver = {
agent === 'chrome' || (await getOption('termsAccepted', false)) agent === 'chrome' || (await getOption('termsAccepted', false))
if (tracking && termsAccepted) { if (tracking && termsAccepted) {
const count = Object.keys(Driver.cache.hostnames).length const hostnames = Object.keys(Driver.cache.hostnames).reduce(
(hostnames, hostname) => {
// eslint-disable-next-line standard/computed-property-even-spacing
const { url, language, detections, hits } = Driver.cache.hostnames[
hostname
]
if (count && (count >= 50 || Driver.lastPing < Date.now() - expiry)) {
await Driver.post(
'https://api.wappalyzer.com/ping/v1/',
Object.keys(Driver.cache.hostnames).reduce((hostnames, hostname) => {
if ( if (
/((local|dev(elopment)?|stag(e|ing)?|test(ing)?|demo(shop)?|admin|google|cache)\.|\/admin|\.local)/.test( /((local|dev(elopment)?|stag(e|ing)?|test(ing)?|demo(shop)?|admin|google|cache)\.|\/admin|\.local)/.test(
hostname hostname
) ) ||
hits < 3
) { ) {
return return
} }
// eslint-disable-next-line standard/computed-property-even-spacing
const { url, language, detections, hits } = Driver.cache.hostnames[
hostname
]
hostnames[url] = hostnames[url] || { hostnames[url] = hostnames[url] || {
applications: resolve(detections).reduce( applications: resolve(detections).reduce(
(technologies, { name, confidence, version }) => { (technologies, { name, confidence, version }) => {
@ -547,9 +544,15 @@ const Driver = {
} }
return hostnames return hostnames
}, {}) },
{}
) )
const count = Object.keys(hostnames).length
if (count && (count >= 50 || Driver.lastPing < Date.now() - expiry)) {
await Driver.post('https://api.wappalyzer.com/ping/v1/', hostnames)
await setOption('hostnames', (Driver.cache.hostnames = {})) await setOption('hostnames', (Driver.cache.hostnames = {}))
Driver.lastPing = Date.now() Driver.lastPing = Date.now()

Loading…
Cancel
Save