mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 16:23:12 +09:00
Added cluster wide command execution + fixed some checks failing due to type mismatch
This commit is contained in:
1 parent
20e66cbd40
commit
ebf2fd2204
1 file changed
+29
-13
@@ -793,19 +793,35 @@ app.post("/api/runCommand", (req,res) => {
|
|||||||
if(err) return res.status(500).send({ auth: false, message: 'Failed to authenticate token.' });
|
if(err) return res.status(500).send({ auth: false, message: 'Failed to authenticate token.' });
|
||||||
|
|
||||||
// validate request.body
|
// validate request.body
|
||||||
let body = req.body;
|
let body = req.body;
|
||||||
if(body.instanceID
|
|
||||||
&& Object.keys(wsSlaves).includes(body.instanceID)
|
if (
|
||||||
&& body.command
|
body.broadcast
|
||||||
&& typeof body.command == "string"
|
&& body.command
|
||||||
&& body.command[0] == "/"){
|
&& typeof body.command == "string"
|
||||||
// execute command
|
&& body.command[0] == "/")
|
||||||
wsSlaves[body.instanceID].runCommand(body.command, data => {
|
{
|
||||||
res.status(200).send({auth: true, message: "success", data});
|
let instanceResponses = [];
|
||||||
});
|
for (let instanceID in wsSlaves) {
|
||||||
} else {
|
// skip loop if the property is from prototype
|
||||||
res.status(400).send({auth: true, message: "Error: invalid request.body"});
|
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"});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user