Add base64 decode to the IVR Menu.
This commit is contained in:
@@ -46,6 +46,31 @@
|
|||||||
ivr_menu_uuid = session:getVariable("ivr_menu_uuid");
|
ivr_menu_uuid = session:getVariable("ivr_menu_uuid");
|
||||||
caller_id_name = session:getVariable("caller_id_name");
|
caller_id_name = session:getVariable("caller_id_name");
|
||||||
caller_id_number = session:getVariable("caller_id_number");
|
caller_id_number = session:getVariable("caller_id_number");
|
||||||
|
domain_uuid = session:getVariable("domain_uuid");
|
||||||
|
|
||||||
|
--settings
|
||||||
|
dofile(scripts_dir.."/resources/functions/settings.lua");
|
||||||
|
settings = settings(domain_uuid);
|
||||||
|
if (settings['recordings']['storage_type'] ~= nil) then
|
||||||
|
if (settings['recordings']['storage_type']['text'] ~= nil) then
|
||||||
|
storage_type = settings['recordings']['storage_type']['text'];
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (settings['recordings']['storage_path'] ~= nil) then
|
||||||
|
if (settings['recordings']['storage_path']['text'] ~= nil) then
|
||||||
|
storage_path = settings['recordings']['storage_path']['text'];
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (settings['server']['temp'] ~= nil) then
|
||||||
|
if (settings['server']['temp']['dir'] ~= nil) then
|
||||||
|
temp_dir = settings['server']['temp']['dir'];
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--set the recordings directory
|
||||||
|
if (domain_count > 1) then
|
||||||
|
recordings_dir = recordings_dir .. "/"..domain_name;
|
||||||
|
end
|
||||||
|
|
||||||
--set default variable(s)
|
--set default variable(s)
|
||||||
tries = 0;
|
tries = 0;
|
||||||
@@ -72,6 +97,7 @@
|
|||||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
status = dbh:query(sql, function(row)
|
status = dbh:query(sql, function(row)
|
||||||
|
domain_uuid = row["domain_uuid"];
|
||||||
ivr_menu_name = row["ivr_menu_name"];
|
ivr_menu_name = row["ivr_menu_name"];
|
||||||
--ivr_menu_extension = row["ivr_menu_extension"];
|
--ivr_menu_extension = row["ivr_menu_extension"];
|
||||||
ivr_menu_greet_long = row["ivr_menu_greet_long"];
|
ivr_menu_greet_long = row["ivr_menu_greet_long"];
|
||||||
@@ -169,6 +195,58 @@
|
|||||||
end
|
end
|
||||||
ivr_menu_invalid_entry = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..ivr_menu_invalid_sound;
|
ivr_menu_invalid_entry = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..ivr_menu_invalid_sound;
|
||||||
|
|
||||||
|
--get the recordings from the database
|
||||||
|
if (storage_type == "base64") then
|
||||||
|
if (string.len(ivr_menu_greet_long) > 1) then
|
||||||
|
sql = [[SELECT * FROM v_recordings
|
||||||
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
|
AND recording_filename = ']].. ivr_menu_greet_long.. [[' ]];
|
||||||
|
--if (debug["sql"]) then
|
||||||
|
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
|
||||||
|
--end
|
||||||
|
status = dbh:query(sql, function(row)
|
||||||
|
--add functions
|
||||||
|
dofile(scripts_dir.."/resources/functions/base64.lua");
|
||||||
|
--get the base64
|
||||||
|
recording_base64 = row["recording_base64"];
|
||||||
|
|
||||||
|
--add the path to filename
|
||||||
|
ivr_menu_greet_long = recordings_dir.."/"..ivr_menu_greet_long;
|
||||||
|
|
||||||
|
--save the recording to the file system
|
||||||
|
if (string.len(recording_base64) > 32) then
|
||||||
|
local file = io.open(ivr_menu_greet_long, "w");
|
||||||
|
file:write(base64.decode(recording_base64));
|
||||||
|
file:close();
|
||||||
|
end
|
||||||
|
end);
|
||||||
|
end
|
||||||
|
if (string.len(ivr_menu_greet_short) > 1) then
|
||||||
|
sql = [[SELECT * FROM v_recordings
|
||||||
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
|
AND recording_filename = ']].. ivr_menu_greet_short.. [[' ]];
|
||||||
|
--if (debug["sql"]) then
|
||||||
|
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
|
||||||
|
--end
|
||||||
|
status = dbh:query(sql, function(row)
|
||||||
|
--add functions
|
||||||
|
dofile(scripts_dir.."/resources/functions/base64.lua");
|
||||||
|
--get the base64
|
||||||
|
recording_base64 = row["recording_base64"];
|
||||||
|
|
||||||
|
--add the path to filename
|
||||||
|
ivr_menu_greet_short = recordings_dir.."/"..ivr_menu_greet_short;
|
||||||
|
|
||||||
|
--save the recording to the file system
|
||||||
|
if (string.len(recording_base64) > 32) then
|
||||||
|
local file = io.open(ivr_menu_greet_short, "w");
|
||||||
|
file:write(base64.decode(recording_base64));
|
||||||
|
file:close();
|
||||||
|
end
|
||||||
|
end);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--define the ivr menu
|
--define the ivr menu
|
||||||
function menu()
|
function menu()
|
||||||
--increment the tries
|
--increment the tries
|
||||||
|
|||||||
@@ -126,7 +126,7 @@
|
|||||||
local f = io.open(recordings_dir .."/".. recording_name, "rb");
|
local f = io.open(recordings_dir .."/".. recording_name, "rb");
|
||||||
local file_content = f:read("*all");
|
local file_content = f:read("*all");
|
||||||
f:close();
|
f:close();
|
||||||
recording_base64 = base64.enc(file_content);
|
recording_base64 = base64.encode(file_content);
|
||||||
|
|
||||||
--delete the previous recording
|
--delete the previous recording
|
||||||
sql = "delete from v_recordings ";
|
sql = "delete from v_recordings ";
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ base64={}
|
|||||||
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
||||||
|
|
||||||
-- encoding
|
-- encoding
|
||||||
function base64.enc(data)
|
function base64.encode(data)
|
||||||
return ((data:gsub('.', function(x)
|
return ((data:gsub('.', function(x)
|
||||||
local r,b='',x:byte()
|
local r,b='',x:byte()
|
||||||
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
|
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
|
||||||
@@ -20,7 +20,7 @@ function base64.enc(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- decoding
|
-- decoding
|
||||||
function base64.dec(data)
|
function base64.decode(data)
|
||||||
data = string.gsub(data, '[^'..b..'=]', '')
|
data = string.gsub(data, '[^'..b..'=]', '')
|
||||||
return (data:gsub('.', function(x)
|
return (data:gsub('.', function(x)
|
||||||
if (x == '=') then return '' end
|
if (x == '=') then return '' end
|
||||||
|
|||||||
Reference in New Issue
Block a user