diff --git a/routes/metadata.js b/routes/metadata.js deleted file mode 100644 index 4f75cc9..0000000 --- a/routes/metadata.js +++ /dev/null @@ -1,9 +0,0 @@ -var express = require('express'); -var router = express.Router(); - -router.get('/', (req, res) => { - res.render('metadata'); -}); - - -module.exports = router; diff --git a/routes/utils.js b/routes/utils.js index 0f72792..cc3e5c6 100644 --- a/routes/utils.js +++ b/routes/utils.js @@ -3,13 +3,19 @@ const dns = require('dns') const lookup = promisify(dns.lookup) const request = require('request') +const { DEV, SERVER_IP } = require('../config') + // https://www.torproject.org/projects/tordnsel.html.en // check if request comes from tor const fromTor = async (req, res, next) => { + if (DEV) { + req.fromTor = req.query.fromTor || false + return next() + } const sourceIp = req.headers['x-forwarded-for'] || req.connection.remoteAddress const ip = sourceIp.split('.').reverse().join('.') - const serverIp = '51.68.126.235'.split('.').reverse().join('.') - const domain = `${ip}.80.${serverIp}.ip-port.exitlist.torproject.org` + const reversedServerIp = SERVER_IP.split('.').reverse().join('.') + const domain = `${ip}.80.${reversedServerIp}.ip-port.exitlist.torproject.org` try { const ret = await lookup(domain, {}) req.fromTor = (ret.address === '127.0.0.2') @@ -21,6 +27,10 @@ const fromTor = async (req, res, next) => { // check if request comes from proxy/VPN/tor const fromVpn = async (req, res, next) => { + if (DEV) { + req.fromVpn = req.query.fromVpn || false + return next() + } const sourceIp = req.headers['x-forwarded-for'] || req.connection.remoteAddress const baseUrl = 'https://check.getipintel.net/check.php?ip=' const url = `${baseUrl}${sourceIp}&contact=anna@fugadalcontrollo.org` @@ -36,10 +46,15 @@ const fromVpn = async (req, res, next) => { } const checkCountry = (req, res, next) => { + if (DEV) { + return next() + } const sourceIp = req.headers['x-forwarded-for'] || req.connection.remoteAddress request(`http://ip-api.com/json/${sourceIp}`, (err, res, body) => { if (!err && res.statusCode === 200) { - req.geoinfo = JSON.parse(body) + try { + req.geoinfo = JSON.parse(body) + } catch (e) {} } next() })