2014-09-02 04:53:57 +08:00
|
|
|
#!/usr/bin/ruby
|
2012-12-01 00:16:42 +08:00
|
|
|
# Set encoding to utf-8
|
|
|
|
# encoding: UTF-8
|
|
|
|
#
|
|
|
|
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
|
|
|
|
#
|
|
|
|
# Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below).
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify it under the
|
|
|
|
# terms of the GNU Lesser General Public License as published by the Free Software
|
|
|
|
# Foundation; either version 3.0 of the License, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
#
|
|
|
|
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
require '../../core/lib/recordandplayback'
|
|
|
|
require 'rubygems'
|
|
|
|
require 'yaml'
|
2013-01-10 23:16:08 +08:00
|
|
|
require 'net/http'
|
2016-09-02 04:56:55 +08:00
|
|
|
require 'net/https'
|
2013-01-10 23:16:08 +08:00
|
|
|
require 'rexml/document'
|
|
|
|
require 'open-uri'
|
2013-01-22 23:56:12 +08:00
|
|
|
require 'digest/md5'
|
2012-12-01 00:16:42 +08:00
|
|
|
|
2014-09-02 04:53:57 +08:00
|
|
|
BigBlueButton.logger = Logger.new("/var/log/bigbluebutton/mconf_decrypter.log",'daily' )
|
2013-06-04 01:23:22 +08:00
|
|
|
#BigBlueButton.logger = Logger.new(STDOUT)
|
2012-12-01 00:16:42 +08:00
|
|
|
|
|
|
|
bbb_props = YAML::load(File.open('../../core/scripts/bigbluebutton.yml'))
|
2014-09-02 04:53:57 +08:00
|
|
|
mconf_props = YAML::load(File.open('mconf-decrypter.yml'))
|
2013-02-09 02:10:28 +08:00
|
|
|
|
2013-06-04 01:23:22 +08:00
|
|
|
# these properties must be global variables (starting with $)
|
|
|
|
$private_key = mconf_props['private_key']
|
|
|
|
$get_recordings_url = mconf_props['get_recordings_url']
|
2016-09-02 04:56:55 +08:00
|
|
|
$verify_ssl_certificate = mconf_props['verify_ssl_certificate']
|
2017-03-11 02:09:23 +08:00
|
|
|
$recording_dir = bbb_props['recording_dir']
|
2013-06-04 01:23:22 +08:00
|
|
|
$raw_dir = "#{$recording_dir}/raw"
|
|
|
|
$archived_dir = "#{$recording_dir}/status/archived"
|
2013-02-23 09:20:55 +08:00
|
|
|
|
2016-08-17 00:09:19 +08:00
|
|
|
def getRequest(url)
|
2016-08-19 03:22:40 +08:00
|
|
|
BigBlueButton.logger.debug("Fetching #{url}")
|
2016-08-17 00:09:19 +08:00
|
|
|
url_parsed = URI.parse(url)
|
|
|
|
http = Net::HTTP.new(url_parsed.host, url_parsed.port)
|
|
|
|
http.use_ssl = (url_parsed.scheme.downcase == "https")
|
2016-09-02 04:56:55 +08:00
|
|
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl? && ! $verify_ssl_certificate
|
2016-08-17 00:09:19 +08:00
|
|
|
http.get(url_parsed.request_uri)
|
|
|
|
end
|
|
|
|
|
2013-05-25 00:26:11 +08:00
|
|
|
def fetchRecordings(url)
|
2013-06-04 01:23:22 +08:00
|
|
|
doc = nil
|
2013-05-25 00:26:11 +08:00
|
|
|
begin
|
2016-08-17 00:09:19 +08:00
|
|
|
response = getRequest(url)
|
|
|
|
# follow redirects once only
|
|
|
|
if response.kind_of?(Net::HTTPRedirection)
|
2016-08-19 03:22:40 +08:00
|
|
|
BigBlueButton.logger.debug("Received a redirect, will make a new request")
|
2016-08-17 00:09:19 +08:00
|
|
|
response = getRequest(response['location'])
|
|
|
|
end
|
|
|
|
|
|
|
|
doc = Nokogiri::XML(response.body)
|
2013-05-25 00:26:11 +08:00
|
|
|
returncode = doc.xpath("//returncode")
|
|
|
|
if returncode.empty? or returncode.text != "SUCCESS"
|
2014-09-02 04:53:57 +08:00
|
|
|
BigBlueButton.logger.error "getRecordings didn't return success:\n#{doc.to_xml(:indent => 2)}"
|
|
|
|
return false
|
2013-05-25 00:26:11 +08:00
|
|
|
end
|
|
|
|
rescue
|
2014-09-02 04:53:57 +08:00
|
|
|
BigBlueButton.logger.error("Exception occurred: #{$!}")
|
2013-05-25 00:26:11 +08:00
|
|
|
return false
|
2013-02-23 09:20:55 +08:00
|
|
|
end
|
2013-01-10 23:16:08 +08:00
|
|
|
|
2013-02-23 09:20:55 +08:00
|
|
|
doc.xpath("//recording").each do |recording|
|
2013-02-27 04:42:41 +08:00
|
|
|
record_id = recording.xpath(".//recordID").text
|
|
|
|
recording.xpath(".//download/format").each do |format|
|
|
|
|
type = format.xpath(".//type").text
|
2013-02-23 09:20:55 +08:00
|
|
|
if type == "encrypted"
|
|
|
|
meeting_id = record_id
|
2013-02-27 04:42:41 +08:00
|
|
|
file_url = format.xpath(".//url").text
|
|
|
|
key_file_url = format.xpath(".//key").text
|
|
|
|
md5_value = format.xpath(".//md5").text
|
2013-02-23 09:20:55 +08:00
|
|
|
|
|
|
|
encrypted_file = file_url.split("/").last
|
2015-11-27 03:43:38 +08:00
|
|
|
decrypted_file = File.basename(encrypted_file, '.*') + ".tar.gz"
|
2015-04-07 04:06:08 +08:00
|
|
|
# can't check only for archived.done because when the file is published, the archived flag is removed
|
|
|
|
# so we check for any .done file
|
2015-07-05 04:02:03 +08:00
|
|
|
if Dir.glob("#{$recording_dir}/status/**/#{record_id}*.done").empty? then
|
2013-06-04 01:23:22 +08:00
|
|
|
Dir.chdir($raw_dir) do
|
2013-10-03 04:37:35 +08:00
|
|
|
BigBlueButton.logger.info("Next recording to be processed is #{meeting_id}")
|
|
|
|
|
|
|
|
BigBlueButton.logger.debug("Removing any file previously downloaded related to this recording")
|
2013-10-14 23:13:49 +08:00
|
|
|
FileUtils.rm_r Dir.glob("#{$raw_dir}/#{record_id}*"), :force => true
|
2013-02-23 09:20:55 +08:00
|
|
|
|
|
|
|
BigBlueButton.logger.debug("recordID = #{record_id}")
|
|
|
|
BigBlueButton.logger.debug("file_url = #{file_url}")
|
|
|
|
BigBlueButton.logger.debug("key_file_url = #{key_file_url}")
|
|
|
|
BigBlueButton.logger.debug("md5_value = #{md5_value}")
|
|
|
|
|
|
|
|
BigBlueButton.logger.info("Downloading the encrypted file to #{encrypted_file}")
|
2014-09-02 04:53:57 +08:00
|
|
|
|
2015-05-19 11:03:08 +08:00
|
|
|
`wget --output-document "#{encrypted_file}" "#{file_url}"`
|
2013-02-09 02:10:28 +08:00
|
|
|
|
2013-02-23 09:20:55 +08:00
|
|
|
md5_calculated = Digest::MD5.file(encrypted_file)
|
|
|
|
|
|
|
|
if md5_calculated == md5_value
|
|
|
|
BigBlueButton.logger.info("The calculated MD5 matches the expected value")
|
|
|
|
key_file = key_file_url.split("/").last
|
|
|
|
decrypted_key_file = File.basename(key_file, '.*') + ".txt"
|
|
|
|
|
|
|
|
BigBlueButton.logger.info("Downloading the key file to #{key_file}")
|
|
|
|
writeOut = open(key_file, "wb")
|
|
|
|
writeOut.write(open(key_file_url).read)
|
|
|
|
writeOut.close
|
|
|
|
|
|
|
|
if key_file != decrypted_key_file
|
2013-03-04 23:51:36 +08:00
|
|
|
BigBlueButton.logger.debug("Locating private key")
|
2013-06-04 01:23:22 +08:00
|
|
|
if not File.exists?("#{$private_key}")
|
2014-09-02 04:53:57 +08:00
|
|
|
BigBlueButton.logger.error "Couldn't find the private key on #{$private_key}"
|
|
|
|
next
|
2013-03-01 03:35:22 +08:00
|
|
|
end
|
2013-03-04 23:51:36 +08:00
|
|
|
BigBlueButton.logger.debug("Decrypting recording key")
|
2013-06-04 01:23:22 +08:00
|
|
|
command = "openssl rsautl -decrypt -inkey #{$private_key} < #{key_file} > #{decrypted_key_file}"
|
2014-09-02 04:53:57 +08:00
|
|
|
status = BigBlueButton.execute(command, false)
|
2013-02-23 09:20:55 +08:00
|
|
|
if not status.success?
|
2014-09-02 04:53:57 +08:00
|
|
|
BigBlueButton.logger.error "Couldn't decrypt the random key with the server private key"
|
|
|
|
next
|
2013-02-23 09:20:55 +08:00
|
|
|
end
|
|
|
|
FileUtils.rm_r "#{key_file}"
|
|
|
|
else
|
|
|
|
BigBlueButton.logger.info("No public key was used to encrypt the random key")
|
|
|
|
end
|
|
|
|
|
2013-03-04 23:51:36 +08:00
|
|
|
BigBlueButton.logger.debug("Decrypting the recording file")
|
2013-02-23 09:20:55 +08:00
|
|
|
command = "openssl enc -aes-256-cbc -d -pass file:#{decrypted_key_file} < #{encrypted_file} > #{decrypted_file}"
|
2014-09-02 04:53:57 +08:00
|
|
|
status = BigBlueButton.execute(command, false)
|
2013-02-09 02:10:28 +08:00
|
|
|
if not status.success?
|
2014-09-02 04:53:57 +08:00
|
|
|
BigBlueButton.logger.error "Couldn't decrypt the recording file using the random key"
|
|
|
|
next
|
2013-02-09 02:10:28 +08:00
|
|
|
end
|
2015-11-27 03:43:38 +08:00
|
|
|
|
|
|
|
command = "tar -xf #{decrypted_file}"
|
|
|
|
status = BigBlueButton.execute(command, false)
|
|
|
|
if not status.success?
|
|
|
|
BigBlueButton.logger.error "Couldn't extract the raw files"
|
|
|
|
next
|
|
|
|
end
|
2013-02-23 09:20:55 +08:00
|
|
|
|
2013-06-04 01:23:22 +08:00
|
|
|
archived_done = File.new("#{$archived_dir}/#{meeting_id}.done", "w")
|
2013-02-23 09:20:55 +08:00
|
|
|
archived_done.write("Archived #{meeting_id}")
|
|
|
|
archived_done.close
|
2017-03-11 02:09:23 +08:00
|
|
|
|
2013-02-23 09:20:55 +08:00
|
|
|
[ "#{encrypted_file}", "#{decrypted_file}", "#{decrypted_key_file}" ].each { |file|
|
|
|
|
BigBlueButton.logger.info("Removing #{file}")
|
|
|
|
FileUtils.rm_r "#{file}"
|
|
|
|
}
|
2013-02-09 02:10:28 +08:00
|
|
|
|
2013-02-23 09:20:55 +08:00
|
|
|
BigBlueButton.logger.info("Recording #{record_id} decrypted successfully")
|
|
|
|
|
|
|
|
else
|
|
|
|
BigBlueButton.logger.error("The calculated MD5 doesn't match the expected value")
|
|
|
|
FileUtils.rm_f(encrypted_file)
|
2013-02-09 02:10:28 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-05-25 00:26:11 +08:00
|
|
|
return true
|
2013-03-04 23:51:36 +08:00
|
|
|
end
|
2013-05-25 00:26:11 +08:00
|
|
|
|
2013-06-04 01:23:22 +08:00
|
|
|
def processGetRecordingsUrlInput(input)
|
|
|
|
if input.respond_to? "each"
|
|
|
|
input.each do |url|
|
|
|
|
processGetRecordingsUrlInput url
|
|
|
|
end
|
|
|
|
else
|
|
|
|
fetchRecordings input
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-06 00:32:48 +08:00
|
|
|
processGetRecordingsUrlInput $get_recordings_url if !$get_recordings_url.nil? and !$get_recordings_url.empty?
|