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:
parent
7fae6c9d4e
commit
28d3ebb51f
|
|
@ -246,6 +246,9 @@ if (!class_exists('scripts')) {
|
|||
$tmp .= " database.switch = \"\";\n";
|
||||
}
|
||||
$tmp .= "\n";
|
||||
$tmp .= " database.backend = {}\n";
|
||||
$tmp .= " database.backend.base64 = 'luasql'\n";
|
||||
$tmp .= "\n";
|
||||
}
|
||||
$tmp .= "--set defaults\n";
|
||||
$tmp .= " expire = {}\n";
|
||||
|
|
|
|||
|
|
@ -303,14 +303,11 @@
|
|||
if (fax_success ~= nil) then
|
||||
if (fax_success =="1") then
|
||||
if (storage_type == "base64") then
|
||||
--include the base64 function
|
||||
require "resources.functions.base64";
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--base64 encode the file
|
||||
local f = io.open(fax_file, "rb");
|
||||
local file_content = f:read("*all");
|
||||
f:close();
|
||||
fax_base64 = base64.encode(file_content);
|
||||
--read file content as base64 string
|
||||
fax_base64 = assert(file.read_base64(fax_file));
|
||||
end
|
||||
|
||||
local sql = {}
|
||||
|
|
@ -363,13 +360,10 @@
|
|||
freeswitch.consoleLog("notice", "[fax] 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
|
||||
result = dbh:query(sql);
|
||||
end
|
||||
|
|
|
|||
|
|
@ -246,18 +246,14 @@
|
|||
if fax_success == "1" then
|
||||
|
||||
if storage_type == "base64" then
|
||||
--include the base64 function
|
||||
require "resources.functions.base64";
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--base64 encode the file
|
||||
local f = io.open(fax_file, "rb");
|
||||
if not f then
|
||||
--read file content as base64 string
|
||||
fax_base64 = file.read_base64(fax_file);
|
||||
if not fax_base64 then
|
||||
log.waitng("Can not find file %s", fax_file)
|
||||
storage_type = nil
|
||||
else
|
||||
local file_content = f:read("*all");
|
||||
f:close()
|
||||
fax_base64 = base64.encode(file_content)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -300,13 +296,10 @@
|
|||
end
|
||||
|
||||
if storage_type == "base64" then
|
||||
local db_type, db_cnn = split_first(database["system"], "://", true)
|
||||
local luasql = require ("luasql." .. db_type);
|
||||
local env = assert (luasql[db_type]());
|
||||
local dbh = env:connect(db_cnn);
|
||||
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
|
||||
result = dbh:query(sql)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@
|
|||
--get the ivr name
|
||||
ivr_menu_uuid = params:getHeader("Menu-Name");
|
||||
|
||||
local log = require "resources.functions.log".ivr_menu
|
||||
|
||||
--get the cache
|
||||
if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
|
||||
XML_STRING = trim(api:execute("memcache", "get configuration:ivr.conf:" .. ivr_menu_uuid));
|
||||
|
|
@ -36,9 +38,11 @@
|
|||
|
||||
--set the cache
|
||||
if (XML_STRING == "-ERR NOT FOUND" or XML_STRING == "-ERR CONNECTION FAILURE") then
|
||||
local Database = require "resources.functions.database"
|
||||
local Settings = require "resources.functions.lazy_settings"
|
||||
|
||||
--connect to the database
|
||||
require "resources.functions.database_handle";
|
||||
dbh = database_handle('system');
|
||||
local dbh = Database.new('system');
|
||||
|
||||
--exits the script if we didn't connect properly
|
||||
assert(dbh:connected());
|
||||
|
|
@ -77,112 +81,73 @@
|
|||
ivr_menu_description = row["ivr_menu_description"];
|
||||
end);
|
||||
|
||||
local settings = Settings.new(dbh, domain_name, domain_uuid)
|
||||
local storage_type = settings:get('recordings', 'storage_type', 'text')
|
||||
|
||||
--get the recordings from the database
|
||||
ivr_menu_greet_long_is_base64 = false;
|
||||
ivr_menu_greet_short_is_base64 = false;
|
||||
ivr_menu_invalid_sound_is_base64 = false;
|
||||
ivr_menu_exit_sound_is_base64 = false;
|
||||
if (settings.recordings.storage_type == "base64") then
|
||||
if (storage_type == "base64") then
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--connect to db
|
||||
local dbh = Database.new('system', 'base64/read');
|
||||
|
||||
--base path for recordings
|
||||
local base_path = recordings_dir.."/"..domain_name
|
||||
|
||||
--function to get recording to local fs
|
||||
local function load_record(name)
|
||||
local path, is_base64 = base_path .. "/" .. name
|
||||
|
||||
if not file_exists(path) then
|
||||
local sql = "SELECT recording_base64 FROM v_recordings " ..
|
||||
"WHERE domain_uuid = '" .. domain_uuid .. "' " ..
|
||||
"AND recording_filename = '" .. name .. "' "
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
|
||||
end
|
||||
|
||||
dbh:query(sql, function(row)
|
||||
--get full path to recording
|
||||
is_base64, name = true, path
|
||||
|
||||
--save the recording to the file system
|
||||
if #row.recording_base64 > 32 then
|
||||
file.write_base64(path, row.recording_base64);
|
||||
end
|
||||
end);
|
||||
else
|
||||
name = path
|
||||
end
|
||||
return name, is_base64
|
||||
end
|
||||
|
||||
--greet long
|
||||
if (string.len(ivr_menu_greet_long) > 1) then
|
||||
if (not file_exists(recordings_dir.."/"..domain_name.."/"..ivr_menu_greet_long)) then
|
||||
sql = [[SELECT recording_base64 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
|
||||
require "resources.functions.base64";
|
||||
--add the path to filename
|
||||
ivr_menu_greet_long = recordings_dir.."/"..domain_name.."/"..ivr_menu_greet_long;
|
||||
ivr_menu_greet_long_is_base64 = true;
|
||||
--save the recording to the file system
|
||||
if (string.len(row["recording_base64"]) > 32) then
|
||||
local file = io.open(ivr_menu_greet_long, "w");
|
||||
file:write(base64.decode(row["recording_base64"]));
|
||||
file:write(row["recording_base64"]);
|
||||
file:close();
|
||||
end
|
||||
end);
|
||||
end
|
||||
end
|
||||
--greet short
|
||||
if (string.len(ivr_menu_greet_short) > 1) then
|
||||
if (not file_exists(recordings_dir.."/"..domain_name.."/"..ivr_menu_greet_short)) 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
|
||||
require "resources.functions.base64";
|
||||
--add the path to filename
|
||||
ivr_menu_greet_short = recordings_dir.."/"..domain_name.."/"..ivr_menu_greet_short;
|
||||
ivr_menu_greet_short_is_base64 = true;
|
||||
--save the recording to the file system
|
||||
if (string.len(row["recording_base64"]) > 32) then
|
||||
local file = io.open(ivr_menu_greet_short, "w");
|
||||
file:write(base64.decode(row["recording_base64"]));
|
||||
file:close();
|
||||
end
|
||||
end);
|
||||
end
|
||||
end
|
||||
--invalid sound
|
||||
if (string.len(ivr_menu_invalid_sound) > 1) then
|
||||
if (not file_exists(recordings_dir.."/"..domain_name.."/"..ivr_menu_invalid_sound)) then
|
||||
sql = [[SELECT * FROM v_recordings
|
||||
WHERE domain_uuid = ']]..domain_uuid..[['
|
||||
AND recording_filename = ']]..ivr_menu_invalid_sound..[[' ]];
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
|
||||
end
|
||||
status = dbh:query(sql, function(row)
|
||||
--add functions
|
||||
require "resources.functions.base64";
|
||||
--add the path to filename
|
||||
ivr_menu_invalid_sound = recordings_dir..domain_name.."/".."/"..ivr_menu_invalid_sound;
|
||||
ivr_menu_invalid_sound_is_base64 = true;
|
||||
--save the recording to the file system
|
||||
if (string.len(row["recording_base64"]) > 32) then
|
||||
local file = io.open(ivr_menu_invalid_sound, "w");
|
||||
file:write(base64.decode(row["recording_base64"]));
|
||||
file:close();
|
||||
end
|
||||
end);
|
||||
end
|
||||
end
|
||||
--exit sound
|
||||
if (string.len(ivr_menu_exit_sound) > 1) then
|
||||
if (not file_exists(recordings_dir.."/"..domain_name.."/"..ivr_menu_exit_sound)) then
|
||||
sql = [[SELECT * FROM v_recordings
|
||||
WHERE domain_uuid = ']]..domain_uuid..[['
|
||||
AND recording_filename = ']]..ivr_menu_exit_sound..[[' ]];
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
|
||||
end
|
||||
status = dbh:query(sql, function(row)
|
||||
--add functions
|
||||
require "resources.functions.base64";
|
||||
--add the path to filename
|
||||
ivr_menu_exit_sound = recordings_dir.."/"..domain_name.."/"..ivr_menu_exit_sound;
|
||||
ivr_menu_exit_sound_is_base64 = true;
|
||||
--save the recording to the file system
|
||||
if (string.len(row["recording_base64"]) > 32) then
|
||||
local file = io.open(ivr_menu_exit_sound, "w");
|
||||
file:write(base64.decode(row["recording_base64"]));
|
||||
file:close();
|
||||
end
|
||||
end);
|
||||
end
|
||||
if #ivr_menu_greet_long > 1 then
|
||||
ivr_menu_greet_long, ivr_menu_greet_long_is_base64 = load_record(ivr_menu_greet_long)
|
||||
end
|
||||
|
||||
elseif (settings.recordings.storage_type == "http_cache") then
|
||||
--greet short
|
||||
if #ivr_menu_greet_short > 1 then
|
||||
ivr_menu_greet_short, ivr_menu_greet_short_is_base64 = load_record(ivr_menu_greet_short)
|
||||
end
|
||||
|
||||
--invalid sound
|
||||
if #ivr_menu_invalid_sound > 1 then
|
||||
ivr_menu_invalid_sound, ivr_menu_invalid_sound_is_base64 = load_record(ivr_menu_invalid_sound)
|
||||
end
|
||||
|
||||
--exit sound
|
||||
if #ivr_menu_exit_sound > 1 then
|
||||
ivr_menu_exit_sound, ivr_menu_exit_sound_is_base64 = load_record(ivr_menu_exit_sound)
|
||||
end
|
||||
|
||||
dbh:release()
|
||||
elseif (storage_type == "http_cache") then
|
||||
--add the path to file name
|
||||
ivr_menu_greet_long = storage_path.."/"..ivr_menu_greet_long;
|
||||
ivr_menu_greet_short = storage_path.."/"..ivr_menu_greet_short;
|
||||
|
|
@ -273,7 +238,7 @@
|
|||
ivr_menu_option_action = r.ivr_menu_option_action
|
||||
ivr_menu_option_param = r.ivr_menu_option_param
|
||||
ivr_menu_option_description = r.ivr_menu_option_description
|
||||
table.insert(xml, [[<entry action="]]..ivr_menu_option_action..[[" digits="]]..ivr_menu_option_digits..[[" param="]]..ivr_menu_option_param..[[" description="]]..ivr_menu_option_description..[["/>]]);
|
||||
table.insert(xml, [[ <entry action="]]..ivr_menu_option_action..[[" digits="]]..ivr_menu_option_digits..[[" param="]]..ivr_menu_option_param..[[" description="]]..ivr_menu_option_description..[["/>]]);
|
||||
end);
|
||||
|
||||
--close the extension tag if it was left open
|
||||
|
|
|
|||
|
|
@ -226,6 +226,9 @@
|
|||
if (row.first_name) then
|
||||
--play the recorded name
|
||||
if (storage_type == "base64") then
|
||||
local Database = require "resources.functions.database";
|
||||
local dbh = Database.new('system', 'base64/read')
|
||||
|
||||
sql = [[SELECT * FROM v_voicemails
|
||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||
AND voicemail_id = ']].. row.extension.. [[' ]];
|
||||
|
|
@ -233,17 +236,16 @@
|
|||
freeswitch.consoleLog("notice", "[directory] SQL: " .. sql .. "\n");
|
||||
end
|
||||
status = dbh:query(sql, function(field)
|
||||
--add functions
|
||||
require "resources.functions.base64";
|
||||
|
||||
--set the voicemail message path
|
||||
file_location = voicemail_dir.."/"..row.extension.."/recorded_name.wav";
|
||||
|
||||
--save the recording to the file system
|
||||
if (string.len(field["voicemail_name_base64"]) > 32) then
|
||||
local file = io.open(file_location, "w");
|
||||
file:write(base64.decode(field["voicemail_name_base64"]));
|
||||
file:close();
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--write decoded string to file
|
||||
file.write_base64(file_location, field["voicemail_name_base64"]);
|
||||
end
|
||||
|
||||
--play the recorded name
|
||||
|
|
@ -266,6 +268,7 @@
|
|||
end
|
||||
end
|
||||
end);
|
||||
dbh:release()
|
||||
elseif (storage_type == "http_cache") then
|
||||
file_location = storage_path.."/"..row.extension.."/recorded_name.wav";
|
||||
if (file_exists(file_location)) then
|
||||
|
|
|
|||
|
|
@ -293,14 +293,11 @@
|
|||
end
|
||||
|
||||
if (storage_type == "base64") then
|
||||
--include the base64 function
|
||||
require "resources.functions.base64";
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--base64 encode the file
|
||||
local f = io.open(fax_file, "rb");
|
||||
local file_content = f:read("*all");
|
||||
f:close();
|
||||
fax_base64 = base64.encode(file_content);
|
||||
--read file content as base64 string
|
||||
fax_base64 = assert(file.read_base64(fax_file));
|
||||
end
|
||||
|
||||
local sql = {}
|
||||
|
|
@ -352,13 +349,10 @@
|
|||
freeswitch.consoleLog("notice", "[FAX] 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
|
||||
result = dbh:query(sql);
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,9 +34,8 @@
|
|||
--include config.lua
|
||||
require "resources.functions.config";
|
||||
|
||||
--connect to the database
|
||||
require "resources.functions.database_handle";
|
||||
dbh = database_handle('system');
|
||||
--include Database class
|
||||
local Database = require "resources.functions.database";
|
||||
|
||||
--get logger
|
||||
local log = require "resources.functions.log".ivr_menu
|
||||
|
|
@ -55,6 +54,9 @@
|
|||
|
||||
local recordings_dir = recordings_dir .. "/" .. domain_name
|
||||
|
||||
--connect to the database
|
||||
dbh = Database.new('system');
|
||||
|
||||
--settings
|
||||
require "resources.functions.settings";
|
||||
settings = settings(domain_uuid);
|
||||
|
|
@ -127,6 +129,9 @@
|
|||
ivr_menu_cid_prefix = row["ivr_menu_cid_prefix"];
|
||||
end);
|
||||
|
||||
--disconnect from db
|
||||
dbh:release()
|
||||
|
||||
--set the caller id name
|
||||
if caller_id_name and #caller_id_name > 0 and ivr_menu_cid_prefix and #ivr_menu_cid_prefix > 0 then
|
||||
caller_id_name = ivr_menu_cid_prefix .. "#" .. caller_id_name;
|
||||
|
|
@ -164,11 +169,12 @@
|
|||
ivr_menu_invalid_sound_is_base64 = false;
|
||||
ivr_menu_exit_sound_is_base64 = false;
|
||||
if (storage_type == "base64") then
|
||||
|
||||
--add functions
|
||||
require "resources.functions.base64";
|
||||
require "resources.functions.mkdir";
|
||||
|
||||
--connect to the database
|
||||
local dbh = Database.new('system', 'base64/read')
|
||||
|
||||
--make sure the recordings directory exists
|
||||
mkdir(recordings_dir);
|
||||
|
||||
|
|
@ -189,13 +195,16 @@
|
|||
local is_base64
|
||||
dbh:query(sql, function(row)
|
||||
if #row.recording_base64 > 32 then
|
||||
local file, err = io.open(full_path, "w");
|
||||
if not file then
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--write decoded string to file
|
||||
local ok, err = file.write_base64(full_path, row.recording_base64);
|
||||
if not ok then
|
||||
log.err("can not create file: "..full_path.."; Error - " .. tostring(err));
|
||||
return
|
||||
end
|
||||
file:write(base64.decode(row.recording_base64));
|
||||
file:close();
|
||||
|
||||
is_base64 = true;
|
||||
end
|
||||
end);
|
||||
|
|
@ -224,6 +233,8 @@
|
|||
ivr_menu_exit_sound, ivr_menu_exit_sound_is_base64 = load_file(exit_sound_file_name)
|
||||
end
|
||||
|
||||
dbh:release()
|
||||
|
||||
elseif (storage_type == "http_cache") then
|
||||
--add the path to file name
|
||||
ivr_menu_greet_long = storage_path.."/"..ivr_menu_greet_long;
|
||||
|
|
@ -317,6 +328,10 @@
|
|||
log.notice("SQL: " .. sql);
|
||||
end
|
||||
|
||||
--connect to the database
|
||||
local dbh = Database.new('system')
|
||||
|
||||
--select actions to execute
|
||||
local actions = {}
|
||||
dbh:query(sql, function(row)
|
||||
-- declare vars
|
||||
|
|
@ -371,6 +386,7 @@
|
|||
-- we have unsupported IVR action
|
||||
log.warning("invalid action in ivr: " .. row.ivr_menu_option_action);
|
||||
end); --end results
|
||||
dbh:release()
|
||||
|
||||
--execute
|
||||
if #actions > 0 then
|
||||
|
|
|
|||
|
|
@ -126,8 +126,8 @@
|
|||
|
||||
--begin recording
|
||||
if (storage_type == "base64") then
|
||||
--include the base64 function
|
||||
require "resources.functions.base64";
|
||||
--include the file io
|
||||
local file = require "resources.functions.file"
|
||||
|
||||
--make the directory
|
||||
mkdir(recordings_dir);
|
||||
|
|
@ -139,11 +139,8 @@
|
|||
--show the storage type
|
||||
freeswitch.consoleLog("notice", "[recordings] ".. storage_type .. "\n");
|
||||
|
||||
--base64 encode the file
|
||||
local f = io.open(recordings_dir .."/".. recording_name, "rb");
|
||||
local file_content = f:read("*all");
|
||||
f:close();
|
||||
recording_base64 = base64.encode(file_content);
|
||||
--read file content as base64 string
|
||||
recording_base64 = assert(file.read_base64(recordings_dir .. "/" .. recording_name));
|
||||
|
||||
elseif (storage_type == "http_cache") then
|
||||
freeswitch.consoleLog("notice", "[recordings] ".. storage_type .. " ".. storage_path .."\n");
|
||||
|
|
@ -189,13 +186,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
|
||||
|
|
|
|||
|
|
@ -1,70 +1,50 @@
|
|||
--get the argv values
|
||||
script_name = argv[0];
|
||||
file_name = table.concat(argv, " ");
|
||||
local script_name = argv[0];
|
||||
local file_name = table.concat(argv, " ");
|
||||
freeswitch.consoleLog("notice", "[streamfile] file_name: " .. file_name .. "\n");
|
||||
|
||||
--include config.lua
|
||||
require "resources.functions.config";
|
||||
|
||||
--connect to the database
|
||||
require "resources.functions.database_handle";
|
||||
dbh = database_handle('system');
|
||||
--load libraries
|
||||
local Database = require "resources.functions.database";
|
||||
local Settings = require "resources.functions.lazy_settings";
|
||||
local file = require "resources.functions.file";
|
||||
local log = require "resources.functions.log".streamfile;
|
||||
|
||||
--get the variables
|
||||
domain_name = session:getVariable("domain_name");
|
||||
domain_uuid = session:getVariable("domain_uuid");
|
||||
local domain_name = session:getVariable("domain_name");
|
||||
local domain_uuid = session:getVariable("domain_uuid");
|
||||
|
||||
--get the sounds dir, language, dialect and voice
|
||||
sounds_dir = session:getVariable("sounds_dir");
|
||||
default_language = session:getVariable("default_language");
|
||||
default_dialect = session:getVariable("default_dialect");
|
||||
default_voice = session:getVariable("default_voice");
|
||||
if (not default_language) then default_language = 'en'; end
|
||||
if (not default_dialect) then default_dialect = 'us'; end
|
||||
if (not default_voice) then default_voice = 'callie'; end
|
||||
|
||||
--settings
|
||||
require "resources.functions.settings";
|
||||
settings = settings(domain_uuid);
|
||||
storage_type = "";
|
||||
storage_path = "";
|
||||
if (settings['recordings'] ~= nil) then
|
||||
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'];
|
||||
storage_path = storage_path:gsub("${domain_name}", domain_name);
|
||||
storage_path = storage_path:gsub("${voicemail_id}", voicemail_id);
|
||||
storage_path = storage_path:gsub("${voicemail_dir}", voicemail_dir);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (not temp_dir) or (#temp_dir == 0) then
|
||||
if (settings['server'] ~= nil) then
|
||||
if (settings['server']['temp'] ~= nil) then
|
||||
if (settings['server']['temp']['dir'] ~= nil) then
|
||||
temp_dir = settings['server']['temp']['dir'];
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local sounds_dir = session:getVariable("sounds_dir");
|
||||
local default_language = session:getVariable("default_language") or 'en';
|
||||
local default_dialect = session:getVariable("default_dialect") or 'us';
|
||||
local default_voice = session:getVariable("default_voice") or 'callie';
|
||||
|
||||
--set the recordings directory
|
||||
recordings_dir = recordings_dir .. "/"..domain_name;
|
||||
local recordings_dir = recordings_dir .. "/" .. domain_name;
|
||||
|
||||
--check if a file exists
|
||||
require "resources.functions.file_exists";
|
||||
--parse file name
|
||||
local file_name_only = file_name:match("([^/]+)$");
|
||||
|
||||
--settings
|
||||
local dbh = Database.new('system');
|
||||
local settings = Settings.new(dbh, domain_name, domain_uuid);
|
||||
local storage_type = settings:get('recordings', 'storage_type', 'text') or '';
|
||||
|
||||
if (not temp_dir) or (#temp_dir == 0) then
|
||||
temp_dir = settings:get('server', 'temp', 'dir') or '/tmp';
|
||||
end
|
||||
|
||||
dbh:release()
|
||||
|
||||
--define the on_dtmf call back function
|
||||
-- luacheck: globals on_dtmf, ignore s arg
|
||||
function on_dtmf(s, type, obj, arg)
|
||||
if (type == "dtmf") then
|
||||
session:setVariable("dtmf_digits", obj['digit']);
|
||||
freeswitch.console_log("info", "[streamfile] dtmf digit: " .. obj['digit'] .. ", duration: " .. obj['duration'] .. "\n");
|
||||
log.info("dtmf digit: " .. obj['digit'] .. ", duration: " .. obj['duration']);
|
||||
if (obj['digit'] == "*") then
|
||||
return("false"); --return to previous
|
||||
elseif (obj['digit'] == "0") then
|
||||
|
|
@ -87,50 +67,43 @@
|
|||
end
|
||||
end
|
||||
|
||||
--parse file name
|
||||
file_name_only = file_name:match("([^/]+)$");
|
||||
|
||||
--if base64, get from db, create temp file
|
||||
if (storage_type == "base64") then
|
||||
if (not file_exists(recordings_dir.."/"..file_name_only)) then
|
||||
sql = [[SELECT * FROM v_recordings
|
||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||
AND recording_filename = ']].. file_name_only.. [[' ]];
|
||||
local full_path = recordings_dir .. "/" .. file_name_only
|
||||
if not file.exists(full_path) then
|
||||
local sql = "SELECT recording_base64 FROM v_recordings "
|
||||
.. "WHERE domain_uuid = '" .. domain_uuid .."'"
|
||||
.. "AND recording_filename = '".. file_name_only.. "' ";
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
|
||||
log.notice("SQL: " .. sql);
|
||||
end
|
||||
status = dbh:query(sql, function(row)
|
||||
--add functions
|
||||
require "resources.functions.base64";
|
||||
--add the path to filename
|
||||
file_name = recordings_dir.."/"..file_name_only;
|
||||
--save the recording to the file system
|
||||
if (string.len(row["recording_base64"]) > 32) then
|
||||
local file = io.open(file_name, "w");
|
||||
file:write(base64.decode(row["recording_base64"]));
|
||||
file:close();
|
||||
|
||||
local dbh = Database.new('system', 'base64/read');
|
||||
local recording_base64 = dbh:first_value(sql);
|
||||
dbh:release();
|
||||
|
||||
if recording_base64 and #recording_base64 > 32 then
|
||||
file_name = full_path;
|
||||
file.write_base64(file_name, recording_base64);
|
||||
end
|
||||
end);
|
||||
else
|
||||
file_name = recordings_dir.."/"..file_name_only;
|
||||
file_name = full_path;
|
||||
end
|
||||
end
|
||||
|
||||
--adjust file path
|
||||
if (not file_exists(file_name)) then
|
||||
if (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name_only)) then
|
||||
file_name = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name_only;
|
||||
elseif (file_exists(recordings_dir.."/"..file_name_only)) then
|
||||
file_name = recordings_dir.."/"..file_name_only;
|
||||
end
|
||||
if not file.exists(file_name) then
|
||||
file_name = file.exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name_only)
|
||||
or file.exists(recordings_dir.."/"..file_name_only)
|
||||
or file_name
|
||||
end
|
||||
|
||||
--stream file if exists
|
||||
if (session:ready()) then
|
||||
session:answer();
|
||||
slept = session:getVariable("slept");
|
||||
local slept = session:getVariable("slept");
|
||||
if (slept == nil or slept == "false") then
|
||||
freeswitch.consoleLog("notice", "[ivr_menu] sleeping (1s)\n");
|
||||
log.notice("sleeping (1s)");
|
||||
session:sleep(1000);
|
||||
if (slept == "false") then
|
||||
session:setVariable("slept", "true");
|
||||
|
|
@ -142,8 +115,8 @@
|
|||
end
|
||||
|
||||
--if base64, remove temp file (increases responsiveness when files remain local)
|
||||
if (storage_type == "base64") then
|
||||
if (file_exists(file_name)) then
|
||||
--os.remove(file_name);
|
||||
end
|
||||
end
|
||||
-- if (storage_type == "base64") then
|
||||
-- if (file.exists(file_name)) then
|
||||
-- file.remove(file_name);
|
||||
-- end
|
||||
-- end
|
||||
|
|
|
|||
Loading…
Reference in New Issue