mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-06 03:33:49 +00:00
Add database support to pin_number.lua.
This commit is contained in:
@@ -22,80 +22,121 @@
|
||||
-- Contributor(s):
|
||||
-- Mark J Crane <markjcrane@fusionpbx.com>
|
||||
|
||||
max_tries = 3;
|
||||
digit_timeout = 5000;
|
||||
max_retries = 3;
|
||||
tries = 0;
|
||||
--set the preset variables
|
||||
max_tries = 3;
|
||||
digit_timeout = 5000;
|
||||
max_retries = 3;
|
||||
tries = 0;
|
||||
|
||||
--define the trim function
|
||||
--include config.lua
|
||||
require "resources.functions.config";
|
||||
|
||||
--define the functions
|
||||
require "resources.functions.trim";
|
||||
|
||||
--define the explode function
|
||||
require "resources.functions.explode";
|
||||
|
||||
function check_pin_number()
|
||||
--sleep
|
||||
session:sleep(500);
|
||||
--increment the number of tries
|
||||
tries = tries + 1;
|
||||
--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
|
||||
if (tries < max_tries) then
|
||||
session:streamFile("phrase:voicemail_fail_auth:#");
|
||||
--make sure the session is ready
|
||||
if ( session:ready() ) then
|
||||
--answer the call
|
||||
session:answer( );
|
||||
|
||||
check_pin_number();
|
||||
--get the variables
|
||||
pin_number = session:getVariable("pin_number");
|
||||
sounds_dir = session:getVariable("sounds_dir");
|
||||
|
||||
--connect to the database
|
||||
if (pin_number == "database") then
|
||||
require "resources.functions.database_handle";
|
||||
dbh = database_handle('system');
|
||||
end
|
||||
end
|
||||
|
||||
--define the check pin number function
|
||||
function check_pin_number()
|
||||
--sleep
|
||||
session:sleep(500);
|
||||
--increment the number of tries
|
||||
tries = tries + 1;
|
||||
--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
|
||||
if (pin_number == "database") then
|
||||
sql = [[SELECT * FROM v_pin_numbers
|
||||
WHERE pin_number = ']] .. digits ..[['
|
||||
AND enabled = 'true' ]];
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("NOTICE", "SQL: "..sql.."\n");
|
||||
end
|
||||
auth = false;
|
||||
dbh:query(sql, function(row)
|
||||
--get the values from the database
|
||||
domain_uuid = row["domain_uuid"];
|
||||
accountcode = row["accountcode"];
|
||||
--set the variable to true
|
||||
auth = true;
|
||||
--set the accountcode
|
||||
if (accountcode ~= nil) then
|
||||
session:setVariable("accountcode", accountcode);
|
||||
end
|
||||
--set the authorized pin number that was used
|
||||
session:setVariable("pin_number", digits);
|
||||
end);
|
||||
|
||||
else
|
||||
session:streamFile("phrase:voicemail_fail_auth:#");
|
||||
session:hangup("NORMAL_CLEARING");
|
||||
return;
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ( session:ready() ) then
|
||||
session:answer( );
|
||||
pin_number = session:getVariable("pin_number");
|
||||
sounds_dir = session:getVariable("sounds_dir");
|
||||
--if not authorized play a message and then hangup
|
||||
if (not auth) then
|
||||
if (tries < max_tries) then
|
||||
session:streamFile("phrase:voicemail_fail_auth:#");
|
||||
check_pin_number();
|
||||
else
|
||||
session:streamFile("phrase:voicemail_fail_auth:#");
|
||||
session:hangup("NORMAL_CLEARING");
|
||||
return;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--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
|
||||
--make sure the session is ready
|
||||
if ( session:ready() ) then
|
||||
|
||||
--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
|
||||
check_pin_number();
|
||||
end
|
||||
end
|
||||
--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
|
||||
check_pin_number();
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user