2012-06-04 16:58:40 +02:00
|
|
|
-- page.lua
|
|
|
|
|
-- Part of FusionPBX
|
|
|
|
|
-- Copyright (C) 2010 Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
-- All rights reserved.
|
|
|
|
|
--
|
|
|
|
|
-- Redistribution and use in source and binary forms, with or without
|
|
|
|
|
-- modification, are permitted provided that the following conditions are met:
|
|
|
|
|
--
|
|
|
|
|
-- 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
|
-- this list of conditions and the following disclaimer.
|
|
|
|
|
--
|
|
|
|
|
-- 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
-- notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
-- documentation and/or other materials provided with the distribution.
|
|
|
|
|
--
|
|
|
|
|
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
|
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
|
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|
|
|
|
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
-- POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
2016-06-30 23:08:14 +02:00
|
|
|
--set default settings
|
|
|
|
|
pin_number = "";
|
|
|
|
|
max_tries = "3";
|
|
|
|
|
digit_timeout = "3000";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2015-08-11 04:06:33 +02:00
|
|
|
--define the trim function
|
|
|
|
|
require "resources.functions.trim";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2015-08-11 04:06:33 +02:00
|
|
|
--define the explode function
|
|
|
|
|
require "resources.functions.explode";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2017-04-18 20:11:39 +02:00
|
|
|
--define the split function
|
|
|
|
|
require "resources.functions.split";
|
|
|
|
|
|
|
|
|
|
--iterator over numbers.
|
|
|
|
|
local function each_number(value)
|
|
|
|
|
local begin_value, end_value = split_first(value, "-", true)
|
|
|
|
|
if (not end_value) or (begin_value == end_value) then
|
|
|
|
|
return function()
|
|
|
|
|
local result = begin_value
|
|
|
|
|
begin_value = nil
|
|
|
|
|
return result
|
2016-06-30 23:08:14 +02:00
|
|
|
end
|
2014-10-22 00:57:29 +02:00
|
|
|
end
|
2017-04-18 20:11:39 +02:00
|
|
|
|
|
|
|
|
if string.find(begin_value, "^0") then
|
|
|
|
|
assert(#begin_value == #end_value, "number in range with leading `0` should have same length")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local number_length = ("." .. tostring(#begin_value))
|
|
|
|
|
begin_value, end_value = tonumber(begin_value), tonumber(end_value)
|
|
|
|
|
assert(begin_value and end_value and (begin_value <= end_value), "Invalid range: " .. value)
|
|
|
|
|
|
|
|
|
|
return function()
|
|
|
|
|
value, begin_value = begin_value, begin_value + 1
|
|
|
|
|
if value > end_value then return end
|
|
|
|
|
return string.format("%" .. number_length .. "d", value)
|
|
|
|
|
end
|
2012-06-04 16:58:40 +02:00
|
|
|
end
|
|
|
|
|
|
2016-06-30 23:08:14 +02:00
|
|
|
--make sure the session is ready
|
|
|
|
|
if ( session:ready() ) then
|
|
|
|
|
--answer the call
|
|
|
|
|
session:answer();
|
|
|
|
|
--get the dialplan variables and set them as local variables
|
|
|
|
|
destination_number = session:getVariable("destination_number");
|
|
|
|
|
pin_number = session:getVariable("pin_number");
|
|
|
|
|
domain_name = session:getVariable("domain_name");
|
|
|
|
|
sounds_dir = session:getVariable("sounds_dir");
|
|
|
|
|
destinations = session:getVariable("destinations");
|
2016-07-06 22:48:00 +02:00
|
|
|
rtp_secure_media = session:getVariable("rtp_secure_media");
|
2016-06-30 23:08:14 +02:00
|
|
|
if (destinations == nil) then
|
|
|
|
|
destinations = session:getVariable("extension_list");
|
2014-07-31 10:40:15 +02:00
|
|
|
end
|
2016-06-30 23:08:14 +02:00
|
|
|
destination_table = explode(",",destinations);
|
|
|
|
|
caller_id_name = session:getVariable("caller_id_name");
|
|
|
|
|
caller_id_number = session:getVariable("caller_id_number");
|
|
|
|
|
sip_from_user = session:getVariable("sip_from_user");
|
|
|
|
|
mute = session:getVariable("mute");
|
2016-07-06 22:48:00 +02:00
|
|
|
|
2016-06-30 23:08:14 +02:00
|
|
|
--set the sounds path for the language, dialect and voice
|
|
|
|
|
default_language = session:getVariable("default_language");
|
|
|
|
|
default_dialect = session:getVariable("default_dialect");
|
|
|
|
|
default_voice = session:getVariable("default_voice");
|
|
|
|
|
if (not default_language) then default_language = 'en'; end
|
|
|
|
|
if (not default_dialect) then default_dialect = 'us'; end
|
|
|
|
|
if (not default_voice) then default_voice = 'callie'; end
|
2016-07-06 22:48:00 +02:00
|
|
|
|
|
|
|
|
--set rtp_secure_media to an empty string if not provided.
|
|
|
|
|
if (rtp_secure_media == nil) then
|
|
|
|
|
rtp_secure_media = 'false';
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--define the conference name
|
2017-04-18 19:56:33 +02:00
|
|
|
local conference_name = "page-"..destination_number.."@"..domain_name.."@page"
|
2016-07-06 22:48:00 +02:00
|
|
|
|
|
|
|
|
--set the caller id
|
|
|
|
|
if (caller_id_name) then
|
|
|
|
|
--caller id name provided do nothing
|
|
|
|
|
else
|
|
|
|
|
effective_caller_id_name = session:getVariable("effective_caller_id_name");
|
|
|
|
|
caller_id_name = effective_caller_id_name;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if (caller_id_number) then
|
|
|
|
|
--caller id number provided do nothing
|
|
|
|
|
else
|
|
|
|
|
effective_caller_id_number = session:getVariable("effective_caller_id_number");
|
|
|
|
|
caller_id_number = effective_caller_id_number;
|
|
|
|
|
end
|
|
|
|
|
|
2016-06-30 23:08:14 +02:00
|
|
|
--set conference flags
|
2016-07-06 22:48:00 +02:00
|
|
|
if (mute == "true") then
|
|
|
|
|
flags = "flags{mute}";
|
|
|
|
|
else
|
|
|
|
|
flags = "flags{}";
|
|
|
|
|
end
|
|
|
|
|
|
2016-06-30 23:08:14 +02:00
|
|
|
--if the pin number is provided then require it
|
2016-07-06 22:48:00 +02:00
|
|
|
if (pin_number) then
|
|
|
|
|
--sleep
|
|
|
|
|
session:sleep(500);
|
|
|
|
|
--get the user pin number
|
|
|
|
|
min_digits = 2;
|
|
|
|
|
max_digits = 20;
|
|
|
|
|
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
|
|
|
|
|
--validate the user pin number
|
|
|
|
|
pin_number_table = explode(",",pin_number);
|
|
|
|
|
for index,pin_number in pairs(pin_number_table) do
|
|
|
|
|
if (digits == pin_number) then
|
|
|
|
|
--set the variable to true
|
|
|
|
|
auth = true;
|
|
|
|
|
--set the authorized pin number that was used
|
|
|
|
|
session:setVariable("pin_number", pin_number);
|
|
|
|
|
--end the loop
|
|
|
|
|
break;
|
|
|
|
|
end
|
2016-06-30 23:08:14 +02:00
|
|
|
end
|
2016-07-06 22:48:00 +02:00
|
|
|
--if not authorized play a message and then hangup
|
|
|
|
|
if (not auth) then
|
|
|
|
|
session:streamFile("phrase:voicemail_fail_auth:#");
|
|
|
|
|
session:hangup("NORMAL_CLEARING");
|
|
|
|
|
return;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--originate the calls
|
|
|
|
|
destination_count = 0;
|
|
|
|
|
api = freeswitch.API();
|
|
|
|
|
for index,value in pairs(destination_table) do
|
2017-04-18 20:11:39 +02:00
|
|
|
for destination in each_number(value) do
|
2016-07-06 22:48:00 +02:00
|
|
|
|
|
|
|
|
--get the destination required for number-alias
|
|
|
|
|
destination = api:execute("user_data", destination .. "@" .. domain_name .. " attr id");
|
|
|
|
|
|
|
|
|
|
--prevent calling the user that initiated the page
|
|
|
|
|
if (sip_from_user ~= destination) then
|
|
|
|
|
--cmd = "username_exists id "..destination.."@"..domain_name;
|
|
|
|
|
--reply = trim(api:executeString(cmd));
|
|
|
|
|
--if (reply == "true") then
|
|
|
|
|
destination_status = "show channels like "..destination.."@";
|
|
|
|
|
reply = trim(api:executeString(destination_status));
|
|
|
|
|
if (reply == "0 total.") then
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "[page] destination "..destination.." available\n");
|
2017-04-18 20:11:39 +02:00
|
|
|
if destination == sip_from_user then
|
2016-06-30 23:08:14 +02:00
|
|
|
--this destination is the caller that initated the page
|
|
|
|
|
else
|
|
|
|
|
--originate the call
|
2017-04-18 20:11:39 +02:00
|
|
|
cmd_string = "bgapi originate {sip_auto_answer=true,sip_h_Alert-Info='Ring Answer',hangup_after_bridge=false,rtp_secure_media="..rtp_secure_media..",origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..destination.."@"..domain_name.." conference:"..conference_name.."+"..flags.." inline";
|
2016-06-30 23:08:14 +02:00
|
|
|
api:executeString(cmd_string);
|
|
|
|
|
destination_count = destination_count + 1;
|
|
|
|
|
end
|
2016-07-06 22:48:00 +02:00
|
|
|
--freeswitch.consoleLog("NOTICE", "cmd_string "..cmd_string.."\n");
|
|
|
|
|
else
|
2017-04-18 20:11:39 +02:00
|
|
|
--look inside the reply to check for the correct domain_name
|
2019-08-04 21:59:23 +02:00
|
|
|
if string.find(reply, domain_name, nil, true) then
|
2016-07-06 22:48:00 +02:00
|
|
|
--found: user is busy
|
|
|
|
|
else
|
2017-04-18 20:11:39 +02:00
|
|
|
--not found
|
2016-07-06 22:48:00 +02:00
|
|
|
if (destination == tonumber(sip_from_user)) then
|
|
|
|
|
--this destination is the caller that initated the page
|
|
|
|
|
else
|
|
|
|
|
--originate the call
|
|
|
|
|
cmd_string = "bgapi originate {sip_auto_answer=true,hangup_after_bridge=false,rtp_secure_media="..rtp_secure_media..",origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..destination.."@"..domain_name.." conference:"..conference_name.."+"..flags.." inline";
|
|
|
|
|
api:executeString(cmd_string);
|
|
|
|
|
destination_count = destination_count + 1;
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-06-30 23:08:14 +02:00
|
|
|
end
|
2016-07-06 22:48:00 +02:00
|
|
|
--end
|
|
|
|
|
end
|
2016-06-30 23:08:14 +02:00
|
|
|
end
|
2014-11-03 19:57:01 +01:00
|
|
|
end
|
2016-07-06 22:48:00 +02:00
|
|
|
|
2016-06-30 23:08:14 +02:00
|
|
|
--send main call to the conference room
|
2016-07-06 22:48:00 +02:00
|
|
|
if (destination_count > 0) then
|
|
|
|
|
if (session:getVariable("moderator") == "true") then
|
|
|
|
|
moderator_flag = ",moderator";
|
|
|
|
|
else
|
|
|
|
|
moderator_flag = "";
|
|
|
|
|
end
|
|
|
|
|
session:execute("conference", conference_name.."+flags{endconf"..moderator_flag.."}");
|
2016-06-30 23:08:14 +02:00
|
|
|
else
|
2016-07-06 22:48:00 +02:00
|
|
|
session:execute("playback", "tone_stream://%(500,500,480,620);loops=3");
|
2016-06-30 23:08:14 +02:00
|
|
|
end
|
2016-07-06 22:48:00 +02:00
|
|
|
|
2012-06-07 21:43:43 +02:00
|
|
|
end
|