vpn check / country

This commit is contained in:
lesion 2018-08-10 23:53:41 +02:00
parent 19a3ed8ae4
commit d603a1aabb
No known key found for this signature in database
GPG Key ID: 352918250B012177
4 changed files with 32 additions and 8 deletions

View File

@ -1,7 +1,7 @@
const express = require('express') const express = require('express')
const router = express.Router() const router = express.Router()
const { fromTor, fromVpn } = require('./utils') const { fromTor, fromVpn, checkCountry } = require('./utils')
// magic // magic
const render = template => (req, res) => res.render(template) const render = template => (req, res) => res.render(template)
@ -19,9 +19,9 @@ 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, (req, res) => { router.get('/vpn', fromTor, fromVpn, checkCountry, (req, res) => {
if (!req.isTor && req.isVpn) render('vpnok') if (!req.fromTor && req.fromVpn) render('vpnok', req.geoinfo )
else render('vpnnook') else render('vpnnook', req.geoinfo )
}) })
module.exports = router module.exports = router

View File

@ -24,16 +24,26 @@ const fromVpn = async (req, res, 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`
console.log(url);
request(url, request(url,
(err, res, body) => { (err, res, body) => {
if (!err && res.statusCode === 200) { if (!err && res.statusCode === 200) {
console.log(body) req.fromVpn = parseFloat(body)>0.5
} else { } else {
console.log(err, body) req.fromVpn = false
} }
next()
}) })
} }
const checkCountry = (req, res, next) => {
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);
}
next();
})
}
module.exports = { fromTor, fromVpn } module.exports = { fromTor, fromVpn, checkCountry }

7
views/vpnnook.pug Normal file
View File

@ -0,0 +1,7 @@
extends layout
block content
p.
E no, arrivi da una {{country}} / {{city}}

7
views/vpnok.pug Normal file
View File

@ -0,0 +1,7 @@
extends layout
block content
p.
Evviva, arrivi da una VPN {{country}} / {{city}}