mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 08:23:12 +09:00
Enable and disable plugins from the commandline (non functional as of yet)
This commit is contained in:
1 parent
e71c183b48
commit
a76e07c07b
4 files changed
+75
-11
No files matched your search
@@ -235,6 +235,12 @@ if (!command || command == "help" || command == "--help") {
|
|||||||
} else if(action == "remove" || action == "uninstall" || action == "delete"){
|
} else if(action == "remove" || action == "uninstall" || action == "delete"){
|
||||||
let status = await pluginManager.removePlugin(process.argv[6]);
|
let status = await pluginManager.removePlugin(process.argv[6]);
|
||||||
if(status && status.msg) console.log(status.msg);
|
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);
|
process.exit(0);
|
||||||
}catch(e){
|
}catch(e){
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ module.exports.editConfig = function(instance, entry, newValue){
|
|||||||
if(objectOps.isJSON(newValue)){
|
if(objectOps.isJSON(newValue)){
|
||||||
config[entry] = JSON.parse(newValue);
|
config[entry] = JSON.parse(newValue);
|
||||||
console.log("Changed config entry "+entry+" from "+JSON.stringify(config[entry])+" to "+JSON.stringify(newValue));
|
console.log("Changed config entry "+entry+" from "+JSON.stringify(config[entry])+" to "+JSON.stringify(newValue));
|
||||||
console.log("new config file:");
|
// console.log("new config file:");
|
||||||
console.log(JSON.stringify(config, null, " "))
|
// console.log(JSON.stringify(config, null, " "))
|
||||||
fs.writeFileSync("config.json", JSON.stringify(config, null, 4));
|
fs.writeFileSync("config.json", JSON.stringify(config, null, 4));
|
||||||
return {
|
return {
|
||||||
ok:true,
|
ok:true,
|
||||||
@@ -46,14 +46,24 @@ module.exports.editConfig = function(instance, entry, newValue){
|
|||||||
} else {
|
} else {
|
||||||
config[entry] = newValue;
|
config[entry] = newValue;
|
||||||
console.log("Changed config entry "+entry+" from "+config[entry]+" to '"+newValue+"'");
|
console.log("Changed config entry "+entry+" from "+config[entry]+" to '"+newValue+"'");
|
||||||
console.log("new config file:");
|
// console.log("new config file:");
|
||||||
console.log(JSON.stringify(config, null, " "))
|
// console.log(JSON.stringify(config, null, " "))
|
||||||
fs.writeFileSync("config.json", JSON.stringify(config, null, 4));
|
fs.writeFileSync("config.json", JSON.stringify(config, null, 4));
|
||||||
return {
|
return {
|
||||||
ok:true,
|
ok:true,
|
||||||
msg:`Changed config entry ${entry} from ***** to '${newValue}'`,
|
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`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -22,12 +22,20 @@ module.exports = function(config){
|
|||||||
// console.log(pluginContents)
|
// console.log(pluginContents)
|
||||||
if(pluginContents.includes("config.js") || pluginContents.includes("config.json")){
|
if(pluginContents.includes("config.js") || pluginContents.includes("config.json")){
|
||||||
try{
|
try{
|
||||||
let pluginConfig = require(path.join("./../../sharedPlugins", dir, "config"));
|
var pluginConfig = require(path.join("./../../sharedPlugins", dir, "config"));
|
||||||
pluginConfig.pluginPath = path.join("./sharedPlugins", dir);
|
pluginConfig.pluginPath = path.join("./sharedPlugins", dir);
|
||||||
returnArray.push(pluginConfig);
|
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.log(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;
|
return returnArray;
|
||||||
@@ -57,11 +65,52 @@ module.exports = function(config){
|
|||||||
msg:`Plugin matching "${name}" not found`,
|
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;
|
||||||
|
}
|
||||||
@@ -35,7 +35,6 @@
|
|||||||
"cookie-parser": "^1.4.3",
|
"cookie-parser": "^1.4.3",
|
||||||
"deepmerge": "^1.5.2",
|
"deepmerge": "^1.5.2",
|
||||||
"ejs": "^2.5.7",
|
"ejs": "^2.5.7",
|
||||||
"ejs-promise": "^0.3.3",
|
|
||||||
"express": "^4.16.2",
|
"express": "^4.16.2",
|
||||||
"express-fileupload": "0.0.6",
|
"express-fileupload": "0.0.6",
|
||||||
"express-prometheus-request-metrics": "github:burnash/express-prometheus-request-metrics",
|
"express-prometheus-request-metrics": "github:burnash/express-prometheus-request-metrics",
|
||||||
|
|||||||
Reference in new issue
Block a user