From 438f90d859de6672336bbc572ea1b781296e67b2 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Tue, 31 Dec 2013 19:08:38 -0500 Subject: [PATCH 01/14] expire functionality in dbal --- src/database/mongo.js | 25 ++++++++++++++++++++----- src/database/redis.js | 8 ++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index f9b6ee8eea..9f1f8ea6a9 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -50,13 +50,20 @@ function createCollections() { db.createCollection('objects', function(err, collection) { if(err) { - winston.error("Error creating collection " + err.message); + winston.error('Error creating collection ' + err.message); return; } + if(collection) { - collection.ensureIndex({_key :1}, {background:true}, function(err, name){ + collection.ensureIndex({_key :1}, {background:true}, function(err, name) { + if(err) { + winston.error('Error creating index ' + err.message); + } + }); + + collection.ensureIndex({'expireAt':1}, {expireAfterSeconds:0, background:true}, function(err, name) { if(err) { - winston.error("Error creating index " + err.message); + winston.error('Error creating index ' + err.message); } }); } @@ -64,13 +71,13 @@ db.createCollection('search', function(err, collection) { if(err) { - winston.error("Error creating collection " + err.message); + winston.error('Error creating collection ' + err.message); return; } if(collection) { collection.ensureIndex({content:'text'}, {background:true}, function(err, name){ if(err) { - winston.error("Error creating index " + err.message); + winston.error('Error creating index ' + err.message); } }); } @@ -241,6 +248,14 @@ }); } + module.expire = function(key, seconds, callback) { + module.expireAt(key, Math.round(Date.now() / 1000) + seconds, callback); + } + + module.expireAt = function(key, timestamp, callback) { + module.setObjectField(key, 'expireAt', new Date(timestamp * 1000), callback); + } + //hashes module.setObject = function(key, data, callback) { data['_key'] = key; diff --git a/src/database/redis.js b/src/database/redis.js index 02941be081..a298980fef 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -211,6 +211,14 @@ redisClient.keys(key, callback); } + module.expire = function(key, seconds, callback) { + redisClient.expire(key, seconds, callback); + } + + module.expireAt = function(key, timestamp, callback) { + redisClient.expireat(key, timestamp, callback); + } + //hashes module.setObject = function(key, data, callback) { From fe53037e5392749ff75a4803e22161e46262746f Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 31 Dec 2013 20:28:31 -0500 Subject: [PATCH 02/14] hopefully fixing #713 --- src/webserver.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/webserver.js b/src/webserver.js index 3606113cc8..48fb5ac17c 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -55,7 +55,7 @@ var path = require('path'), /** * `options` object requires: req, res - * accepts: metaTags + * accepts: metaTags, linkTags */ app.build_header = function (options, callback) { var custom_header = { @@ -83,8 +83,6 @@ var path = require('path'), rel: 'apple-touch-icon', href: meta.config['brand:logo'] || nconf.get('relative_path') + '/logo.png' }], - metaString = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || [])), - linkTags = utils.buildLinkTags(defaultLinkTags.concat(options.linkTags || [])), templateValues = { cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css', pluginCSS: plugins.cssFiles.map(function(file) { return { path: file + (meta.config['cache-buster'] ? '?v=' + meta.config['cache-buster'] : '') }; }), @@ -106,6 +104,13 @@ var path = require('path'), var uid = '0'; + // Meta Tags + templateValues.meta_tags = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || [])).map(function(tag) { + tag.content = tag.content.replace('"', '"').replace("'", '''); + return tag; + }); + templateValues.link_tags = utils.buildLinkTags(defaultLinkTags.concat(options.linkTags || [])); + if(options.req.user && options.req.user.uid) { uid = options.req.user.uid; } From f7a1cca8619d392efb7c6e0fbbd46178acb76c26 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 31 Dec 2013 20:53:24 -0500 Subject: [PATCH 03/14] properly fixed #713 --- src/webserver.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/webserver.js b/src/webserver.js index 86e1a830db..035e8ae0b3 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -94,21 +94,28 @@ var path = require('path'), browserTitle: meta.config.title || 'NodeBB', csrf: options.res.locals.csrf_token, relative_path: nconf.get('relative_path'), - meta_tags: metaString, - link_tags: linkTags, clientScripts: clientScripts, navigation: custom_header.navigation, 'cache-buster': meta.config['cache-buster'] ? 'v=' + meta.config['cache-buster'] : '', allowRegistration: meta.config.allowRegistration === undefined || parseInt(meta.config.allowRegistration, 10) === 1 + }, + escapeList = { + '&': '&', + '<': '<', + '>': '>', + "'": ''', + '"': '"' }; var uid = '0'; // Meta Tags - templateValues.meta_tags = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || [])).map(function(tag) { - tag.content = tag.content.replace('"', '"').replace("'", '''); + templateValues.meta_tags = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || []).map(function(tag) { + tag.content = tag.content.replace(/[&<>'"]/g, function(tag) { + return escapeList[tag] || tag; + }); return tag; - }); + })); templateValues.link_tags = utils.buildLinkTags(defaultLinkTags.concat(options.linkTags || [])); if(options.req.user && options.req.user.uid) { From fd88aff195479c7af7ab5825d9480d6e5492e2ee Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Wed, 1 Jan 2014 14:11:12 -0500 Subject: [PATCH 04/14] mongo string fix --- src/database/mongo.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index 9f1f8ea6a9..fceb39d00f 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -269,6 +269,9 @@ module.setObjectField = function(key, field, value, callback) { var data = {}; // if there is a '.' in the field name it inserts subdocument in mongo, replace '.'s with \uff0E + if(typeof field !== 'string') { + field = field.toString(); + } field = field.replace(/\./g, '\uff0E'); data[field] = value; db.collection('objects').update({_key:key}, {$set:data}, {upsert:true, w: 1}, function(err, result) { @@ -318,7 +321,7 @@ var _fields = {}; for(var i=0; i Date: Wed, 1 Jan 2014 14:15:53 -0500 Subject: [PATCH 05/14] thread delete restore fix --- src/postTools.js | 2 +- src/threadTools.js | 4 ++-- src/websockets.js | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/postTools.js b/src/postTools.js index 5af411e55e..37d1ac0a53 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -152,7 +152,7 @@ var winston = require('winston'), // Delete the thread if it is the last undeleted post threadTools.getLatestUndeletedPid(postData.tid, function(err, pid) { if (err && err.message === 'no-undeleted-pids-found') { - threadTools.delete(postData.tid, function(err) { + threadTools.delete(postData.tid, uid, function(err) { if (err) { winston.error('Could not delete topic (tid: ' + postData.tid + ')', err.stack); } diff --git a/src/threadTools.js b/src/threadTools.js index 859d6faac4..b69c42fa7c 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -91,7 +91,7 @@ var winston = require('winston'), } } - ThreadTools.delete = function(tid, callback) { + ThreadTools.delete = function(tid, uid, callback) { topics.delete(tid); db.decrObjectField('global', 'topicCount'); @@ -112,7 +112,7 @@ var winston = require('winston'), } } - ThreadTools.restore = function(tid, socket, callback) { + ThreadTools.restore = function(tid, uid, callback) { topics.restore(tid); db.incrObjectField('global', 'topicCount'); ThreadTools.unlock(tid); diff --git a/src/websockets.js b/src/websockets.js index b435d4b6ec..9682e6cfef 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -562,9 +562,10 @@ websockets.init = function(io) { socket.on('api:topic.delete', function(data) { threadTools.privileges(data.tid, uid, function(err, privileges) { if (!err && privileges.editable) { - threadTools.delete(data.tid, function(err) { + threadTools.delete(data.tid, uid, function(err) { if (!err) { emitTopicPostStats(); + events.logTopicDelete(uid, data.tid); socket.emit('api:topic.delete', { status: 'ok', tid: data.tid @@ -578,7 +579,7 @@ websockets.init = function(io) { socket.on('api:topic.restore', function(data) { threadTools.privileges(data.tid, uid, function(err, privileges) { if (!err && privileges.editable) { - threadTools.restore(data.tid, socket, function(err) { + threadTools.restore(data.tid, uid, function(err) { emitTopicPostStats(); socket.emit('api:topic.restore', { From 1996e64c9b47fd54f4fdeefae801e1ef8f2a969d Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Wed, 1 Jan 2014 14:38:12 -0500 Subject: [PATCH 06/14] if imgur client id is not set but local file uploads are enabled use that --- public/src/modules/composer.js | 3 +-- src/posts.js | 36 ++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js index 192a707142..f148dc2d49 100644 --- a/public/src/modules/composer.js +++ b/public/src/modules/composer.js @@ -94,9 +94,8 @@ define(['taskbar'], function(taskbar) { var postContainer = $(composerTemplate[0]); - if(config.imgurClientIDSet) { + if(config.allowFileUploads || config.imgurClientIDSet) initializeFileReader(post_uuid); - } var postData = composer.posts[post_uuid], titleEl = postContainer.find('.title'), diff --git a/src/posts.js b/src/posts.js index 0eb19b4a24..0ab4222321 100644 --- a/src/posts.js +++ b/src/posts.js @@ -360,24 +360,26 @@ var db = require('./database'), Posts.uploadPostImage = function(image, callback) { - if(!meta.config.imgurClientID) { - return callback('imgurClientID not set', null); - } + if(meta.config.imgurClientID) { + if(!image) { + return callback('invalid image', null); + } - if(!image) { - return callback('invalid image', null); + require('./imgur').upload(meta.config.imgurClientID, image.data, 'base64', function(err, data) { + if(err) { + callback(err.message, null); + } else { + callback(null, { + url: data.link, + name: image.name + }); + } + }); + } else if (meta.config.allowFileUploads) { + Posts.uploadPostFile(image, callback); + } else { + callback('Uploads are disabled!'); } - - require('./imgur').upload(meta.config.imgurClientID, image.data, 'base64', function(err, data) { - if(err) { - callback(err.message, null); - } else { - callback(null, { - url: data.link, - name: image.name - }); - } - }); } Posts.uploadPostFile = function(file, callback) { @@ -400,7 +402,7 @@ var db = require('./database'), var uploadPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), filename); fs.writeFile(uploadPath, buffer, function (err) { - if(err) { + if(err) { callback(err.message, null); } else { callback(null, { From d0e4689907b3dd2a217718ff90854b2c08528fa4 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Wed, 1 Jan 2014 14:44:15 -0500 Subject: [PATCH 07/14] removed extra event in websocket.js --- src/websockets.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/websockets.js b/src/websockets.js index 9682e6cfef..f6bf315df3 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -565,7 +565,6 @@ websockets.init = function(io) { threadTools.delete(data.tid, uid, function(err) { if (!err) { emitTopicPostStats(); - events.logTopicDelete(uid, data.tid); socket.emit('api:topic.delete', { status: 'ok', tid: data.tid From 714e61b1377262c647b1ddf3a6f3e345216a6214 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 1 Jan 2014 15:31:27 -0500 Subject: [PATCH 08/14] upping markdown minver --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c13dbd78eb..16ff37e67c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "uglify-js": "~2.4.0", "validator": "~1.5.1", "nodebb-plugin-mentions": "~0.1.16", - "nodebb-plugin-markdown": "~0.2.1", + "nodebb-plugin-markdown": "~0.3.0", "nodebb-theme-vanilla": "~0.0.12", "nodebb-theme-cerulean": "0.0.10", "cron": "~1.0.1", From e3185b9560775dbcb3d55e852417f9ef127e94f2 Mon Sep 17 00:00:00 2001 From: cmastudios Date: Wed, 1 Jan 2014 19:46:11 -0500 Subject: [PATCH 09/14] Calculate age based on days instead of years Calculating the age based on the year only caused issues in the display of the age because it was off. Example: Person who was born in march of 1999 is displayed as 15 instead of 14 after the turn of the year. --- src/routes/user.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/user.js b/src/routes/user.js index dd5491b43e..144cf08508 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -539,7 +539,7 @@ var fs = require('fs'), if (!data.birthday) { data.age = ''; } else { - data.age = new Date().getFullYear() - new Date(data.birthday).getFullYear(); + data.age = Math.floor((new Date().getTime() - new Date(data.birthday).getTime()) / 31536000000); } function canSeeEmail() { @@ -581,4 +581,4 @@ var fs = require('fs'), }; -}(exports)); \ No newline at end of file +}(exports)); From 095e5527e3dff23cd206c5e7af5495ce7e51c91d Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 2 Jan 2014 02:17:47 -0500 Subject: [PATCH 10/14] upping markdown minver --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 16ff37e67c..fe7a2aff80 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "uglify-js": "~2.4.0", "validator": "~1.5.1", "nodebb-plugin-mentions": "~0.1.16", - "nodebb-plugin-markdown": "~0.3.0", + "nodebb-plugin-markdown": "~0.3.1", "nodebb-theme-vanilla": "~0.0.12", "nodebb-theme-cerulean": "0.0.10", "cron": "~1.0.1", From 8bfb338eee886c618632bc1e6eba24c5f1f6bde0 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 2 Jan 2014 14:26:08 -0500 Subject: [PATCH 11/14] #712 --- public/templates/admin/settings.tpl | 2 +- public/templates/category.tpl | 3 ++- src/categories.js | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/public/templates/admin/settings.tpl b/public/templates/admin/settings.tpl index 5f334cad02..aa364e4742 100644 --- a/public/templates/admin/settings.tpl +++ b/public/templates/admin/settings.tpl @@ -123,7 +123,7 @@
diff --git a/public/templates/category.tpl b/public/templates/category.tpl index 8b56a89107..30dd871851 100644 --- a/public/templates/category.tpl +++ b/public/templates/category.tpl @@ -10,12 +10,13 @@
- +
     
+

diff --git a/src/categories.js b/src/categories.js index ac65ae2405..b511ede803 100644 --- a/src/categories.js +++ b/src/categories.js @@ -80,6 +80,7 @@ var db = require('./database.js'), 'category_id': category_id, 'active_users': [], 'topics': [], + 'disableSocialButtons': meta.config.disableSocialButtons !== undefined ? parseInt(meta.config.disableSocialButtons, 10) !== 0 : false, 'twitter-intent-url': 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(nconf.get('url') + 'category/' + category_slug) + '&text=' + encodeURIComponent(category_name), 'facebook-share-url': 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(nconf.get('url') + 'category/' + category_slug), 'google-share-url': 'https://plus.google.com/share?url=' + encodeURIComponent(nconf.get('url') + 'category/' + category_slug), From 520fcadd3f28d5b00460eabcfdf087ed5248744d Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 2 Jan 2014 14:53:27 -0500 Subject: [PATCH 12/14] closes #456 --- src/logger.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/logger.js b/src/logger.js index eac28782d7..6ee2775255 100644 --- a/src/logger.js +++ b/src/logger.js @@ -3,11 +3,12 @@ */ var fs = require('fs'), + path = require('path'), express = require('express'), winston = require('winston'), util = require('util'), socketio = require('socket.io'), - meta = require('./meta.js'); + meta = require('./meta'); var opts = { /* @@ -72,10 +73,20 @@ var opts = { /* Open the streams to log to: either a path or stdout */ var stream; if(value && fs.existsSync(value)) { - stream = fs.createWriteStream(value, {flags: 'a'}); - } - else + fs.stat(value, function(err, stats) { + if(stats.isDirectory()) { + stream = fs.createWriteStream(path.join(value, 'nodebb.log'), {flags: 'a'}); + } else { + stream = fs.createWriteStream(value, {flags: 'a'}); + } + stream.on('error', function(err) { + winston.error(err.message); + }); + }); + + } else { stream = process.stdout; + } return stream; } @@ -112,8 +123,7 @@ var opts = { */ if(meta.config.loggerStatus > 0) { return opts.express.ofn(req,res,next); - } - else { + } else { return next(); } } @@ -140,11 +150,13 @@ var opts = { for(var v in clients) { var client = clients[v]; - if(client.oEmit != undefined && client.oEmit != client.emit) + if(client.oEmit != undefined && client.oEmit != client.emit) { client.emit = client.oEmit; + } - if(client.$oEmit != undefined && client.$oEmit != client.$emit) + if(client.$oEmit != undefined && client.$oEmit != client.$emit) { client.$emit = client.$oEmit; + } } } From 2c398f81d278bb5393ad9826f399b707c66b7b81 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 2 Jan 2014 15:06:08 -0500 Subject: [PATCH 13/14] fixed the twitter link to @NodeBB --- src/routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/api.js b/src/routes/api.js index 3f0dbc270c..c637dd58f5 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -66,7 +66,7 @@ var path = require('path'), data.motd_class = (parseInt(meta.config.show_motd, 10) === 1 || meta.config.show_motd === undefined) ? '' : ' none'; data.motd_class += (meta.config.motd && meta.config.motd.length > 0 ? '' : ' default'); - data.motd = require('marked')(meta.config.motd || "\n\n# NodeBB v" + pkg.version + "\nWelcome to NodeBB, the discussion platform of the future."); + data.motd = require('marked')(meta.config.motd || "\n\n# NodeBB v" + pkg.version + "\nWelcome to NodeBB, the discussion platform of the future."); res.json(data); }); }); From b5ab0c9097f285198d5cd6a6ebbe8037ebea6506 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 2 Jan 2014 15:20:54 -0500 Subject: [PATCH 14/14] updated minvers for markdown and mentions --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fe7a2aff80..7ec54f1ab8 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,8 @@ "prompt": "~0.2.11", "uglify-js": "~2.4.0", "validator": "~1.5.1", - "nodebb-plugin-mentions": "~0.1.16", - "nodebb-plugin-markdown": "~0.3.1", + "nodebb-plugin-mentions": "~0.1", + "nodebb-plugin-markdown": "~0.3", "nodebb-theme-vanilla": "~0.0.12", "nodebb-theme-cerulean": "0.0.10", "cron": "~1.0.1",