mirror of
https://github.com/cloudmaker97/Discord-Captcha-Verification.git
synced 2025-12-06 01:48:34 +00:00
Implemented feature for blocking VPN-users
This commit is contained in:
parent
efd8966f02
commit
9ce846800e
7 changed files with 33115 additions and 37 deletions
42
modules/network/blacklist.js
Normal file
42
modules/network/blacklist.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
const fs = require('fs');
|
||||
const readline = require('readline');
|
||||
|
||||
class Blacklist {
|
||||
constructor() {
|
||||
this.blacklist = [];
|
||||
}
|
||||
|
||||
async loadBlacklist() {
|
||||
const files = ["vpn.txt", "datacenter.txt"];
|
||||
const folder = "./modules/network/blacklist/";
|
||||
for (const file of files) {
|
||||
const fileStream = fs.createReadStream(folder + file);
|
||||
const rl = readline.createInterface({
|
||||
input: fileStream,
|
||||
crlfDelay: Infinity
|
||||
});
|
||||
for await (const line of rl) {
|
||||
this.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
return resolve(this.blacklist);
|
||||
});
|
||||
}
|
||||
|
||||
add(ip) {
|
||||
if(!this.isBlacklisted(ip))
|
||||
this.blacklist.push(ip);
|
||||
}
|
||||
|
||||
remove(ip) {
|
||||
this.blacklist = this.blacklist.filter(blacklistedIp => blacklistedIp !== ip);
|
||||
}
|
||||
|
||||
isBlacklisted(ip) {
|
||||
return this.blacklist.includes(ip);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new Blacklist();
|
||||
29774
modules/network/blacklist/datacenter.txt
Normal file
29774
modules/network/blacklist/datacenter.txt
Normal file
File diff suppressed because it is too large
Load diff
3206
modules/network/blacklist/vpn.txt
Normal file
3206
modules/network/blacklist/vpn.txt
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,43 +1,60 @@
|
|||
const express = require('express');
|
||||
const { turnstileSitekey, turnstileSecret, port } = require('./../../config.json');
|
||||
const app = express();
|
||||
const { IpDeniedError, IpFilter } = require('express-ipfilter');
|
||||
const express = require('express');
|
||||
const expressApp = express();
|
||||
const event = require('../events/index').eventBus;
|
||||
const blacklist = require('../network/blacklist');
|
||||
|
||||
app.use('/', express.static(__dirname + '/public'));
|
||||
app.use(express.json())
|
||||
// This will load the blacklist and start the webserver when it's done
|
||||
blacklist.loadBlacklist().then(blacklist => {
|
||||
console.log('Network-Blacklist has been loaded')
|
||||
expressApp.use('/', express.static(__dirname + '/public'));
|
||||
expressApp.use(IpFilter(blacklist));
|
||||
expressApp.use(express.json())
|
||||
|
||||
// This endpoint will return the turnstile sitekey
|
||||
app.get('/turnstile/id', (req, res) => {
|
||||
res.json({ id: turnstileSitekey });
|
||||
});
|
||||
|
||||
// This endpoint will verify the token from turnstile and adds the user to the database
|
||||
app.post('/verify', (req, res) => {
|
||||
let turnstileToken = req.body.token;
|
||||
let authenticationObject = req.body.data;
|
||||
let internetProtocolAddress = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
|
||||
|
||||
let formData = new FormData();
|
||||
formData.append('secret', turnstileSecret);
|
||||
formData.append('response', turnstileToken);
|
||||
|
||||
fetch("https://challenges.cloudflare.com/turnstile/v0/siteverify", {
|
||||
body: formData,
|
||||
method: 'POST',
|
||||
}).then(response => response.json()).then(data => {
|
||||
if (data.success) {
|
||||
event.emit('verification:success', authenticationObject, internetProtocolAddress);
|
||||
res.json({ success: true });
|
||||
expressApp.use((err, req, res, _next) => {
|
||||
if (err instanceof IpDeniedError) {
|
||||
res.status(401)
|
||||
res.json({ networkBlacklisted: err.message })
|
||||
} else {
|
||||
console.log('Verification failed');
|
||||
res.json({ success: false });
|
||||
res.status(err.status || 500)
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error(error);
|
||||
res.json({ success: false });
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Webserver is available on http://localhost:${port}`)
|
||||
})
|
||||
|
||||
// This endpoint will return the turnstile sitekey
|
||||
expressApp.get('/turnstile/id', (req, res) => {
|
||||
res.json({ id: turnstileSitekey });
|
||||
});
|
||||
|
||||
// This endpoint will verify the token from turnstile and adds the user to the database
|
||||
expressApp.post('/verify', (req, res) => {
|
||||
let turnstileToken = req.body.token;
|
||||
let authenticationObject = req.body.data;
|
||||
let internetProtocolAddress = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
|
||||
|
||||
let formData = new FormData();
|
||||
formData.append('secret', turnstileSecret);
|
||||
formData.append('response', turnstileToken);
|
||||
|
||||
fetch("https://challenges.cloudflare.com/turnstile/v0/siteverify", {
|
||||
body: formData,
|
||||
method: 'POST',
|
||||
}).then(response => response.json()).then(data => {
|
||||
if (data.success) {
|
||||
event.emit('verification:success', authenticationObject, internetProtocolAddress);
|
||||
res.json({ success: true });
|
||||
} else {
|
||||
console.log('Verification failed');
|
||||
res.json({ success: false });
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error(error);
|
||||
res.json({ success: false });
|
||||
});
|
||||
});
|
||||
|
||||
expressApp.listen(port, () => {
|
||||
console.log(`Webserver is available on http://localhost:${port}`)
|
||||
})
|
||||
});
|
||||
|
|
@ -2,6 +2,10 @@ function inititalize() {
|
|||
fetch('/turnstile/id')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if(data.networkBlacklisted) {
|
||||
failed("Dein Netzwerk ist gesperrt. Bitte schalte deinen VPN aus, sofern du einen benutzt.");
|
||||
return;
|
||||
}
|
||||
if(getUserData() === false) {
|
||||
failed('Kein Benutzer gefunden. Bitte versuchen Sie es erneut.');
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@
|
|||
"dependencies": {
|
||||
"body-parser": "^1.20.2",
|
||||
"discord.js": "^14.14.1",
|
||||
"express": "^4.19.2"
|
||||
"express": "^4.19.2",
|
||||
"express-ipfilter": "^1.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tailwindcss": "^3.4.3"
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ importers:
|
|||
express:
|
||||
specifier: ^4.19.2
|
||||
version: 4.19.2
|
||||
express-ipfilter:
|
||||
specifier: ^1.3.2
|
||||
version: 1.3.2
|
||||
devDependencies:
|
||||
tailwindcss:
|
||||
specifier: ^3.4.3
|
||||
|
|
@ -286,6 +289,10 @@ packages:
|
|||
resolution: {integrity: sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==}
|
||||
engines: {node: '>= 0.6'}
|
||||
|
||||
express-ipfilter@1.3.2:
|
||||
resolution: {integrity: sha512-yMzCWGuVMnR8CFlsIC2spHWoQYp9vtyZXUgS/JdV5GOJgrz6zmKOEZsA4eF1XrxkOIVzaVk6yzTBk65pBhliNw==}
|
||||
engines: {node: '>=8.9.0'}
|
||||
|
||||
express@4.19.2:
|
||||
resolution: {integrity: sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==}
|
||||
engines: {node: '>= 0.10.0'}
|
||||
|
|
@ -374,6 +381,13 @@ packages:
|
|||
inherits@2.0.4:
|
||||
resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==}
|
||||
|
||||
ip6@0.2.10:
|
||||
resolution: {integrity: sha512-1LdpyKjhvepd6EbAU6rW4g14vuYtx5TnJX9TfZZBhsM6DsyPQLNzW12rtbUqXBMwqFrLVV/Gcxv0GNFvJp2cYA==}
|
||||
hasBin: true
|
||||
|
||||
ip@2.0.1:
|
||||
resolution: {integrity: sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ==}
|
||||
|
||||
ipaddr.js@1.9.1:
|
||||
resolution: {integrity: sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==}
|
||||
engines: {node: '>= 0.10'}
|
||||
|
|
@ -602,6 +616,10 @@ packages:
|
|||
resolution: {integrity: sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==}
|
||||
engines: {node: '>= 0.6'}
|
||||
|
||||
range_check@2.0.4:
|
||||
resolution: {integrity: sha512-aed0ocXXj+SIiNNN9b+mZWA3Ow2GXHtftOGk2xQwshK5GbEZAvUcPWNQBLTx/lPcdFRIUFlFCRtHTQNIFMqynQ==}
|
||||
engines: {node: '>=10.0.0'}
|
||||
|
||||
raw-body@2.5.2:
|
||||
resolution: {integrity: sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==}
|
||||
engines: {node: '>= 0.8'}
|
||||
|
|
@ -1057,6 +1075,13 @@ snapshots:
|
|||
|
||||
etag@1.8.1: {}
|
||||
|
||||
express-ipfilter@1.3.2:
|
||||
dependencies:
|
||||
ip: 2.0.1
|
||||
lodash: 4.17.21
|
||||
proxy-addr: 2.0.7
|
||||
range_check: 2.0.4
|
||||
|
||||
express@4.19.2:
|
||||
dependencies:
|
||||
accepts: 1.3.8
|
||||
|
|
@ -1191,6 +1216,10 @@ snapshots:
|
|||
|
||||
inherits@2.0.4: {}
|
||||
|
||||
ip6@0.2.10: {}
|
||||
|
||||
ip@2.0.1: {}
|
||||
|
||||
ipaddr.js@1.9.1: {}
|
||||
|
||||
is-binary-path@2.1.0:
|
||||
|
|
@ -1359,6 +1388,11 @@ snapshots:
|
|||
|
||||
range-parser@1.2.1: {}
|
||||
|
||||
range_check@2.0.4:
|
||||
dependencies:
|
||||
ip6: 0.2.10
|
||||
ipaddr.js: 1.9.1
|
||||
|
||||
raw-body@2.5.2:
|
||||
dependencies:
|
||||
bytes: 3.1.2
|
||||
|
|
|
|||
Loading…
Reference in a new issue