Added unknownUserRootRedirect option, #3172

Ylian Saint-Hilaire committed Oct 8, 2021 at 13:24 UTC 09b2a3bba89c0df34ce86168a446debc08d55eaf
3 files changed +12 -5
meshcentral-config-schema.json
+1
@@ -282,6 +282,7 @@
282 "titlePicture": { "type": "string", "default": null, "description": "Web site .png logo file that is 450x66 in size placed in meshcentral-data that is used on the top of many pages." },
283 "loginPicture": { "type": "string", "default": null, "description": "Web site .png logo file placed in meshcentral-data that used on the login page when sitestyle is 2." },
284 "rootRedirect": { "type": "string", "default": null, "description": "Redirects HTTP root requests to this URL. When in use, direct users to /login to see the normal login page." },
285 + "unknownUserRootRedirect": { "type": "string", "default": null, "description": "Redirects HTTP root requests to this URL only where user is not already logged in. When in use, direct users to /login to see the normal login page." },
286 "userQuota": { "type": "integer" },
287 "meshQuota": { "type": "integer" },
288 "loginKey": { "type": [ "string", "array" ], "items": { "type": "string" }, "default": null, "description": "Requires that users add the value ?key=xxx in the URL in order to see the web site." },
meshctrl.js
+1 -1
@@ -837,7 +837,7 @@ if (args['_'].length == 0) {
837 var localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(0, -5);
838 console.log("List sharing links for a specified device, Example usages:\r\n");
839 console.log(winRemoveSingleQuotes(" MeshCtrl DeviceSharing --id 'deviceid'"));
840 - console.log(winRemoveSingleQuotes(" MeshCtrl DeviceSharing --id 'deviceid' --remote abcdef"));
840 + console.log(winRemoveSingleQuotes(" MeshCtrl DeviceSharing --id 'deviceid' --remove abcdef"));
841 console.log(winRemoveSingleQuotes(" MeshCtrl DeviceSharing --id 'deviceid' --add Guest --start " + localISOTime + " --duration 30"));
842 console.log(winRemoveSingleQuotes(" MeshCtrl DeviceSharing --id 'deviceid' --add Guest --type terminal --consent prompt"));
843 console.log("\r\nRequired arguments:\r\n");
webserver.js
+10 -4
@@ -2435,6 +2435,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
2435 return;
2436 }
2437
2438 + // If set and there is no user logged in, redirect the root page. Make sure not to redirect if /login is used
2439 + if ((typeof domain.unknownuserrootredirect == 'string') && ((req.session == null) || (req.session.userid == null))) {
2440 + var q = require('url').parse(req.url, true);
2441 + if (!q.pathname.endsWith('/login')) { res.redirect(domain.unknownuserrootredirect + getQueryPortion(req)); return; }
2442 + }
2443 +
2444 if ((domain.sspi != null) && ((req.query.login == null) || (obj.parent.loginCookieEncryptionKey == null))) {
2445 // Login using SSPI
2446 domain.sspi.authenticate(req, res, function (err) {
@@ -5642,13 +5648,13 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5648 if ((parent.config.domains[i].dns != null) || (parent.config.domains[i].share != null)) { continue; } // This is a subdomain with a DNS name, no added HTTP bindings needed.
5649 var domain = parent.config.domains[i];
5650 var url = domain.url;
5645 - if (domain.rootredirect == null) {
5651 + if (typeof domain.rootredirect == 'string') {
5652 + // Root page redirects the user to a different URL
5653 + obj.app.get(url, handleRootRedirect);
5654 + } else {
5655 // Present the login page as the root page
5656 obj.app.get(url, handleRootRequest);
5657 obj.app.post(url, handleRootPostRequest);
5649 - } else {
5650 - // Root page redirects the user to a different URL
5651 - obj.app.get(url, handleRootRedirect);
5658 }
5659 obj.app.get(url + 'refresh.ashx', function (req, res) { res.sendStatus(200); });
5660 if ((domain.myserver !== false) && ((domain.myserver == null) || (domain.myserver.backup === true))) { obj.app.get(url + 'backup.zip', handleBackupRequest); }