Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
86 lines (70 loc) · 2.52 KB
/
Copy pathserver.js
File metadata and controls
86 lines (70 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const express = require('express');
const bodyParser = require('body-parser');
const { URLSearchParams } = require('url');
const fetch = require('node-fetch');
const app = express();
const SITE_KEY = "chk_000000000000000000000000"; // Modify this.
const SECRET_KEY = "chk_secret_000000000000000000000000000000000000000000000000"; // Modify this.
const port = process.env.PORT || 3000;
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.set('view engine', 'ejs');
app.use('/assets', express.static(__dirname + '/public/assets'));
app.get('/', (req, res) => {
res.render('index', {
site_key: SITE_KEY,
error: null,
success: false,
});
})
app.post('/login', (req, res) => {
let email = req.body.email;
let token = req.body['v4g-checkpoint-response'];
const body = new URLSearchParams();
body.set('secret', SECRET_KEY);
body.set('token', token);
let url = 'https://challenges.v4guard.io/checkpoint/v1/tokenverify';
let options = {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: body
};
fetch(url, options)
.then(res => res.json())
.then(json => {
if (!json.success) {
return res.render('index', {
site_key: SITE_KEY,
error: `An error occured: ${json.errors[0]}`,
success: null
});
}
if (json.response.blocked) {
return res.render('index', {
site_key: SITE_KEY,
error: `Disable your VPN/proxy!`,
success: null
});
}
return res.render('index', {
site_key: SITE_KEY,
error: null,
success: `Welcome ${email}!`
});
})
.catch(err => {
return res.render('index', {
site_key: SITE_KEY,
error: `An error occured: ${err}`,
success: null
});
});
});
let server = app.listen(port, () => {
let host = server.address().address == '::' ? 'localhost' : server.address().address
let port = server.address().port
console.log(``);
console.log(`\t\x1B[38;2;127;39;199m\x1B[1mv4Guard Checkpoint\x1B[22m - demonstration`);
console.log(`\t\x1b[38;2;203;11;160m➜ Listening on \x1b]8;;http://${host}:${port}\u0007http://${host}:${port}\x1b]8;;\u0007\x1b[39m`);
console.log(``);
});