From cbf07204939b0b5d37212c247744e11043c7ed1b Mon Sep 17 00:00:00 2001 From: lesion Date: Sat, 11 Aug 2018 01:08:00 +0200 Subject: [PATCH] vpn working --- routes/index.js | 14 ++++++++++---- routes/utils.js | 7 ++++--- views/vpnnook.pug | 2 +- views/vpnok.pug | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/routes/index.js b/routes/index.js index 56bf74e..d3b7b58 100644 --- a/routes/index.js +++ b/routes/index.js @@ -4,7 +4,7 @@ const router = express.Router() const { fromTor, fromVpn, checkCountry } = require('./utils') // magic -const render = template => (req, res) => res.render(template) +const render = (template, data) => (req, res) => res.render(template, data) router.get('/', render('index')) @@ -19,9 +19,15 @@ router.get('/metadata', render('metadata')) router.get('/mail', render('mail')) // level V (vpn -> read mail) -router.get('/vpn', fromTor, fromVpn, checkCountry, (req, res) => { - if (!req.fromTor && req.fromVpn) render('vpnok', req.geoinfo ) - else render('vpnnook', req.geoinfo ) +router.get('/vpn', fromTor, fromVpn, checkCountry, (req, res, next) => { + console.log('son qui dentro'); + 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 diff --git a/routes/utils.js b/routes/utils.js index 386c8ff..be9c096 100644 --- a/routes/utils.js +++ b/routes/utils.js @@ -36,14 +36,15 @@ const fromVpn = async (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) => { if (!err && res.statusCode === 200) { console.log(body); req.geoinfo = JSON.parse(body); - console.log(res.geoinfo); + console.log(req.geoinfo); } - next(); + next() }) } -module.exports = { fromTor, fromVpn, checkCountry } \ No newline at end of file +module.exports = { fromTor, fromVpn, checkCountry } diff --git a/views/vpnnook.pug b/views/vpnnook.pug index 7bf9984..c39586b 100644 --- a/views/vpnnook.pug +++ b/views/vpnnook.pug @@ -2,6 +2,6 @@ extends layout block content p. - E no, arrivi da una {{country}} / {{city}} + E no, arrivi da #{country} - #{city} diff --git a/views/vpnok.pug b/views/vpnok.pug index 470a8b6..c031652 100644 --- a/views/vpnok.pug +++ b/views/vpnok.pug @@ -2,6 +2,6 @@ extends layout block content p. - Evviva, arrivi da una VPN {{country}} / {{city}} + Evviva, arrivi da una VPN in #{country}