From 5dbcd68f92fc4eee796d3fd7f0b986d2c06adb0d Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Sun, 9 May 2021 20:54:31 +0200 Subject: [PATCH] feat(bma): configure with env var --- app/modules/bma/index.ts | 28 ++++++++++++++++++++++++++++ app/modules/bma/lib/network.ts | 9 +++++++++ 2 files changed, 37 insertions(+) diff --git a/app/modules/bma/index.ts b/app/modules/bma/index.ts index ca769502a..fc1e5d3fe 100644 --- a/app/modules/bma/index.ts +++ b/app/modules/bma/index.ts @@ -275,6 +275,34 @@ export class BMAPI extends stream.Transform { } startService = async () => { + // Override BMA configuration from environment variables + if (process.env.DUNITER_BMA_ENABLED === "true") { + if (this.conf.nobma) { + this.conf.nobma = false; + } + if (this.server.conf.upnp) { + this.server.conf.upnp = false; + } + } + + if (process.env.DUNITER_BMA_IP4) { + this.server.conf.ipv4 = process.env.DUNITER_BMA_IP4; + } + if (process.env.DUNITER_BMA_IP6) { + this.server.conf.ipv6 = process.env.DUNITER_BMA_IP6; + } + if (process.env.DUNITER_BMA_REMOTE_HOST) { + this.server.conf.remotehost = process.env.DUNITER_BMA_REMOTE_HOST; + } + if (process.env.DUNITER_BMA_PORT) { + this.server.conf.port = parseInt(process.env.DUNITER_BMA_PORT); + } + if (process.env.DUNITER_BMA_REMOTE_PORT) { + this.server.conf.remoteport = parseInt( + process.env.DUNITER_BMA_REMOTE_PORT + ); + } + if (this.conf.nobma) { // Disable BMA return Promise.resolve(); diff --git a/app/modules/bma/lib/network.ts b/app/modules/bma/lib/network.ts index 059c4b2c2..799b0a78b 100644 --- a/app/modules/bma/lib/network.ts +++ b/app/modules/bma/lib/network.ts @@ -80,7 +80,16 @@ export const Network = { if (whitelist.indexOf("127.0.0.1") === -1) { whitelist.push("127.0.0.1"); } + if (whitelist.indexOf("::1") === -1) { + whitelist.push("::1"); + } const ddosConf = server.conf.dos || {}; + + // Override BMA DDOS configuration from environment variables + if (process.env.DUNITER_BMA_WHITELIST) { + ddosConf.whitelist = process.env.DUNITER_BMA_WHITELIST.split(","); + } + ddosConf.silentStart = true; ddosConf.whitelist = Underscore.uniq( (ddosConf.whitelist || []).concat(whitelist) -- GitLab