From 5f33cf4d3b0bbb1bb1e3fd843a4bf55dc750cadf Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Thu, 12 Sep 2019 15:35:22 +0200 Subject: [PATCH] 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. --- .travis.yml | 2 - CHANGELOG.md | 1 + client.js | 22 +----- lib/manager/configManager.js | 69 ------------------- sharedPlugins/serverManager/index.js | 8 --- .../serverManager/js/api-endpoints.js | 41 +---------- sharedPlugins/serverManager/masterPlugin.js | 3 - sharedPlugins/serverManager/static/index.html | 18 +---- sharedPlugins/serverManager/static/index.js | 37 ---------- .../serverManager/static/serverManager.css | 4 -- 10 files changed, 4 insertions(+), 201 deletions(-) delete mode 100644 lib/manager/configManager.js diff --git a/.travis.yml b/.travis.yml index f7059a13..31d07777 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,6 @@ before_install: - curl -o factorio.tar.gz -L https://www.factorio.com/get-download/latest/headless/linux64 - tar -xf factorio.tar.gz - npm install -g codecov - # Needed for lib/manager/configManager - - echo {} > config.json script: - npm run-script ci-cover - codecov -f coverage/lcov.info diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a267ed0..bccfa8b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Version 2.0.0 Breaks discordChat, playerManager, serverSelect, trainTeleports and clusterioModel. - 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 diff --git a/client.js b/client.js index c2055dc7..8bc3bce3 100644 --- a/client.js +++ b/client.js @@ -20,7 +20,6 @@ const crypto = require("crypto"); const objectOps = require("lib/objectOps.js"); const fileOps = require("lib/fileOps"); const stringUtils = require("lib/stringUtils.js"); -const configManager = require("lib/manager/configManager.js"); const pluginManager = require("lib/manager/pluginManager"); const hashFile = require('lib/hash').hashFile; @@ -235,12 +234,10 @@ async function manage(config, instance) { function usage(instance, tool, action){ if(tool && tool == "mods"){ 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") { console.log(`node client.js manage ${instance.name} ${tool} ["list", "add", "remove"]`); } 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] || ""; @@ -268,23 +265,6 @@ async function manage(config, instance) { console.log("Got error from modManager:") 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"){ (async function(){try{ if(action == "list"){ diff --git a/lib/manager/configManager.js b/lib/manager/configManager.js deleted file mode 100644 index ab6034e2..00000000 --- a/lib/manager/configManager.js +++ /dev/null @@ -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`, - } - } -}; diff --git a/sharedPlugins/serverManager/index.js b/sharedPlugins/serverManager/index.js index 82202ceb..4734b88d 100644 --- a/sharedPlugins/serverManager/index.js +++ b/sharedPlugins/serverManager/index.js @@ -10,7 +10,6 @@ module.exports = class remoteCommands { this.config = mergedConfig; this.socket = extras.socket; const pluginManager = require("lib/manager/pluginManager.js"); - const configManager = require("lib/manager/configManager.js"); // const modManager = require("lib/manager/modManager.js")(this.config); this.socket.on("hello", () => { this.socket.emit("registerServerManager"); @@ -23,13 +22,6 @@ module.exports = class remoteCommands { // let mods = modManager.getMods() // 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) => { callback(await pluginManager.getPlugins()); }); diff --git a/sharedPlugins/serverManager/js/api-endpoints.js b/sharedPlugins/serverManager/js/api-endpoints.js index 6c3301ef..40cd7c7e 100644 --- a/sharedPlugins/serverManager/js/api-endpoints.js +++ b/sharedPlugins/serverManager/js/api-endpoints.js @@ -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){ // Retrieve the latest ${type} from the server and store it - if(type == "config"){ - that.serverSockets[instanceID].socket.emit("serverManagerGetConfig", {}, data => { - that.serverSockets[instanceID].config = data; - }); - } else if(type == "plugins"){ + if(type == "plugins"){ that.serverSockets[instanceID].socket.emit("serverManagerGetPlugins", {}, data => { that.serverSockets[instanceID].plugins = data; }); diff --git a/sharedPlugins/serverManager/masterPlugin.js b/sharedPlugins/serverManager/masterPlugin.js index cfe7e2a3..e972283d 100644 --- a/sharedPlugins/serverManager/masterPlugin.js +++ b/sharedPlugins/serverManager/masterPlugin.js @@ -63,9 +63,6 @@ class masterPlugin { server.socket.emit("serverManagerGetPlugins", {}, 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. diff --git a/sharedPlugins/serverManager/static/index.html b/sharedPlugins/serverManager/static/index.html index 5af40484..0dd92458 100644 --- a/sharedPlugins/serverManager/static/index.html +++ b/sharedPlugins/serverManager/static/index.html @@ -26,23 +26,7 @@ if(server.plugins) server.plugins.forEach(plugin => { html += `
  • ${plugin.name}

    ${plugin.description}

  • ` }); - html += `
    ` - if(permissions && permissions.cluster && permissions.cluster.includes("readConfig")){ - if(server.config){ - html += ` - -
    ` + html += `` } %> <%- html %> diff --git a/sharedPlugins/serverManager/static/index.js b/sharedPlugins/serverManager/static/index.js index 8c893dbf..478ccfcc 100644 --- a/sharedPlugins/serverManager/static/index.js +++ b/sharedPlugins/serverManager/static/index.js @@ -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 let pluginStatuses = document.querySelectorAll(".pluginStatus"); pluginStatuses.forEach(pluginStatus => { diff --git a/sharedPlugins/serverManager/static/serverManager.css b/sharedPlugins/serverManager/static/serverManager.css index 7a610d99..99b0142b 100644 --- a/sharedPlugins/serverManager/static/serverManager.css +++ b/sharedPlugins/serverManager/static/serverManager.css @@ -6,10 +6,6 @@ width:calc((( 100% ) - (( 100% ) / 4))/2); float:left; } -#config { - width:calc((( 100% ) - (( 100% ) / 4))/2); - float:left; -} ul { list-style: none; padding:0px;