[mirotalksfu] - improve host protection mode

هذا الالتزام موجود في:
Miroslav Pejic
2024-04-27 22:47:57 +02:00
الأصل 8b87f6b3b0
التزام 7cae61ba85
2 ملفات معدلة مع 22 إضافات و4 حذوفات

عرض الملف

@@ -3,6 +3,7 @@
module.exports = class Host { module.exports = class Host {
constructor() { constructor() {
this.authorizedIPs = new Map(); this.authorizedIPs = new Map();
this.roomActive = false;
} }
/** /**
@@ -20,6 +21,7 @@ module.exports = class Host {
*/ */
setAuthorizedIP(ip, authorized) { setAuthorizedIP(ip, authorized) {
this.authorizedIPs.set(ip, authorized); this.authorizedIPs.set(ip, authorized);
this.roomActive = true;
} }
/** /**
@@ -31,12 +33,21 @@ module.exports = class Host {
return this.authorizedIPs.has(ip); return this.authorizedIPs.has(ip);
} }
/**
* Host room active
* @returns boolean
*/
isRoomActive() {
return this.roomActive;
}
/** /**
* Delete ip from authorized IPs * Delete ip from authorized IPs
* @param {string} ip * @param {string} ip
* @returns boolean * @returns boolean
*/ */
deleteIP(ip) { deleteIP(ip) {
this.roomActive = false;
return this.authorizedIPs.delete(ip); return this.authorizedIPs.delete(ip);
} }
}; };

عرض الملف

@@ -311,7 +311,7 @@ function startServer() {
// main page // main page
app.get(['/'], (req, res) => { app.get(['/'], (req, res) => {
//log.debug('/ - hostCfg ----->', hostCfg); //log.debug('/ - hostCfg ----->', hostCfg);
if (hostCfg.protected && !hostCfg.authenticated) { if ((hostCfg.protected && !hostCfg.authenticated) || authHost.isRoomActive()) {
const ip = getIP(req); const ip = getIP(req);
if (allowedIP(ip)) { if (allowedIP(ip)) {
res.sendFile(views.landing); res.sendFile(views.landing);
@@ -329,7 +329,7 @@ function startServer() {
app.get(['/newroom'], (req, res) => { app.get(['/newroom'], (req, res) => {
//log.info('/newroom - hostCfg ----->', hostCfg); //log.info('/newroom - hostCfg ----->', hostCfg);
if (hostCfg.protected && !hostCfg.authenticated) { if ((hostCfg.protected && !hostCfg.authenticated) || authHost.isRoomActive()) {
const ip = getIP(req); const ip = getIP(req);
if (allowedIP(ip)) { if (allowedIP(ip)) {
res.sendFile(views.newRoom); res.sendFile(views.newRoom);
@@ -405,7 +405,7 @@ function startServer() {
// join room by id // join room by id
app.get('/join/:roomId', (req, res) => { app.get('/join/:roomId', (req, res) => {
//log.debug('/join/room - hostCfg ----->', hostCfg); //log.debug('/join/room - hostCfg ----->', hostCfg);
if (hostCfg.authenticated) { if (hostCfg.authenticated || authHost.isRoomActive()) {
res.sendFile(views.room); res.sendFile(views.room);
} else { } else {
if (hostCfg.protected) { if (hostCfg.protected) {
@@ -2075,7 +2075,13 @@ function startServer() {
function allowedIP(ip) { function allowedIP(ip) {
const authorizedIPs = authHost.getAuthorizedIPs(); const authorizedIPs = authHost.getAuthorizedIPs();
const authorizedIP = authHost.isAuthorizedIP(ip); const authorizedIP = authHost.isAuthorizedIP(ip);
log.info('Allowed IPs', { ip: ip, authorizedIP: authorizedIP, authorizedIPs: authorizedIPs }); const isRoomActive = authHost.isRoomActive();
log.info('Allowed IPs', {
ip: ip,
authorizedIP: authorizedIP,
authorizedIPs: authorizedIPs,
isRoomActive: isRoomActive,
});
return authHost != null && authorizedIP; return authHost != null && authorizedIP;
} }
@@ -2088,6 +2094,7 @@ function startServer() {
log.info('Remove IP from auth', { log.info('Remove IP from auth', {
ip: ip, ip: ip,
authorizedIps: authHost.getAuthorizedIPs(), authorizedIps: authHost.getAuthorizedIPs(),
roomActive: authHost.isRoomActive(),
}); });
} }
} }