summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2013-01-01 17:56:50 +0000
committerTed Trask <ttrask01@yahoo.com>2013-01-01 17:56:50 +0000
commite9c272da7a795d3fb47cc7a4ffad684e8efde0e2 (patch)
treeace29e0892f77c74f48c3a4cee25eab3b0958f2d
parentb84409d78e9434df06424f04496d5fbeb00d8eba (diff)
downloadacf-freeswitch-vmail-e9c272da7a795d3fb47cc7a4ffad684e8efde0e2.tar.bz2
acf-freeswitch-vmail-e9c272da7a795d3fb47cc7a4ffad684e8efde0e2.tar.xz
Replace io.popen with modelfunctions.run_executable
-rw-r--r--vmail-model.lua48
1 files changed, 16 insertions, 32 deletions
diff --git a/vmail-model.lua b/vmail-model.lua
index 3690667..b0ea6a6 100644
--- a/vmail-model.lua
+++ b/vmail-model.lua
@@ -58,53 +58,37 @@ local table_creation_scripts = {
-- ################################################################################
-- LOCAL FUNCTIONS
-local function escape_quotes(str)
- return string.gsub(str or "", "'", "'\\''")
-end
-
local function voicemail_inject(user, domain, sound_file, cid_num, cid_name)
- local cmd = "echo -e 'auth "..escape_quotes(config.event_socket_password).."\n\n"
- cmd = cmd.."api voicemail_inject "..escape_quotes(user).."@"..escape_quotes(domain).." "..escape_quotes(sound_file).." "..escape_quotes(cid_num).." "..string.gsub(escape_quotes(cid_name), " ", "%%20")
- cmd = cmd.."\n\nexit\n\n' | nc "..format.escapespecialcharacters(config.event_socket_ip).." "..format.escapespecialcharacters(config.event_socket_port).." 2>&1"
- local f = io.popen( cmd )
- local result = f:read("*a") or ""
- f:close()
- return result
+ local cmd = "auth "..config.event_socket_password.."\n\n"
+ cmd = cmd.."api voicemail_inject "..user.."@"..domain.." "..sound_file.." "..cid_num.." "..string.gsub(cid_name, " ", "%%20")
+ cmd = cmd.."\n\nexit\n\n"
+ return modelfunctions.run_executable({"nc", config.event_socket_ip, config.event_socket_port}, true, cmd)
end
local function voicemail_callback(extension, sound_file, username)
- local cmd = "echo -e 'auth "..escape_quotes(config.event_socket_password).."\n\nbgapi "
+ local cmd = "auth "..config.event_socket_password.."\n\nbgapi "
local c = config.callback_command
c = c:gsub("%$1", extension)
c = c:gsub("%$2", sound_file)
c = c:gsub("%$3", username)
- cmd = cmd..escape_quotes(c)
- cmd = cmd.."\n\nexit\n\n' | nc "..format.escapespecialcharacters(config.event_socket_ip).." "..format.escapespecialcharacters(config.event_socket_port).." 2>&1"
- local f = io.popen( cmd )
- local result = f:read("*a") or ""
- f:close()
- return result
+ cmd = cmd..c
+ cmd = cmd.."\n\nexit\n\n"
+ return modelfunctions.run_executable({"nc", config.event_socket_ip, config.event_socket_port}, true, cmd)
end
-- Need to update the voicemail module to turn off MWI
local function voicemail_update(user, domain)
- local cmd = "echo -e 'auth "..escape_quotes(config.event_socket_password).."\n\n"
- cmd = cmd.."api vm_list "..escape_quotes(user).."@"..escape_quotes(domain)
- cmd = cmd.."\n\nexit\n\n' | nc "..format.escapespecialcharacters(config.event_socket_ip).." "..format.escapespecialcharacters(config.event_socket_port).." 2>&1"
- local f = io.popen( cmd )
- local result = f:read("*a") or ""
- f:close()
- return result
+ local cmd = "auth "..config.event_socket_password.."\n\n"
+ cmd = cmd.."api vm_list "..user.."@"..domain
+ cmd = cmd.."\n\nexit\n\n"
+ return modelfunctions.run_executable({"nc", config.event_socket_ip, config.event_socket_port}, true, cmd)
end
local function voicemail_read(user, domain, message)
- local cmd = "echo -e 'auth "..escape_quotes(config.event_socket_password).."\n\n"
- cmd = cmd.."api vm_read "..escape_quotes(user).."@"..escape_quotes(domain).." read "..escape_quotes(message)
- cmd = cmd.."\n\nexit\n\n' | nc "..format.escapespecialcharacters(config.event_socket_ip).." "..format.escapespecialcharacters(config.event_socket_port).." 2>&1"
- local f = io.popen( cmd )
- local result = f:read("*a") or ""
- f:close()
- return result
+ local cmd = "auth "..config.event_socket_password.."\n\n"
+ cmd = cmd.."api vm_read "..user.."@"..domain.." read "..message
+ cmd = cmd.."\n\nexit\n\n"
+ return modelfunctions.run_executable({"nc", config.event_socket_ip, config.event_socket_port}, true, cmd)
end
local function assert (v, m)