diff --git a/crowdsec.js b/crowdsec.js index 8dbd9b11..04e506db 100644 --- a/crowdsec.js +++ b/crowdsec.js @@ -12,22 +12,31 @@ module.exports.CreateCrowdSecBouncer = function (parent, config) { // Current captcha state const currentCaptchaIpList = {}; - // Set the default values - if (typeof config.userAgent != 'string') { config.userAgent = "CrowdSec Express-NodeJS bouncer/v0.0.1"; } + // Set the default values. "config" will come in with lowercase names with everything, so we need to correct some value names. + if (typeof config.useragent != 'string') { config.useragent = 'CrowdSec Express-NodeJS bouncer/v0.0.1'; } if (typeof config.timeout != 'number') { config.timeout = 2000; } - if ((typeof config.fallbackRemediation != 'string') || (["bypass", "captcha", "ban"].indexOf(config.fallbackRemediation) == -1)) { config.fallbackRemediation = BAN_REMEDIATION; } - if (typeof config.maxRemediation != 'number') { config.maxRemediation = BAN_REMEDIATION; } - if (typeof config.captchaGenerationCacheDuration != 'number') { config.captchaGenerationCacheDuration = 60 * 1000; } - if (typeof config.captchaResolutionCacheDuration != 'number') { config.captchaResolutionCacheDuration = 30 * 60 * 1000; } - if (typeof config.captchaTexts != 'object') { config.captchaTexts = {}; } - if (typeof config.banTexts != 'object') { config.banTexts = {}; } - if (typeof config.colors != 'object') { config.colors = {}; } - if (typeof config.hideCrowdsecMentions != 'boolean') { config.hideCrowdsecMentions = false; } - if (typeof config.customCss != 'string') { config.customCss = ''; } + if ((typeof config.fallbackremediation != 'string') || (['bypass', 'captcha', 'ban'].indexOf(config.fallbackremediation) == -1)) { config.fallbackremediation = BAN_REMEDIATION; } + if (typeof config.maxremediation != 'number') { config.maxremediation = BAN_REMEDIATION; } + if (typeof config.captchagenerationcacheduration != 'number') { config.captchagenerationcacheduration = 60 * 1000; } // 60 seconds + if (typeof config.captcharesolutioncacheduration != 'number') { config.captcharesolutioncacheduration = 30 * 60 * 1000; } // 30 minutes + if (typeof config.captchatexts != 'object') { config.captchatexts = {}; } else { + if (typeof config.captchatexts.tabtitle == 'string') { config.captchatexts.tabTitle = config.captchatexts.tabtitle; delete config.captchatexts.tabtitle; } // Fix "tabTitle" capitalization + } + if (typeof config.bantexts != 'object') { config.bantexts = {}; } else { + if (typeof config.bantexts.tabtitle == 'string') { config.bantexts.tabTitle = config.bantexts.tabtitle; delete config.bantexts.tabtitle; } // Fix "tabTitle" capitalization + } + if (typeof config.colors != 'object') { config.colors = {}; } else { + var colors = {}; + // All of the values in "text" and "background" sections happen to be lowercase, so, we can use the values as-is. + if (typeof config.colors.text == 'object') { colors.text = config.colors.text; } + if (typeof config.colors.background == 'object') { colors.background = config.colors.background; } + config.colors = colors; + } + if (typeof config.hidecrowdsecmentions != 'boolean') { config.hidecrowdsecmentions = false; } + if (typeof config.customcss != 'string') { delete config.customcss; } if (typeof config.bypass != 'boolean') { config.bypass = false; } - if (typeof config.trustedRangesForIpForwarding != 'object') { config.trustedRangesForIpForwarding = []; } - if (typeof config.customLogger != 'object') { config.customLogger = null; } - if (typeof config.bypassConnectionTest != 'boolean') { config.bypassConnectionTest = false; } + if (typeof config.customlogger != 'object') { delete config.customlogger; } + if (typeof config.bypassconnectiontest != 'boolean') { config.bypassconnectiontest = false; } // Setup the logger var logger = config.customLogger ? config.customLogger : getLogger(); @@ -35,16 +44,16 @@ module.exports.CreateCrowdSecBouncer = function (parent, config) { // Configure the bouncer configure({ url: config.url, - apiKey: config.apiKey, - userAgent: config.userAgent, + apiKey: config.apikey, + userAgent: config.useragent, timeout: config.timeout, - fallbackRemediation: config.fallbackRemediation, - maxRemediation: config.maxRemediation, - captchaTexts: config.captchaTexts, - banTexts: config.banTexts, + fallbackRemediation: config.fallbackremediation, + maxRemediation: config.maxremediation, + captchaTexts: config.captchatexts, + banTexts: config.bantexts, colors: config.colors, - hideCrowdsecMentions: config.hideCrowdsecMentions, - customCss: config.customCss + hideCrowdsecMentions: config.hidecrowdsecmentions, + customCss: config.customcss }); // Test connectivity @@ -53,7 +62,7 @@ module.exports.CreateCrowdSecBouncer = function (parent, config) { // Process a web request obj.process = async function (domain, req, res, next) { try { - var remediation = config.fallbackRemediation; + var remediation = config.fallbackremediation; try { remediation = await getRemediationForIp(req.clientIp); } catch (ex) { } //console.log('CrowdSec', req.clientIp, remediation, req.url); switch (remediation) { @@ -75,7 +84,7 @@ module.exports.CreateCrowdSecBouncer = function (parent, config) { // Process a captcha request obj.applyCaptcha = async function (req, res, next) { - await applyCaptchaEx(req.clientIp, req, res, next, config.captchaGenerationCacheDuration, config.captchaResolutionCacheDuration, logger); + await applyCaptchaEx(req.clientIp, req, res, next, config.captchagenerationcacheduration, config.captcharesolutioncacheduration, logger); } // Process a captcha request diff --git a/meshcentral.js b/meshcentral.js index 7d6adcad..4f3e77c3 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -698,7 +698,7 @@ function CreateMeshCentralServer(config, args) { obj.args = args = config2.settings; // Lower case all keys in the config file - obj.common.objKeysToLower(config2, ['ldapoptions', 'defaultuserwebstate', 'forceduserwebstate', 'httpheaders', 'crowdsec']); + obj.common.objKeysToLower(config2, ['ldapoptions', 'defaultuserwebstate', 'forceduserwebstate', 'httpheaders']); // Grad some of the values from the original config.json file if present. if ((config.settings.vault != null) && (config2.settings != null)) { config2.settings.vault = config.settings.vault; } @@ -1196,7 +1196,7 @@ function CreateMeshCentralServer(config, args) { for (i in args) { config2.settings[i] = args[i]; } // Lower case all keys in the config file - common.objKeysToLower(config2, ['ldapoptions', 'defaultuserwebstate', 'forceduserwebstate', 'httpheaders', 'crowdsec']); + common.objKeysToLower(config2, ['ldapoptions', 'defaultuserwebstate', 'forceduserwebstate', 'httpheaders']); // Grad some of the values from the original config.json file if present. config2['mysql'] = config['mysql']; @@ -3518,7 +3518,7 @@ function getConfig(createSampleConfig) { // Lower case all keys in the config file try { - require('./common.js').objKeysToLower(config, ['ldapoptions', 'defaultuserwebstate', 'forceduserwebstate', 'httpheaders', 'crowdsec']); + require('./common.js').objKeysToLower(config, ['ldapoptions', 'defaultuserwebstate', 'forceduserwebstate', 'httpheaders']); } catch (ex) { console.log('CRITICAL ERROR: Unable to access the file \"./common.js\".\r\nCheck folder & file permissions.'); process.exit(); diff --git a/package.json b/package.json index 6fb329d3..460dc9c6 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,8 @@ "sample-config-advanced.json" ], "dependencies": { + "@crowdsec/express-bouncer": "^0.1.0", + "@yetzt/nedb": "^1.8.0", "archiver": "^5.3.1", "body-parser": "^1.19.0", "cbor": "~5.2.0", @@ -45,13 +47,21 @@ "express": "^4.17.0", "express-handlebars": "^5.3.5", "express-ws": "^4.0.0", + "image-size": "^1.0.1", "ipcheck": "^0.1.0", + "loadavg-windows": "^1.1.1", "minimist": "^1.2.5", "multiparty": "^4.2.1", - "@yetzt/nedb": "^1.8.0", "node-forge": "^1.0.0", + "node-windows": "^0.1.4", + "otplib": "^10.2.3", + "pg": "^8.7.1", + "pgtools": "^0.3.2", + "ssh2": "^1.11.0", + "web-push": "^3.5.0", "ws": "^5.2.3", - "yauzl": "^2.10.0" + "yauzl": "^2.10.0", + "yubikeyotp": "^0.2.0" }, "engines": { "node": ">=10.0.0"