From c9bf9011976586fbe9c2ecbf7cfe07c7a8058812 Mon Sep 17 00:00:00 2001 From: hahnmichaelf Date: Fri, 14 Sep 2018 20:30:05 -0400 Subject: [PATCH 1/2] Fix for category/subcategory updates --- src/app.js | 19 +++++++++++++------ src/scripts/update.js | 10 +++++++--- src/utils/db.js | 7 ++++++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/app.js b/src/app.js index 2fe10447..ca9fa2d0 100644 --- a/src/app.js +++ b/src/app.js @@ -16,12 +16,19 @@ module.exports.check = (input) => { } module.exports.update = async () => { - if(config.lookups.DNS.IP.enabled || config.lookups.DNS.NS.enabled || config.lookups.HTTP.enabled) { - debug("Spawning update process..."); - const updateProcess = fork(path.join(__dirname,'scripts/update.js')); - updateProcess.on('message', data => db.write(data.url,data)); - updateProcess.on('exit', () => setTimeout(() => this.update(),config.interval.cacheRenewCheck)); - } + /* Create and write to cache.db */ + debug("Spawning update process..."); + const updateProcess = fork(path.join(__dirname,'scripts/update.js')); + debug("Writing to cache.db") + updateProcess.on('message', data => db.write(data.url,data)); + + /* After db is initially written, write the cache.db every cacheRenewCheck-defined period */ + updateProcess.on('exit', () => { + debug("UpdateProcess completed - Next run is in " + config.interval.cacheRenewCheck/1000 + " seconds.") + setTimeout(() => { + this.update(); + }, config.interval.cacheRenewCheck); + }) } module.exports.serve = async (electronApp) => { diff --git a/src/scripts/update.js b/src/scripts/update.js index 87cf9171..325c040c 100644 --- a/src/scripts/update.js +++ b/src/scripts/update.js @@ -18,7 +18,7 @@ process.once('close', () => process.exit(1)); debug("Updating scams..."); - await Promise.all(serialijse.deserialize(cacheFile).scams.reverse().filter(scam => scam.howRecent() > config.interval.cacheExpiration).map(async scam => { + Promise.all(serialijse.deserialize(cacheFile).scams.reverse().filter(scam => scam.howRecent() > config.interval.cacheExpiration).map(async scam => { if(config.lookups.HTTP.enabled) await scam.getStatus(); if(config.lookups.DNS.IP.enabled) await scam.getIP(); if(config.lookups.DNS.NS.enabled) await scam.getNameservers(); @@ -27,12 +27,16 @@ process.once('close', () => process.exit(1)); url: scam.url, name: scam.name, ip: scam.ip, + category: scam.category, + subcategory: scam.subcategory, nameservers: scam.nameservers, status: scam.status, statusCode: scam.statusCode, updated: Date.now() }); - })); - debug("Done updating!"); + })).then(() => { + debug("Updating scams completed!") + process.exit(1) + }) })(); diff --git a/src/utils/db.js b/src/utils/db.js index bd3db47e..ccbccc1e 100644 --- a/src/utils/db.js +++ b/src/utils/db.js @@ -38,11 +38,16 @@ const readEntries = async () => { Object.assign(db,serialijse.deserialize(cacheFile)); yaml.safeLoad(scamsFile).filter(entry => !db.scams.find(scam => scam.url == entry.url)).map(entry => new Scam(entry)).forEach(entry => db.scams.push(entry)); yaml.safeLoad(verifiedFile).filter(entry => !db.verified.find(verified => verified.url == entry.url)).forEach(entry => db.verified.push(entry)); + yaml.safeLoad(scamsFile).forEach(entry => { + var index = db.scams.indexOf(db.scams.find(scam => scam.url == entry.url)) + db.scams[index].category = entry.category; + db.scams[index].subcategory = entry.subcategory; + db.scams[index].description = entry.description; + }); } } const updateIndex = async () => { - debug("Updating index..."); const scamDictionary = createDictionary(db.scams); const verifiedDictionary = createDictionary(db.verified); From 83359d99d9968d7876e925a7a2eb7cd8d42bba78 Mon Sep 17 00:00:00 2001 From: hahnmichaelf Date: Wed, 19 Sep 2018 16:10:44 -0400 Subject: [PATCH 2/2] Extend to verified_urls.yaml --- src/utils/db.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/utils/db.js b/src/utils/db.js index ccbccc1e..f124e9d4 100644 --- a/src/utils/db.js +++ b/src/utils/db.js @@ -44,6 +44,12 @@ const readEntries = async () => { db.scams[index].subcategory = entry.subcategory; db.scams[index].description = entry.description; }); + yaml.safeLoad(verifiedFile).forEach(entry => { + var index = db.verified.indexOf(db.verified.find(verified => verified.url == entry.url)) + db.verified[index].url = entry.url; + db.verified[index].description = entry.description; + if(entry.addresses) db.verified[index].addresses = entry.addresses; + }); } }