Skip to content

Commit

Permalink
added possibilty to run together with greenlight
Browse files Browse the repository at this point in the history
  • Loading branch information
svoeth committed Apr 26, 2020
1 parent a606fe2 commit 8ba5c3e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
HOST=127.0.0.1
PORT=5000
PORT=5001
# you can call `sudo bbb-conf --secret` for the following two values
BBB_API_URL=https://demo.bigbluebutton.org/bigbluebutton
BBB_API_SECRET=FIXME
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The first user gets moderator level access.

### Setup

Tested with an BBB instance installed with [bbb-install.sh](https://github.com/bigbluebutton/bbb-install).
Tested with an BBB instance installed with [bbb-install.sh](https://github.com/bigbluebutton/bbb-install). Can be run next to greenlight on the same machine by using different subdirectory and port.

Installation requires git and bbb to be installed on the same machine

Expand All @@ -29,7 +29,8 @@ npm install

Create an `.env` file (use `.env.sample` as a template) and enter your BBB API URL and Secret there. You can get these by running `sudo bbb-conf --secret`.

For serving the pages, copy `bbb-easy-join.nginx` to `/etc/bigbluebutton/nginx/`. If there are already `greenlight-redirect.nginx` and/or `greenlight.nginx`, rename (remove the .nginx suffix) or delete them.
For serving the pages, copy `bbb-easy-join.nginx` to `/etc/bigbluebutton/nginx/`. If there is already `greenlight-redirect.nginx` you have to decide which subdirectory gets served by nginx if calling $DOMAIN/.
Either remove `greenlight-redirect.nginx` or remove redirect in `bbb-easy-join.nginx` beforce copying (remove last 3 lines).

You can start the service by running `/usr/bin/node /var/www/bbb-easy-join/app.js`
If you want to keep the service running in background and on startup:
Expand Down
26 changes: 13 additions & 13 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const querystring = require('querystring')
const slugify = require('slugify')
const express = require('express')
const app = express()
const port = process.env.PORT || 5000
const port = process.env.PORT || 5001
const host = process.env.HOST || '0.0.0.0'

const BBB_API_URL = process.env.BBB_API_URL
Expand Down Expand Up @@ -73,10 +73,10 @@ app.set('trust proxy', 'loopback')
app.use(express.urlencoded({ extended: true }))

app.get('/', function(req, res) {
res.redirect('/b');
res.redirect('/easy');
})

app.get('/b', function (req, res) {
app.get('/easy', function (req, res) {
res.render('index', {
roomName: req.query.roomName,
roomBlocked: req.query.roomBlocked,
Expand All @@ -86,7 +86,7 @@ app.get('/b', function (req, res) {

// create a room (optionally with password)
// if password is set provide mod and user pw for welcome message
app.post('/b', async function (req, res) {
app.post('/easy', async function (req, res) {
var roomName = req.body.room
var room = slugify(roomName, { lower: true })

Expand All @@ -108,7 +108,7 @@ app.post('/b', async function (req, res) {

//set welcome message(s)
if (typeof WELCOME_MESSAGE === 'string') {
var url = req.protocol + '://' + req.get('host') + '/b/' + roomName
var url = req.protocol + '://' + req.get('host') + '/easy/' + roomName
var joinpattern = new RegExp('%%JOINURL%%', 'g')
//if the room has a manual password set we will provide two welcome msgs and only inform moderators about joining options and passwords
if (room_password.startsWith('user-')) {
Expand All @@ -131,20 +131,20 @@ app.post('/b', async function (req, res) {
if (meet.messageKey === 'idNotUnique') {
// timeout as a very basic bruteforce prevention to prevent room search
setTimeout(function (){
res.redirect('/b' + `?roomName=${encodeURIComponent(roomName)}&roomBlocked=true`);
res.redirect('/easy' + `?roomName=${encodeURIComponent(roomName)}&roomBlocked=true`);
}, 1000);
return
} else {
res.redirect('/b');
res.redirect('/easy');
return
}
}

//slugify roomName because room contains prefix
res.redirect('/b/' + room )
res.redirect('/easy/' + room )
})

app.get('/b/:room', async function (req, res){
app.get('/easy/:room', async function (req, res){
// added slugify lower to prevent error if accidental uppercase or special characters are in adress
var room = slugify(req.params.room, { lower: true })
var info = await getMeetingInfo(room)
Expand All @@ -153,7 +153,7 @@ app.get('/b/:room', async function (req, res){
if (info.returncode === 'FAILED') {
// timeout as a very basic bruteforce prevention to prevent room search
setTimeout(function (){
res.redirect('/b' + `?roomName=${encodeURIComponent(req.params.room)}&roomMissing=true`)
res.redirect('/easy' + `?roomName=${encodeURIComponent(req.params.room)}&roomMissing=true`)
}, 1000);
return
}
Expand All @@ -178,12 +178,12 @@ app.get('/b/:room', async function (req, res){
wrongPw: req.query.wrongPw })
})

app.post('/b/:room', async function (req, res) {
app.post('/easy/:room', async function (req, res) {
var room = slugify(req.params.room)
var name = req.body.name
var info = await getMeetingInfo(room)
if (info.returncode === 'FAILED') {
res.redirect('/b')
res.redirect('/easy')
return
}

Expand All @@ -201,7 +201,7 @@ app.post('/b/:room', async function (req, res) {
if (password != req.body.room_password) {
// timeout as a very basic bruteforce prevention - double time for password try (2 seconds)
setTimeout(function (){
res.redirect('/b/' + info.meetingName + `?username=${encodeURIComponent(name)}&wrongPw=true`);
res.redirect('/easy/' + info.meetingName + `?username=${encodeURIComponent(name)}&wrongPw=true`);
}, 2000);
return;
}
Expand Down
6 changes: 3 additions & 3 deletions bbb-easy-join.nginx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
location /b {
proxy_pass http://127.0.0.1:5000;
location /easy {
proxy_pass http://127.0.0.1:5001;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
}

location = / {
return 307 /b;
return 307 /easy;
}

4 changes: 2 additions & 2 deletions views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<% if (roomBlocked) { %>
<div class="alert danger"><p>Room <em><%= roomName %></em> already exists.
<br>
<a href="/b/<%= roomName %>">Click here to join <em><%= roomName %></em>.</a></p></div>
<a href="/easy/<%= roomName %>">Click here to join <em><%= roomName %></em>.</a></p></div>
<h4>
Or choose another room name:
</h4>
Expand All @@ -61,7 +61,7 @@
<p>(think of a unique name for your room)</p>
<% } %>
<% } %>
<form method="POST" action="/b">
<form method="POST" action="/easy">
<input type="text" id="room" required="" name="room" <% if (roomName && roomMissing) { %>value="<%= roomName %>"<% } %>placeholder="Roomname" size="29" class="field input-default" autofocus="">
<input type="password" id="room_password" name="room_password" placeholder="Password (optional)" size="29" class="field input-default">
<input type="submit" value="Create Room" class="submit_btn button success large"><br>
Expand Down
2 changes: 1 addition & 1 deletion views/join.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<% if (wrongPw) { %>
<div class="alert danger"><p>Wrong password</p></div>
<% } %>
<form method="POST" action="/b/<%= room %>">
<form method="POST" action="/easy/<%= room %>">
<input type="text" id="name" required="" name="name" <% if (username) { %>value="<%= username %>"<% } %> placeholder="Choose a name" size="29" class="field input-default" autofocus>
<% if (requiresPassword) { %>
<input type="password" id="room_password" required="" name="room_password" placeholder="Password (required)" size="29" class="field input-default">
Expand Down

0 comments on commit 8ba5c3e

Please sign in to comment.