Improved MeshCtrl with proxy support.

This commit is contained in:
Ylian Saint-Hilaire 2020-04-15 22:27:03 -07:00
parent e58838dfe8
commit 74f02b984b
2 changed files with 22 additions and 3 deletions

View File

@ -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);

View File

@ -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.