Merge pull request #235 from Hornwitser/config-part-3

Config Rewrite Part 3
This commit is contained in:
Arvids Godjuks authored and GitHub committed 2019-09-18 14:06:50 +02:00
commit e15462439a
14 files changed
+529 -574

No files matched your search

+2 -10
View File
@@ -10,8 +10,7 @@ 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);
// const modManager = require("lib/manager/modManager");
this.socket.on("hello", () => {
this.socket.emit("registerServerManager");
});
@@ -20,16 +19,9 @@ module.exports = class remoteCommands {
});
this.socket.on("serverManagerGetMods", async (data, callback) => {
// TODO: Implement this function separately from listMods (which console.logs it)
// let mods = modManager.getMods()
// let mods = modManager.getMods(this.config)
// 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());
});
@@ -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;
});
@@ -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.
+1 -17
View File
@@ -26,23 +26,7 @@
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 += `</ul></div><div id="config">`
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 += `</ul></div>`
}
%>
<%- 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
let pluginStatuses = document.querySelectorAll(".pluginStatus");
pluginStatuses.forEach(pluginStatus => {
@@ -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;