Fixed for typing issue #2416

Ylian Saint-Hilaire committed Apr 15, 2021 at 15:38 UTC 56ba656bd4cc23ab3376ad327b49fc686ded3fee
4 files changed +33 -1
meshcentral-config-schema.json
+2 -1
@@ -345,7 +345,8 @@
345 "force2factor": { "type": "boolean", "default": false, "description": "Requires that all accounts setup 2FA." },
346 "skip2factor": { "type": "string", "description": "IP addresses where 2FA login is skipped, for example: 127.0.0.1,192.168.2.0/24" },
347 "oldPasswordBan": { "type": "integer", "description": "Number of old passwords the server should remember and not allow the user to switch back to." },
348 - "banCommonPasswords": { "type": "boolean", "default": false, "description": "Uses WildLeek to block use of the 10000 most commonly used passwords." }
348 + "banCommonPasswords": { "type": "boolean", "default": false, "description": "Uses WildLeek to block use of the 10000 most commonly used passwords." },
349 + "loginTokens": { "type": "boolean", "default": true, "description": "Allows users to create alternative username/passwords for their account." }
350 }
351 },
352 "twoFactorCookieDurationDays": { "type": "integer", "default": 30, "description": "Number of days that a user is allowed to remember this device for when completing 2FA. Set this to 0 to remove this option." },
meshuser.js
+9
@@ -5610,6 +5610,15 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5610 }
5611 break;
5612 }
5613 + case 'createLoginToken': {
5614 + if ((typeof domain.passwordrequirements != 'object') && (domain.passwordrequirements.logintokens == false)) break; // Login tokens are not supported on this server
5615 + if (common.validateString(command.name, 1, 100) == false) break; // Check name
5616 + if ((typeof command.expire != 'number') || (command.expire < 0)) break; // Check expire
5617 +
5618 + console.log(command);
5619 +
5620 + break;
5621 + }
5622 case 'getDeviceDetails': {
5623 if (common.validateStrArray(command.nodeids, 1) == false) break; // Check nodeids
5624 if (common.validateString(command.type, 3, 4) == false) break; // Check type
views/default.handlebars
+21
@@ -381,6 +381,7 @@
381 <a href=# onclick="return account_showChangePassword()">Change password</a><span id="p2nextPasswordUpdateTime"></span><br />
382 <a href=# onclick="return account_showDeleteAccount()">Delete account</a><br />
383 </span>
384 + <span id="accountCreateLoginTokenSpan" style="display:none"><a href=# onclick="return account_createLoginToken()">Create login token</a><br /></span>
385 </p>
386 <br style=clear:both />
387 </div>
@@ -1934,6 +1935,7 @@
1935 QV('manageEmail2FA', features & 0x00800000);
1936 QV('p2AccountPassActions', ((features & 4) == 0) && (serverinfo.domainauth == false) && (userinfo != null) && (userinfo._id.split('/')[2].startsWith('~') == false)); // Hide Account Actions if in single user mode or domain authentication
1937 //QV('p2AccountImage', ((features & 4) == 0) && (serverinfo.domainauth == false)); // If account actions are not visible, also remove the image on that panel
1938 + QV('accountCreateLoginTokenSpan', features2 & 0x00000080);
1939 QV('p2AccountImage', !accountSettingsLocked)
1940 QV('p2ServerActions', (siteRights & 21) && ((serverFeatures & 15) != 0));
1941 QV('LeftMenuMyServer', (siteRights & 21) && ((serverFeatures & 64) != 0)); // 16 + 4 + 1
@@ -10169,6 +10171,25 @@
10171 return false;
10172 }
10173
10174 + function account_createLoginToken() {
10175 + if (xxdialogMode) return false;
10176 + var y = '', x = "Create a temporary username and password that can be used as alternative login to your account. This is useful for allowing tools or other services to access your account." + '<br /><br />';
10177 + var options = { 0 : "Unlimited", 1 : "1 minute", 5 : "5 minutes", 10 : "10 minutes", 15 : "15 minutes", 30 : "30 minutes", 45 : "45 minutes", 60 : "60 minutes", 120 : "2 hours", 240 : "4 hours", 480 : "8 hours", 720 : "12 hours", 960 : "16 hours", 1440 : "24 hours", 2880 : "2 days", 5760 : "4 days" }
10178 + for (var i in options) { y += '<option value=' + i + '>' + options[i] + '</option>'; }
10179 + x += addHtmlValue("Token Name", '<input id=d2tokenName style=width:250px maxlength=100 type=text onchange=account_createLoginTokenValidate() onkeyup=account_createLoginTokenValidate() />');
10180 + x += addHtmlValue("Expire Time", '<select id=d2tokenExpire style=width:250px>' + y + '</select>');
10181 + setDialogMode(2, "Create Login Token", 3, account_createLoginTokenEx, x);
10182 + QE('idx_dlgOkButton', false);
10183 + }
10184 +
10185 + function account_createLoginTokenValidate() {
10186 + QE('idx_dlgOkButton', Q('d2tokenName').value.length > 0);
10187 + }
10188 +
10189 + function account_createLoginTokenEx() {
10190 + meshserver.send({ action: 'createLoginToken', name: Q('d2tokenName').value, expire: parseInt(Q('d2tokenExpire').value) });
10191 + }
10192 +
10193 function account_showAccountNotifySettings() {
10194 if (xxdialogMode) return false;
10195 var x = '';
webserver.js
+1
@@ -2547,6 +2547,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
2547 if (((obj.args.noagentupdate == 1) || (obj.args.noagentupdate == true))) { features2 += 0x00000010; } // No agent update
2548 if (parent.amtProvisioningServer != null) { features2 += 0x00000020; } // Intel AMT LAN provisioning server
2549 if (((typeof domain.passwordrequirements != 'object') || (domain.passwordrequirements.push2factor != false)) && (obj.parent.firebase != null)) { features2 += 0x00000040; } // Indicates device push notification 2FA is enabled
2550 + if ((typeof domain.passwordrequirements != 'object') || (domain.passwordrequirements.logintokens != false)) { features2 += 0x00000080; } // Indicates login tokens are allowed
2551
2552 // Create a authentication cookie
2553 const authCookie = obj.parent.encodeCookie({ userid: dbGetFunc.user._id, domainid: domain.id, ip: req.clientIp }, obj.parent.loginCookieEncryptionKey);