mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 00:13:12 +09:00
Remove config management
Remove lib/manager/configManager.js and the config management command line interface as well as the serverManager's web interface for config management. The configuration rewrite will work differently and is not compatible with configManager.js.
This commit is contained in:
1 parent
dd865b42b5
commit
5f33cf4d3b
10 files changed
+4
-201
No files matched your search
@@ -5,8 +5,6 @@ before_install:
|
|||||||
- curl -o factorio.tar.gz -L https://www.factorio.com/get-download/latest/headless/linux64
|
- curl -o factorio.tar.gz -L https://www.factorio.com/get-download/latest/headless/linux64
|
||||||
- tar -xf factorio.tar.gz
|
- tar -xf factorio.tar.gz
|
||||||
- npm install -g codecov
|
- npm install -g codecov
|
||||||
# Needed for lib/manager/configManager
|
|
||||||
- echo {} > config.json
|
|
||||||
script:
|
script:
|
||||||
- npm run-script ci-cover
|
- npm run-script ci-cover
|
||||||
- codecov -f coverage/lcov.info
|
- codecov -f coverage/lcov.info
|
||||||
@@ -20,6 +20,7 @@ Version 2.0.0
|
|||||||
Breaks discordChat, playerManager, serverSelect, trainTeleports and
|
Breaks discordChat, playerManager, serverSelect, trainTeleports and
|
||||||
clusterioModel.
|
clusterioModel.
|
||||||
- Instance names can no longer be invalid Windows file names.
|
- Instance names can no longer be invalid Windows file names.
|
||||||
|
- Removed config management from the command line and the server manager.
|
||||||
|
|
||||||
|
|
||||||
Version 1.2.1
|
Version 1.2.1
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ const crypto = require("crypto");
|
|||||||
const objectOps = require("lib/objectOps.js");
|
const objectOps = require("lib/objectOps.js");
|
||||||
const fileOps = require("lib/fileOps");
|
const fileOps = require("lib/fileOps");
|
||||||
const stringUtils = require("lib/stringUtils.js");
|
const stringUtils = require("lib/stringUtils.js");
|
||||||
const configManager = require("lib/manager/configManager.js");
|
|
||||||
const pluginManager = require("lib/manager/pluginManager");
|
const pluginManager = require("lib/manager/pluginManager");
|
||||||
const hashFile = require('lib/hash').hashFile;
|
const hashFile = require('lib/hash').hashFile;
|
||||||
|
|
||||||
@@ -235,12 +234,10 @@ async function manage(config, instance) {
|
|||||||
function usage(instance, tool, action){
|
function usage(instance, tool, action){
|
||||||
if(tool && tool == "mods"){
|
if(tool && tool == "mods"){
|
||||||
console.log('node client.js manage '+instance.name+' '+tool+' ["list", "search", "add", "remove"]');
|
console.log('node client.js manage '+instance.name+' '+tool+' ["list", "search", "add", "remove"]');
|
||||||
} else if(tool && tool == "config") {
|
|
||||||
console.log('node client.js manage '+instance.name+' '+tool+' ["list", "edit"]');
|
|
||||||
} else if(tool && tool == "plugins") {
|
} else if(tool && tool == "plugins") {
|
||||||
console.log(`node client.js manage ${instance.name} ${tool} ["list", "add", "remove"]`);
|
console.log(`node client.js manage ${instance.name} ${tool} ["list", "add", "remove"]`);
|
||||||
} else {
|
} else {
|
||||||
console.log('node client.js manage '+(instance && instance.name || '[instance, "shared"]') +' '+ (tool || '["mods", "config", "plugins"]') + ' ...');
|
console.log('node client.js manage '+(instance && instance.name || '[instance, "shared"]') +' '+ (tool || '["mods", "plugins"]') + ' ...');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const tool = process.argv[4] || "";
|
const tool = process.argv[4] || "";
|
||||||
@@ -268,23 +265,6 @@ async function manage(config, instance) {
|
|||||||
console.log("Got error from modManager:")
|
console.log("Got error from modManager:")
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}})();
|
}})();
|
||||||
} else if(tool == "config"){
|
|
||||||
// allow managing the config
|
|
||||||
if(action == "list" || action == "show" || action == "display"){
|
|
||||||
configManager.displayConfig(instance.name);
|
|
||||||
} else if(action == "edit"){
|
|
||||||
let newConfigValue = "";
|
|
||||||
process.argv.forEach((arg, i)=>{
|
|
||||||
if(i >= 8){
|
|
||||||
newConfigValue += " "+arg;
|
|
||||||
} else if(i >= 7){
|
|
||||||
newConfigValue += arg;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
configManager.editConfig(instance, process.argv[6], newConfigValue);
|
|
||||||
} else {
|
|
||||||
usage(instance, tool);
|
|
||||||
}
|
|
||||||
} else if(tool == "plugins"){
|
} else if(tool == "plugins"){
|
||||||
(async function(){try{
|
(async function(){try{
|
||||||
if(action == "list"){
|
if(action == "list"){
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
/**
|
|
||||||
Provides tools for managing both masters and slaves config files.
|
|
||||||
@module configManager
|
|
||||||
*/
|
|
||||||
// require modules
|
|
||||||
const asTable = require("as-table").configure({delimiter: ' | '});
|
|
||||||
const fs = require("fs");
|
|
||||||
|
|
||||||
// internal requires
|
|
||||||
var config = require("./../../config");
|
|
||||||
const objectOps = require("./../objectOps.js");
|
|
||||||
/**
|
|
||||||
console.log()s each entry in the config
|
|
||||||
|
|
||||||
@param {string} instance Either undefined, "shared" or the instance to show the config for.
|
|
||||||
*/
|
|
||||||
module.exports.displayConfig = function(instance){
|
|
||||||
console.log(asTable(this.getConfig(instance)));
|
|
||||||
}
|
|
||||||
module.exports.getConfig = async function(instance){
|
|
||||||
if(!instance || instance == "shared"){
|
|
||||||
let configArray = [];
|
|
||||||
Object.keys(config).forEach(key=>{
|
|
||||||
if(key != "__comment"){
|
|
||||||
if(typeof config[key] == "object"){
|
|
||||||
configArray.push({entry: key, value: JSON.stringify(config[key])});
|
|
||||||
} else configArray.push({entry: key, value: config[key]});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return configArray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
module.exports.editConfig = function(instance, entry, newValue){
|
|
||||||
if(!instance || instance == "shared"){
|
|
||||||
if(config[entry] && newValue){
|
|
||||||
if(objectOps.isJSON(newValue)){
|
|
||||||
config[entry] = JSON.parse(newValue);
|
|
||||||
console.log("Changed config entry "+entry+" from "+JSON.stringify(config[entry])+" to "+JSON.stringify(newValue));
|
|
||||||
// console.log("new config file:");
|
|
||||||
// console.log(JSON.stringify(config, null, " "))
|
|
||||||
fs.writeFileSync("config.json", JSON.stringify(config, null, 4));
|
|
||||||
return {
|
|
||||||
ok:true,
|
|
||||||
msg:`Changed config entry ${entry} from Object to ${JSON.stringify(newValue)}`,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
config[entry] = newValue;
|
|
||||||
console.log("Changed config entry "+entry+" from "+config[entry]+" to '"+newValue+"'");
|
|
||||||
// console.log("new config file:");
|
|
||||||
// console.log(JSON.stringify(config, null, " "))
|
|
||||||
fs.writeFileSync("config.json", JSON.stringify(config, null, 4));
|
|
||||||
return {
|
|
||||||
ok:true,
|
|
||||||
msg:`Changed config entry ${entry} from ***** to '${newValue}'`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
ok:false,
|
|
||||||
msg:`No such config parameter`,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
ok:false,
|
|
||||||
msg:`Editing config for single instances is not yet supported`,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -10,7 +10,6 @@ module.exports = class remoteCommands {
|
|||||||
this.config = mergedConfig;
|
this.config = mergedConfig;
|
||||||
this.socket = extras.socket;
|
this.socket = extras.socket;
|
||||||
const pluginManager = require("lib/manager/pluginManager.js");
|
const pluginManager = require("lib/manager/pluginManager.js");
|
||||||
const configManager = require("lib/manager/configManager.js");
|
|
||||||
// const modManager = require("lib/manager/modManager.js")(this.config);
|
// const modManager = require("lib/manager/modManager.js")(this.config);
|
||||||
this.socket.on("hello", () => {
|
this.socket.on("hello", () => {
|
||||||
this.socket.emit("registerServerManager");
|
this.socket.emit("registerServerManager");
|
||||||
@@ -23,13 +22,6 @@ module.exports = class remoteCommands {
|
|||||||
// let mods = modManager.getMods()
|
// let mods = modManager.getMods()
|
||||||
// callback(mods);
|
// callback(mods);
|
||||||
});
|
});
|
||||||
this.socket.on("serverManagerGetConfig", async (data, callback) => {
|
|
||||||
let config = await configManager.getConfig(data.instance);
|
|
||||||
callback(config);
|
|
||||||
});
|
|
||||||
this.socket.on("serverManagerEditConfig", async (data, callback) => {
|
|
||||||
callback(configManager.editConfig(data.instance, data.entry, data.value));
|
|
||||||
});
|
|
||||||
this.socket.on("serverManagerGetPlugins", async (data, callback) => {
|
this.socket.on("serverManagerGetPlugins", async (data, callback) => {
|
||||||
callback(await pluginManager.getPlugins());
|
callback(await pluginManager.getPlugins());
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -77,48 +77,9 @@ module.exports = that => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
that.app.post("/api/serverManager/editConfig", async (req,res) => {
|
|
||||||
if((req.body.token || req.cookies.token)
|
|
||||||
&& req.body.instanceID
|
|
||||||
&& typeof req.body.instanceID == "string"
|
|
||||||
&& req.body.entry
|
|
||||||
&& typeof req.body.entry == "string"
|
|
||||||
&& req.body.value !== undefined
|
|
||||||
&& that.playerManager){
|
|
||||||
let perms = await that.playerManager.main.getPermissions((req.body.token || req.cookies.token));
|
|
||||||
if(perms.cluster.includes("writeConfig")
|
|
||||||
|| (perms.instance[req.body.instanceID]
|
|
||||||
&& perms.instance[req.body.instanceID].includes("writeConfig"))){
|
|
||||||
that.serverSockets[req.body.instanceID].socket.emit("serverManagerEditConfig", {
|
|
||||||
entry: req.body.entry,
|
|
||||||
value: req.body.value,
|
|
||||||
}, async resp => {
|
|
||||||
if(resp.ok){
|
|
||||||
// Retrieve the latest config from the server and store it
|
|
||||||
await updateData("config", req.body.instanceID);
|
|
||||||
}
|
|
||||||
res.send(resp);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
res.send({
|
|
||||||
ok:false,
|
|
||||||
msg:"Insufficient permissions",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res.send({
|
|
||||||
ok:false,
|
|
||||||
msg:"Invalid request body",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
async function updateData(type, instanceID){
|
async function updateData(type, instanceID){
|
||||||
// Retrieve the latest ${type} from the server and store it
|
// Retrieve the latest ${type} from the server and store it
|
||||||
if(type == "config"){
|
if(type == "plugins"){
|
||||||
that.serverSockets[instanceID].socket.emit("serverManagerGetConfig", {}, data => {
|
|
||||||
that.serverSockets[instanceID].config = data;
|
|
||||||
});
|
|
||||||
} else if(type == "plugins"){
|
|
||||||
that.serverSockets[instanceID].socket.emit("serverManagerGetPlugins", {}, data => {
|
that.serverSockets[instanceID].socket.emit("serverManagerGetPlugins", {}, data => {
|
||||||
that.serverSockets[instanceID].plugins = data;
|
that.serverSockets[instanceID].plugins = data;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -63,9 +63,6 @@ class masterPlugin {
|
|||||||
server.socket.emit("serverManagerGetPlugins", {}, data => {
|
server.socket.emit("serverManagerGetPlugins", {}, data => {
|
||||||
server.plugins = data;
|
server.plugins = data;
|
||||||
});
|
});
|
||||||
server.socket.emit("serverManagerGetConfig", {}, data => {
|
|
||||||
server.config = data;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// I can't seem to get express static pages + ejs rendering to work properly, so I write my own thing.
|
// I can't seem to get express static pages + ejs rendering to work properly, so I write my own thing.
|
||||||
|
|||||||
@@ -26,23 +26,7 @@
|
|||||||
if(server.plugins) server.plugins.forEach(plugin => {
|
if(server.plugins) server.plugins.forEach(plugin => {
|
||||||
html += `<li><div class="pluginStatus" style="background-color: ${plugin.enabled ? 'green' : 'red'}"></div><div style="width: calc( 100% - 50px )"><h3>${plugin.name}</h3><p>${plugin.description}</p></div></li>`
|
html += `<li><div class="pluginStatus" style="background-color: ${plugin.enabled ? 'green' : 'red'}"></div><div style="width: calc( 100% - 50px )"><h3>${plugin.name}</h3><p>${plugin.description}</p></div></li>`
|
||||||
});
|
});
|
||||||
html += `</ul></div><div id="config">`
|
html += `</ul></div>`
|
||||||
if(permissions && permissions.cluster && permissions.cluster.includes("readConfig")){
|
|
||||||
if(server.config){
|
|
||||||
html += `<ul>`;
|
|
||||||
server.config.forEach(setting => {
|
|
||||||
if(setting.entry[1] !== "_" && setting.entry !== "masterAuthSecret"){
|
|
||||||
html += `<li class="settingInput">
|
|
||||||
<p style="width: 50%; display:inline-block;">${setting.entry}</p>
|
|
||||||
<input style="color:black; width: calc(50% - 4px); box-sizing: border-box;" value='${setting.value}'>
|
|
||||||
</li>`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
html += `</ul>
|
|
||||||
<input id="submitSettings" type="button" value="Save changes" style="color:black"/>
|
|
||||||
</div>`
|
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
<%- html %>
|
<%- html %>
|
||||||
|
|||||||
@@ -1,40 +1,3 @@
|
|||||||
// Handle config editing
|
|
||||||
originalSettings = {};
|
|
||||||
let settings = document.querySelectorAll(".settingInput");
|
|
||||||
settings.forEach(setting => {
|
|
||||||
let entry = setting.children[0].innerText
|
|
||||||
originalSettings[setting.children[0].innerText] = {
|
|
||||||
entry: setting.children[0].innerText,
|
|
||||||
value: setting.children[1].value,
|
|
||||||
}
|
|
||||||
setting.children[1].addEventListener("input", ()=>{
|
|
||||||
let newValue = setting.children[1].value;
|
|
||||||
if(newValue != originalSettings[entry].value){
|
|
||||||
setting.children[1].style.backgroundColor = "lightgreen";
|
|
||||||
} else {
|
|
||||||
setting.children[1].style.backgroundColor = "";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
let submitSettings = document.querySelector("#submitSettings");
|
|
||||||
submitSettings.addEventListener("click", async ()=>{
|
|
||||||
let settings = document.querySelectorAll(".settingInput");
|
|
||||||
for(let i = 0; i < settings.length; i++){
|
|
||||||
let setting = settings[i];
|
|
||||||
let entry = setting.children[0].innerText
|
|
||||||
if(setting.children[1].value != originalSettings[entry].value){
|
|
||||||
// upload new changes, display results somehow
|
|
||||||
let status = await postJSON("/api/serverManager/editConfig", {
|
|
||||||
entry,
|
|
||||||
value: setting.children[1].value,
|
|
||||||
instanceID: getParameterByName("instanceID"),
|
|
||||||
});
|
|
||||||
if(status.ok){
|
|
||||||
setting.children[1].style.backgroundColor = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Handle plugin management
|
// Handle plugin management
|
||||||
let pluginStatuses = document.querySelectorAll(".pluginStatus");
|
let pluginStatuses = document.querySelectorAll(".pluginStatus");
|
||||||
pluginStatuses.forEach(pluginStatus => {
|
pluginStatuses.forEach(pluginStatus => {
|
||||||
|
|||||||
@@ -6,10 +6,6 @@
|
|||||||
width:calc((( 100% ) - (( 100% ) / 4))/2);
|
width:calc((( 100% ) - (( 100% ) / 4))/2);
|
||||||
float:left;
|
float:left;
|
||||||
}
|
}
|
||||||
#config {
|
|
||||||
width:calc((( 100% ) - (( 100% ) / 4))/2);
|
|
||||||
float:left;
|
|
||||||
}
|
|
||||||
ul {
|
ul {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
padding:0px;
|
padding:0px;
|
||||||
|
|||||||
Reference in new issue
Block a user