From 7081c7dcc418627362e655449ed15f80264f76a4 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 28 Feb 2014 16:50:39 -0500 Subject: [PATCH 01/11] moved ip log to api --- src/routes/api.js | 3 +++ src/webserver.js | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/routes/api.js b/src/routes/api.js index 4b326fe565..d7e4419b22 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -30,6 +30,9 @@ var path = require('path'), user.updateLastOnlineTime(req.user.uid); } + // Log IP address + db.sortedSetAdd('ip:recent', +new Date(), req.ip || 'Unknown'); + next(); }); diff --git a/src/webserver.js b/src/webserver.js index b4d5afe7b6..8d340c3dd1 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -289,9 +289,6 @@ process.on('uncaughtException', function(err) { // Disable framing res.setHeader('X-Frame-Options', 'SAMEORIGIN'); - // Log IP address - db.sortedSetAdd('ip:recent', +new Date(), req.ip || 'Unknown'); - next(); }); From e75c303b89bc21d9e775738e1a3cc44f25aafa96 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 28 Feb 2014 17:19:42 -0500 Subject: [PATCH 02/11] added unique visitor count to admin dashboard --- public/src/forum/admin/index.js | 11 +++++++++++ public/templates/admin/index.tpl | 25 +++++++++++++++++++++++++ src/routes/api.js | 3 +-- src/socket.io/admin.js | 25 +++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/public/src/forum/admin/index.js b/public/src/forum/admin/index.js index 1870884328..7c9f6db3bd 100644 --- a/public/src/forum/admin/index.js +++ b/public/src/forum/admin/index.js @@ -35,6 +35,17 @@ define(function() { $('.restart').on('click', function() { socket.emit('admin.restart'); }); + + socket.emit('admin.getVisitorCount', function(err, data) { + if(err) { + return app.alertError(err.message); + } + + var uniqueVisitors = $('#unique-visitors'); + for(var key in data) { + uniqueVisitors.find('#' + key).text(data[key]); + } + }); }; Admin.updateRoomUsage = function(err, data) { diff --git a/public/templates/admin/index.tpl b/public/templates/admin/index.tpl index 2d548c459c..3fac2b0917 100644 --- a/public/templates/admin/index.tpl +++ b/public/templates/admin/index.tpl @@ -36,4 +36,29 @@ +
+
+
Unique Visitors
+
+
+
+
+
Day
+
+
+
+
Week
+
+
+
+
Month
+
+
+
+
All Time
+
+
+
+
+
\ No newline at end of file diff --git a/src/routes/api.js b/src/routes/api.js index d7e4419b22..134964d185 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -30,8 +30,7 @@ var path = require('path'), user.updateLastOnlineTime(req.user.uid); } - // Log IP address - db.sortedSetAdd('ip:recent', +new Date(), req.ip || 'Unknown'); + db.sortedSetAdd('ip:recent', Date.now(), req.ip || 'Unknown'); next(); }); diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index 3d5fd87726..316d77a347 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -9,6 +9,7 @@ var groups = require('../groups'), categories = require('../categories'), CategoryTools = require('../categoryTools'), logger = require('../logger'), + db = require('../database'), admin = { user: require('../admin/user'), categories: require('../admin/categories') @@ -35,6 +36,30 @@ SocketAdmin.restart = function(socket, data, callback) { meta.restart(); }; + +SocketAdmin.getVisitorCount = function(socket, data, callback) { + var terms = { + day: 86400000, + week: 604800000, + month: 2592000000 + }; + var now = Date.now(); + async.parallel({ + day: function(next) { + db.sortedSetCount('ip:recent', now - terms.day, now, next); + }, + week: function(next) { + db.sortedSetCount('ip:recent', now - terms.week, now, next); + }, + month: function(next) { + db.sortedSetCount('ip:recent', now - terms.month, now, next); + }, + alltime: function(next) { + db.sortedSetCount('ip:recent', 0, now, next); + } + }, callback); +} + /* Topics */ SocketAdmin.topics = {}; From 84dc012198c74fc58417e674433845947c41c4ac Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 28 Feb 2014 18:17:17 -0500 Subject: [PATCH 03/11] closes #1142 --- public/src/forum/topic.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 84eafc8621..4ab60fe365 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -141,16 +141,16 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { } loadingEl.remove(); - categoriesEl.on('click', function(e) { - var el = $(e.target); + categoriesEl.on('click', 'li[data-cid]', function(e) { + var el = $(this); if (el.is('li')) { - confirmCat.html(e.target.innerHTML); + confirmCat.html(el.html()); confirmDiv.css({display: 'block'}); targetCid = el.attr('data-cid'); - targetCatLabel = e.html(); + targetCatLabel = el.html(); commitEl.prop('disabled', false); } - }, false); + }); commitEl.on('click', function() { if (!commitEl.prop('disabled') && targetCid) { From d63ff461f319487abcdb1fe2455f2b9420094687 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 28 Feb 2014 19:56:00 -0500 Subject: [PATCH 04/11] changed executable to not run watch-mode using the loader --- nodebb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodebb b/nodebb index d33baeba04..26ec782725 100755 --- a/nodebb +++ b/nodebb @@ -56,7 +56,7 @@ case "$1" in echo "Launching NodeBB in \"development\" mode." echo "To run the production build of NodeBB, please use \"forever\"." echo "More Information: https://github.com/designcreateplay/NodeBB/wiki/How-to-run-NodeBB" - NODE_ENV=development supervisor -q --extensions 'node|js|tpl' -- loader "$@" + NODE_ENV=development supervisor -q --extensions 'node|js|tpl' -- app "$@" ;; *) From 5e2460e17e23b6534d5701266bf473494bac356b Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 28 Feb 2014 20:05:19 -0500 Subject: [PATCH 05/11] fixed #1144 --- src/plugins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins.js b/src/plugins.js index 4d01840498..9462785054 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -246,7 +246,7 @@ var fs = require('fs'), `data.priority`, the relative priority of the method when it is eventually called (default: 10) */ - if (data.hook && data.method) { + if (data.hook && data.method && typeof data.method === 'string' && data.method.length > 0) { data.id = id; if (!data.priority) data.priority = 10; data.method = data.method.split('.').reduce(function(memo, prop) { From 5540313b7f913e939f49c925e7a443df8ebdd6c1 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 28 Feb 2014 20:13:28 -0500 Subject: [PATCH 06/11] fixing path resolution for plugins in production mode --- src/meta.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/meta.js b/src/meta.js index f4411904fd..88e8504762 100644 --- a/src/meta.js +++ b/src/meta.js @@ -3,6 +3,7 @@ var fs = require('fs'), async = require('async'), winston = require('winston'), nconf = require('nconf'), + _ = require('underscore'), utils = require('./../public/src/utils'), translator = require('./../public/src/translator'), @@ -250,12 +251,17 @@ var fs = require('fs'), jsPath = path.normalize(jsPath); if (jsPath.substring(0, 7) === 'plugins') { - var paths = jsPath.split(path.sep), - mappedPath = paths[1]; + var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) { + if (jsPath.match(mappedPath)) { + return mappedPath; + } else { + return null; + } + }).filter(function(a) { return a; }); - if (plugins.staticDirs[mappedPath]) { - jsPath = jsPath.replace(path.join('plugins', mappedPath), ''); - return path.join(plugins.staticDirs[mappedPath], jsPath); + if (matches.length) { + var relPath = jsPath.slice(new String('plugins/' + matches[0]).length); + return plugins.staticDirs[matches[0]] + relPath; } else { winston.warn('[meta.scripts.get] Could not resolve mapped path: ' + mappedPath + '. Are you sure it is defined by a plugin?'); return null; From 1c19ae48bd8ede4626cab81430650573c87db501 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 28 Feb 2014 20:39:27 -0500 Subject: [PATCH 07/11] fixed #1143 -- also removed near-meaningless info messages saying that a Hook had been registered. --- src/plugins.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/plugins.js b/src/plugins.js index 9462785054..f334d8b0da 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -246,24 +246,31 @@ var fs = require('fs'), `data.priority`, the relative priority of the method when it is eventually called (default: 10) */ + var method; + if (data.hook && data.method && typeof data.method === 'string' && data.method.length > 0) { data.id = id; if (!data.priority) data.priority = 10; - data.method = data.method.split('.').reduce(function(memo, prop) { - if (memo[prop]) { + method = data.method.split('.').reduce(function(memo, prop) { + if (memo !== null && memo[prop]) { return memo[prop]; } else { - // Couldn't find method by path, assuming property with periods in it (evil!) - Plugins.libraries[data.id][data.method]; + // Couldn't find method by path, aborting + return null; } }, Plugins.libraries[data.id]); + if (method === null) { + winston.warn('[plugins/' + id + '] Hook method mismatch: ' + data.hook + ' => ' + data.method); + return callback(); + } + + // Write the actual method reference to the hookObj + data.method = method; + Plugins.loadedHooks[data.hook] = Plugins.loadedHooks[data.hook] || []; Plugins.loadedHooks[data.hook].push(data); - if (global.env === 'development') { - winston.info('[plugins] Hook registered: ' + data.hook + ' will call ' + id); - } callback(); } else return; }; From 24b669bd396f49de392c34d22f7bcfa6ed17ca19 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 28 Feb 2014 20:47:49 -0500 Subject: [PATCH 08/11] some fixes for search plugin --- src/postTools.js | 4 +--- src/posts.js | 4 ++-- src/routes/api.js | 10 ++++------ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/postTools.js b/src/postTools.js index a097df2d30..b610e19415 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -90,9 +90,7 @@ var winston = require('winston'), topics.setTopicField(tid, 'thumb', options.topic_thumb); - db.searchRemove('topic', tid, function() { - db.searchIndex('topic', title, tid); - }); + plugins.fireHook('action:topic.edit', tid); } posts.getPostData(pid, function(err, postData) { diff --git a/src/posts.js b/src/posts.js index 18d71deb0f..ac428870d0 100644 --- a/src/posts.js +++ b/src/posts.js @@ -92,10 +92,10 @@ var db = require('./database'), return next(err); } - postData.content = content; - plugins.fireHook('action:post.save', postData); + postData.content = content; + next(null, postData); }); } diff --git a/src/routes/api.js b/src/routes/api.js index 134964d185..3274b4c584 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -393,15 +393,13 @@ var path = require('path'), return res.redirect('/404'); } - var limit = 50; - function searchPosts(callback) { Plugins.fireHook('filter:search.query', { index: 'post', - query: req.params.terms + query: req.params.term }, function(err, pids) { if (err) { - return callback(err, null); + return callback(err); } posts.getPostSummaryByPids(pids, false, callback); @@ -411,10 +409,10 @@ var path = require('path'), function searchTopics(callback) { Plugins.fireHook('filter:search.query', { index: 'topic', - query: req.params.terms + query: req.params.term }, function(err, tids) { if (err) { - return callback(err, null); + return callback(err); } topics.getTopicsByTids(tids, 0, callback); From 1f136c6a727cc5e6f8eeb786bfa89f28dcdd5ab6 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 28 Feb 2014 20:51:12 -0500 Subject: [PATCH 09/11] ninjafix to mappedPath --- src/meta.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meta.js b/src/meta.js index 88e8504762..93f53e04d3 100644 --- a/src/meta.js +++ b/src/meta.js @@ -263,7 +263,7 @@ var fs = require('fs'), var relPath = jsPath.slice(new String('plugins/' + matches[0]).length); return plugins.staticDirs[matches[0]] + relPath; } else { - winston.warn('[meta.scripts.get] Could not resolve mapped path: ' + mappedPath + '. Are you sure it is defined by a plugin?'); + winston.warn('[meta.scripts.get] Could not resolve mapped path: ' + jsPath + '. Are you sure it is defined by a plugin?'); return null; } } else { From 8eca1955304bcc7c9330387e02cb30590e36cdce Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 28 Feb 2014 22:08:33 -0500 Subject: [PATCH 10/11] updateHeader once on load --- public/src/forum/topic.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 4ab60fe365..9a86aaec32 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -322,11 +322,10 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { localStorage.removeItem('topic:' + tid + ':bookmark'); } }); - updateHeader(); - } else { - updateHeader(); } + updateHeader(); + $('#post-container').on('mouseenter', '.favourite-tooltip', function(e) { if (!$(this).data('users-loaded')) { $(this).data('users-loaded', "true"); From 0fecbf7cbffb5553fd0c046075ed55b18a689964 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 28 Feb 2014 23:38:04 -0500 Subject: [PATCH 11/11] entity decoding in filenames --- src/routes/plugins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/plugins.js b/src/routes/plugins.js index 774fee7217..00f37d8d02 100644 --- a/src/routes/plugins.js +++ b/src/routes/plugins.js @@ -44,7 +44,7 @@ var nconf = require('nconf'), if (matches) { async.map(matches, function(mappedPath, next) { - var filePath = path.join(plugins.staticDirs[mappedPath], relPath.slice(mappedPath.length)); + var filePath = path.join(plugins.staticDirs[mappedPath], decodeURIComponent(relPath.slice(mappedPath.length))); fs.exists(filePath, function(exists) { if (exists) {