2012-06-04 16:58:40 +02:00
|
|
|
--
|
|
|
|
|
-- FusionPBX
|
|
|
|
|
-- Version: MPL 1.1
|
|
|
|
|
--
|
|
|
|
|
-- The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
-- 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
-- the License. You may obtain a copy of the License at
|
|
|
|
|
-- http://www.mozilla.org/MPL/
|
|
|
|
|
--
|
|
|
|
|
-- Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
-- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
-- for the specific language governing rights and limitations under the
|
|
|
|
|
-- License.
|
|
|
|
|
--
|
|
|
|
|
-- The Original Code is FusionPBX
|
|
|
|
|
--
|
|
|
|
|
-- The Initial Developer of the Original Code is
|
|
|
|
|
-- Mark J Crane <markjcrane@fusionpbx.com>
|
2015-08-13 07:38:46 +02:00
|
|
|
-- Copyright (C) 2010 - 2015
|
2012-06-04 16:58:40 +02:00
|
|
|
-- the Initial Developer. All Rights Reserved.
|
|
|
|
|
--
|
|
|
|
|
-- Contributor(s):
|
|
|
|
|
-- Mark J Crane <markjcrane@fusionpbx.com>
|
2014-08-23 16:03:23 +02:00
|
|
|
-- Errol W Samuels <ewsamuels@gmail.com>
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2012-12-02 09:38:24 +01:00
|
|
|
--user defined variables
|
|
|
|
|
max_tries = "3";
|
|
|
|
|
digit_timeout = "5000";
|
|
|
|
|
extension = argv[1];
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2012-12-02 09:38:24 +01:00
|
|
|
--set the debug options
|
|
|
|
|
debug["sql"] = false;
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2013-03-31 10:18:41 +02:00
|
|
|
--include config.lua
|
2015-08-11 04:06:33 +02:00
|
|
|
require "resources.functions.config";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2012-12-02 09:38:24 +01:00
|
|
|
--connect to the database
|
2013-05-07 23:41:33 +02:00
|
|
|
if (file_exists(database_dir.."/core.db")) then
|
2013-03-31 10:18:41 +02:00
|
|
|
--dbh = freeswitch.Dbh("core:core"); -- when using sqlite
|
|
|
|
|
dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db");
|
|
|
|
|
else
|
2015-08-11 04:06:33 +02:00
|
|
|
require "resources.functions.database_handle";
|
2013-04-30 01:29:46 +02:00
|
|
|
dbh = database_handle('switch');
|
2013-03-31 10:18:41 +02:00
|
|
|
end
|
|
|
|
|
|
2015-01-30 02:32:38 +01:00
|
|
|
--prepare the api object
|
|
|
|
|
api = freeswitch.API();
|
|
|
|
|
|
|
|
|
|
--add the function
|
2015-08-11 04:06:33 +02:00
|
|
|
require "resources.functions.trim";
|
2015-01-30 02:32:38 +01:00
|
|
|
|
2013-03-31 10:18:41 +02:00
|
|
|
--exits the script if we didn't connect properly
|
|
|
|
|
assert(dbh:connected());
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
if ( session:ready() ) then
|
2012-12-02 09:38:24 +01:00
|
|
|
--answer the session
|
|
|
|
|
session:answer();
|
|
|
|
|
|
|
|
|
|
--get session variables
|
|
|
|
|
pin_number = session:getVariable("pin_number");
|
|
|
|
|
sounds_dir = session:getVariable("sounds_dir");
|
2014-08-23 16:03:23 +02:00
|
|
|
domain_uuid = session:getVariable("domain_uuid");
|
2012-12-02 09:38:24 +01:00
|
|
|
domain_name = session:getVariable("domain_name");
|
2013-11-01 16:50:49 +01:00
|
|
|
context = session:getVariable("context");
|
2014-08-22 09:57:47 +02:00
|
|
|
sofia_profile_name = session:getVariable("sofia_profile_name");
|
2012-06-04 16:58:40 +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
|
|
|
|
|
|
|
|
|
|
--set defaults
|
|
|
|
|
if (digit_min_length) then
|
|
|
|
|
--do nothing
|
|
|
|
|
else
|
|
|
|
|
digit_min_length = "2";
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if (digit_max_length) then
|
|
|
|
|
--do nothing
|
|
|
|
|
else
|
|
|
|
|
digit_max_length = "11";
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--if the pin number is provided then require it
|
|
|
|
|
if (pin_number) then
|
2014-07-31 10:40:15 +02:00
|
|
|
--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
|
|
|
|
|
end
|
|
|
|
|
--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
|
2012-06-04 16:58:40 +02:00
|
|
|
end
|
|
|
|
|
|
2015-01-30 02:32:38 +01:00
|
|
|
--predefined variables
|
|
|
|
|
uuid = '';
|
|
|
|
|
call_hostname = '';
|
|
|
|
|
callee_num = '';
|
|
|
|
|
|
2012-12-02 09:38:24 +01:00
|
|
|
--check the database to get the uuid of a ringing call
|
2014-08-23 16:03:23 +02:00
|
|
|
sql = "select call_uuid as uuid, hostname, callee_num, ip_addr from channels ";
|
2015-08-12 08:09:56 +02:00
|
|
|
sql = sql .. "where callstate in ('RINGING', 'EARLY') ";
|
2015-08-13 07:38:46 +02:00
|
|
|
--sql = sql .. "AND direction = 'outbound' ";
|
2012-12-02 09:38:24 +01:00
|
|
|
if (extension) then
|
|
|
|
|
sql = sql .. "and presence_id = '"..extension.."@"..domain_name.."' ";
|
2012-12-05 09:48:43 +01:00
|
|
|
else
|
2012-12-05 10:08:36 +01:00
|
|
|
if (domain_count > 1) then
|
2013-11-01 16:50:49 +01:00
|
|
|
sql = sql .. "and context = '"..context.."' ";
|
2012-12-05 10:08:36 +01:00
|
|
|
end
|
2012-12-02 09:38:24 +01:00
|
|
|
end
|
|
|
|
|
if (debug["sql"]) then
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "sql "..sql.."\n");
|
|
|
|
|
end
|
2013-01-20 02:13:19 +01:00
|
|
|
dbh:query(sql, function(result)
|
2012-12-02 09:38:24 +01:00
|
|
|
--for key, val in pairs(result) do
|
|
|
|
|
-- freeswitch.consoleLog("NOTICE", "result "..key.." "..val.."\n");
|
|
|
|
|
--end
|
2012-06-04 16:58:40 +02:00
|
|
|
uuid = result.uuid;
|
2014-08-22 09:57:47 +02:00
|
|
|
call_hostname = result.hostname;
|
2014-08-23 16:03:23 +02:00
|
|
|
callee_num = result.callee_num;
|
2012-06-04 16:58:40 +02:00
|
|
|
end);
|
|
|
|
|
end
|
|
|
|
|
|
2014-08-22 09:57:47 +02:00
|
|
|
--get the hostname
|
2015-01-30 02:32:38 +01:00
|
|
|
hostname = trim(api:execute("hostname", ""));
|
2014-08-22 09:57:47 +02:00
|
|
|
freeswitch.consoleLog("NOTICE", "Hostname:"..hostname.." Call Hostname:"..call_hostname.."\n");
|
|
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
--intercept a call that is ringing
|
|
|
|
|
if (uuid) then
|
2015-02-21 21:33:23 +01:00
|
|
|
if (session:getVariable("billmsec") == nil) then
|
|
|
|
|
if (hostname == call_hostname) then
|
|
|
|
|
session:execute("intercept", uuid);
|
|
|
|
|
else
|
|
|
|
|
session:execute("export", "sip_h_X-intercept_uuid="..uuid);
|
|
|
|
|
session:execute("export", "sip_h_X-domain_uuid="..domain_uuid);
|
|
|
|
|
session:execute("export", "sip_h_X-domain_name="..domain_name);
|
|
|
|
|
session:execute("export", "sip_h_X-callee_num="..callee_num);
|
|
|
|
|
port = freeswitch.getGlobalVariable(sofia_profile_name.."_sip_port");
|
|
|
|
|
session:execute("bridge", "sofia/"..sofia_profile_name.."/**@"..call_hostname..":"..port);
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "Send call to other host.... \n");
|
|
|
|
|
end
|
2014-08-22 09:57:47 +02:00
|
|
|
end
|
2012-06-04 16:58:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--notes
|
|
|
|
|
--originate a call
|
|
|
|
|
--cmd = "originate user/1007@voip.example.com &intercept("..uuid..")";
|
|
|
|
|
--api = freeswitch.API();
|
|
|
|
|
--result = api:executeString(cmd);
|