Update v1.1.1-beta1
This commit is contained in:
@@ -10,10 +10,24 @@ const logAndBanSuspiciousActivity = async (req, res, next) => {
|
||||
const ip = req.headers['cf-connecting-ip'] || req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
||||
const url = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
||||
|
||||
if (req.originalUrl === '/auth/activedirectory', "/favicon.ico" && req.method === 'POST') {
|
||||
// Skip monitoring for localhost/local IPs
|
||||
const localIps = ['127.0.0.1', '::1', 'localhost', '::ffff:127.0.0.1'];
|
||||
if (localIps.includes(ip)) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Skip monitoring for Chrome DevTools requests
|
||||
if (req.originalUrl.includes('.well-known/appspecific/com.chrome.devtools.json')) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip monitoring for specific endpoints
|
||||
if (req.originalUrl === '/auth/activedirectory' || req.originalUrl === '/favicon.ico') {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
let bans;
|
||||
try {
|
||||
|
||||
90
models/websocketManager.js
Normal file
90
models/websocketManager.js
Normal file
@@ -0,0 +1,90 @@
|
||||
const WebSocket = require('ws');
|
||||
const { logger } = require('../config/logs');
|
||||
|
||||
class WebSocketManager {
|
||||
constructor(server) {
|
||||
this.wss = new WebSocket.Server({ server });
|
||||
this.connections = new Map(); // Pour stocker les connexions utilisateur
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
this.wss.on('connection', (ws, req) => {
|
||||
|
||||
ws.on('message', (message) => {
|
||||
try {
|
||||
const data = JSON.parse(message);
|
||||
this.handleMessage(ws, data);
|
||||
} catch (error) {
|
||||
logger.error('Error handling WebSocket message:', error);
|
||||
}
|
||||
});
|
||||
|
||||
ws.on('close', () => {
|
||||
this.handleDisconnect(ws);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
handleMessage(ws, data) {
|
||||
switch (data.type) {
|
||||
case 'join':
|
||||
this.handleJoin(ws, data);
|
||||
break;
|
||||
case 'leave':
|
||||
this.handleLeave(ws, data);
|
||||
break;
|
||||
default:
|
||||
logger.warn('Unknown message type:', data.type);
|
||||
}
|
||||
}
|
||||
|
||||
handleJoin(ws, data) {
|
||||
const { userId, fileId } = data;
|
||||
this.connections.set(ws, { userId, fileId });
|
||||
this.broadcastFileStatus(fileId);
|
||||
}
|
||||
|
||||
handleLeave(ws, data) {
|
||||
const { fileId } = data;
|
||||
this.connections.delete(ws);
|
||||
this.broadcastFileStatus(fileId);
|
||||
}
|
||||
|
||||
handleDisconnect(ws) {
|
||||
const connection = this.connections.get(ws);
|
||||
if (connection) {
|
||||
this.broadcastFileStatus(connection.fileId);
|
||||
this.connections.delete(ws);
|
||||
}
|
||||
}
|
||||
|
||||
broadcastFileStatus(fileId) {
|
||||
const activeUsers = Array.from(this.connections.values())
|
||||
.filter(conn => conn.fileId === fileId)
|
||||
.map(conn => conn.userId);
|
||||
|
||||
const message = JSON.stringify({
|
||||
type: 'fileStatus',
|
||||
fileId,
|
||||
activeUsers
|
||||
});
|
||||
|
||||
this.wss.clients.forEach(client => {
|
||||
if (client.readyState === WebSocket.OPEN) {
|
||||
client.send(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Méthode pour envoyer une mise à jour à tous les clients
|
||||
broadcast(data) {
|
||||
this.wss.clients.forEach(client => {
|
||||
if (client.readyState === WebSocket.OPEN) {
|
||||
client.send(JSON.stringify(data));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WebSocketManager;
|
||||
Reference in New Issue
Block a user