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..f124e9d4 100644 --- a/src/utils/db.js +++ b/src/utils/db.js @@ -38,11 +38,22 @@ 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; + }); + 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; + }); } } const updateIndex = async () => { - debug("Updating index..."); const scamDictionary = createDictionary(db.scams); const verifiedDictionary = createDictionary(db.verified);