Plugin and meshcmd fixes.

Ylian Saint-Hilaire committed Oct 25, 2019 at 01:16 UTC 51437519540d951c747d2b6e63c6d8ca1643a97b
5 files changed +27 -26
agents/meshcmd.js
+4 -3
@@ -141,6 +141,7 @@ function run(argv) {
141 if ((typeof args.serverid) == 'string') { settings.serverid = args.serverid; }
142 if ((typeof args.serverhttpshash) == 'string') { settings.serverhttpshash = args.serverhttpshash; }
143 if ((typeof args.remoteport) == 'string') { settings.remoteport = parseInt(args.remoteport); }
144 + if ((typeof args.remotetarget) == 'string') { settings.remotetarget = args.remotetarget; }
145 if ((typeof args.out) == 'string') { settings.output = args.out; }
146 if ((typeof args.output) == 'string') { settings.output = args.output; }
147 if ((typeof args.debug) == 'string') { settings.debuglevel = parseInt(args.debug); }
@@ -2049,10 +2050,10 @@ function startRouter() {
2050 tcpserver.on('error', function (e) { console.log('ERROR: ' + JSON.stringify(e)); exit(0); return; });
2051 tcpserver.listen(settings.localport, function () {
2052 // We started listening.
2052 - if (settings.remotename == null) {
2053 + if (settings.remotetarget == null) {
2054 console.log('Redirecting local port ' + settings.localport + ' to remote port ' + settings.remoteport + '.');
2055 } else {
2055 - console.log('Redirecting local port ' + settings.localport + ' to ' + settings.remotename + ':' + settings.remoteport + '.');
2056 + console.log('Redirecting local port ' + settings.localport + ' to ' + settings.remotetarget + ':' + settings.remoteport + '.');
2057 }
2058 console.log('Press ctrl-c to exit.');
2059
@@ -2069,7 +2070,7 @@ function OnTcpClientConnected(c) {
2070 c.on('end', function () { disconnectTunnel(this, this.websocket, 'Client closed'); });
2071 c.pause();
2072 try {
2072 - options = http.parseUri(settings.serverurl + '?user=' + settings.username + '&pass=' + settings.password + '&nodeid=' + settings.remotenodeid + '&tcpport=' + settings.remoteport);
2073 + options = http.parseUri(settings.serverurl + '?user=' + settings.username + '&pass=' + settings.password + '&nodeid=' + settings.remotenodeid + '&tcpport=' + settings.remoteport + (settings.remotetarget == null ? '' : '&tcpaddr=' + settings.remotetarget));
2074 } catch (e) { console.log('Unable to parse \"serverUrl\".'); process.exit(1); return; }
2075 options.checkServerIdentity = onVerifyServer;
2076 options.rejectUnauthorized = false;
agents/meshcmd.min.js
+4 -3
@@ -141,6 +141,7 @@ function run(argv) {
141 if ((typeof args.serverid) == 'string') { settings.serverid = args.serverid; }
142 if ((typeof args.serverhttpshash) == 'string') { settings.serverhttpshash = args.serverhttpshash; }
143 if ((typeof args.remoteport) == 'string') { settings.remoteport = parseInt(args.remoteport); }
144 + if ((typeof args.remotetarget) == 'string') { settings.remotetarget = args.remotetarget; }
145 if ((typeof args.out) == 'string') { settings.output = args.out; }
146 if ((typeof args.output) == 'string') { settings.output = args.output; }
147 if ((typeof args.debug) == 'string') { settings.debuglevel = parseInt(args.debug); }
@@ -2049,10 +2050,10 @@ function startRouter() {
2050 tcpserver.on('error', function (e) { console.log('ERROR: ' + JSON.stringify(e)); exit(0); return; });
2051 tcpserver.listen(settings.localport, function () {
2052 // We started listening.
2052 - if (settings.remotename == null) {
2053 + if (settings.remotetarget == null) {
2054 console.log('Redirecting local port ' + settings.localport + ' to remote port ' + settings.remoteport + '.');
2055 } else {
2055 - console.log('Redirecting local port ' + settings.localport + ' to ' + settings.remotename + ':' + settings.remoteport + '.');
2056 + console.log('Redirecting local port ' + settings.localport + ' to ' + settings.remotetarget + ':' + settings.remoteport + '.');
2057 }
2058 console.log('Press ctrl-c to exit.');
2059
@@ -2069,7 +2070,7 @@ function OnTcpClientConnected(c) {
2070 c.on('end', function () { disconnectTunnel(this, this.websocket, 'Client closed'); });
2071 c.pause();
2072 try {
2072 - options = http.parseUri(settings.serverurl + '?user=' + settings.username + '&pass=' + settings.password + '&nodeid=' + settings.remotenodeid + '&tcpport=' + settings.remoteport);
2073 + options = http.parseUri(settings.serverurl + '?user=' + settings.username + '&pass=' + settings.password + '&nodeid=' + settings.remotenodeid + '&tcpport=' + settings.remoteport + (settings.remotetarget == null ? '' : '&tcpaddr=' + settings.remotetarget));
2074 } catch (e) { console.log('Unable to parse \"serverUrl\".'); process.exit(1); return; }
2075 options.checkServerIdentity = onVerifyServer;
2076 options.rejectUnauthorized = false;
meshuser.js
+17 -19
@@ -611,7 +611,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
611 try { fs.mkdirSync(path); } catch (e) { }
612 try { fs.mkdirSync(path + "/" + command.newfolder); } catch (e) { }
613 }
614 - }
614 + }
615 else if (command.fileop == 'delete') {
616 // Delete a file
617 if (common.validateArray(command.delfiles, 1) == false) return;
@@ -669,7 +669,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
669
670 switch (cmd) {
671 case 'help': {
672 - r = 'Available commands: help, info, versions, args, resetserver, showconfig, usersessions, tasklimiter, setmaxtasks, cores,\r\n'
672 + r = 'Available commands: help, info, versions, args, resetserver, showconfig, usersessions, tasklimiter, setmaxtasks, cores,\r\n'
673 r += 'migrationagents, agentstats, webstats, mpsstats, swarmstats, acceleratorsstats, updatecheck, serverupdate, nodeconfig,\r\n';
674 r += 'heapdump, relays, autobackup, backupconfig, dupagents, dispatchtable.';
675 break;
@@ -735,7 +735,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
735 }
736 case 'info': {
737 var info = process.memoryUsage();
738 - info.dbType = ['None','NeDB','MongoJS','MongoDB'][parent.db.databaseType];
738 + info.dbType = ['None', 'NeDB', 'MongoJS', 'MongoDB'][parent.db.databaseType];
739 if (parent.db.databaseType == 3) { info.dbChangeStream = parent.db.changeStream; }
740 try { info.platform = process.platform; } catch (ex) { }
741 try { info.arch = process.arch; } catch (ex) { }
@@ -813,7 +813,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
813 if (config.domains[i].yubikey && config.domains[i].yubikey.secret) { config.domains[i].yubikey.secret = '(present)'; }
814 }
815 }
816 -
816 +
817 r = JSON.stringify(removeAllUnderScore(config), null, 4);
818 break;
819 }
@@ -1335,7 +1335,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1335 if (command.email != null) { newuser.email = command.email.toLowerCase(); if (command.emailVerified === true) { newuser.emailVerified = true; } } // Email
1336 if (command.resetNextLogin === true) { newuser.passchange = -1; } else { newuser.passchange = Math.floor(Date.now() / 1000); }
1337 if (user.groups) { newuser.groups = user.groups; } // New accounts are automatically part of our groups (Realms).
1338 -
1338 +
1339 parent.users[newuserid] = newuser;
1340
1341 // Create a user, generate a salt and hash the password
@@ -1862,7 +1862,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1862
1863 if (unknownUsers.length > 0) {
1864 // Send error back, user not found.
1865 - displayNotificationMessage('User' + ((unknownUsers.length > 1)?'s':'') + ' ' + EscapeHtml(unknownUsers.join(', ')) + ' not found.', 'Device Group', 'ServerNotify');
1865 + displayNotificationMessage('User' + ((unknownUsers.length > 1) ? 's' : '') + ' ' + EscapeHtml(unknownUsers.join(', ')) + ' not found.', 'Device Group', 'ServerNotify');
1866 }
1867
1868 if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'addmeshuser', responseid: command.responseid, result: 'ok', removed: removedCount, failed: failCount })); } catch (ex) { } }
@@ -2483,8 +2483,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2483 case 'inviteAgent':
2484 {
2485 var err = null, mesh = null;
2486 - try
2487 - {
2486 + try {
2487 if ((parent.parent.mailserver == null) || (args.lanonly == true)) { err = 'Unsupported feature'; } // This operation requires the email server
2488 else if ((parent.parent.certificates.CommonName == null) || (parent.parent.certificates.CommonName.indexOf('.') == -1)) { err = 'Unsupported feature'; } // Server name must be configured
2489 else if (common.validateString(command.meshid, 1, 1024) == false) { err = 'Invalid group identifier'; } // Check meshid
@@ -3034,7 +3033,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3033 db.Get(nodeid, function (err, nodes) {
3034 if ((nodes == null) || (nodes.length != 1)) { if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'getmqttlogin', responseid: command.responseid, result: 'Invalid node id' })); } catch (ex) { } return; } }
3035 var node = nodes[0];
3037 -
3036 +
3037 // Get the device group for this node
3038 var mesh = parent.meshes[node.meshid];
3039 if (mesh) {
@@ -3071,11 +3070,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3070 if (common.validateString(command.nodeid, 1, 1024) == false) break; // Check nodeid
3071 if (common.validateInt(command.mode, 0, 3) == false) break; // Check connection mode
3072 // Validate if communication mode is possible
3074 - if (command.mode == null || command.mode==0) {
3073 + if (command.mode == null || command.mode == 0) {
3074 break; //unsupported
3075 } else if (command.mode == 1) {
3076 var state = parent.parent.GetConnectivityState(command.nodeid);
3078 - if ( (state == null) || (state.connectivity & 4)==0 ) break;
3077 + if ((state == null) || (state.connectivity & 4) == 0) break;
3078 } else if (command.mode == 2) {
3079 if (parent.parent.mpsserver.ciraConnections[command.nodeid] == null) break;
3080 } else if (command.mode == 3) {
@@ -3101,18 +3100,17 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3100 break;
3101 }
3102 case 'plugin': {
3103 + if (parent.parent.pluginHandler == null) break; // If the plugin's are not supported, reject this command.
3104 command.userid = user._id;
3105 -
3105 if (command.routeToNode === true) {
3107 - routeCommandToNode(command);
3106 + routeCommandToNode(command);
3107 } else {
3109 - try {
3110 - var pluginHandler = require('./pluginHandler.js').pluginHandler(parent.parent);
3111 - pluginHandler.plugins[command.plugin].serveraction(command, obj, parent);
3112 - } catch (e) { console.log('Error loading plugin handler (' + e + ')'); }
3108 + try {
3109 + var pluginHandler = require('./pluginHandler.js').pluginHandler(parent.parent);
3110 + pluginHandler.plugins[command.plugin].serveraction(command, obj, parent);
3111 + } catch (e) { console.log('Error loading plugin handler (' + e + ')'); }
3112 }
3114 -
3115 - break;
3113 + break;
3114 }
3115 default: {
3116 // Unknown user action
views/default.handlebars
+1 -1
@@ -4687,7 +4687,7 @@
4687 var x = '';
4688 if (nodeids.length > 1) { x = format("Are you sure you want to uninstall the selected {0} agents?", nodeids.length); } else { x = "Are you sure you want to uninstall selected agent?"; }
4689 x += '<br /><br />';
4690 - if (nodeids.length > 1) { x += "This will not remove the devices from the server, but the devices will not longer be able to connect to the server. All remote access to the devices will be lost. The devices must be connect for this command to work."; } else { x += "This will not remove this device from the server, but the device will not longer be able to connect to the server. All remote access to the device will be lost. The device must be connect for this command to work."; }
4690 + if (nodeids.length > 1) { x += "This will not remove the devices from the server, but the devices will not longer be able to connect to the server. All remote access to the devices will be lost. The devices must be connected for this command to work."; } else { x += "This will not remove this device from the server, but the device will not longer be able to connect to the server. All remote access to the device will be lost. The device must be connect for this command to work."; }
4691 x += '<br /><br /><label style=color:red><input id=p10check type=checkbox onchange=p10validateDeleteNodeDialog() />' + "Confirm" + '</label>';
4692 setDialogMode(2, "Uninstall agent", 3, p10showSendUninstallAgentDialogEx, x, nodeids);
4693 p10validateSendUninstallAgentDialog();
webserver.js
+1
@@ -2955,6 +2955,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
2955 localPort: 1234,
2956 remoteName: node.name,
2957 remoteNodeId: node._id,
2958 + remoteTarget: '',
2959 remotePort: 3389,
2960 username: '',
2961 password: '',