Change. Use only require to load function.

Fix. Remove multiple definition of same function.
This commit is contained in:
Alexey Melnichuk
2015-08-10 12:43:06 +04:00
parent 565395c44f
commit 703b61636a
64 changed files with 207 additions and 400 deletions

View File

@@ -6,7 +6,7 @@
debug["sql"] = true; debug["sql"] = true;
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--set the api --set the api

View File

@@ -57,7 +57,7 @@ This method causes the script to get its manadatory arguments directly from the
local sql = nil local sql = nil
--define the functions --define the functions
dofile(scripts_dir.."/resources/functions/trim.lua"); require "resources.functions.trim";
--define the logger function --define the logger function
local function logger(level, log, data) local function logger(level, log, data)
@@ -88,7 +88,7 @@ This method causes the script to get its manadatory arguments directly from the
--if not cached then get the information from the database --if not cached then get the information from the database
if (cache == "-ERR NOT FOUND") then if (cache == "-ERR NOT FOUND") then
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--log if not connect --log if not connect
@@ -123,7 +123,7 @@ This method causes the script to get its manadatory arguments directly from the
else else
--get from memcache --get from memcache
--add the function --add the function
dofile(scripts_dir.."/resources/functions/explode.lua"); require "resources.functions.explode";
--parse the cache --parse the cache
array = explode("&", cache); array = explode("&", cache);

View File

@@ -37,19 +37,19 @@
debug["sql"] = false; debug["sql"] = false;
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--prepare the api object --prepare the api object
api = freeswitch.API(); api = freeswitch.API();
--general functions --general functions
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
dofile(scripts_dir.."/resources/functions/trim.lua"); require "resources.functions.trim";
dofile(scripts_dir.."/resources/functions/file_exists.lua"); require "resources.functions.file_exists";
dofile(scripts_dir.."/resources/functions/explode.lua"); require "resources.functions.explode";
dofile(scripts_dir.."/resources/functions/format_seconds.lua"); require "resources.functions.format_seconds";
dofile(scripts_dir.."/resources/functions/mkdir.lua"); require "resources.functions.mkdir";
--get the session variables --get the session variables
uuid = session:getVariable("uuid"); uuid = session:getVariable("uuid");
@@ -153,7 +153,7 @@
end_epoch = os.time(); end_epoch = os.time();
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--get the conference sessions --get the conference sessions

View File

@@ -2,9 +2,9 @@
require "resources.functions.config"; require "resources.functions.config";
--additional includes --additional includes
dofile(scripts_dir.."/resources/functions/file_exists.lua"); require "resources.functions.file_exists";
dofile(scripts_dir.."/resources/functions/trim.lua"); require "resources.functions.trim";
dofile(scripts_dir.."/resources/functions/mkdir.lua"); require "resources.functions.mkdir";
--get the argv values --get the argv values
script_name = argv[0]; script_name = argv[0];

View File

@@ -19,8 +19,8 @@
-- the Initial Developer. All Rights Reserved. -- the Initial Developer. All Rights Reserved.
--add functions --add functions
dofile(scripts_dir.."/resources/functions/file_exists.lua"); require "resources.functions.file_exists";
dofile(scripts_dir.."/resources/functions/trim.lua"); require "resources.functions.trim";
--set the api object --set the api object
api = freeswitch.API(); api = freeswitch.API();

View File

@@ -32,7 +32,7 @@
end end
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--get the cache --get the cache
@@ -64,7 +64,7 @@
else else
--add the function --add the function
dofile(scripts_dir.."/resources/functions/explode.lua"); require "resources.functions.explode";
--parse the cache --parse the cache
array = explode("&", cache); array = explode("&", cache);

View File

@@ -23,16 +23,8 @@
-- Mark J Crane <markjcrane@fusionpbx.com> -- Mark J Crane <markjcrane@fusionpbx.com>
-- Errol Samuels <voiptology@gmail.com> -- Errol Samuels <voiptology@gmail.com>
--define explode --define the explode function
function explode ( seperator, str ) require "resources.functions.explode";
local pos, arr = 0, {}
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
--usage --usage
--luarun app.lua event_notify internal reboot 1003@domain.fusionpbx.com yealink --luarun app.lua event_notify internal reboot 1003@domain.fusionpbx.com yealink

View File

@@ -28,9 +28,9 @@
debug["sql"] = false; debug["sql"] = false;
--include config.lua --include config.lua
dofile(scripts_dir .. "/resources/functions/config.lua"); require "resources.functions.config";
dofile(scripts_dir .. "/resources/functions/explode.lua"); require "resources.functions.explode";
dofile(scripts_dir .. "/resources/functions/trim.lua"); require "resources.functions.trim";
--check the missed calls --check the missed calls
function missed() function missed()

View File

