Added .well-known support.
Ylian Saint-Hilaire committed
Dec 21, 2020 at 23:25 UTC
23290232593c2831aad6f6fe8044010c84745dca
2 files changed
+19
-9
redirserver.js
+7
-3
@@ -94,9 +94,9 @@ module.exports.CreateRedirServer = function (parent, db, args, func) {
94
for (var i in parent.config.domains) {
95
if (parent.config.domains[i].dns != null) { continue; }
96
var url = parent.config.domains[i].url;
97
- obj.app.post(url + "amtevents.ashx", obj.parent.webserver.handleAmtEventRequest);
98
- obj.app.get(url + "meshsettings", obj.parent.webserver.handleMeshSettingsRequest);
99
- obj.app.get(url + "meshagents", obj.parent.webserver.handleMeshAgentRequest);
97
+ obj.app.post(url + 'amtevents.ashx', obj.parent.webserver.handleAmtEventRequest);
98
+ obj.app.get(url + 'meshsettings', obj.parent.webserver.handleMeshSettingsRequest);
99
+ obj.app.get(url + 'meshagents', obj.parent.webserver.handleMeshAgentRequest);
100
101
// Server redirects
102
if (parent.config.domains[i].redirects) {
@@ -115,6 +115,10 @@ module.exports.CreateRedirServer = function (parent, db, args, func) {
115
obj.app.get(url, performRedirection); // Root redirection
116
obj.app.get(url + 'player.htm', performRedirection); // Player redirection
117
118
+ // Setup any .well-known folders
119
+ var p = obj.parent.path.join(obj.parent.datapath, '.well-known' + ((parent.config.domains[i].id == '') ? '' : ('-' + parent.config.domains[i].id)));
120
+ if (obj.parent.fs.existsSync(p)) { obj.app.use(url + '.well-known', obj.express.static(p)); }
121
+
122
// Setup all of the redirections to HTTPS
123
const redirections = ['terms', 'logout', 'MeshServerRootCert.cer', 'mescript.ashx', 'checkmail', 'agentinvite', 'messenger', 'meshosxagent', 'devicepowerevents.ashx', 'downloadfile.ashx', 'userfiles/*', 'webrelay.ashx', 'health.ashx', 'logo.png', 'welcome.jpg'];
124
for (i in redirections) { obj.app.get(url + redirections[i], performRedirection); }
webserver.js
+12
-6
@@ -5451,6 +5451,10 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5451
});
5452
}
5453
5454
+ // Setup any .well-known folders
5455
+ var p = obj.parent.path.join(obj.parent.datapath, '.well-known' + ((parent.config.domains[i].id == '') ? '' : ('-' + parent.config.domains[i].id)));
5456
+ if (obj.parent.fs.existsSync(p)) { obj.app.use(url + '.well-known', obj.express.static(p)); }
5457
+
5458
// Setup the alternative agent-only port
5459
if (obj.agentapp) {
5460
// Receive mesh agent connections on alternate port
@@ -5558,7 +5562,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5562
parent.debug('web', 'Sending 2FA email to: ' + user.email);
5563
parent.mailserver.sendAccountLoginMail(domain, user.email, user.otpekey.k, obj.getLanguageCodes(req), req.query.key);
5564
// Ask for a login token & confirm email was sent
5561
- try { ws.send(JSON.stringify({ action: 'close', cause: 'noauth', msg: 'tokenrequired', email2fa: email2fa, email2fasent: true, twoFactorCookieDays: twoFactorCookieDays })); ws.close(); } catch (e) { }
5565
+ try { ws.send(JSON.stringify({ action: 'close', cause: 'noauth', msg: 'tokenrequired', email2fa: email2fa, sms2fa: sms2fa, email2fasent: true, twoFactorCookieDays: twoFactorCookieDays })); ws.close(); } catch (e) { }
5566
} else if ((req.query.token == '**sms**') && (sms2fa == true)) {
5567
// Cause a token to be sent to the user's phone number
5568
user.otpsms = { k: obj.common.zeroPad(getRandomSixDigitInteger(), 6), d: Date.now() };
@@ -5566,24 +5570,24 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5570
parent.debug('web', 'Sending 2FA SMS to: ' + user.phone);
5571
parent.smsserver.sendToken(domain, user.phone, user.otpsms.k, obj.getLanguageCodes(req));
5572
// Ask for a login token & confirm sms was sent
5569
- try { ws.send(JSON.stringify({ action: 'close', cause: 'noauth', msg: 'tokenrequired', sms2fa: sms2fa, sms2fasent: true, twoFactorCookieDays: twoFactorCookieDays })); ws.close(); } catch (e) { }
5573
+ try { ws.send(JSON.stringify({ action: 'close', cause: 'noauth', msg: 'tokenrequired', email2fa: email2fa, sms2fa: sms2fa, sms2fasent: true, twoFactorCookieDays: twoFactorCookieDays })); ws.close(); } catch (e) { }
5574
} else {
5575
// Ask for a login token
5576
parent.debug('web', 'Asking for login token');
5573
- try { ws.send(JSON.stringify({ action: 'close', cause: 'noauth', msg: 'tokenrequired', email2fa: email2fa, twoFactorCookieDays: twoFactorCookieDays })); ws.close(); } catch (e) { }
5577
+ try { ws.send(JSON.stringify({ action: 'close', cause: 'noauth', msg: 'tokenrequired', email2fa: email2fa, sms2fa: sms2fa, twoFactorCookieDays: twoFactorCookieDays })); ws.close(); } catch (e) { }
5578
}
5579
} else {
5580
checkUserOneTimePassword(req, domain, user, req.query.token, null, function (result) {
5581
if (result == false) {
5582
// Failed, ask for a login token again
5583
parent.debug('web', 'Invalid login token, asking again');
5580
- try { ws.send(JSON.stringify({ action: 'close', cause: 'noauth', msg: 'tokenrequired', email2fa: email2fa, twoFactorCookieDays: twoFactorCookieDays })); ws.close(); } catch (e) { }
5584
+ try { ws.send(JSON.stringify({ action: 'close', cause: 'noauth', msg: 'tokenrequired', email2fa: email2fa, sms2fa: sms2fa, twoFactorCookieDays: twoFactorCookieDays })); ws.close(); } catch (e) { }
5585
} else {
5586
// We are authenticated with 2nd factor.
5587
// Check email verification
5588
if (emailcheck && (user.email != null) && (user.emailVerified !== true)) {
5589
parent.debug('web', 'Invalid login, asking for email validation');
5586
- try { ws.send(JSON.stringify({ action: 'close', cause: 'emailvalidation', msg: 'emailvalidationrequired', email2fa: email2fa, email2fasent: true })); ws.close(); } catch (e) { }
5590
+ try { ws.send(JSON.stringify({ action: 'close', cause: 'emailvalidation', msg: 'emailvalidationrequired', email2fa: email2fa, sms2fa: sms2fa, email2fasent: true })); ws.close(); } catch (e) { }
5591
} else {
5592
func(ws, req, domain, user);
5593
}
@@ -5594,7 +5598,9 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5598
// Check email verification
5599
if (emailcheck && (user.email != null) && (user.emailVerified !== true)) {
5600
parent.debug('web', 'Invalid login, asking for email validation');
5597
- try { ws.send(JSON.stringify({ action: 'close', cause: 'emailvalidation', msg: 'emailvalidationrequired', email2fa: email2fa, email2fasent: true })); ws.close(); } catch (e) { }
5601
+ var email2fa = (((typeof domain.passwordrequirements != 'object') || (domain.passwordrequirements.email2factor != false)) && (parent.mailserver != null) && (user.otpekey != null));
5602
+ var sms2fa = (((typeof domain.passwordrequirements != 'object') || (domain.passwordrequirements.sms2factor != false)) && (parent.smsserver != null) && (user.phone != null));
5603
+ try { ws.send(JSON.stringify({ action: 'close', cause: 'emailvalidation', msg: 'emailvalidationrequired', email2fa: email2fa, sms2fa: sms2fa, email2fasent: true })); ws.close(); } catch (e) { }
5604
} else {
5605
// We are authenticated
5606
func(ws, req, domain, user);