From 74f02b984b0681d29fa9ff93ace7cd7f7d299210 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Wed, 15 Apr 2020 22:27:03 -0700 Subject: [PATCH] Improved MeshCtrl with proxy support. --- meshctrl.js | 23 ++++++++++++++++++++--- views/default.handlebars | 2 ++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/meshctrl.js b/meshctrl.js index 484a7ddd..b8941f7f 100644 --- a/meshctrl.js +++ b/meshctrl.js @@ -1,10 +1,14 @@ #!/usr/bin/env node -const crypto = require('crypto'); +// Make sure we have the dependency modules +try { require('minimist'); } catch (ex) { console.log('Missing module "minimist", type "npm install minimist" to install it.'); return; } +try { require('ws'); } catch (ex) { console.log('Missing module "ws", type "npm install ws" to install it.'); return; } + var settings = {}; +const crypto = require('crypto'); const args = require('minimist')(process.argv.slice(2)); const possibleCommands = ['listusers', 'listdevicegroups', 'listdevices', 'listusersofdevicegroup', 'serverinfo', 'userinfo', 'adduser', 'removeuser', 'adddevicegroup', 'removedevicegroup', 'broadcast', 'showevents', 'addusertodevicegroup', 'removeuserfromdevicegroup', 'addusertodevice', 'removeuserfromdevice', 'sendinviteemail', 'generateinvitelink', 'config']; -//console.log(args); +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; } } if (args['_'].length == 0) { console.log("MeshCtrl performs command line actions on a MeshCentral server."); @@ -39,6 +43,7 @@ if (args['_'].length == 0) { console.log(" --loginkey [hex] - Server login key in hex."); console.log(" --loginkeyfile [file] - File containing server login key in hex."); console.log(" --domain [domainid] - Domain id, default is empty."); + console.log(" --proxy [http://proxy:1] - Specify an HTTP proxy."); return; } else { settings.cmd = args['_'][0].toLowerCase(); @@ -493,6 +498,12 @@ function serverConnect() { // TODO: checkServerIdentity does not work??? var options = { rejectUnauthorized: false, checkServerIdentity: onVerifyServer } + // Setup the HTTP proxy if needed + if (args.proxy != null) { + const HttpsProxyAgent = require('https-proxy-agent'); + options.agent = new HttpsProxyAgent(require('url').parse(args.proxy)); + } + // Password authentication if (args.loginpass != null) { var username = 'admin'; @@ -661,7 +672,13 @@ function serverConnect() { } }); - ws.on('close', function close() { process.exit(); }); + ws.on('close', function() { process.exit(); }); + ws.on('error', function (err) { + if (err.code == 'ENOTFOUND') { console.log('Unable to resolve ' + url); } + else if (err.code == 'ECONNREFUSED') { console.log('Unable to connect to ' + url); } + else { console.log(err); } + process.exit(); + }); ws.on('message', function incoming(rawdata) { //console.log(rawdata); diff --git a/views/default.handlebars b/views/default.handlebars index 1945d818..a9aaeea5 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -5874,6 +5874,8 @@ QV('p11DeskConsoleMsg', true); if (p11DeskConsoleMsgTimer != null) { clearTimeout(p11DeskConsoleMsgTimer); } p11DeskConsoleMsgTimer = setTimeout(p11clearConsoleMsg, 8000); + } else { + p11clearConsoleMsg(); } } desktop.m.CompressionLevel = desktopsettings.quality; // Number from 1 to 100. 50 or less is best.