From 1b9f398a4f666bd02c74e8b3135444a63be4fd28 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Sat, 10 Jul 2021 13:22:46 -0700 Subject: [PATCH] Fixed root cert link when using multi-domains, #2883. --- webserver.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/webserver.js b/webserver.js index a49d0740..668e865c 100644 --- a/webserver.js +++ b/webserver.js @@ -2874,7 +2874,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { getRenderPage((domain.sitestyle == 2) ? 'login2' : 'login', req, domain), getRenderArgs({ loginmode: loginmode, - rootCertLink: getRootCertLink(), + rootCertLink: getRootCertLink(domain), newAccount: newAccountsAllowed, newAccountPass: (((domain.newaccountspass == null) || (domain.newaccountspass == '')) ? 0 : 1), serverDnsName: obj.getWebServerName(domain), @@ -2960,9 +2960,14 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { } // Get the link to the root certificate if needed - function getRootCertLink() { + function getRootCertLink(domain) { // Check if the HTTPS certificate is issued from MeshCentralRoot, if so, add download link to root certificate. - if ((obj.args.tlsoffload == null) && (obj.parent.config.letsencrypt == null) && (obj.tlsSniCredentials == null) && (obj.certificates.WebIssuer.indexOf('MeshCentralRoot-') == 0) && (obj.certificates.CommonName.indexOf('.') != -1)) { return 'Root Certificate'; } + if (obj.isTrustedCert(domain) == false) { + // Get the domain suffix + var xdomain = (domain.dns == null) ? domain.id : ''; + if (xdomain != '') xdomain += '/'; + return 'Root Certificate'; + } return ''; } @@ -3193,10 +3198,10 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { setContentDispositionHeader(res, 'application/octet-stream', filename, null, 'file.bin'); try { res.sendFile(obj.path.resolve(__dirname, path)); } catch (e) { res.sendStatus(404); } } else { - render(req, res, getRenderPage((domain.sitestyle == 2) ? 'download2' : 'download', req, domain), getRenderArgs({ rootCertLink: getRootCertLink(), messageid: 1, fileurl: req.path + '?download=1', filename: filename, filesize: stat.size }, req, domain)); + render(req, res, getRenderPage((domain.sitestyle == 2) ? 'download2' : 'download', req, domain), getRenderArgs({ rootCertLink: getRootCertLink(domain), messageid: 1, fileurl: req.path + '?download=1', filename: filename, filesize: stat.size }, req, domain)); } } else { - render(req, res, getRenderPage((domain.sitestyle == 2) ? 'download2' : 'download', req, domain), getRenderArgs({ rootCertLink: getRootCertLink(), messageid: 2 }, req, domain)); + render(req, res, getRenderPage((domain.sitestyle == 2) ? 'download2' : 'download', req, domain), getRenderArgs({ rootCertLink: getRootCertLink(domain), messageid: 2 }, req, domain)); } }