Improved MeshCtrl with proxy support.

Ylian Saint-Hilaire committed Apr 15, 2020 at 22:27 UTC 74f02b984b0681d29fa9ff93ace7cd7f7d299210
2 files changed +22 -3
meshctrl.js
+20 -3
@@ -1,10 +1,14 @@
1 #!/usr/bin/env node
2
3 -const crypto = require('crypto');
3 +// Make sure we have the dependency modules
4 +try { require('minimist'); } catch (ex) { console.log('Missing module "minimist", type "npm install minimist" to install it.'); return; }
5 +try { require('ws'); } catch (ex) { console.log('Missing module "ws", type "npm install ws" to install it.'); return; }
6 +
7 var settings = {};
8 +const crypto = require('crypto');
9 const args = require('minimist')(process.argv.slice(2));
10 const possibleCommands = ['listusers', 'listdevicegroups', 'listdevices', 'listusersofdevicegroup', 'serverinfo', 'userinfo', 'adduser', 'removeuser', 'adddevicegroup', 'removedevicegroup', 'broadcast', 'showevents', 'addusertodevicegroup', 'removeuserfromdevicegroup', 'addusertodevice', 'removeuserfromdevice', 'sendinviteemail', 'generateinvitelink', 'config'];
7 -//console.log(args);
11 +if (args.proxy != null) { try { require('https-proxy-agent'); } catch (ex) { console.log('Missing module "https-proxy-agent", type "npm install https-proxy-agent" to install it.'); return; } }
12
13 if (args['_'].length == 0) {
14 console.log("MeshCtrl performs command line actions on a MeshCentral server.");
@@ -39,6 +43,7 @@ if (args['_'].length == 0) {
43 console.log(" --loginkey [hex] - Server login key in hex.");
44 console.log(" --loginkeyfile [file] - File containing server login key in hex.");
45 console.log(" --domain [domainid] - Domain id, default is empty.");
46 + console.log(" --proxy [http://proxy:1] - Specify an HTTP proxy.");
47 return;
48 } else {
49 settings.cmd = args['_'][0].toLowerCase();
@@ -493,6 +498,12 @@ function serverConnect() {
498 // TODO: checkServerIdentity does not work???
499 var options = { rejectUnauthorized: false, checkServerIdentity: onVerifyServer }
500
501 + // Setup the HTTP proxy if needed
502 + if (args.proxy != null) {
503 + const HttpsProxyAgent = require('https-proxy-agent');
504 + options.agent = new HttpsProxyAgent(require('url').parse(args.proxy));
505 + }
506 +
507 // Password authentication
508 if (args.loginpass != null) {
509 var username = 'admin';
@@ -661,7 +672,13 @@ function serverConnect() {
672 }
673 });
674
664 - ws.on('close', function close() { process.exit(); });
675 + ws.on('close', function() { process.exit(); });
676 + ws.on('error', function (err) {
677 + if (err.code == 'ENOTFOUND') { console.log('Unable to resolve ' + url); }
678 + else if (err.code == 'ECONNREFUSED') { console.log('Unable to connect to ' + url); }
679 + else { console.log(err); }
680 + process.exit();
681 + });
682
683 ws.on('message', function incoming(rawdata) {
684 //console.log(rawdata);
views/default.handlebars
+2
@@ -5874,6 +5874,8 @@
5874 QV('p11DeskConsoleMsg', true);
5875 if (p11DeskConsoleMsgTimer != null) { clearTimeout(p11DeskConsoleMsgTimer); }
5876 p11DeskConsoleMsgTimer = setTimeout(p11clearConsoleMsg, 8000);
5877 + } else {
5878 + p11clearConsoleMsg();
5879 }
5880 }
5881 desktop.m.CompressionLevel = desktopsettings.quality; // Number from 1 to 100. 50 or less is best.