Skip to content

Commit

Permalink
fix: 🐛 add default keyword blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
denghongcai committed Feb 17, 2021
1 parent bc635df commit a9ba767
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
3 changes: 2 additions & 1 deletion config-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"port": 25,
"disableWebhook": true
},
"host": "disposable.dhc-app.com"
"host": "disposable.dhc-app.com",
"keywordBlackList": ["admin", "postmaster", "system", "webmaster", "administrator", "hostmaster", "service", "server", "root"]
}
21 changes: 21 additions & 0 deletions modules/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Created by Hongcai Deng on 2015/12/28.
*/

'use strict';

const path = require('path');
const fs = require('fs');

const defaultConfigJsonPath = path.join(__dirname, '..', 'config-default.json')
const defaultConfigPath = path.join(__dirname, '..', 'config-default.js')

let config = {};

if (fs.existsSync(defaultConfigJsonPath)) {
config = require(defaultConfigJsonPath);
} else {
config = require(defaultConfigPath);
}

module.exports = config;
22 changes: 20 additions & 2 deletions modules/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@

'use strict';

let shortid = require('shortid');
let mailin = require('./mailin');
const shortid = require('shortid');
const mailin = require('./mailin');
const config = require('./config');

let onlines = new Map();

function checkShortIdMatchBlackList(id) {
const keywordBlackList = config.keywordBlackList;
if (keywordBlackList && keywordBlackList.length > 0) {
for (let i = 0; i < keywordBlackList.length; i++) {
const keyword = keywordBlackList[i];
if (id.includes(keyword)) {
return true;
}
}
}
return false;
}

module.exports = function(io) {
mailin.on('message', function(connection, data) {
let to = data.headers.to.toLowerCase();
Expand All @@ -31,6 +45,10 @@ module.exports = function(io) {
});

socket.on('set shortid', function(id) {
if (checkShortIdMatchBlackList(id)) {
// skip set shortid if match keyword blacklist
return;
}
onlines.delete(socket.shortid);
socket.shortid = id;
onlines.set(socket.shortid, socket);
Expand Down
2 changes: 1 addition & 1 deletion modules/mailin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

let path = require('path');
let mailin = require('mailin');
let config = require(path.join(__dirname, '..', 'config-default.json'));
let config = require('./config');

mailin.start(config.mailin);

Expand Down

0 comments on commit a9ba767

Please sign in to comment.