Added ability to add host to blocked table if visit count is exceeded
This commit is contained in:
@@ -19,6 +19,10 @@ const logger = winston.createLogger({
|
||||
* on exit.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Log a message at level ERROR and exit
|
||||
* @param {string} message
|
||||
*/
|
||||
function logErrorAndExit(message) {
|
||||
logger.error(message)
|
||||
process.exit(1)
|
||||
@@ -92,6 +96,19 @@ function addHostToTable(hostname) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a host to the blocked table, hit after visit count is exceeded.
|
||||
* @param {string} hostname Host to add to blocked table
|
||||
*/
|
||||
function addHostToBlockedTable(hostname) {
|
||||
db.serialize(() => {
|
||||
db.run("insert into hosts (hostname) values (?)", [hostname], (err, row) => {
|
||||
if (err !== null) {
|
||||
logger.info("Attempted to visit blocked page " + hostname)
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Either initialize a row in the database, or update the visit count for a row.
|
||||
* @param {string} hostname Host that was visited
|
||||
@@ -116,6 +133,7 @@ exports.visitHost = function (hostname, callbackFn) {
|
||||
} else {
|
||||
// Do the blocking, make this configurable.
|
||||
if (row.visitcount >= 2) {
|
||||
addHostToBlockedTable(hostname)
|
||||
callbackFn(false);
|
||||
} else {
|
||||
updateVisitCount(hostname);
|
||||
|
||||
Reference in New Issue
Block a user