mirror of https://gitgud.io/fatchan/jschan.git
parent
036bcd3c94
commit
504fbd4496
6 changed files with 88 additions and 3 deletions
@ -0,0 +1,29 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
const cache = require(__dirname+'/../../redis.js') |
||||||
|
, dynamicResponse = require(__dirname+'/../dynamic.js') |
||||||
|
, { dnsbl } = require(__dirname+'/../../configs/main.js') |
||||||
|
, { batch } = require('dnsbl'); |
||||||
|
|
||||||
|
module.exports = async (req, res, next) => { |
||||||
|
|
||||||
|
if (dnsbl.enabled && dnsbl.blacklists.length > 0) { |
||||||
|
const ip = req.headers['x-real-ip'] || req.connection.remoteAddress; |
||||||
|
let isBlacklisted = await cache.get(`blacklisted:${ip}`); |
||||||
|
if (isBlacklisted === null) { //not cached
|
||||||
|
const dnsblResp = await batch(ip, dnsbl.blacklists); |
||||||
|
isBlacklisted = dnsblResp.some(r => r.listed === true); |
||||||
|
await cache.set(`blacklisted:${ip}`, isBlacklisted, dnsbl.cacheTime); |
||||||
|
} |
||||||
|
if (isBlacklisted) { |
||||||
|
return dynamicResponse(req, res, 403, 'message', { |
||||||
|
'title': 'Forbidden', |
||||||
|
'message': 'Your IP address is listed on a blacklist', |
||||||
|
'redirect': req.headers.referer || '/' |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
return next(); |
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,29 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
const cache = require(__dirname+'/../redis.js') |
||||||
|
, dynamicResponse = require(__dirname+'/dynamic.js') |
||||||
|
, { dnsbl } = require(__dirname+'/../configs/main.js') |
||||||
|
, { batch } = require('dnsbl'); |
||||||
|
|
||||||
|
module.exports = async (req, res, next) => { |
||||||
|
|
||||||
|
if (dnsbl.enabled) { |
||||||
|
const ip = req.headers['x-real-ip'] || req.connection.remoteAddress; |
||||||
|
let isBlacklisted = await cache.get(`blacklisted:${ip}`); |
||||||
|
if (isBlacklisted === null) { //not cached
|
||||||
|
const dnsblResp = await batch(ip, dnsbl.blacklists); |
||||||
|
isBlacklisted = dnsblResp.some(r => r.listed === true); |
||||||
|
await cache.set(`blacklisted:${ip}`, isBlacklisted, dnsbl.cacheTime); |
||||||
|
} |
||||||
|
if (isBlacklisted) { |
||||||
|
return dynamicResponse(req, res, 403, 'message', { |
||||||
|
'title': 'Forbidden', |
||||||
|
'message': 'Your IP address is listed on a blacklist', |
||||||
|
'redirect': req.headers.referer || '/' |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
return next(); |
||||||
|
|
||||||
|
} |
||||||
|
|
Loading…
Reference in new issue