@@ -29,28 +29,14 @@
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--define the explode function --define the explode function
function explode ( seperator, str ) require "resources.functions.explode";
local pos, arr = 0, {}
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
--array count --array count
function count(t) require "resources.functions.count";
c = 0;
for k,v in pairs(t) do
c = c+1;
end
return c;
end
-- set channel variables to lua variables -- set channel variables to lua variables
domain_uuid = env:getHeader("domain_uuid"); domain_uuid = env:getHeader("domain_uuid");
@@ -66,7 +52,7 @@
end end
--settings --settings
dofile(scripts_dir.."/resources/functions/settings.lua"); require "resources.functions.settings";
settings = settings(domain_uuid); settings = settings(domain_uuid);
storage_type = ""; storage_type = "";
storage_path = ""; storage_path = "";
@@ -311,7 +297,7 @@
if (fax_success =="1") then if (fax_success =="1") then
if (storage_type == "base64") then if (storage_type == "base64") then
--include the base64 function --include the base64 function
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--base64 encode the file --base64 encode the file
local f = io.open(fax_file, "rb"); local f = io.open(fax_file, "rb");

View File

@@ -25,10 +25,10 @@
debug["sql"] = false; debug["sql"] = false;
--general functions --general functions
dofile(scripts_dir .. "/resources/functions/config.lua"); require "resources.functions.config";
dofile(scripts_dir .. "/resources/functions/explode.lua"); require "resources.functions.explode";
dofile(scripts_dir.."/resources/functions/trim.lua"); require "resources.functions.trim";
--dofile(scripts_dir.."/resources/functions/file_exists.lua"); -- require "resources.functions.file_exists";
--create the api object --create the api object
api = freeswitch.API(); api = freeswitch.API();

View File

@@ -29,18 +29,14 @@
outbound_caller_id_number = session:getVariable("outbound_caller_id_number"); outbound_caller_id_number = session:getVariable("outbound_caller_id_number");
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--prepare the api object --prepare the api object
api = freeswitch.API(); api = freeswitch.API();
--add the trim function --define the trim function
function trim(s) require "resources.functions.trim";
if (s) then
return s:gsub("^%s+", ""):gsub("%s+$", "")
end
end
--get the cache --get the cache
cache = trim(api:execute("memcache", "get app:dialplan:outbound:is_local:" .. destination_number .. "@" .. domain_name)); cache = trim(api:execute("memcache", "get app:dialplan:outbound:is_local:" .. destination_number .. "@" .. domain_name));
@@ -84,7 +80,7 @@
end)); end));
else else
--add the function --add the function
dofile(scripts_dir.."/resources/functions/explode.lua"); require "resources.functions.explode";
--define the array/table and variables --define the array/table and variables
local var = {} local var = {}

View File

@@ -26,16 +26,8 @@
--set the debug options --set the debug options
debug["sql"] = false; debug["sql"] = false;
--define explode --define the explode function
function explode ( seperator, str ) require "resources.functions.explode";
local pos, arr = 0, {}
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
--set the defaults --set the defaults
max_tries = 3; max_tries = 3;
@@ -45,7 +37,7 @@
profile = "internal"; profile = "internal";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--answer --answer

View File

@@ -28,12 +28,12 @@
-- Luis Daniel Lucio Qurioz <dlucio@okay.com.mx> -- Luis Daniel Lucio Qurioz <dlucio@okay.com.mx>
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--include functions --include functions
dofile(scripts_dir.."/resources/functions/trim.lua"); require "resources.functions.trim";
dofile(scripts_dir.."/resources/functions/explode.lua"); require "resources.functions.explode";
--get the variables --get the variables
domain_name = session:getVariable("domain_name"); domain_name = session:getVariable("domain_name");

View File

@@ -29,21 +29,11 @@
max_tries = "3"; max_tries = "3";
digit_timeout = "5000"; digit_timeout = "5000";
--add a trim function --define the trim function
function trim (s) require "resources.functions.trim";
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
--add the explode function --define the explode function
function explode ( seperator, str ) require "resources.functions.explode";
local pos, arr = 0, {}
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
--get the argv values --get the argv values
script_name = argv[0]; script_name = argv[0];

View File

@@ -33,21 +33,11 @@
uuid = argv[1]; uuid = argv[1];
timeout = argv[2]; timeout = argv[2];
--add a trim function --define the trim function
function trim (s) require "resources.functions.trim";
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
--add the explode function --define the explode function
function explode ( seperator, str ) require "resources.functions.explode";
local pos, arr = 0, {}
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
--prepare the api --prepare the api
api = freeswitch.API(); api = freeswitch.API();

View File

@@ -26,7 +26,7 @@
--debug --debug
debug["toll_type"] = false debug["toll_type"] = false
dofile(scripts_dir.."/resources/functions/explode.lua"); require "resources.functions.explode";
--create the api object and get variables --create the api object and get variables
api = freeswitch.API() api = freeswitch.API()

View File

