Added support for alternate SSH port.

Ylian Saint-Hilaire committed May 7, 2021 at 12:52 UTC c582dce3bcf519af7c1adf73e73c715c63e363bf
2 files changed +34 -7
meshuser.js
+8
@@ -4202,6 +4202,14 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4202 }
4203 }
4204
4205 + if ((typeof command.sshport == 'number') && (command.sshport > 0) && (command.sshport < 65536)) {
4206 + if ((command.sshport == 22) && (node.sshport != null)) {
4207 + delete node.sshport; change = 1; changes.push('sshport'); // Delete the SSH port
4208 + } else {
4209 + node.sshport = command.sshport; change = 1; changes.push('sshport'); // Set the SSH port
4210 + }
4211 + }
4212 +
4213 if (domain.geolocation && command.userloc && ((node.userloc == null) || (command.userloc[0] != node.userloc[0]) || (command.userloc[1] != node.userloc[1]))) {
4214 change = 1;
4215 if ((command.userloc.length == 0) && (node.userloc)) {
views/default.handlebars
+26 -7
@@ -82,6 +82,9 @@
82 <div id="altPortContextMenu" class="contextMenu noselect" style="display:none;min-width:0px">
83 <div class="cmtext" onclick="cmaltportaction(1,event)">Alternate Port</div>
84 </div>
85 + <div id="sshPortContextMenu" class="contextMenu noselect" style="display:none;min-width:0px">
86 + <div class="cmtext" onclick="cmsshportaction(1,event)">Alternate Port</div>
87 + </div>
88 <div id="rfbPortContextMenu" class="contextMenu noselect" style="display:none;min-width:0px">
89 <div class="cmtext" onclick="cmrfbportaction(1,event)">Alternate Port</div>
90 </div>
@@ -2948,6 +2951,7 @@
2951 node.userloc = message.event.node.userloc;
2952 node.rdpport = message.event.node.rdpport;
2953 node.rfbport = message.event.node.rfbport;
2954 + node.sshport = message.event.node.sshport;
2955 node.consent = message.event.node.consent;
2956 node.pmt = message.event.node.pmt;
2957 if (message.event.node.links != null) { node.links = message.event.node.links; } else { delete node.links; }
@@ -5412,21 +5416,35 @@
5416 // Save the new RDP port to the server
5417 var rdpport = ((Q('d10rdpport').value.length > 0) ? parseInt(Q('d10rdpport').value) : 3389);
5418 meshserver.send({ action: 'changedevice', nodeid: currentNode._id, rdpport: rdpport });
5415 - if (currentNode != null) { p10MCRouter(currentNode._id, 3, rdpport); }
5419 + //if (currentNode != null) { p10MCRouter(currentNode._id, 3, rdpport); }
5420 }, x, currentNode);
5421 Q('d10rdpport').focus();
5422 if (currentNode.rdpport != null) { Q('d10rdpport').value = currentNode.rdpport; }
5423 }
5424
5425 + function cmsshportaction(action) {
5426 + if (xxdialogMode) return;
5427 + var x = "SSH remote connection port:" + '<br /><br /><input type=text placeholder="22" inputmode="numeric" pattern="[0-9]*" onkeypress="return (event.keyCode == 8) || (event.charCode >= 48 && event.charCode <= 57)" maxlength=5 id=d10sshport type=text>';
5428 + setDialogMode(2, "SSH Connection", 3, function() {
5429 + setDialogMode(0);
5430 + // Save the new SSH port to the server
5431 + var sshport = ((Q('d10sshport').value.length > 0) ? parseInt(Q('d10sshport').value) : 22);
5432 + meshserver.send({ action: 'changedevice', nodeid: currentNode._id, sshport: sshport });
5433 + //if (currentNode != null) { p10MCRouter(currentNode._id, 3, sshport); }
5434 + }, x, currentNode);
5435 + Q('d10sshport').focus();
5436 + if (currentNode.sshport != null) { Q('d10sshport').value = currentNode.sshport; }
5437 + }
5438 +
5439 function cmrfbportaction(action) {
5440 if (xxdialogMode) return;
5423 - var x = "noVNC remote connection port:" + '<br /><br /><input type=text placeholder="5900" inputmode="numeric" pattern="[0-9]*" onkeypress="return (event.keyCode == 8) || (event.charCode >= 48 && event.charCode <= 57)" maxlength=5 id=d10rfbport type=text>';
5424 - setDialogMode(2, "noVNC Connection", 3, function() {
5441 + var x = "VNC remote connection port:" + '<br /><br /><input type=text placeholder="5900" inputmode="numeric" pattern="[0-9]*" onkeypress="return (event.keyCode == 8) || (event.charCode >= 48 && event.charCode <= 57)" maxlength=5 id=d10rfbport type=text>';
5442 + setDialogMode(2, "VNC Connection", 3, function() {
5443 setDialogMode(0);
5444 // Save the new RFB port to the server
5445 var rfbport = ((Q('d10rfbport').value.length > 0) ? parseInt(Q('d10rfbport').value) : 3389);
5446 meshserver.send({ action: 'changedevice', nodeid: currentNode._id, rfbport: rfbport });
5429 - if (currentNode != null) { p10rfb(currentNode._id, rfbport); }
5447 + //if (currentNode != null) { p10rfb(currentNode._id, rfbport); }
5448 }, x, currentNode);
5449 Q('d10rfbport').focus();
5450 if (currentNode.rfbport != null) { Q('d10rfbport').value = currentNode.rfbport; }
@@ -5511,6 +5529,7 @@
5529 QV('deskConnectContextMenu', false);
5530 QV('altPortContextMenu', false);
5531 QV('rfbPortContextMenu', false);
5532 + QV('sshPortContextMenu', false);
5533 QV('filesContextMenu', false);
5534 QV('deskPlayerContextMenu', false);
5535 QV('deskKeyShortcutContextMenu', false);
@@ -6449,12 +6468,12 @@
6468 if (node.agent.id > 4) {
6469 if ((navigator.platform.toLowerCase() == 'win32') || (navigator.platform.toLowerCase() == 'macintel')) {
6470 if ((serverinfo.devicemeshrouterlinks == null) || (serverinfo.devicemeshrouterlinks.ssh != false)) {
6452 - x += '<a href=# onclick=p10MCRouter("' + node._id + '",4,22) title="' + "Requires installation of MeshCentral Router." + '">' + "SSH" + '</a>&nbsp;';
6471 + x += '<a href=# cmenu=sshPortContextMenu onclick=p10MCRouter("' + node._id + '",4,22) title="' + "Requires installation of MeshCentral Router." + '">' + "SSH" + '</a>&nbsp;';
6472 }
6473 }
6474 if (navigator.platform.toLowerCase() == 'win32') {
6475 if ((serverinfo.devicemeshrouterlinks == null) || (serverinfo.devicemeshrouterlinks.scp != false)) {
6457 - x += '<a href=# onclick=p10MCRouter("' + node._id + '",5,22) title="' + "Requires installation of MeshCentral Router." + '">' + "SCP" + '</a>&nbsp;';
6476 + x += '<a href=# cmenu=sshPortContextMenu onclick=p10MCRouter("' + node._id + '",5,22) title="' + "Requires installation of MeshCentral Router." + '">' + "SCP" + '</a>&nbsp;';
6477 }
6478 }
6479 }
@@ -6483,7 +6502,7 @@
6502
6503 // SSH link
6504 if ((features2 & 0x200) && (((connectivity & 1) != 0) || (node.mtype == 3)) && (node.agent) && ((meshrights & 8) != 0) && (node.agent.id != 14)) {
6486 - x += '<a href=# id=sshLink onclick=p10ssh("' + node._id + '") title="' + "Launch web-based SSH session to this device" + '.">' + "Web-SSH" + '</a>&nbsp;';
6505 + x += '<a href=# cmenu=sshPortContextMenu id=sshLink onclick=p10ssh("' + node._id + '") title="' + "Launch web-based SSH session to this device" + '.">' + "Web-SSH" + '</a>&nbsp;';
6506 }
6507
6508 // MQTT options