This commit is contained in:
lesion 2018-08-10 00:31:44 +02:00
parent 7d559f9a31
commit 1e3fb44ea6
No known key found for this signature in database
GPG Key ID: 352918250B012177

View File

@ -5,11 +5,15 @@ const lookup = promisify(dns.lookup)
// https://www.torproject.org/projects/tordnsel.html.en // https://www.torproject.org/projects/tordnsel.html.en
// check if request comes from tor // check if request comes from tor
module.exports = async (req, res, next) => { module.exports = async (req, res, next) => {
const source_ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress const source_ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress
const ip = source_ip.split('.').reverse().join('.') const ip = source_ip.split('.').reverse().join('.')
const server_ip = '51.68.126.235'.split('.').reverse().join('.') const server_ip = '51.68.126.235'.split('.').reverse().join('.')
const domain = `${ip}.80.${server_ip}.ip-port.exitlist.torproject.org` const domain = `${ip}.80.${server_ip}.ip-port.exitlist.torproject.org`
try {
const ret = await lookup(domain, {}) const ret = await lookup(domain, {})
req.fromTor = (ret.address === '127.0.0.2') req.fromTor = (ret.address === '127.0.0.2')
next() } catch(e) {
req.fromTor = false
}
next()
} }