mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-23 17:00:24 +01:00
adding hook filter:topic.reply for antispam
This commit is contained in:
@@ -13,7 +13,24 @@ var async = require('async'),
|
|||||||
user = require('../user'),
|
user = require('../user'),
|
||||||
websockets = require('./index'),
|
websockets = require('./index'),
|
||||||
|
|
||||||
SocketPosts = {};
|
SocketPosts = {},
|
||||||
|
|
||||||
|
// a shy request-wannabe build from a socket for spam detection purposes
|
||||||
|
reqFromSocket = function(socket) {
|
||||||
|
var headers = socket.handshake.headers,
|
||||||
|
host = headers['host'],
|
||||||
|
referer = headers['referer'];
|
||||||
|
|
||||||
|
return {
|
||||||
|
'ip': headers['x-forwarded-for'] || socket.handshake.address.address,
|
||||||
|
'host': host,
|
||||||
|
'protocol': headers['secure'] ? 'https' : 'http',
|
||||||
|
'secure': !!headers['secure'],
|
||||||
|
'url': referer,
|
||||||
|
'path': referer.substr(referer.indexOf(host) + host.length),
|
||||||
|
'headers': headers
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
SocketPosts.reply = function(socket, data, callback) {
|
SocketPosts.reply = function(socket, data, callback) {
|
||||||
|
|
||||||
@@ -26,6 +43,7 @@ SocketPosts.reply = function(socket, data, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.uid = socket.uid;
|
data.uid = socket.uid;
|
||||||
|
data.req = reqFromSocket(socket);
|
||||||
|
|
||||||
topics.reply(data, function(err, postData) {
|
topics.reply(data, function(err, postData) {
|
||||||
if(err) {
|
if(err) {
|
||||||
|
|||||||
@@ -141,6 +141,16 @@ module.exports = function(Topics) {
|
|||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function(next) {
|
function(next) {
|
||||||
|
plugins.fireHook('filter:topic.reply', data, function(err, filteredData) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
content = filteredData.content || data.content;
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
threadTools.exists(tid, next);
|
threadTools.exists(tid, next);
|
||||||
},
|
},
|
||||||
function(topicExists, next) {
|
function(topicExists, next) {
|
||||||
|
|||||||
Reference in New Issue
Block a user