mirror of
https://github.com/lovasoa/whitebophir
synced 2024-09-20 14:21:54 +00:00
add option to block tools (#66)
* add option to block tools * use tool name instead of computing an id Co-authored-by: Ophir LOJKINE <ophir.lojkine@auto-grid.com> * require comma separated list as input of blocked tools environment variable Co-authored-by: Ophir LOJKINE <ophir.lojkine@auto-grid.com> * Log attempts to use blocked tools Co-authored-by: Ophir LOJKINE <ophir.lojkine@auto-grid.com> * fix syntax * require tool names to not have a comma in them * Update server/configuration.js Co-authored-by: Ophir LOJKINE <pere.jobs@gmail.com>
This commit is contained in:
parent
e6811518dc
commit
edace1c293
4 changed files with 21 additions and 4 deletions
|
@ -156,10 +156,17 @@ Tools.HTML = {
|
|||
|
||||
Tools.list = {}; // An array of all known tools. {"toolName" : {toolObject}}
|
||||
|
||||
Tools.isBlocked = function toolIsBanned(tool) {
|
||||
if (tool.name.includes(",")) throw new Error("Tool Names must not contain a comma");
|
||||
return Tools.server_config.BLOCKED_TOOLS.includes(tool.name);
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a new tool, without touching the User Interface
|
||||
*/
|
||||
Tools.register = function registerTool(newTool) {
|
||||
if (Tools.isBlocked(newTool)) return;
|
||||
|
||||
if (newTool.name in Tools.list) {
|
||||
console.log("Tools.add: The tool '" + newTool.name + "' is already" +
|
||||
"in the list. Updating it...");
|
||||
|
@ -184,12 +191,14 @@ Tools.register = function registerTool(newTool) {
|
|||
newTool.draw(msg, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a new tool to the user interface
|
||||
*/
|
||||
Tools.add = function (newTool) {
|
||||
if (Tools.isBlocked(newTool)) return;
|
||||
|
||||
Tools.register(newTool);
|
||||
|
||||
if (newTool.stylesheet) {
|
||||
|
@ -246,7 +255,7 @@ Tools.addToolListeners = function addToolListeners(tool) {
|
|||
var target = listener.target || Tools.board;
|
||||
target.addEventListener(event, listener, { 'passive': false });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Tools.removeToolListeners = function removeToolListeners(tool) {
|
||||
for (var event in tool.compiledListeners) {
|
||||
|
@ -256,7 +265,7 @@ Tools.removeToolListeners = function removeToolListeners(tool) {
|
|||
// also attempt to remove with capture = true in IE
|
||||
if (Tools.isIE) target.removeEventListener(event, listener, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Tools.send = function (data, toolName) {
|
||||
toolName = toolName || Tools.curTool.name;
|
||||
|
|
|
@ -5,4 +5,5 @@ module.exports = {
|
|||
"MAX_BOARD_SIZE": config.MAX_BOARD_SIZE,
|
||||
"MAX_EMIT_COUNT": config.MAX_EMIT_COUNT,
|
||||
"MAX_EMIT_COUNT_PERIOD": config.MAX_EMIT_COUNT_PERIOD,
|
||||
"BLOCKED_TOOLS": config.BLOCKED_TOOLS,
|
||||
};
|
|
@ -31,4 +31,7 @@ module.exports = {
|
|||
|
||||
/** Duration after which the emit count is reset in miliseconds */
|
||||
MAX_EMIT_COUNT_PERIOD: parseInt(process.env['WBO_MAX_EMIT_COUNT_PERIOD']) || 4096,
|
||||
};
|
||||
|
||||
/** Blocked Tools. A comma-separated list of tools that should not appear on boards. */
|
||||
BLOCKED_TOOLS: (process.env['WBO_BLOCKED_TOOLS'] || "").split(','),
|
||||
};
|
||||
|
|
|
@ -96,6 +96,10 @@ function socketConnection(socket) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!message.data.tool || config.BLOCKED_TOOLS.includes(message.data.tool)) {
|
||||
log('BLOCKED MESSAGE', message.data);
|
||||
return;
|
||||
}
|
||||
|
||||
// Save the message in the board
|
||||
handleMessage(boardName, data, socket);
|
||||
|
|
Loading…
Reference in a new issue