Allow use odbc to store files (record/voicemail) in database. (#1535)
* Change. Allow use odbc to store files (record/voicemail) in database. * Fix. Generate correct default config.
This commit is contained in:
committed by
FusionPBX
parent
119a007acd
commit
09f2d8fa43
@@ -325,20 +325,19 @@
|
||||
--show the storage type
|
||||
freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n");
|
||||
|
||||
--include the base64 function
|
||||
require "resources.functions.base64";
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--base64 encode the file
|
||||
if (file_exists(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext)) then
|
||||
--get the base
|
||||
local f = io.open(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, "rb");
|
||||
local file_content = f:read("*all");
|
||||
f:close();
|
||||
message_base64 = base64.encode(file_content);
|
||||
-- build full path to file
|
||||
local full_path = voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext
|
||||
|
||||
if file_exists(full_path) then
|
||||
--read file content as base64 string
|
||||
message_base64 = assert(file.read_base64(full_path));
|
||||
--freeswitch.consoleLog("notice", "[voicemail] ".. message_base64 .. "\n");
|
||||
|
||||
--delete the file
|
||||
os.remove(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext);
|
||||
os.remove(full_path);
|
||||
end
|
||||
end
|
||||
|
||||
@@ -407,13 +406,10 @@
|
||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||
end
|
||||
if (storage_type == "base64") then
|
||||
array = explode("://", database["system"]);
|
||||
local luasql = require "luasql.postgres";
|
||||
local env = assert (luasql.postgres());
|
||||
local db = env:connect(array[2]);
|
||||
res, serr = db:execute(sql);
|
||||
db:close();
|
||||
env:close();
|
||||
local Database = require "resources.functions.database"
|
||||
local dbh = Database.new('system', 'base64');
|
||||
dbh:query(sql);
|
||||
dbh:release();
|
||||
else
|
||||
dbh:query(sql);
|
||||
end
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
-- POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
local Database = require "resources.functions.database"
|
||||
|
||||
--define a function to choose the greeting
|
||||
function choose_greeting()
|
||||
|
||||
@@ -87,6 +89,8 @@
|
||||
|
||||
--get the greeting from the database
|
||||
if (storage_type == "base64") then
|
||||
local dbh = Database.new('system', 'base64/read')
|
||||
|
||||
sql = [[SELECT * FROM v_voicemail_greetings
|
||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||
AND voicemail_id = ']].. voicemail_id.. [['
|
||||
@@ -95,19 +99,20 @@
|
||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||
end
|
||||
status = dbh:query(sql, function(row)
|
||||
--add functions
|
||||
require "resources.functions.base64";
|
||||
|
||||
--set the voicemail message path
|
||||
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
||||
|
||||
--save the greeting to the file system
|
||||
if (string.len(row["greeting_base64"]) > 32) then
|
||||
local file = io.open(greeting_location, "w");
|
||||
file:write(base64.decode(row["greeting_base64"]));
|
||||
file:close();
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--write decoded string to file
|
||||
assert(file.write_base64(greeting_location, row["greeting_base64"]));
|
||||
end
|
||||
end);
|
||||
|
||||
dbh:release()
|
||||
elseif (storage_type == "http_cache") then
|
||||
greeting_location = storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
||||
end
|
||||
|
||||
+10
-6
@@ -23,6 +23,8 @@
|
||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
-- POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
local Database = require "resources.functions.database"
|
||||
|
||||
--define function to listen to the recording
|
||||
function listen_to_recording (message_number, uuid, created_epoch, caller_id_name, caller_id_number)
|
||||
|
||||
@@ -72,6 +74,8 @@
|
||||
end
|
||||
--get the recordings from the database
|
||||
if (storage_type == "base64") then
|
||||
local dbh = Database.new('system', 'base64/read')
|
||||
|
||||
sql = [[SELECT * FROM v_voicemail_messages
|
||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||
AND voicemail_message_uuid = ']].. uuid.. [[' ]];
|
||||
@@ -79,9 +83,6 @@
|
||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
|
||||
end
|
||||
status = dbh:query(sql, function(row)
|
||||
--add functions
|
||||
require "resources.functions.base64";
|
||||
|
||||
--set the voicemail message path
|
||||
mkdir(voicemail_dir.."/"..voicemail_id);
|
||||
message_intro_location = voicemail_dir.."/"..voicemail_id.."/intro_"..uuid.."."..vm_message_ext;
|
||||
@@ -94,11 +95,14 @@
|
||||
file:close();
|
||||
end
|
||||
if (string.len(row["message_base64"]) > 32) then
|
||||
local file = io.open(message_location, "w");
|
||||
file:write(base64.decode(row["message_base64"]));
|
||||
file:close();
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--write decoded string to file
|
||||
assert(file.write_base64(message_location, row["message_base64"]));
|
||||
end
|
||||
end);
|
||||
dbh:release()
|
||||
elseif (storage_type == "http_cache") then
|
||||
message_location = storage_path.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext;
|
||||
end
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
-- POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
local Database = require"resources.functions.database"
|
||||
|
||||
--play the greeting
|
||||
function play_greeting()
|
||||
--voicemail prompt
|
||||
@@ -43,6 +45,8 @@
|
||||
|
||||
--get the greeting from the database
|
||||
if (storage_type == "base64") then
|
||||
local dbh = Database.new('system', 'base64/read')
|
||||
|
||||
sql = [[SELECT * FROM v_voicemail_greetings
|
||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||
AND voicemail_id = ']].. voicemail_id.. [['
|
||||
@@ -50,29 +54,33 @@
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||
end
|
||||
local saved
|
||||
status = dbh:query(sql, function(row)
|
||||
--add functions
|
||||
require "resources.functions.base64";
|
||||
|
||||
--set the voicemail message path
|
||||
mkdir(voicemail_dir.."/"..voicemail_id);
|
||||
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
||||
|
||||
--if not found, save greeting to local file system
|
||||
--if (not file_exists(greeting_location)) then
|
||||
--saved = file_exists(greeting_location)
|
||||
--if not saved then
|
||||
if (string.len(row["greeting_base64"]) > 32) then
|
||||
local file = io.open(greeting_location, "w");
|
||||
file:write(base64.decode(row["greeting_base64"]));
|
||||
file:close();
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--write decoded string to file
|
||||
saved = file.write_base64(greeting_location, row["greeting_base64"]);
|
||||
end
|
||||
--end
|
||||
end);
|
||||
dbh:release();
|
||||
|
||||
if saved then
|
||||
--play the greeting
|
||||
session:execute("playback",voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||
|
||||
--delete the greeting (retain local for better responsiveness)
|
||||
--os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||
end);
|
||||
end
|
||||
elseif (storage_type == "http_cache") then
|
||||
session:execute("playback",storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||
else
|
||||
|
||||
@@ -82,13 +82,11 @@
|
||||
|
||||
--if base64, encode file
|
||||
if (storage_type == "base64") then
|
||||
--include the base64 function
|
||||
require "resources.functions.base64";
|
||||
--base64 encode the file
|
||||
local f = io.open(real_file, "rb");
|
||||
local file_content = f:read("*all");
|
||||
f:close();
|
||||
greeting_base64 = base64.encode(file_content);
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--read file content as base64 string
|
||||
greeting_base64 = assert(file.read_base64(real_file));
|
||||
end
|
||||
|
||||
--delete the previous recording
|
||||
@@ -134,13 +132,10 @@
|
||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||
end
|
||||
if (storage_type == "base64") then
|
||||
array = explode("://", database["system"]);
|
||||
local luasql = require "luasql.postgres";
|
||||
local env = assert (luasql.postgres());
|
||||
local db = env:connect(array[2]);
|
||||
res, serr = db:execute(sql);
|
||||
db:close();
|
||||
env:close();
|
||||
local Database = require "resources.functions.database"
|
||||
local dbh = Database.new('system', 'base64');
|
||||
dbh:query(sql);
|
||||
dbh:release();
|
||||
else
|
||||
dbh:query(sql);
|
||||
end
|
||||
|
||||
@@ -43,9 +43,6 @@
|
||||
|
||||
--record and save the file
|
||||
if (storage_type == "base64") then
|
||||
--include the base64 function
|
||||
require "resources.functions.base64";
|
||||
|
||||
--set the location
|
||||
voicemail_name_location = voicemail_dir.."/"..voicemail_id.."/recorded_name.wav";
|
||||
|
||||
@@ -58,10 +55,11 @@
|
||||
freeswitch.consoleLog("notice", "[recordings] ".. storage_type .. "\n");
|
||||
|
||||
--base64 encode the file
|
||||
local f = io.open(voicemail_name_location, "rb");
|
||||
local file_content = f:read("*all");
|
||||
f:close();
|
||||
voicemail_name_base64 = base64.encode(file_content);
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--read file content as base64 string
|
||||
voicemail_name_base64 = assert(file.read_base64(voicemail_name_location));
|
||||
|
||||
--update the voicemail name
|
||||
sql = "UPDATE v_voicemails ";
|
||||
@@ -72,13 +70,10 @@
|
||||
freeswitch.consoleLog("notice", "[recording] SQL: " .. sql .. "\n");
|
||||
end
|
||||
if (storage_type == "base64") then
|
||||
array = explode("://", database["system"]);
|
||||
local luasql = require "luasql.postgres";
|
||||
local env = assert (luasql.postgres());
|
||||
local dbh = env:connect(array[2]);
|
||||
res, serr = dbh:execute(sql);
|
||||
dbh:close();
|
||||
env:close();
|
||||
local Database = require "resources.functions.database"
|
||||
local dbh = Database.new('system', 'base64');
|
||||
dbh:query(sql);
|
||||
dbh:release();
|
||||
else
|
||||
dbh:query(sql);
|
||||
end
|
||||
|
||||
@@ -63,6 +63,12 @@
|
||||
--include languages file
|
||||
local Text = require "resources.functions.text"
|
||||
local text = Text.new("app.voicemail.app_languages")
|
||||
local dbh = dbh
|
||||
|
||||
--connect using other backend if needed
|
||||
if storage_type == "base64" then
|
||||
dbh = Database.new('system', 'base64/read')
|
||||
end
|
||||
|
||||
--get voicemail message details
|
||||
sql = [[SELECT * FROM v_voicemail_messages
|
||||
@@ -82,21 +88,25 @@
|
||||
--message_priority = row["message_priority"];
|
||||
--get the recordings from the database
|
||||
if (storage_type == "base64") then
|
||||
--add functions
|
||||
require "resources.functions.base64";
|
||||
|
||||
--set the voicemail message path
|
||||
message_location = voicemail_dir.."/"..id.."/msg_"..uuid.."."..vm_message_ext;
|
||||
|
||||
--save the recording to the file system
|
||||
if (string.len(row["message_base64"]) > 32) then
|
||||
local f = io.open(message_location, "w");
|
||||
f:write(base64.decode(row["message_base64"]));
|
||||
f:close();
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--write decoded string to file
|
||||
file.write_base64(message_location, row["message_base64"]);
|
||||
end
|
||||
end
|
||||
end);
|
||||
|
||||
--close temporary connection
|
||||
if storage_type == "base64" then
|
||||
dbh:release()
|
||||
end
|
||||
|
||||
--format the message length and date
|
||||
message_length_formatted = format_seconds(message_length);
|
||||
if (debug["info"]) then
|
||||
|
||||
Reference in New Issue
Block a user