From 5ca931a52c1a9112ad8638c7a5f5de5e9e2001b8 Mon Sep 17 00:00:00 2001 From: pichalite Date: Fri, 17 Feb 2017 22:07:50 +0000 Subject: [PATCH 1/5] Update gruntfile to build on initialization --- Gruntfile.js | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 85ea76938f..1c69a6726f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,24 +1,24 @@ "use strict"; -var fork = require('child_process').fork, - env = process.env, - worker, updateWorker, - incomplete = [], - running = 0; - +var fork = require('child_process').fork; +var env = process.env; +var worker, updateWorker, initWorker; +var incomplete = []; +var running = 0; module.exports = function (grunt) { var args = []; + var initArgs = ['--build']; if (!grunt.option('verbose')) { args.push('--log-level=info'); + initArgs.push('--log-level=info'); } function update(action, filepath, target) { - var updateArgs = args.slice(), - fromFile = '', - compiling = '', - time = Date.now(); - + var updateArgs = args.slice(); + var compiling = ''; + var time = Date.now(); + if (target === 'lessUpdated_Client') { compiling = 'clientCSS'; } else if (target === 'lessUpdated_Admin') { @@ -44,12 +44,16 @@ module.exports = function (grunt) { if (updateWorker) { updateWorker.kill('SIGKILL'); } - updateWorker = fork('app.js', updateArgs, { env: env }); + updateWorker = fork('app.js', updateArgs, { + env: env + }); ++running; updateWorker.on('exit', function () { --running; if (running === 0) { - worker = fork('app.js', args, { env: env }); + worker = fork('app.js', args, { + env: env + }); worker.on('message', function () { if (incomplete.length) { incomplete = []; @@ -136,10 +140,18 @@ module.exports = function (grunt) { } else { grunt.registerTask('default', ['watch']); } - env.NODE_ENV = 'development'; - worker = fork('app.js', args, { env: env }); + initWorker = fork('app.js', initArgs, { + env: env + }); + + initWorker.on('exit', function () { + worker = fork('app.js', args, { + env: env + }); + }); + grunt.event.on('watch', update); -}; \ No newline at end of file +}; From bb3c8b910a59284285804dd984cf761ba96cba83 Mon Sep 17 00:00:00 2001 From: pichalite Date: Fri, 17 Feb 2017 23:33:37 +0000 Subject: [PATCH 2/5] Skip option skips build --- Gruntfile.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 1c69a6726f..f3c4f1723e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -135,23 +135,24 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-watch'); - if (grunt.option('skip')) { - grunt.registerTask('default', ['watch:serverUpdated']); - } else { - grunt.registerTask('default', ['watch']); - } - + grunt.registerTask('default', ['watch']); env.NODE_ENV = 'development'; - initWorker = fork('app.js', initArgs, { - env: env - }); - - initWorker.on('exit', function () { + if (grunt.option('skip')) { worker = fork('app.js', args, { env: env }); - }); + } else { + initWorker = fork('app.js', initArgs, { + env: env + }); + + initWorker.on('exit', function () { + worker = fork('app.js', args, { + env: env + }); + }); + } grunt.event.on('watch', update); }; From 458cbfd603155470c7e71913c34f597b732555c0 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 23 Feb 2017 12:14:20 -0500 Subject: [PATCH 3/5] show dashboard notice if forum is running in dev mode --- public/language/en-GB/admin/general/dashboard.json | 1 + src/controllers/admin/dashboard.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/public/language/en-GB/admin/general/dashboard.json b/public/language/en-GB/admin/general/dashboard.json index a70dda322e..02046bd17a 100644 --- a/public/language/en-GB/admin/general/dashboard.json +++ b/public/language/en-GB/admin/general/dashboard.json @@ -21,6 +21,7 @@ "upgrade-available": "

A new version (v%1) has been released. Consider upgrading your NodeBB.

", "prerelease-upgrade-available": "

This is an outdated pre-release version of NodeBB. A new version (v%1) has been released. Consider upgrading your NodeBB.

", "prerelease-warning": "

This is a pre-release version of NodeBB. Unintended bugs may occur.

", + "running-in-development": "Forum is running in development mode. The forum may be open to potential vulnerabilities; please contact your system administrator.", "notices": "Notices", "restart-not-required": "Restart not required", diff --git a/src/controllers/admin/dashboard.js b/src/controllers/admin/dashboard.js index 09c2838d73..2ffbea0e98 100644 --- a/src/controllers/admin/dashboard.js +++ b/src/controllers/admin/dashboard.js @@ -30,6 +30,14 @@ dashboardController.get = function (req, res, next) { link:'/admin/extend/plugins' } ]; + + if (global.env !== 'production') { + notices.push({ + done: false, + notDoneText: '[[admin/general/dashboard:running-in-development]]' + }); + } + plugins.fireHook('filter:admin.notices', notices, next); } }, function (err, results) { From 9079ee5b143db78d1186eb8ef2466c46b1b9291b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 23 Feb 2017 20:44:14 +0300 Subject: [PATCH 4/5] style --- src/middleware/header.js | 203 ++++++++++++++++++++------------------- 1 file changed, 105 insertions(+), 98 deletions(-) diff --git a/src/middleware/header.js b/src/middleware/header.js index 5e78416a0a..0c33e621e5 100644 --- a/src/middleware/header.js +++ b/src/middleware/header.js @@ -59,115 +59,122 @@ module.exports = function (middleware) { }; templateValues.configJSON = JSON.stringify(res.locals.config); - - async.parallel({ - scripts: function (next) { - plugins.fireHook('filter:scripts.get', [], next); - }, - isAdmin: function (next) { - user.isAdministrator(req.uid, next); - }, - isGlobalMod: function (next) { - user.isGlobalModerator(req.uid, next); - }, - isModerator: function (next) { - user.isModeratorOfAnyCategory(req.uid, next); - }, - user: function (next) { - var userData = { - uid: 0, - username: '[[global:guest]]', - userslug: '', - email: '', - picture: meta.config.defaultAvatar, - status: 'offline', - reputation: 0, - 'email:confirmed': false - }; - if (req.uid) { - user.getUserFields(req.uid, Object.keys(userData), next); - } else { - next(null, userData); - } + async.waterfall([ + function (next) { + async.parallel({ + scripts: function (next) { + plugins.fireHook('filter:scripts.get', [], next); + }, + isAdmin: function (next) { + user.isAdministrator(req.uid, next); + }, + isGlobalMod: function (next) { + user.isGlobalModerator(req.uid, next); + }, + isModerator: function (next) { + user.isModeratorOfAnyCategory(req.uid, next); + }, + user: function (next) { + var userData = { + uid: 0, + username: '[[global:guest]]', + userslug: '', + email: '', + picture: meta.config.defaultAvatar, + status: 'offline', + reputation: 0, + 'email:confirmed': false + }; + if (req.uid) { + user.getUserFields(req.uid, Object.keys(userData), next); + } else { + next(null, userData); + } + }, + isEmailConfirmSent: function (next) { + if (!meta.config.requireEmailConfirmation || !req.uid) { + return next(null, false); + } + db.get('uid:' + req.uid + ':confirm:email:sent', next); + }, + navigation: async.apply(navigation.get), + tags: async.apply(meta.tags.parse, res.locals.metaTags, res.locals.linkTags), + banned: async.apply(user.isBanned, req.uid), + banReason: async.apply(user.getBannedReason, req.uid) + }, next); }, - isEmailConfirmSent: function (next) { - if (!meta.config.requireEmailConfirmation || !req.uid) { - return next(null, false); + function (results, next) { + if (results.banned) { + req.logout(); + return res.redirect('/?banned=' + (results.banReason || 'no-reason')); } - db.get('uid:' + req.uid + ':confirm:email:sent', next); - }, - navigation: async.apply(navigation.get), - tags: async.apply(meta.tags.parse, res.locals.metaTags, res.locals.linkTags), - banned: async.apply(user.isBanned, req.uid), - banReason: async.apply(user.getBannedReason, req.uid) - }, function (err, results) { - if (err) { - return callback(err); - } - if (results.banned) { - req.logout(); - return res.redirect('/?banned=' + (results.banReason || 'no-reason')); - } + results.user.isAdmin = results.isAdmin; + results.user.isGlobalMod = results.isGlobalMod; + results.user.isMod = !!results.isModerator; + results.user.uid = parseInt(results.user.uid, 10); + results.user.email = String(results.user.email).replace(/\\/g, '\\\\').replace(/"/g, '\\"'); + results.user['email:confirmed'] = parseInt(results.user['email:confirmed'], 10) === 1; + results.user.isEmailConfirmSent = !!results.isEmailConfirmSent; - results.user.isAdmin = results.isAdmin; - results.user.isGlobalMod = results.isGlobalMod; - results.user.isMod = !!results.isModerator; - results.user.uid = parseInt(results.user.uid, 10); - results.user.email = String(results.user.email).replace(/\\/g, '\\\\').replace(/"/g, '\\"'); - results.user['email:confirmed'] = parseInt(results.user['email:confirmed'], 10) === 1; - results.user.isEmailConfirmSent = !!results.isEmailConfirmSent; - - if (res.locals.config && parseInt(meta.config.disableCustomUserSkins, 10) !== 1 && res.locals.config.bootswatchSkin !== 'default') { - templateValues.bootswatchCSS = '//maxcdn.bootstrapcdn.com/bootswatch/latest/' + res.locals.config.bootswatchSkin + '/bootstrap.min.css'; - } - - templateValues.browserTitle = controllers.helpers.buildTitle(data.title); - templateValues.navigation = results.navigation; - templateValues.metaTags = results.tags.meta; - templateValues.linkTags = results.tags.link; - templateValues.isAdmin = results.user.isAdmin; - templateValues.isGlobalMod = results.user.isGlobalMod; - templateValues.showModMenu = results.user.isAdmin || results.user.isGlobalMod || results.user.isMod; - templateValues.user = results.user; - templateValues.userJSON = JSON.stringify(results.user); - templateValues.useCustomCSS = parseInt(meta.config.useCustomCSS, 10) === 1 && meta.config.customCSS; - templateValues.customCSS = templateValues.useCustomCSS ? (meta.config.renderedCustomCSS || '') : ''; - templateValues.useCustomJS = parseInt(meta.config.useCustomJS, 10) === 1; - templateValues.customJS = templateValues.useCustomJS ? meta.config.customJS : ''; - templateValues.maintenanceHeader = parseInt(meta.config.maintenanceMode, 10) === 1 && !results.isAdmin; - templateValues.defaultLang = meta.config.defaultLang || 'en-GB'; - templateValues.privateUserInfo = parseInt(meta.config.privateUserInfo, 10) === 1; - templateValues.privateTagListing = parseInt(meta.config.privateTagListing, 10) === 1; - - templateValues.template = {name: res.locals.template}; - templateValues.template[res.locals.template] = true; - - templateValues.scripts = results.scripts.map(function (script) { - return {src: script}; - }); - - if (req.route && req.route.path === '/') { - modifyTitle(templateValues); - } + if (res.locals.config && parseInt(meta.config.disableCustomUserSkins, 10) !== 1 && res.locals.config.bootswatchSkin !== 'default') { + templateValues.bootswatchCSS = '//maxcdn.bootstrapcdn.com/bootswatch/latest/' + res.locals.config.bootswatchSkin + '/bootstrap.min.css'; + } - plugins.fireHook('filter:middleware.renderHeader', {templateValues: templateValues, req: req, res: res}, function (err, data) { - if (err) { - return callback(err); + templateValues.browserTitle = controllers.helpers.buildTitle(data.title); + templateValues.navigation = results.navigation; + templateValues.metaTags = results.tags.meta; + templateValues.linkTags = results.tags.link; + templateValues.isAdmin = results.user.isAdmin; + templateValues.isGlobalMod = results.user.isGlobalMod; + templateValues.showModMenu = results.user.isAdmin || results.user.isGlobalMod || results.user.isMod; + templateValues.user = results.user; + templateValues.userJSON = JSON.stringify(results.user); + templateValues.useCustomCSS = parseInt(meta.config.useCustomCSS, 10) === 1 && meta.config.customCSS; + templateValues.customCSS = templateValues.useCustomCSS ? (meta.config.renderedCustomCSS || '') : ''; + templateValues.useCustomJS = parseInt(meta.config.useCustomJS, 10) === 1; + templateValues.customJS = templateValues.useCustomJS ? meta.config.customJS : ''; + templateValues.maintenanceHeader = parseInt(meta.config.maintenanceMode, 10) === 1 && !results.isAdmin; + templateValues.defaultLang = meta.config.defaultLang || 'en-GB'; + templateValues.privateUserInfo = parseInt(meta.config.privateUserInfo, 10) === 1; + templateValues.privateTagListing = parseInt(meta.config.privateTagListing, 10) === 1; + + templateValues.template = {name: res.locals.template}; + templateValues.template[res.locals.template] = true; + + templateValues.scripts = results.scripts.map(function (script) { + return {src: script}; + }); + + if (req.route && req.route.path === '/') { + modifyTitle(templateValues); } - req.app.render('header', data.templateValues, callback); - }); - }); + plugins.fireHook('filter:middleware.renderHeader', { + req: req, + res: res, + templateValues: templateValues + }, next); + }, + function (data, next) { + req.app.render('header', data.templateValues, next); + } + ], callback); }; middleware.renderFooter = function (req, res, data, callback) { - plugins.fireHook('filter:middleware.renderFooter', {templateValues: data, req: req, res: res}, function (err, data) { - if (err) { - return callback(err); + async.waterfall([ + function (next) { + plugins.fireHook('filter:middleware.renderFooter', { + req: req, + res: res, + templateValues: data, + }, next); + }, + function (data, next) { + req.app.render('footer', data.templateValues, next); } - req.app.render('footer', data.templateValues, callback); - }); + ], callback); }; function modifyTitle(obj) { From c1b1ff5c6ec5a35ed1e127edc5ccfc06dd04c5c2 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 23 Feb 2017 12:46:59 -0500 Subject: [PATCH 5/5] adding origin to new local ioConfig var, as per @barisusakli, re: #5472 --- src/socket.io/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/socket.io/index.js b/src/socket.io/index.js index f4732d9d9e..4ddf638e9e 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -22,6 +22,10 @@ Sockets.init = function (server) { var SocketIO = require('socket.io'); var socketioWildcard = require('socketio-wildcard')(); + var ioConfig = { + transports: nconf.get('socket.io:transports') + }; + io = new SocketIO({ path: nconf.get('relative_path') + '/socket.io' }); @@ -47,17 +51,15 @@ Sockets.init = function (server) { } if (!override) { - io.set('origins', parsedUrl.protocol + '//' + domain + ':*'); + ioConfig.origins = parsedUrl.protocol + '//' + domain + ':*'; winston.info('[socket.io] Restricting access to origin: ' + parsedUrl.protocol + '//' + domain + ':*'); } else { - io.set('origins', override); + ioConfig.origins = override; winston.info('[socket.io] Restricting access to origin: ' + override); } } - io.listen(server, { - transports: nconf.get('socket.io:transports') - }); + io.listen(server, ioConfig); Sockets.server = io; };