diff --git a/client.js b/client.js index 3acc337d..d12f7c0d 100644 --- a/client.js +++ b/client.js @@ -235,6 +235,12 @@ if (!command || command == "help" || command == "--help") { } else if(action == "remove" || action == "uninstall" || action == "delete"){ let status = await pluginManager.removePlugin(process.argv[6]); if(status && status.msg) console.log(status.msg); + } else if(action == "enable"){ + let status = await pluginManager.enablePlugin(process.argv[6]); + if(status && status.msg) console.log(status.msg); + } else if(action == "disable"){ + let status = await pluginManager.disablePlugin(process.argv[6]); + if(status && status.msg) console.log(status.msg); } process.exit(0); }catch(e){ diff --git a/lib/manager/configManager.js b/lib/manager/configManager.js index 1beceb26..ab6034e2 100644 --- a/lib/manager/configManager.js +++ b/lib/manager/configManager.js @@ -36,8 +36,8 @@ module.exports.editConfig = function(instance, 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, " ")) + // console.log("new config file:"); + // console.log(JSON.stringify(config, null, " ")) fs.writeFileSync("config.json", JSON.stringify(config, null, 4)); return { ok:true, @@ -46,14 +46,24 @@ module.exports.editConfig = function(instance, entry, 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, " ")) + // 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/lib/manager/pluginManager.js b/lib/manager/pluginManager.js index 3eff4035..eaff30c0 100644 --- a/lib/manager/pluginManager.js +++ b/lib/manager/pluginManager.js @@ -22,12 +22,20 @@ module.exports = function(config){ // console.log(pluginContents) if(pluginContents.includes("config.js") || pluginContents.includes("config.json")){ try{ - let pluginConfig = require(path.join("./../../sharedPlugins", dir, "config")); + var pluginConfig = require(path.join("./../../sharedPlugins", dir, "config")); pluginConfig.pluginPath = path.join("./sharedPlugins", dir); - returnArray.push(pluginConfig); }catch(e){ console.log(e) - } + } + + fs.stat(path.join(pluginConfig.pluginPath, "DISABLED"), (err, stat)=>{ + if(err){ + pluginConfig.enabled = true; + } else { + pluginConfig.enabled = false; + } + }); + returnArray.push(pluginConfig); } } return returnArray; @@ -57,11 +65,52 @@ module.exports = function(config){ msg:`Plugin matching "${name}" not found`, } }, - enablePlugin: function(){ - + enablePlugin: async function(name, instance){ + let plugins = await this.getPlugins(); + let plugin = plugins[findInArray("name", name, plugins)[0]]; + if(plugin){ + let files = await fs.readdir(plugin.pluginPath); + if(files.includes("DISABLED")){ + await fs.unlink(path.join(plugin.pluginPath, "DISABLED")); + return { + ok:true, + msg:`Globally enabled plugin ${name}`, + } + } else { + return { + ok:true, + msg:`Plugin ${name} already enabled`, + } + } + } else { + return { + ok:false, + msg:`Found no excact match for plugin ${name}`, + } + } }, - disablePlugin: function(){ - + disablePlugin: async function(name, instance){ + let plugins = await this.getPlugins(); + let plugin = plugins[findInArray("name", name, plugins)[0]]; + if(plugin){ + await fs.writeFile(path.join(plugin.pluginPath, "DISABLED"), ""); + return { + ok:true, + msg:`Plugin ${name} is now disabled on this host`, + } + } else { + return { + ok:false, + msg:`Found no excact match for plugin ${name}`, + } + } } } } +function findInArray(key, value, array){ + let indexes = []; + for(let i in array){ + if(array[i][key] && array[i][key] === value) indexes.push(i); + } + return indexes; +} diff --git a/package.json b/package.json index 78b56bb0..d8d6b585 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "cookie-parser": "^1.4.3", "deepmerge": "^1.5.2", "ejs": "^2.5.7", - "ejs-promise": "^0.3.3", "express": "^4.16.2", "express-fileupload": "0.0.6", "express-prometheus-request-metrics": "github:burnash/express-prometheus-request-metrics",