diff --git a/.gitignore b/.gitignore index a5a56e68..3ba5e9a3 100644 --- a/.gitignore +++ b/.gitignore @@ -48,7 +48,6 @@ saves sharedPlugins/* !sharedPlugins/inventoryImports/ !sharedPlugins/UPSdisplay/ -!sharedPlugins/remoteCommands/ !sharedPlugins/researchSync/ !sharedPlugins/globalChat/ !sharedPlugins/clusterioMod/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 75e994cb..02b70141 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,8 @@ Version 2.0.0 add in a remote interface. - Removed mod uploading and distributing from the HTTP interface. Breaks the old unmaintained and no longer needed factorioClusterioClient. +- Removed the remoteCommands plugin and the old runCommand interface. Breaks + playerManager and external tools sending commands. Version 1.2.3 diff --git a/CLI tools/cluster_rcon.js b/CLI tools/cluster_rcon.js deleted file mode 100644 index becb0e08..00000000 --- a/CLI tools/cluster_rcon.js +++ /dev/null @@ -1,40 +0,0 @@ -const needle = require("needle"); -const cli = require("cli"); -const config = require("./../config.json"); - -let options = cli.parse() -cli.setUsage(`node cluster_rcon /c game.player.force = "player"`) -if(process.argv.length < 3){ - cli.getUsage() - process.exit(1) -} - -const token = config.masterAuthToken -let commandArray = process.argv; -commandArray.shift(); -commandArray.shift(); -const needleOptionsWithTokenAuthHeader = { - headers: { - 'x-access-token': token, - }, -}; - -let command = commandArray.join(" "); -let killBiters = `/silent-command local surface=game.surfaces[1] for key, entity in pairs(surface.find_entities_filtered({force="enemy"})) do entity.destroy() end`; - -(async ()=>{ - needle.post(config.masterURL+"/api/runCommand", { - broadcast:true, - command, - }, needleOptionsWithTokenAuthHeader, (err, resp) => { - console.log(resp.body) - }); - // setInterval(()=>{ - // needle.post(config.masterURL+"/api/runCommand", { - // broadcast:true, - // command: killBiters, - // }, needleOptionsWithTokenAuthHeader, (err, resp) => { - // console.log(resp.body) - // }); - // }, 1000*60*5); -})(); diff --git a/master.js b/master.js index 454f6191..48a0686a 100644 --- a/master.js +++ b/master.js @@ -340,50 +340,6 @@ app.get("/api/modmeta", async function(req, res) { }); -/** -POST endpoint for running commands on slaves. -Requires x-access-token header to be set. Find you api token in secret-api-token.txt on the master (after running it once) - -@memberof clusterioMaster -@instance -@alias api/runCommand -@param {object} JSON {instanceID:19412312, broadcast:false, command:"/c game.print('hello')"} -@returns {object} Status {auth: bool, message: "Informative error", data:{}} -*/ -app.post("/api/runCommand", authenticate.middleware, function(req,res) { - endpointHitCounter.labels(req.route.path).inc(); - // validate request.body - let body = req.body; - - if ( - body.broadcast - && body.command - && typeof body.command == "string" - && body.command[0] == "/") - { - let instanceResponses = []; - for (let instanceID in wsSlaves) { - // skip loop if the property is from prototype - if (!wsSlaves.hasOwnProperty(instanceID)) continue; - wsSlaves[instanceID].runCommand(body.command); - } - res.status(200).send({auth: true, message: "success", response: "Cluster wide messaging initiated"}); - } else if ( - body.instanceID - && wsSlaves[body.instanceID] - && body.command - && typeof body.command == "string" - && body.command[0] == "/") - { - // execute command - wsSlaves[body.instanceID].runCommand(body.command, data => { - res.status(200).send({auth: true, message: "success", data}); - }); - } else { - res.status(400).send({auth: true, message: "Error: invalid request.body"}); - } -}); - var localeCache; /** GET endpoint. Returns factorio's base locale as a JSON object. @@ -423,15 +379,6 @@ class wsSlave { prometheusWsUsageCounter.labels('heartbeat', this.instanceID).inc(); this.lastBeat = Date.now(); }); - // handle command return values - this.commandsWaitingForReturn = {}; - this.socket.on("runCommandReturnValue", resp => { - prometheusWsUsageCounter.labels('runCommandReturnValue', this.instanceID).inc(); - if(resp.commandID && resp.body && this.commandsWaitingForReturn[resp.commandID] && this.commandsWaitingForReturn[resp.commandID].callback && typeof this.commandsWaitingForReturn[resp.commandID].callback == "function"){ - this.commandsWaitingForReturn[resp.commandID].callback(resp.body); - delete this.commandsWaitingForReturn[resp.commandID]; - } - }); this.socket.on("gameChat", data => { prometheusWsUsageCounter.labels('gameChat', this.instanceID).inc(); @@ -455,11 +402,6 @@ class wsSlave { } }); } - runCommand(command, callback){ - let commandID = Math.random().toString(); - this.socket.emit("runCommand", {command, commandID}); - if(commandID) this.commandsWaitingForReturn[commandID] = {callback, timestamp: Date.now()}; - } } io.use((socket, next) => { diff --git a/sharedPlugins/remoteCommands/config.js b/sharedPlugins/remoteCommands/config.js deleted file mode 100644 index 07a83322..00000000 --- a/sharedPlugins/remoteCommands/config.js +++ /dev/null @@ -1,13 +0,0 @@ -/* - Config for clusterio remote command plugin. - Allows you to execute commands on slaves with a web API. - - Careful, may allow for RCE vulnerabilities. -*/ -module.exports = { - // Name of package. For display somewhere I guess. - name: "remoteCommands", - version: "1.0.0", - binary: "nodePackage", - description: "Config for clusterio remote command plugin. Allows you to execute commands on slaves with a web API.", -} \ No newline at end of file diff --git a/sharedPlugins/remoteCommands/index.js b/sharedPlugins/remoteCommands/index.js deleted file mode 100644 index 62a7df20..00000000 --- a/sharedPlugins/remoteCommands/index.js +++ /dev/null @@ -1,25 +0,0 @@ -module.exports = class remoteCommands { - constructor(mergedConfig, messageInterface, extras){ - this.messageInterface = messageInterface; - this.config = mergedConfig; - this.socket = extras.socket; - - if(this.config.allowRemoteCommandExecution){ - this.socket.on("runCommand", data => { - let {commandID} = data; - this.messageInterface(data.command); - if(commandID){ - this.socket.emit("runCommandReturnValue", { - commandID, - body: { - info: "Command was sent to factorio", - }, - }); - } - }); - } - } - scriptOutput(data){ - // we don't return anything yet - } -} diff --git a/sharedPlugins/remoteCommands/test/missing.js b/sharedPlugins/remoteCommands/test/missing.js deleted file mode 100644 index 923d82bf..00000000 --- a/sharedPlugins/remoteCommands/test/missing.js +++ /dev/null @@ -1,4 +0,0 @@ -// These are libraries that does not have any units test, they are -// required here in order to track coverage for them. - -require('../index');