Improved agent meshcore self-update debugging.

This commit is contained in:
Ylian Saint-Hilaire 2021-03-04 16:27:43 -08:00
parent 67c28658fe
commit 77e3acad08
6 changed files with 1709 additions and 1676 deletions

View File

@ -113,7 +113,7 @@ function run(argv) {
//console.log('addedModules = ' + JSON.stringify(addedModules)); //console.log('addedModules = ' + JSON.stringify(addedModules));
var actionpath = 'meshaction.txt'; var actionpath = 'meshaction.txt';
if (args.actionfile != null) { actionpath = args.actionfile; } if (args.actionfile != null) { actionpath = args.actionfile; }
var actions = ['HELP', 'ROUTE', 'MICROLMS', 'AMTCONFIG', 'AMTSCAN', 'AMTPOWER', 'AMTFEATURES', 'AMTNETWORK', 'AMTLOADWEBAPP', 'AMTLOADSMALLWEBAPP', 'AMTLOADLARGEWEBAPP', 'AMTCLEARWEBAPP', 'AMTSTORAGESTATE', 'AMTINFO', 'AMTINFODEBUG', 'AMTVERSIONS', 'AMTHASHES', 'AMTSAVESTATE', 'AMTUUID', 'AMTCCM', 'AMTDEACTIVATE', 'AMTACMDEACTIVATE', 'SMBIOS', 'RAWSMBIOS', 'MESHCOMMANDER', 'AMTAUDITLOG', 'AMTEVENTLOG', 'AMTPRESENCE', 'AMTWIFI', 'AMTWAKE']; var actions = ['HELP', 'ROUTE', 'MICROLMS', 'AMTCONFIG', 'AMTSCAN', 'AMTPOWER', 'AMTFEATURES', 'AMTNETWORK', 'AMTLOADWEBAPP', 'AMTLOADSMALLWEBAPP', 'AMTLOADLARGEWEBAPP', 'AMTCLEARWEBAPP', 'AMTSTORAGESTATE', 'AMTINFO', 'AMTINFODEBUG', 'AMTVERSIONS', 'AMTHASHES', 'AMTSAVESTATE', 'AMTUUID', 'AMTCCM', 'AMTDEACTIVATE', 'AMTACMDEACTIVATE', 'SMBIOS', 'RAWSMBIOS', 'MESHCOMMANDER', 'AMTAUDITLOG', 'AMTEVENTLOG', 'AMTPRESENCE', 'AMTWIFI', 'AMTWAKE', 'AMTSTOPCONFIGURATION'];
// Load the action file // Load the action file
var actionfile = null; var actionfile = null;
@ -428,7 +428,19 @@ function run(argv) {
console.log('Proxy set to ' + proxy[0] + ':' + proxyport); console.log('Proxy set to ' + proxy[0] + ':' + proxyport);
} }
if (settings.action == 'smbios') { if (settings.action == 'amtstopconfiguration') {
// Stop Intel AMT configuration
var amtMeiModule, amtMei;
try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
amtMei.stopConfiguration(function (state) {
if (state == 3) { console.log("Intel AMT is not in in-provisionning mode."); }
else if (state == 1) { console.log("Intel AMT internal error."); }
else if (state == 0) { console.log("Success."); }
else { console.log("Unknown state: " + state); }
exit(1);
});
} else if (settings.action == 'smbios') {
// Display SM BIOS tables in raw form // Display SM BIOS tables in raw form
SMBiosTables = require('smbios'); SMBiosTables = require('smbios');
SMBiosTables.get(function (data) { SMBiosTables.get(function (data) {

View File

@ -2751,7 +2751,11 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
break; break;
case 'agentupdateex': case 'agentupdateex':
// Perform an direct agent update without requesting any information from the server, this should not typically be used. // Perform an direct agent update without requesting any information from the server, this should not typically be used.
if (args['_'].length == 1) {
if (args['_'][0].startsWith('https://')) { agentUpdate_Start(args['_'][0], { sessionid: sessionid }); } else { response = "Usage: agentupdateex https://server/path"; }
} else {
agentUpdate_Start(null, { sessionid: sessionid }); agentUpdate_Start(null, { sessionid: sessionid });
}
break; break;
case 'msh': case 'msh':
response = JSON.stringify(_MSH(), null, 2); response = JSON.stringify(_MSH(), null, 2);
@ -4139,8 +4143,10 @@ function agentUpdate_Start(updateurl, updateoptions) {
var sessionid = (updateoptions != null) ? updateoptions.sessionid : null; // If this is null, messages will be broadcast. Otherwise they will be unicasted var sessionid = (updateoptions != null) ? updateoptions.sessionid : null; // If this is null, messages will be broadcast. Otherwise they will be unicasted
// If the url starts with *, switch it to use the same protoco, host and port as the control channel. // If the url starts with *, switch it to use the same protoco, host and port as the control channel.
if (updateurl != null) {
updateurl = getServerTargetUrlEx(updateurl); updateurl = getServerTargetUrlEx(updateurl);
if (updateurl.startsWith("wss://")) { updateurl = "https://" + updateurl.substring(6); } if (updateurl.startsWith("wss://")) { updateurl = "https://" + updateurl.substring(6); }
}
if (agentUpdate_Start._selfupdate != null) { if (agentUpdate_Start._selfupdate != null) {
// We were already called, so we will ignore this duplicate request // We were already called, so we will ignore this duplicate request
@ -4171,10 +4177,10 @@ function agentUpdate_Start(updateurl, updateoptions) {
return; return;
} }
if (sessionid != null) { sendConsoleText('Downloading update from: ' + updateurl, sessionid); } if ((sessionid != null) && (updateurl != null)) { sendConsoleText('Downloading update from: ' + updateurl, sessionid); }
var options = require('http').parseUri(updateurl != null ? updateurl : require('MeshAgent').ServerUrl); var options = require('http').parseUri(updateurl != null ? updateurl : require('MeshAgent').ServerUrl);
options.protocol = 'https:'; options.protocol = 'https:';
if (updateurl == null) { options.path = ('/meshagents?id=' + require('MeshAgent').ARCHID); } if (updateurl == null) { options.path = ('/meshagents?id=' + require('MeshAgent').ARCHID); sendConsoleText('Downloading update from: ' + options.path, sessionid); }
options.rejectUnauthorized = false; options.rejectUnauthorized = false;
options.checkServerIdentity = function checkServerIdentity(certs) { options.checkServerIdentity = function checkServerIdentity(certs) {
// If the tunnel certificate matches the control channel certificate, accept the connection // If the tunnel certificate matches the control channel certificate, accept the connection

View File

@ -353,8 +353,10 @@ function agentUpdate_Start(updateurl, updateoptions) {
var sessionid = (updateoptions != null) ? updateoptions.sessionid : null; // If this is null, messages will be broadcast. Otherwise they will be unicasted var sessionid = (updateoptions != null) ? updateoptions.sessionid : null; // If this is null, messages will be broadcast. Otherwise they will be unicasted
// If the url starts with *, switch it to use the same protoco, host and port as the control channel. // If the url starts with *, switch it to use the same protoco, host and port as the control channel.
if (updateurl != null) {
updateurl = getServerTargetUrlEx(updateurl); updateurl = getServerTargetUrlEx(updateurl);
if (updateurl.startsWith("wss://")) { updateurl = "https://" + updateurl.substring(6); } if (updateurl.startsWith("wss://")) { updateurl = "https://" + updateurl.substring(6); }
}
if (agentUpdate_Start._selfupdate != null) { if (agentUpdate_Start._selfupdate != null) {
// We were already called, so we will ignore this duplicate request // We were already called, so we will ignore this duplicate request
@ -385,10 +387,10 @@ function agentUpdate_Start(updateurl, updateoptions) {
return; return;
} }
if (sessionid != null) { sendConsoleText('Downloading update from: ' + updateurl, sessionid); } if ((sessionid != null) && (updateurl != null)) { sendConsoleText('Downloading update from: ' + updateurl, sessionid); }
var options = require('http').parseUri(updateurl != null ? updateurl : require('MeshAgent').ServerUrl); var options = require('http').parseUri(updateurl != null ? updateurl : require('MeshAgent').ServerUrl);
options.protocol = 'https:'; options.protocol = 'https:';
if (updateurl == null) { options.path = ('/meshagents?id=' + require('MeshAgent').ARCHID); } if (updateurl == null) { options.path = ('/meshagents?id=' + require('MeshAgent').ARCHID); sendConsoleText('Downloading update from: ' + options.path, sessionid); }
options.rejectUnauthorized = false; options.rejectUnauthorized = false;
options.checkServerIdentity = function checkServerIdentity(certs) { options.checkServerIdentity = function checkServerIdentity(certs) {
// If the tunnel certificate matches the control channel certificate, accept the connection // If the tunnel certificate matches the control channel certificate, accept the connection
@ -1002,7 +1004,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
var response = null; var response = null;
switch (cmd) { switch (cmd) {
case 'help': case 'help':
response = "Available commands are: agentupdate, dbkeys, dbget, dbset, dbcompact, eval, netinfo, osinfo, setdebug, versions."; response = "Available commands are: agentupdate, agentupdateex, dbkeys, dbget, dbset, dbcompact, eval, netinfo, osinfo, setdebug, versions.";
break; break;
case '_descriptors': case '_descriptors':
response = 'Open Descriptors: ' + JSON.stringify(getOpenDescriptors()); response = 'Open Descriptors: ' + JSON.stringify(getOpenDescriptors());
@ -1016,7 +1018,11 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
break; break;
case 'agentupdateex': case 'agentupdateex':
// Perform an direct agent update without requesting any information from the server, this should not typically be used. // Perform an direct agent update without requesting any information from the server, this should not typically be used.
if (args['_'].length == 1) {
if (args['_'][0].startsWith('https://')) { agentUpdate_Start(args['_'][0], { sessionid: sessionid }); } else { response = "Usage: agentupdateex https://server/path"; }
} else {
agentUpdate_Start(null, { sessionid: sessionid }); agentUpdate_Start(null, { sessionid: sessionid });
}
break; break;
case 'eval': case 'eval':
{ // Eval JavaScript { // Eval JavaScript

View File

@ -1170,6 +1170,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
obj.agentCoreUpdateTaskId = taskid; obj.agentCoreUpdateTaskId = taskid;
const url = '*' + require('url').parse(obj.agentExeInfo.url).path; const url = '*' + require('url').parse(obj.agentExeInfo.url).path;
var cmd = { action: 'agentupdate', url: url, hash: obj.agentExeInfo.hashhex }; var cmd = { action: 'agentupdate', url: url, hash: obj.agentExeInfo.hashhex };
parent.parent.debug('agentupdate', "Sending agent update url: " + cmd.url);
// Add the hash // Add the hash
if (obj.agentExeInfo.fileHash != null) { cmd.hash = obj.agentExeInfo.fileHashHex; } else { cmd.hash = obj.agentExeInfo.hashhex; } if (obj.agentExeInfo.fileHash != null) { cmd.hash = obj.agentExeInfo.fileHashHex; } else { cmd.hash = obj.agentExeInfo.hashhex; }
@ -1486,6 +1487,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
obj.agentCoreUpdateTaskId = taskid; obj.agentCoreUpdateTaskId = taskid;
const url = '*' + require('url').parse(obj.agentExeInfo.url).path; const url = '*' + require('url').parse(obj.agentExeInfo.url).path;
var cmd = { action: 'agentupdate', url: url, hash: obj.agentExeInfo.hashhex, sessionid: agentUpdateFunc.sessionid }; var cmd = { action: 'agentupdate', url: url, hash: obj.agentExeInfo.hashhex, sessionid: agentUpdateFunc.sessionid };
parent.parent.debug('agentupdate', "Sending user requested agent update url: " + cmd.url);
// Add the hash // Add the hash
if (obj.agentExeInfo.fileHash != null) { cmd.hash = obj.agentExeInfo.fileHashHex; } else { cmd.hash = obj.agentExeInfo.hashhex; } if (obj.agentExeInfo.fileHash != null) { cmd.hash = obj.agentExeInfo.fileHashHex; } else { cmd.hash = obj.agentExeInfo.hashhex; }

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff