mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 00:13:12 +09:00
Remove remoteCommands plugin and interface
Remove the half baked remote rcon command interface in preparation for a better version based on a new socket.io communication layer.
This commit is contained in:
1 parent
ca2967e255
commit
27fc68da0f
7 files changed
+2
-141
No files matched your search
@@ -48,7 +48,6 @@ saves
|
|||||||
sharedPlugins/*
|
sharedPlugins/*
|
||||||
!sharedPlugins/inventoryImports/
|
!sharedPlugins/inventoryImports/
|
||||||
!sharedPlugins/UPSdisplay/
|
!sharedPlugins/UPSdisplay/
|
||||||
!sharedPlugins/remoteCommands/
|
|
||||||
!sharedPlugins/researchSync/
|
!sharedPlugins/researchSync/
|
||||||
!sharedPlugins/globalChat/
|
!sharedPlugins/globalChat/
|
||||||
!sharedPlugins/clusterioMod/
|
!sharedPlugins/clusterioMod/
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ Version 2.0.0
|
|||||||
add in a remote interface.
|
add in a remote interface.
|
||||||
- Removed mod uploading and distributing from the HTTP interface. Breaks
|
- Removed mod uploading and distributing from the HTTP interface. Breaks
|
||||||
the old unmaintained and no longer needed factorioClusterioClient.
|
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
|
Version 1.2.3
|
||||||
|
|||||||
@@ -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);
|
|
||||||
})();
|
|
||||||
@@ -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;
|
var localeCache;
|
||||||
/**
|
/**
|
||||||
GET endpoint. Returns factorio's base locale as a JSON object.
|
GET endpoint. Returns factorio's base locale as a JSON object.
|
||||||
@@ -423,15 +379,6 @@ class wsSlave {
|
|||||||
prometheusWsUsageCounter.labels('heartbeat', this.instanceID).inc();
|
prometheusWsUsageCounter.labels('heartbeat', this.instanceID).inc();
|
||||||
this.lastBeat = Date.now();
|
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 => {
|
this.socket.on("gameChat", data => {
|
||||||
prometheusWsUsageCounter.labels('gameChat', this.instanceID).inc();
|
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) => {
|
io.use((socket, next) => {
|
||||||
|
|||||||
@@ -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.",
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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');
|
|
||||||
Reference in new issue
Block a user