[mirotalk] - keep room name through authentication
This commit is contained in:
@@ -100,6 +100,18 @@
|
||||
| screen | boolean | screen stream |
|
||||
| notify | boolean | welcome message |
|
||||
|
||||
> **Note**
|
||||
|
||||
When [host protection is enabled](https://github.com/miroslavpejic85/mirotalk/commit/285c92605585bf204996dc0bade9b3e7c62d75df#commitcomment-103108955), the URL format for direct room access after authentication should be as follows:
|
||||
|
||||
- https://p2p.mirotalk.com/?room=test
|
||||
|
||||
After host authentication, participants can join the room using any of the following URL formats:
|
||||
|
||||
- https://p2p.mirotalk.com/join/test
|
||||
- https://p2p.mirotalk.com/join/?room=test
|
||||
- https://p2p.mirotalk.com/join/?room=test&name=mirotalk&audio=0&video=0&screen=0¬ify=0
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
+57
-45
@@ -224,7 +224,23 @@ app.use(express.static(dir.public)); // Use all static files from the public fol
|
||||
app.use(bodyParser.urlencoded({ extended: true })); // Need for Slack API body parser
|
||||
app.use(apiBasePath + '/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); // api docs
|
||||
|
||||
// all start from here
|
||||
// Logs requests
|
||||
app.use((req, res, next) => {
|
||||
log.debug('New request:', {
|
||||
// headers: req.headers,
|
||||
body: req.body,
|
||||
method: req.method,
|
||||
path: req.originalUrl,
|
||||
});
|
||||
next();
|
||||
});
|
||||
|
||||
// POST start from here...
|
||||
app.post('*', function (next) {
|
||||
next();
|
||||
});
|
||||
|
||||
// GET start from here...
|
||||
app.get('*', function (next) {
|
||||
next();
|
||||
});
|
||||
@@ -249,7 +265,7 @@ app.use((err, req, res, next) => {
|
||||
|
||||
// main page
|
||||
app.get(['/'], (req, res) => {
|
||||
if (hostCfg.protected == true) {
|
||||
if (hostCfg.protected) {
|
||||
hostCfg.authenticated = false;
|
||||
res.sendFile(views.login);
|
||||
} else {
|
||||
@@ -257,46 +273,6 @@ app.get(['/'], (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// logged
|
||||
app.get(['/logged'], (req, res) => {
|
||||
const ip = getIP(req);
|
||||
if (allowedIP(ip)) {
|
||||
if (Object.keys(req.query).length > 0) {
|
||||
log.debug('Logged: Direct Join', req.query);
|
||||
// http://localhost:3000/?room=test
|
||||
const { room } = checkXSS(req.query);
|
||||
if (room) {
|
||||
return res.sendFile(views.client);
|
||||
}
|
||||
}
|
||||
res.sendFile(views.landing);
|
||||
} else {
|
||||
hostCfg.authenticated = false;
|
||||
res.sendFile(views.login);
|
||||
}
|
||||
});
|
||||
|
||||
// handle login on host protected
|
||||
app.post(['/login'], (req, res) => {
|
||||
if (hostCfg.protected == true) {
|
||||
const ip = getIP(req);
|
||||
log.debug(`Request login to host from: ${ip}`, req.body);
|
||||
const { username, password } = checkXSS(req.body);
|
||||
if (username == hostCfg.username && password == hostCfg.password) {
|
||||
hostCfg.authenticated = true;
|
||||
authHost = new Host(ip, true);
|
||||
log.debug('LOGIN OK', { ip: ip, authorized: authHost.isAuthorized(ip) });
|
||||
res.status(200).json({ message: 'authorized' });
|
||||
} else {
|
||||
log.debug('LOGIN KO', { ip: ip, authorized: false });
|
||||
hostCfg.authenticated = false;
|
||||
res.status(401).json({ message: 'unauthorized' });
|
||||
}
|
||||
} else {
|
||||
res.redirect('/');
|
||||
}
|
||||
});
|
||||
|
||||
// mirotalk about
|
||||
app.get(['/about'], (req, res) => {
|
||||
res.sendFile(views.about);
|
||||
@@ -304,7 +280,7 @@ app.get(['/about'], (req, res) => {
|
||||
|
||||
// set new room name and join
|
||||
app.get(['/newcall'], (req, res) => {
|
||||
if (hostCfg.protected == true) {
|
||||
if (hostCfg.protected) {
|
||||
const ip = getIP(req);
|
||||
if (allowedIP(ip)) {
|
||||
res.sendFile(views.newCall);
|
||||
@@ -346,7 +322,9 @@ app.get('/join/', (req, res) => {
|
||||
*/
|
||||
const { room, name, audio, video, screen, notify } = checkXSS(req.query);
|
||||
// all the params are mandatory for the direct room join
|
||||
if (room && name && audio && video && screen && notify) {
|
||||
// if (room && name && audio && video && screen && notify) {
|
||||
if (room) {
|
||||
// only room mandatory
|
||||
return res.sendFile(views.client);
|
||||
}
|
||||
}
|
||||
@@ -368,6 +346,40 @@ app.get('/join/*', function (req, res) {
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
// logged
|
||||
app.get(['/logged'], (req, res) => {
|
||||
const ip = getIP(req);
|
||||
if (allowedIP(ip)) {
|
||||
res.sendFile(views.landing);
|
||||
} else {
|
||||
hostCfg.authenticated = false;
|
||||
res.sendFile(views.login);
|
||||
}
|
||||
});
|
||||
|
||||
/* AXIOS */
|
||||
|
||||
// handle login on host protected
|
||||
app.post(['/login'], (req, res) => {
|
||||
if (hostCfg.protected) {
|
||||
const ip = getIP(req);
|
||||
log.debug(`Request login to host from: ${ip}`, req.body);
|
||||
const { username, password } = checkXSS(req.body);
|
||||
if (username == hostCfg.username && password == hostCfg.password) {
|
||||
hostCfg.authenticated = true;
|
||||
authHost = new Host(ip, true);
|
||||
log.debug('LOGIN OK', { ip: ip, authorized: authHost.isAuthorized(ip) });
|
||||
res.status(200).json({ message: 'authorized' });
|
||||
} else {
|
||||
log.debug('LOGIN KO', { ip: ip, authorized: false });
|
||||
hostCfg.authenticated = false;
|
||||
res.status(401).json({ message: 'unauthorized' });
|
||||
}
|
||||
} else {
|
||||
res.redirect('/');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
MiroTalk API v1
|
||||
For api docs we use: https://swagger.io/
|
||||
@@ -1277,7 +1289,7 @@ function allowedIP(ip) {
|
||||
* @param {object} socket
|
||||
*/
|
||||
function removeIP(socket) {
|
||||
if (hostCfg.protected == true) {
|
||||
if (hostCfg.protected) {
|
||||
const ip = socket.handshake.address;
|
||||
log.debug('Host protected check ip', { ip: ip });
|
||||
if (ip && allowedIP(ip)) {
|
||||
|
||||
@@ -144,7 +144,11 @@
|
||||
})
|
||||
.then(function (response) {
|
||||
console.log(response);
|
||||
window.location.href = '/logged/?room=' + room;
|
||||
// http://localhost:3010/?room=test
|
||||
if (room) {
|
||||
return (window.location.href = '/join/' + room);
|
||||
}
|
||||
return (window.location.href = '/logged');
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error(error);
|
||||
|
||||
Reference in New Issue
Block a user