@@ -50,7 +50,7 @@
password_tries = 0; password_tries = 0;
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--set the api --set the api
@@ -123,7 +123,7 @@
end end
--settings --settings
dofile(scripts_dir.."/resources/functions/settings.lua"); require "resources.functions.settings";
settings = settings(domain_uuid); settings = settings(domain_uuid);
storage_type = ""; storage_type = "";
storage_path = ""; storage_path = "";
@@ -199,36 +199,36 @@
end end
--general functions --general functions
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
dofile(scripts_dir.."/resources/functions/trim.lua"); require "resources.functions.trim";
dofile(scripts_dir.."/resources/functions/file_exists.lua"); require "resources.functions.file_exists";
dofile(scripts_dir.."/resources/functions/explode.lua"); require "resources.functions.explode";
dofile(scripts_dir.."/resources/functions/format_seconds.lua"); require "resources.functions.format_seconds";
dofile(scripts_dir.."/resources/functions/mkdir.lua"); require "resources.functions.mkdir";
dofile(scripts_dir.."/resources/functions/copy.lua"); require "resources.functions.copy";
--voicemail functions --voicemail functions
dofile(scripts_dir.."/app/voicemail/resources/functions/on_dtmf.lua"); require "app.voicemail.resources.functions.on_dtmf";
dofile(scripts_dir.."/app/voicemail/resources/functions/get_voicemail_id.lua"); require "app.voicemail.resources.functions.get_voicemail_id";
dofile(scripts_dir.."/app/voicemail/resources/functions/check_password.lua"); require "app.voicemail.resources.functions.check_password";
dofile(scripts_dir.."/app/voicemail/resources/functions/change_password.lua"); require "app.voicemail.resources.functions.change_password";
dofile(scripts_dir.."/app/voicemail/resources/functions/macro.lua"); require "app.voicemail.resources.functions.macro";
dofile(scripts_dir.."/app/voicemail/resources/functions/play_greeting.lua"); require "app.voicemail.resources.functions.play_greeting";
dofile(scripts_dir.."/app/voicemail/resources/functions/record_message.lua"); require "app.voicemail.resources.functions.record_message";
dofile(scripts_dir.."/app/voicemail/resources/functions/record_menu.lua"); require "app.voicemail.resources.functions.record_menu";
dofile(scripts_dir.."/app/voicemail/resources/functions/forward_to_extension.lua"); require "app.voicemail.resources.functions.forward_to_extension";
dofile(scripts_dir.."/app/voicemail/resources/functions/main_menu.lua"); require "app.voicemail.resources.functions.main_menu";
dofile(scripts_dir.."/app/voicemail/resources/functions/listen_to_recording.lua"); require "app.voicemail.resources.functions.listen_to_recording";
dofile(scripts_dir.."/app/voicemail/resources/functions/message_waiting.lua"); require "app.voicemail.resources.functions.message_waiting";
dofile(scripts_dir.."/app/voicemail/resources/functions/send_email.lua"); require "app.voicemail.resources.functions.send_email";
dofile(scripts_dir.."/app/voicemail/resources/functions/delete_recording.lua"); require "app.voicemail.resources.functions.delete_recording";
dofile(scripts_dir.."/app/voicemail/resources/functions/message_saved.lua"); require "app.voicemail.resources.functions.message_saved";
dofile(scripts_dir.."/app/voicemail/resources/functions/return_call.lua"); require "app.voicemail.resources.functions.return_call";
dofile(scripts_dir.."/app/voicemail/resources/functions/menu_messages.lua"); require "app.voicemail.resources.functions.menu_messages";
dofile(scripts_dir.."/app/voicemail/resources/functions/advanced.lua"); require "app.voicemail.resources.functions.advanced";
dofile(scripts_dir.."/app/voicemail/resources/functions/record_greeting.lua"); require "app.voicemail.resources.functions.record_greeting";
dofile(scripts_dir.."/app/voicemail/resources/functions/choose_greeting.lua"); require "app.voicemail.resources.functions.choose_greeting";
dofile(scripts_dir.."/app/voicemail/resources/functions/record_name.lua"); require "app.voicemail.resources.functions.record_name";
--send a message waiting event --send a message waiting event
if (voicemail_action == "mwi") then if (voicemail_action == "mwi") then
@@ -317,7 +317,7 @@
freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n"); freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n");
--include the base64 function --include the base64 function
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--base64 encode the file --base64 encode the file
if (file_exists(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext)) then if (file_exists(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext)) then

View File

@@ -82,4 +82,3 @@
end end
end end
end end
--dofile(scripts_dir.."/app/voicemail/resources/functions/check_password.lua");

View File

@@ -96,7 +96,7 @@
end end
status = dbh:query(sql, function(row) status = dbh:query(sql, function(row)
--add functions --add functions
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--set the voicemail message path --set the voicemail message path
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext; greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;

View File

@@ -67,7 +67,7 @@
end end
status = dbh:query(sql, function(row) status = dbh:query(sql, function(row)
--add functions --add functions
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--set the voicemail message path --set the voicemail message path
message_location = voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext; message_location = voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext;

View File

@@ -52,7 +52,7 @@
end end
status = dbh:query(sql, function(row) status = dbh:query(sql, function(row)
--add functions --add functions
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--set the voicemail message path --set the voicemail message path
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext; greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;

View File

@@ -83,7 +83,7 @@
--if base64, encode file --if base64, encode file
if (storage_type == "base64") then if (storage_type == "base64") then
--include the base64 function --include the base64 function
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--base64 encode the file --base64 encode the file
local f = io.open(real_file, "rb"); local f = io.open(real_file, "rb");
local file_content = f:read("*all"); local file_content = f:read("*all");

View File

@@ -44,7 +44,7 @@
--record and save the file --record and save the file
if (storage_type == "base64") then if (storage_type == "base64") then
--include the base64 function --include the base64 function
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--set the location --set the location
voicemail_name_location = voicemail_dir.."/"..voicemail_id.."/recorded_name.wav"; voicemail_name_location = voicemail_dir.."/"..voicemail_id.."/recorded_name.wav";

View File

@@ -52,7 +52,7 @@
--require the email address to send the email --require the email address to send the email
if (string.len(voicemail_mail_to) > 2) then if (string.len(voicemail_mail_to) > 2) then
--include languages file --include languages file
dofile(scripts_dir.."/app/voicemail/app_languages.lua"); require "app.voicemail.app_languages";
--get voicemail message details --get voicemail message details
sql = [[SELECT * FROM v_voicemail_messages sql = [[SELECT * FROM v_voicemail_messages
@@ -73,7 +73,7 @@
--get the recordings from the database --get the recordings from the database
if (storage_type == "base64") then if (storage_type == "base64") then
--add functions --add functions
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--set the voicemail message path --set the voicemail message path
message_location = voicemail_dir.."/"..id.."/msg_"..uuid.."."..vm_message_ext; message_location = voicemail_dir.."/"..id.."/msg_"..uuid.."."..vm_message_ext;

View File

@@ -39,23 +39,18 @@
--only run the script a single time --only run the script a single time
runonce = true runonce = true
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--used to stop the lua service --used to stop the lua service
local file = assert(io.open(run_file, "w")); local file = assert(io.open(run_file, "w"));
file:write("remove this file to stop the script"); file:write("remove this file to stop the script");
--add the trim function --define the trim function
function trim(s) require "resources.functions.trim";
return s:gsub("^%s+", ""):gsub("%s+$", "")
end
--check if a file exists --check if a file exists
function file_exists(name) require "resources.functions.file_exists";
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
--create the api object --create the api object
api = freeswitch.API(); api = freeswitch.API();

View File

@@ -39,9 +39,9 @@
debug["cache"] = false; debug["cache"] = false;
--general functions --general functions
dofile(scripts_dir.."/resources/functions/trim.lua"); require "resources.functions.trim";
dofile(scripts_dir.."/resources/functions/file_exists.lua"); require "resources.functions.file_exists";
dofile(scripts_dir.."/resources/functions/explode.lua"); require "resources.functions.explode";
--if the params class and methods do not exist then add them to prevent errors --if the params class and methods do not exist then add them to prevent errors
if (not params) then if (not params) then

View File

@@ -36,7 +36,7 @@
if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--exits the script if we didn't connect properly --exits the script if we didn't connect properly

View File

@@ -36,7 +36,7 @@
if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--exits the script if we didn't connect properly --exits the script if we didn't connect properly

View File

@@ -35,7 +35,7 @@
if (XML_STRING == "-ERR NOT FOUND") then if (XML_STRING == "-ERR NOT FOUND") then
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--exits the script if we didn't connect properly --exits the script if we didn't connect properly

View File

@@ -25,7 +25,7 @@
-- POSSIBILITY OF SUCH DAMAGE. -- POSSIBILITY OF SUCH DAMAGE.
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--exits the script if we didn't connect properly --exits the script if we didn't connect properly

View File

@@ -34,7 +34,7 @@
--set the cache --set the cache
if (XML_STRING == "-ERR NOT FOUND") then if (XML_STRING == "-ERR NOT FOUND") then
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--exits the script if we didn't connect properly --exits the script if we didn't connect properly

View File

@@ -32,7 +32,7 @@
--user_call - user has been called --user_call - user has been called
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--exits the script if we didn't connect properly --exits the script if we didn't connect properly

View File

@@ -109,7 +109,7 @@
--database connection --database connection
if (continue) then if (continue) then
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--exits the script if we didn't connect properly --exits the script if we didn't connect properly
@@ -154,14 +154,14 @@
--freeswitch.consoleLog("notice", "[xml_handler-directory.lua] local_hostname is " .. local_hostname .. "\n"); --freeswitch.consoleLog("notice", "[xml_handler-directory.lua] local_hostname is " .. local_hostname .. "\n");
--add the file_exists function --add the file_exists function
dofile(scripts_dir.."/resources/functions/file_exists.lua"); require "resources.functions.file_exists";
--connect to the switch database --connect to the switch database
if (file_exists(database_dir.."/core.db")) then if (file_exists(database_dir.."/core.db")) then
--dbh_switch = freeswitch.Dbh("core:core"); -- when using sqlite --dbh_switch = freeswitch.Dbh("core:core"); -- when using sqlite
dbh_switch = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); dbh_switch = freeswitch.Dbh("sqlite://"..database_dir.."/core.db");
else else
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh_switch = database_handle('switch'); dbh_switch = database_handle('switch');
end end

View File

@@ -65,7 +65,7 @@
--database connection --database connection
if (continue) then if (continue) then
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--exits the script if we didn't connect properly --exits the script if we didn't connect properly

View File

@@ -32,7 +32,7 @@
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
if (session:ready()) then if (session:ready()) then

View File

@@ -35,11 +35,11 @@
require "resources.functions.config"; require "resources.functions.config";
--general functions --general functions
dofile(scripts_dir.."/resources/functions/file_exists.lua"); require "resources.functions.file_exists";
dofile(scripts_dir.."/resources/functions/mkdir.lua"); require "resources.functions.mkdir";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--make sure the scripts/run dir exists --make sure the scripts/run dir exists

View File

@@ -32,20 +32,10 @@
debug["sql"] = false; debug["sql"] = false;
--define the trim function --define the trim function
function trim (s) require "resources.functions.trim"
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
--define the explode function --define the explode function
function explode ( seperator, str ) require "resources.functions.explode"
local pos, arr = 0, {}
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
--create the api object --create the api object
api = freeswitch.API(); api = freeswitch.API();
@@ -81,7 +71,7 @@
session:sleep(1000); session:sleep(1000);
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--request id is true --request id is true

View File

@@ -30,20 +30,10 @@
debug["sql"] = true; debug["sql"] = true;
--define the trim function --define the trim function
function trim (s) require "resources.functions.trim"
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
--define the explode function --define the explode function
function explode ( seperator, str ) require "resources.functions.explode"
local pos, arr = 0, {}
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
--create the api object --create the api object
api = freeswitch.API(); api = freeswitch.API();
@@ -82,17 +72,17 @@
require "resources.functions.config"; require "resources.functions.config";
--check if the session is ready --check if the session is ready
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
if (database["type"] == "mysql") then if (database["type"] == "mysql") then
sql = "SELECT CONCAT(v_contacts.contact_name_given, ' ', v_contacts.contact_name_family,' (',v_contact_phones.phone_type,')') AS name FROM v_contacts "; sql = "SELECT CONCAT(v_contacts.contact_name_given, ' ', v_contacts.contact_name_family,' (',v_contact_phones.phone_type,')') AS name FROM v_contacts ";
else else
sql = "SELECT v_contacts.contact_name_given || ' ' || v_contacts.contact_name_family || ' (' || v_contact_phones.phone_type || ')' AS name FROM v_contacts "; sql = "SELECT v_contacts.contact_name_given || ' ' || v_contacts.contact_name_family || ' (' || v_contact_phones.phone_type || ')' AS name FROM v_contacts ";
end end
sql = sql .. "INNER JOIN v_contact_phones ON v_contact_phones.contact_uuid = v_contacts.contact_uuid "; sql = sql .. "INNER JOIN v_contact_phones ON v_contact_phones.contact_uuid = v_contacts.contact_uuid ";
sql = sql .. "INNER JOIN v_destinations ON v_destinations.domain_uuid = v_contacts.domain_uuid "; sql = sql .. "INNER JOIN v_destinations ON v_destinations.domain_uuid = v_contacts.domain_uuid ";
sql = sql .. "WHERE v_contact_phones.phone_number = '"..caller.."' AND v_destinations.destination_number='"..callee.."'"; sql = sql .. "WHERE v_contact_phones.phone_number = '"..caller.."' AND v_destinations.destination_number='"..callee.."'";

View File

@@ -26,10 +26,7 @@
digit_timeout = "5000"; digit_timeout = "5000";
--check if a file exists --check if a file exists
function file_exists(name) require "resources.functions.file_exists"
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
--run if the session is ready --run if the session is ready
if ( session:ready() ) then if ( session:ready() ) then

View File

@@ -28,13 +28,11 @@
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--add a trim function --define the trim function
function trim (s) require "resources.functions.trim"
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
--get the variables --get the variables
domain_name = session:getVariable("domain_name"); domain_name = session:getVariable("domain_name");

View File

@@ -37,7 +37,7 @@
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
if ( session:ready() ) then if ( session:ready() ) then

View File

@@ -37,11 +37,11 @@
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--settings --settings
dofile(scripts_dir.."/resources/functions/settings.lua"); require "resources.functions.settings";
settings = settings(domain_uuid); settings = settings(domain_uuid);
storage_type = ""; storage_type = "";
storage_path = ""; storage_path = "";
@@ -151,16 +151,8 @@
end end
end end
--define explode --define the explode function
function explode ( seperator, str ) require "resources.functions.explode"
local pos, arr = 0, {}
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
--define a function to convert dialpad letters to numbers --define a function to convert dialpad letters to numbers
function dialpad_to_digit(letter) function dialpad_to_digit(letter)
@@ -193,16 +185,11 @@
return count return count
end end
--define trim --define the trim function
function trim (s) require "resources.functions.trim"
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
--check if a file exists --check if a file exists
function file_exists(name) require "resources.functions.file_exists"
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
--define select_entry function --define select_entry function
function select_entry() function select_entry()
@@ -261,7 +248,7 @@
end end
status = dbh:query(sql, function(field) status = dbh:query(sql, function(field)
--add functions --add functions
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--set the voicemail message path --set the voicemail message path
file_location = voicemail_dir.."/"..row.extension.."/recorded_name.wav"; file_location = voicemail_dir.."/"..row.extension.."/recorded_name.wav";

View File

@@ -30,7 +30,7 @@
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
api = freeswitch.API(); api = freeswitch.API();

View File

@@ -30,13 +30,13 @@
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
api = freeswitch.API(); api = freeswitch.API();
--other libs --other libs
dofile(scripts_dir.."/resources/functions/trim.lua"); require "resources.functions.trim";
aleg_number = argv[1]; aleg_number = argv[1];
bleg_number = argv[2]; bleg_number = argv[2];

View File

@@ -26,19 +26,11 @@ predefined_destination = "";
max_tries = "3"; max_tries = "3";
digit_timeout = "5000"; digit_timeout = "5000";
function trim (s) --define the trim function
return (string.gsub(s, "^%s*(.-)%s*$", "%1")) require "resources.functions.trim";
end
function explode ( seperator, str ) --define the explode function
local pos, arr = 0, {} require "resources.functions.explode";
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
if ( session:ready() ) then if ( session:ready() ) then
session:answer( ); session:answer( );

View File

@@ -34,24 +34,16 @@ digit_timeout = "5000";
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
api = freeswitch.API(); api = freeswitch.API();
function trim (s) --define the trim function
return (string.gsub(s, "^%s*(.-)%s*$", "%1")) require "resources.functions.trim";
end
function explode ( seperator, str ) --define the explode function
local pos, arr = 0, {} require "resources.functions.explode";
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
if ( session:ready() ) then if ( session:ready() ) then
session:answer( ); session:answer( );

View File

@@ -32,20 +32,10 @@
debug["sql"] = false; debug["sql"] = false;
--define the trim function --define the trim function
function trim (s) require "resources.functions.trim";
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
--define the explode function --define the explode function
function explode ( seperator, str ) require "resources.functions.explode";
local pos, arr = 0, {}
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
--create the api object --create the api object
api = freeswitch.API(); api = freeswitch.API();
@@ -80,7 +70,7 @@
session:sleep(1000); session:sleep(1000);
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--determine whether to update the dial string --determine whether to update the dial string

View File

@@ -31,7 +31,7 @@ extension = argv[1];
require "resources.functions.config"; require "resources.functions.config";
--add the file_exists function --add the file_exists function
dofile(scripts_dir.."/resources/functions/file_exists.lua"); require "resources.functions.file_exists";
--connect to the database --connect to the database
if (file_exists(database_dir.."/core.db")) then if (file_exists(database_dir.."/core.db")) then
@@ -39,7 +39,7 @@ extension = argv[1];
dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db");
freeswitch.consoleLog("NOTICE", "[eavesdrop] using core.db\n"); freeswitch.consoleLog("NOTICE", "[eavesdrop] using core.db\n");
else else
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('switch'); dbh = database_handle('switch');
freeswitch.consoleLog("NOTICE", "[eavesdrop] using freeswitch db\n"); freeswitch.consoleLog("NOTICE", "[eavesdrop] using freeswitch db\n");

View File

@@ -27,7 +27,7 @@
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
if (session:ready()) then if (session:ready()) then

View File

@@ -34,28 +34,14 @@
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--define the explode function --define the explode function
function explode ( seperator, str ) require "resources.functions.explode";
local pos, arr = 0, {}
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
--array count --array count
function count(t) require "resources.functions.count";
c = 0;
for k,v in pairs(t) do
c = c+1;
end
return c;
end
-- show all channel variables -- show all channel variables
--dat = env:serialize() --dat = env:serialize()
@@ -137,7 +123,7 @@
end end
--settings --settings
dofile(scripts_dir.."/resources/functions/settings.lua"); require "resources.functions.settings";
settings = settings(domain_uuid); settings = settings(domain_uuid);
storage_type = ""; storage_type = "";
storage_path = ""; storage_path = "";
@@ -300,7 +286,7 @@
if (fax_success =="1") then if (fax_success =="1") then
if (storage_type == "base64") then if (storage_type == "base64") then
--include the base64 function --include the base64 function
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--base64 encode the file --base64 encode the file
local f = io.open(fax_file, "rb"); local f = io.open(fax_file, "rb");

View File

@@ -32,20 +32,10 @@
debug["sql"] = true; debug["sql"] = true;
--define the trim function --define the trim function
function trim (s) require "resources.functions.trim";
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
--define the explode function --define the explode function
function explode ( seperator, str ) require "resources.functions.explode";
local pos, arr = 0, {}
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
--create the api object --create the api object
api = freeswitch.API(); api = freeswitch.API();
@@ -79,7 +69,7 @@
session:sleep(1000); session:sleep(1000);
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--determine whether to update the dial string --determine whether to update the dial string

View File

@@ -39,7 +39,7 @@
--dbh = freeswitch.Dbh("core:core"); -- when using sqlite --dbh = freeswitch.Dbh("core:core"); -- when using sqlite
dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db");
else else
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('switch'); dbh = database_handle('switch');
end end
@@ -47,7 +47,7 @@
api = freeswitch.API(); api = freeswitch.API();
--add the function --add the function
dofile(scripts_dir.."/resources/functions/trim.lua"); require "resources.functions.trim";
--exits the script if we didn't connect properly --exits the script if we didn't connect properly
assert(dbh:connected()); assert(dbh:connected());

View File

@@ -34,10 +34,10 @@
require "resources.functions.config"; require "resources.functions.config";
--add the function --add the function
dofile(scripts_dir.."/resources/functions/explode.lua"); require "resources.functions.explode";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--check if the session is ready --check if the session is ready
@@ -147,7 +147,7 @@
--dbh = freeswitch.Dbh("core:core"); -- when using sqlite --dbh = freeswitch.Dbh("core:core"); -- when using sqlite
dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db");
else else
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('switch'); dbh = database_handle('switch');
end end

View File

@@ -35,7 +35,7 @@
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--get the variables --get the variables
@@ -47,7 +47,7 @@
domain_uuid = session:getVariable("domain_uuid"); domain_uuid = session:getVariable("domain_uuid");
--settings --settings
dofile(scripts_dir.."/resources/functions/settings.lua"); require "resources.functions.settings";
settings = settings(domain_uuid); settings = settings(domain_uuid);
storage_type = ""; storage_type = "";
storage_path = ""; storage_path = "";
@@ -83,16 +83,11 @@
--set default variable(s) --set default variable(s)
tries = 0; tries = 0;
--add the trim function --define the trim function
function trim(s) require "resources.functions.trim"
return s:gsub("^%s+", ""):gsub("%s+$", "")
end
--check if a file exists --check if a file exists
function file_exists(name) require "resources.functions.file_exists"
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
--prepare the api object --prepare the api object
api = freeswitch.API(); api = freeswitch.API();
@@ -216,7 +211,7 @@
end end
status = dbh:query(sql, function(row) status = dbh:query(sql, function(row)
--add functions --add functions
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--add the path to filename --add the path to filename
ivr_menu_greet_long = recordings_dir.."/"..greet_long_file_name; ivr_menu_greet_long = recordings_dir.."/"..greet_long_file_name;
ivr_menu_greet_long_is_base64 = true; ivr_menu_greet_long_is_base64 = true;
@@ -240,7 +235,7 @@
end end
status = dbh:query(sql, function(row) status = dbh:query(sql, function(row)
--add functions --add functions
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--add the path to filename --add the path to filename
ivr_menu_greet_short = recordings_dir.."/"..greet_short_file_name; ivr_menu_greet_short = recordings_dir.."/"..greet_short_file_name;
ivr_menu_greet_short_is_base64 = true; ivr_menu_greet_short_is_base64 = true;
@@ -264,7 +259,7 @@
end end
status = dbh:query(sql, function(row) status = dbh:query(sql, function(row)
--add functions --add functions
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--add the path to filename --add the path to filename
ivr_menu_invalid_sound = recordings_dir.."/"..invalid_sound_file_name; ivr_menu_invalid_sound = recordings_dir.."/"..invalid_sound_file_name;
ivr_menu_invalid_sound_is_base64 = true; ivr_menu_invalid_sound_is_base64 = true;
@@ -288,7 +283,7 @@
end end
status = dbh:query(sql, function(row) status = dbh:query(sql, function(row)
--add functions --add functions
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--add the path to filename --add the path to filename
ivr_menu_exit_sound = recordings_dir.."/"..exit_sound_file_name; ivr_menu_exit_sound = recordings_dir.."/"..exit_sound_file_name;
ivr_menu_exit_sound_is_base64 = true; ivr_menu_exit_sound_is_base64 = true;

View File

@@ -31,16 +31,11 @@
local file = assert(io.open(tmp_file, "w")); local file = assert(io.open(tmp_file, "w"));
file:write("remove this file to stop the script"); file:write("remove this file to stop the script");
--add the trim function --define the trim function
function trim(s) require "resources.functions.trim"
return s:gsub("^%s+", ""):gsub("%s+$", "")
end
--check if a file exists --check if a file exists
function file_exists(name) require "resources.functions.file_exists"
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
--create the api object --create the api object
api = freeswitch.API(); api = freeswitch.API();

View File

@@ -28,19 +28,11 @@ pin_number = "";
max_tries = "3"; max_tries = "3";
digit_timeout = "3000"; digit_timeout = "3000";
function trim (s) --define the trim function
return (string.gsub(s, "^%s*(.-)%s*$", "%1")) require "resources.functions.trim";
end
function explode ( seperator, str ) --define the explode function
local pos, arr = 0, {} require "resources.functions.explode";
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
if ( session:ready() ) then if ( session:ready() ) then
session:answer(); session:answer();

View File

@@ -20,7 +20,7 @@
--connect to the database --connect to the database
--dbh = freeswitch.Dbh("core:core"); -- when using sqlite --dbh = freeswitch.Dbh("core:core"); -- when using sqlite
dbh = freeswitch.Dbh("sqlite://"..database_dir.."/park.db"); dbh = freeswitch.Dbh("sqlite://"..database_dir.."/park.db");
--dofile(scripts_dir.."/resources/functions/database_handle.lua"); --require "resources.functions.database_handle";
--dbh = database_handle('system'); --dbh = database_handle('system');
--exits the script if we didn't connect properly --exits the script if we didn't connect properly
@@ -38,21 +38,11 @@
park_timeout_seconds = session:getVariable("park_timeout_seconds"); park_timeout_seconds = session:getVariable("park_timeout_seconds");
park_music = session:getVariable("park_music"); park_music = session:getVariable("park_music");
--add the explode function --define the trim function
function explode ( seperator, str ) require "resources.functions.trim";
local pos, arr = 0, {}
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
--add the trim function --define the explode function
function trim(s) require "resources.functions.explode";
return s:gsub("^%s+", ""):gsub("%s+$", "")
end
--if park_timeout_seconds is not defined set the timeout to 5 minutes --if park_timeout_seconds is not defined set the timeout to 5 minutes
if (not park_timeout_seconds) then if (not park_timeout_seconds) then

View File

@@ -34,7 +34,7 @@
--connect to the database --connect to the database
--dbh = freeswitch.Dbh("core:core"); -- when using sqlite --dbh = freeswitch.Dbh("core:core"); -- when using sqlite
dbh = freeswitch.Dbh("sqlite://"..database_dir.."/park.db"); dbh = freeswitch.Dbh("sqlite://"..database_dir.."/park.db");
--dofile(scripts_dir.."/resources/functions/database_handle.lua"); --require "resources.functions.database_handle";
--get the argv values --get the argv values
script_name = argv[0]; script_name = argv[0];
@@ -48,10 +48,8 @@
--prepare the api --prepare the api
api = freeswitch.API(); api = freeswitch.API();
--add a trim function --define the trim function
function trim (s) require "resources.functions.trim";
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
--monitor the parking lot if the call has hungup send a terminated event, and delete from the db --monitor the parking lot if the call has hungup send a terminated event, and delete from the db
x = 0 x = 0

View File

@@ -27,19 +27,11 @@ digit_timeout = 5000;
max_retries = 3; max_retries = 3;
tries = 0; tries = 0;
function trim (s) --define the trim function
return (string.gsub(s, "^%s*(.-)%s*$", "%1")) require "resources.functions.trim";
end
function explode ( seperator, str ) --define the explode function
local pos, arr = 0, {} require "resources.functions.explode";
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
pos = sp + 1 -- jump past current divider
end
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
return arr
end
function check_pin_number() function check_pin_number()
--sleep --sleep

View File

@@ -37,21 +37,21 @@
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--get the domain_uuid --get the domain_uuid
domain_uuid = session:getVariable("domain_uuid"); domain_uuid = session:getVariable("domain_uuid");
--add functions --add functions
dofile(scripts_dir.."/resources/functions/mkdir.lua"); require "resources.functions.mkdir";
dofile(scripts_dir.."/resources/functions/explode.lua"); require "resources.functions.explode";
--initialize the recordings --initialize the recordings
api = freeswitch.API(); api = freeswitch.API();
--settings --settings
dofile(scripts_dir.."/resources/functions/settings.lua"); require "resources.functions.settings";
settings = settings(domain_uuid); settings = settings(domain_uuid);
storage_type = ""; storage_type = "";
storage_path = ""; storage_path = "";
@@ -124,7 +124,7 @@
--begin recording --begin recording
if (storage_type == "base64") then if (storage_type == "base64") then
--include the base64 function --include the base64 function
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--make the directory --make the directory
mkdir(recordings_dir); mkdir(recordings_dir);

View File

@@ -6,7 +6,7 @@ function base64.encode(s)
local mime = require("mime"); local mime = require("mime");
return (mime.b64(s)); return (mime.b64(s));
else else
dofile(scripts_dir.."/resources/functions/base64_alex.lua"); require "resources.functions.base64_alex";
return base64.enc(s); return base64.enc(s);
end end
end end
@@ -17,7 +17,7 @@ function base64.decode(s)
local mime = require("mime"); local mime = require("mime");
return (mime.unb64(s)); return (mime.unb64(s));
else else
dofile(scripts_dir.."/resources/functions/base64_alex.lua"); require "resources.functions.base64_alex";
return base64.dec(s); return base64.dec(s);
end end
end end

View File

@@ -2,10 +2,8 @@
--debug --debug
debug["sql"] = false; debug["sql"] = false;
--define trim --define the trim function
function trim (s) require "resources.functions.trim";
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
--get the domain_uuid --get the domain_uuid
if (domain_uuid == nil) then if (domain_uuid == nil) then

View File

@@ -6,7 +6,7 @@
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = database_handle('system');
--get the variables --get the variables
@@ -23,7 +23,7 @@
if (not default_voice) then default_voice = 'callie'; end if (not default_voice) then default_voice = 'callie'; end
--settings --settings
dofile(scripts_dir.."/resources/functions/settings.lua"); require "resources.functions.settings";
settings = settings(domain_uuid); settings = settings(domain_uuid);
storage_type = ""; storage_type = "";
storage_path = ""; storage_path = "";
@@ -57,10 +57,7 @@
end end
--check if a file exists --check if a file exists
function file_exists(name) require "resources.functions.file_exists";
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
--define the on_dtmf call back function --define the on_dtmf call back function
function on_dtmf(s, type, obj, arg) function on_dtmf(s, type, obj, arg)
@@ -103,7 +100,7 @@
end end
status = dbh:query(sql, function(row) status = dbh:query(sql, function(row)
--add functions --add functions
dofile(scripts_dir.."/resources/functions/base64.lua"); require "resources.functions.base64";
--add the path to filename --add the path to filename
file_name = recordings_dir.."/"..file_name_only; file_name = recordings_dir.."/"..file_name_only;
--save the recording to the file system --save the recording to the file system

View File

@@ -27,10 +27,8 @@
domain_name = argv[1]; domain_name = argv[1];
wakeup_number = argv[2]; wakeup_number = argv[2];
--add the trim function --define the trim function
function trim(s) require "resources.functions.trim";
return s:gsub("^%s+", ""):gsub("%s+$", "")
end
--add is_numeric --add is_numeric
function is_numeric(text) function is_numeric(text)