Improved MeshCmd.exe.
Ylian Saint-Hilaire committed
Jan 25, 2018 at 16:28 UTC
63e342646d4b71596b39c578a42e18cb8b6dc5b1
1 file changed
+67
-53
agents/meshcmd.js
+67
-53
@@ -94,6 +94,8 @@ function run(argv) {
94
if ((typeof args.out) == 'string') { settings.output = args.out; }
95
if ((typeof args.output) == 'string') { settings.output = args.output; }
96
if ((typeof args.debug) == 'string') { settings.debugLevel = parseInt(args.debug); }
97
+ if (args.noconsole) { settings.noconsole = true; }
98
+ if (args.nocommander) { settings.noconsole = true; }
99
if (args.lmsdebug) { settings.lmsdebug = true; }
100
if (args.tls) { settings.tls = true; }
101
if ((argv.length > 1) && (actions.indexOf(argv[1].toUpperCase()) >= 0)) { settings.action = argv[1]; }
@@ -133,7 +135,7 @@ function run(argv) {
135
} else if ((settings.action == 'meversion') || (settings.action == 'meversions') || (settings.action == 'mever')) {
136
var amtMeiModule = require('amt_heci');
137
var amtMei = new amtMeiModule();
136
- amtMei.on('error', function (e) { console.log(e); exit(1); return; });
138
+ amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
139
amtMei.on('connect', function () {
140
this.getVersion(function (val) {
141
console.log("MEI Version = " + val.BiosVersion.toString());
@@ -144,14 +146,14 @@ function run(argv) {
146
} else if (settings.action == 'mehashes') {
147
var amtMeiModule = require('amt_heci');
148
var amtMei = new amtMeiModule();
147
- amtMei.on('error', function (e) { console.log(e); exit(1); return; });
149
+ amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
150
amtMei.on('connect', function () {
151
this.getHashHandles(function (handles) {
152
exitOnCount = handles.length;
153
for (var i = 0; i < handles.length; ++i) {
154
this.getCertHashEntry(handles[i], function (result) {
153
- console.log('----------\r\n' + result.name + ', (' + (result.isDefault ? 'Default' : '') + (result.isActive ? ', Active' : ', Disabled') + ')\r\n' + result.hashAlgorithmStr + ': ' + result.certificateHash);
154
- if (--exitOnCount == 0) { console.log('----------'); exit(1); }
155
+ console.log(result.name + ', (' + (result.isDefault ? 'Default' : '') + (result.isActive ? ', Active' : ', Disabled') + ')\r\n ' + result.hashAlgorithmStr + ': ' + result.certificateHash);
156
+ if (--exitOnCount == 0) { exit(1); }
157
});
158
}
159
});
@@ -159,7 +161,7 @@ function run(argv) {
161
} else if (settings.action == 'meinfo') {
162
var amtMeiModule = require('amt_heci');
163
var amtMei = new amtMeiModule();
162
- amtMei.on('error', function (e) { console.log(e); exit(1); return; });
164
+ amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
165
amtMei.on('connect', function () {
166
mestate = {};
167
this.getVersion(function (val) { for (var version in val.Versions) { if (val.Versions[version].Description == 'AMT') { mestate.ver = val.Versions[version].Version; } } });
@@ -189,7 +191,7 @@ function run(argv) {
191
debug(1, "Settings: " + JSON.stringify(settings));
192
saveEntireAmtState();
193
} else if (settings.action == 'amtlms') {
192
- startLms();
194
+ startLms(function (state) { console.log(['MicroLMS did not start. MicroLMS must run as administrator or LMS any already be active.', 'MicroLMS started.', 'MicroLMS started, MeshCommander on HTTP/16994.'][state]); if (state == 0) { exit(0); } });
195
} else {
196
console.log('Invalid \"action\" specified.'); exit(1); return;
197
}
@@ -197,17 +199,19 @@ function run(argv) {
199
200
// Save the entire Intel AMT state
201
function saveEntireAmtState() {
202
+ // See if MicroLMS needs to be started
203
+ if ((settings.hostname == '127.0.0.1') || (settings.hostname.toLowerCase() == 'localhost')) { settings.noconsole = true; startLms(); }
204
+
205
console.log('Fetching all Intel AMT state, this may take a few minutes...');
206
var transport = require('amt-wsman-duk-0.2.0');
207
var wsman = require('amt-wsman-0.2.0');
208
var amt = require('amt-0.2.0');
209
wsstack = new wsman(transport, settings.hostname, settings.tls?16993:16992, settings.username, settings.password, settings.tls);
210
amtstack = new amt(wsstack);
206
- //amtstack.onProcessChanged = onWsmanProcessChanged;
207
- //amtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], onWsmanResponse);
208
-
209
- //var AllWsman = "CIM_Controller,CIM_CoolingDevice".split(',');
211
+ amtstack.onProcessChanged = onWsmanProcessChanged;
212
+ //var AllWsman = "AMT_GeneralSystemDefenseCapabilities".split(',');
213
var AllWsman = "AMT_8021xCredentialContext,AMT_8021XProfile,AMT_ActiveFilterStatistics,AMT_AgentPresenceCapabilities,AMT_AgentPresenceInterfacePolicy,AMT_AgentPresenceService,AMT_AgentPresenceWatchdog,AMT_AgentPresenceWatchdogAction,AMT_AlarmClockService,IPS_AlarmClockOccurrence,AMT_AssetTable,AMT_AssetTableService,AMT_AuditLog,AMT_AuditPolicyRule,AMT_AuthorizationService,AMT_BootCapabilities,AMT_BootSettingData,AMT_ComplexFilterEntryBase,AMT_CRL,AMT_CryptographicCapabilities,AMT_EACCredentialContext,AMT_EndpointAccessControlService,AMT_EnvironmentDetectionInterfacePolicy,AMT_EnvironmentDetectionSettingData,AMT_EthernetPortSettings,AMT_EventLogEntry,AMT_EventManagerService,AMT_EventSubscriber,AMT_FilterEntryBase,AMT_FilterInSystemDefensePolicy,AMT_GeneralSettings,AMT_GeneralSystemDefenseCapabilities,AMT_Hdr8021Filter,AMT_HeuristicPacketFilterInterfacePolicy,AMT_HeuristicPacketFilterSettings,AMT_HeuristicPacketFilterStatistics,AMT_InterfacePolicy,AMT_IPHeadersFilter,AMT_KerberosSettingData,AMT_ManagementPresenceRemoteSAP,AMT_MessageLog,AMT_MPSUsernamePassword,AMT_NetworkFilter,AMT_NetworkPortDefaultSystemDefensePolicy,AMT_NetworkPortSystemDefenseCapabilities,AMT_NetworkPortSystemDefensePolicy,AMT_PCIDevice,AMT_PETCapabilities,AMT_PETFilterForTarget,AMT_PETFilterSetting,AMT_ProvisioningCertificateHash,AMT_PublicKeyCertificate,AMT_PublicKeyManagementCapabilities,AMT_PublicKeyManagementService,AMT_PublicPrivateKeyPair,AMT_RedirectionService,AMT_RemoteAccessCapabilities,AMT_RemoteAccessCredentialContext,AMT_RemoteAccessPolicyAppliesToMPS,AMT_RemoteAccessPolicyRule,AMT_RemoteAccessService,AMT_SetupAndConfigurationService,AMT_SNMPEventSubscriber,AMT_StateTransitionCondition,AMT_SystemDefensePolicy,AMT_SystemDefensePolicyInService,AMT_SystemDefenseService,AMT_SystemPowerScheme,AMT_ThirdPartyDataStorageAdministrationService,AMT_ThirdPartyDataStorageService,AMT_TimeSynchronizationService,AMT_TLSCredentialContext,AMT_TLSProtocolEndpoint,AMT_TLSProtocolEndpointCollection,AMT_TLSSettingData,AMT_TrapTargetForService,AMT_UserInitiatedConnectionService,AMT_WebUIService,AMT_WiFiPortConfigurationService,CIM_AbstractIndicationSubscription,CIM_Account,CIM_AccountManagementCapabilities,CIM_AccountManagementService,CIM_AccountOnSystem,CIM_AdminDomain,CIM_AlertIndication,CIM_AssignedIdentity,CIM_AssociatedPowerManagementService,CIM_AuthenticationService,CIM_AuthorizationService,CIM_BIOSElement,CIM_BIOSFeature,CIM_BIOSFeatureBIOSElements,CIM_BootConfigSetting,CIM_BootService,CIM_BootSettingData,CIM_BootSourceSetting,CIM_Capabilities,CIM_Card,CIM_Chassis,CIM_Chip,CIM_Collection,CIM_Component,CIM_ComputerSystem,CIM_ComputerSystemPackage,CIM_ConcreteComponent,CIM_ConcreteDependency,CIM_Controller,CIM_CoolingDevice,CIM_Credential,CIM_CredentialContext,CIM_CredentialManagementService,CIM_Dependency,CIM_DeviceSAPImplementation,CIM_ElementCapabilities,CIM_ElementConformsToProfile,CIM_ElementLocation,CIM_ElementSettingData,CIM_ElementSoftwareIdentity,CIM_ElementStatisticalData,CIM_EnabledLogicalElement,CIM_EnabledLogicalElementCapabilities,CIM_EthernetPort,CIM_Fan,CIM_FilterCollection,CIM_FilterCollectionSubscription,CIM_HostedAccessPoint,CIM_HostedDependency,CIM_HostedService,CIM_Identity,CIM_IEEE8021xCapabilities,CIM_IEEE8021xSettings,CIM_Indication,CIM_IndicationService,CIM_InstalledSoftwareIdentity,CIM_KVMRedirectionSAP,CIM_LANEndpoint,CIM_ListenerDestination,CIM_ListenerDestinationWSManagement,CIM_Location,CIM_Log,CIM_LogEntry,CIM_LogicalDevice,CIM_LogicalElement,CIM_LogicalPort,CIM_LogicalPortCapabilities,CIM_LogManagesRecord,CIM_ManagedCredential,CIM_ManagedElement,CIM_ManagedSystemElement,CIM_MediaAccessDevice,CIM_MemberOfCollection,CIM_Memory,CIM_MessageLog,CIM_NetworkPort,CIM_NetworkPortCapabilities,CIM_NetworkPortConfigurationService,CIM_OrderedComponent,CIM_OwningCollectionElement,CIM_OwningJobElement,CIM_PCIController,CIM_PhysicalComponent,CIM_PhysicalElement,CIM_PhysicalElementLocation,CIM_PhysicalFrame,CIM_PhysicalMemory,CIM_PhysicalPackage,CIM_Policy,CIM_PolicyAction,CIM_PolicyCondition,CIM_PolicyInSystem,CIM_PolicyRule,CIM_PolicyRuleInSystem,CIM_PolicySet,CIM_PolicySetAppliesToElement,CIM_PolicySetInSystem,CIM_PowerManagementCapabilities,CIM_PowerManagementService,CIM_PowerSupply,CIM_Privilege,CIM_PrivilegeManagementCapabilities,CIM_PrivilegeManagementService,CIM_ProcessIndication,CIM_Processor,CIM_ProtocolEndpoint,CIM_ProvidesServiceToElement,CIM_Realizes,CIM_RecordForLog,CIM_RecordLog,CIM_RedirectionService,CIM_ReferencedProfile,CIM_RegisteredProfile,CIM_RemoteAccessAvailableToElement,CIM_RemoteIdentity,CIM_RemotePort,CIM_RemoteServiceAccessPoint,CIM_Role,CIM_RoleBasedAuthorizationService,CIM_RoleBasedManagementCapabilities,CIM_RoleLimitedToTarget,CIM_SAPAvailableForElement,CIM_SecurityService,CIM_Sensor,CIM_Service,CIM_ServiceAccessBySAP,CIM_ServiceAccessPoint,CIM_ServiceAffectsElement,CIM_ServiceAvailableToElement,CIM_ServiceSAPDependency,CIM_ServiceServiceDependency,CIM_SettingData,CIM_SharedCredential,CIM_SoftwareElement,CIM_SoftwareFeature,CIM_SoftwareFeatureSoftwareElements,CIM_SoftwareIdentity,CIM_StatisticalData,CIM_StorageExtent,CIM_System,CIM_SystemBIOS,CIM_SystemComponent,CIM_SystemDevice,CIM_SystemPackaging,CIM_UseOfLog,CIM_Watchdog,CIM_WiFiEndpoint,CIM_WiFiEndpointCapabilities,CIM_WiFiEndpointSettings,CIM_WiFiPort,CIM_WiFiPortCapabilities,IPS_AdminProvisioningRecord,IPS_ClientProvisioningRecord,IPS_HostBasedSetupService,IPS_HostIPSettings,IPS_IderSessionUsingPort,IPS_IPv6PortSettings,IPS_KVMRedirectionSettingData,IPS_KvmSessionUsingPort,IPS_ManualProvisioningRecord,IPS_OptInService,IPS_ProvisioningAuditRecord,IPS_ProvisioningRecordLog,IPS_RasSessionUsingPort,IPS_ScreenSettingData,IPS_SecIOService,IPS_SessionUsingPort,IPS_SolSessionUsingPort,IPS_TLSProvisioningRecord".split(',');
214
+ IntelAmtEntireStateProgress = 101;
215
IntelAmtEntireStateCalls = 3;
216
IntelAmtEntireState = { 'localtime': Date(), 'utctime': new Date().toUTCString(), 'isotime': new Date().toISOString() };
217
amtstack.BatchEnum(null, AllWsman, saveEntireAmtStateOk2, null, true);
@@ -215,12 +219,12 @@ function saveEntireAmtState() {
219
amtstack.GetMessageLog(saveEntireAmtStateOk4);
220
}
221
218
-//function onWsmanProcessChanged(a, b) { console.log('onWsmanProcessChanged', a, b); }
222
+function onWsmanProcessChanged(a, b) { var x = Math.floor((a * 100) / b); if (x < IntelAmtEntireStateProgress) { IntelAmtEntireStateProgress = x; console.log((100 - x) + '%'); } }
223
//function onWsmanResponse(stack, name, responses, status) { console.log('onWsmanResponse', JSON.stringify(responses), status); exit(1); }
224
221
-function saveEntireAmtStateOk2(stack, name, responses, status) { IntelAmtEntireState['wsmanenums'] = responses; saveEntireAmtStateDone(); }
222
-function saveEntireAmtStateOk3(stack, messages) { IntelAmtEntireState['auditlog'] = messages; saveEntireAmtStateDone(); }
223
-function saveEntireAmtStateOk4(stack, messages) { IntelAmtEntireState['eventlog'] = messages; saveEntireAmtStateDone(); }
225
+function saveEntireAmtStateOk2(stack, name, responses, status) { if (status == 600) { console.log('ERROR: Unable to connect to Intel(R) AMT.'); exit(2); } IntelAmtEntireState['wsmanenums'] = responses; saveEntireAmtStateDone(); }
226
+function saveEntireAmtStateOk3(stack, messages, status) { if (status == 600) { console.log('ERROR: Unable to connect to Intel(R) AMT.'); exit(2); } IntelAmtEntireState['auditlog'] = messages; saveEntireAmtStateDone(); }
227
+function saveEntireAmtStateOk4(stack, messages, tag, status) { if (status == 600) { console.log('ERROR: Unable to connect to Intel(R) AMT.'); exit(2); } IntelAmtEntireState['eventlog'] = messages; saveEntireAmtStateDone(); }
228
229
function saveEntireAmtStateDone() {
230
if (--IntelAmtEntireStateCalls != 0) return;
@@ -267,7 +271,7 @@ function getAmtInfo(func, tag) {
271
}
272
273
// Start LMS
270
-function startLms() {
274
+function startLms(func) {
275
var lme_heci = require('lme_heci');
276
var amtLms = null;
277
var http = require('http');
@@ -276,49 +280,59 @@ function startLms() {
280
281
var amtMeiModule = require('amt_heci');
282
amtMei = new amtMeiModule();
279
- amtMei.on('error', function (e) { console.log(e); exit(1); return; });
283
+ amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
284
//console.log('PTHI Connecting...');
285
amtMei.on('connect', function () {
286
//console.log("PTHI Connected.");
287
amtLms = new lme_heci({ debug: settings.lmsdebug });
284
- amtLms.on('error', function (e) { console.log('LME connection failed', e); });
288
+ amtLms.on('error', function (e) {
289
+ //console.log('LME connection failed', e);
290
+ if (func) { func(0); }
291
+ });
292
//console.log('LME Connecting...');
293
amtLms.on('connect', function () {
294
//console.log("LME Connected.");
288
- amtLms.meshCommander = http.createServer();
289
- amtLms.meshCommander.listen(16994);
290
- amtLms.meshCommander.on('upgrade', function (req, socket, head) {
291
- //console.log("WebSocket for " + req.url.split('?')[0]);
292
- switch (req.url.split('?')[0]) {
293
- case '/lms.ashx': // MeshCommander control channel (PTHI)
294
- socket.ws = socket.upgradeWebSocket();
295
- socket.ws.on('data', processLmsControlData);
296
- break;
297
- case '/webrelay.ashx': // MeshCommander data channel (LME)
298
- socket.ws = socket.upgradeWebSocket();
299
- amtLms.bindDuplexStream(socket.ws, 'IPv4', 16992);
300
- break;
301
- default:
302
- socket.end();
303
- break;
304
- }
305
- });
306
- amtLms.meshCommander.on('request', function (req, rsp) {
307
- //console.log("WebRequest for " + req.url.split('?')[0]);
308
- switch (req.url.split('?')[0]) {
309
- case '/': // Serve MeshCommander Web Application for LMS
310
- rsp.writeHead(200, 'OK', { Server: 'JSLMS', 'Cache-Control': 'max-age=0, no-cache', 'X-Frame-Options': 'DENY', 'Content-Type': 'text/html', 'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked', ETag: _IntelAmtWebApp_etag });
311
- rsp.end(Buffer.from(_IntelAmtWebApp, 'base64'));
312
- break;
313
- default: // Unknown request
314
- rsp.statusCode = 404;
315
- rsp.statusMessage = "Not Found";
316
- rsp.end();
317
- break;
318
- }
295
+ if (settings.noconsole !== true) {
296
+ amtLms.meshCommander = http.createServer();
297
+ amtLms.meshCommander.listen(16994);
298
+ amtLms.meshCommander.on('upgrade', function (req, socket, head) {
299
+ //console.log("WebSocket for " + req.url.split('?')[0]);
300
+ switch (req.url.split('?')[0]) {
301
+ case '/lms.ashx': // MeshCommander control channel (PTHI)
302
+ socket.ws = socket.upgradeWebSocket();
303
+ socket.ws.on('data', processLmsControlData);
304
+ break;
305
+ case '/webrelay.ashx': // MeshCommander data channel (LME)
306
+ socket.ws = socket.upgradeWebSocket();
307
+ amtLms.bindDuplexStream(socket.ws, 'IPv4', 16992);
308
+ break;
309
+ default:
310
+ socket.end();
311
+ break;
312
+ }
313
+ });
314
+ amtLms.meshCommander.on('request', function (req, rsp) {
315
+ //console.log("WebRequest for " + req.url.split('?')[0]);
316
+ switch (req.url.split('?')[0]) {
317
+ case '/': // Serve MeshCommander Web Application for LMS
318
+ rsp.writeHead(200, 'OK', { Server: 'JSLMS', 'Cache-Control': 'max-age=0, no-cache', 'X-Frame-Options': 'DENY', 'Content-Type': 'text/html', 'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked', ETag: _IntelAmtWebApp_etag });
319
+ rsp.end(Buffer.from(_IntelAmtWebApp, 'base64'));
320
+ break;
321
+ default: // Unknown request
322
+ rsp.statusCode = 404;
323
+ rsp.statusMessage = "Not Found";
324
+ rsp.end();
325
+ break;
326
+ }
327
320
- });
321
- console.log("LMS started, MeshCommander on HTTP/16994.");
328
+ });
329
+ //console.log("LMS started, MeshCommander on HTTP/16994.");
330
+ if (func) { func(2); }
331
+ } else {
332
+ //console.log("LMS started.");
333
+ if (func) { func(1); }
334
+ }
335
+
336
});
337
});
338
}
@@ -374,7 +388,7 @@ function processLmsControlData(data) {
388
// Starts the router
389
function startRouter() {
390
tcpserver = net.createServer(OnTcpClientConnected);
377
- tcpserver.on('error', function (err) { console.log(err); exit(0); return; });
391
+ tcpserver.on('error', function (e) { console.log('ERROR: ' + e); exit(0); return; });
392
tcpserver.listen(settings.localPort, function () {
393
// We started listening.
394
if (settings.remoteName == null) {
@@ -405,7 +419,7 @@ function OnTcpClientConnected(c) {
419
c.websocket.tcp = c;
420
c.websocket.tunneling = false;
421
c.websocket.upgrade = OnWebSocket;
408
- c.websocket.on('error', function (msg) { console.log(msg); });
422
+ c.websocket.on('error', function (e) { console.log('ERROR: ' + e); });
423
c.websocket.end();
424
} catch (e) { debug(2, e); }
425
}
@@ -576,4 +590,4 @@ function deleteStorage(name, func, noretry) {
590
req.end();
591
}
592
579
-try { run(process.argv); } catch (e) { console.log(e); }
593
+try { run(process.argv); } catch (e) { console.log('ERROR: ' + e); }