Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nodebb-plugin-email-blacklist

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodebb-plugin-email-blacklist - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

.eslintrc

159

library.js

@@ -1,114 +0,93 @@

var https = require('https');
var pluginData = require('./plugin.json');
var winston = module.parent.require('winston');
var meta = require.main.require('./src/meta');
var pluginSettings;
var Plugin = {};
'use strict';
pluginData.nbbId = pluginData.id.replace(/nodebb-plugin-/, '');
const https = require('https');
Plugin.load = function (params, callback) {
const winston = require.main.require('winston');
const pluginData = require('./plugin.json');
var render = function (req, res, next) {
res.render('admin/plugins/' + pluginData.nbbId, pluginData || {});
};
const meta = require.main.require('./src/meta');
meta.settings.get(pluginData.nbbId, function (err, settings) {
if (err)
return callback(err);
if (!settings) {
winston.warn('[plugins/' + pluginData.nbbId + '] Settings not set or could not be retrieved!');
return callback();
}
const Plugin = module.exports;
winston.info('[plugins/' + pluginData.nbbId + '] Settings loaded');
pluginSettings = settings;
pluginData.nbbId = pluginData.id.replace(/nodebb-plugin-/, '');
params.router.get('/admin/plugins/' + pluginData.nbbId, params.middleware.admin.buildHeader, render);
params.router.get('/api/admin/plugins/' + pluginData.nbbId, render);
callback();
});
Plugin.load = async function (params) {
const routeHelpers = require.main.require('./src/routes/helpers');
const { router } = params;
routeHelpers.setupAdminPageRoute(router, `/admin/plugins/${pluginData.nbbId}`, (req, res) => {
res.render(`admin/plugins/${pluginData.nbbId}`, {
title: pluginData.name,
});
});
};
Plugin.onEmailSave = async (data) => {
if (isBlacklistedDomain(data.email)) {
throw new Error('Blacklisted email provider.');
}
const pluginSettings = await meta.settings.get(pluginData.nbbId);
if (isBlacklistedDomain(data.email, pluginSettings.domains)) {
throw new Error('Blacklisted email provider.');
}
if (pluginSettings.isTempMailEnabled === 'on' && !await isTempMail(data.email)) {
throw new Error('Blacklisted email provider.');
}
if (pluginSettings.isTempMailEnabled === 'on' && !await isTempMail(data.email)) {
throw new Error('Blacklisted email provider.');
}
return data;
return data;
};
// Plugin.filterEmailRegister = function (regData, next) {
// if (regData && regData.userData && regData.userData.email) {
// if (isBlacklistedDomain(regData.userData.email))
// return next(new Error('Blacklisted email provider.'));
// if (pluginSettings.isTempMailEnabled === 'on')
// return isTempMail(regData.userData.email, regData, next);
// }
// return next(null, regData);
// };
Plugin.filterEmailUpdate = function (data, next) {
if (data && data.email) {
if (isBlacklistedDomain(data.email))
return next(new Error('Blacklisted email provider.'));
if (pluginSettings.isTempMailEnabled === 'on')
return isTempMail(data.email, data, next);
}
return next(null, data);
Plugin.filterEmailUpdate = async function (data) {
if (data && data.email) {
const pluginSettings = await meta.settings.get(pluginData.nbbId);
if (isBlacklistedDomain(data.email, pluginSettings.domains)) {
throw new Error('Blacklisted email provider.');
}
if (pluginSettings.isTempMailEnabled === 'on') {
return await isTempMail(data.email);
}
}
return data;
};
function isBlacklistedDomain(email) {
var domain = email.substring(email.indexOf('@') + 1);
var lines = pluginSettings.domains.split('\n');
for (var i = 0; i < lines.length; i++)
if (domain === lines[i].trim())
return true;
return false;
function isBlacklistedDomain(email, domains = '') {
const emailDomain = String(email).substring(email.indexOf('@') + 1);
const domainBlacklist = (domains || '').split('\n').map(line => line.trim());
return domainBlacklist.includes(emailDomain);
}
function isTempMail(email) {
// Note: does not work, isTempMail is now a paid service and requires an API token
return new Promise((resolve, reject) => {
https.request({
host: 'www.istempmail.com',
path: '/api-public/check/' + email
}, function (res) {
var body = '';
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function () {
winston.info('[plugins/' + pluginData.nbbId + '] isTempMail: ' + body);
var jsonBody = JSON.parse(body);
if ("blocked" in jsonBody && jsonBody.blocked) {
return resolve(false);
}
// Note: does not work, isTempMail is now a paid service and requires an API token
return new Promise((resolve, reject) => {
https.request({
host: 'www.istempmail.com',
path: `/api-public/check/${email}`,
}, (res) => {
let body = '';
res.on('data', (chunk) => {
body += chunk;
});
res.on('end', () => {
winston.info(`[plugins/${pluginData.nbbId}] isTempMail: ${body}`);
const jsonBody = JSON.parse(body);
if ('blocked' in jsonBody && jsonBody.blocked) {
return resolve(false);
}
resolve(true);
}).on('error', function(err) {
winston.warn('[plugins/' + pluginData.nbbId + '] Error with the request:', err.message);
reject(err);
});
}).end();
});
resolve(true);
}).on('error', (err) => {
winston.warn(`[plugins/${pluginData.nbbId}] Error with the request: ${err.message}`);
reject(err);
});
}).end();
});
}
Plugin.admin = {
menu: function (header, callback) {
header.plugins.push({
"route": '/plugins/' + pluginData.nbbId,
"icon": pluginData.faIcon,
"name": pluginData.name
});
menu: function (header, callback) {
header.plugins.push({
route: `/plugins/${pluginData.nbbId}`,
icon: pluginData.faIcon,
name: pluginData.name,
});
callback(null, header);
}
callback(null, header);
},
};
module.exports = Plugin;
{
"name": "nodebb-plugin-email-blacklist",
"version": "2.0.0",
"version": "3.0.0",
"description": "nodebb email blacklist",

@@ -17,4 +17,9 @@ "main": "library.js",

"nbbpm": {
"compatibility": "^1.19.0 || ^2.0.0"
"compatibility": "^3.2.0"
},
"devDependencies": {
"eslint": "8.57.0",
"eslint-config-nodebb": "0.2.1",
"eslint-plugin-import": "2.29.1"
}
}
'use strict';
define('admin/plugins/email-blacklist', [
'settings', 'alerts',
], function (settings, alerts) {
'settings',
], function (settings) {
var ACP = {};

@@ -14,13 +14,3 @@

function saveSettings() {
settings.save('email-blacklist', $('.email-blacklist-settings'), function () {
alerts.alert({
type: 'success',
alert_id: 'email-blacklist-saved',
title: 'Settings Saved',
message: 'Please reload your NodeBB to apply these settings',
clickfn: function () {
socket.emit('admin.reload');
},
});
});
settings.save('email-blacklist', $('.email-blacklist-settings'));
}

@@ -27,0 +17,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc