From d67ae5c2be6a0eaf0c09b5939620901cb0af993c Mon Sep 17 00:00:00 2001 From: psychobunny Date: Sat, 25 Jan 2014 00:05:41 -0500 Subject: [PATCH 1/4] changing undetected minified JS file warning to info message instead --- src/meta.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meta.js b/src/meta.js index dd272bd796..7b3e7b6228 100644 --- a/src/meta.js +++ b/src/meta.js @@ -255,7 +255,7 @@ var fs = require('fs'), }, minFile: function (next) { if (!fs.existsSync(Meta.js.minFile)) { - winston.warn('No minified client-side library found'); + winston.info('No minified client-side library found'); return next(null, 0); } From d718eca935b000be15275ebb419ff7af3c639141 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Sat, 25 Jan 2014 01:34:56 -0500 Subject: [PATCH 2/4] fixes global meta leak, and categories meta require, #873 --- src/categories.js | 1 + src/messaging.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/categories.js b/src/categories.js index 06394ee47f..3750deb459 100644 --- a/src/categories.js +++ b/src/categories.js @@ -5,6 +5,7 @@ var db = require('./database.js'), topics = require('./topics.js'), plugins = require('./plugins'), CategoryTools = require('./categoryTools'), + meta = require('./meta'), async = require('async'), winston = require('winston'), diff --git a/src/messaging.js b/src/messaging.js index af3b8a1183..1c9a23f9f9 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -1,7 +1,7 @@ var db = require('./database'), async = require('async'), user = require('./user'), - plugins = require('./plugins'); + plugins = require('./plugins'), meta = require('./meta'); From 393bb7245ce7a73bbd346b1c1a1d69e9172f275c Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Sat, 25 Jan 2014 12:05:48 -0500 Subject: [PATCH 3/4] closes #866 --- src/posts.js | 2 +- src/socket.io/meta.js | 2 +- src/topics.js | 6 +++--- src/upgrade.js | 39 +++++++++++++++++++++++++++++++++++++-- src/user.js | 5 ++--- src/webserver.js | 1 - 6 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/posts.js b/src/posts.js index 650311c979..b4aa4c1882 100644 --- a/src/posts.js +++ b/src/posts.js @@ -194,7 +194,7 @@ var db = require('./database'), post.user_rep = userData.reputation || 0; post.user_postcount = userData.postcount || 0; post.user_banned = parseInt(userData.banned, 10) === 1; - post.picture = userData.picture || gravatar.url('', {}, https = nconf.get('https')); + post.picture = userData.picture || gravatar.url('', {}, true); if(meta.config.disableSignatures === undefined || parseInt(meta.config.disableSignatures, 10) === 0) { post.signature = signature; diff --git a/src/socket.io/meta.js b/src/socket.io/meta.js index 106c6d5621..096c7553b3 100644 --- a/src/socket.io/meta.js +++ b/src/socket.io/meta.js @@ -58,7 +58,7 @@ SocketMeta.updateHeader = function(socket, data, callback) { email: '', picture: gravatar.url('', { s: '24' - }, nconf.get('https')), + }, true), config: { allowGuestSearching: meta.config.allowGuestSearching } diff --git a/src/topics.js b/src/topics.js index aeac06f43e..2183ddc354 100644 --- a/src/topics.js +++ b/src/topics.js @@ -713,14 +713,14 @@ var async = require('async'), topicData.unreplied = parseInt(topicData.postcount, 10) === 1; topicData.username = topicInfo.username || 'anonymous'; topicData.userslug = topicInfo.userslug || ''; - topicData.picture = topicInfo.picture || gravatar.url('', {}, https = nconf.get('https')); + topicData.picture = topicInfo.picture || gravatar.url('', {}, true); topicData.categoryIcon = topicInfo.categoryData.icon; topicData.categoryName = topicInfo.categoryData.name; topicData.categorySlug = topicInfo.categoryData.slug; topicData.badgeclass = (topicInfo.hasread && parseInt(current_user, 10) !== 0) ? '' : 'badge-important'; topicData.teaser_username = topicInfo.teaserInfo.username || ''; topicData.teaser_userslug = topicInfo.teaserInfo.userslug || ''; - topicData.teaser_userpicture = topicInfo.teaserInfo.picture || gravatar.url('', {}, https = nconf.get('https')); + topicData.teaser_userpicture = topicInfo.teaserInfo.picture || gravatar.url('', {}, true); topicData.teaser_pid = topicInfo.teaserInfo.pid; topicData.teaser_timestamp = utils.toISOString(topicInfo.teaserInfo.timestamp); @@ -1018,7 +1018,7 @@ var async = require('async'), pid: postData.pid, username: userData.username || 'anonymous', userslug: userData.userslug, - picture: userData.picture || gravatar.url('', {}, https = nconf.get('https')), + picture: userData.picture || gravatar.url('', {}, true), timestamp: postData.timestamp }); }); diff --git a/src/upgrade.js b/src/upgrade.js index 688d84183f..8eff8db0c7 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -17,7 +17,7 @@ var db = require('./database'), Upgrade.check = function(callback) { // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema - var latestSchema = new Date(2014, 0, 23, 16, 5).getTime(); + var latestSchema = new Date(2014, 0, 25, 0, 0).getTime(); db.get('schemaDate', function(err, value) { if (parseInt(value, 10) >= latestSchema) { @@ -318,11 +318,46 @@ Upgrade.upgrade = function(callback) { winston.info('[2014/1/23] Updating Administrators Group'); next(); }); - }) + }); } else { winston.info('[2014/1/23] Updating Administrators Group -- skipped'); next(); } + }, + function(next) { + thisSchemaDate = new Date(2014, 0, 25, 0, 0).getTime(); + if (schemaDate < thisSchemaDate) { + updatesMade = true; + + db.getSortedSetRange('users:joindate', 0, -1, function(err, uids) { + if(err) { + return next(err); + } + + if(!uids || !uids.length) { + winston.info('[2014/1/25] Updating User Gravatars to HTTPS -- skipped'); + return next(); + } + + var gravatar = require('gravatar'); + + function updateGravatar(uid, next) { + User.getUserFields(uid, ['email', 'picture', 'gravatarpicture'], function(err, userData) { + var gravatarPicture = User.createGravatarURLFromEmail(userData.email); + if(userData.picture === userData.gravatarpicture) { + User.setUserField(uid, 'picture', gravatarPicture); + } + User.setUserField(uid, 'gravatarpicture', gravatarPicture, next); + }); + } + + winston.info('[2014/1/25] Updating User Gravatars to HTTPS'); + async.each(uids, updateGravatar, next); + }); + } else { + winston.info('[2014/1/25] Updating User Gravatars to HTTPS -- skipped'); + next(); + } } // Add new schema updates here // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 17!!! diff --git a/src/user.js b/src/user.js index 2a983b0c21..14c370b451 100644 --- a/src/user.js +++ b/src/user.js @@ -442,15 +442,14 @@ var bcrypt = require('bcrypt'), size: '128', default: 'identicon', rating: 'pg' - }, - https = nconf.get('https'); + }; if (!email) { email = ''; options.forcedefault = 'y'; } - return gravatar.url(email, options, https); + return gravatar.url(email, options, true); }; User.hashPassword = function(password, callback) { diff --git a/src/webserver.js b/src/webserver.js index bf31fd22f4..03bcf4abf3 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -200,7 +200,6 @@ if(nconf.get('ssl')) { // Local vars, other assorted setup app.use(function (req, res, next) { - nconf.set('https', req.secure); res.locals.csrf_token = req.session._csrf; // Disable framing From 2e786cc4d126e9c290d5cbf358a183a58d0b9654 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Sat, 25 Jan 2014 16:39:27 -0500 Subject: [PATCH 4/4] closes #873, removed global translator, templates and server objects --- app.js | 4 +--- public/src/templates.js | 4 ++-- src/emailer.js | 14 ++++++++------ src/routes/admin.js | 5 +++-- src/socket.io/index.js | 4 ++-- src/webserver.js | 17 +++++------------ 6 files changed, 21 insertions(+), 27 deletions(-) diff --git a/app.js b/app.js index 8dec4daa79..c4084fa676 100644 --- a/app.js +++ b/app.js @@ -106,11 +106,9 @@ upgrade.check(function(schema_ok) { if (schema_ok || nconf.get('check-schema') === false) { - sockets.init(); + sockets.init(webserver.server); plugins.init(); - global.templates = {}; - global.translator = translator; translator.loadServer(); diff --git a/public/src/templates.js b/public/src/templates.js index 06295dc79e..3e32653c1c 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -79,7 +79,7 @@ template.prototype.parse = parse; template.prototype.html = String(html); - global.templates[file] = new template; + templates[file] = new template; loaded--; if (loaded === 0) { @@ -396,7 +396,7 @@ namespace = ''; } else { // clean up all undefined conditionals - template = template.replace(//gi, ''); + template = template.replace(//gi, ''); } return template; diff --git a/src/emailer.js b/src/emailer.js index 529fdaf38f..18c48256cc 100644 --- a/src/emailer.js +++ b/src/emailer.js @@ -1,16 +1,18 @@ -var User = require('./user'), +var fs = require('fs'), + async = require('async'), + path = require('path'), + + User = require('./user'), Plugins = require('./plugins'), Meta = require('./meta'), Translator = require('../public/src/translator'), - - fs = require('fs'), - async = require('async'), - path = require('path'), + templates = require('../public/src/templates'), Emailer = {}; var render = function(template, params, callback) { - if (templates[template] !== null) { + + if (templates[template]) { Translator.translate(templates[template].parse(params), function(template) { callback(null, template); }); diff --git a/src/routes/admin.js b/src/routes/admin.js index d7c1c7863f..0cdac99a9a 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -7,13 +7,14 @@ var nconf = require('nconf'), user = require('./../user'), groups = require('../groups'), topics = require('./../topics'), - pkg = require('./../../package.json'), + pkg = require('./../../package'), categories = require('./../categories'), meta = require('../meta'), plugins = require('../plugins'), Languages = require('../languages'), events = require('./../events'), - utils = require('./../../public/src/utils.js'); + utils = require('./../../public/src/utils'), + templates = require('./../../public/src/templates'); (function (Admin) { Admin.isAdmin = function (req, res, next) { diff --git a/src/socket.io/index.js b/src/socket.io/index.js index 993b9bb8ed..90ff00d7f3 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -30,9 +30,9 @@ Sockets.userSockets = {}; Sockets.rooms = {}; -Sockets.init = function() { +Sockets.init = function(server) { - io = socketioWildcard(SocketIO).listen(global.server, { + io = socketioWildcard(SocketIO).listen(server, { log: false, transports: ['websocket', 'xhr-polling', 'jsonp-polling', 'flashsocket'], 'browser client minification': true diff --git a/src/webserver.js b/src/webserver.js index 03bcf4abf3..ee5b1a0dc6 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -28,7 +28,9 @@ var path = require('path'), meta = require('./meta'), feed = require('./feed'), plugins = require('./plugins'), - logger = require('./logger'); + logger = require('./logger'), + templates = require('./../public/src/templates'), + translator = require('./../public/src/translator'); if(nconf.get('ssl')) { server = require('https').createServer({ @@ -39,13 +41,12 @@ if(nconf.get('ssl')) { server = require('http').createServer(WebServer); } +module.exports.server = server; (function (app) { "use strict"; - var templates = null, - clientScripts; - + var clientScripts; plugins.ready(function() { // Minify client-side libraries @@ -60,9 +61,6 @@ if(nconf.get('ssl')) { }); }); - - server.app = app; - /** * `options` object requires: req, res * accepts: metaTags, linkTags @@ -375,8 +373,6 @@ if(nconf.get('ssl')) { }); module.exports.init = function () { - templates = global.templates; - // translate all static templates served by webserver here. ex. footer, logout plugins.fireHook('filter:footer.build', '', function(err, appendHTML) { var footer = templates.footer.parse({ @@ -931,6 +927,3 @@ if(nconf.get('ssl')) { }); }(WebServer)); - - -global.server = server;