Adding blocked_hosts table, ensure only new hosts are inserted.

This commit is contained in:
Jacob Windle 2019-02-13 16:10:57 -05:00
parent b10d007b4d
commit 5f577071ee

View File

@ -39,7 +39,29 @@ exports.initializeDatabase = function() {
if (err !== null)
throw err
console.log(JSON.parse(data))
// console.log(JSON.parse(data))
let blockedData = JSON.parse(data)
db.run("create table if not exists blocked_hosts (hostname TEXT)", (err, row) => {
if (err !== null) {
logErrorAndExit("Error creating table blocked_hosts: " + err)
}
})
db.get("select count(*) from blocked_hosts", (err, row) => {
if (err !== null) {
logErrorAndExit("Error getting count of blocked_hosts")
}
// if (blockedData.hosts.length row['count(*)'])
for (let host of blockedData.hosts) {
db.get("select hostname from blocked_hosts where hostname = ?", [host], (err, row) => {
if (err !== null) {
db.run("insert into blocked_hosts (hostname) values (?)", [hostname]);
}
// TODO -- run a diff for whatever has been deleted from the config file.
})
}
})
})
} catch(err) {
console.log(err)