network: add trusted ips
This allows the user to set trusted ips to Cloudflare or some other CDN and have the logs have the correct IPs. fixes #801
This commit is contained in:
+23
-1
@@ -2,7 +2,10 @@
|
||||
|
||||
exports = module.exports = {
|
||||
getBlocklist,
|
||||
setBlocklist
|
||||
setBlocklist,
|
||||
|
||||
getTrustedIps,
|
||||
setTrustedIps
|
||||
};
|
||||
|
||||
const assert = require('assert'),
|
||||
@@ -11,6 +14,7 @@ const assert = require('assert'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
network = require('../network.js'),
|
||||
reverseProxy = require('../reverseproxy.js'),
|
||||
safe = require('safetydance');
|
||||
|
||||
async function getBlocklist(req, res, next) {
|
||||
@@ -32,3 +36,21 @@ async function setBlocklist(req, res, next) {
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
async function getTrustedIps(req, res, next) {
|
||||
const [error, trustedIps] = await safe(reverseProxy.getTrustedIps());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { trustedIps }));
|
||||
}
|
||||
|
||||
async function setTrustedIps(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.trustedIps !== 'string') return next(new HttpError(400, 'trustedIps must be a string'));
|
||||
|
||||
const [error] = await safe(reverseProxy.setTrustedIps(req.body.trustedIps, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user