migrate blocklist to a txt file

this allows easy copy/pasting of existing deny lists which contain
comments and blank lines
This commit is contained in:
Girish Ramakrishnan
2020-09-14 10:29:48 -07:00
parent 467fa59023
commit 20e206fa43
10 changed files with 78 additions and 29 deletions

View File

@@ -6,6 +6,7 @@ exports = module.exports = {
};
var assert = require('assert'),
auditSource = require('../auditsource.js'),
BoxError = require('../boxerror.js'),
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess,
@@ -22,12 +23,11 @@ function getBlocklist(req, res, next) {
function setBlocklist(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (!Array.isArray(req.body.blocklist)) return next(new HttpError(400, 'blocklist is required'));
if (!req.body.blocklist.every(x => typeof x === 'string')) return next(new HttpError(400, 'blocklist must be array of strings'));
if (typeof req.body.blocklist !== 'string') return next(new HttpError(400, 'blocklist must be a string'));
req.clearTimeout(); // can take a while if there is a lot of network ranges
network.setBlocklist(req.body.blocklist, function (error) {
network.setBlocklist(req.body.blocklist, auditSource.fromRequest(req), function (error) {
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));