Note: We appreciate your feedback and bug reports to continue improving our platform. Thank you for your continued support!
This commit is contained in:
@@ -3,25 +3,47 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const setupFilePath = path.join(__dirname, '../data', 'setup.json');
|
||||
|
||||
function isIpAllowed(ip, allowedIps) {
|
||||
return allowedIps.some(allowedIp => {
|
||||
|
||||
if (allowedIp.includes('/')) {
|
||||
const [network, bits] = allowedIp.split('/');
|
||||
const ipLong = ip2long(ip);
|
||||
const networkLong = ip2long(network);
|
||||
const mask = ~(2 ** (32 - bits) - 1);
|
||||
return (ipLong & mask) === (networkLong & mask);
|
||||
}
|
||||
|
||||
return ip === allowedIp;
|
||||
});
|
||||
}
|
||||
|
||||
function ip2long(ip) {
|
||||
return ip.split('.')
|
||||
.reduce((long, octet) => (long << 8) + parseInt(octet), 0) >>> 0;
|
||||
}
|
||||
|
||||
function sendDiscordWebhook(url, req, statusCode) {
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
||||
|
||||
const setupData = JSON.parse(fs.readFileSync(setupFilePath, 'utf-8'));
|
||||
const allowedIps = setupData[0].allowedIps || [];
|
||||
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
||||
|
||||
if (isIpAllowed(ip, allowedIps)) {
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
|
||||
const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
||||
const statusEmoji = [200, 302].includes(statusCode) ? '✅' : '❌';
|
||||
const statusMessage = `**Statut:** ${statusEmoji} (${statusCode})`;
|
||||
|
||||
const timestamp = new Date().toLocaleString('fr-FR', { timeZone: 'UTC', hour12: false });
|
||||
const userAgent = req.get('User-Agent');
|
||||
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
const webhookId = uuidv4();
|
||||
|
||||
const userId = req.user ? req.user.id : 'Inconnu';
|
||||
const userName = req.user ? req.user.name : 'Inconnu';
|
||||
|
||||
@@ -40,17 +62,19 @@ function sendDiscordWebhook(url, req, statusCode) {
|
||||
}
|
||||
}]
|
||||
};
|
||||
|
||||
axios.post(url, data)
|
||||
.then(response => {
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Erreur lors de l\'envoi du webhook:', error);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function discordWebhookSuspisiousAlertMiddleware(req, res, next) {
|
||||
const setupData = JSON.parse(fs.readFileSync(setupFilePath, 'utf-8'));
|
||||
|
||||
|
||||
|
||||
res.on('finish', () => {
|
||||
const discordWebhookUrl = setupData[0].webhooks_discord;
|
||||
sendDiscordWebhook(discordWebhookUrl, req, res.statusCode);
|
||||
|
||||
Reference in New Issue
Block a user