Improved agent invitations, #3694

This commit is contained in:
Ylian Saint-Hilaire
2022-02-23 16:14:32 -08:00
parent fb1c8ef0c3
commit e58419a6c3
4 changed files with 54 additions and 10 deletions

View File

@@ -85,7 +85,7 @@
<button id="tlinuxtab" class="tablinks" onclick="openTab(event, 'linuxtab')">Linux</button>
<button id="tmacostab" class="tablinks" onclick="openTab(event, 'macostab')">MacOS</button>
<button id="tandrotab" class="tablinks" onclick="openTab(event, 'androtab')">Android</button>
<button id="tandrotab" class="tablinks" onclick="openTab(event, 'assistab')">Assistant</button>
<button id="tassistab" class="tablinks" onclick="openTab(event, 'assistab')">Assistant</button>
</div>
<div id="wintab64" class="tabcontent" style="background-color:white;color:black">
@@ -180,6 +180,7 @@
var serverHttps = '{{{serverhttps}}}';
var serverNoProxy = '{{{servernoproxy}}}';
var installFlags = '{{{installflags}}}';
var showAgents = parseInt('{{{showagents}}}'); // 0 = Show all agents, 1 = Windows only, 2 = Linux only, 4 = MacOS only, 8 = Assistant only, 16 = Android
var magenturl = '{{{magenturl}}}';
var groupName = decodeURIComponent('{{{meshname}}}');
var urlargs = parseUriArgs();
@@ -215,8 +216,30 @@
document.title = "Agent Installation";
}
// Setup visible tabs
var tabcount = 0, tabselect = null;
var tab1 = (showAgents == 0) || (showAgents & 1);
var tab2 = (showAgents == 0) || (showAgents & 1);
var tab3 = (showAgents == 0) || (showAgents & 2);
var tab4 = (showAgents == 0) || (showAgents & 4);
var tab5 = (showAgents == 0) || (showAgents & 16);
var tab6 = (showAgents == 0) || (showAgents & 8);
if (tab6) { tabcount++; tabselect = 'assistab'; }
if (tab5) { tabcount++; tabselect = 'androtab'; }
if (tab4) { tabcount++; tabselect = 'macostab'; }
if (tab3) { tabcount++; tabselect = 'linuxtab'; }
if (tab2) { tabcount++; tabselect = 'wintab32'; }
if (tab1) { tabcount++; tabselect = 'wintab64'; }
QV('twintab64', tab1 && (tabcount > 1));
QV('twintab32', tab2 && (tabcount > 1));
QV('tlinuxtab', tab3 && (tabcount > 1));
QV('tmacostab', tab4 && (tabcount > 1));
QV('tandrotab', tab5 && (tabcount > 1));
QV('tassistab', tab6 && (tabcount > 1));
userInterfaceSelectMenu();
setup();
openTab(null, tabselect);
}
// Create the QR code

View File

