Minor MeshCMD improvements.

Ylian Saint-Hilaire committed Oct 25, 2021 at 23:12 UTC 5eb7c18e24284227183eddf63463017091aebb23
1 file changed +23 -21
agents/meshcmd.js
+23 -21
@@ -437,7 +437,7 @@ function run(argv) {
437 // Start Intel AMT configuration
438 var amtMeiModule, amtMei;
439 try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
440 - amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
440 + amtMei.on('error', function (e) { console.log('amtstartconfig error: ' + e); exit(1); return; });
441 amtMei.startConfiguration(function (state) {
442 if (state == 3) { console.log("Intel AMT is not in correct mode."); }
443 else if (state == 1) { console.log("Intel AMT internal error."); }
@@ -451,7 +451,7 @@ function run(argv) {
451 // Stop Intel AMT configuration
452 var amtMeiModule, amtMei;
453 try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
454 - amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
454 + amtMei.on('error', function (e) { console.log('amtstopconfig error: ' + e); exit(1); return; });
455 amtMei.stopConfiguration(function (state) {
456 if (state == 3) { console.log("Intel AMT is not in in-provisionning mode."); }
457 else if (state == 1) { console.log("Intel AMT internal error."); }
@@ -494,7 +494,7 @@ function run(argv) {
494 // Display Intel ME versions
495 var amtMeiModule, amtMei;
496 try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
497 - amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
497 + amtMei.on('error', function (e) { console.log('amtversion error: ' + e); exit(1); return; });
498 amtMei.getVersion(function (val) {
499 if (args.json) {
500 console.log(JSON.stringify(val, null, 2));
@@ -517,7 +517,7 @@ function run(argv) {
517 // Display Intel AMT list of trusted hashes
518 var amtMeiModule, amtMei, amtHashes = [];
519 try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
520 - amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
520 + amtMei.on('error', function (e) { console.log('amthashes error: ' + e); exit(1); return; });
521 amtMei.getHashHandles(function (handles) {
522 exitOnCount = handles.length;
523 for (var i = 0; i < handles.length; ++i) {
@@ -541,7 +541,7 @@ function run(argv) {
541 mestate = {};
542 var amtMeiModule, amtMei;
543 try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
544 - amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
544 + amtMei.on('error', function (e) { console.log('amtinfo error: ' + e); exit(1); return; });
545 try {
546 amtMei.getVersion(function (result) {
547 if (result) {
@@ -633,7 +633,7 @@ function run(argv) {
633 options.checkServerIdentity = function (cert) { }
634 //console.log("options: " + JSON.stringify(options, null, 2));
635 var req = http.request(options);
636 - req.on('error', function (e) { console.log("Error: " + e); exit(1); });
636 + req.on('error', function (e) { console.log("amtinfojson error: " + e); exit(1); });
637 req.on('response', function (response) { console.log("Status code: " + response.statusCode); exit(1); });
638 req.end(JSON.stringify(state));
639 } else {
@@ -1290,7 +1290,7 @@ function configureJsonControl(data) {
1290 function deactivateCCM() {
1291 var amtMeiModule, amtMei;
1292 try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
1293 - amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
1293 + amtMei.on('error', function (e) { console.log('deactivateCCM() error: ' + e); exit(1); return; });
1294 amtMei.unprovision(1, function (status) { if (status == 0) { console.log('Success'); } else { console.log('Error ' + status); } exit(1); });
1295 }
1296
@@ -1488,7 +1488,7 @@ function getAmtInfo(func, tag) {
1488 getAmtInfoFetchingTimer = null;
1489 var amtMeiModule, amtMei;
1490 try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
1491 - amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
1491 + amtMei.on('error', function (e) { console.log('getAmtInfo() error: ' + e); exit(1); return; });
1492 }, 3000);
1493 amtMei.getProtocolVersion(function (result) { if (result != null) { amtMeiTmpState.MeiVersion = result; } });
1494 amtMei.getVersion(function (val) {
@@ -1549,7 +1549,7 @@ function startLms(func, lmscommander, tag) {
1549
1550 console.log('Setting up MEI...');
1551 try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
1552 - amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
1552 + amtMei.on('error', function (e) { console.log('startLms() error: ' + e); exit(1); return; });
1553 //console.log("PTHI Connected.");
1554
1555 try { amtLms = new lme_heci({ debug: settings.lmsdebug }); } catch (ex) { if (func != null) { func(0, tag); } return; }
@@ -2038,7 +2038,7 @@ function startRouter() {
2038 options.rejectUnauthorized = false;
2039 settings.websocket = http.request(options);
2040 settings.websocket.upgrade = OnServerWebSocket;
2041 - settings.websocket.on('error', function (e) { console.log("ERROR: " + JSON.stringify(e)); });
2041 + settings.websocket.on('error', function (ex) { console.log("Unable to connect to server: " + JSON.stringify(ex)); process.exit(1); return; });
2042 settings.websocket.end();
2043 }
2044
@@ -2143,7 +2143,7 @@ function OnServerWebSocket(msg, s, head) {
2143
2144 function startRouterEx() {
2145 tcpserver = net.createServer(OnTcpClientConnected);
2146 - tcpserver.on('error', function (e) { console.log("ERROR: " + JSON.stringify(e)); exit(0); return; });
2146 + tcpserver.on('error', function (e) { console.log("startRouterEx() Error: " + JSON.stringify(e)); exit(0); return; });
2147 try {
2148 tcpserver.listen(settings.localport, function () {
2149 // We started listening.
@@ -2177,7 +2177,7 @@ function OnTcpClientConnected(c) {
2177 c.websocket.tcp = c;
2178 c.websocket.tunneling = false;
2179 c.websocket.upgrade = OnWebSocket;
2180 - c.websocket.on('error', function (e) { console.log("ERROR: " + JSON.stringify(e)); });
2180 + c.websocket.on('error', function (e) { console.log("OnTcpClientConnected() Error: " + JSON.stringify(e)); });
2181 c.websocket.end();
2182 } catch (e) { debug(2, e); }
2183 }
@@ -2218,17 +2218,19 @@ function discoverMeshServerOnce() {
2218 for (var adapter in interfaces) {
2219 if (interfaces.hasOwnProperty(adapter)) {
2220 for (var i = 0; i < interfaces[adapter].length; ++i) {
2221 - var addr = interfaces[adapter][i];
2222 - multicastSockets[i] = dgram.createSocket({ type: (addr.family == 'IPv4' ? 'udp4' : 'udp6') });
2223 - multicastSockets[i].bind({ address: addr.address, exclusive: false });
2224 - if (addr.family == 'IPv4') {
2225 - try {
2221 + try {
2222 + var addr = interfaces[adapter][i];
2223 + if (multicastSockets[i] == null) {
2224 + multicastSockets[i] = dgram.createSocket({ type: (addr.family == 'IPv4' ? 'udp4' : 'udp6') });
2225 + multicastSockets[i].bind({ address: addr.address, exclusive: false });
2226 + }
2227 + if (addr.family == 'IPv4') {
2228 multicastSockets[i].addMembership(membershipIPv4);
2229 //multicastSockets[i].setMulticastLoopback(true);
2230 multicastSockets[i].once('message', OnMulticastMessage);
2231 multicastSockets[i].send(settings.serverid, 16989, membershipIPv4);
2230 - } catch (e) { }
2231 - }
2232 + }
2233 + } catch (ex) { }
2234 }
2235 }
2236 }
@@ -3051,7 +3053,7 @@ if (serviceName == null) {
3053 else if (process.execPath.includes('LMS')) { serviceName = 'LMS'; }
3054 else if (process.execPath.includes('MeshCommander')) { serviceName = 'MeshCommander'; }
3055 if (serviceName == null) { for (var i in process.argv) { if ((process.argv[i].toLowerCase() == '-install') || (process.argv[i].toLowerCase() == '-uninstall')) { console.log('In order to install/uninstall, a service type must be specified.'); process.exit(); } } }
3054 - if (serviceName == null) { try { run(process.argv); } catch (e) { console.log("ERROR: " + e); } }
3056 + if (serviceName == null) { try { run(process.argv); } catch (e) { console.log("Run() error: " + e); } }
3057 } else {
3058 var serviceHost = require('service-host');
3059 var meshcmdService = new serviceHost({ name: serviceName, displayName: serviceDisplayName, startType: 'AUTO_START', description: serviceDesc });
@@ -3074,6 +3076,6 @@ if (serviceName == null) {
3076 meshcmdService.on('serviceStop', function onStop() { console.log("Stopping service"); process.exit(); }); // The console.log() is for debugging, will be ignored unless "console.setDestination()" is set.
3077
3078 // Called when the executable is not running as a service, run normally.
3077 - meshcmdService.on('normalStart', function onNormalStart() { try { run(process.argv); } catch (e) { console.log("ERROR: " + e); } });
3079 + meshcmdService.on('normalStart', function onNormalStart() { try { run(process.argv); } catch (e) { console.log("onNormalStart() error: " + e); } });
3080 meshcmdService.run();
3081 }