From 1e3fb44ea6c424fdb852754b1a0bdf17a2276b78 Mon Sep 17 00:00:00 2001 From: lesion Date: Fri, 10 Aug 2018 00:31:44 +0200 Subject: [PATCH] minor --- routes/tor.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/routes/tor.js b/routes/tor.js index 04700e3..c2d8d64 100644 --- a/routes/tor.js +++ b/routes/tor.js @@ -5,11 +5,15 @@ const lookup = promisify(dns.lookup) // https://www.torproject.org/projects/tordnsel.html.en // check if request comes from tor module.exports = async (req, res, next) => { - const source_ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress - const ip = source_ip.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 source_ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress + const ip = source_ip.split('.').reverse().join('.') + const server_ip = '51.68.126.235'.split('.').reverse().join('.') + const domain = `${ip}.80.${server_ip}.ip-port.exitlist.torproject.org` + try { const ret = await lookup(domain, {}) req.fromTor = (ret.address === '127.0.0.2') - next() + } catch(e) { + req.fromTor = false + } + next() }