@@ -4962,7 +4962,10 @@
}
x += '<div id=urlInviteDiv>' + format("Invite someone to install the mesh agent by sharing an invitation link. This link points the user to installation instructions for the \"{0}\" device group. The link is public and no account for this server is needed.", EscapeHtml(mesh.name)) + '<br /><br />';
x += addHtmlValue("Link Expiration", '<select id=d2inviteExpire style=width:236px onchange=d2RequestInvitationLink()><option value=1>' + "1 hour" + '</option><option value=8>' + "8 hours" + '</option><option value=24>' + "1 day" + '</option><option value=168>' + "1 week" + '</option><option value=5040>' + "1 month" + '</option><option value=0>' + "Unlimited" + '</option></select>');
x += addHtmlValue("Agents", '<select id=d2agentType style=width:236px onchange=d2ChangedInviteType()><option value=0>' + "All Available Agents" + '</option><option value=1>' + "Windows MeshAgent" + '</option><option value=2>' + "Linux MeshAgent" + '</option><option value=4>' + "MacOS MeshAgent" + '</option><option value=8>' + "MeshCentral Assistant" + '</option></select>');
x += '<div id=d2agentInstallTypeDiv>';
x += addHtmlValue("Installation Type", '<select id=d2agentInviteType style=width:236px onchange=d2RequestInvitationLink()><option value=0>' + "Background and interactive" + '</option><option value=2>' + "Background only" + '</option><option value=1>' + "Interactive only" + '</option></select>');
x += '</div>';
x += '<div id=agentInvitationLinkDiv style="text-align:center;font-size:large;margin:16px;display:none"><a href=# id=agentInvitationLink rel="noreferrer noopener" target="_blank" style=cursor:pointer></a> <img src=images/link4.png height=10 width=10 title="' + "Copy link to clipboard" + '" style=cursor:pointer onclick=d2CopyInviteToClip()></div></div>';
setDialogMode(2, "Invite", 3, performAgentInvite, x, meshid);
if (features & 64) { Q('d2InviteType').focus(); d2ChangedInviteType(); } else { Q('d2inviteExpire').focus(); validateAgentInvite(); }
@@ -4971,14 +4974,18 @@
}
function d2RequestInvitationLink() {
meshserver.send({ action: 'createInviteLink', meshid: xxdialogTag, expire: parseInt(Q('d2inviteExpire').value), flags: parseInt(Q('d2agentInviteType').value) });
meshserver.send({ action: 'createInviteLink', meshid: xxdialogTag, expire: parseInt(Q('d2inviteExpire').value), flags: parseInt(Q('d2agentInviteType').value), agents: parseInt(Q('d2agentType').value) });
}
function d2ChangedInviteType() {
QV('urlInviteDiv', Q('d2InviteType').value == 0);
QV('d2agentexpirediv', Q('agentInviteNameOs').value == 4);
QV('emailInviteDiv', Q('d2InviteType').value == 1);
if (features & 64) {
QV('urlInviteDiv', Q('d2InviteType').value == 0);
QV('d2agentexpirediv', Q('agentInviteNameOs').value == 4);
QV('emailInviteDiv', Q('d2InviteType').value == 1);
}
QV('d2agentInstallTypeDiv', parseInt(Q('d2agentType').value) < 2);
validateAgentInvite();
d2RequestInvitationLink();
}
function d2CopyInviteToClip() { copyTextToClip(Q('agentInvitationLink').href); }
@@ -12758,11 +12765,15 @@
x += '<div style=width:100%;text-align:center><a rel="noreferrer noopener" target=_blank href="' + url + '">' + url + '</a></div><br />';
x += '<div style=margin-bottom:5px><label><input id=agentJoinCheck type=checkbox onclick=p20editmeshInviteCodeValidate() />' + "Enable Invite Codes" + '</label></div>';
x += addHtmlValue("Invite Codes", '<input id=agentInviteCode style=width:236px onkeyup=p20editmeshInviteCodeValidate() placeholder="code1, code2, code3" />');
x += addHtmlValue("Agents", '<select id=agentType style=width:236px onchange=p20editmeshInviteCodeValidate()><option value=0>' + "All Available Agents" + '</option><option value=1>' + "Windows MeshAgent" + '</option><option value=2>' + "Linux MeshAgent" + '</option><option value=4>' + "MacOS MeshAgent" + '</option><option value=8>' + "MeshCentral Assistant" + '</option></select>');
x += '<div id=d2agentInstallTypeDiv>';
x += addHtmlValue("Installation Type", '<select id=agentInviteType style=width:236px><option value=0>' + "Background and interactive" + '</option><option value=2>' + "Background only" + '</option><option value=1>' + "Interactive only" + '</option></select>');
x += '</div>';
setDialogMode(2, "Invite Codes", 3, p20editmeshInviteCodeEx, x);
if (currentMesh.invite != null) {
Q('agentJoinCheck').checked = true;
Q('agentInviteCode').value = currentMesh.invite.codes.join(', ');
if (currentMesh.invite.ag) { Q('agentType').value = currentMesh.invite.ag; }
Q('agentInviteType').value = (currentMesh.invite.flags & 3);
}
p20editmeshInviteCodeValidate();
@@ -12780,15 +12791,17 @@
var ok = true, codes = Q('agentInviteCode').value.split(',');
for (var i in codes) { codes[i] = codes[i].trim(); if (codes[i] == '') { ok = false; } }
QE('agentInviteCode', Q('agentJoinCheck').checked);
QE('agentType', Q('agentJoinCheck').checked);
QE('agentInviteType', Q('agentJoinCheck').checked);
QE('idx_dlgOkButton', (Q('agentJoinCheck').checked == false) || (ok));
QV('d2agentInstallTypeDiv', parseInt(Q('agentType').value) < 2);
}
function p20editmeshInviteCodeEx() {
if (Q('agentJoinCheck').checked == true) {
var codes = Q('agentInviteCode').value.split(',');
for (var i in codes) { codes[i] = codes[i].trim(); }
meshserver.send({ action: 'editmesh', meshid: currentMesh._id, invite: { codes: codes, flags: parseInt(Q('agentInviteType').value) } });
meshserver.send({ action: 'editmesh', meshid: currentMesh._id, invite: { codes: codes, flags: parseInt(Q('agentInviteType').value), ag: parseInt(Q('agentType').value) } });
} else {
meshserver.send({ action: 'editmesh', meshid: currentMesh._id, invite: '*' });
}