[mirotalksfu] - #126 improvements
هذا الالتزام موجود في:
@@ -1,18 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
const Logger = require('./Logger');
|
||||
const log = new Logger('Host');
|
||||
|
||||
module.exports = class Host {
|
||||
constructor(ip, authorized) {
|
||||
this.auth = new Map();
|
||||
this.auth.set(ip, authorized);
|
||||
//log.debug('AUTH ---> ', this.auth.get(ip));
|
||||
constructor() {
|
||||
this.authorizedIPs = new Map();
|
||||
}
|
||||
isAuthorized(ip) {
|
||||
return this.auth.has(ip);
|
||||
|
||||
/**
|
||||
* Get authorized IPs
|
||||
* @returns object
|
||||
*/
|
||||
getAuthorizedIPs() {
|
||||
return Object.fromEntries(this.authorizedIPs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set authorized IP
|
||||
* @param {string} ip
|
||||
* @param {boolean} authorized
|
||||
*/
|
||||
setAuthorizedIP(ip, authorized) {
|
||||
this.authorizedIPs.set(ip, authorized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if IP is authorized
|
||||
* @param {string} ip
|
||||
* @returns boolean
|
||||
*/
|
||||
isAuthorizedIP(ip) {
|
||||
return this.authorizedIPs.has(ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete ip from authorized IPs
|
||||
* @param {string} ip
|
||||
* @returns boolean
|
||||
*/
|
||||
deleteIP(ip) {
|
||||
return this.auth.delete(ip);
|
||||
return this.authorizedIPs.delete(ip);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -163,14 +163,14 @@ const views = {
|
||||
room: path.join(__dirname, '../../', 'public/views/Room.html'),
|
||||
};
|
||||
|
||||
let announcedIP = config.mediasoup.webRtcTransport.listenIps[0].announcedIp; // AnnouncedIP (server public IPv4)
|
||||
const authHost = new Host(); // Authenticated IP by Login
|
||||
|
||||
let authHost; // Authenticated IP by Login
|
||||
|
||||
let roomList = new Map();
|
||||
let roomList = new Map(); // All Rooms
|
||||
|
||||
let presenters = {}; // collect presenters grp by roomId
|
||||
|
||||
let announcedIP = config.mediasoup.webRtcTransport.listenIps[0].announcedIp; // AnnouncedIP (server public IPv4)
|
||||
|
||||
// All mediasoup workers
|
||||
let workers = [];
|
||||
let nextMediasoupWorkerIdx = 0;
|
||||
@@ -284,7 +284,7 @@ function startServer() {
|
||||
if (hostCfg.protected && isPeerValid && !hostCfg.authenticated) {
|
||||
const ip = getIP(req);
|
||||
hostCfg.authenticated = true;
|
||||
authHost = new Host(ip, true);
|
||||
authHost.setAuthorizedIP(ip, true);
|
||||
log.debug('Direct Join user auth as host done', {
|
||||
ip: ip,
|
||||
username: username,
|
||||
@@ -375,8 +375,12 @@ function startServer() {
|
||||
if (hostCfg.protected && isPeerValid && !hostCfg.authenticated) {
|
||||
const ip = getIP(req);
|
||||
hostCfg.authenticated = true;
|
||||
authHost = new Host(ip, true);
|
||||
log.debug('HOST LOGIN OK', { ip: ip, authorized: authHost.isAuthorized(ip) });
|
||||
authHost.setAuthorizedIP(ip, true);
|
||||
log.debug('HOST LOGIN OK', {
|
||||
ip: ip,
|
||||
authorized: authHost.isAuthorizedIP(ip),
|
||||
authorizedIps: authHost.getAuthorizedIPs(),
|
||||
});
|
||||
return res.status(200).json({ message: 'authorized' });
|
||||
}
|
||||
|
||||
@@ -1492,7 +1496,7 @@ function startServer() {
|
||||
return req.headers['x-forwarded-for'] || req.socket.remoteAddress;
|
||||
}
|
||||
function allowedIP(ip) {
|
||||
return authHost != null && authHost.isAuthorized(ip);
|
||||
return authHost != null && authHost.isAuthorizedIP(ip);
|
||||
}
|
||||
function removeIP(socket) {
|
||||
if (hostCfg.protected) {
|
||||
@@ -1500,7 +1504,10 @@ function startServer() {
|
||||
if (ip && allowedIP(ip)) {
|
||||
authHost.deleteIP(ip);
|
||||
hostCfg.authenticated = false;
|
||||
log.debug('Remove IP from auth', { ip: ip });
|
||||
log.info('Remove IP from auth', {
|
||||
ip: ip,
|
||||
authorizedIps: authHost.getAuthorizedIPs(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم