@arnaudw38/nodebb-plugin-spam-be-gone 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/library.js +68 -7
- package/package.json +2 -3
package/library.js
CHANGED
|
@@ -4,7 +4,6 @@ const util = require('util');
|
|
|
4
4
|
const https = require('https');
|
|
5
5
|
const querystring = require('querystring');
|
|
6
6
|
const Honeypot = require('project-honeypot');
|
|
7
|
-
const stopforumspam = require('stopforumspam');
|
|
8
7
|
|
|
9
8
|
const winston = require.main.require('winston');
|
|
10
9
|
const nconf = require.main.require('nconf');
|
|
@@ -50,6 +49,71 @@ function getTurnstileConfigFromSettings(settings) {
|
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
51
|
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
function sfsRequest(path, method = 'GET', payload = null) {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
const body = payload ? querystring.stringify(payload) : null;
|
|
57
|
+
const options = {
|
|
58
|
+
hostname: 'api.stopforumspam.org',
|
|
59
|
+
path,
|
|
60
|
+
method,
|
|
61
|
+
headers: {
|
|
62
|
+
'Accept': 'application/json',
|
|
63
|
+
'User-Agent': pluginData.id,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
if (body) {
|
|
67
|
+
options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
68
|
+
options.headers['Content-Length'] = Buffer.byteLength(body);
|
|
69
|
+
}
|
|
70
|
+
const req = https.request(options, (res) => {
|
|
71
|
+
let responseData = '';
|
|
72
|
+
res.on('data', (chunk) => { responseData += chunk; });
|
|
73
|
+
res.on('end', () => {
|
|
74
|
+
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
75
|
+
return reject(new Error(`StopForumSpam request failed (${res.statusCode})`));
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
resolve(JSON.parse(responseData || '{}'));
|
|
79
|
+
} catch (err) {
|
|
80
|
+
reject(new Error('Invalid StopForumSpam response'));
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
req.on('error', reject);
|
|
85
|
+
if (body) {
|
|
86
|
+
req.write(body);
|
|
87
|
+
}
|
|
88
|
+
req.end();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function sfsIsSpammer({ ip, email, username }) {
|
|
93
|
+
const params = { f: 'json' };
|
|
94
|
+
if (ip) { params.ip = ip; }
|
|
95
|
+
if (email) { params.email = email; }
|
|
96
|
+
if (username) { params.username = username; }
|
|
97
|
+
return await sfsRequest(`/api?${querystring.stringify(params)}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function sfsSubmit({ ip, email, username }, evidence) {
|
|
101
|
+
if (!pluginSettings.stopforumspamApiKey) {
|
|
102
|
+
throw new Error('[[spam-be-gone:sfs-api-key-not-set]]');
|
|
103
|
+
}
|
|
104
|
+
const payload = {
|
|
105
|
+
api_key: pluginSettings.stopforumspamApiKey,
|
|
106
|
+
ip_addr: ip || '',
|
|
107
|
+
email: email || '',
|
|
108
|
+
username: username || '',
|
|
109
|
+
evidence: evidence || '',
|
|
110
|
+
};
|
|
111
|
+
const result = await sfsRequest('/add', 'POST', payload);
|
|
112
|
+
if (result && (result.success === 1 || result.success === true)) {
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
throw new Error((result && (result.error || result.message)) || 'StopForumSpam submit failed');
|
|
116
|
+
}
|
|
53
117
|
Plugin.middleware.isAdminOrGlobalMod = function (req, res, next) {
|
|
54
118
|
User.isAdminOrGlobalMod(req.uid, (err, isAdminOrGlobalMod) => {
|
|
55
119
|
if (err) {
|
|
@@ -100,9 +164,6 @@ Plugin.load = async function (params) {
|
|
|
100
164
|
if (!settings.akismetMinReputationHam) {
|
|
101
165
|
settings.akismetMinReputationHam = 10;
|
|
102
166
|
}
|
|
103
|
-
if (settings.stopforumspamApiKey) {
|
|
104
|
-
stopforumspam.Key(settings.stopforumspamApiKey);
|
|
105
|
-
}
|
|
106
167
|
|
|
107
168
|
pluginSettings = settings;
|
|
108
169
|
|
|
@@ -137,7 +198,7 @@ Plugin.report = async function (req, res, next) {
|
|
|
137
198
|
if (isAdmin) {
|
|
138
199
|
return res.status(403).send({ message: '[[spam-be-gone:cant-report-admin]]' });
|
|
139
200
|
}
|
|
140
|
-
await
|
|
201
|
+
await sfsSubmit({ ip: ips[0], email: fields.email, username: fields.username }, `Manual submission from user: ${req.uid} to user: ${fields.uid} via ${pluginData.id}`);
|
|
141
202
|
res.status(200).json({ message: '[[spam-be-gone:user-reported]]' });
|
|
142
203
|
} catch (err) {
|
|
143
204
|
winston.error(`[plugins/${pluginData.nbbId}][report-error] ${err.message}`);
|
|
@@ -152,7 +213,7 @@ Plugin.reportFromQueue = async (req, res) => {
|
|
|
152
213
|
}
|
|
153
214
|
const submitData = { ip: data.ip, email: data.email, username: data.username };
|
|
154
215
|
try {
|
|
155
|
-
await
|
|
216
|
+
await sfsSubmit(submitData, `Manual submission from user: ${req.uid} to user: ${data.username} via ${pluginData.id}`);
|
|
156
217
|
res.status(200).json({ message: '[[spam-be-gone:user-reported]]' });
|
|
157
218
|
} catch (err) {
|
|
158
219
|
winston.error(`[plugins/${pluginData.nbbId}][report-error] ${err.message}\n${JSON.stringify(submitData, null, 4)}`);
|
|
@@ -283,7 +344,7 @@ Plugin.getRegistrationQueue = async function (data) {
|
|
|
283
344
|
async function augmentWitSpamData(user) {
|
|
284
345
|
try {
|
|
285
346
|
user.ip = user.ip.replace('::ffff:', '');
|
|
286
|
-
let body = await
|
|
347
|
+
let body = await sfsIsSpammer({ ip: user.ip, email: user.email, username: user.username });
|
|
287
348
|
if (!body) {
|
|
288
349
|
body = { success: 1, username: { frequency: 0, appears: 0 }, email: { frequency: 0, appears: 0 }, ip: { frequency: 0, appears: 0, asn: null } };
|
|
289
350
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arnaudw38/nodebb-plugin-spam-be-gone",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "Anti-spam plugin for NodeBB 4.x using Akismet, StopForumSpam, ProjectHoneyPot, and Cloudflare Turnstile (Turnstile-only fork)",
|
|
5
5
|
"main": "library.js",
|
|
6
6
|
"scripts": {},
|
|
@@ -33,8 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"async": "^3.2.0",
|
|
36
|
-
"project-honeypot": "~0.0.0"
|
|
37
|
-
"stopforumspam": "^1.3.8"
|
|
36
|
+
"project-honeypot": "~0.0.0"
|
|
38
37
|
},
|
|
39
38
|
"nbbpm": {
|
|
40
39
|
"compatibility": "^4.0.0"
|