From 4b2ec8eed6856f253cf2b46cf76c8840056e5666 Mon Sep 17 00:00:00 2001 From: Adhidarma Hadiwinoto <me@adhisimon.org> Date: Wed, 4 Dec 2019 19:02:19 +0700 Subject: [PATCH] blacklist help --- config.sample.json | 4 +++- lib/command-handler/help.js | 9 +++++++-- lib/command-handler/index.js | 2 +- lib/http-listener.js | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/config.sample.json b/config.sample.json index 71f10e5..89bd8aa 100644 --- a/config.sample.json +++ b/config.sample.json @@ -8,5 +8,7 @@ "127.0.0.1", "::ffff:127.0.0.1", "::1" - ] + ], + "blacklist_help_for_origins": [], + "blacklist_help_for_origin_transports": [] } \ No newline at end of file diff --git a/lib/command-handler/help.js b/lib/command-handler/help.js index 314e757..1e8c64d 100644 --- a/lib/command-handler/help.js +++ b/lib/command-handler/help.js @@ -1,3 +1,4 @@ +const config = require('komodo-sdk/config'); const logger = require('komodo-sdk/logger'); const commands = require('../command-group'); @@ -27,10 +28,14 @@ const msg = 'Perintah tersedia:\n\n' + cmds2.join(',\n\n'); logger.verbose('Help return message constructed', { count: cmds.length, chars: msg.length, lines: msg.split(/\r\n|\r|\n/).length }); -module.exports = function(cb) { +module.exports = function(tokens, params, cb) { + const blacklisted = ((config.blacklist_help_for_origins || []).indexOf(params.origin || '') >= 0) + || ((config.blacklist_help_for_origin_transports || []).indexOf(params.origin_transport || '') >= 0) + ; + const body = blacklisted ? `Perintah "${tokens[0]}" tdk tersedia pd jalur SMS dan sejenis.` : msg; const responseParams = { - body: msg + body } cb(null, null, responseParams); diff --git a/lib/command-handler/index.js b/lib/command-handler/index.js index 3736514..787da16 100644 --- a/lib/command-handler/index.js +++ b/lib/command-handler/index.js @@ -93,7 +93,7 @@ function execute(msg, params, cb) { handlerSupplierBalances(tokens, params, cb); } else if (commandGroup === 'help') { - handlerHelp(cb) + handlerHelp(tokens, params, cb) } else { cb(commandError.ERR_NOT_IMPLEMENTED); diff --git a/lib/http-listener.js b/lib/http-listener.js index a512d37..c0eb853 100644 --- a/lib/http-listener.js +++ b/lib/http-listener.js @@ -97,6 +97,7 @@ function mainHandler(req, res) { const params = { origin: req.body.origin || req.query.origin || 'MESSAGING', + origin_transport: req.body.origin_transport || req.query.origin_transport, report_ip: req.body.report_ip || req.query.report_ip || req.ip, report_port: req.body.report_port || req.query.report_port, from: req.body.partner || req.query.partner || req.body.from || req.query.from, -- 1.9.0