vpn working

This commit is contained in:
lesion 2018-08-11 01:08:00 +02:00
parent d603a1aabb
commit cbf0720493
4 changed files with 16 additions and 9 deletions

View File

@ -4,7 +4,7 @@ const router = express.Router()
const { fromTor, fromVpn, checkCountry } = require('./utils') const { fromTor, fromVpn, checkCountry } = require('./utils')
// magic // magic
const render = template => (req, res) => res.render(template) const render = (template, data) => (req, res) => res.render(template, data)
router.get('/', render('index')) router.get('/', render('index'))
@ -19,9 +19,15 @@ router.get('/metadata', render('metadata'))
router.get('/mail', render('mail')) router.get('/mail', render('mail'))
// level V (vpn -> read mail) // level V (vpn -> read mail)
router.get('/vpn', fromTor, fromVpn, checkCountry, (req, res) => { router.get('/vpn', fromTor, fromVpn, checkCountry, (req, res, next) => {
if (!req.fromTor && req.fromVpn) render('vpnok', req.geoinfo ) console.log('son qui dentro');
else render('vpnnook', req.geoinfo ) if (!req.fromTor && req.fromVpn) {
res.render('vpnok', req.geoinfo);
} else {
res.render('vpnnook', req.geoinfo);
}
// console.log('sono qui dentro?!?!');
// render('torok')
}) })
module.exports = router module.exports = router

View File

@ -36,13 +36,14 @@ const fromVpn = async (req, res, next) => {
} }
const checkCountry = (req, res, next) => { const checkCountry = (req, res, next) => {
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) {
console.log(body); console.log(body);
req.geoinfo = JSON.parse(body); req.geoinfo = JSON.parse(body);
console.log(res.geoinfo); console.log(req.geoinfo);
} }
next(); next()
}) })
} }

View File

@ -2,6 +2,6 @@ extends layout
block content block content
p. p.
E no, arrivi da una {{country}} / {{city}} E no, arrivi da #{country} - #{city}

View File

@ -2,6 +2,6 @@ extends layout
block content block content
p. p.
Evviva, arrivi da una VPN {{country}} / {{city}} Evviva, arrivi da una VPN in #{country}