Skip to content

Node.js based forum software built for the modern web

feat(admin): add localhost and URL mismatch warnings to dashboard notices

Julian Lam644034d48b5f
diff --git a/public/language/en-GB/admin/dashboard.json b/public/language/en-GB/admin/dashboard.json
index 1cec2284e7..bc14cf5091 100644
--- a/public/language/en-GB/admin/dashboard.json
+++ b/public/language/en-GB/admin/dashboard.json
@@ -35,6 +35,8 @@
"prerelease-warning": "This is a <strong>pre-release</strong> version of NodeBB. Unintended bugs may occur. <i class=\"fa fa-exclamation-triangle\"></i>",
"fallback-emailer-not-found": "Fallback emailer not found!",
"running-in-development": "Forum is running in development mode. The forum may be open to potential vulnerabilities; please contact your system administrator",
+ "localhost-warning": "NodeBB is configured with a localhost URL. This should be updated to your actual domain.",
+ "url-mismatch-warning": "Admin panel accessed from a URL different from what is configured in config.json. (Requested: %1, Configured: %2)",
"latest-lookup-failed": "Failed to look up latest available version of NodeBB",
"notices": "Notices",
diff --git a/src/controllers/admin/dashboard.js b/src/controllers/admin/dashboard.js
index c58d82e661..a865e03b95 100644
--- a/src/controllers/admin/dashboard.js
+++ b/src/controllers/admin/dashboard.js
@@ -5,6 +5,7 @@ const semver = require('semver');
const winston = require('winston');
const _ = require('lodash');
+const tx = require('../../translator');
const versions = require('../../admin/versions');
const db = require('../../database');
const meta = require('../../meta');
@@ -21,7 +22,7 @@ const dashboardController = module.exports;
dashboardController.get = async function (req, res) {
const [stats, notices, latestVersion, lastrestart, isAdmin, popularSearches] = await Promise.all([
getStats(),
- getNotices(),
+ getNotices(req),
getLatestVersion(),
getLastRestart(),
user.isAdministrator(req.uid),
@@ -47,7 +48,7 @@ dashboardController.get = async function (req, res) {
});
};
-async function getNotices() {
+async function getNotices(req) {
const notices = [
{
done: !meta.reloadRequired,
@@ -77,6 +78,25 @@ async function getNotices() {
});
}
+ const configuredUrl = nconf.get('url');
+ if (configuredUrl === 'http://localhost:4567') {
+ notices.push({
+ done: false,
+ notDoneText: '[[admin/dashboard:localhost-warning]]',
+ });
+ }
+
+ if (configuredUrl && req) {
+ const requestHost = req.get('host');
+ const configuredHost = new URL(configuredUrl).host;
+ if (requestHost !== configuredHost) {
+ notices.push({
+ done: false,
+ notDoneText: tx.compile('admin/dashboard:url-mismatch-warning', requestHost, configuredHost),
+ });
+ }
+ }
+
return await plugins.hooks.fire('filter:admin.notices', notices);
}