Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow msh get/set/delete from console #6074

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion agents/meshcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4142,7 +4142,67 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
}
break;
case 'msh':
response = JSON.stringify(_MSH(), null, 2);
if (args['_'].length == 0) {
response = JSON.stringify(_MSH(), null, 2);
} else if (args['_'].length > 3) {
response = 'Proper usage: msh [get|set|delete]\r\nmsh get MeshServer\r\nmsh set abc "xyz"\r\nmsh delete abc';
} else {
var mshFileName = process.execPath.replace('.exe','') + '.msh';
switch (args['_'][0].toLocaleLowerCase()) {
case 'get':
if (typeof args['_'][1] != 'string' || args['_'].length > 2) {
response = 'Proper usage: msh get MeshServer';
} else if(_MSH()[args['_'][1]]) {
response = _MSH()[args['_'][1]];
} else {
response = "Unknown Value: " + args['_'][1];
}
break;
case 'set':
if (typeof args['_'][1] != 'string' || typeof args['_'][2] != 'string') {
response = 'Proper usage: msh set abc "xyz"';
} else {
var jsonToSave = _MSH();
jsonToSave[args['_'][1]] = args['_'][2];
var updatedContent = '';
for (var key in jsonToSave) {
if (jsonToSave.hasOwnProperty(key)) {
updatedContent += key + '=' + jsonToSave[key] + '\n';
}
}
try {
require('fs').writeFileSync(mshFileName, updatedContent);
response = "msh set " + args['_'][1] + " successful"
} catch (ex) {
response = "msh set " + args['_'][1] + " unsuccessful";
}
}
break;
case 'delete':
if (typeof args['_'][1] != 'string') {
response = 'Proper usage: msh delete abc';
} else {
var jsonToSave = _MSH();
delete jsonToSave[args['_'][1]];
var updatedContent = '';
for (var key in jsonToSave) {
if (jsonToSave.hasOwnProperty(key)) {
updatedContent += key + '=' + jsonToSave[key] + '\n';
}
}
try {
require('fs').writeFileSync(mshFileName, updatedContent);
response = "msh delete " + args['_'][1] + " successful"
} catch (ex) {
response = "msh delete " + args['_'][1] + " unsuccessful";
}
}
break;
default:
response = 'Proper usage: msh [get|set|delete]\r\nmsh get MeshServer\r\nmsh set abc "xyz"\r\nmsh delete abc';
break;
}
}
break;
case 'dnsinfo':
if (require('os').dns == null) {
Expand Down
Loading