firewall: implement blocklist
This commit is contained in:
33
src/routes/network.js
Normal file
33
src/routes/network.js
Normal file
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
getBlocklist,
|
||||
setBlocklist
|
||||
};
|
||||
|
||||
var assert = require('assert'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
network = require('../network.js');
|
||||
|
||||
function getBlocklist(req, res, next) {
|
||||
network.getBlocklist(function (error, blocklist) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { blocklist }));
|
||||
});
|
||||
}
|
||||
|
||||
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'));
|
||||
|
||||
network.setBlocklist(req.body.blocklist, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user