Merge branch 'master' of https://github.com/fusionpbx/fusionpbx
This commit is contained in:
commit
f47a717f9d
|
|
@ -543,7 +543,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
|
||||||
echo " if (document.getElementById('tr_caller_id_name')) { document.getElementById('tr_caller_id_name').style.display = 'none'; }\n";
|
echo " if (document.getElementById('tr_caller_id_name')) { document.getElementById('tr_caller_id_name').style.display = 'none'; }\n";
|
||||||
echo " if (document.getElementById('tr_caller_id_number')) { document.getElementById('tr_caller_id_number').style.display = 'none'; }\n";
|
echo " if (document.getElementById('tr_caller_id_number')) { document.getElementById('tr_caller_id_number').style.display = 'none'; }\n";
|
||||||
echo " document.getElementById('tr_actions').style.display = 'none';\n";
|
echo " document.getElementById('tr_actions').style.display = 'none';\n";
|
||||||
echo " document.getElementById('tr_fax_detection').style.display = 'none';\n";
|
echo " if (document.getElementById('tr_fax_detection')) { document.getElementById('tr_fax_detection').style.display = 'none'; }\n";
|
||||||
echo " document.getElementById('tr_cid_name_prefix').style.display = 'none';\n";
|
echo " document.getElementById('tr_cid_name_prefix').style.display = 'none';\n";
|
||||||
echo " if (document.getElementById('tr_sell')) { document.getElementById('tr_sell').style.display = 'none'; }\n";
|
echo " if (document.getElementById('tr_sell')) { document.getElementById('tr_sell').style.display = 'none'; }\n";
|
||||||
echo " if (document.getElementById('tr_buy')) { document.getElementById('tr_buy').style.display = 'none'; }\n";
|
echo " if (document.getElementById('tr_buy')) { document.getElementById('tr_buy').style.display = 'none'; }\n";
|
||||||
|
|
@ -555,7 +555,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
|
||||||
echo " if (document.getElementById('tr_caller_id_name')) { document.getElementById('tr_caller_id_name').style.display = ''; }\n";
|
echo " if (document.getElementById('tr_caller_id_name')) { document.getElementById('tr_caller_id_name').style.display = ''; }\n";
|
||||||
echo " if (document.getElementById('tr_caller_id_number')) { document.getElementById('tr_caller_id_number').style.display = ''; }\n";
|
echo " if (document.getElementById('tr_caller_id_number')) { document.getElementById('tr_caller_id_number').style.display = ''; }\n";
|
||||||
echo " document.getElementById('tr_actions').style.display = '';\n";
|
echo " document.getElementById('tr_actions').style.display = '';\n";
|
||||||
echo " document.getElementById('tr_fax_detection').style.display = '';\n";
|
echo " if (document.getElementById('tr_fax_detection')) { document.getElementById('tr_fax_detection').style.display = ''; }\n";
|
||||||
echo " document.getElementById('tr_cid_name_prefix').style.display = '';\n";
|
echo " document.getElementById('tr_cid_name_prefix').style.display = '';\n";
|
||||||
echo " if (document.getElementById('tr_sell')) { document.getElementById('tr_sell').style.display = ''; }\n";
|
echo " if (document.getElementById('tr_sell')) { document.getElementById('tr_sell').style.display = ''; }\n";
|
||||||
echo " if (document.getElementById('tr_buy')) { document.getElementById('tr_buy').style.display = ''; }\n";
|
echo " if (document.getElementById('tr_buy')) { document.getElementById('tr_buy').style.display = ''; }\n";
|
||||||
|
|
|
||||||
|
|
@ -28,145 +28,218 @@
|
||||||
max_tries = "3";
|
max_tries = "3";
|
||||||
digit_timeout = "3000";
|
digit_timeout = "3000";
|
||||||
|
|
||||||
--debug
|
|
||||||
debug["sql"] = false;
|
|
||||||
|
|
||||||
--define the trim function
|
--define the trim function
|
||||||
require "resources.functions.trim"
|
require "resources.functions.trim"
|
||||||
|
|
||||||
--define the explode function
|
|
||||||
require "resources.functions.explode"
|
|
||||||
|
|
||||||
--create the api object
|
--create the api object
|
||||||
api = freeswitch.API();
|
api = freeswitch.API();
|
||||||
|
|
||||||
--include config.lua
|
--include config.lua
|
||||||
require "resources.functions.config";
|
require "resources.functions.config";
|
||||||
|
|
||||||
|
--include config.lua
|
||||||
|
require "resources.functions.settings";
|
||||||
|
|
||||||
|
require "resources.functions.channel_utils";
|
||||||
|
|
||||||
|
local log = require "resources.functions.log".call_forward
|
||||||
|
local cache = require "resources.functions.cache"
|
||||||
|
local Database = require "resources.functions.database"
|
||||||
|
|
||||||
|
local function opt(t, ...)
|
||||||
|
if select('#', ...) == 0 then
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
if type(t) ~= 'table' then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return opt(t[...], select(2, ...))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function empty(t)
|
||||||
|
return (not t) or (#t == 0)
|
||||||
|
end
|
||||||
|
|
||||||
--check if the session is ready
|
--check if the session is ready
|
||||||
if (session:ready()) then
|
if not session:ready() then return end
|
||||||
--answer the call
|
|
||||||
|
--answer the call
|
||||||
session:answer();
|
session:answer();
|
||||||
|
|
||||||
--get the variables
|
--get the variables
|
||||||
enabled = session:getVariable("enabled");
|
local enabled = session:getVariable("enabled");
|
||||||
pin_number = session:getVariable("pin_number");
|
local pin_number = session:getVariable("pin_number");
|
||||||
sounds_dir = session:getVariable("sounds_dir");
|
local sounds_dir = session:getVariable("sounds_dir");
|
||||||
domain_uuid = session:getVariable("domain_uuid");
|
local domain_uuid = session:getVariable("domain_uuid");
|
||||||
domain_name = session:getVariable("domain_name");
|
local domain_name = session:getVariable("domain_name");
|
||||||
extension_uuid = session:getVariable("extension_uuid");
|
local extension_uuid = session:getVariable("extension_uuid");
|
||||||
context = session:getVariable("context");
|
local request_id = session:getVariable("request_id");
|
||||||
if (not context ) then context = 'default'; end
|
local extension, dial_string
|
||||||
request_id = session:getVariable("request_id");
|
|
||||||
|
|
||||||
--set the sounds path for the language, dialect and voice
|
--set the sounds path for the language, dialect and voice
|
||||||
default_language = session:getVariable("default_language");
|
local default_language = session:getVariable("default_language") or 'en';
|
||||||
default_dialect = session:getVariable("default_dialect");
|
local default_dialect = session:getVariable("default_dialect") or 'us';
|
||||||
default_voice = session:getVariable("default_voice");
|
local default_voice = session:getVariable("default_voice") or 'callie';
|
||||||
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
|
|
||||||
|
|
||||||
--a moment to sleep
|
--a moment to sleep
|
||||||
session:sleep(1000);
|
session:sleep(1000);
|
||||||
|
|
||||||
--connect to the database
|
--connect to the database
|
||||||
require "resources.functions.database_handle";
|
dbh = Database.new('system');
|
||||||
dbh = database_handle('system');
|
|
||||||
|
|
||||||
--request id is true
|
--request id is true
|
||||||
if (request_id == "true") then
|
if (request_id == "true") then
|
||||||
--unset extension uuid
|
--unset extension uuid
|
||||||
extension_uuid = nil;
|
extension_uuid = nil;
|
||||||
|
|
||||||
--get the id
|
--get the extension
|
||||||
if (session:ready()) then
|
if not session:ready() then return end
|
||||||
min_digits = 2;
|
local min_digits = 2;
|
||||||
max_digits = 20;
|
local max_digits = 20;
|
||||||
id = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_id:#", "", "\\d+");
|
extension = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_id:#", "", "\\d+");
|
||||||
end
|
if empty(extension) then return end
|
||||||
|
|
||||||
--get the pin number
|
--get the pin number
|
||||||
if (session:ready()) then
|
if not session:ready() then return end
|
||||||
min_digits = 3;
|
min_digits = 3;
|
||||||
max_digits = 20;
|
max_digits = 20;
|
||||||
caller_pin_number = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
|
local caller_pin_number = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
|
||||||
end
|
if empty(caller_pin_number) then return end
|
||||||
|
|
||||||
--check to see if the pin number is correct
|
--check to see if the pin number is correct
|
||||||
if (session:ready()) then
|
if not session:ready() then return end
|
||||||
sql = "SELECT * FROM v_voicemails ";
|
local sql = "SELECT * FROM v_voicemails ";
|
||||||
sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .."' ";
|
sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .."' ";
|
||||||
sql = sql .. "AND voicemail_id = '" .. id .."' ";
|
sql = sql .. "AND voicemail_id = '" .. extension .."' ";
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[call_forward] "..sql .."\n");
|
log.notice(sql);
|
||||||
end
|
end
|
||||||
dbh:query(sql, function(row)
|
local voicemail_password = dbh:first_value(sql)
|
||||||
voicemail_password = row.voicemail_password;
|
|
||||||
--freeswitch.consoleLog("notice", "[call_forward] "..voicemail_password .."\n");
|
|
||||||
end);
|
|
||||||
if (voicemail_password ~= caller_pin_number) then
|
if (voicemail_password ~= caller_pin_number) then
|
||||||
--access denied
|
--access denied
|
||||||
session:streamFile("phrase:voicemail_fail_auth:#");
|
session:streamFile("phrase:voicemail_fail_auth:#");
|
||||||
session:hangup("NORMAL_CLEARING");
|
return session:hangup("NORMAL_CLEARING");
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--determine whether to update the dial string
|
--determine whether to update the dial string
|
||||||
if (session:ready()) then
|
if not session:ready() then return end
|
||||||
sql = "select * from v_extensions ";
|
|
||||||
|
local sql = "select * from v_extensions ";
|
||||||
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
||||||
if (extension_uuid ~= nil) then
|
if (extension_uuid ~= nil) then
|
||||||
sql = sql .. "and extension_uuid = '"..extension_uuid.."' ";
|
sql = sql .. "and extension_uuid = '"..extension_uuid.."' ";
|
||||||
else
|
else
|
||||||
sql = sql .. "and (extension = '"..id.."' or number_alias = '"..id.."') ";
|
sql = sql .. "and (extension = '"..extension.."' or number_alias = '"..extension.."') ";
|
||||||
end
|
end
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[call_forward] "..sql.."\n");
|
log.notice(sql);
|
||||||
end
|
end
|
||||||
status = dbh:query(sql, function(row)
|
local row = dbh:first_row(sql)
|
||||||
|
if not row then return end
|
||||||
|
|
||||||
extension_uuid = row.extension_uuid;
|
extension_uuid = row.extension_uuid;
|
||||||
extension = row.extension;
|
extension = row.extension;
|
||||||
number_alias = row.number_alias or '';
|
local number_alias = row.number_alias or '';
|
||||||
accountcode = row.accountcode;
|
local accountcode = row.accountcode;
|
||||||
forward_all_enabled = row.forward_all_enabled;
|
local forward_all_enabled = row.forward_all_enabled;
|
||||||
forward_all_destination = row.forward_all_destination;
|
local forward_all_destination = row.forward_all_destination;
|
||||||
follow_me_uuid = row.follow_me_uuid;
|
local follow_me_uuid = row.follow_me_uuid;
|
||||||
toll_allow = row.toll_allow or '';
|
local toll_allow = row.toll_allow or '';
|
||||||
--freeswitch.consoleLog("NOTICE", "[call forward] extension "..row.extension.."\n");
|
local forward_caller_id_uuid = row.forward_caller_id_uuid;
|
||||||
--freeswitch.consoleLog("NOTICE", "[call forward] accountcode "..row.accountcode.."\n");
|
|
||||||
end);
|
--toggle enabled
|
||||||
|
if enabled == "toggle" then
|
||||||
|
enabled = (forward_all_enabled == "true") and "false" or "true";
|
||||||
end
|
end
|
||||||
|
|
||||||
--toggle enabled
|
if not session:ready() then return end
|
||||||
if (session:ready() and enabled == "toggle") then
|
|
||||||
if (forward_all_enabled == "true") then
|
|
||||||
enabled = "false";
|
|
||||||
else
|
|
||||||
enabled = "true";
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--get the forward destination
|
--get the forward destination
|
||||||
if (session:ready() and (enabled == "true" or enabled == "toggle") ) then
|
if enabled == "true" and empty(forward_all_destination) then
|
||||||
if (string.len(forward_all_destination) == 0) then
|
|
||||||
forward_all_destination = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-enter_destination_telephone_number.wav", "", "\\d+");
|
forward_all_destination = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-enter_destination_telephone_number.wav", "", "\\d+");
|
||||||
|
if empty(forward_all_destination) then return end
|
||||||
|
end
|
||||||
|
|
||||||
|
--set call forward
|
||||||
|
if enabled == "true" then
|
||||||
|
--set forward_all_enabled
|
||||||
|
forward_all_enabled = "true";
|
||||||
|
channel_display(session:get_uuid(), "Activated")
|
||||||
|
--say the destination number
|
||||||
|
session:say(forward_all_destination, default_language, "number", "iterated");
|
||||||
|
--notify the caller
|
||||||
|
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_set.wav");
|
||||||
|
end
|
||||||
|
|
||||||
|
--get the caller_id for outbound call
|
||||||
|
local forward_caller_id = ""
|
||||||
|
if enabled == "true" and not empty(forward_caller_id_uuid) then
|
||||||
|
local sql = "select destination_number, destination_description,"..
|
||||||
|
"destination_caller_id_number, destination_caller_id_name " ..
|
||||||
|
"from v_destinations where domain_uuid = '" .. domain_uuid .. "' and " ..
|
||||||
|
"destination_type = 'inbound' and destination_uuid = '" .. forward_caller_id_uuid .. "'";
|
||||||
|
local row = dbh:first_row(sql)
|
||||||
|
if row then
|
||||||
|
local caller_id_number = row.destination_caller_id_number
|
||||||
|
if empty(caller_id_number) then
|
||||||
|
caller_id_number = row.destination_number
|
||||||
|
end
|
||||||
|
|
||||||
|
local caller_id_name = row.destination_caller_id_name
|
||||||
|
if empty(caller_id_name) then
|
||||||
|
caller_id_name = row.destination_description
|
||||||
|
end
|
||||||
|
|
||||||
|
if not empty(caller_id_number) then
|
||||||
|
forward_caller_id = forward_caller_id ..
|
||||||
|
",outbound_caller_id_number=" .. caller_id_number ..
|
||||||
|
",origination_caller_id_number=" .. caller_id_number
|
||||||
|
end
|
||||||
|
|
||||||
|
if not empty(caller_id_name) then
|
||||||
|
forward_caller_id = forward_caller_id ..
|
||||||
|
",outbound_caller_id_name=" .. caller_id_name ..
|
||||||
|
",origination_caller_id_name=" .. caller_id_name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--set the dial string
|
--set the dial string
|
||||||
if (session:ready() and enabled == "true") then
|
if enabled == "true" then
|
||||||
|
local destination_extension, destination_number_alias
|
||||||
|
|
||||||
--used for number_alias to get the correct user
|
--used for number_alias to get the correct user
|
||||||
sql = "select * from v_extensions ";
|
local sql = "select extension, number_alias from v_extensions ";
|
||||||
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
||||||
sql = sql .. "and number_alias = '"..forward_all_destination.."' ";
|
sql = sql .. "and number_alias = '"..forward_all_destination.."' ";
|
||||||
status = dbh:query(sql, function(row)
|
dbh:query(sql, function(row)
|
||||||
destination_user = row.extension;
|
destination_user = row.extension;
|
||||||
|
destination_extension = row.extension;
|
||||||
|
destination_number_alias = row.number_alias or '';
|
||||||
end);
|
end);
|
||||||
|
|
||||||
|
local presence_id
|
||||||
|
if destination_extension then
|
||||||
|
if (#destination_number_alias > 0) and (opt(settings(domain_uuid), 'provision', 'number_as_presence_id', 'boolean') == 'true') then
|
||||||
|
presence_id = destination_number_alias
|
||||||
|
else
|
||||||
|
presence_id = destination_extension
|
||||||
|
end
|
||||||
|
elseif extension then
|
||||||
|
-- setting here presence_id equal extension not dialed number allows work BLF and intercept.
|
||||||
|
-- $presence_id = extension_presence_id($this->extension, $this->number_alias);
|
||||||
|
if (#number_alias > 0) and (opt(settings(domain_uuid), 'provision', 'number_as_presence_id', 'boolean') == 'true') then
|
||||||
|
presence_id = number_alias
|
||||||
|
else
|
||||||
|
presence_id = extension
|
||||||
|
end
|
||||||
|
else
|
||||||
|
presence_id = forward_all_destination
|
||||||
|
end
|
||||||
|
|
||||||
--set the dial_string
|
--set the dial_string
|
||||||
dial_string = "{presence_id="..forward_all_destination.."@"..domain_name;
|
dial_string = "{presence_id="..presence_id.."@"..domain_name;
|
||||||
dial_string = dial_string .. ",instant_ringback=true";
|
dial_string = dial_string .. ",instant_ringback=true";
|
||||||
dial_string = dial_string .. ",domain_uuid="..domain_uuid;
|
dial_string = dial_string .. ",domain_uuid="..domain_uuid;
|
||||||
dial_string = dial_string .. ",sip_invite_domain="..domain_name;
|
dial_string = dial_string .. ",sip_invite_domain="..domain_name;
|
||||||
|
|
@ -176,6 +249,7 @@
|
||||||
if (accountcode ~= nil) then
|
if (accountcode ~= nil) then
|
||||||
dial_string = dial_string .. ",accountcode="..accountcode;
|
dial_string = dial_string .. ",accountcode="..accountcode;
|
||||||
end
|
end
|
||||||
|
dial_string = dial_string .. forward_caller_id
|
||||||
dial_string = dial_string .. "}";
|
dial_string = dial_string .. "}";
|
||||||
|
|
||||||
if (destination_user ~= nil) then
|
if (destination_user ~= nil) then
|
||||||
|
|
@ -195,52 +269,36 @@
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--set call forward
|
--unset call forward
|
||||||
if (session:ready() and enabled == "true") then
|
if session:ready() and enabled == "false" then
|
||||||
--set forward_all_enabled
|
|
||||||
forward_all_enabled = "true";
|
|
||||||
--say the destination number
|
|
||||||
session:say(forward_all_destination, default_language, "number", "iterated");
|
|
||||||
--notify the caller
|
|
||||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_set.wav");
|
|
||||||
end
|
|
||||||
|
|
||||||
--unset call forward
|
|
||||||
if (session:ready() and enabled == "false") then
|
|
||||||
--set forward_all_enabled
|
--set forward_all_enabled
|
||||||
forward_all_enabled = "false";
|
forward_all_enabled = "false";
|
||||||
|
channel_display(session:get_uuid(), "Cancelled")
|
||||||
--notify the caller
|
--notify the caller
|
||||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_cancelled.wav");
|
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_cancelled.wav");
|
||||||
end
|
end
|
||||||
|
|
||||||
--disable the follow me
|
--disable the follow me
|
||||||
if (session:ready() and enabled == "true" and follow_me_uuid ~= nil) then
|
if enabled == "true" and not empty(follow_me_uuid) then
|
||||||
if (string.len(follow_me_uuid) > 0) then
|
local sql = "update v_follow_me set ";
|
||||||
sql = "update v_follow_me set ";
|
|
||||||
sql = sql .. "follow_me_enabled = 'false' ";
|
sql = sql .. "follow_me_enabled = 'false' ";
|
||||||
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
||||||
sql = sql .. "and follow_me_uuid = '"..follow_me_uuid.."' ";
|
sql = sql .. "and follow_me_uuid = '"..follow_me_uuid.."' ";
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[call_forward] "..sql.."\n");
|
log.notice(sql);
|
||||||
end
|
end
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
--check the destination
|
--check the destination
|
||||||
if (forward_all_destination == nil) then
|
if empty(forward_all_destination) then
|
||||||
enabled = false;
|
enabled = "false";
|
||||||
forward_all_enabled = "false";
|
|
||||||
else
|
|
||||||
if (string.len(forward_all_destination) == 0) then
|
|
||||||
enabled = false;
|
|
||||||
forward_all_enabled = "false";
|
forward_all_enabled = "false";
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
--update the extension
|
--update the extension
|
||||||
if (session:ready()) then
|
do
|
||||||
sql = "update v_extensions set ";
|
local sql = "update v_extensions set ";
|
||||||
if (enabled == "true") then
|
if (enabled == "true") then
|
||||||
sql = sql .. "forward_all_destination = '"..forward_all_destination.."', ";
|
sql = sql .. "forward_all_destination = '"..forward_all_destination.."', ";
|
||||||
sql = sql .. "dial_string = '"..dial_string:gsub("'", "''").."', ";
|
sql = sql .. "dial_string = '"..dial_string:gsub("'", "''").."', ";
|
||||||
|
|
@ -253,25 +311,26 @@
|
||||||
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
||||||
sql = sql .. "and extension_uuid = '"..extension_uuid.."' ";
|
sql = sql .. "and extension_uuid = '"..extension_uuid.."' ";
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[call_forward] "..sql.."\n");
|
log.notice(sql);
|
||||||
end
|
end
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
|
end
|
||||||
|
|
||||||
--clear the cache
|
--disconnect from database
|
||||||
if (extension ~= nil) then
|
dbh:release()
|
||||||
api:execute("memcache", "delete directory:"..extension.."@"..domain_name);
|
|
||||||
|
--clear the cache
|
||||||
|
if extension and #extension > 0 and cache.support() then
|
||||||
|
cache.del("directory:"..extension.."@"..domain_name);
|
||||||
if #number_alias > 0 then
|
if #number_alias > 0 then
|
||||||
api:execute("memcache", "delete directory:"..number_alias.."@"..domain_name);
|
cache.del("directory:"..number_alias.."@"..domain_name);
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- hangup
|
--hangup
|
||||||
if (session:ready()) then
|
if (session:ready()) then
|
||||||
--wait for the file to be written before proceeding
|
--wait for the file to be written before proceeding
|
||||||
session:sleep(100);
|
session:sleep(100);
|
||||||
|
|
||||||
--end the call
|
--end the call
|
||||||
session:hangup();
|
session:hangup();
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
@ -22,94 +22,82 @@
|
||||||
-- Contributor(s):
|
-- Contributor(s):
|
||||||
-- Mark J Crane <markjcrane@fusionpbx.com>
|
-- Mark J Crane <markjcrane@fusionpbx.com>
|
||||||
|
|
||||||
--set default variables
|
--include config.lua
|
||||||
min_digits = "1";
|
require "resources.functions.config";
|
||||||
max_digits = "11";
|
|
||||||
max_tries = "3";
|
|
||||||
digit_timeout = "3000";
|
|
||||||
|
|
||||||
--debug
|
|
||||||
debug["sql"] = true;
|
|
||||||
|
|
||||||
--define the trim function
|
|
||||||
require "resources.functions.trim";
|
|
||||||
|
|
||||||
--define the explode function
|
|
||||||
require "resources.functions.explode";
|
|
||||||
|
|
||||||
--create the api object
|
--create the api object
|
||||||
api = freeswitch.API();
|
api = freeswitch.API();
|
||||||
|
|
||||||
--include config.lua
|
require "resources.functions.channel_utils";
|
||||||
require "resources.functions.config";
|
local log = require "resources.functions.log".follow_me
|
||||||
|
local cache = require "resources.functions.cache"
|
||||||
|
local Database = require "resources.functions.database"
|
||||||
|
|
||||||
--check if the session is ready
|
--check if the session is ready
|
||||||
if ( session:ready() ) then
|
if not session:ready() then return end
|
||||||
--answer the call
|
|
||||||
|
--answer the call
|
||||||
session:answer();
|
session:answer();
|
||||||
|
|
||||||
--get the variables
|
--get the variables
|
||||||
pin_number = session:getVariable("pin_number");
|
local domain_uuid = session:getVariable("domain_uuid");
|
||||||
sounds_dir = session:getVariable("sounds_dir");
|
local domain_name = session:getVariable("domain_name");
|
||||||
domain_uuid = session:getVariable("domain_uuid");
|
local extension_uuid = session:getVariable("extension_uuid");
|
||||||
domain_name = session:getVariable("domain_name");
|
|
||||||
extension_uuid = session:getVariable("extension_uuid");
|
|
||||||
context = session:getVariable("context");
|
|
||||||
if (not context ) then context = 'default'; end
|
|
||||||
|
|
||||||
--set the sounds path for the language, dialect and voice
|
--set the sounds path for the language, dialect and voice
|
||||||
default_language = session:getVariable("default_language");
|
local sounds_dir = session:getVariable("sounds_dir");
|
||||||
default_dialect = session:getVariable("default_dialect");
|
local default_language = session:getVariable("default_language") or 'en';
|
||||||
default_voice = session:getVariable("default_voice");
|
local default_dialect = session:getVariable("default_dialect") or 'us';
|
||||||
if (not default_language) then default_language = 'en'; end
|
local default_voice = session:getVariable("default_voice") or 'callie';
|
||||||
if (not default_dialect) then default_dialect = 'us'; end
|
|
||||||
if (not default_voice) then default_voice = 'callie'; end
|
|
||||||
|
|
||||||
--a moment to sleep
|
--a moment to sleep
|
||||||
session:sleep(1000);
|
session:sleep(1000);
|
||||||
|
|
||||||
--connect to the database
|
--check if the session is ready
|
||||||
require "resources.functions.database_handle";
|
if not session:ready() then return end
|
||||||
dbh = database_handle('system');
|
|
||||||
|
|
||||||
--determine whether to update the dial string
|
--connect to the database
|
||||||
sql = "select * from v_extensions ";
|
local dbh = Database.new('system');
|
||||||
|
|
||||||
|
--determine whether to update the dial string
|
||||||
|
local sql = "select extension, number_alias, accountcode, follow_me_uuid ";
|
||||||
|
sql = sql .. "from v_extensions ";
|
||||||
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
||||||
sql = sql .. "and extension_uuid = '"..extension_uuid.."' ";
|
sql = sql .. "and extension_uuid = '"..extension_uuid.."' ";
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[follow_me] "..sql.."\n");
|
log.notice(sql);
|
||||||
end
|
end
|
||||||
status = dbh:query(sql, function(row)
|
|
||||||
extension = row.extension;
|
|
||||||
number_alias = row.number_alias or '';
|
|
||||||
accountcode = row.accountcode;
|
|
||||||
follow_me_uuid = row.follow_me_uuid;
|
|
||||||
--freeswitch.consoleLog("NOTICE", "[call forward] extension "..row.extension.."\n");
|
|
||||||
--freeswitch.consoleLog("NOTICE", "[call forward] accountcode "..row.accountcode.."\n");
|
|
||||||
end);
|
|
||||||
|
|
||||||
--determine whether to update the dial string
|
local row = dbh:first_row(sql)
|
||||||
enabled = "false";
|
if not row then return end
|
||||||
sql = "select * from v_follow_me ";
|
|
||||||
|
local extension = row.extension;
|
||||||
|
local number_alias = row.number_alias or '';
|
||||||
|
local accountcode = row.accountcode;
|
||||||
|
local follow_me_uuid = row.follow_me_uuid;
|
||||||
|
|
||||||
|
--determine whether to update the dial string
|
||||||
|
sql = "select follow_me_enabled, call_prompt, cid_name_prefix, cid_number_prefix, dial_string "
|
||||||
|
sql = sql .. "from v_follow_me ";
|
||||||
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
||||||
sql = sql .. "and follow_me_uuid = '"..follow_me_uuid.."' ";
|
sql = sql .. "and follow_me_uuid = '"..follow_me_uuid.."' ";
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[follow_me] "..sql.."\n");
|
log.notice(sql);
|
||||||
end
|
end
|
||||||
status = dbh:query(sql, function(row)
|
|
||||||
enabled = row.follow_me_enabled;
|
|
||||||
call_prompt = row.call_prompt;
|
|
||||||
cid_name_prefix = row.cid_name_prefix;
|
|
||||||
cid_number_prefix = row.cid_number_prefix;
|
|
||||||
dial_string = row.dial_string;
|
|
||||||
end);
|
|
||||||
|
|
||||||
--set follow me
|
row = dbh:first_row(sql)
|
||||||
|
if not row then return end
|
||||||
|
|
||||||
|
local enabled = row.follow_me_enabled;
|
||||||
|
local call_prompt = row.call_prompt;
|
||||||
|
local cid_name_prefix = row.cid_name_prefix;
|
||||||
|
local cid_number_prefix = row.cid_number_prefix;
|
||||||
|
local dial_string = row.dial_string;
|
||||||
|
|
||||||
|
--set follow me
|
||||||
if (enabled == "false") then
|
if (enabled == "false") then
|
||||||
--answer and play a tone
|
--play a tone
|
||||||
session:answer();
|
channel_display(session:get_uuid(), "Activated")
|
||||||
api = freeswitch.API();
|
|
||||||
reply = api:executeString("uuid_display "..session:get_uuid().." Activated ");
|
|
||||||
|
|
||||||
session:execute("sleep", "2000");
|
session:execute("sleep", "2000");
|
||||||
session:execute("playback", "tone_stream://%(200,0,500,600,700)");
|
session:execute("playback", "tone_stream://%(200,0,500,600,700)");
|
||||||
|
|
@ -117,12 +105,10 @@
|
||||||
--session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_set.wav");
|
--session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_set.wav");
|
||||||
end
|
end
|
||||||
|
|
||||||
--unset follow me
|
--unset follow me
|
||||||
if (enabled == "true") then
|
if (enabled == "true") then
|
||||||
--answer and play a tone
|
--play a tone
|
||||||
session:answer();
|
channel_display(session:get_uuid(), "Cancelled")
|
||||||
api = freeswitch.API();
|
|
||||||
reply = api:executeString("uuid_display "..session:get_uuid().." Cancelled ");
|
|
||||||
|
|
||||||
session:execute("sleep", "2000");
|
session:execute("sleep", "2000");
|
||||||
session:execute("playback", "tone_stream://%(500,0,300,200,100,50,25)");
|
session:execute("playback", "tone_stream://%(500,0,300,200,100,50,25)");
|
||||||
|
|
@ -130,8 +116,7 @@
|
||||||
--session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_cancelled.wav");
|
--session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_cancelled.wav");
|
||||||
end
|
end
|
||||||
|
|
||||||
--enable or disable follow me
|
--enable or disable follow me
|
||||||
if (follow_me_uuid ~= nil) then
|
|
||||||
sql = "update v_follow_me set ";
|
sql = "update v_follow_me set ";
|
||||||
if (enabled == "true") then
|
if (enabled == "true") then
|
||||||
sql = sql .. "follow_me_enabled = 'false' ";
|
sql = sql .. "follow_me_enabled = 'false' ";
|
||||||
|
|
@ -141,39 +126,36 @@
|
||||||
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
||||||
sql = sql .. "and follow_me_uuid = '"..follow_me_uuid.."' ";
|
sql = sql .. "and follow_me_uuid = '"..follow_me_uuid.."' ";
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[follow_me] "..sql.."\n");
|
log.notice(sql);
|
||||||
end
|
end
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
end
|
|
||||||
|
|
||||||
--update the extension
|
--update the extension
|
||||||
sql = "update v_extensions set ";
|
sql = "update v_extensions set ";
|
||||||
if (enabled == "true") then
|
if (enabled == "true") then
|
||||||
sql = sql .. "dial_string = null, ";
|
sql = sql .. "dial_string = null, ";
|
||||||
else
|
else
|
||||||
sql = sql .. "dial_string = '"..dial_string.."', ";
|
sql = sql .. "dial_string = '"..dial_string:gsub("'", "''").."', ";
|
||||||
end
|
end
|
||||||
sql = sql .. "do_not_disturb = 'false', ";
|
sql = sql .. "do_not_disturb = 'false', ";
|
||||||
sql = sql .. "forward_all_enabled= 'false' ";
|
sql = sql .. "forward_all_enabled= 'false' ";
|
||||||
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
|
||||||
sql = sql .. "and extension_uuid = '"..extension_uuid.."' ";
|
sql = sql .. "and extension_uuid = '"..extension_uuid.."' ";
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[follow_me] "..sql.."\n");
|
log.notice(sql);
|
||||||
end
|
end
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
|
|
||||||
--clear the cache
|
--clear the cache
|
||||||
if (extension ~= nil) then
|
if (extension ~= nil) and cache.support() then
|
||||||
api:execute("memcache", "delete directory:"..extension.."@"..domain_name);
|
cache.del("directory:"..extension.."@"..domain_name);
|
||||||
if #number_alias > 0 then
|
if #number_alias > 0 then
|
||||||
api:execute("memcache", "delete directory:"..number_alias.."@"..domain_name);
|
cache.del("directory:"..number_alias.."@"..domain_name);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--wait for the file to be written before proceeding
|
--wait for the file to be written before proceeding
|
||||||
session:sleep(1000);
|
session:sleep(1000);
|
||||||
|
|
||||||
--end the call
|
--end the call
|
||||||
session:hangup();
|
session:hangup();
|
||||||
|
|
||||||
end
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,14 @@ function channel_evalute(uuid, cmd)
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function channel_display(uuid, text)
|
||||||
|
local cmd = ("uuid_display %s '%s'"):format(uuid, text)
|
||||||
|
local result = trim(api:executeString(cmd))
|
||||||
|
if result:sub(1, 4) == '-ERR' then return nil, result end
|
||||||
|
if result == '_undef_' then return false end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
local _switchname
|
local _switchname
|
||||||
local function switchname()
|
local function switchname()
|
||||||
if _switchname then return _switchname end
|
if _switchname then return _switchname end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue