From a7ab1c568c8710dd70b44a19c194881bddf80aa3 Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Fri, 4 Apr 2014 07:08:00 +0000 Subject: [PATCH] Check add the option to record the user. --- .../install/scripts/app/dialplan/index.lua | 34 +++++++-- .../resources/after/010_user_record.lua | 73 +++++++++++++++++++ .../resources/before/010_user_exists.lua | 9 +++ .../resources/inbound/020_call_block.lua | 10 +-- 4 files changed, 116 insertions(+), 10 deletions(-) create mode 100644 resources/install/scripts/app/dialplan/resources/after/010_user_record.lua create mode 100644 resources/install/scripts/app/dialplan/resources/before/010_user_exists.lua diff --git a/resources/install/scripts/app/dialplan/index.lua b/resources/install/scripts/app/dialplan/index.lua index 580305307c..0679747163 100644 --- a/resources/install/scripts/app/dialplan/index.lua +++ b/resources/install/scripts/app/dialplan/index.lua @@ -31,10 +31,12 @@ -- dir /usr/local/freeswitch/scripts -1 --set local variables - local context = session:getVariable("context"); - local destination_number = session:getVariable("destination_number"); - local call_direction = session:getVariable("call_direction"); - local domain_name = session:getVariable("domain_name"); + uuid = session:getVariable("uuid"); + context = session:getVariable("context"); + destination_number = session:getVariable("destination_number"); + call_direction = session:getVariable("call_direction"); + domain_name = session:getVariable("domain_name"); + recordings_dir = session:getVariable("recordings_dir"); --determine the call direction if (call_direction == nil) then @@ -72,6 +74,17 @@ end end +--include before + result = assert (io.popen ("dir " ..scripts_dir.."/app/dialplan/resources/before /b -1")); + for file in result:lines() do + if (string.sub(file, -4) == ".lua") then + if file_exists(scripts_dir.."/app/dialplan/resources/before/"..file) then + dofile(scripts_dir.."/app/dialplan/resources/before/"..file); + end + --freeswitch.consoleLog("notice", "[app:dialplan] lua: before/" .. file .. "\n"); + end + end + --include the dialplans result = assert (io.popen ("dir " ..scripts_dir.."/app/dialplan/resources/"..dialplan_dir.." /b -1")); for file in result:lines() do @@ -79,6 +92,17 @@ if file_exists(scripts_dir.."/app/dialplan/resources/"..dialplan_dir.."/"..file) then dofile(scripts_dir.."/app/dialplan/resources/"..dialplan_dir.."/"..file); end - freeswitch.consoleLog("notice", "[app:dialplan] lua: "..dialplan_dir.."/" .. file .. "\n"); + --freeswitch.consoleLog("notice", "[app:dialplan] lua: "..dialplan_dir.."/" .. file .. "\n"); + end + end + +--include after + result = assert (io.popen ("dir " ..scripts_dir.."/app/dialplan/resources/after /b -1")); + for file in result:lines() do + if (string.sub(file, -4) == ".lua") then + if file_exists(scripts_dir.."/app/dialplan/resources/after/"..file) then + dofile(scripts_dir.."/app/dialplan/resources/after/"..file); + end + --freeswitch.consoleLog("notice", "[app:dialplan] lua: after/" .. file .. "\n"); end end diff --git a/resources/install/scripts/app/dialplan/resources/after/010_user_record.lua b/resources/install/scripts/app/dialplan/resources/after/010_user_record.lua new file mode 100644 index 0000000000..cbf6e9c78d --- /dev/null +++ b/resources/install/scripts/app/dialplan/resources/after/010_user_record.lua @@ -0,0 +1,73 @@ +--set the user_exists to true or false + if (context ~= "public") then + --set the recording path + path = recordings_dir + if (domain_count > 1) then + path = path.."/"..domain_name; + end + path = path.."/archive/"..(os.date("%Y")).."/"..(os.date("%b")).."/"..(os.date("%d")).."/"..uuid..".wav"; + + --check whether to record the to user + if (user_exists == "true") then + if (session:ready()) then + --get user_variable -> record + cmd = "user_data ".. destination_number .."@"..domain_name.." var user_record"; + user_record = trim(api:executeString(cmd)); + --freeswitch.consoleLog("notice", "[app:dialplan] " .. cmd .. "\n"); + + --set the record_session variable + --uuid_record, [start|stop|mask|unmask] [],Record session audio,mod_commands + if (user_record == "all") then + record_session = true; + end + if (user_record == "inbound" and call_direction == "inbound") then + record_session = true; + end + if (user_record == "outbound" and call_direction == "outbound") then + record_session = true; + end + if (user_record == "local" and call_direction == "local") then + record_session = true; + end + end + end + + --check whether to record the from user + if (not record_session) then + --get the from user + sip_from_user = session:getVariable("sip_from_user"); + sip_from_uri = session:getVariable("sip_from_uri"); + sip_from_host = session:getVariable("sip_from_host"); + + --get user exists true or false + cmd = "user_exists id ".. sip_from_user .." "..sip_from_host; + user_exists = trim(api:executeString(cmd)); + + --get user_variable -> record + cmd = "user_data ".. sip_from_user .."@"..sip_from_host.." var user_record"; + freeswitch.consoleLog("notice", "[app:dialplan] " .. cmd .. "\n"); + user_record = trim(api:executeString(cmd)); + + --set the record_session variable + --uuid_record, [start|stop|mask|unmask] [],Record session audio,mod_commands + if (user_record == "all") then + record_session = true; + end + if (user_record == "inbound" and call_direction == "inbound") then + record_session = true; + end + if (user_record == "outbound" and call_direction == "outbound") then + record_session = true; + end + if (user_record == "local" and call_direction == "local") then + record_session = true; + end + end + + --record the session + if (record_session) then + cmd = "uuid_record "..uuid.." start "..path; + session:execute("set", "api_on_answer="..cmd); + --freeswitch.consoleLog("notice", "[app:dialplan] "..cmd.."\n"); + end + end \ No newline at end of file diff --git a/resources/install/scripts/app/dialplan/resources/before/010_user_exists.lua b/resources/install/scripts/app/dialplan/resources/before/010_user_exists.lua new file mode 100644 index 0000000000..012b6fbbfe --- /dev/null +++ b/resources/install/scripts/app/dialplan/resources/before/010_user_exists.lua @@ -0,0 +1,9 @@ +--set the user_exists to true or false + if (context ~= "public") then + if (user_exists == nil) then + --get user exists true or false + cmd = "user_exists id ".. destination_number .." "..domain_name; + user_exists = trim(api:executeString(cmd)); + --freeswitch.consoleLog("notice", "[app:dialplan] "..cmd.." user_exists: "..user_exists.."\n"); + end + end \ No newline at end of file diff --git a/resources/install/scripts/app/dialplan/resources/inbound/020_call_block.lua b/resources/install/scripts/app/dialplan/resources/inbound/020_call_block.lua index 2ba011a6f8..2d071a5fff 100644 --- a/resources/install/scripts/app/dialplan/resources/inbound/020_call_block.lua +++ b/resources/install/scripts/app/dialplan/resources/inbound/020_call_block.lua @@ -16,7 +16,7 @@ -- -- The Initial Developer of the Original Code is -- Gerrit Visser --- Copyright (C) 2011 +-- Copyright (C) 2011-2014 -- the Initial Developer. All Rights Reserved. -- -- Contributor(s): @@ -56,7 +56,7 @@ This method causes the script to get its manadatory arguments directly from the local function logger(level, log, data) -- output data to console 'log' if debug level is on if string.find(params["loglevel"], level) then - freeswitch.consoleLog(log, "[Call Block]: " .. data .. "\n") + freeswitch.consoleLog(log, "[Call Block]: " .. data .. "\n"); end end @@ -66,7 +66,7 @@ This method causes the script to get its manadatory arguments directly from the --log if not connect if dbh:connected() == false then - logger("W", "NOTICE", "db was not connected") + logger("W", "NOTICE", "db was not connected"); end -- We have a single command letter @@ -75,7 +75,7 @@ This method causes the script to get its manadatory arguments directly from the params["cmd"] = argv[1]; -- ensure that we have a fresh status on exit - session:setVariable("call_block", "") + session:setVariable("call_block", ""); --send to the log logger("D", "NOTICE", "params are: " .. string.format("'%s', '%s', '%s', '%s'", params["cid_num"], @@ -102,7 +102,7 @@ This method causes the script to get its manadatory arguments directly from the k = 0 for v in string.gmatch(found_action, "[%w%.]+") do details[k] = v - --logger("W", "INFO", "Details: " .. details[k]) + logger("W", "INFO", "Details: " .. details[k]); k = k + 1 end dbh:query("UPDATE v_call_block SET call_block_count = " .. found_count + 1 .. " WHERE call_block_uuid = '" .. found_uuid .. "'")