2011-03-27 09:15:19 +08:00
|
|
|
require 'rubygems'
|
2011-04-29 17:10:59 +08:00
|
|
|
require 'bundler'
|
|
|
|
Bundler.setup(:default)
|
|
|
|
|
2011-03-27 13:57:42 +08:00
|
|
|
#require 'sinatra'
|
|
|
|
require 'sinatra/base'
|
2011-03-28 08:10:13 +08:00
|
|
|
require 'haml'
|
2011-03-27 09:15:19 +08:00
|
|
|
require 'bigbluebutton-api'
|
2011-03-28 08:10:13 +08:00
|
|
|
|
2011-03-27 13:57:42 +08:00
|
|
|
#TODO: manage exceptions
|
2011-03-27 17:42:59 +08:00
|
|
|
# support of multiple conferences
|
|
|
|
# wait student for meeting to start
|
|
|
|
# logout
|
2011-03-28 10:35:24 +08:00
|
|
|
|
2011-04-29 17:10:59 +08:00
|
|
|
|
2011-03-27 13:57:42 +08:00
|
|
|
class LoginScreen < Sinatra::Base
|
|
|
|
use Rack::Session::Pool, :expire_after => 2592000
|
|
|
|
|
2011-04-29 17:10:59 +08:00
|
|
|
configure do
|
|
|
|
set :pass_inst, "instructor"
|
|
|
|
set :pass_stud, "student"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2011-03-27 17:42:59 +08:00
|
|
|
get('/login/?') {
|
2011-04-29 17:10:59 +08:00
|
|
|
if session["user"].nil? == false
|
|
|
|
redirect to("/?")
|
|
|
|
else
|
|
|
|
haml :login
|
|
|
|
end
|
2011-03-27 13:57:42 +08:00
|
|
|
}
|
|
|
|
|
2011-04-29 07:20:23 +08:00
|
|
|
post('/login/?') do
|
2011-03-27 13:57:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
username=params[:txtusername]
|
|
|
|
password=params[:txtpassword]
|
|
|
|
|
2011-04-29 17:10:59 +08:00
|
|
|
if password==settings.pass_inst
|
2011-03-27 13:57:42 +08:00
|
|
|
session["user"]=username
|
2011-03-27 17:42:59 +08:00
|
|
|
session["role"]="instructor"
|
2011-04-29 17:10:59 +08:00
|
|
|
elsif password==settings.pass_stud
|
2011-03-27 13:57:42 +08:00
|
|
|
session["user"]=username
|
|
|
|
session["role"]="student"
|
|
|
|
end
|
2011-04-29 07:20:23 +08:00
|
|
|
redirect to("/")
|
2011-03-27 13:57:42 +08:00
|
|
|
end
|
|
|
|
end
|
2011-03-28 08:10:13 +08:00
|
|
|
|
2011-03-27 13:57:42 +08:00
|
|
|
class Main < Sinatra::Base
|
2011-04-29 17:10:59 +08:00
|
|
|
|
2011-03-27 13:57:42 +08:00
|
|
|
use LoginScreen
|
2011-03-28 10:35:24 +08:00
|
|
|
|
2011-03-27 17:42:59 +08:00
|
|
|
#enable logger
|
2011-03-27 13:57:42 +08:00
|
|
|
set :logging, true
|
2011-03-28 08:10:13 +08:00
|
|
|
|
2011-03-27 17:42:59 +08:00
|
|
|
configure do
|
2011-04-29 17:10:59 +08:00
|
|
|
set :pass_inst, "instructor"
|
|
|
|
set :pass_stud, "student"
|
|
|
|
|
2011-03-27 17:42:59 +08:00
|
|
|
#setting up logger
|
2011-04-29 04:28:33 +08:00
|
|
|
log = File.new("log/sinatra.log", "a")
|
2011-03-27 17:42:59 +08:00
|
|
|
STDOUT.reopen(log)
|
|
|
|
STDERR.reopen(log)
|
|
|
|
|
|
|
|
#loading config YAML file
|
2011-04-29 04:28:33 +08:00
|
|
|
config_file = 'bigbluebutton.yml'
|
2011-03-27 17:42:59 +08:00
|
|
|
unless File.exist? config_file
|
|
|
|
puts config_file + " does not exists..."
|
|
|
|
end
|
|
|
|
puts "loading config file..."
|
|
|
|
$config = YAML.load_file(config_file)
|
|
|
|
|
|
|
|
#setting bigbluebutton object
|
|
|
|
puts "setting bigbluebutton session" + $config['bbb_url']
|
|
|
|
$bbb_api = BigBlueButton::BigBlueButtonApi.new($config['bbb_url'], $config['bbb_salt'], $config['bbb_version'], true)
|
|
|
|
|
|
|
|
end
|
2011-03-28 08:10:13 +08:00
|
|
|
|
2011-03-27 13:57:42 +08:00
|
|
|
before do
|
|
|
|
unless session['user']
|
2011-04-29 07:20:23 +08:00
|
|
|
redirect ("/login")
|
2011-03-27 13:57:42 +08:00
|
|
|
end
|
|
|
|
end
|
2011-03-27 17:42:59 +08:00
|
|
|
get('/?') {
|
2011-04-29 17:10:59 +08:00
|
|
|
puts "getting meetings..."
|
|
|
|
resp = $bbb_api.get_meetings
|
|
|
|
@conflist = Hash.new
|
|
|
|
unless !resp["meetings"].nil? then
|
|
|
|
puts resp[:meetings]
|
|
|
|
@conflist = resp[:meetings]
|
|
|
|
end
|
2011-03-27 13:57:42 +08:00
|
|
|
|
2011-04-29 17:10:59 +08:00
|
|
|
@message = ""
|
|
|
|
if @conflist.length == 0
|
|
|
|
@message = "No meetings running..."
|
2011-03-27 13:57:42 +08:00
|
|
|
end
|
2011-04-29 17:10:59 +08:00
|
|
|
|
|
|
|
haml :list
|
|
|
|
|
2011-03-27 13:57:42 +08:00
|
|
|
}
|
|
|
|
|
2011-04-29 17:10:59 +08:00
|
|
|
get '/logout' do
|
|
|
|
session.clear
|
|
|
|
redirect to("/login")
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/enter' do
|
|
|
|
meeting_id = params[:meetingid]
|
|
|
|
username = session['user']
|
|
|
|
passwd = nil
|
|
|
|
|
|
|
|
if session['role'] == "instructor"
|
|
|
|
passwd = settings.pass_inst
|
|
|
|
elsif session['role'] == "student"
|
|
|
|
passwd = settings.pass_stud
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect $bbb_api.join_meeting_url(meeting_id, username, passwd)
|
|
|
|
end
|
2011-03-27 17:42:59 +08:00
|
|
|
|
2011-03-27 13:57:42 +08:00
|
|
|
get '/metadata' do
|
|
|
|
haml :metadata
|
|
|
|
end
|
2011-03-28 10:35:24 +08:00
|
|
|
|
2011-03-27 13:57:42 +08:00
|
|
|
post '/metadata/process' do
|
2011-04-29 17:10:59 +08:00
|
|
|
meeting_name=params[:txtname]
|
|
|
|
meeting_id=params[:txtid]
|
2011-03-27 13:57:42 +08:00
|
|
|
|
2011-04-29 17:10:59 +08:00
|
|
|
metadata = Hash.new
|
|
|
|
metadata[:title]=params[:txttitle]
|
|
|
|
metadata[:series]=params[:txtseries]
|
|
|
|
metadata[:instructor]=params[:txtinstructor]
|
2011-03-27 13:57:42 +08:00
|
|
|
|
2011-04-29 17:10:59 +08:00
|
|
|
$bbb_api.create_meeting(meeting_name, meeting_id, settings.pass_inst, settings.pass_stud, nil, nil, nil, nil, nil, true, metadata)
|
2011-03-27 13:57:42 +08:00
|
|
|
|
2011-04-29 17:10:59 +08:00
|
|
|
redirect to("/enter?meetingid=#{meeting_id}")
|
2011-03-27 17:42:59 +08:00
|
|
|
end
|
|
|
|
|
2011-03-28 10:35:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-03-27 13:57:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
|