avoid tor/vpn check in dev mode
use fromTor/fromVpn in query string
This commit is contained in:
parent
e3b04de244
commit
e404c509dc
@ -1,9 +0,0 @@
|
|||||||
var express = require('express');
|
|
||||||
var router = express.Router();
|
|
||||||
|
|
||||||
router.get('/', (req, res) => {
|
|
||||||
res.render('metadata');
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
|
@ -3,13 +3,19 @@ const dns = require('dns')
|
|||||||
const lookup = promisify(dns.lookup)
|
const lookup = promisify(dns.lookup)
|
||||||
const request = require('request')
|
const request = require('request')
|
||||||
|
|
||||||
|
const { DEV, SERVER_IP } = require('../config')
|
||||||
|
|
||||||
// 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
|
||||||
const fromTor = async (req, res, next) => {
|
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 sourceIp = req.headers['x-forwarded-for'] || req.connection.remoteAddress
|
||||||
const ip = sourceIp.split('.').reverse().join('.')
|
const ip = sourceIp.split('.').reverse().join('.')
|
||||||
const serverIp = '51.68.126.235'.split('.').reverse().join('.')
|
const reversedServerIp = SERVER_IP.split('.').reverse().join('.')
|
||||||
const domain = `${ip}.80.${serverIp}.ip-port.exitlist.torproject.org`
|
const domain = `${ip}.80.${reversedServerIp}.ip-port.exitlist.torproject.org`
|
||||||
try {
|
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')
|
||||||
@ -21,6 +27,10 @@ const fromTor = async (req, res, next) => {
|
|||||||
|
|
||||||
// check if request comes from proxy/VPN/tor
|
// check if request comes from proxy/VPN/tor
|
||||||
const fromVpn = async (req, res, next) => {
|
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 sourceIp = req.headers['x-forwarded-for'] || req.connection.remoteAddress
|
||||||
const baseUrl = 'https://check.getipintel.net/check.php?ip='
|
const baseUrl = 'https://check.getipintel.net/check.php?ip='
|
||||||
const url = `${baseUrl}${sourceIp}&contact=anna@fugadalcontrollo.org`
|
const url = `${baseUrl}${sourceIp}&contact=anna@fugadalcontrollo.org`
|
||||||
@ -36,10 +46,15 @@ const fromVpn = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const checkCountry = (req, res, next) => {
|
const checkCountry = (req, res, next) => {
|
||||||
|
if (DEV) {
|
||||||
|
return next()
|
||||||
|
}
|
||||||
const sourceIp = req.headers['x-forwarded-for'] || req.connection.remoteAddress
|
const sourceIp = req.headers['x-forwarded-for'] || req.connection.remoteAddress
|
||||||
request(`http://ip-api.com/json/${sourceIp}`, (err, res, body) => {
|
request(`http://ip-api.com/json/${sourceIp}`, (err, res, body) => {
|
||||||
if (!err && res.statusCode === 200) {
|
if (!err && res.statusCode === 200) {
|
||||||
req.geoinfo = JSON.parse(body)
|
try {
|
||||||
|
req.geoinfo = JSON.parse(body)
|
||||||
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user